[PATCH] D25103: [CUDA] Handle attributes on CUDA lambdas appearing between [...] and (...).
Justin Lebar via cfe-commits
cfe-commits at lists.llvm.org
Fri Sep 30 10:19:19 PDT 2016
jlebar updated this revision to Diff 73085.
jlebar marked an inline comment as done.
jlebar added a comment.
Don't hallucinate a function declarator.
https://reviews.llvm.org/D25103
Files:
clang/lib/Parse/ParseExprCXX.cpp
clang/test/Parser/lambda-attr.cu
Index: clang/test/Parser/lambda-attr.cu
===================================================================
--- /dev/null
+++ clang/test/Parser/lambda-attr.cu
@@ -0,0 +1,33 @@
+// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s
+// RUN: %clang_cc1 -std=c++11 -fsyntax-only -fcuda-is-device -verify %s
+
+// expected-no-diagnostics
+
+__attribute__((device)) void device_fn() {}
+__attribute__((device)) void hd_fn() {}
+
+__attribute__((device)) void device_attr() {
+ ([]() __attribute__((device)) { device_fn(); })();
+ ([] __attribute__((device)) () { device_fn(); })();
+ ([] __attribute__((device)) { device_fn(); })();
+
+ ([&]() __attribute__((device)){ device_fn(); })();
+ ([&] __attribute__((device)) () { device_fn(); })();
+ ([&] __attribute__((device)) { device_fn(); })();
+
+ ([&](int) __attribute__((device)){ device_fn(); })(0);
+ ([&] __attribute__((device)) (int) { device_fn(); })(0);
+}
+
+__attribute__((host)) __attribute__((device)) void host_device_attrs() {
+ ([]() __attribute__((host)) __attribute__((device)){ hd_fn(); })();
+ ([] __attribute__((host)) __attribute__((device)) () { hd_fn(); })();
+ ([] __attribute__((host)) __attribute__((device)) { hd_fn(); })();
+
+ ([&]() __attribute__((host)) __attribute__((device)){ hd_fn(); })();
+ ([&] __attribute__((host)) __attribute__((device)) () { hd_fn(); })();
+ ([&] __attribute__((host)) __attribute__((device)) { hd_fn(); })();
+
+ ([&](int) __attribute__((host)) __attribute__((device)){ hd_fn(); })(0);
+ ([&] __attribute__((host)) __attribute__((device)) (int) { hd_fn(); })(0);
+}
Index: clang/lib/Parse/ParseExprCXX.cpp
===================================================================
--- clang/lib/Parse/ParseExprCXX.cpp
+++ clang/lib/Parse/ParseExprCXX.cpp
@@ -1124,22 +1124,30 @@
DeclSpec DS(AttrFactory);
Declarator D(DS, Declarator::LambdaExprContext);
TemplateParameterDepthRAII CurTemplateDepthTracker(TemplateParameterDepth);
- Actions.PushLambdaScope();
+ Actions.PushLambdaScope();
+
+ ParsedAttributes Attr(AttrFactory);
+ SourceLocation DeclLoc = Tok.getLocation();
+ SourceLocation DeclEndLoc = DeclLoc;
+ if (getLangOpts().CUDA) {
+ // In CUDA code, GNU attributes are allowed to appear immediately after the
+ // "[...]", even if there is no "(...)" before the lambda body.
+ MaybeParseGNUAttributes(Attr, &DeclEndLoc);
+ D.takeAttributes(Attr, DeclEndLoc);
+ }
TypeResult TrailingReturnType;
if (Tok.is(tok::l_paren)) {
ParseScope PrototypeScope(this,
Scope::FunctionPrototypeScope |
Scope::FunctionDeclarationScope |
Scope::DeclScope);
- SourceLocation DeclEndLoc;
BalancedDelimiterTracker T(*this, tok::l_paren);
T.consumeOpen();
SourceLocation LParenLoc = T.getOpenLocation();
// Parse parameter-declaration-clause.
- ParsedAttributes Attr(AttrFactory);
SmallVector<DeclaratorChunk::ParamInfo, 16> ParamInfo;
SourceLocation EllipsisLoc;
@@ -1245,12 +1253,10 @@
Diag(Tok, diag::err_lambda_missing_parens)
<< TokKind
<< FixItHint::CreateInsertion(Tok.getLocation(), "() ");
- SourceLocation DeclLoc = Tok.getLocation();
- SourceLocation DeclEndLoc = DeclLoc;
+ DeclEndLoc = DeclLoc;
// GNU-style attributes must be parsed before the mutable specifier to be
// compatible with GCC.
- ParsedAttributes Attr(AttrFactory);
MaybeParseGNUAttributes(Attr, &DeclEndLoc);
// Parse 'mutable', if it's there.
@@ -1297,7 +1303,6 @@
TrailingReturnType),
Attr, DeclEndLoc);
}
-
// FIXME: Rename BlockScope -> ClosureScope if we decide to continue using
// it.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D25103.73085.patch
Type: text/x-patch
Size: 3793 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160930/c1f436d2/attachment-0001.bin>
More information about the cfe-commits
mailing list