[PATCH] D70242: [OpenCL] Allow addr space qualifiers on lambda call expressions

2019-12-04 Thread Anastasia Stulova via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGe6522a96f56c: [OpenCL] Allow addr space qualifiers on lambda 
call expressions (authored by Anastasia).
Herald added a project: clang.

Changed prior to commit:
  https://reviews.llvm.org/D70242?vs=229305=232086#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D70242/new/

https://reviews.llvm.org/D70242

Files:
  clang/lib/Parse/ParseExprCXX.cpp
  clang/test/SemaOpenCLCXX/address-space-lambda.cl


Index: clang/test/SemaOpenCLCXX/address-space-lambda.cl
===
--- clang/test/SemaOpenCLCXX/address-space-lambda.cl
+++ clang/test/SemaOpenCLCXX/address-space-lambda.cl
@@ -3,7 +3,7 @@
 //CHECK: CXXMethodDecl {{.*}} constexpr operator() 'int (int) const __generic'
 auto glambda = [](auto a) { return a; };
 
-__kernel void foo() {
+__kernel void test() {
   int i;
 //CHECK: CXXMethodDecl {{.*}} constexpr operator() 'void () const __generic'
   auto  llambda = [&]() {i++;};
@@ -23,3 +23,31 @@
   (*(__constant decltype(llambda) *)nullptr)(); //expected-error{{multiple 
address spaces specified for type}}
   (*(decltype(llambda) *)nullptr)();
 }
+
+__kernel void test_qual() {
+//CHECK: |-CXXMethodDecl {{.*}} constexpr operator() 'void () const'
+  auto priv1 = []() __private {};
+  priv1();
+//CHECK: |-CXXMethodDecl {{.*}} constexpr operator() 'void () const __generic'
+  auto priv2 = []() __generic {};
+  priv2();
+  auto priv3 = []() __global {}; //expected-note-re{{candidate function not 
viable: address space mismatch in 'this' argument ('(lambda at {{.*}})'), 
parameter type must be 'const __global (lambda at {{.*}})'}} 
//expected-note{{conversion candidate of type 'void (*)()'}}
+  priv3(); //expected-error{{no matching function for call to object of type}}
+
+  __constant auto const1 = []() __private{}; //expected-note-re{{candidate 
function not viable: address space mismatch in 'this' argument ('__constant 
(lambda at {{.*}})'), parameter type must be 'const (lambda at {{.*}}'}} 
//expected-note{{conversion candidate of type 'void (*)()'}}
+  const1(); //expected-error{{no matching function for call to object of type 
'__constant (lambda at}}
+  __constant auto const2 = []() __generic{}; //expected-note-re{{candidate 
function not viable: address space mismatch in 'this' argument ('__constant 
(lambda at {{.*}})'), parameter type must be 'const __generic (lambda at 
{{.*}}'}} //expected-note{{conversion candidate of type 'void (*)()'}}
+  const2(); //expected-error{{no matching function for call to object of type 
'__constant (lambda at}}
+//CHECK: |-CXXMethodDecl {{.*}} constexpr operator() 'void () const __constant'
+  __constant auto const3 = []() __constant{};
+  const3();
+
+  [&] () __global {} (); //expected-error{{no matching function for call to 
object of type '(lambda at}} expected-note-re{{candidate function not viable: 
address space mismatch in 'this' argument ('(lambda at {{.*}})'), parameter 
type must be 'const __global (lambda at {{.*}})'}}
+  [&] () __private {} (); //expected-error{{no matching function for call to 
object of type '(lambda at}} expected-note-re{{candidate function not viable: 
address space mismatch in 'this' argument ('(lambda at {{.*}})'), parameter 
type must be 'const (lambda at {{.*}})'}}
+
+  [&] __private {} (); //expected-error{{lambda requires '()' before attribute 
specifier}} expected-error{{expected body of lambda expression}}
+
+  [&] () mutable __private {} ();
+  [&] () __private mutable {} (); //expected-error{{expected body of lambda 
expression}}
+}
+
Index: clang/lib/Parse/ParseExprCXX.cpp
===
--- clang/lib/Parse/ParseExprCXX.cpp
+++ clang/lib/Parse/ParseExprCXX.cpp
@@ -1352,6 +1352,13 @@
 // Parse attribute-specifier[opt].
 MaybeParseCXX11Attributes(Attr, );
 
