From: Eli Friedman Date: Fri, 9 Mar 2012 03:27:46 +0000 (+0000) Subject: Make sure we update the static local decl address map when we are forced to rebuild... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=71cba34b6e2d3fb81860bd2176ab7003eaf2e918;p=clang Make sure we update the static local decl address map when we are forced to rebuild a global because of the initializer. . git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@152372 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/CodeGen/CGDecl.cpp b/lib/CodeGen/CGDecl.cpp index fcea927c63..06a3343bc2 100644 --- a/lib/CodeGen/CGDecl.cpp +++ b/lib/CodeGen/CGDecl.cpp @@ -312,7 +312,9 @@ void CodeGenFunction::EmitStaticVarDecl(const VarDecl &D, llvm::Type *LTy = CGM.getTypes().ConvertTypeForMem(D.getType()); llvm::Type *LPtrTy = LTy->getPointerTo(CGM.getContext().getTargetAddressSpace(D.getType())); - DMEntry = llvm::ConstantExpr::getBitCast(GV, LPtrTy); + llvm::Constant *CastedVal = llvm::ConstantExpr::getBitCast(GV, LPtrTy); + DMEntry = CastedVal; + CGM.setStaticLocalDeclAddress(&D, CastedVal); // Emit global variable debug descriptor for static vars. CGDebugInfo *DI = getDebugInfo(); diff --git a/lib/CodeGen/CodeGenModule.h b/lib/CodeGen/CodeGenModule.h index d6983ce782..be0727eaee 100644 --- a/lib/CodeGen/CodeGenModule.h +++ b/lib/CodeGen/CodeGenModule.h @@ -279,7 +279,7 @@ class CodeGenModule : public CodeGenTypeCache { llvm::StringMap CFConstantStringMap; llvm::StringMap ConstantStringMap; - llvm::DenseMap StaticLocalDeclMap; + llvm::DenseMap StaticLocalDeclMap; llvm::DenseMap AtomicSetterHelperFnMap; llvm::DenseMap AtomicGetterHelperFnMap; @@ -397,12 +397,12 @@ public: return *RRData; } - llvm::Value *getStaticLocalDeclAddress(const VarDecl *VD) { - return StaticLocalDeclMap[VD]; + llvm::Constant *getStaticLocalDeclAddress(const VarDecl *D) { + return StaticLocalDeclMap[D]; } void setStaticLocalDeclAddress(const VarDecl *D, - llvm::GlobalVariable *GV) { - StaticLocalDeclMap[D] = GV; + llvm::Constant *C) { + StaticLocalDeclMap[D] = C; } llvm::Constant *getAtomicSetterHelperFnMap(QualType Ty) { diff --git a/test/CodeGenCXX/static-init.cpp b/test/CodeGenCXX/static-init.cpp index 2db54c2c8b..a96cb7ac8e 100644 --- a/test/CodeGenCXX/static-init.cpp +++ b/test/CodeGenCXX/static-init.cpp @@ -63,3 +63,19 @@ namespace test1 { // Make sure we emit the initializer correctly for the following: char base_req[] = { "foo" }; + +namespace union_static_local { + // CHECK: define internal void @_ZZN18union_static_local4testEvEN1c4mainEv + // CHECK: call void @_ZN18union_static_local1fEPNS_1xE(%"union.union_static_local::x"* bitcast ({ [2 x i8*] }* @_ZZN18union_static_local4testEvE3foo to %"union.union_static_local::x"*)) + union x { long double y; const char *x[2]; }; + void f(union x*); + void test() { + static union x foo = { .x = { "a", "b" } }; + struct c { + static void main() { + f(&foo); + } + }; + c::main(); + } +}