Report a warning when dropping outdated debug info metadata.

Use DiagnosticInfo to emit the warning.

llvm-svn: 199346
This commit is contained in:
Manman Ren 2014-01-16 01:51:12 +00:00
parent baf2c2211d
commit 2ebfb42fe9
6 changed files with 56 additions and 3 deletions

View 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

View 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

View 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;
}

View 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();
}

View 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;
}

View 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