]> granicus.if.org Git - clang/commitdiff
[OpenCL] Fix address space deduction in template args.
authorAnastasia Stulova <anastasia.stulova@arm.com>
Mon, 19 Nov 2018 11:00:14 +0000 (11:00 +0000)
committerAnastasia Stulova <anastasia.stulova@arm.com>
Mon, 19 Nov 2018 11:00:14 +0000 (11:00 +0000)
Don't deduce address spaces for non-pointer-like types
in template args.

Fixes PR38603!

Differential Revision: https://reviews.llvm.org/D54634

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@347189 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaType.cpp
test/CodeGenOpenCLCXX/template-address-spaces.cl [new file with mode: 0644]

index 8c008bbcc71c8cde0ad7237b2bf28ee3b5bd7b57..97ceaf97ff46b5efa4a8071193dca9d1651cc623 100644 (file)
@@ -7227,7 +7227,9 @@ static void deduceOpenCLImplicitAddrSpace(TypeProcessingState &State,
     if (IsPointee) {
       ImpAddr = LangAS::opencl_generic;
     } else {
-      if (D.getContext() == DeclaratorContext::FileContext) {
+      if (D.getContext() == DeclaratorContext::TemplateArgContext) {
+        // Do not deduce address space for non-pointee type in template args
+      } else if (D.getContext() == DeclaratorContext::FileContext) {
         ImpAddr = LangAS::opencl_global;
       } else {
         if (D.getDeclSpec().getStorageClassSpec() == DeclSpec::SCS_static ||
diff --git a/test/CodeGenOpenCLCXX/template-address-spaces.cl b/test/CodeGenOpenCLCXX/template-address-spaces.cl
new file mode 100644 (file)
index 0000000..606ab22
--- /dev/null
@@ -0,0 +1,31 @@
+// RUN: %clang_cc1 -cl-std=c++ %s -emit-llvm -o - -O0 -triple spir-unknown-unknown | FileCheck %s
+
+template <typename T>
+struct S{
+  T a;
+  T foo();
+};
+
+template<typename T>
+T S<T>::foo() { return a;}
+
+//CHECK: %struct.S = type { i32 }
+//CHECK: %struct.S.0 = type { i32 addrspace(4)* }
+//CHECK: %struct.S.1 = type { i32 addrspace(1)* }
+
+//CHECK: i32 @_ZN1SIiE3fooEv(%struct.S* %this)
+//CHECK: i32 addrspace(4)* @_ZN1SIPU3AS4iE3fooEv(%struct.S.0* %this)
+//CHECK: i32 addrspace(1)* @_ZN1SIPU3AS1iE3fooEv(%struct.S.1* %this)
+
+void bar(){
+  S<int> sint;
+  S<int*> sintptr;
+  S<__global int*> sintptrgl;
+  // FIXME: Preserve AS in TreeTransform
+  //S<__global int> sintgl;
+
+  sint.foo();
+  sintptr.foo();
+  sintptrgl.foo();
+  //sintgl.foo();
+}