diff options
author | John McCall <rjmccall@apple.com> | 2010-02-02 08:02:49 +0000 |
---|---|---|
committer | John McCall <rjmccall@apple.com> | 2010-02-02 08:02:49 +0000 |
commit | fb8b69aef3377aaa786d1278aaae7e7b04ac095f (patch) | |
tree | 39d41f571f9024781d92428c981d0a06474684c9 /lib/CodeGen/CGExprConstant.cpp | |
parent | 2e13db8bc64bc99922b0aeb45443c681c1643c82 (diff) |
Codegen CXXConstructExprs with trivial constructors as constants.
Eliminates a lot of spurious global initializers, fixing PR6205.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@95077 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/CGExprConstant.cpp')
-rw-r--r-- | lib/CodeGen/CGExprConstant.cpp | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/lib/CodeGen/CGExprConstant.cpp b/lib/CodeGen/CGExprConstant.cpp index d843d023f7..f4dd8dc337 100644 --- a/lib/CodeGen/CGExprConstant.cpp +++ b/lib/CodeGen/CGExprConstant.cpp @@ -668,6 +668,29 @@ public: return 0; } + llvm::Constant *VisitCXXConstructExpr(CXXConstructExpr *E) { + if (!E->getConstructor()->isTrivial()) + 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"); + assert(E->getConstructor()->isCopyConstructor() && + "trivial ctor has argument but isn't a copy ctor"); + + Expr *Arg = E->getArg(0); + assert(CGM.getContext().hasSameUnqualifiedType(Ty, Arg->getType()) && + "argument to copy ctor is of wrong type"); + + return Visit(E->getArg(0)); + } + + return CGM.EmitNullConstant(Ty); + } + llvm::Constant *VisitStringLiteral(StringLiteral *E) { assert(!E->getType()->isPointerType() && "Strings are always arrays"); |