diff options
| author | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2010-08-25 23:14:56 +0000 |
|---|---|---|
| committer | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2010-08-25 23:14:56 +0000 |
| commit | 1194d5e3d2309d449a020df6b9fdf97207ef86f6 (patch) | |
| tree | 716f3de77d6ef992659991a85ed3c8639d0c2e20 /clang | |
| parent | c5e7e703b5254f6a04120b1f13c6cd0c7518e867 (diff) | |
| download | bcm5719-llvm-1194d5e3d2309d449a020df6b9fdf97207ef86f6.tar.gz bcm5719-llvm-1194d5e3d2309d449a020df6b9fdf97207ef86f6.zip | |
Fix miscompilation. The custom new[]/delete[] methods were not getting called for arrays with more than 1 dimension.
llvm-svn: 112107
Diffstat (limited to 'clang')
| -rw-r--r-- | clang/lib/Sema/SemaExprCXX.cpp | 13 | ||||
| -rw-r--r-- | clang/test/CodeGenCXX/new.cpp | 11 |
2 files changed, 19 insertions, 5 deletions
diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp index 0bff419107b..5d850839f9d 100644 --- a/clang/lib/Sema/SemaExprCXX.cpp +++ b/clang/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<CXXRecordDecl>(AllocType->getAs<RecordType>()->getDecl()); + = cast<CXXRecordDecl>(AllocElemType->getAs<RecordType>()->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<CXXRecordDecl>(AllocType->getAs<RecordType>()->getDecl()); + = cast<CXXRecordDecl>(AllocElemType->getAs<RecordType>()->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<RecordType>()) { + QualType PointeeElem = Context.getBaseElementType(Pointee); + if (const RecordType *RT = PointeeElem->getAs<RecordType>()) { CXXRecordDecl *RD = cast<CXXRecordDecl>(RT->getDecl()); if (!UseGlobal && diff --git a/clang/test/CodeGenCXX/new.cpp b/clang/test/CodeGenCXX/new.cpp index 61a5a153ca5..372bf463647 100644 --- a/clang/test/CodeGenCXX/new.cpp +++ b/clang/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]; +} |

