[cfe-commits] r94504 - in /cfe/trunk: lib/CodeGen/CGDecl.cpp test/CodeGenCXX/static-init.cpp
Anders Carlsson
andersca at mac.com
Mon Jan 25 20:02:23 PST 2010
Author: andersca
Date: Mon Jan 25 22:02:23 2010
New Revision: 94504
URL: http://llvm.org/viewvc/llvm-project?rev=94504&view=rev
Log:
Make sure to always mark a global variable as not being constant if it has a C++ initializer.
Modified:
cfe/trunk/lib/CodeGen/CGDecl.cpp
cfe/trunk/test/CodeGenCXX/static-init.cpp
Modified: cfe/trunk/lib/CodeGen/CGDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDecl.cpp?rev=94504&r1=94503&r2=94504&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGDecl.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGDecl.cpp Mon Jan 25 22:02:23 2010
@@ -138,8 +138,13 @@
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;
}
Modified: cfe/trunk/test/CodeGenCXX/static-init.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/static-init.cpp?rev=94504&r1=94503&r2=94504&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/static-init.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/static-init.cpp Mon Jan 25 22:02:23 2010
@@ -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 @@
// CHECK: call void @_ZN1AC1Ev(
static A& a = *new A;
}
+
+int a();
+void h() {
+ static const int i = a();
+}
More information about the cfe-commits
mailing list