From ecac409cb0a26fb79ecb0ff15e2e446daa121371 Mon Sep 17 00:00:00 2001 From: Anders Carlsson Date: Fri, 5 Feb 2010 05:19:42 +0000 Subject: If a global initializer has a non-trivial destructor it can't be emitted as a constant (even if it has a trivial constructor). llvm-svn: 95363 --- clang/lib/CodeGen/CGExprConstant.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'clang/lib/CodeGen/CGExprConstant.cpp') diff --git a/clang/lib/CodeGen/CGExprConstant.cpp b/clang/lib/CodeGen/CGExprConstant.cpp index a358b54fa3c6..436c41723d7f 100644 --- a/clang/lib/CodeGen/CGExprConstant.cpp +++ b/clang/lib/CodeGen/CGExprConstant.cpp @@ -675,9 +675,18 @@ public: if (!E->getConstructor()->isTrivial()) return 0; + QualType Ty = E->getType(); + + const CXXRecordDecl *RD = + cast(Ty->getAs()->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"); -- cgit v1.2.3