Anastasia created this revision. Anastasia added reviewers: rjmccall, yaxunl.
Don't deduce address spaces for non-pointer-like types in template args. This fixes bug reported in https://bugs.llvm.org/show_bug.cgi?id=38603 and enables most of template functionality to work correctly. There is still work to be done on address spaces in TreeTransforms to enable full functionality of address spaces with templates (hence FIXME in the test). https://reviews.llvm.org/D54634 Files: lib/Sema/SemaType.cpp test/CodeGenOpenCLCXX/template-address-spaces.cl Index: test/CodeGenOpenCLCXX/template-address-spaces.cl =================================================================== --- /dev/null +++ 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: lib/Sema/SemaType.cpp =================================================================== --- lib/Sema/SemaType.cpp +++ lib/Sema/SemaType.cpp @@ -7223,7 +7223,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 ||
Index: test/CodeGenOpenCLCXX/template-address-spaces.cl =================================================================== --- /dev/null +++ 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: lib/Sema/SemaType.cpp =================================================================== --- lib/Sema/SemaType.cpp +++ lib/Sema/SemaType.cpp @@ -7223,7 +7223,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 ||
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits