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

Davide Italiano dccitaliano at gmail.com
Wed Jun 17 14:33:27 PDT 2015


Test the right condition, add a comment && a test.


http://reviews.llvm.org/D10508

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

Index: lib/CodeGen/CGClass.cpp
===================================================================
--- lib/CodeGen/CGClass.cpp
+++ lib/CodeGen/CGClass.cpp
@@ -1293,6 +1293,10 @@
                          const CXXRecordDecl *BaseClassDecl,
                          const CXXRecordDecl *MostDerivedClassDecl)
 {
+  // Give up if the destructor is not accessible.
+  if (!BaseClassDecl->getDestructor())
+    return false;
+
   // If the destructor is trivial we don't have to check anything else.
   if (BaseClassDecl->hasTrivialDestructor())
     return true;
Index: test/CodeGenCXX/destructor-crash.cpp
===================================================================
--- test/CodeGenCXX/destructor-crash.cpp
+++ 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.27872.patch
Type: text/x-patch
Size: 964 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20150617/4e077562/attachment.bin>


More information about the cfe-commits mailing list