[PATCH] D69938: [OpenCL] Use __generic addr space when generating internal representation of lambda

John McCall via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Nov 7 09:05:02 PST 2019


rjmccall added a comment.

It does make logical sense to be able to qualify the call operator of a lambda.  The lambda always starts as a temporary, so presumably we want the default address space qualifier on lambdas to be compatible with the address space of temporaries.  However, that's probably also true of the default address qualifier on methods in general or you wouldn't be able to call them on temporaries and locals.  Thus, we should be able to use the same default in both cases, which seems to be what you've implemented.

It even makes sense to be able to qualify a lambda with an address space that's not compatible with the address space of temporaries; that just means that the lambda has to be copied elsewhere before it can be invoked.

The right place to write the qualifier is the same place where you have to write attributes and/or `mutable`, i.e. in the lambda declarator, something like `[]() __local { ... }`.

Arguably there ought to be a special-case rule allowing lambdas with no captures to be called in an arbitrary address space, but I don't think we need to go there in this patch.



================
Comment at: clang/test/SemaOpenCLCXX/address-space-lambda.cl:13
+  __constant auto err = [&]() {}; //expected-note-re{{candidate function not viable: address space mismatch in 'this' argument ('__constant (lambda at {{.*}})'), parameter type must be 'const __generic (lambda at {{.*}})'}}
+  err(); //expected-error-re{{no matching function for call to object of type '__constant (lambda at {{.*}})'}}
+}
----------------
Can we get a better diagnostic here when a candidate would have succeeded except for an address-space mismatch?  Something like "candidate function not viable: cannot convert 'this' from '__constant' address space to '__generic'"?  You can do that in a separate patch, of course.


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

https://reviews.llvm.org/D69938





More information about the cfe-commits mailing list