azabaznov created this revision. azabaznov added reviewers: svenvh, Anastasia. Herald added a subscriber: yaxunl. azabaznov requested review of this revision. Herald added a project: clang. Herald added a subscriber: cfe-commits.
This change affects 'SemaOpenCLCXX/newdelete.cl' test, thus the patch contains adjustments in types validation of operators new and delete Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D96178 Files: clang/lib/AST/ASTContext.cpp clang/lib/Sema/SemaDeclCXX.cpp clang/test/CodeGenOpenCLCXX/addrspace-new-delete.cl Index: clang/test/CodeGenOpenCLCXX/addrspace-new-delete.cl =================================================================== --- /dev/null +++ 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; +} Index: clang/lib/Sema/SemaDeclCXX.cpp =================================================================== --- clang/lib/Sema/SemaDeclCXX.cpp +++ clang/lib/Sema/SemaDeclCXX.cpp @@ -15277,11 +15277,18 @@ QualType ResultType = FnDecl->getType()->castAs<FunctionType>()->getReturnType(); - // The operator is valid on any address space for OpenCL. if (SemaRef.getLangOpts().OpenCLCPlusPlus) { + // The operator is valid on any address space for OpenCL. + // Drop address space from actual and expected result types. if (auto *PtrTy = ResultType->getAs<PointerType>()) { ResultType = RemoveAddressSpaceFromPtr(SemaRef, PtrTy); } + + if (CanQual<PointerType> ExpectedPtrTy = + ExpectedResultType->getAs<PointerType>()) { + ExpectedResultType = SemaRef.Context.getCanonicalType( + RemoveAddressSpaceFromPtr(SemaRef, ExpectedPtrTy->getTypePtr())); + } } // Check that the result type is what we expect. @@ -15311,10 +15318,17 @@ QualType FirstParamType = FnDecl->getParamDecl(0)->getType(); if (SemaRef.getLangOpts().OpenCLCPlusPlus) { // The operator is valid on any address space for OpenCL. + // Drop address space from actual and expected first parameter types. if (auto *PtrTy = FnDecl->getParamDecl(0)->getType()->getAs<PointerType>()) { FirstParamType = RemoveAddressSpaceFromPtr(SemaRef, PtrTy); } + + if (CanQual<PointerType> ExpectedPtrTy = + ExpectedFirstParamType->getAs<PointerType>()) { + ExpectedFirstParamType = SemaRef.Context.getCanonicalType( + RemoveAddressSpaceFromPtr(SemaRef, ExpectedPtrTy->getTypePtr())); + } } // Check that the first parameter type is what we expect. Index: clang/lib/AST/ASTContext.cpp =================================================================== --- clang/lib/AST/ASTContext.cpp +++ clang/lib/AST/ASTContext.cpp @@ -1445,7 +1445,7 @@ ObjCSuperType = QualType(); // void * type - if (LangOpts.OpenCLVersion >= 200) { + if (LangOpts.OpenCLGenericAddressSpace) { auto Q = VoidTy.getQualifiers(); Q.setAddressSpace(LangAS::opencl_generic); VoidPtrTy = getPointerType(getCanonicalType(
Index: clang/test/CodeGenOpenCLCXX/addrspace-new-delete.cl =================================================================== --- /dev/null +++ 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; +} Index: clang/lib/Sema/SemaDeclCXX.cpp =================================================================== --- clang/lib/Sema/SemaDeclCXX.cpp +++ clang/lib/Sema/SemaDeclCXX.cpp @@ -15277,11 +15277,18 @@ QualType ResultType = FnDecl->getType()->castAs<FunctionType>()->getReturnType(); - // The operator is valid on any address space for OpenCL. if (SemaRef.getLangOpts().OpenCLCPlusPlus) { + // The operator is valid on any address space for OpenCL. + // Drop address space from actual and expected result types. if (auto *PtrTy = ResultType->getAs<PointerType>()) { ResultType = RemoveAddressSpaceFromPtr(SemaRef, PtrTy); } + + if (CanQual<PointerType> ExpectedPtrTy = + ExpectedResultType->getAs<PointerType>()) { + ExpectedResultType = SemaRef.Context.getCanonicalType( + RemoveAddressSpaceFromPtr(SemaRef, ExpectedPtrTy->getTypePtr())); + } } // Check that the result type is what we expect. @@ -15311,10 +15318,17 @@ QualType FirstParamType = FnDecl->getParamDecl(0)->getType(); if (SemaRef.getLangOpts().OpenCLCPlusPlus) { // The operator is valid on any address space for OpenCL. + // Drop address space from actual and expected first parameter types. if (auto *PtrTy = FnDecl->getParamDecl(0)->getType()->getAs<PointerType>()) { FirstParamType = RemoveAddressSpaceFromPtr(SemaRef, PtrTy); } + + if (CanQual<PointerType> ExpectedPtrTy = + ExpectedFirstParamType->getAs<PointerType>()) { + ExpectedFirstParamType = SemaRef.Context.getCanonicalType( + RemoveAddressSpaceFromPtr(SemaRef, ExpectedPtrTy->getTypePtr())); + } } // Check that the first parameter type is what we expect. Index: clang/lib/AST/ASTContext.cpp =================================================================== --- clang/lib/AST/ASTContext.cpp +++ clang/lib/AST/ASTContext.cpp @@ -1445,7 +1445,7 @@ ObjCSuperType = QualType(); // void * type - if (LangOpts.OpenCLVersion >= 200) { + if (LangOpts.OpenCLGenericAddressSpace) { auto Q = VoidTy.getQualifiers(); Q.setAddressSpace(LangAS::opencl_generic); VoidPtrTy = getPointerType(getCanonicalType(
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits