Index: include/clang/AST/Type.h =================================================================== --- include/clang/AST/Type.h +++ include/clang/AST/Type.h @@ -1981,6 +1981,7 @@ bool isObjCBoxableRecordType() const; bool isInterfaceType() const; bool isStructureOrClassType() const; + bool isTemplateSpecializationType() const; bool isUnionType() const; bool isComplexIntegerType() const; // GCC _Complex integer type. bool isVectorType() const; // GCC vector type. @@ -6507,6 +6508,10 @@ return isa(this); } +inline bool Type::isTemplateSpecializationType() const { + return isa(this); +} + #define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \ inline bool Type::is##Id##Type() const { \ return isSpecificBuiltinType(BuiltinType::Id); \ Index: lib/Sema/SemaType.cpp =================================================================== --- lib/Sema/SemaType.cpp +++ lib/Sema/SemaType.cpp @@ -7414,9 +7414,13 @@ (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. - // 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()) || + // Expect for: + // - pointer or reference types because the addr space in template + // argument can only belong to a pointee. + // - template specialization as addr space in template argument doesn't + // affect specialization. + (T->isDependentType() && (!T->isPointerType() && !T->isReferenceType() && + !T->isTemplateSpecializationType())) || // 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 @@ -38,3 +38,33 @@ int foo[10]; xxx(&foo[0]); } + +// Deducing addr spaces for template specialization is fine +// addr space of template arg can't affecting the addr space +// of specialization + +template +struct x1 { +//CHECK: -CXXMethodDecl {{.*}} operator= '__generic x1 &(const __generic x1 &) __generic' + x1& operator=(const x1& xx) { + y = xx.y; + return *this; + } + int y; +}; + +template +struct x2 { +//CHECK: -CXXMethodDecl {{.*}} foo 'void (__generic x1 *) __generic' + void foo(x1* xx) { + m[0] = *xx; + } +//CHECK: -FieldDecl {{.*}} m 'x1 [2]' + x1 m[2]; +}; + +void bar(__global x1* xx, __global x2* bar) +{ + bar->foo(xx); +} +