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. https://reviews.llvm.org/D62584 Files: lib/Sema/SemaType.cpp test/SemaOpenCLCXX/address-space-deduction.cl 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() ||
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() ||
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits