]> granicus.if.org Git - clang/commitdiff
Fix miscompilation. The custom new[]/delete[] methods were not getting called for...
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>
Wed, 25 Aug 2010 23:14:56 +0000 (23:14 +0000)
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>
Wed, 25 Aug 2010 23:14:56 +0000 (23:14 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@112107 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaExprCXX.cpp
test/CodeGenCXX/new.cpp

index 0bff419107bf1a524b43998ece55f68571d6e5ee..5d850839f9d59e3045e90efd5c0f41f840ecb6f5 100644 (file)
@@ -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 && 
index 61a5a153ca52bbf6c9997668aee398ad27199f35..372bf463647cc9d1a0edfdcd88ccf0c561602304 100644 (file)
@@ -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];
+}