]> granicus.if.org Git - clang/commitdiff
Make sure we update the static local decl address map when we are forced to rebuild...
authorEli Friedman <eli.friedman@gmail.com>
Fri, 9 Mar 2012 03:27:46 +0000 (03:27 +0000)
committerEli Friedman <eli.friedman@gmail.com>
Fri, 9 Mar 2012 03:27:46 +0000 (03:27 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@152372 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CGDecl.cpp
lib/CodeGen/CodeGenModule.h
test/CodeGenCXX/static-init.cpp

index fcea927c63ada05eacaf9f9d60ba51d8f2b46f6a..06a3343bc259014c2e683c07ec8fa757855cef32 100644 (file)
@@ -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();
index d6983ce782237f8729360ead186a665fe6d43674..be0727eaeeb7c34e80b445c9630663d1e268ee5f 100644 (file)
@@ -279,7 +279,7 @@ class CodeGenModule : public CodeGenTypeCache {
 
   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 @@ 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) {
index 2db54c2c8b518056d109630f3ca664acec595742..a96cb7ac8e02a5664f33486b640a7dc4a014fb7a 100644 (file)
@@ -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();
+  }
+}