diff options
author | Chris Lattner <sabre@nondot.org> | 2009-12-05 06:49:57 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2009-12-05 06:49:57 +0000 |
commit | ff933b709777ce535efb455a10dd487de5694998 (patch) | |
tree | b574a0326232e62fc475fe7eb089e7d6d89d77a5 /lib/CodeGen/CGDecl.cpp | |
parent | 02dd4b1e279114cc51422fab8b42a7759421800e (diff) |
simplify a condition and add a testcase.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@90652 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/CGDecl.cpp')
-rw-r--r-- | lib/CodeGen/CGDecl.cpp | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/lib/CodeGen/CGDecl.cpp b/lib/CodeGen/CGDecl.cpp index abb391af5d..0950d916f7 100644 --- a/lib/CodeGen/CGDecl.cpp +++ b/lib/CodeGen/CGDecl.cpp @@ -323,14 +323,16 @@ void CodeGenFunction::EmitLocalBlockVarDecl(const VarDecl &D) { if (Ty->isConstantSizeType()) { if (!Target.useGlobalsForAutomaticVariables()) { - // All constant structs and arrays should be global if - // their initializer is constant and if the element type is POD. - if (CGM.getCodeGenOpts().MergeAllConstants) { - if (Ty.isConstant(getContext()) - && (Ty->isArrayType() || Ty->isRecordType()) - && (D.getInit() - && D.getInit()->isConstantInitializer(getContext())) - && Ty->isPODType()) { + // If this value is an array or struct, is POD, and if the initializer is + // a staticly determinable constant, try to optimize it. + if (D.getInit() && + (Ty->isArrayType() || Ty->isRecordType()) && + Ty->isPODType() && + D.getInit()->isConstantInitializer(getContext())) { + + // If this variable is marked 'const', emit the value as a global. + if (CGM.getCodeGenOpts().MergeAllConstants && + Ty.isConstant(getContext())) { EmitStaticBlockVarDecl(D); return; } |