From: Argyrios Kyrtzidis Date: Wed, 25 Aug 2010 23:14:56 +0000 (+0000) Subject: Fix miscompilation. The custom new[]/delete[] methods were not getting called for... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=d2932986a16244b7f9a3f9a7a6b0daf543c91540;p=clang Fix miscompilation. The custom new[]/delete[] methods were not getting called for arrays with more than 1 dimension. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@112107 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaExprCXX.cpp b/lib/Sema/SemaExprCXX.cpp index 0bff419107..5d850839f9 100644 --- a/lib/Sema/SemaExprCXX.cpp +++ b/lib/Sema/SemaExprCXX.cpp @@ -940,9 +940,11 @@ bool Sema::FindAllocationFunctions(SourceLocation StartLoc, SourceRange Range, DeclarationName DeleteName = Context.DeclarationNames.getCXXOperatorName( IsArray ? OO_Array_Delete : OO_Delete); - if (AllocType->isRecordType() && !UseGlobal) { + QualType AllocElemType = Context.getBaseElementType(AllocType); + + if (AllocElemType->isRecordType() && !UseGlobal) { CXXRecordDecl *Record - = cast(AllocType->getAs()->getDecl()); + = cast(AllocElemType->getAs()->getDecl()); if (FindAllocationOverload(StartLoc, Range, NewName, &AllocArgs[0], AllocArgs.size(), Record, /*AllowMissing=*/true, OperatorNew)) @@ -980,9 +982,9 @@ bool Sema::FindAllocationFunctions(SourceLocation StartLoc, SourceRange Range, // the allocated type is not a class type or array thereof, the // deallocation function’s name is looked up in the global scope. LookupResult FoundDelete(*this, DeleteName, StartLoc, LookupOrdinaryName); - if (AllocType->isRecordType() && !UseGlobal) { + if (AllocElemType->isRecordType() && !UseGlobal) { CXXRecordDecl *RD - = cast(AllocType->getAs()->getDecl()); + = cast(AllocElemType->getAs()->getDecl()); LookupQualifiedName(FoundDelete, RD); } if (FoundDelete.isAmbiguous()) @@ -1469,7 +1471,8 @@ Sema::ActOnCXXDelete(SourceLocation StartLoc, bool UseGlobal, DeclarationName DeleteName = Context.DeclarationNames.getCXXOperatorName( ArrayForm ? OO_Array_Delete : OO_Delete); - if (const RecordType *RT = Pointee->getAs()) { + QualType PointeeElem = Context.getBaseElementType(Pointee); + if (const RecordType *RT = PointeeElem->getAs()) { CXXRecordDecl *RD = cast(RT->getDecl()); if (!UseGlobal && diff --git a/test/CodeGenCXX/new.cpp b/test/CodeGenCXX/new.cpp index 61a5a153ca..372bf46364 100644 --- a/test/CodeGenCXX/new.cpp +++ b/test/CodeGenCXX/new.cpp @@ -144,3 +144,14 @@ void t13(int n) { // CHECK-NEXT: ret void } + +struct Alloc{ + void* operator new[](size_t size); + void operator delete[](void* p); +}; + +void f() { + // CHECK: call i8* @_ZN5AllocnaEm(i64 200) + // CHECK: call void @_ZN5AllocdaEPv(i8* + delete[] new Alloc[10][20]; +}