[cfe-commits] r112107 - in /cfe/trunk: lib/Sema/SemaExprCXX.cpp test/CodeGenCXX/new.cpp
Argyrios Kyrtzidis
akyrtzi at gmail.com
Wed Aug 25 16:14:56 PDT 2010
Author: akirtzidis
Date: Wed Aug 25 18:14:56 2010
New Revision: 112107
URL: http://llvm.org/viewvc/llvm-project?rev=112107&view=rev
Log:
Fix miscompilation. The custom new[]/delete[] methods were not getting called for arrays with more than 1 dimension.
Modified:
cfe/trunk/lib/Sema/SemaExprCXX.cpp
cfe/trunk/test/CodeGenCXX/new.cpp
Modified: cfe/trunk/lib/Sema/SemaExprCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprCXX.cpp?rev=112107&r1=112106&r2=112107&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExprCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExprCXX.cpp Wed Aug 25 18:14:56 2010
@@ -940,9 +940,11 @@
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 @@
// 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 @@
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 &&
Modified: cfe/trunk/test/CodeGenCXX/new.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/new.cpp?rev=112107&r1=112106&r2=112107&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/new.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/new.cpp Wed Aug 25 18:14:56 2010
@@ -144,3 +144,14 @@
// 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];
+}
More information about the cfe-commits
mailing list