aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnders Carlsson <andersca@mac.com>2010-02-05 05:19:42 +0000
committerAnders Carlsson <andersca@mac.com>2010-02-05 05:19:42 +0000
commit7d94a9503c90fd26cd41a5cae3831d79e334526f (patch)
tree554c9536711de8a8f1f77d870c1b1726e01b0e26
parentf5416bdb75832e0a400cf3b19bd2116d2fed9ebe (diff)
If a global initializer has a non-trivial destructor it can't be emitted as a constant (even if it has a trivial constructor).
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@95363 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/CodeGen/CGExprConstant.cpp11
-rw-r--r--test/CodeGenCXX/global-init.cpp5
2 files changed, 15 insertions, 1 deletions
diff --git a/lib/CodeGen/CGExprConstant.cpp b/lib/CodeGen/CGExprConstant.cpp
index a358b54fa3..436c41723d 100644
--- a/lib/CodeGen/CGExprConstant.cpp
+++ b/lib/CodeGen/CGExprConstant.cpp
@@ -675,9 +675,18 @@ public:
if (!E->getConstructor()->isTrivial())
return 0;
+ QualType Ty = E->getType();
+
+ const CXXRecordDecl *RD =
+ cast<CXXRecordDecl>(Ty->getAs<RecordType>()->getDecl());
+
+ // If the class doesn't have a trivial destructor, we can't emit it as a
+ // constant expr.
+ if (!RD->hasTrivialDestructor())
+ return 0;
+
// Only copy and default constructors can be trivial.
- QualType Ty = E->getType();
if (E->getNumArgs()) {
assert(E->getNumArgs() == 1 && "trivial ctor with > 1 argument");
diff --git a/test/CodeGenCXX/global-init.cpp b/test/CodeGenCXX/global-init.cpp
index fd8c159755..b60e056d70 100644
--- a/test/CodeGenCXX/global-init.cpp
+++ b/test/CodeGenCXX/global-init.cpp
@@ -9,6 +9,8 @@ struct B { B(); ~B(); };
struct C { void *field; };
+struct D { ~D(); };
+
// CHECK: @c = global %struct.C zeroinitializer, align 8
// CHECK: call void @_ZN1AC1Ev(%struct.A* @a)
@@ -23,4 +25,7 @@ B b;
// CHECK-NOT: call void @_ZN1CC1Ev(%struct.C* @c)
C c;
+// CHECK: call i32 @__cxa_atexit(void (i8*)* bitcast (void (%struct.A*)* @_ZN1DD1Ev to void (i8*)*), i8* getelementptr inbounds (%struct.A* @d, i32 0, i32 0), i8* bitcast (i8** @__dso_handle to i8*))
+D d;
+
// CHECK: define internal void @__cxx_global_initialization() {