#include "llvm/Support/InstVisitor.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/ADT/STLExtras.h"
-#include "llvm/Support/Visibility.h"
+#include "llvm/Support/Compiler.h"
#include <algorithm>
#include <iostream>
#include <sstream>
// returning back to the pass manager, or else the pass manager may try to
// run other passes on the broken module.
if (RealPass)
- abortIfBroken();
+ return abortIfBroken();
return false;
}
// returning back to the pass manager, or else the pass manager may try to
// run other passes on the broken module.
if (RealPass)
- abortIfBroken();
+ return abortIfBroken();
return false;
}
visitGlobalVariable(*I);
// If the module is broken, abort at this time.
- abortIfBroken();
- return false;
+ return abortIfBroken();
}
virtual void getAnalysisUsage(AnalysisUsage &AU) const {
/// abortIfBroken - If the module is broken and we are supposed to abort on
/// this condition, do so.
///
- void abortIfBroken() {
+ bool abortIfBroken() {
if (Broken) {
msgs << "Broken module found, ";
switch (action) {
case PrintMessageAction:
msgs << "verification continues.\n";
std::cerr << msgs.str();
- break;
+ return false;
case ReturnStatusAction:
- break;
+ msgs << "compilation terminated.\n";
+ return Broken;
}
}
+ return false;
}
}
};
- RegisterOpt<Verifier> X("verify", "Module Verifier");
+ RegisterPass<Verifier> X("verify", "Module Verifier");
} // End anonymous namespace
void Verifier::visitGlobalValue(GlobalValue &GV) {
- Assert1(!GV.isExternal() || GV.hasExternalLinkage(),
- "Global is external, but doesn't have external linkage!", &GV);
+ Assert1(!GV.isExternal() ||
+ GV.hasExternalLinkage() ||
+ GV.hasDLLImportLinkage() ||
+ GV.hasExternalWeakLinkage(),
+ "Global is external, but doesn't have external or dllimport or weak linkage!",
+ &GV);
+
+ Assert1(!GV.hasDLLImportLinkage() || GV.isExternal(),
+ "Global is marked as dllimport, but not external", &GV);
+
Assert1(!GV.hasAppendingLinkage() || isa<GlobalVariable>(GV),
"Only global variables can have appending linkage!", &GV);
}
for (unsigned i = 0, e = I.getNumOperands(); i != e; ++i) {
- // Check to make sure that the "address of" an intrinsic function is never
- // taken.
Assert1(I.getOperand(i) != 0, "Instruction has null operand!", &I);
+
+ // Check to make sure that only first-class-values are operands to
+ // instructions.
+ Assert1(I.getOperand(i)->getType()->isFirstClassType(),
+ "Instruction operands must be first-class values!", &I);
+
if (Function *F = dyn_cast<Function>(I.getOperand(i))) {
+ // Check to make sure that the "address of" an intrinsic function is never
+ // taken.
Assert1(!F->isIntrinsic() || (i == 0 && isa<CallInst>(I)),
"Cannot take the address of an intrinsic!", &I);
} else if (BasicBlock *OpBB = dyn_cast<BasicBlock>(I.getOperand(i))) {