diff options
author | Richard Smith <richard-llvm@metafoo.co.uk> | 2012-11-12 21:38:00 +0000 |
---|---|---|
committer | Richard Smith <richard-llvm@metafoo.co.uk> | 2012-11-12 21:38:00 +0000 |
commit | 5f9a7e31d038843f1d3a5e2544fc365ffd563951 (patch) | |
tree | 45e9647cfe64696b36292ae896b90488f3dd0526 /lib/AST/ASTContext.cpp | |
parent | 5af8de8c7255ca4df52cbb0d5e0d28d67c53524c (diff) |
Remove abuse of hasTrivial*, and fix miscompile wherein global arrays with
internal linkage, no uses, trivial construction, and nontrivial destruction
were not emitted.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@167756 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/AST/ASTContext.cpp')
-rw-r--r-- | lib/AST/ASTContext.cpp | 31 |
1 files changed, 12 insertions, 19 deletions
diff --git a/lib/AST/ASTContext.cpp b/lib/AST/ASTContext.cpp index 2f7288109c..577dd0adaf 100644 --- a/lib/AST/ASTContext.cpp +++ b/lib/AST/ASTContext.cpp @@ -7446,27 +7446,20 @@ bool ASTContext::DeclMustBeEmitted(const Decl *D) { if (VD->isThisDeclarationADefinition() == VarDecl::DeclarationOnly) return false; - // Structs that have non-trivial constructors or destructors are required. - - // FIXME: Handle references. - // FIXME: Be more selective about which constructors we care about. - if (const RecordType *RT = VD->getType()->getAs<RecordType>()) { - if (const CXXRecordDecl *RD = dyn_cast<CXXRecordDecl>(RT->getDecl())) { - if (RD->hasDefinition() && !(RD->hasTrivialDefaultConstructor() && - RD->hasTrivialCopyConstructor() && - RD->hasTrivialMoveConstructor() && - RD->hasTrivialDestructor())) - return true; - } - } - + // Variables that can be needed in other TUs are required. GVALinkage L = GetGVALinkageForVariable(VD); - if (L == GVA_Internal || L == GVA_TemplateInstantiation) { - if (!(VD->getInit() && VD->getInit()->HasSideEffects(*this))) - return false; - } + if (L != GVA_Internal && L != GVA_TemplateInstantiation) + return true; - return true; + // Variables that have destruction with side-effects are required. + if (VD->getType().isDestructedType()) + return true; + + // Variables that have initialization with side-effects are required. + if (VD->getInit() && VD->getInit()->HasSideEffects(*this)) + return true; + + return false; } CallingConv ASTContext::getDefaultCXXMethodCallConv(bool isVariadic) { |