[PATCH] D54634: [OpenCL] Fix address space deduction in template args

Phabricator via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Nov 19 03:02:59 PST 2018


This revision was automatically updated to reflect the committed changes.
Closed by commit rL347189: [OpenCL] Fix address space deduction in template args. (authored by stulova, committed by ).
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D54634?vs=174381&id=174579#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D54634

Files:
  cfe/trunk/lib/Sema/SemaType.cpp
  cfe/trunk/test/CodeGenOpenCLCXX/template-address-spaces.cl


Index: cfe/trunk/test/CodeGenOpenCLCXX/template-address-spaces.cl
===================================================================
--- cfe/trunk/test/CodeGenOpenCLCXX/template-address-spaces.cl
+++ cfe/trunk/test/CodeGenOpenCLCXX/template-address-spaces.cl
@@ -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();
+}
Index: cfe/trunk/lib/Sema/SemaType.cpp
===================================================================
--- cfe/trunk/lib/Sema/SemaType.cpp
+++ cfe/trunk/lib/Sema/SemaType.cpp
@@ -7227,7 +7227,9 @@
     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 ||


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D54634.174579.patch
Type: text/x-patch
Size: 1742 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20181119/75e393f7/attachment.bin>


More information about the cfe-commits mailing list