summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--llvm/lib/IR/Verifier.cpp22
-rw-r--r--llvm/unittests/IR/VerifierTest.cpp24
2 files changed, 39 insertions, 7 deletions
diff --git a/llvm/lib/IR/Verifier.cpp b/llvm/lib/IR/Verifier.cpp
index 217dfcd7c76..c47bb2518e0 100644
--- a/llvm/lib/IR/Verifier.cpp
+++ b/llvm/lib/IR/Verifier.cpp
@@ -4460,17 +4460,16 @@ struct VerifierLegacyPass : public FunctionPass {
static char ID;
Verifier V;
- bool FatalErrors;
+ bool FatalErrors = true;
VerifierLegacyPass()
: FunctionPass(ID),
- V(&dbgs(), /*ShouldTreatBrokenDebugInfoAsError=*/true),
- FatalErrors(true) {
+ V(&dbgs(), /*ShouldTreatBrokenDebugInfoAsError=*/false) {
initializeVerifierLegacyPassPass(*PassRegistry::getPassRegistry());
}
explicit VerifierLegacyPass(bool FatalErrors)
: FunctionPass(ID),
- V(&dbgs(), /*ShouldTreatBrokenDebugInfoAsError=*/true),
+ V(&dbgs(), /*ShouldTreatBrokenDebugInfoAsError=*/false),
FatalErrors(FatalErrors) {
initializeVerifierLegacyPassPass(*PassRegistry::getPassRegistry());
}
@@ -4483,9 +4482,20 @@ struct VerifierLegacyPass : public FunctionPass {
}
bool doFinalization(Module &M) override {
- if (!V.verify(M) && FatalErrors)
- report_fatal_error("Broken module found, compilation aborted!");
+ bool HasErrors = !V.verify(M);
+ if (FatalErrors) {
+ if (HasErrors)
+ report_fatal_error("Broken module found, compilation aborted!");
+ assert(!V.hasBrokenDebugInfo() && "Module contains invalid debug info");
+ }
+ // Strip broken debug info.
+ if (V.hasBrokenDebugInfo()) {
+ DiagnosticInfoIgnoringInvalidDebugMetadata DiagInvalid(M);
+ M.getContext().diagnose(DiagInvalid);
+ if (!StripDebugInfo(M))
+ report_fatal_error("Failed to strip malformed debug info");
+ }
return false;
}
diff --git a/llvm/unittests/IR/VerifierTest.cpp b/llvm/unittests/IR/VerifierTest.cpp
index 85148afdeca..c33c92a6f7c 100644
--- a/llvm/unittests/IR/VerifierTest.cpp
+++ b/llvm/unittests/IR/VerifierTest.cpp
@@ -7,7 +7,6 @@
//
//===----------------------------------------------------------------------===//
-#include "llvm/IR/Verifier.h"
#include "llvm/IR/Constants.h"
#include "llvm/IR/DIBuilder.h"
#include "llvm/IR/DerivedTypes.h"
@@ -16,7 +15,9 @@
#include "llvm/IR/GlobalVariable.h"
#include "llvm/IR/Instructions.h"
#include "llvm/IR/LLVMContext.h"
+#include "llvm/IR/LegacyPassManager.h"
#include "llvm/IR/Module.h"
+#include "llvm/IR/Verifier.h"
#include "gtest/gtest.h"
namespace llvm {
@@ -198,5 +199,26 @@ TEST(VerifierTest, StripInvalidDebugInfo) {
}
#endif
+TEST(VerifierTest, StripInvalidDebugInfoLegacy) {
+ LLVMContext C;
+ Module M("M", C);
+ DIBuilder DIB(M);
+ DIB.createCompileUnit(dwarf::DW_LANG_C89, "broken.c", "/",
+ "unittest", false, "", 0);
+ DIB.finalize();
+ EXPECT_FALSE(verifyModule(M));
+
+ // Now break it.
+ auto *File = DIB.createFile("not-a-CU.f", ".");
+ NamedMDNode *NMD = M.getOrInsertNamedMetadata("llvm.dbg.cu");
+ NMD->addOperand(File);
+ EXPECT_TRUE(verifyModule(M));
+
+ legacy::PassManager Passes;
+ Passes.add(createVerifierPass(false));
+ Passes.run(M);
+ EXPECT_FALSE(verifyModule(M));
+}
+
} // end anonymous namespace
} // end namespace llvm
OpenPOWER on IntegriCloud