Skip to content

Commit 1ad62a9

Browse files
committed
[diagtool] Make the BuiltinDiagnosticsByID table sorted
When building with -DLLVM_ENABLE_EXPENSIVE_CHECKS=ON with a recent libstdc++ (e.g. from gcc 13.3.0) the testcase clang/test/Misc/warning-flags-tree.c fail with the message: + diagtool tree --internal .../include/c++/13.3.0/bits/stl_algo.h:2013: In function: _ForwardIterator std::lower_bound(_ForwardIterator, _ForwardIterator, const _Tp &, _Compare) [_ForwardIterator = const diagtool::DiagnosticRecord *, _Tp = diagtool::DiagnosticRecord, _Compare = bool (*)(const diagtool::DiagnosticRecord &, const diagtool::DiagnosticRecord &)] Error: elements in iterator range [first, last) are not partitioned by the predicate __comp and value __val. Objects involved in the operation: iterator "first" @ 0x7ffea8ef2fd8 { } iterator "last" @ 0x7ffea8ef2fd0 { } The reason for this error is that std::lower_bound is called on BuiltinDiagnosticsByID without it being entirely sorted. Calling std::lower_bound If the range is not sorted, the behavior of this function is undefined. This is detected when building with expensive checks. To make BuiltinDiagnosticsByID sorted we need to slightly change the order the inc-files are included.
1 parent 9f231a8 commit 1ad62a9

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

clang/tools/diagtool/DiagnosticNames.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,28 +23,29 @@ llvm::ArrayRef<DiagnosticRecord> diagtool::getBuiltinDiagnosticsByName() {
2323
return llvm::ArrayRef(BuiltinDiagnosticsByName);
2424
}
2525

26-
2726
// FIXME: Is it worth having two tables, especially when this one can get
2827
// out of sync easily?
28+
// clang-format off
2929
static const DiagnosticRecord BuiltinDiagnosticsByID[] = {
3030
#define DIAG(ENUM, CLASS, DEFAULT_MAPPING, DESC, GROUP, SFINAE, NOWERROR, \
3131
SHOWINSYSHEADER, SHOWINSYSMACRO, DEFER, CATEGORY) \
3232
{#ENUM, diag::ENUM, STR_SIZE(#ENUM, uint8_t)},
3333
#include "clang/Basic/DiagnosticCommonKinds.inc"
34-
#include "clang/Basic/DiagnosticCrossTUKinds.inc"
3534
#include "clang/Basic/DiagnosticDriverKinds.inc"
3635
#include "clang/Basic/DiagnosticFrontendKinds.inc"
3736
#include "clang/Basic/DiagnosticSerializationKinds.inc"
3837
#include "clang/Basic/DiagnosticLexKinds.inc"
3938
#include "clang/Basic/DiagnosticParseKinds.inc"
4039
#include "clang/Basic/DiagnosticASTKinds.inc"
4140
#include "clang/Basic/DiagnosticCommentKinds.inc"
41+
#include "clang/Basic/DiagnosticCrossTUKinds.inc"
4242
#include "clang/Basic/DiagnosticSemaKinds.inc"
4343
#include "clang/Basic/DiagnosticAnalysisKinds.inc"
4444
#include "clang/Basic/DiagnosticRefactoringKinds.inc"
4545
#include "clang/Basic/DiagnosticInstallAPIKinds.inc"
4646
#undef DIAG
4747
};
48+
// clang-format on
4849

4950
static bool orderByID(const DiagnosticRecord &Left,
5051
const DiagnosticRecord &Right) {

0 commit comments

Comments
 (0)