Author: Anton Zabaznov Date: 2021-02-17T12:18:46+03:00 New Revision: e1a64aa66c332d16b3f0dae0426ee29eeb6bbba6
URL: https://github.com/llvm/llvm-project/commit/e1a64aa66c332d16b3f0dae0426ee29eeb6bbba6 DIFF: https://github.com/llvm/llvm-project/commit/e1a64aa66c332d16b3f0dae0426ee29eeb6bbba6.diff LOG: [OpenCL] Create VoidPtrTy with generic AS in C++ for OpenCL mode This change affects 'SemaOpenCLCXX/newdelete.cl' test, thus the patch contains adjustments in types validation of operators new and delete Reviewed By: Anastasia Differential Revision: https://reviews.llvm.org/D96178 Added: clang/test/CodeGenOpenCLCXX/addrspace-new-delete.cl Modified: clang/lib/AST/ASTContext.cpp clang/lib/Sema/SemaDeclCXX.cpp Removed: ################################################################################ diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp index 80ec858ca0f0..02f9b214fe94 100644 --- a/clang/lib/AST/ASTContext.cpp +++ b/clang/lib/AST/ASTContext.cpp @@ -1445,7 +1445,7 @@ void ASTContext::InitBuiltinTypes(const TargetInfo &Target, ObjCSuperType = QualType(); // void * type - if (LangOpts.OpenCLVersion >= 200) { + if (LangOpts.OpenCLGenericAddressSpace) { auto Q = VoidTy.getQualifiers(); Q.setAddressSpace(LangAS::opencl_generic); VoidPtrTy = getPointerType(getCanonicalType( diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp index 8bfaa46162bc..bef7cb39fdff 100644 --- a/clang/lib/Sema/SemaDeclCXX.cpp +++ b/clang/lib/Sema/SemaDeclCXX.cpp @@ -15261,11 +15261,13 @@ CheckOperatorNewDeleteDeclarationScope(Sema &SemaRef, return false; } -static QualType -RemoveAddressSpaceFromPtr(Sema &SemaRef, const PointerType *PtrTy) { - QualType QTy = PtrTy->getPointeeType(); - QTy = SemaRef.Context.removeAddrSpaceQualType(QTy); - return SemaRef.Context.getPointerType(QTy); +static CanQualType RemoveAddressSpaceFromPtr(Sema &SemaRef, + const PointerType *PtrTy) { + auto &Ctx = SemaRef.Context; + Qualifiers PtrQuals = PtrTy->getPointeeType().getQualifiers(); + PtrQuals.removeAddressSpace(); + return Ctx.getPointerType(Ctx.getCanonicalType(Ctx.getQualifiedType( + PtrTy->getPointeeType().getUnqualifiedType(), PtrQuals))); } static inline bool @@ -15277,11 +15279,14 @@ CheckOperatorNewDeleteTypes(Sema &SemaRef, const FunctionDecl *FnDecl, QualType ResultType = FnDecl->getType()->castAs<FunctionType>()->getReturnType(); - // The operator is valid on any address space for OpenCL. if (SemaRef.getLangOpts().OpenCLCPlusPlus) { - if (auto *PtrTy = ResultType->getAs<PointerType>()) { + // The operator is valid on any address space for OpenCL. + // Drop address space from actual and expected result types. + if (const auto *PtrTy = ResultType->getAs<PointerType>()) ResultType = RemoveAddressSpaceFromPtr(SemaRef, PtrTy); - } + + if (auto ExpectedPtrTy = ExpectedResultType->getAs<PointerType>()) + ExpectedResultType = RemoveAddressSpaceFromPtr(SemaRef, ExpectedPtrTy); } // Check that the result type is what we expect. @@ -15311,10 +15316,14 @@ CheckOperatorNewDeleteTypes(Sema &SemaRef, const FunctionDecl *FnDecl, QualType FirstParamType = FnDecl->getParamDecl(0)->getType(); if (SemaRef.getLangOpts().OpenCLCPlusPlus) { // The operator is valid on any address space for OpenCL. - if (auto *PtrTy = - FnDecl->getParamDecl(0)->getType()->getAs<PointerType>()) { + // Drop address space from actual and expected first parameter types. + if (const auto *PtrTy = + FnDecl->getParamDecl(0)->getType()->getAs<PointerType>()) FirstParamType = RemoveAddressSpaceFromPtr(SemaRef, PtrTy); - } + + if (auto ExpectedPtrTy = ExpectedFirstParamType->getAs<PointerType>()) + ExpectedFirstParamType = + RemoveAddressSpaceFromPtr(SemaRef, ExpectedPtrTy); } // Check that the first parameter type is what we expect. diff --git a/clang/test/CodeGenOpenCLCXX/addrspace-new-delete.cl b/clang/test/CodeGenOpenCLCXX/addrspace-new-delete.cl new file mode 100644 index 000000000000..f3a397419def --- /dev/null +++ b/clang/test/CodeGenOpenCLCXX/addrspace-new-delete.cl @@ -0,0 +1,16 @@ +// RUN: %clang_cc1 %s -triple spir -cl-std=clc++ -emit-llvm -O0 -o - | FileCheck %s + +typedef __SIZE_TYPE__ size_t; + +class A { +public: + void* operator new(size_t); + void operator delete(void *ptr); +}; + +void test_new_delete(A **a) { +// CHECK: %{{.*}} = call spir_func i8 addrspace(4)* @_ZNU3AS41AnwEj(i32 {{.*}}) + *a = new A; +// CHECK: call spir_func void @_ZNU3AS41AdlEPU3AS4v(i8 addrspace(4)* {{.*}}) + delete *a; +} _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits