mirror of
https://github.com/capstone-engine/llvm-capstone.git
synced 2025-01-07 08:34:59 +00:00
Serialized diagnostic severity levels should be stable.
Serialized diagnostics were accidentally using the AST diagnostic level values rather than a dedicated stable enum, so the addition of "remark" broke the reading of existing serialized diagnostics files. I've added a .dia file generated from Xcode 5's Clang to make sure we don't break this in the future. llvm-svn: 202733
This commit is contained in:
parent
77d7698709
commit
7ef1c387a0
@ -46,6 +46,19 @@ enum RecordIDs {
|
||||
RECORD_LAST = RECORD_FIXIT
|
||||
};
|
||||
|
||||
/// A stable version of DiagnosticIDs::Level.
|
||||
///
|
||||
/// Do not change the order of values in this enum, and please increment the
|
||||
/// serialized diagnostics version number when you add to it.
|
||||
enum Level {
|
||||
Ignored = 0,
|
||||
Note,
|
||||
Warning,
|
||||
Error,
|
||||
Fatal,
|
||||
Remark
|
||||
};
|
||||
|
||||
/// \brief Returns a DiagnosticConsumer that serializes diagnostics to
|
||||
/// a bitcode file.
|
||||
///
|
||||
|
@ -174,7 +174,7 @@ private:
|
||||
const SourceManager &SM);
|
||||
|
||||
/// \brief The version of the diagnostics file.
|
||||
enum { Version = 1 };
|
||||
enum { Version = 2 };
|
||||
|
||||
/// \brief Language options, which can differ from one clone of this client
|
||||
/// to another.
|
||||
@ -566,6 +566,21 @@ void SDiagsWriter::HandleDiagnostic(DiagnosticsEngine::Level DiagLevel,
|
||||
&Info);
|
||||
}
|
||||
|
||||
static serialized_diags::Level getStableLevel(DiagnosticsEngine::Level Level) {
|
||||
switch (Level) {
|
||||
#define CASE(X) case DiagnosticsEngine::X: return serialized_diags::X;
|
||||
CASE(Ignored)
|
||||
CASE(Note)
|
||||
CASE(Remark)
|
||||
CASE(Warning)
|
||||
CASE(Error)
|
||||
CASE(Fatal)
|
||||
#undef CASE
|
||||
}
|
||||
|
||||
llvm_unreachable("invalid diagnostic level");
|
||||
}
|
||||
|
||||
void SDiagsWriter::EmitDiagnosticMessage(SourceLocation Loc,
|
||||
PresumedLoc PLoc,
|
||||
DiagnosticsEngine::Level Level,
|
||||
@ -579,7 +594,7 @@ void SDiagsWriter::EmitDiagnosticMessage(SourceLocation Loc,
|
||||
// Emit the RECORD_DIAG record.
|
||||
Record.clear();
|
||||
Record.push_back(RECORD_DIAG);
|
||||
Record.push_back(Level);
|
||||
Record.push_back(getStableLevel(Level));
|
||||
AddLocToRecord(Loc, SM, PLoc, Record);
|
||||
|
||||
if (const Diagnostic *Info = D.dyn_cast<const Diagnostic*>()) {
|
||||
|
BIN
clang/test/Misc/Inputs/serialized-diags-stable.dia
Normal file
BIN
clang/test/Misc/Inputs/serialized-diags-stable.dia
Normal file
Binary file not shown.
20
clang/test/Misc/serialized-diags-stable.c
Normal file
20
clang/test/Misc/serialized-diags-stable.c
Normal file
@ -0,0 +1,20 @@
|
||||
// RUN: rm -f %t
|
||||
// RUN: not %clang -Wall -fsyntax-only %s --serialize-diagnostics %t.dia > /dev/null 2>&1
|
||||
// RUN: c-index-test -read-diagnostics %t.dia 2>&1 | FileCheck %s
|
||||
|
||||
// RUN: c-index-test -read-diagnostics %S/Inputs/serialized-diags-stable.dia 2>&1 | FileCheck %s
|
||||
|
||||
int foo() {
|
||||
// CHECK: serialized-diags-stable.c:[[@LINE+2]]:1: warning: control reaches end of non-void function [-Wreturn-type] [Semantic Issue]
|
||||
// CHECK-NEXT: Number FIXITs = 0
|
||||
}
|
||||
|
||||
// CHECK: serialized-diags-stable.c:[[@LINE+5]]:13: error: redefinition of 'bar' as different kind of symbol [] [Semantic Issue]
|
||||
// CHECK-NEXT: Number FIXITs = 0
|
||||
// CHECK-NEXT: +-/Volumes/Lore/llvm-public/clang/test/Misc/serialized-diags-stable.c:[[@LINE+2]]:6: note: previous definition is here [] []
|
||||
// CHECK-NEXT: Number FIXITs = 0
|
||||
void bar() {}
|
||||
typedef int bar;
|
||||
|
||||
|
||||
// CHECK-LABEL: Number of diagnostics: 2
|
@ -67,13 +67,19 @@ CXLoadedDiagnostic::~CXLoadedDiagnostic() {}
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
CXDiagnosticSeverity CXLoadedDiagnostic::getSeverity() const {
|
||||
// FIXME: possibly refactor with logic in CXStoredDiagnostic.
|
||||
switch (severity) {
|
||||
case DiagnosticsEngine::Ignored: return CXDiagnostic_Ignored;
|
||||
case DiagnosticsEngine::Note: return CXDiagnostic_Note;
|
||||
case DiagnosticsEngine::Warning: return CXDiagnostic_Warning;
|
||||
case DiagnosticsEngine::Error: return CXDiagnostic_Error;
|
||||
case DiagnosticsEngine::Fatal: return CXDiagnostic_Fatal;
|
||||
// FIXME: Fail more softly if the diagnostic level is unknown?
|
||||
assert(severity == static_cast<serialized_diags::Level>(severity) &&
|
||||
"unknown serialized diagnostic level");
|
||||
|
||||
switch (static_cast<serialized_diags::Level>(severity)) {
|
||||
#define CASE(X) case serialized_diags::X: return CXDiagnostic_##X;
|
||||
CASE(Ignored)
|
||||
CASE(Note)
|
||||
CASE(Warning)
|
||||
CASE(Error)
|
||||
CASE(Fatal)
|
||||
CASE(Remark)
|
||||
#undef CASE
|
||||
}
|
||||
|
||||
llvm_unreachable("Invalid diagnostic level");
|
||||
@ -175,7 +181,7 @@ void CXLoadedDiagnostic::decodeLocation(CXSourceLocation location,
|
||||
// Deserialize diagnostics.
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
enum { MaxSupportedVersion = 1 };
|
||||
enum { MaxSupportedVersion = 2 };
|
||||
typedef SmallVector<uint64_t, 64> RecordData;
|
||||
enum LoadResult { Failure = 1, Success = 0 };
|
||||
enum StreamResult { Read_EndOfStream,
|
||||
|
Loading…
Reference in New Issue
Block a user