r196488 - PR17983: Fix crasher bug in C++1y mode when performing a non-global array

Richard Smith richard-llvm at metafoo.co.uk
Thu Dec 5 00:30:59 PST 2013


Author: rsmith
Date: Thu Dec  5 02:30:59 2013
New Revision: 196488

URL: http://llvm.org/viewvc/llvm-project?rev=196488&view=rev
Log:
PR17983: Fix crasher bug in C++1y mode when performing a non-global array
delete on a class which has no array cookie and has no class-specific operator
new.

Modified:
    cfe/trunk/lib/Sema/SemaDeclCXX.cpp
    cfe/trunk/lib/Sema/SemaExprCXX.cpp
    cfe/trunk/test/CodeGenCXX/cxx1y-sized-deallocation.cpp

Modified: cfe/trunk/lib/Sema/SemaDeclCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclCXX.cpp?rev=196488&r1=196487&r2=196488&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclCXX.cpp Thu Dec  5 02:30:59 2013
@@ -6192,6 +6192,10 @@ bool Sema::CheckDestructor(CXXDestructor
     Context.DeclarationNames.getCXXOperatorName(OO_Delete);
     if (FindDeallocationFunction(Loc, RD, Name, OperatorDelete))
       return true;
+    // If there's no class-specific operator delete, look up the global
+    // non-array delete.
+    if (!OperatorDelete)
+      OperatorDelete = FindUsualDeallocationFunction(Loc, true, Name);
 
     MarkFunctionReferenced(Loc, OperatorDelete);
     

Modified: cfe/trunk/lib/Sema/SemaExprCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprCXX.cpp?rev=196488&r1=196487&r2=196488&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExprCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExprCXX.cpp Thu Dec  5 02:30:59 2013
@@ -2233,8 +2233,7 @@ bool Sema::FindDeallocationFunction(Sour
     return true;
   }
 
-  // Look for a global declaration.
-  Operator = FindUsualDeallocationFunction(StartLoc, true, Name);
+  Operator = 0;
   return false;
 }
 
@@ -2384,7 +2383,7 @@ Sema::ActOnCXXDelete(SourceLocation Star
 
         // Otherwise, the usual operator delete[] should be the
         // function we just found.
-        else if (isa<CXXMethodDecl>(OperatorDelete))
+        else if (OperatorDelete && isa<CXXMethodDecl>(OperatorDelete))
           UsualArrayDeleteWantsSize = (OperatorDelete->getNumParams() == 2);
       }
 

Modified: cfe/trunk/test/CodeGenCXX/cxx1y-sized-deallocation.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/cxx1y-sized-deallocation.cpp?rev=196488&r1=196487&r2=196488&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/cxx1y-sized-deallocation.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/cxx1y-sized-deallocation.cpp Thu Dec  5 02:30:59 2013
@@ -30,6 +30,8 @@ template<typename T>
 void del() {
   ::delete get<T*>();
   ::delete[] get<T*>();
+  delete get<T*>();
+  delete[] get<T*>();
 }
 
 template void del<A>();
@@ -44,6 +46,9 @@ D::D() {}
 // CHECK-LABEL: define weak_odr void @_Z3delIiEvv()
 // CHECK: call void @_ZdlPvm(i8* %{{[^ ]*}}, i64 4)
 // CHECK: call void @_ZdaPv(i8* %{{[^ ]*}})
+//
+// CHECK: call void @_ZdlPvm(i8* %{{[^ ]*}}, i64 4)
+// CHECK: call void @_ZdaPv(i8* %{{[^ ]*}})
 
 // CHECK-LABEL: define linkonce void @_ZdlPvm(i8*
 // CHECK: call void @_ZdlPv(i8* %0)
@@ -51,12 +56,20 @@ D::D() {}
 // CHECK-LABEL: define weak_odr void @_Z3delI1BEvv()
 // CHECK: call void @_ZdlPvm(i8* %{{[^ ]*}}, i64 4)
 // CHECK: call void @_ZdaPv(i8* %{{[^ ]*}})
