r240742 - [Sema] Commit a better fix for r240242

Davide Italiano davide at freebsd.org
Thu Jun 25 17:18:35 PDT 2015


Author: davide
Date: Thu Jun 25 19:18:35 2015
New Revision: 240742

URL: http://llvm.org/viewvc/llvm-project?rev=240742&view=rev
Log:
[Sema] Commit a better fix for r240242

Skip calls to HasTrivialDestructorBody() in the case where the
destructor is never invoked. Alternatively, Richard proposed to change
Sema to declare a trivial destructor for anonymous union member, which
seems too wasteful.

Differential Revision:	http://reviews.llvm.org/D10508

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=240742&r1=240741&r2=240742&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGClass.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGClass.cpp Thu Jun 25 19:18:35 2015
@@ -1294,10 +1294,6 @@ 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;
 
@@ -1343,6 +1339,11 @@ FieldHasTrivialDestructorBody(ASTContext
     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);
 }
 





More information about the cfe-commits mailing list