diff options
author | Richard Smith <richard-llvm@metafoo.co.uk> | 2013-06-14 03:07:01 +0000 |
---|---|---|
committer | Richard Smith <richard-llvm@metafoo.co.uk> | 2013-06-14 03:07:01 +0000 |
commit | a509f2fdfa8ffb4ce9edaee84daca44bcb07ee78 (patch) | |
tree | a4443f45f9d76e9fbc4dd2543d6f023e49eb3f4c /clang/lib/CodeGen/CGExpr.cpp | |
parent | 18db1f2f1a0b05ba97c92f0ef2c4b4be8614ae9b (diff) | |
download | bcm5719-llvm-a509f2fdfa8ffb4ce9edaee84daca44bcb07ee78.tar.gz bcm5719-llvm-a509f2fdfa8ffb4ce9edaee84daca44bcb07ee78.zip |
Emit initializers for static-storage-duration temporaries as constants where
possible.
llvm-svn: 183967
Diffstat (limited to 'clang/lib/CodeGen/CGExpr.cpp')
-rw-r--r-- | clang/lib/CodeGen/CGExpr.cpp | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp index 034525cff67..cbad66c8bc8 100644 --- a/clang/lib/CodeGen/CGExpr.cpp +++ b/clang/lib/CodeGen/CGExpr.cpp @@ -321,6 +321,13 @@ LValue CodeGenFunction::EmitMaterializeTemporaryExpr( llvm::Value *Object = createReferenceTemporary(*this, M, E); LValue RefTempDst = MakeAddrLValue(Object, M->getType()); + if (llvm::GlobalVariable *Var = dyn_cast<llvm::GlobalVariable>(Object)) { + // We should not have emitted the initializer for this temporary as a + // constant. + assert(!Var->hasInitializer()); + Var->setInitializer(CGM.EmitNullConstant(E->getType())); + } + EmitScalarInit(E, M->getExtendingDecl(), RefTempDst, false); pushTemporaryCleanup(*this, M, E, Object); @@ -343,7 +350,16 @@ LValue CodeGenFunction::EmitMaterializeTemporaryExpr( // Create and initialize the reference temporary. llvm::Value *Object = createReferenceTemporary(*this, M, E); - EmitAnyExprToMem(E, Object, Qualifiers(), /*IsInit*/true); + if (llvm::GlobalVariable *Var = dyn_cast<llvm::GlobalVariable>(Object)) { + // If the temporary is a global and has a constant initializer, we may + // have already initialized it. + if (!Var->hasInitializer()) { + Var->setInitializer(CGM.EmitNullConstant(E->getType())); + EmitAnyExprToMem(E, Object, Qualifiers(), /*IsInit*/true); + } + } else { + EmitAnyExprToMem(E, Object, Qualifiers(), /*IsInit*/true); + } pushTemporaryCleanup(*this, M, E, Object); // Perform derived-to-base casts and/or field accesses, to get from the |