Report a warning when dropping outdated debug info metadata.
authorManman Ren <manman.ren@gmail.com>
Thu, 16 Jan 2014 01:51:12 +0000 (01:51 +0000)
committerManman Ren <manman.ren@gmail.com>
Thu, 16 Jan 2014 01:51:12 +0000 (01:51 +0000)
Use DiagnosticInfo to emit the warning.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@199346 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/IR/DiagnosticInfo.h
include/llvm/IR/DiagnosticPrinter.h
lib/IR/AutoUpgrade.cpp
lib/IR/DiagnosticInfo.cpp
lib/IR/DiagnosticPrinter.cpp
test/Bitcode/drop-debug-info.ll

index 151e155eaf855151ad3ac59fa66a8d5c3cfb2594..4c7af89d72fa26db343e1b380c3e28388bf16aef 100644 (file)
@@ -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
index 721b1b4212e0692b0b2f621c9f9118b58b33fe27..6177b7fe10a052a6db08bf489a40487760dcd329 100644 (file)
@@ -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
 
index d12bf7b9e3c9f502ca6aaf91323d585d8e905bc6..4340c057c1bd9469ef9a4a50b69a2164b949141e 100644 (file)
@@ -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;
 }
index 2b1221acdcaf87e08f2ea6cef26c88ee8b26342a..bd758830a2b14962a183f2c1048b05303ffb9706 100644 (file)
@@ -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();
+}
index d76f9f586a9e1af52988fa065afb981e8d424af0..5e160266c8fe7f8e1bbd42e98f7947a0d3e574af 100644 (file)
@@ -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;
+}
index da4ae0c541eb042d4f0ea18140710a4392e515cb..8786ebb3b43a961b898de0c18d7dc9b58b994ec4 100644 (file)
@@ -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