+// Parse OpenCL addr space attribute.
+if (Tok.isOneOf(tok::kw___private, tok::kw___global, tok::kw___local,
+tok::kw___constant, tok::kw___generic)) {
+  ParseOpenCLQualifiers(DS.getAttributes());
+  ConsumeToken();
+}
+
 SourceLocation FunLocalRangeEnd = DeclEndLoc;
 
 // Parse trailing-return-type[opt].
@@ -1380,10 +1387,12 @@
   NoexceptExpr.isUsable() ? NoexceptExpr.get() : nullptr,
   /*ExceptionSpecTokens*/ nullptr,
   /*DeclsInPrototype=*/None, LParenLoc, FunLocalRangeEnd, 
D,
-  TrailingReturnType),
+  TrailingReturnType, ),
   std::move(Attr), DeclEndLoc);
   } else if (Tok.isOneOf(tok::kw_mutable, tok::arrow, tok::kw___attribute,
- tok::kw_constexpr, tok::kw_consteval) ||
+ tok::kw_constexpr, tok::kw_consteval,
+ tok::kw___private, tok::kw___global, tok::kw___local,
+   

[PATCH] D70242: [OpenCL] Allow addr space qualifiers on lambda call expressions

2019-11-19 Thread Anastasia Stulova via Phabricator via cfe-commits
Anastasia added a comment.

In D70242#1748313 , @rjmccall wrote:

> Well that was easy.
>
> Do we accept the address-space attribute in this position, or is that TBD?


We accept the OpenCL one right at the end. I might need to test more in C++ 
though...


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D70242/new/

https://reviews.llvm.org/D70242



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D70242: [OpenCL] Allow addr space qualifiers on lambda call expressions

2019-11-16 Thread John McCall via Phabricator via cfe-commits
rjmccall accepted this revision.
rjmccall added a comment.
This revision is now accepted and ready to land.

Well that was easy.

Do we accept the address-space attribute in this position, or is that TBD?


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D70242/new/

https://reviews.llvm.org/D70242



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D70242: [OpenCL] Allow addr space qualifiers on lambda call expressions

2019-11-14 Thread Anastasia Stulova via Phabricator via cfe-commits
Anastasia created this revision.
Anastasia added a reviewer: rjmccall.
Herald added subscribers: ebevhan, yaxunl.
Anastasia edited the summary of this revision.

The addr space qualifier can be added optionally for lambdas after the 
attributes. They will alter the default address space of lambda call operator 
that is in `__generic` address space by default for OpenCL (see 
https://reviews.llvm.org/D69938).

**Syntax: **

  [ captures ] ( params ) specifiers exception attr opencl_addrspace -> ret { 
body }

**Example:**

  [&] (int i) mutable __global { ... };

On the call into lambda a compatibility check will be performed to determine 
whether address space of lambda object and its call operator are compatible. 
This will follow regular address space conversion rules and there will be no 
difference to the behavior of address spaces in method qualifiers (see: 
https://reviews.llvm.org/D55850)


https://reviews.llvm.org/D70242

Files:
  clang/lib/Parse/ParseExprCXX.cpp
  clang/test/SemaOpenCLCXX/address-space-lambda.cl


Index: clang/test/SemaOpenCLCXX/address-space-lambda.cl
===
--- clang/test/SemaOpenCLCXX/address-space-lambda.cl
+++ clang/test/SemaOpenCLCXX/address-space-lambda.cl
@@ -3,7 +3,7 @@
 //CHECK: CXXMethodDecl {{.*}} constexpr operator() 'int (int) const __generic'
 auto glambda = [](auto a) { return a; };
 
-__kernel void foo() {
+__kernel void test() {
   int i;
 //CHECK: CXXMethodDecl {{.*}} constexpr operator() 'void () const __generic'
   auto  llambda = [&]() {i++;};
@@ -17,3 +17,31 @@
   (*(__constant decltype(llambda) *) nullptr)(); //expected-error{{multiple 
address spaces specified for type}}
   (*(decltype(llambda) *) nullptr)();
 }
+
+__kernel void test_qual() {
+//CHECK: |-CXXMethodDecl {{.*}} constexpr operator() 'void () const'
+  auto priv1 = []() __private {};
+  priv1();
+//CHECK: |-CXXMethodDecl {{.*}} constexpr operator() 'void () const __generic'
+  auto priv2 = []() __generic {};
+  priv2();
+  auto priv3 = []() __global {}; //expected-note-re{{candidate function not 
viable: address space mismatch in 'this' argument ('(lambda at {{.*}})'), 
parameter type must be 'const __global (lambda at {{.*}})'}} 
//expected-note{{conversion candidate of type 'void (*)()'}}
+  priv3(); //expected-error{{no matching function for call to object of type}}
+
+  __constant auto const1 = []() __private{}; //expected-note-re{{candidate 
function not viable: address space mismatch in 'this' argument ('__constant 
(lambda at {{.*}})'), parameter type must be 'const (lambda at {{.*}}'}} 
//expected-note{{conversion candidate of type 'void (*)()'}}
+  const1(); //expected-error{{no matching function for call to object of type 
'__constant (lambda at}}
+  __constant auto const2 = []() __generic{}; //expected-note-re{{candidate 
function not viable: address space mismatch in 'this' argument ('__constant 
(lambda at {{.*}})'), parameter type must be 'const __generic (lambda at 
{{.*}}'}} //expected-note{{conversion candidate of type 'void (*)()'}}
+  const2(); //expected-error{{no matching function for call to object of type 
'__constant (lambda at}}
+//CHECK: |-CXXMethodDecl {{.*}} constexpr operator() 'void () const __constant'
+  __constant auto const3 = []() __constant{};
+  const3();
+
+  [&] () __global {} (); //expected-error{{no matching function for call to 
object of type '(lambda at}} expected-note-re{{candidate function not viable: 
address space mismatch in 'this' argument ('(lambda at {{.*}})'), parameter 
type must be 'const __global (lambda at {{.*}})'}}
+  [&] () __private {} (); //expected-error{{no matching function for call to 
object of type '(lambda at}} expected-note-re{{candidate function not viable: 
address space mismatch in 'this' argument ('(lambda at {{.*}})'), parameter 
type must be 'const (lambda at {{.*}})'}}
+
+  [&] __private {} (); //expected-error{{lambda requires '()' before attribute 
specifier}} expected-error{{expected body of lambda expression}}
+
+  [&] () mutable __private {} ();
+  [&] () __private mutable {} (); //expected-error{{expected body of lambda 
expression}}
+}
+
Index: clang/lib/Parse/ParseExprCXX.cpp
===
--- clang/lib/Parse/ParseExprCXX.cpp
+++ clang/lib/Parse/ParseExprCXX.cpp
@@ -1316,6 +1316,13 @@
 // Parse attribute-specifier[opt].
 MaybeParseCXX11Attributes(Attr, );
 
+// Parse OpenCL addr space attribute.
+if (Tok.isOneOf(tok::kw___private, tok::kw___global, tok::kw___local,
+tok::kw___constant, tok::kw___generic)) {
+  ParseOpenCLQualifiers(DS.getAttributes());
+  ConsumeToken();
+}
+
 SourceLocation FunLocalRangeEnd = DeclEndLoc;
 
 // Parse trailing-return-type[opt].
@@ -1344,10 +1351,12 @@
   NoexceptExpr.isUsable() ? NoexceptExpr.get() : nullptr,
   /*ExceptionSpecTokens*/ nullptr,