]> granicus.if.org Git - clang/commitdiff
Relax an assertion, fixing PR1968
authorChris Lattner <sabre@nondot.org>
Tue, 5 Feb 2008 06:37:34 +0000 (06:37 +0000)
committerChris Lattner <sabre@nondot.org>
Tue, 5 Feb 2008 06:37:34 +0000 (06:37 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@46742 91177308-0d34-0410-b5e6-96231b3b80d8

CodeGen/CodeGenModule.cpp
test/CodeGen/globalinit.c

index 382f651272f8010e6d48299eda9de00aae715493..9de5d3426f0b252d0314227deddd50d91d0bfa4b 100644 (file)
@@ -123,6 +123,12 @@ llvm::Constant *CodeGenModule::GetAddrOfFunctionDecl(const FunctionDecl *D,
   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 @@ llvm::Constant *CodeGenModule::GetAddrOfGlobalVar(const VarDecl *D,
   // 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.
index e880b9a9174fccb86e42ab5a822c5777f7e777e2..a5535b5853ad32f3e8f5e15243d98f8fdcb79348 100644 (file)
@@ -45,3 +45,8 @@ int c[] = { EnumA, EnumB };
 
 // Binary operators
 int d[] = { EnumA | EnumB };
+
+// PR1968
+static int array[];
+static int array[4];
+