]> granicus.if.org Git - clang/commitdiff
Make sure to always mark a global variable as not being constant if it has a C++...
authorAnders Carlsson <andersca@mac.com>
Tue, 26 Jan 2010 04:02:23 +0000 (04:02 +0000)
committerAnders Carlsson <andersca@mac.com>
Tue, 26 Jan 2010 04:02:23 +0000 (04:02 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@94504 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CGDecl.cpp
test/CodeGenCXX/static-init.cpp

index 9606a71527a4f8f06ddc73ab208f399d07c9caae..23b4ff26a2e18f13bb4f0902dc507ae5d476c06a 100644 (file)
@@ -138,8 +138,13 @@ CodeGenFunction::AddInitializerToGlobalBlockVarDecl(const VarDecl &D,
   if (!Init) {
     if (!getContext().getLangOptions().CPlusPlus)
       CGM.ErrorUnsupported(D.getInit(), "constant l-value expression");
-    else
+    else {
+      // Since we have a static initializer, this global variable can't 
+      // be constant.
+      GV->setConstant(false);
+      
       EmitStaticCXXBlockVarDeclInit(D, GV);
+    }
     return GV;
   }
   
index cbd90e7894069b919ace21dd80d698a56fd94a1f..33d92d6853692c86c914e37f24e06c429b3385d1 100644 (file)
@@ -1,4 +1,6 @@
 // RUN: %clang_cc1 %s -triple=x86_64-apple-darwin10 -emit-llvm -o - | FileCheck %s
+
+// CHECK: @_ZZ1hvE1i = internal global i32 0, align 4
 struct A {
   A();
   ~A();
@@ -15,3 +17,8 @@ void g() {
   // CHECK: call void @_ZN1AC1Ev(
   static A& a = *new A;
 }
+
+int a();
+void h() {
+  static const int i = a();
+}