]> granicus.if.org Git - clang/commitdiff
simplify a condition and add a testcase.
authorChris Lattner <sabre@nondot.org>
Sat, 5 Dec 2009 06:49:57 +0000 (06:49 +0000)
committerChris Lattner <sabre@nondot.org>
Sat, 5 Dec 2009 06:49:57 +0000 (06:49 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@90652 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CGDecl.cpp
test/CodeGen/decl.c [new file with mode: 0644]

index abb391af5d68259cd160edc68a069aab3846f754..0950d916f7a8612f90424a29d205cf46033f646c 100644 (file)
@@ -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;
         }
diff --git a/test/CodeGen/decl.c b/test/CodeGen/decl.c
new file mode 100644 (file)
index 0000000..e2d55ec
--- /dev/null
@@ -0,0 +1,12 @@
+// RUN: clang-cc -emit-llvm < %s | FileCheck %s
+
+// CHECK: @test1.x = internal constant [12 x i32] [i32 1
+
+void test1() {
+  // This should codegen as a "@test1.x" global.
+  const int x[] = { 1, 2, 3, 4, 6, 8, 9, 10, 123, 231, 123,23 };
+  foo(x);
+
+// CHECK: @test1()
+// CHECK: {{call.*@foo.*@test1.x}}
+}