]> granicus.if.org Git - clang/commitdiff
Set constant bit on static block vars as well. Patch by Anders Johnson!q
authorDaniel Dunbar <daniel@zuster.org>
Fri, 13 Feb 2009 22:58:39 +0000 (22:58 +0000)
committerDaniel Dunbar <daniel@zuster.org>
Fri, 13 Feb 2009 22:58:39 +0000 (22:58 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@64502 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CGDecl.cpp
test/CodeGen/init.c

index ddc68d68c5e44304aa022096acab3472cff72f89..bb2705ff60acee6a386bea021b99e11b8210c076 100644 (file)
@@ -109,7 +109,7 @@ CodeGenFunction::GenerateStaticBlockVarDecl(const VarDecl &D,
     assert(0 && "Unknown context for block var decl");
 
   llvm::GlobalValue *GV =
-    new llvm::GlobalVariable(Init->getType(), false,
+    new llvm::GlobalVariable(Init->getType(), Ty.isConstant(getContext()),
                              Linkage,
                              Init, ContextName + Separator +D.getNameAsString(),
                              &CGM.getModule(), 0, Ty.getAddressSpace());
index fa39ba6f5a0af439c2da2bb76d7d4a2c0c4a2e22..b53b81edb8b4650b77d59c46e812465808dbf668 100644 (file)
@@ -1,4 +1,5 @@
-// RUN: clang -emit-llvm %s -o -
+// RUN: clang -triple i386-unknown-unknown -emit-llvm %s -o %t &&
+
 void f1() {
   // Scalars in braces.
   int a = { 1 };
@@ -20,3 +21,11 @@ void f3() {
   struct S a[1] = { { foo } };
 }
 
+// Constants
+// RUN: grep '@g3 = constant i32 10' %t &&
+// RUN: grep '@f4.g4 = internal constant i32 12' %t
+const int g3 = 10;
+int f4() {
+  static const int g4 = 12;
+  return g4;
+}