From d0c4792ca6bde9d60002760c10eb605ed2eebde8 Mon Sep 17 00:00:00 2001 From: Anders Carlsson Date: Tue, 26 Jan 2010 06:15:16 +0000 Subject: [PATCH] If a global variable has an initializer with side effects, it can never be deferred (even if it's in an anonymous namespace). git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@94525 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/CodeGenModule.cpp | 5 ++--- test/CodeGenCXX/anonymous-namespaces.cpp | 16 ++++++++++++++++ 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/lib/CodeGen/CodeGenModule.cpp b/lib/CodeGen/CodeGenModule.cpp index cf504a7c2a..65b29313c6 100644 --- a/lib/CodeGen/CodeGenModule.cpp +++ b/lib/CodeGen/CodeGenModule.cpp @@ -580,9 +580,8 @@ bool CodeGenModule::MayDeferGeneration(const ValueDecl *Global) { // Static data may be deferred, but out-of-line static data members // cannot be. - if (VD->isInAnonymousNamespace()) - return true; - if (VD->getLinkage() == VarDecl::InternalLinkage) { + if (VD->getLinkage() == VarDecl::InternalLinkage || + VD->isInAnonymousNamespace()) { // Initializer has side effects? if (VD->getInit() && VD->getInit()->HasSideEffects(Context)) return false; diff --git a/test/CodeGenCXX/anonymous-namespaces.cpp b/test/CodeGenCXX/anonymous-namespaces.cpp index 7689c941e1..695f8f59de 100644 --- a/test/CodeGenCXX/anonymous-namespaces.cpp +++ b/test/CodeGenCXX/anonymous-namespaces.cpp @@ -1,9 +1,25 @@ // RUN: %clang_cc1 -emit-llvm %s -o - | FileCheck %s + +int f(); + namespace { + // CHECK: @_ZN12_GLOBAL__N_11bE = internal global i32 0 + // CHECK: @_ZN12_GLOBAL__N_1L1cE = internal global i32 0 + // CHECK: @_ZN12_GLOBAL__N_11D1dE = internal global i32 0 // CHECK: @_ZN12_GLOBAL__N_11aE = internal global i32 0 int a = 0; + int b = f(); + + static int c = f(); + + class D { + static int d; + }; + + int D::d = f(); + // CHECK: define internal i32 @_ZN12_GLOBAL__N_13fooEv() int foo() { return 32; -- 2.50.1