diff options
| author | Chris Lattner <sabre@nondot.org> | 2002-04-24 19:12:21 +0000 |
|---|---|---|
| committer | Chris Lattner <sabre@nondot.org> | 2002-04-24 19:12:21 +0000 |
| commit | d46bb6e933655be5d14f3e58bb2ebcda50090b81 (patch) | |
| tree | f345343f84349f0e6afb8c3564a94670ce871646 /llvm/lib | |
| parent | 21ea83bb3e2ac4b519c6449f3503a6dbe7246eea (diff) | |
| download | bcm5719-llvm-d46bb6e933655be5d14f3e58bb2ebcda50090b81.tar.gz bcm5719-llvm-d46bb6e933655be5d14f3e58bb2ebcda50090b81.zip | |
* 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
llvm-svn: 2309
Diffstat (limited to 'llvm/lib')
| -rw-r--r-- | llvm/lib/VMCore/Verifier.cpp | 42 |
1 files changed, 41 insertions, 1 deletions
diff --git a/llvm/lib/VMCore/Verifier.cpp b/llvm/lib/VMCore/Verifier.cpp index a4bbf1dccf8..5c7f98b05bd 100644 --- a/llvm/lib/VMCore/Verifier.cpp +++ b/llvm/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. // |

