r240242 - [Codegen] Don't crash if destructor is not accessible.

Davide Italiano davide at freebsd.org
Sun Jun 21 09:33:50 PDT 2015


Author: davide
Date: Sun Jun 21 11:33:50 2015
New Revision: 240242

URL: http://llvm.org/viewvc/llvm-project?rev=240242&view=rev
Log:
[Codegen] Don't crash if destructor is not accessible.

Testcase provided, in the PR, by Christian Shelton and
reduced by David Majnemer.

PR:		23584
Differential Revision:	http://reviews.llvm.org/D10508
Reviewed by:	rnk

Added:
    cfe/trunk/test/CodeGenCXX/destructor-crash.cpp
Modified:
    cfe/trunk/lib/CodeGen/CGClass.cpp

Modified: cfe/trunk/lib/CodeGen/CGClass.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGClass.cpp?rev=240242&r1=240241&r2=240242&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGClass.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGClass.cpp Sun Jun 21 11:33:50 2015
@@ -1297,6 +1297,10 @@ HasTrivialDestructorBody(ASTContext &Con
   if (BaseClassDecl->hasTrivialDestructor())
     return true;
 
+  // Give up if the destructor is not accessible.
+  if (!BaseClassDecl->getDestructor())
+    return false;
+
   if (!BaseClassDecl->getDestructor()->hasTrivialBody())
     return false;
 

Added: cfe/trunk/test/CodeGenCXX/destructor-crash.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/destructor-crash.cpp?rev=240242&view=auto
==============================================================================
--- cfe/trunk/test/CodeGenCXX/destructor-crash.cpp (added)
+++ cfe/trunk/test/CodeGenCXX/destructor-crash.cpp Sun Jun 21 11:33:50 2015
@@ -0,0 +1,19 @@
+// RUN: %clang_cc1 %s -emit-llvm -std=c++11 -o %t
+
+struct A {
+  ~A();
+};
+
+struct B {
+  A a;
+};
+
+struct C {
+  union {
+    B b;
+  };
+
+  ~C() noexcept;
+};
+
+C::~C() noexcept {}





More information about the cfe-commits mailing list