enum DiagnosticKind {
DK_InlineAsm,
DK_StackSize,
+ DK_DebugMetadataVersion,
DK_FirstPluginKind
};
}
};
+/// 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
namespace llvm {
// Forward declarations.
+class Module;
class raw_ostream;
class StringRef;
class Twine;
// 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.
// IR related types.
virtual DiagnosticPrinter &operator<<(const Value &V);
+ virtual DiagnosticPrinter &operator<<(const Module &M);
};
} // End namespace llvm
#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"
/// 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;
}
DP << "stack size limit exceeded (" << getStackSize() << ") in "
<< getFunction();
}
+
+void DiagnosticInfoDebugMetadataVersion::print(DiagnosticPrinter &DP) const {
+ DP << "invalid debug metadata version (" << getMetadataVersion() << ") in "
+ << getModule();
+}
#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"
Stream << V.getName();
return *this;
}
+
+DiagnosticPrinter &DiagnosticPrinterRawOStream::operator<<(const Module &M) {
+ Stream << M.getModuleIdentifier();
+ return *this;
+}
-; 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:
!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