[cfe-commits] r152372 - in /cfe/trunk: lib/CodeGen/CGDecl.cpp lib/CodeGen/CodeGenModule.h test/CodeGenCXX/static-init.cpp
Eli Friedman
eli.friedman at gmail.com
Thu Mar 8 19:27:46 PST 2012
Author: efriedma
Date: Thu Mar 8 21:27:46 2012
New Revision: 152372
URL: http://llvm.org/viewvc/llvm-project?rev=152372&view=rev
Log:
Make sure we update the static local decl address map when we are forced to rebuild a global because of the initializer. <rdar://problem/10957867>.
Modified:
cfe/trunk/lib/CodeGen/CGDecl.cpp
cfe/trunk/lib/CodeGen/CodeGenModule.h
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=152372&r1=152371&r2=152372&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGDecl.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGDecl.cpp Thu Mar 8 21:27:46 2012
@@ -312,7 +312,9 @@
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();
Modified: cfe/trunk/lib/CodeGen/CodeGenModule.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.h?rev=152372&r1=152371&r2=152372&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenModule.h (original)
+++ cfe/trunk/lib/CodeGen/CodeGenModule.h Thu Mar 8 21:27:46 2012
@@ -279,7 +279,7 @@
llvm::StringMap<llvm::Constant*> CFConstantStringMap;
llvm::StringMap<llvm::GlobalVariable*> ConstantStringMap;
- llvm::DenseMap<const Decl*, llvm::Value*> StaticLocalDeclMap;
+ llvm::DenseMap<const Decl*, llvm::Constant *> StaticLocalDeclMap;
llvm::DenseMap<QualType, llvm::Constant *> AtomicSetterHelperFnMap;
llvm::DenseMap<QualType, llvm::Constant *> AtomicGetterHelperFnMap;
@@ -397,12 +397,12 @@
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) {
Modified: cfe/trunk/test/CodeGenCXX/static-init.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/static-init.cpp?rev=152372&r1=152371&r2=152372&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/static-init.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/static-init.cpp Thu Mar 8 21:27:46 2012
@@ -63,3 +63,19 @@
// 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();
+ }
+}
More information about the cfe-commits
mailing list