[PATCH] D62584: [OpenCL][PR42033] Deducing addr space of pointer/reference with template parameter types

Anastasia Stulova via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed May 29 06:32:20 PDT 2019

Anastasia created this revision.
Anastasia added reviewers: rjmccall, mantognini.
Herald added subscribers: ebevhan, yaxunl.

If dependent types appear in pointers or references we have to allow the addr space deduction because the addr space in template argument will belong to the pointee and not the pointer or reference itself. Hence we end up with un-deduced i.e. `Default` address space.



Index: test/SemaOpenCLCXX/address-space-deduction.cl
--- test/SemaOpenCLCXX/address-space-deduction.cl
+++ test/SemaOpenCLCXX/address-space-deduction.cl
@@ -10,3 +10,16 @@
   //CHECK: `-VarDecl {{.*}} foo2 'const __global int' static constexpr cinit
   static constexpr int foo2 = 0;
+template <class T>
+void xxx(T *in) {
+  // This pointer can't be deduced to generic because addr space
+  // will be taken from the template argument.
+  //CHECK: `-VarDecl {{.*}} i 'T *' cinit
+  T *i = in;
+__kernel void test() {
+  int foo[10];
+  xxx(&foo[0]);
Index: lib/Sema/SemaType.cpp
--- lib/Sema/SemaType.cpp
+++ lib/Sema/SemaType.cpp
@@ -7360,7 +7360,9 @@
       (T->isVoidType() && !IsPointee) ||
       // Do not deduce addr spaces for dependent types because they might end
       // up instantiating to a type with an explicit address space qualifier.
-      T->isDependentType() ||
+      // Expect for pointer or reference types because the addr space in
+      // template argument can only belong to a pointee.
+      (T->isDependentType() && !T->isPointerType() && !T->isReferenceType()) ||
       // Do not deduce addr space of decltype because it will be taken from
       // its argument.
       T->isDecltypeType() ||

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D62584.201889.patch
Type: text/x-patch
Size: 1379 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190529/ac0eb5b6/attachment.bin>

More information about the cfe-commits mailing list