[PATCH] [Clang/CodeGen] Prevent crash if destructor class is not accessible (Part two)

Davide Italiano dccitaliano at gmail.com
Mon Jun 22 18:44:55 PDT 2015


Hi rsmith, rjmccall,

Phab doesn't allow me to reopen closed review or upload a new diff to a closed review. Anyhow.
This changes the code as Richard proposed. Thank you both for the time spent on this.

http://reviews.llvm.org/D10626

Files:
  lib/CodeGen/CGClass.cpp

Index: lib/CodeGen/CGClass.cpp
===================================================================
--- lib/CodeGen/CGClass.cpp
+++ lib/CodeGen/CGClass.cpp
@@ -1297,10 +1297,6 @@
   if (BaseClassDecl->hasTrivialDestructor())
     return true;
 
-  // Give up if the destructor is not accessible.
-  if (!BaseClassDecl->getDestructor())
-    return false;
-
   if (!BaseClassDecl->getDestructor()->hasTrivialBody())
     return false;
 
@@ -1346,6 +1342,11 @@
     return true;
 
   CXXRecordDecl *FieldClassDecl = cast<CXXRecordDecl>(RT->getDecl());
+
+  // The destructor for an implicit anonymous union member is never invoked.
+  if (FieldClassDecl->isUnion() && FieldClassDecl->isAnonymousStructOrUnion())
+    return false;
+
   return HasTrivialDestructorBody(Context, FieldClassDecl, FieldClassDecl);
 }

EMAIL PREFERENCES
  http://reviews.llvm.org/settings/panel/emailpreferences/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D10626.28186.patch
Type: text/x-patch
Size: 812 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20150623/5263d3a8/attachment.bin>


More information about the cfe-commits mailing list