diff --git a/clang/include/clang/AST/ASTContext.h b/clang/include/clang/AST/ASTContext.h --- a/clang/include/clang/AST/ASTContext.h +++ b/clang/include/clang/AST/ASTContext.h @@ -1362,6 +1362,12 @@ /// Get address space for OpenCL type. LangAS getOpenCLTypeAddrSpace(const Type *T) const; + /// Returns default address space based on OpenCL version and enabled features + inline LangAS getDefaultOpenCLAddrSpace() { + return LangOpts.OpenCLGenericAddressSpace ? LangAS::opencl_generic + : LangAS::opencl_private; + } + void setcudaConfigureCallDecl(FunctionDecl *FD) { cudaConfigureCallDecl = FD; } diff --git a/clang/lib/Sema/Sema.cpp b/clang/lib/Sema/Sema.cpp --- a/clang/lib/Sema/Sema.cpp +++ b/clang/lib/Sema/Sema.cpp @@ -1430,7 +1430,7 @@ LangAS Sema::getDefaultCXXMethodAddrSpace() const { if (getLangOpts().OpenCL) - return LangAS::opencl_generic; + return getASTContext().getDefaultOpenCLAddrSpace(); return LangAS::Default; } diff --git a/clang/lib/Sema/SemaTemplateDeduction.cpp b/clang/lib/Sema/SemaTemplateDeduction.cpp --- a/clang/lib/Sema/SemaTemplateDeduction.cpp +++ b/clang/lib/Sema/SemaTemplateDeduction.cpp @@ -3879,8 +3879,9 @@ // "lvalue reference to A" is used in place of A for type deduction. if (isForwardingReference(QualType(ParamRefType, 0), FirstInnerIndex) && Arg->isLValue()) { - if (S.getLangOpts().OpenCL && !ArgType.hasAddressSpace()) - ArgType = S.Context.getAddrSpaceQualType(ArgType, LangAS::opencl_generic); + if (S.getLangOpts().OpenCL && !ArgType.hasAddressSpace()) + ArgType = S.Context.getAddrSpaceQualType( + ArgType, S.Context.getDefaultOpenCLAddrSpace()); ArgType = S.Context.getLValueReferenceType(ArgType); } } else { diff --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp --- a/clang/lib/Sema/SemaType.cpp +++ b/clang/lib/Sema/SemaType.cpp @@ -2092,9 +2092,7 @@ !PointeeType->isSamplerT() && !PointeeType.hasAddressSpace()) PointeeType = S.getASTContext().getAddrSpaceQualType( - PointeeType, S.getLangOpts().OpenCLGenericAddressSpace - ? LangAS::opencl_generic - : LangAS::opencl_private); + PointeeType, S.getASTContext().getDefaultOpenCLAddrSpace()); return PointeeType; }