Add a verifier assertion
authorChris Lattner <sabre@nondot.org>
Wed, 15 Dec 2004 20:23:49 +0000 (20:23 +0000)
committerChris Lattner <sabre@nondot.org>
Wed, 15 Dec 2004 20:23:49 +0000 (20:23 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@18965 91177308-0d34-0410-b5e6-96231b3b80d8

lib/VMCore/Verifier.cpp

index 4653ef89551f5941bc27707adf6fad93aadc4567..0998720a4a7d2a095d78ad26b47920367845c118 100644 (file)
@@ -128,7 +128,7 @@ namespace {  // Anonymous namespace for class
       }
 
       for (Module::giterator I = M.gbegin(), E = M.gend(); I != E; ++I)
-        visitGlobalValue(*I);
+        visitGlobalVariable(*I);
 
       // If the module is broken, abort at this time.
       abortIfBroken();
@@ -171,6 +171,7 @@ namespace {  // Anonymous namespace for class
     // Verification methods...
     void verifySymbolTable(SymbolTable &ST);
     void visitGlobalValue(GlobalValue &GV);
+    void visitGlobalVariable(GlobalVariable &GV);
     void visitFunction(Function &F);
     void visitBasicBlock(BasicBlock &BB);
     void visitPHINode(PHINode &PN);
@@ -262,6 +263,16 @@ void Verifier::visitGlobalValue(GlobalValue &GV) {
   }
 }
 
+void Verifier::visitGlobalVariable(GlobalVariable &GV) {
+  if (GV.hasInitializer()) 
+    Assert1(GV.getInitializer()->getType() == GV.getType()->getElementType(),
+            "Global variable initializer type does not match global "
+            "variable type!", &GV);
+  
+  visitGlobalValue(GV);
+}
+
+
 // verifySymbolTable - Verify that a function or module symbol table is ok
 //
 void Verifier::verifySymbolTable(SymbolTable &ST) {