This is an archive of the discontinued LLVM Phabricator instance.

[clang][cuda/hip] Allow `__noinline__` lambdas
ClosedPublic

Authored by Pierre-vh on Nov 2 2022, 6:42 AM.

Details

Summary

D124866 seem to have had an unintended side effect: noinline on lambdas was no longer accepted.

This fixes the regression and adds a test case for it.

Diff Detail

Event Timeline

Pierre-vh created this revision.Nov 2 2022, 6:42 AM
Herald added a project: Restricted Project. · View Herald TranscriptNov 2 2022, 6:42 AM
Herald added a subscriber: mattd. · View Herald Transcript
Pierre-vh requested review of this revision.Nov 2 2022, 6:42 AM
Herald added a project: Restricted Project. · View Herald TranscriptNov 2 2022, 6:42 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript
yaxunl added a comment.Nov 2 2022, 8:18 AM

need a CodeGenCUDA test

tra added a comment.Nov 2 2022, 10:31 AM

LGTM in principle. Please wait for @rsmith's OK.

clang/lib/Parse/ParseExprCXX.cpp
1297–1308

Nit. I'd rearrange it a bit.

while (true) {
  if (Tok.is(tok::kw___noinline__)) {
    IdentifierInfo *AttrName = Tok.getIdentifierInfo();
    SourceLocation AttrNameLoc = ConsumeToken();
    Attr.addNew(AttrName, AttrNameLoc, nullptr, AttrNameLoc, nullptr, 0,
                ParsedAttr::AS_Keyword);
  } else if (Tok.is(tok::kw___attribute))
    ParseGNUAttributes(Attr, nullptr, &D);
  else 
    break;
}

Can you also add a release note for the fix?

clang/lib/Parse/ParseExprCXX.cpp
1300

Any other keyword attributes that are missing?

alignas/_Alignas
__forceinline
__cdecl/__stdcall/etc

LGTM in principle. Please wait for @rsmith's OK.

I'm happy to defer to @aaron.ballman on this :)

Pierre-vh updated this revision to Diff 472875.Nov 3 2022, 2:05 AM
Pierre-vh marked 2 inline comments as done.

Comments

Not sure if the release note is in the right place though.
As for the test, I did something quite targeted/minimal, hope it's fine?

clang/lib/Parse/ParseExprCXX.cpp
1300

I'm not too familiar with how those attributes work yet, so maybe there's more to handle but I don't have any concrete example of it being an issue and would rather not touch those unless needed

yaxunl added inline comments.Nov 3 2022, 10:23 AM
clang/lib/Parse/ParseExprCXX.cpp
1300

CUDA only allows __attribute__ for lambda. __noinline__ used to be an attribute. That's why people use it with lambda. I don't think people use other keywords with lambda.

Comments

Not sure if the release note is in the right place though.
As for the test, I did something quite targeted/minimal, hope it's fine?

LGTM. Thanks.

aaron.ballman accepted this revision.Nov 3 2022, 10:31 AM

LGTM aside from some very minor nits.

clang/docs/ReleaseNotes.rst
641
785–786

Unrelated whitespace changes that can be rolled back.

clang/lib/Parse/ParseExprCXX.cpp
1300

CUDA only allows attribute for lambda. noinline used to be an attribute. That's why people use it with lambda. I don't think people use other keywords with lambda.

Ahhh, thank you, that helps!

This revision is now accepted and ready to land.Nov 3 2022, 10:31 AM
This revision was automatically updated to reflect the committed changes.
Pierre-vh marked 3 inline comments as done.