From 982bbf404eba2d968afda5c674d4821652159c53 Mon Sep 17 00:00:00 2001 From: Davide Italiano Date: Fri, 26 Jun 2015 00:18:35 +0000 Subject: [PATCH] [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 llvm-svn: 240742 --- clang/lib/CodeGen/CGClass.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/clang/lib/CodeGen/CGClass.cpp b/clang/lib/CodeGen/CGClass.cpp index 6538351edf22..62df9820a6c3 100644 --- a/clang/lib/CodeGen/CGClass.cpp +++ b/clang/lib/CodeGen/CGClass.cpp @@ -1294,10 +1294,6 @@ HasTrivialDestructorBody(ASTContext &Context, 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 &Context, return true; CXXRecordDecl *FieldClassDecl = cast(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); }