summaryrefslogtreecommitdiffstats
path: root/clang/test
diff options
context:
space:
mode:
authorAnastasia Stulova <anastasia.stulova@arm.com>2019-12-03 17:24:33 +0000
committerAnastasia Stulova <anastasia.stulova@arm.com>2019-12-04 12:25:20 +0000
commite6522a96f56ce0257ab8cc6fca77bf9ea4462fa6 (patch)
treebc7fb5ed0bf428b18e16e0d4ed86d662e74959c5 /clang/test
parent92ce2aff680e31a726c17267e36ff13a1ef31696 (diff)
downloadbcm5719-llvm-e6522a96f56ce0257ab8cc6fca77bf9ea4462fa6.tar.gz
bcm5719-llvm-e6522a96f56ce0257ab8cc6fca77bf9ea4462fa6.zip
[OpenCL] Allow addr space qualifiers on lambda call expressions
The addr space qualifier can be added optionally for lambdas after the attributes. They will alter the default addr space of lambda call operator that is in generic address space by default for OpenCL. 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 addr space conversion rules and there will be no difference to how addr spaces work in method qualifiers. Tags: #clang Differential Revision: https://reviews.llvm.org/D70242
Diffstat (limited to 'clang/test')
-rw-r--r--clang/test/SemaOpenCLCXX/address-space-lambda.cl30
1 files changed, 29 insertions, 1 deletions
diff --git a/clang/test/SemaOpenCLCXX/address-space-lambda.cl b/clang/test/SemaOpenCLCXX/address-space-lambda.cl
index 8f7a839da44..cf87bfaeede 100644
--- a/clang/test/SemaOpenCLCXX/address-space-lambda.cl
+++ b/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 @@ __kernel void foo() {
(*(__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}}
+}
+
OpenPOWER on IntegriCloud