Skip to content

Commit 4cedc90

Browse files
committed
[diagtool] Make the BuiltinDiagnosticsByID table sorted
Extracted the includes into a wrapper header file DiagnosticIDs.inc. Added is_sorted assert.
1 parent 1ad62a9 commit 4cedc90

File tree

3 files changed

+42
-60
lines changed

3 files changed

+42
-60
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
//===--- DiagnosticIDs.inc --------------------------------------*- C++ -*-===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
///
9+
/// \file
10+
/// Defines the Diagnostic IDs in ID sorted order.
11+
///
12+
//===----------------------------------------------------------------------===//
13+
14+
// Turn off clang-format, as the order of the includes are important to make
15+
// sure the table is sorted.
16+
17+
// clang-format off
18+
#include "clang/Basic/DiagnosticCommonKinds.inc"
19+
#include "clang/Basic/DiagnosticDriverKinds.inc"
20+
#include "clang/Basic/DiagnosticFrontendKinds.inc"
21+
#include "clang/Basic/DiagnosticSerializationKinds.inc"
22+
#include "clang/Basic/DiagnosticLexKinds.inc"
23+
#include "clang/Basic/DiagnosticParseKinds.inc"
24+
#include "clang/Basic/DiagnosticASTKinds.inc"
25+
#include "clang/Basic/DiagnosticCommentKinds.inc"
26+
#include "clang/Basic/DiagnosticCrossTUKinds.inc"
27+
#include "clang/Basic/DiagnosticSemaKinds.inc"
28+
#include "clang/Basic/DiagnosticAnalysisKinds.inc"
29+
#include "clang/Basic/DiagnosticRefactoringKinds.inc"
30+
#include "clang/Basic/DiagnosticInstallAPIKinds.inc"
31+
// clang-format on

clang/lib/Basic/DiagnosticIDs.cpp

Lines changed: 3 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -37,43 +37,15 @@ struct StaticDiagInfoDescriptionStringTable {
3737
#define DIAG(ENUM, CLASS, DEFAULT_SEVERITY, DESC, GROUP, SFINAE, NOWERROR, \
3838
SHOWINSYSHEADER, SHOWINSYSMACRO, DEFERRABLE, CATEGORY) \
3939
char ENUM##_desc[sizeof(DESC)];
40-
// clang-format off
41-
#include "clang/Basic/DiagnosticCommonKinds.inc"
42-
#include "clang/Basic/DiagnosticDriverKinds.inc"
43-
#include "clang/Basic/DiagnosticFrontendKinds.inc"
44-
#include "clang/Basic/DiagnosticSerializationKinds.inc"
45-
#include "clang/Basic/DiagnosticLexKinds.inc"
46-
#include "clang/Basic/DiagnosticParseKinds.inc"
47-
#include "clang/Basic/DiagnosticASTKinds.inc"
48-
#include "clang/Basic/DiagnosticCommentKinds.inc"
49-
#include "clang/Basic/DiagnosticCrossTUKinds.inc"
50-
#include "clang/Basic/DiagnosticSemaKinds.inc"
51-
#include "clang/Basic/DiagnosticAnalysisKinds.inc"
52-
#include "clang/Basic/DiagnosticRefactoringKinds.inc"
53-
#include "clang/Basic/DiagnosticInstallAPIKinds.inc"
54-
// clang-format on
40+
#include "clang/Basic/DiagnosticIDs.inc"
5541
#undef DIAG
5642
};
5743

5844
const StaticDiagInfoDescriptionStringTable StaticDiagInfoDescriptions = {
5945
#define DIAG(ENUM, CLASS, DEFAULT_SEVERITY, DESC, GROUP, SFINAE, NOWERROR, \
6046
SHOWINSYSHEADER, SHOWINSYSMACRO, DEFERRABLE, CATEGORY) \
6147
DESC,
62-
// clang-format off
63-
#include "clang/Basic/DiagnosticCommonKinds.inc"
64-
#include "clang/Basic/DiagnosticDriverKinds.inc"
65-
#include "clang/Basic/DiagnosticFrontendKinds.inc"
66-
#include "clang/Basic/DiagnosticSerializationKinds.inc"
67-
#include "clang/Basic/DiagnosticLexKinds.inc"
68-
#include "clang/Basic/DiagnosticParseKinds.inc"
69-
#include "clang/Basic/DiagnosticASTKinds.inc"
70-
#include "clang/Basic/DiagnosticCommentKinds.inc"
71-
#include "clang/Basic/DiagnosticCrossTUKinds.inc"
72-
#include "clang/Basic/DiagnosticSemaKinds.inc"
73-
#include "clang/Basic/DiagnosticAnalysisKinds.inc"
74-
#include "clang/Basic/DiagnosticRefactoringKinds.inc"
75-
#include "clang/Basic/DiagnosticInstallAPIKinds.inc"
76-
// clang-format on
48+
#include "clang/Basic/DiagnosticIDs.inc"
7749
#undef DIAG
7850
};
7951

