[cfe-commits] r52084 - in /cfe/trunk: lib/CodeGen/CGDecl.cpp test/CodeGen/static-local-union.c

Eli Friedman eli.friedman at gmail.com
Sat Jun 7 18:23:18 PDT 2008


Author: efriedma
Date: Sat Jun  7 20:23:18 2008
New Revision: 52084

URL: http://llvm.org/viewvc/llvm-project?rev=52084&view=rev
Log:
Don't crash emitting an initializer for a static local with union type.  
This fix just makes sure to construct the global with the appropriate 
type, and fixes up the one user this affects to compensate.


Added:
    cfe/trunk/test/CodeGen/static-local-union.c
Modified:
    cfe/trunk/lib/CodeGen/CGDecl.cpp

Modified: cfe/trunk/lib/CodeGen/CGDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDecl.cpp?rev=52084&r1=52083&r2=52084&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/CGDecl.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGDecl.cpp Sat Jun  7 20:23:18 2008
@@ -93,8 +93,9 @@
   else
     assert(0 && "Unknown context for block var decl"); // FIXME Handle objc.
 
-  llvm::GlobalValue *GV = 
-    new llvm::GlobalVariable(LTy, false, llvm::GlobalValue::InternalLinkage,
+  llvm::GlobalValue *GV =
+    new llvm::GlobalVariable(Init->getType(), false,
+                             llvm::GlobalValue::InternalLinkage,
                              Init, ContextName + Separator + D.getName(),
                              &CGM.getModule(), 0, Ty.getAddressSpace());
 
@@ -115,7 +116,10 @@
     CGM.AddAnnotation(Ann);
   }
 
-  DMEntry = GV;
+  const llvm::Type *LTy = CGM.getTypes().ConvertTypeForMem(D.getType());
+  const llvm::Type *LPtrTy =
+    llvm::PointerType::get(LTy, D.getType().getAddressSpace());
+  DMEntry = llvm::ConstantExpr::getBitCast(GV, LPtrTy);
 
   // Emit global variable debug descriptor for static vars.
   CGDebugInfo *DI = CGM.getDebugInfo();

Added: cfe/trunk/test/CodeGen/static-local-union.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/static-local-union.c?rev=52084&view=auto

==============================================================================
--- cfe/trunk/test/CodeGen/static-local-union.c (added)
+++ cfe/trunk/test/CodeGen/static-local-union.c Sat Jun  7 20:23:18 2008
@@ -0,0 +1,4 @@
+// RUN: clang -emit-llvm < %s
+
+int a() {static union{int a;} r[2] = {1,2};return r[1].a;}
+





More information about the cfe-commits mailing list