[PATCH] [Clang/CodeGen] Prevent crash if destructor class is not accessible

Davide Italiano dccitaliano at gmail.com
Sun Jun 21 09:38:26 PDT 2015


REPOSITORY
  rL LLVM

http://reviews.llvm.org/D10508

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

Index: cfe/trunk/lib/CodeGen/CGClass.cpp
===================================================================
--- cfe/trunk/lib/CodeGen/CGClass.cpp
+++ cfe/trunk/lib/CodeGen/CGClass.cpp
@@ -1297,6 +1297,10 @@
   if (BaseClassDecl->hasTrivialDestructor())
     return true;
 
+  // Give up if the destructor is not accessible.
+  if (!BaseClassDecl->getDestructor())
+    return false;
+
   if (!BaseClassDecl->getDestructor()->hasTrivialBody())
     return false;
 
Index: cfe/trunk/test/CodeGenCXX/destructor-crash.cpp
===================================================================
--- cfe/trunk/test/CodeGenCXX/destructor-crash.cpp
+++ cfe/trunk/test/CodeGenCXX/destructor-crash.cpp
@@ -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 {}

EMAIL PREFERENCES
  http://reviews.llvm.org/settings/panel/emailpreferences/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D10508.28090.patch
Type: text/x-patch
Size: 898 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20150621/a25c24e0/attachment.bin>


More information about the cfe-commits mailing list