[clang] [diagtool] Make the BuiltinDiagnosticsByID table sorted (PR #120321)

Karl-Johan Karlsson via cfe-commits cfe-commits at lists.llvm.org
Sun Dec 29 15:00:35 PST 2024


================
@@ -23,28 +23,29 @@ llvm::ArrayRef<DiagnosticRecord> diagtool::getBuiltinDiagnosticsByName() {
   return llvm::ArrayRef(BuiltinDiagnosticsByName);
 }
 
-
 // FIXME: Is it worth having two tables, especially when this one can get
 // out of sync easily?
+// clang-format off
 static const DiagnosticRecord BuiltinDiagnosticsByID[] = {
 #define DIAG(ENUM, CLASS, DEFAULT_MAPPING, DESC, GROUP, SFINAE, NOWERROR,      \
              SHOWINSYSHEADER, SHOWINSYSMACRO, DEFER, CATEGORY)                 \
   {#ENUM, diag::ENUM, STR_SIZE(#ENUM, uint8_t)},
 #include "clang/Basic/DiagnosticCommonKinds.inc"
-#include "clang/Basic/DiagnosticCrossTUKinds.inc"
 #include "clang/Basic/DiagnosticDriverKinds.inc"
 #include "clang/Basic/DiagnosticFrontendKinds.inc"
 #include "clang/Basic/DiagnosticSerializationKinds.inc"
 #include "clang/Basic/DiagnosticLexKinds.inc"
 #include "clang/Basic/DiagnosticParseKinds.inc"
 #include "clang/Basic/DiagnosticASTKinds.inc"
 #include "clang/Basic/DiagnosticCommentKinds.inc"
+#include "clang/Basic/DiagnosticCrossTUKinds.inc"
----------------
karka228 wrote:

Verify the changed include order by adding an assert in getDiagnosticForID below:
```
  // The requirement for lower_bound to produce a valid result it is
  // enough if the BuiltinDiagnosticsByID is partitioned (by DiagID),
  // but as we want this function to work for all possible values of
  // DiagID sent in as argument it is better to right away check if
  // BuiltinDiagnosticsByID is sorted.
  assert(llvm::is_sorted(BuiltinDiagnosticsByID, orderByID) &&
	 "IDs in BuiltinDiagnosticsByID must be sorted.");
```

https://github.com/llvm/llvm-project/pull/120321


More information about the cfe-commits mailing list