[cfe-commits] r65472 - in /cfe/trunk: lib/CodeGen/CGDecl.cpp test/CodeGen/const-init.c

Daniel Dunbar daniel at zuster.org
Wed Feb 25 12:08:34 PST 2009


Author: ddunbar
Date: Wed Feb 25 14:08:33 2009
New Revision: 65472

URL: http://llvm.org/viewvc/llvm-project?rev=65472&view=rev
Log:
Allow constant initializers to reference their defining decl.
 - PR3662.

Modified:
    cfe/trunk/lib/CodeGen/CGDecl.cpp
    cfe/trunk/test/CodeGen/const-init.c

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

==============================================================================
--- cfe/trunk/lib/CodeGen/CGDecl.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGDecl.cpp Wed Feb 25 14:08:33 2009
@@ -106,6 +106,10 @@
   llvm::GlobalVariable *GV = 
     CreateStaticBlockVarDecl(D, ".", llvm::GlobalValue::InternalLinkage);
 
+  // Store into LocalDeclMap before generating initializer to handle
+  // circular references.
+  DMEntry = GV;
+
   if (D.getInit()) {
     llvm::Constant *Init = CGM.EmitConstantExpr(D.getInit(), this);
 
@@ -162,6 +166,11 @@
   if (D.getAttr<UsedAttr>())
     CGM.AddUsedGlobal(GV);
 
+  // We may have to cast the constant because of the initializer
+  // mismatch above.
+  //
+  // FIXME: It is really dangerous to store this in the map; if anyone
+  // RAUW's the GV uses of this constant will be invalid.
   const llvm::Type *LTy = CGM.getTypes().ConvertTypeForMem(D.getType());
   const llvm::Type *LPtrTy =
     llvm::PointerType::get(LTy, D.getType().getAddressSpace());

Modified: cfe/trunk/test/CodeGen/const-init.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/const-init.c?rev=65472&r1=65471&r2=65472&view=diff

==============================================================================
--- cfe/trunk/test/CodeGen/const-init.c (original)
+++ cfe/trunk/test/CodeGen/const-init.c Wed Feb 25 14:08:33 2009
@@ -85,4 +85,15 @@
   static int *p[] = { &g19 };
 }
 
+// RUN: grep '@g20.l0 = internal global .struct.g20_s1 <{ .struct.g20_s0\* null, .struct.g20_s0\*\* getelementptr (.struct.g20_s1\* @g20.l0, i32 0, i32 0) }>'  %t &&
+
+struct g20_s0;
+struct g20_s1 {
+  struct g20_s0 *f0, **f1;
+};
+void *g20(void) {
+  static struct g20_s1 l0 = { ((void*) 0), &l0.f0 };
+  return l0.f1;
+}
+
 // RUN: true





More information about the cfe-commits mailing list