Fix crash in VerifyType when checking Contexts. Because there may not be a

Module (we were called with verifyFunction and an unowned Function) we can't
rely on Mod->getContext().

llvm-svn: 96275
This commit is contained in:
Nick Lewycky 2010-02-15 21:52:04 +00:00
parent 1dcde6b319
commit a21f060918

View File

@ -161,7 +161,8 @@ namespace {
VerifierFailureAction action; VerifierFailureAction action;
// What to do if verification fails. // What to do if verification fails.
Module *Mod; // Module we are verifying right now Module *Mod; // Module we are verifying right now
DominatorTree *DT; // Dominator Tree, caution can be null! LLVMContext *Context; // Context within which we are verifying
DominatorTree *DT; // Dominator Tree, caution can be null!
std::string Messages; std::string Messages;
raw_string_ostream MessagesStr; raw_string_ostream MessagesStr;
@ -178,24 +179,25 @@ namespace {
Verifier() Verifier()
: FunctionPass(&ID), : FunctionPass(&ID),
Broken(false), RealPass(true), action(AbortProcessAction), Broken(false), RealPass(true), action(AbortProcessAction),
DT(0), MessagesStr(Messages) {} Mod(0), Context(0), DT(0), MessagesStr(Messages) {}
explicit Verifier(VerifierFailureAction ctn) explicit Verifier(VerifierFailureAction ctn)
: FunctionPass(&ID), : FunctionPass(&ID),
Broken(false), RealPass(true), action(ctn), DT(0), Broken(false), RealPass(true), action(ctn), Mod(0), Context(0), DT(0),
MessagesStr(Messages) {} MessagesStr(Messages) {}
explicit Verifier(bool AB) explicit Verifier(bool AB)
: FunctionPass(&ID), : FunctionPass(&ID),
Broken(false), RealPass(true), Broken(false), RealPass(true),
action( AB ? AbortProcessAction : PrintMessageAction), DT(0), action( AB ? AbortProcessAction : PrintMessageAction), Mod(0),
MessagesStr(Messages) {} Context(0), DT(0), MessagesStr(Messages) {}
explicit Verifier(DominatorTree &dt) explicit Verifier(DominatorTree &dt)
: FunctionPass(&ID), : FunctionPass(&ID),
Broken(false), RealPass(false), action(PrintMessageAction), Broken(false), RealPass(false), action(PrintMessageAction), Mod(0),
DT(&dt), MessagesStr(Messages) {} Context(0), DT(&dt), MessagesStr(Messages) {}
bool doInitialization(Module &M) { bool doInitialization(Module &M) {
Mod = &M; Mod = &M;
Context = &M.getContext();
verifyTypeSymbolTable(M.getTypeSymbolTable()); verifyTypeSymbolTable(M.getTypeSymbolTable());
// If this is a real pass, in a pass manager, we must abort before // If this is a real pass, in a pass manager, we must abort before
@ -211,6 +213,7 @@ namespace {
if (RealPass) DT = &getAnalysis<DominatorTree>(); if (RealPass) DT = &getAnalysis<DominatorTree>();
Mod = F.getParent(); Mod = F.getParent();
if (!Context) Context = &F.getContext();
visit(F); visit(F);
InstsInThisBlock.clear(); InstsInThisBlock.clear();
@ -596,6 +599,9 @@ void Verifier::visitFunction(Function &F) {
const FunctionType *FT = F.getFunctionType(); const FunctionType *FT = F.getFunctionType();
unsigned NumArgs = F.arg_size(); unsigned NumArgs = F.arg_size();
Assert1(Context == &F.getContext(),
"Function context does not match Module context!", &F);
Assert1(!F.hasCommonLinkage(), "Functions may not have common linkage", &F); Assert1(!F.hasCommonLinkage(), "Functions may not have common linkage", &F);
Assert2(FT->getNumParams() == NumArgs, Assert2(FT->getNumParams() == NumArgs,
"# formal arguments must match # of arguments for function type!", "# formal arguments must match # of arguments for function type!",
@ -1482,7 +1488,7 @@ void Verifier::visitInstruction(Instruction &I) {
void Verifier::VerifyType(const Type *Ty) { void Verifier::VerifyType(const Type *Ty) {
if (!Types.insert(Ty)) return; if (!Types.insert(Ty)) return;
Assert1(&Mod->getContext() == &Ty->getContext(), Assert1(Context == &Ty->getContext(),
"Type context does not match Module context!", Ty); "Type context does not match Module context!", Ty);
switch (Ty->getTypeID()) { switch (Ty->getTypeID()) {