diff options
| author | Adrian Prantl <aprantl@apple.com> | 2017-10-02 18:31:29 +0000 |
|---|---|---|
| committer | Adrian Prantl <aprantl@apple.com> | 2017-10-02 18:31:29 +0000 |
| commit | a8b2ddbde453fab0db90be21b9a1ff961a7770e0 (patch) | |
| tree | 190712a839a2ce48d61e75501d2f68440891a2d8 /llvm/lib/IR | |
| parent | 6e17c00a88e23d0cc4cb491bfd0830f3df7fff66 (diff) | |
| download | bcm5719-llvm-a8b2ddbde453fab0db90be21b9a1ff961a7770e0.tar.gz bcm5719-llvm-a8b2ddbde453fab0db90be21b9a1ff961a7770e0.zip | |
Move the stripping of invalid debug info from the Verifier to AutoUpgrade.
This came out of a recent discussion on llvm-dev
(https://reviews.llvm.org/D38042). Currently the Verifier will strip
the debug info metadata from a module if it finds the dbeug info to be
malformed. This feature is very valuable since it allows us to improve
the Verifier by making it stricter without breaking bcompatibility,
but arguable the Verifier pass should not be modifying the IR. This
patch moves the stripping of broken debug info into AutoUpgrade
(UpgradeDebugInfo to be precise), which is a much better location for
this since the stripping of malformed (i.e., produced by older, buggy
versions of Clang) is a (harsh) form of AutoUpgrade.
This change is mostly NFC in nature, the one big difference is the
behavior when LLVM module passes are introducing malformed debug
info. Prior to this patch, a NoAsserts build would have printed a
warning and stripped the debug info, after this patch the Verifier
will report a fatal error. I believe this behavior is actually more
desirable anyway.
Differential Revision: https://reviews.llvm.org/D38184
llvm-svn: 314699
Diffstat (limited to 'llvm/lib/IR')
| -rw-r--r-- | llvm/lib/IR/AutoUpgrade.cpp | 24 | ||||
| -rw-r--r-- | llvm/lib/IR/DebugInfo.cpp | 2 | ||||
| -rw-r--r-- | llvm/lib/IR/Metadata.cpp | 1 | ||||
| -rw-r--r-- | llvm/lib/IR/Verifier.cpp | 29 |
4 files changed, 23 insertions, 33 deletions
diff --git a/llvm/lib/IR/AutoUpgrade.cpp b/llvm/lib/IR/AutoUpgrade.cpp index 2a69912671e..e190b201ccc 100644 --- a/llvm/lib/IR/AutoUpgrade.cpp +++ b/llvm/lib/IR/AutoUpgrade.cpp @@ -27,6 +27,7 @@ #include "llvm/IR/IntrinsicInst.h" #include "llvm/IR/LLVMContext.h" #include "llvm/IR/Module.h" +#include "llvm/IR/Verifier.h" #include "llvm/Support/ErrorHandling.h" #include "llvm/Support/Regex.h" #include <cstring> @@ -2358,15 +2359,26 @@ Value *llvm::UpgradeBitCastExpr(unsigned Opc, Constant *C, Type *DestTy) { /// info. Return true if module is modified. bool llvm::UpgradeDebugInfo(Module &M) { unsigned Version = getDebugMetadataVersionFromModule(M); - if (Version == DEBUG_METADATA_VERSION) - return false; - - bool RetCode = StripDebugInfo(M); - if (RetCode) { + if (Version == DEBUG_METADATA_VERSION) { + bool BrokenDebugInfo = false; + if (verifyModule(M, &llvm::errs(), &BrokenDebugInfo)) + report_fatal_error("Broken module found, compilation aborted!"); + if (!BrokenDebugInfo) + // Everything is ok. + return false; + else { + // Diagnose malformed debug info. + DiagnosticInfoIgnoringInvalidDebugMetadata Diag(M); + M.getContext().diagnose(Diag); + } + } + bool Modified = StripDebugInfo(M); + if (Modified && Version != DEBUG_METADATA_VERSION) { + // Diagnose a version mismatch. DiagnosticInfoDebugMetadataVersion DiagVersion(M, Version); M.getContext().diagnose(DiagVersion); } - return RetCode; + return Modified; } bool llvm::UpgradeModuleFlags(Module &M) { diff --git a/llvm/lib/IR/DebugInfo.cpp b/llvm/lib/IR/DebugInfo.cpp index 289798648b5..ae044b3d287 100644 --- a/llvm/lib/IR/DebugInfo.cpp +++ b/llvm/lib/IR/DebugInfo.cpp @@ -290,7 +290,7 @@ static MDNode *stripDebugLocFromLoopID(MDNode *N) { bool llvm::stripDebugInfo(Function &F) { bool Changed = false; - if (F.getSubprogram()) { + if (F.getMetadata(LLVMContext::MD_dbg)) { Changed = true; F.setSubprogram(nullptr); } diff --git a/llvm/lib/IR/Metadata.cpp b/llvm/lib/IR/Metadata.cpp index ac02ff76c84..a148ab65fc8 100644 --- a/llvm/lib/IR/Metadata.cpp +++ b/llvm/lib/IR/Metadata.cpp @@ -1431,7 +1431,6 @@ void GlobalObject::setMetadata(StringRef Kind, MDNode *N) { MDNode *GlobalObject::getMetadata(unsigned KindID) const { SmallVector<MDNode *, 1> MDs; getMetadata(KindID, MDs); - assert(MDs.size() <= 1 && "Expected at most one metadata attachment"); if (MDs.empty()) return nullptr; return MDs[0]; diff --git a/llvm/lib/IR/Verifier.cpp b/llvm/lib/IR/Verifier.cpp index 57559356f4d..7c6e4585b9e 100644 --- a/llvm/lib/IR/Verifier.cpp +++ b/llvm/lib/IR/Verifier.cpp @@ -4684,19 +4684,8 @@ struct VerifierLegacyPass : public FunctionPass { HasErrors |= !V->verify(F); HasErrors |= !V->verify(); - 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"); - } + if (FatalErrors && (HasErrors || V->hasBrokenDebugInfo())) + report_fatal_error("Broken module found, compilation aborted!"); return false; } @@ -4999,19 +4988,9 @@ VerifierAnalysis::Result VerifierAnalysis::run(Function &F, PreservedAnalyses VerifierPass::run(Module &M, ModuleAnalysisManager &AM) { auto Res = AM.getResult<VerifierAnalysis>(M); - if (FatalErrors) { - if (Res.IRBroken) - report_fatal_error("Broken module found, compilation aborted!"); - assert(!Res.DebugInfoBroken && "Module contains invalid debug info"); - } + if (FatalErrors && (Res.IRBroken || Res.DebugInfoBroken)) + report_fatal_error("Broken module found, compilation aborted!"); - // Strip broken debug info. - if (Res.DebugInfoBroken) { - DiagnosticInfoIgnoringInvalidDebugMetadata DiagInvalid(M); - M.getContext().diagnose(DiagInvalid); - if (!StripDebugInfo(M)) - report_fatal_error("Failed to strip malformed debug info"); - } return PreservedAnalyses::all(); } |

