summaryrefslogtreecommitdiffstats
path: root/clang/lib/CodeGen
diff options
context:
space:
mode:
authorKristina Brooks <kristina@nym.hush.com>2018-11-12 01:19:16 +0000
committerKristina Brooks <kristina@nym.hush.com>2018-11-12 01:19:16 +0000
commit7349d90b74c88ea9910978f862c622168e357132 (patch)
tree406a74604af4007a582fcdacd91e63726d64bbfa /clang/lib/CodeGen
parent4f9b4700299f108ac960e4f6b16d69e96f50d12f (diff)
downloadbcm5719-llvm-7349d90b74c88ea9910978f862c622168e357132.tar.gz
bcm5719-llvm-7349d90b74c88ea9910978f862c622168e357132.zip
[CodeGen][CXX]: Fix no_destroy CG bug under specific circumstances
Summary: Class with no user-defined destructor that has an inherited member that has a non-trivial destructor and a non-default constructor will attempt to emit a destructor despite being marked as __attribute((no_destroy)) in which case it would trigger an assertion due to an incorrect assumption. In addition this adds missing test coverage for IR generation for no_destroy. (Note that here use of no_destroy is synonymous with its global flag counterpart `-fno-c++-static-destructors` being enabled) Differential Revision: https://reviews.llvm.org/D54344 llvm-svn: 346628
Diffstat (limited to 'clang/lib/CodeGen')
-rw-r--r--clang/lib/CodeGen/CGDeclCXX.cpp9
1 files changed, 9 insertions, 0 deletions
diff --git a/clang/lib/CodeGen/CGDeclCXX.cpp b/clang/lib/CodeGen/CGDeclCXX.cpp
index 4a025c27652..2884f138719 100644
--- a/clang/lib/CodeGen/CGDeclCXX.cpp
+++ b/clang/lib/CodeGen/CGDeclCXX.cpp
@@ -64,6 +64,15 @@ static void EmitDeclInit(CodeGenFunction &CGF, const VarDecl &D,
/// static storage duration.
static void EmitDeclDestroy(CodeGenFunction &CGF, const VarDecl &D,
ConstantAddress Addr) {
+ // Honor __attribute__((no_destroy)) and bail instead of attempting
+ // to emit a reference to a possibly nonexistent destructor, which
+ // in turn can cause a crash. This will result in a global constructor
+ // that isn't balanced out by a destructor call as intended by the
+ // attribute. This also checks for -fno-c++-static-destructors and
+ // bails even if the attribute is not present.
+ if (D.isNoDestroy(CGF.getContext()))
+ return;
+
CodeGenModule &CGM = CGF.CGM;
// FIXME: __attribute__((cleanup)) ?
OpenPOWER on IntegriCloud