diff options
| author | Anders Carlsson <andersca@mac.com> | 2010-01-26 06:15:16 +0000 |
|---|---|---|
| committer | Anders Carlsson <andersca@mac.com> | 2010-01-26 06:15:16 +0000 |
| commit | d6b21e484241adc5d56770360806e52d073bb351 (patch) | |
| tree | 558870d5cc196eb760af280c201cf2ea0ca340b5 | |
| parent | 91f61fc921e4abcaeb4a85b4e52f1db0cbdf2468 (diff) | |
| download | bcm5719-llvm-d6b21e484241adc5d56770360806e52d073bb351.tar.gz bcm5719-llvm-d6b21e484241adc5d56770360806e52d073bb351.zip | |
If a global variable has an initializer with side effects, it can never be deferred (even if it's in an anonymous namespace).
llvm-svn: 94525
| -rw-r--r-- | clang/lib/CodeGen/CodeGenModule.cpp | 5 | ||||
| -rw-r--r-- | clang/test/CodeGenCXX/anonymous-namespaces.cpp | 16 |
2 files changed, 18 insertions, 3 deletions
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp index cf504a7c2a0..65b29313c60 100644 --- a/clang/lib/CodeGen/CodeGenModule.cpp +++ b/clang/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/clang/test/CodeGenCXX/anonymous-namespaces.cpp b/clang/test/CodeGenCXX/anonymous-namespaces.cpp index 7689c941e10..695f8f59def 100644 --- a/clang/test/CodeGenCXX/anonymous-namespaces.cpp +++ b/clang/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; |

