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

Davide Italiano dccitaliano at gmail.com
Fri Jun 19 15:14:16 PDT 2015


Reordered checks as suggested.
Anders Carlsson LGTM'd the change. Reid, do you think we can go forward and check this in?


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
@@ -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: 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.28053.patch
Type: text/x-patch
Size: 838 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20150619/cc05e59a/attachment.bin>


More information about the cfe-commits mailing list