[cfe-commits] r135073 - in /cfe/trunk: lib/Sema/SemaExprCXX.cpp test/CodeGenCXX/partial-destruction.cpp test/SemaCXX/new-delete.cpp

John McCall rjmccall at apple.com
Wed Jul 13 13:12:57 PDT 2011


Author: rjmccall
Date: Wed Jul 13 15:12:57 2011
New Revision: 135073

URL: http://llvm.org/viewvc/llvm-project?rev=135073&view=rev
Log:
Enforce access control for the destructor in a new[] expression and mark
it as used.  Otherwise, we can fail to instantiate or validate the destructor,
which can lead to crashes in IR gen like PR10351.


Modified:
    cfe/trunk/lib/Sema/SemaExprCXX.cpp
    cfe/trunk/test/CodeGenCXX/partial-destruction.cpp
    cfe/trunk/test/SemaCXX/new-delete.cpp

Modified: cfe/trunk/lib/Sema/SemaExprCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprCXX.cpp?rev=135073&r1=135072&r2=135073&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExprCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExprCXX.cpp Wed Jul 13 15:12:57 2011
@@ -1148,7 +1148,17 @@
   if (OperatorDelete)
     MarkDeclarationReferenced(StartLoc, OperatorDelete);
 
-  // FIXME: Also check that the destructor is accessible. (C++ 5.3.4p16)
+  // C++0x [expr.new]p17:
+  //   If the new expression creates an array of objects of class type,
+  //   access and ambiguity control are done for the destructor.
+  if (ArraySize && Constructor) {
+    if (CXXDestructorDecl *dtor = LookupDestructor(Constructor->getParent())) {
+      MarkDeclarationReferenced(StartLoc, dtor);
+      CheckDestructorAccess(StartLoc, dtor, 
+                            PDiag(diag::err_access_dtor)
+                              << Context.getBaseElementType(AllocType));
+    }
+  }
 
   PlacementArgs.release();
   ConstructorArgs.release();

Modified: cfe/trunk/test/CodeGenCXX/partial-destruction.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/partial-destruction.cpp?rev=135073&r1=135072&r2=135073&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/partial-destruction.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/partial-destruction.cpp Wed Jul 13 15:12:57 2011
@@ -153,3 +153,17 @@
   }
 
 }
+
+// PR10351
+namespace test3 {
+  struct A { A(); ~A(); void *p; };
+  struct B {
+    B() {}
+    A a;
+  };
+
+  B *test() {
+    return new B[10];
+    // invoke void @_ZN5test31BD1Ev(
+  }
+}

Modified: cfe/trunk/test/SemaCXX/new-delete.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/new-delete.cpp?rev=135073&r1=135072&r2=135073&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/new-delete.cpp (original)
+++ cfe/trunk/test/SemaCXX/new-delete.cpp Wed Jul 13 15:12:57 2011
@@ -389,3 +389,11 @@
     new DoesNotExist; // expected-error {{expected a type}}
   }
 }
+
+namespace ArrayNewNeedsDtor {
+  struct A { A(); private: ~A(); }; // expected-note {{declared private here}}
+  struct B { B(); A a; }; // expected-error {{field of type 'ArrayNewNeedsDtor::A' has private destructor}}
+  B *test9() {
+    return new B[5]; // expected-note {{implicit default destructor for 'ArrayNewNeedsDtor::B' first required here}}
+  }
+}





More information about the cfe-commits mailing list