[cfe-commits] r46742 - in /cfe/trunk: CodeGen/CodeGenModule.cpp test/CodeGen/globalinit.c

Chris Lattner sabre at nondot.org
Mon Feb 4 22:37:35 PST 2008


Author: lattner
Date: Tue Feb  5 00:37:34 2008
New Revision: 46742

URL: http://llvm.org/viewvc/llvm-project?rev=46742&view=rev
Log:
Relax an assertion, fixing PR1968

Modified:
    cfe/trunk/CodeGen/CodeGenModule.cpp
    cfe/trunk/test/CodeGen/globalinit.c

Modified: cfe/trunk/CodeGen/CodeGenModule.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/CodeGen/CodeGenModule.cpp?rev=46742&r1=46741&r2=46742&view=diff

==============================================================================
--- cfe/trunk/CodeGen/CodeGenModule.cpp (original)
+++ cfe/trunk/CodeGen/CodeGenModule.cpp Tue Feb  5 00:37:34 2008
@@ -123,6 +123,12 @@
   return Entry = NewFn;
 }
 
+static bool IsZeroElementArray(const llvm::Type *Ty) {
+  if (const llvm::ArrayType *ATy = dyn_cast<llvm::ArrayType>(Ty))
+    return ATy->getNumElements() == 0;
+  return false;
+}
+
 llvm::Constant *CodeGenModule::GetAddrOfGlobalVar(const VarDecl *D,
                                                   bool isDefinition) {
   assert(D->hasGlobalStorage() && "Not a global variable");
@@ -178,8 +184,13 @@
   // is incredibly slow!
   ReplaceMapValuesWith(GV, NewPtrForOldDecl);
   
+  // Verify that GV was a declaration or something like x[] which turns into
+  // [0 x type].
+  assert((GV->isDeclaration() || 
+          IsZeroElementArray(GV->getType()->getElementType())) &&
+         "Shouldn't replace non-declaration");
+         
   // Ok, delete the old global now, which is dead.
-  assert(GV->isDeclaration() && "Shouldn't replace non-declaration");
   GV->eraseFromParent();
   
   // Return the new global which has the right type.

Modified: cfe/trunk/test/CodeGen/globalinit.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/globalinit.c?rev=46742&r1=46741&r2=46742&view=diff

==============================================================================
--- cfe/trunk/test/CodeGen/globalinit.c (original)
+++ cfe/trunk/test/CodeGen/globalinit.c Tue Feb  5 00:37:34 2008
@@ -45,3 +45,8 @@
 
 // Binary operators
 int d[] = { EnumA | EnumB };
+
+// PR1968
+static int array[];
+static int array[4];
+





More information about the cfe-commits mailing list