+//
+// CHECK: call void @_ZdlPvm(i8* %{{[^ ]*}}, i64 4)
+// CHECK: call void @_ZdaPv(i8* %{{[^ ]*}})
 
 // CHECK-LABEL: define weak_odr void @_Z3delI1CEvv()
 // CHECK: call void @_ZdlPvm(i8* %{{[^ ]*}}, i64 1)
 // CHECK: mul i64 1, %{{[^ ]*}}
 // CHECK: add i64 %{{[^ ]*}}, 8
 // CHECK: call void @_ZdaPvm(i8* %{{[^ ]*}}, i64 %{{[^ ]*}})
+//
+// CHECK: call void @_ZdlPvm(i8* %{{[^ ]*}}, i64 1)
+// CHECK: mul i64 1, %{{[^ ]*}}
+// CHECK: add i64 %{{[^ ]*}}, 8
+// CHECK: call void @_ZdaPvm(i8* %{{[^ ]*}}, i64 %{{[^ ]*}})
 
 // CHECK-LABEL: define linkonce void @_ZdaPvm(i8*
 // CHECK: call void @_ZdaPv(i8* %0)
@@ -66,25 +79,32 @@ D::D() {}
 // CHECK: mul i64 8, %{{[^ ]*}}
 // CHECK: add i64 %{{[^ ]*}}, 8
 // CHECK: call void @_ZdaPvm(i8* %{{[^ ]*}}, i64 %{{[^ ]*}})
+//
+// CHECK-NOT: Zdl
+// CHECK: call void %{{.*}}
+// CHECK-NOT: Zdl
+// CHECK: mul i64 8, %{{[^ ]*}}
+// CHECK: add i64 %{{[^ ]*}}, 8
+// CHECK: call void @_ZdaPvm(i8* %{{[^ ]*}}, i64 %{{[^ ]*}})
 
 // CHECK-LABEL: define weak_odr void @_Z3delI1EEvv()
 // CHECK: call void @_ZdlPvm(i8* %{{[^ ]*}}, i64 1)
 // CHECK: call void @_ZdaPv(i8* %{{[^ ]*}})
+//
+// CHECK: call void @_ZN1EdlEPv(i8* %{{[^ ]*}})
+// CHECK: call void @_ZN1EdaEPv(i8* %{{[^ ]*}})
 
 // CHECK-LABEL: define weak_odr void @_Z3delI1FEvv()
 // CHECK: call void @_ZdlPvm(i8* %{{[^ ]*}}, i64 1)
 // CHECK: mul i64 1, %{{[^ ]*}}
 // CHECK: add i64 %{{[^ ]*}}, 8
 // CHECK: call void @_ZdaPvm(i8* %{{[^ ]*}}, i64 %{{[^ ]*}})
+//
+// CHECK: call void @_ZN1FdlEPvm(i8* %{{[^ ]*}}, i64 1)
+// CHECK: mul i64 1, %{{[^ ]*}}
+// CHECK: add i64 %{{[^ ]*}}, 8
+// CHECK: call void @_ZN1FdaEPvm(i8* %{{[^ ]*}}, i64 %{{[^ ]*}})
 
-// CHECK-LABEL: define void @_Z10member_delv()
-// CHECK-NOT: Zdl
-// CHECK: call void %{{[^ ]*}}(%{{[^ ]*}}* %
-// CHECK-NOT: Zdl
-// CHECK: }
-void member_del() {
-  delete get<D*>();
-}
 
 // CHECK-LABEL: define linkonce_odr void @_ZN1DD0Ev(%{{[^ ]*}}* %this)
 // CHECK: call void @_ZdlPvm(i8* %{{[^ ]*}}, i64 8)





More information about the cfe-commits mailing list