summaryrefslogtreecommitdiffstats
path: root/lib/VMCore/Verifier.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2002-04-24 19:12:21 +0000
committerChris Lattner <sabre@nondot.org>2002-04-24 19:12:21 +0000
commita00409ea1a1cd99614fa00e5926dc4630dc62b54 (patch)
treeef5e030104568a798be3d1afa16f313bb26ef728 /lib/VMCore/Verifier.cpp
parentefdd0a2c2eaccb6a6d9846faa64bb78e893f295b (diff)
downloadexternal_llvm-a00409ea1a1cd99614fa00e5926dc4630dc62b54.zip
external_llvm-a00409ea1a1cd99614fa00e5926dc4630dc62b54.tar.gz
external_llvm-a00409ea1a1cd99614fa00e5926dc4630dc62b54.tar.bz2
* Abort program on verification errors
* Verify that load, store, and GEP instructions indices are correct, because they _continually_ bite me on this pool allocations stuff git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@2309 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/VMCore/Verifier.cpp')
-rw-r--r--lib/VMCore/Verifier.cpp42
1 files changed, 41 insertions, 1 deletions
diff --git a/lib/VMCore/Verifier.cpp b/lib/VMCore/Verifier.cpp
index a4bbf1d..5c7f98b 100644
--- a/lib/VMCore/Verifier.cpp
+++ b/lib/VMCore/Verifier.cpp
@@ -10,6 +10,7 @@
// with the same name as something in the symbol table, but with a different
// address as what is in the symbol table...
// * Both of a binary operator's parameters are the same type
+// * Verify that the indices of mem access instructions match other operands
// . Verify that arithmetic and other things are only performed on first class
// types. No adding structures or arrays.
// . All of the constants in a switch statement are of the correct type
@@ -29,7 +30,7 @@
// * It is illegal to have a internal function that is just a declaration
// * It is illegal to have a ret instruction that returns a value that does not
// agree with the function return value type.
-// . All other things that are tested by asserts spread about the code...
+// * All other things that are tested by asserts spread about the code...
//
//===----------------------------------------------------------------------===//
@@ -42,6 +43,7 @@
#include "llvm/iPHINode.h"
#include "llvm/iTerminators.h"
#include "llvm/iOther.h"
+#include "llvm/iMemory.h"
#include "llvm/Argument.h"
#include "llvm/SymbolTable.h"
#include "llvm/Support/CFG.h"
@@ -66,6 +68,14 @@ namespace { // Anonymous namespace for class
return false;
}
+ bool doFinalization(Module *M) {
+ if (Broken) {
+ cerr << "Broken module found, compilation aborted!\n";
+ abort();
+ }
+ return false;
+ }
+
// Verification methods...
void verifySymbolTable(SymbolTable *ST);
void visitFunction(Function *F);
@@ -73,6 +83,9 @@ namespace { // Anonymous namespace for class
void visitPHINode(PHINode *PN);
void visitBinaryOperator(BinaryOperator *B);
void visitCallInst(CallInst *CI);
+ void visitGetElementPtrInst(GetElementPtrInst *GEP);
+ void visitLoadInst(LoadInst *LI);
+ void visitStoreInst(StoreInst *SI);
void visitInstruction(Instruction *I);
// CheckFailed - A check failed, so print out the condition and the message
@@ -222,6 +235,33 @@ void Verifier::visitBinaryOperator(BinaryOperator *B) {
visitInstruction(B);
}
+void Verifier::visitGetElementPtrInst(GetElementPtrInst *GEP) {
+ const Type *ElTy =MemAccessInst::getIndexedType(GEP->getOperand(0)->getType(),
+ GEP->copyIndices(), true);
+ Assert1(ElTy, "Invalid indices for GEP pointer type!", GEP);
+ Assert2(PointerType::get(ElTy) == GEP->getType(),
+ "GEP is not of right type for indices!\n", GEP, ElTy);
+ visitInstruction(GEP);
+}
+
+void Verifier::visitLoadInst(LoadInst *LI) {
+ const Type *ElTy = LoadInst::getIndexedType(LI->getOperand(0)->getType(),
+ LI->copyIndices());
+ Assert1(ElTy, "Invalid indices for load pointer type!", LI);
+ Assert2(ElTy == LI->getType(),
+ "Load is not of right type for indices!\n", LI, ElTy);
+ visitInstruction(LI);
+}
+
+void Verifier::visitStoreInst(StoreInst *SI) {
+ const Type *ElTy = StoreInst::getIndexedType(SI->getOperand(1)->getType(),
+ SI->copyIndices());
+ Assert1(ElTy, "Invalid indices for store pointer type!", SI);
+ Assert2(ElTy == SI->getOperand(0)->getType(),
+ "Stored value is not of right type for indices!\n", SI, ElTy);
+ visitInstruction(SI);
+}
+
// verifyInstruction - Verify that a non-terminator instruction is well formed.
//