summaryrefslogtreecommitdiff
path: root/lib/IR/Verifier.cpp
diff options
context:
space:
mode:
authorDuncan P. N. Exon Smith <dexonsmith@apple.com>2014-04-15 16:27:38 +0000
committerDuncan P. N. Exon Smith <dexonsmith@apple.com>2014-04-15 16:27:38 +0000
commit32791b02facda5b879f2bcf7dd3f1faea1e4782d (patch)
tree1fe8ec4d917295d0a54e8d538006088bb6b781e3 /lib/IR/Verifier.cpp
parentabf483ba524027caa3c5cd3de452d9feb11170d3 (diff)
downloadllvm-32791b02facda5b879f2bcf7dd3f1faea1e4782d.tar.gz
llvm-32791b02facda5b879f2bcf7dd3f1faea1e4782d.tar.bz2
llvm-32791b02facda5b879f2bcf7dd3f1faea1e4782d.tar.xz
verify-di: Implement DebugInfoVerifier
Implement DebugInfoVerifier, which steals verification relying on DebugInfoFinder from Verifier. - Adds LegacyDebugInfoVerifierPassPass, a ModulePass which wraps DebugInfoVerifier. Uses -verify-di command-line flag. - Change verifyModule() to invoke DebugInfoVerifier as well as Verifier. - Add a call to createDebugInfoVerifierPass() wherever there was a call to createVerifierPass(). This implementation as a module pass should sidestep efficiency issues, allowing us to turn debug info verification back on. <rdar://problem/15500563> git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@206300 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/IR/Verifier.cpp')
-rw-r--r--lib/IR/Verifier.cpp141
1 files changed, 92 insertions, 49 deletions
diff --git a/lib/IR/Verifier.cpp b/lib/IR/Verifier.cpp
index 1f977e8470..887ca7d48e 100644
--- a/lib/IR/Verifier.cpp
+++ b/lib/IR/Verifier.cpp
@@ -61,6 +61,7 @@
#include "llvm/IR/DerivedTypes.h"
#include "llvm/IR/Dominators.h"
#include "llvm/IR/InlineAsm.h"
+#include "llvm/IR/InstIterator.h"
#include "llvm/IR/InstVisitor.h"
#include "llvm/IR/IntrinsicInst.h"
#include "llvm/IR/LLVMContext.h"
@@ -160,9 +161,6 @@ class Verifier : public InstVisitor<Verifier>, VerifierSupport {
/// personality function.
const Value *PersonalityFn;
- /// \brief Finder keeps track of all debug info MDNodes in a Module.
- DebugInfoFinder Finder;
-
public:
explicit Verifier(raw_ostream &OS = dbgs())
: VerifierSupport(OS), Context(nullptr), DL(nullptr),
@@ -196,24 +194,18 @@ public:
// FIXME: It's really gross that we have to cast away constness here.
DT.recalculate(const_cast<Function &>(F));
- Finder.reset();
Broken = false;
// FIXME: We strip const here because the inst visitor strips const.
visit(const_cast<Function &>(F));
InstsInThisBlock.clear();
PersonalityFn = nullptr;
- if (VerifyDebugInfo)
- // Verify Debug Info.
- verifyDebugInfo();
-
return !Broken;
}
bool verify(const Module &M) {
this->M = &M;
Context = &M.getContext();
- Finder.reset();
Broken = false;
// Scan through, checking all of the external function's linkage now...
@@ -241,13 +233,6 @@ public:
visitModuleFlags(M);
visitModuleIdents(M);
- if (VerifyDebugInfo) {
- Finder.reset();
- Finder.processModule(M);
- // Verify Debug Info.
- verifyDebugInfo();
- }
-
return !Broken;
}
@@ -332,8 +317,21 @@ private:
void VerifyBitcastType(const Value *V, Type *DestTy, Type *SrcTy);
void VerifyConstantExprBitcastType(const ConstantExpr *CE);
+};
+class DebugInfoVerifier : public VerifierSupport {
+public:
+ explicit DebugInfoVerifier(raw_ostream &OS = dbgs()) : VerifierSupport(OS) {}
+ bool verify(const Module &M) {
+ this->M = &M;
+ verifyDebugInfo();
+ return !Broken;
+ }
+
+private:
void verifyDebugInfo();
+ void processInstructions(DebugInfoFinder &Finder);
+ void processCallInst(DebugInfoFinder &Finder, const CallInst &CI);
};
} // End anonymous namespace
@@ -2109,11 +2107,6 @@ void Verifier::visitInstruction(Instruction &I) {
MDNode *MD = I.getMetadata(LLVMContext::MD_range);
Assert1(!MD || isa<LoadInst>(I), "Ranges are only for loads!", &I);
- if (VerifyDebugInfo) {
- MD = I.getMetadata(LLVMContext::MD_dbg);
- Finder.processLocation(*M, DILocation(MD));
- }
-
InstsInThisBlock.insert(&I);
}
@@ -2313,17 +2306,7 @@ void Verifier::visitIntrinsicFunctionCall(Intrinsic::ID ID, CallInst &CI) {
MDNode *MD = cast<MDNode>(CI.getArgOperand(0));
Assert1(MD->getNumOperands() == 1,
"invalid llvm.dbg.declare intrinsic call 2", &CI);
- if (VerifyDebugInfo)
- Finder.processDeclare(*M, cast<DbgDeclareInst>(&CI));
} break;
- case Intrinsic::dbg_value: { //llvm.dbg.value
- if (VerifyDebugInfo) {
- Assert1(CI.getArgOperand(0) && isa<MDNode>(CI.getArgOperand(0)),
- "invalid llvm.dbg.value intrinsic call 1", &CI);
- Finder.processValue(*M, cast<DbgValueInst>(&CI));
- }
- break;
- }
case Intrinsic::memcpy:
case Intrinsic::memmove:
case Intrinsic::memset:
@@ -2385,25 +2368,51 @@ void Verifier::visitIntrinsicFunctionCall(Intrinsic::ID ID, CallInst &CI) {
}
}
-void Verifier::verifyDebugInfo() {
+void DebugInfoVerifier::verifyDebugInfo() {
+ if (!VerifyDebugInfo)
+ return;
+
+ DebugInfoFinder Finder;
+ Finder.processModule(*M);
+ processInstructions(Finder);
+
// Verify Debug Info.
- if (VerifyDebugInfo) {
- for (DICompileUnit CU : Finder.compile_units()) {
- Assert1(CU.Verify(), "DICompileUnit does not Verify!", CU);
- }
- for (DISubprogram S : Finder.subprograms()) {
- Assert1(S.Verify(), "DISubprogram does not Verify!", S);
- }
- for (DIGlobalVariable GV : Finder.global_variables()) {
- Assert1(GV.Verify(), "DIGlobalVariable does not Verify!", GV);
- }
- for (DIType T : Finder.types()) {
- Assert1(T.Verify(), "DIType does not Verify!", T);
- }
- for (DIScope S : Finder.scopes()) {
- Assert1(S.Verify(), "DIScope does not Verify!", S);
+ for (DICompileUnit CU : Finder.compile_units())
+ Assert1(CU.Verify(), "DICompileUnit does not Verify!", CU);
+ for (DISubprogram S : Finder.subprograms())
+ Assert1(S.Verify(), "DISubprogram does not Verify!", S);
+ for (DIGlobalVariable GV : Finder.global_variables())
+ Assert1(GV.Verify(), "DIGlobalVariable does not Verify!", GV);
+ for (DIType T : Finder.types())
+ Assert1(T.Verify(), "DIType does not Verify!", T);
+ for (DIScope S : Finder.scopes())
+ Assert1(S.Verify(), "DIScope does not Verify!", S);
+}
+
+void DebugInfoVerifier::processInstructions(DebugInfoFinder &Finder) {
+ for (const Function &F : *M)
+ for (auto I = inst_begin(&F), E = inst_end(&F); I != E; ++I) {
+ if (MDNode *MD = I->getMetadata(LLVMContext::MD_dbg))
+ Finder.processLocation(*M, DILocation(MD));
+ if (const CallInst *CI = dyn_cast<CallInst>(&*I))
+ processCallInst(Finder, *CI);
}
- }
+}
+
+void DebugInfoVerifier::processCallInst(DebugInfoFinder &Finder,
+ const CallInst &CI) {
+ if (Function *F = CI.getCalledFunction())
+ if (Intrinsic::ID ID = (Intrinsic::ID)F->getIntrinsicID())
+ switch (ID) {
+ case Intrinsic::dbg_declare:
+ Finder.processDeclare(*M, cast<DbgDeclareInst>(&CI));
+ break;
+ case Intrinsic::dbg_value:
+ Finder.processValue(*M, cast<DbgValueInst>(&CI));
+ break;
+ default:
+ break;
+ }
}
//===----------------------------------------------------------------------===//
@@ -2433,7 +2442,8 @@ bool llvm::verifyModule(const Module &M, raw_ostream *OS) {
// Note that this function's return value is inverted from what you would
// expect of a function called "verify".
- return !V.verify(M) || Broken;
+ DebugInfoVerifier DIV(OS ? *OS : NullStr);
+ return !V.verify(M) || !DIV.verify(M) || Broken;
}
namespace {
@@ -2469,15 +2479,48 @@ struct VerifierLegacyPass : public FunctionPass {
AU.setPreservesAll();
}
};
+struct DebugInfoVerifierLegacyPass : public ModulePass {
+ static char ID;
+
+ DebugInfoVerifier V;
+ bool FatalErrors;
+
+ DebugInfoVerifierLegacyPass() : ModulePass(ID), FatalErrors(true) {
+ initializeDebugInfoVerifierLegacyPassPass(*PassRegistry::getPassRegistry());
+ }
+ explicit DebugInfoVerifierLegacyPass(bool FatalErrors)
+ : ModulePass(ID), V(dbgs()), FatalErrors(FatalErrors) {
+ initializeDebugInfoVerifierLegacyPassPass(*PassRegistry::getPassRegistry());
+ }
+
+ bool runOnModule(Module &M) override {
+ if (!V.verify(M) && FatalErrors)
+ report_fatal_error("Broken debug info found, compilation aborted!");
+
+ return false;
+ }
+
+ void getAnalysisUsage(AnalysisUsage &AU) const override {
+ AU.setPreservesAll();
+ }
+};
}
char VerifierLegacyPass::ID = 0;
INITIALIZE_PASS(VerifierLegacyPass, "verify", "Module Verifier", false, false)
+char DebugInfoVerifierLegacyPass::ID = 0;
+INITIALIZE_PASS(DebugInfoVerifierLegacyPass, "verify-di", "Debug Info Verifier",
+ false, false)
+
FunctionPass *llvm::createVerifierPass(bool FatalErrors) {
return new VerifierLegacyPass(FatalErrors);
}
+ModulePass *llvm::createDebugInfoVerifierPass(bool FatalErrors) {
+ return new DebugInfoVerifierLegacyPass(FatalErrors);
+}
+
PreservedAnalyses VerifierPass::run(Module *M) {
if (verifyModule(*M, &dbgs()) && FatalErrors)
report_fatal_error("Broken module found, compilation aborted!");