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.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@202733
91177308-0d34-0410-b5e6-
96231b3b80d8
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.
///
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.
&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,
// 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*>()) {
--- /dev/null
+// 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
//===----------------------------------------------------------------------===//
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");
// Deserialize diagnostics.
//===----------------------------------------------------------------------===//
-enum { MaxSupportedVersion = 1 };
+enum { MaxSupportedVersion = 2 };
typedef SmallVector<uint64_t, 64> RecordData;
enum LoadResult { Failure = 1, Success = 0 };
enum StreamResult { Read_EndOfStream,