@@ -85,21 +57,7 @@ const uint32_t StaticDiagInfoDescriptionOffsets[] = {
8557
#define DIAG(ENUM, CLASS, DEFAULT_SEVERITY, DESC, GROUP, SFINAE, NOWERROR, \
8658
SHOWINSYSHEADER, SHOWINSYSMACRO, DEFERRABLE, CATEGORY) \
8759
offsetof(StaticDiagInfoDescriptionStringTable, ENUM##_desc),
88-
// clang-format off
89-
#include "clang/Basic/DiagnosticCommonKinds.inc"
90-
#include "clang/Basic/DiagnosticDriverKinds.inc"
91-
#include "clang/Basic/DiagnosticFrontendKinds.inc"
92-
#include "clang/Basic/DiagnosticSerializationKinds.inc"
93-
#include "clang/Basic/DiagnosticLexKinds.inc"
94-
#include "clang/Basic/DiagnosticParseKinds.inc"
95-
#include "clang/Basic/DiagnosticASTKinds.inc"
96-
#include "clang/Basic/DiagnosticCommentKinds.inc"
97-
#include "clang/Basic/DiagnosticCrossTUKinds.inc"
98-
#include "clang/Basic/DiagnosticSemaKinds.inc"
99-
#include "clang/Basic/DiagnosticAnalysisKinds.inc"
100-
#include "clang/Basic/DiagnosticRefactoringKinds.inc"
101-
#include "clang/Basic/DiagnosticInstallAPIKinds.inc"
102-
// clang-format on
60+
#include "clang/Basic/DiagnosticIDs.inc"
10361
#undef DIAG
10462
};
10563

clang/tools/diagtool/DiagnosticNames.cpp

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -25,27 +25,13 @@ llvm::ArrayRef<DiagnosticRecord> diagtool::getBuiltinDiagnosticsByName() {
2525

2626
// FIXME: Is it worth having two tables, especially when this one can get
2727
// out of sync easily?
28-
// clang-format off
2928
static const DiagnosticRecord BuiltinDiagnosticsByID[] = {
3029
#define DIAG(ENUM, CLASS, DEFAULT_MAPPING, DESC, GROUP, SFINAE, NOWERROR, \
3130
SHOWINSYSHEADER, SHOWINSYSMACRO, DEFER, CATEGORY) \
3231
{#ENUM, diag::ENUM, STR_SIZE(#ENUM, uint8_t)},
33-
#include "clang/Basic/DiagnosticCommonKinds.inc"
34-
#include "clang/Basic/DiagnosticDriverKinds.inc"
35-
#include "clang/Basic/DiagnosticFrontendKinds.inc"
36-
#include "clang/Basic/DiagnosticSerializationKinds.inc"
37-
#include "clang/Basic/DiagnosticLexKinds.inc"
38-
#include "clang/Basic/DiagnosticParseKinds.inc"
39-
#include "clang/Basic/DiagnosticASTKinds.inc"
40-
#include "clang/Basic/DiagnosticCommentKinds.inc"
41-
#include "clang/Basic/DiagnosticCrossTUKinds.inc"
42-
#include "clang/Basic/DiagnosticSemaKinds.inc"
43-
#include "clang/Basic/DiagnosticAnalysisKinds.inc"
44-
#include "clang/Basic/DiagnosticRefactoringKinds.inc"
45-
#include "clang/Basic/DiagnosticInstallAPIKinds.inc"
32+
#include "clang/Basic/DiagnosticIDs.inc"
4633
#undef DIAG
4734
};
48-
// clang-format on
4935

5036
static bool orderByID(const DiagnosticRecord &Left,
5137
const DiagnosticRecord &Right) {
@@ -55,6 +41,13 @@ static bool orderByID(const DiagnosticRecord &Left,
5541
const DiagnosticRecord &diagtool::getDiagnosticForID(short DiagID) {
5642
DiagnosticRecord Key = {nullptr, DiagID, 0};
5743

44+
// The requirement for lower_bound to produce a valid result it is
45+
// enough if the BuiltinDiagnosticsByID is partitioned (by DiagID),
46+
// but as we want this function to work for all possible values of
47+
// DiagID sent in as argument it is better to right away check if
48+
// BuiltinDiagnosticsByID is sorted.
49+
assert(llvm::is_sorted(BuiltinDiagnosticsByID, orderByID) &&
50+
"IDs in BuiltinDiagnosticsByID must be sorted.");
5851
const DiagnosticRecord *Result =
5952
llvm::lower_bound(BuiltinDiagnosticsByID, Key, orderByID);
6053
assert(Result && "diagnostic not found; table may be out of date");

0 commit comments

Comments
 (0)