#include "llvm/Support/InstVisitor.h"
#include "Support/STLExtras.h"
#include <algorithm>
-
-namespace llvm {
+using namespace llvm;
namespace { // Anonymous namespace for class
visitGlobalValue(*I);
for (Module::giterator I = M.gbegin(), E = M.gend(); I != E; ++I)
- if (I->isExternal() && I->hasInternalLinkage())
- CheckFailed("Global Variable is external with internal linkage!", I);
+ visitGlobalValue(*I);
// If the module is broken, abort at this time.
abortIfBroken();
void visitUserOp2(Instruction &I) { visitUserOp1(I); }
void visitIntrinsicFunctionCall(Intrinsic::ID ID, CallInst &CI);
+
+ void WriteValue(const Value *V) {
+ if (!V) return;
+ if (isa<Instruction>(V)) {
+ std::cerr << *V;
+ } else if (const Type *Ty = dyn_cast<Type>(V)) {
+ WriteTypeSymbolic(std::cerr, Ty, Mod);
+ } else {
+ WriteAsOperand (std::cerr, V, true, true, Mod);
+ std::cerr << "\n";
+ }
+ }
+
+
// CheckFailed - A check failed, so print out the condition and the message
// that failed. This provides a nice place to put a breakpoint if you want
// to see why something is not correct.
//
- inline void CheckFailed(const std::string &Message,
- const Value *V1 = 0, const Value *V2 = 0,
- const Value *V3 = 0, const Value *V4 = 0) {
+ void CheckFailed(const std::string &Message,
+ const Value *V1 = 0, const Value *V2 = 0,
+ const Value *V3 = 0, const Value *V4 = 0) {
std::cerr << Message << "\n";
- if (V1) { WriteAsOperand (std::cerr, V1, true, true, Mod); std::cerr << "\n"; }
- if (V2) { WriteAsOperand (std::cerr, V2, true, true, Mod); std::cerr << "\n"; }
- if (V3) { WriteAsOperand (std::cerr, V3, true, true, Mod); std::cerr << "\n"; }
- if (V4) { WriteAsOperand (std::cerr, V4, true, true, Mod); std::cerr << "\n"; }
+ WriteValue(V1);
+ WriteValue(V2);
+ WriteValue(V3);
+ WriteValue(V4);
Broken = true;
}
};
RegisterOpt<Verifier> X("verify", "Module Verifier");
+} // End anonymous namespace
+
// Assert - We know that cond should be true, if not print an error message.
#define Assert(C, M) \
void Verifier::visitGlobalValue(GlobalValue &GV) {
Assert1(!GV.isExternal() || GV.hasExternalLinkage(),
- "Global value has Internal Linkage!", &GV);
+ "Global is external, but doesn't have external linkage!", &GV);
Assert1(!GV.hasAppendingLinkage() || isa<GlobalVariable>(GV),
"Only global variables can have appending linkage!", &GV);
Assert2(FT->getNumParams() == NumArgs,
"# formal arguments must match # of arguments for function type!",
&F, FT);
+ Assert1(F.getReturnType()->isFirstClassType() ||
+ F.getReturnType() == Type::VoidTy,
+ "Functions cannot return aggregate values!", &F);
// Check that the argument values match the function type for this function...
unsigned i = 0;
"Cannot take the address of an intrinsic!", &I);
else if (Instruction *Op = dyn_cast<Instruction>(I.getOperand(i))) {
+ BasicBlock *OpBlock = Op->getParent();
+
// Check that a definition dominates all of its uses.
//
if (!isa<PHINode>(I)) {
+ // Invoke results are only usable in the normal destination, not in the
+ // exceptional destination.
+ if (InvokeInst *II = dyn_cast<InvokeInst>(Op))
+ OpBlock = II->getNormalDest();
+
// Definition must dominate use unless use is unreachable!
- Assert2(DS->dominates(Op->getParent(), BB) ||
+ Assert2(DS->dominates(OpBlock, BB) ||
!DS->dominates(&BB->getParent()->getEntryBlock(), BB),
"Instruction does not dominate all uses!", Op, &I);
} else {
// PHI nodes are more difficult than other nodes because they actually
// "use" the value in the predecessor basic blocks they correspond to.
BasicBlock *PredBB = cast<BasicBlock>(I.getOperand(i+1));
- Assert2(DS->dominates(Op->getParent(), PredBB) ||
+ Assert2(DS->dominates(OpBlock, PredBB) ||
!DS->dominates(&BB->getParent()->getEntryBlock(), PredBB),
"Instruction does not dominate all uses!", Op, &I);
}
case Intrinsic::longjmp: NumArgs = 2; break;
case Intrinsic::sigsetjmp: NumArgs = 2; break;
case Intrinsic::siglongjmp: NumArgs = 2; break;
+
+ case Intrinsic::dbg_stoppoint: NumArgs = 4; break;
+ case Intrinsic::dbg_region_start:NumArgs = 1; break;
+ case Intrinsic::dbg_region_end: NumArgs = 1; break;
+ case Intrinsic::dbg_func_start: NumArgs = 1; break;
+ case Intrinsic::dbg_declare: NumArgs = 1; break;
+
+ case Intrinsic::memcpy: NumArgs = 4; break;
+ case Intrinsic::memmove: NumArgs = 4; break;
case Intrinsic::alpha_ctlz: NumArgs = 1; break;
case Intrinsic::alpha_cttz: NumArgs = 1; break;
"Illegal # arguments for intrinsic function!", IF);
}
-} // End anonymous namespace
//===----------------------------------------------------------------------===//
// Implement the public interfaces to this file...
//===----------------------------------------------------------------------===//
-FunctionPass *createVerifierPass() {
+FunctionPass *llvm::createVerifierPass() {
return new Verifier();
}
// verifyFunction - Create
-bool verifyFunction(const Function &f) {
+bool llvm::verifyFunction(const Function &f) {
Function &F = (Function&)f;
assert(!F.isExternal() && "Cannot verify external functions");
// verifyModule - Check a module for errors, printing messages on stderr.
// Return true if the module is corrupt.
//
-bool verifyModule(const Module &M) {
+bool llvm::verifyModule(const Module &M) {
PassManager PM;
Verifier *V = new Verifier();
PM.add(V);
PM.run((Module&)M);
return V->Broken;
}
-
-} // End llvm namespace