From 071c81065a282edba989bcf7c260b5838a59db50 Mon Sep 17 00:00:00 2001 From: Anders Carlsson Date: Tue, 26 Jan 2010 04:02:23 +0000 Subject: [PATCH] Make sure to always mark a global variable as not being constant if it has a C++ initializer. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@94504 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/CGDecl.cpp | 7 ++++++- test/CodeGenCXX/static-init.cpp | 7 +++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/CodeGen/CGDecl.cpp b/lib/CodeGen/CGDecl.cpp index 9606a71527..23b4ff26a2 100644 --- a/lib/CodeGen/CGDecl.cpp +++ b/lib/CodeGen/CGDecl.cpp @@ -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; } diff --git a/test/CodeGenCXX/static-init.cpp b/test/CodeGenCXX/static-init.cpp index cbd90e7894..33d92d6853 100644 --- a/test/CodeGenCXX/static-init.cpp +++ b/test/CodeGenCXX/static-init.cpp @@ -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(); +} -- 2.50.1