From 2ebfb42fe906eff23165e47723a7cbb83e7c9e60 Mon Sep 17 00:00:00 2001 From: Manman Ren Date: Thu, 16 Jan 2014 01:51:12 +0000 Subject: [PATCH] Report a warning when dropping outdated debug info metadata. Use DiagnosticInfo to emit the warning. llvm-svn: 199346 --- llvm/include/llvm/IR/DiagnosticInfo.h | 30 ++++++++++++++++++++++++ llvm/include/llvm/IR/DiagnosticPrinter.h | 3 +++ llvm/lib/IR/AutoUpgrade.cpp | 11 +++++++-- llvm/lib/IR/DiagnosticInfo.cpp | 5 ++++ llvm/lib/IR/DiagnosticPrinter.cpp | 6 +++++ llvm/test/Bitcode/drop-debug-info.ll | 4 +++- 6 files changed, 56 insertions(+), 3 deletions(-) diff --git a/llvm/include/llvm/IR/DiagnosticInfo.h b/llvm/include/llvm/IR/DiagnosticInfo.h index 151e155eaf85..4c7af89d72fa 100644 --- a/llvm/include/llvm/IR/DiagnosticInfo.h +++ b/llvm/include/llvm/IR/DiagnosticInfo.h @@ -39,6 +39,7 @@ enum DiagnosticSeverity { enum DiagnosticKind { DK_InlineAsm, DK_StackSize, + DK_DebugMetadataVersion, DK_FirstPluginKind }; @@ -160,6 +161,35 @@ public: } }; +/// Diagnostic information for debug metadata version reporting. +/// This is basically a module and a version. +class DiagnosticInfoDebugMetadataVersion : public DiagnosticInfo { +private: + /// The module that is concerned by this debug metadata version diagnostic. + const Module &M; + /// The actual metadata version. + unsigned MetadataVersion; + +public: + /// \p The module that is concerned by this debug metadata version diagnostic. + /// \p The actual metadata version. + DiagnosticInfoDebugMetadataVersion(const Module &M, unsigned MetadataVersion, + DiagnosticSeverity Severity = DS_Warning) + : DiagnosticInfo(DK_DebugMetadataVersion, Severity), M(M), + MetadataVersion(MetadataVersion) {} + + const Module &getModule() const { return M; } + unsigned getMetadataVersion() const { return MetadataVersion; } + + /// \see DiagnosticInfo::print. + virtual void print(DiagnosticPrinter &DP) const; + + /// Hand rolled RTTI. + static bool classof(const DiagnosticInfo *DI) { + return DI->getKind() == DK_DebugMetadataVersion; + } +}; + } // End namespace llvm #endif diff --git a/llvm/include/llvm/IR/DiagnosticPrinter.h b/llvm/include/llvm/IR/DiagnosticPrinter.h index 721b1b4212e0..6177b7fe10a0 100644 --- a/llvm/include/llvm/IR/DiagnosticPrinter.h +++ b/llvm/include/llvm/IR/DiagnosticPrinter.h @@ -20,6 +20,7 @@ namespace llvm { // Forward declarations. +class Module; class raw_ostream; class StringRef; class Twine; @@ -49,6 +50,7 @@ public: // IR related types. virtual DiagnosticPrinter &operator<<(const Value &V) = 0; + virtual DiagnosticPrinter &operator<<(const Module &M) = 0; }; /// \brief Basic diagnostic printer that uses an underlying raw_ostream. @@ -78,6 +80,7 @@ public: // IR related types. virtual DiagnosticPrinter &operator<<(const Value &V); + virtual DiagnosticPrinter &operator<<(const Module &M); }; } // End namespace llvm diff --git a/llvm/lib/IR/AutoUpgrade.cpp b/llvm/lib/IR/AutoUpgrade.cpp index d12bf7b9e3c9..4340c057c1bd 100644 --- a/llvm/lib/IR/AutoUpgrade.cpp +++ b/llvm/lib/IR/AutoUpgrade.cpp @@ -14,6 +14,7 @@ #include "llvm/AutoUpgrade.h" #include "llvm/DebugInfo.h" #include "llvm/IR/Constants.h" +#include "llvm/IR/DiagnosticInfo.h" #include "llvm/IR/Function.h" #include "llvm/IR/IRBuilder.h" #include "llvm/IR/Instruction.h" @@ -494,8 +495,14 @@ Value *llvm::UpgradeBitCastExpr(unsigned Opc, Constant *C, Type *DestTy) { /// Check the debug info version number, if it is out-dated, drop the debug /// info. Return true if module is modified. bool llvm::UpgradeDebugInfo(Module &M) { - if (getDebugMetadataVersionFromModule(M) == DEBUG_METADATA_VERSION) + unsigned Version = getDebugMetadataVersionFromModule(M); + if (Version == DEBUG_METADATA_VERSION) return false; - return StripDebugInfo(M); + bool RetCode = StripDebugInfo(M); + if (RetCode) { + DiagnosticInfoDebugMetadataVersion DiagVersion(M, Version); + M.getContext().diagnose(DiagVersion); + } + return RetCode; } diff --git a/llvm/lib/IR/DiagnosticInfo.cpp b/llvm/lib/IR/DiagnosticInfo.cpp index 2b1221acdcaf..bd758830a2b1 100644 --- a/llvm/lib/IR/DiagnosticInfo.cpp +++ b/llvm/lib/IR/DiagnosticInfo.cpp @@ -51,3 +51,8 @@ void DiagnosticInfoStackSize::print(DiagnosticPrinter &DP) const { DP << "stack size limit exceeded (" << getStackSize() << ") in " << getFunction(); } + +void DiagnosticInfoDebugMetadataVersion::print(DiagnosticPrinter &DP) const { + DP << "invalid debug metadata version (" << getMetadataVersion() << ") in " + << getModule(); +} diff --git a/llvm/lib/IR/DiagnosticPrinter.cpp b/llvm/lib/IR/DiagnosticPrinter.cpp index d76f9f586a9e..5e160266c8fe 100644 --- a/llvm/lib/IR/DiagnosticPrinter.cpp +++ b/llvm/lib/IR/DiagnosticPrinter.cpp @@ -13,6 +13,7 @@ #include "llvm/ADT/Twine.h" #include "llvm/IR/DiagnosticPrinter.h" +#include "llvm/IR/Module.h" #include "llvm/IR/Value.h" #include "llvm/Support/raw_ostream.h" @@ -99,3 +100,8 @@ DiagnosticPrinter &DiagnosticPrinterRawOStream::operator<<(const Value &V) { Stream << V.getName(); return *this; } + +DiagnosticPrinter &DiagnosticPrinterRawOStream::operator<<(const Module &M) { + Stream << M.getModuleIdentifier(); + return *this; +} diff --git a/llvm/test/Bitcode/drop-debug-info.ll b/llvm/test/Bitcode/drop-debug-info.ll index da4ae0c541eb..8786ebb3b43a 100644 --- a/llvm/test/Bitcode/drop-debug-info.ll +++ b/llvm/test/Bitcode/drop-debug-info.ll @@ -1,4 +1,5 @@ -; RUN: llvm-as < %s | llvm-dis | FileCheck %s +; RUN: llvm-as < %s -o %t.bc 2>&1 >/dev/null | FileCheck -check-prefix=WARN %s +; RUN: llvm-dis < %t.bc | FileCheck %s define i32 @main() { entry: @@ -22,5 +23,6 @@ entry: !9 = metadata !{i32 2, metadata !"Dwarf Version", i32 2} !12 = metadata !{i32 4, i32 0, metadata !4, null} +; WARN: warning: invalid debug metadata version (0) ; CHECK-NOT: !dbg ; CHECK-NOT: !llvm.dbg.cu