1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-24 19:52:54 +01:00

Add some basic checks of CallInst's.

Assert now returns from the current function on error.

llvm-svn: 2308
This commit is contained in:
Chris Lattner 2002-04-18 22:11:52 +00:00
parent 039edb92f3
commit bffa0990cf

View File

@ -41,6 +41,7 @@
#include "llvm/DerivedTypes.h" #include "llvm/DerivedTypes.h"
#include "llvm/iPHINode.h" #include "llvm/iPHINode.h"
#include "llvm/iTerminators.h" #include "llvm/iTerminators.h"
#include "llvm/iOther.h"
#include "llvm/Argument.h" #include "llvm/Argument.h"
#include "llvm/SymbolTable.h" #include "llvm/SymbolTable.h"
#include "llvm/Support/CFG.h" #include "llvm/Support/CFG.h"
@ -71,6 +72,7 @@ namespace { // Anonymous namespace for class
void visitBasicBlock(BasicBlock *BB); void visitBasicBlock(BasicBlock *BB);
void visitPHINode(PHINode *PN); void visitPHINode(PHINode *PN);
void visitBinaryOperator(BinaryOperator *B); void visitBinaryOperator(BinaryOperator *B);
void visitCallInst(CallInst *CI);
void visitInstruction(Instruction *I); void visitInstruction(Instruction *I);
// CheckFailed - A check failed, so print out the condition and the message // CheckFailed - A check failed, so print out the condition and the message
@ -89,11 +91,11 @@ namespace { // Anonymous namespace for class
// Assert - We know that cond should be true, if not print an error message. // Assert - We know that cond should be true, if not print an error message.
#define Assert(C, M) \ #define Assert(C, M) \
do { if (!(C)) { CheckFailed(#C, M); } } while (0) do { if (!(C)) { CheckFailed(#C, M); return; } } while (0)
#define Assert1(C, M, V1) \ #define Assert1(C, M, V1) \
do { if (!(C)) { CheckFailed(#C, M, V1); } } while (0) do { if (!(C)) { CheckFailed(#C, M, V1); return; } } while (0)
#define Assert2(C, M, V1, V2) \ #define Assert2(C, M, V1, V2) \
do { if (!(C)) { CheckFailed(#C, M, V1, V2); } } while (0) do { if (!(C)) { CheckFailed(#C, M, V1, V2); return; } } while (0)
// verifySymbolTable - Verify that a function or module symbol table is ok // verifySymbolTable - Verify that a function or module symbol table is ok
@ -156,7 +158,7 @@ void Verifier::visitBasicBlock(BasicBlock *BB) {
Assert1(BB->getTerminator(), "Basic Block does not have terminator!\n", BB); Assert1(BB->getTerminator(), "Basic Block does not have terminator!\n", BB);
// Check that the terminator is ok as well... // Check that the terminator is ok as well...
if (BB->getTerminator() && isa<ReturnInst>(BB->getTerminator())) { if (isa<ReturnInst>(BB->getTerminator())) {
Instruction *I = BB->getTerminator(); Instruction *I = BB->getTerminator();
Function *F = I->getParent()->getParent(); Function *F = I->getParent()->getParent();
if (I->getNumOperands() == 0) if (I->getNumOperands() == 0)
@ -189,7 +191,7 @@ void Verifier::visitPHINode(PHINode *PN) {
find(Preds.begin(), Preds.end(), BB); find(Preds.begin(), Preds.end(), BB);
Assert2(PI != Preds.end(), "PHI node has entry for basic block that" Assert2(PI != Preds.end(), "PHI node has entry for basic block that"
" is not a predecessor!", PN, BB); " is not a predecessor!", PN, BB);
if (PI != Preds.end()) Preds.erase(PI); Preds.erase(PI);
} }
// There should be no entries left in the predecessor list... // There should be no entries left in the predecessor list...
@ -201,6 +203,13 @@ void Verifier::visitPHINode(PHINode *PN) {
visitInstruction(PN); visitInstruction(PN);
} }
void Verifier::visitCallInst(CallInst *CI) {
Assert1(isa<PointerType>(CI->getOperand(0)->getType()),
"Called function must be a pointer!", CI);
PointerType *FPTy = cast<PointerType>(CI->getOperand(0)->getType());
Assert1(isa<FunctionType>(FPTy->getElementType()),
"Called function is not pointer to function type!", CI);
}
// visitBinaryOperator - Check that both arguments to the binary operator are // visitBinaryOperator - Check that both arguments to the binary operator are
// of the same type! // of the same type!
@ -227,7 +236,7 @@ void Verifier::visitInstruction(Instruction *I) {
UI != UE; ++UI) { UI != UE; ++UI) {
Assert1(isa<Instruction>(*UI), "Use of instruction is not an instruction!", Assert1(isa<Instruction>(*UI), "Use of instruction is not an instruction!",
*UI); *UI);
if (Instruction *Used = dyn_cast<Instruction>(*UI)) Instruction *Used = cast<Instruction>(*UI);
Assert2(Used->getParent() != 0, "Instruction referencing instruction not" Assert2(Used->getParent() != 0, "Instruction referencing instruction not"
" embeded in a basic block!", I, Used); " embeded in a basic block!", I, Used);
} }