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");
struct C { void *field; };
+struct D { ~D(); };
+
// CHECK: @c = global %struct.C zeroinitializer, align 8
// CHECK: call void @_ZN1AC1Ev(%struct.A* @a)
// 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() {