[clang] [analyzer] Fix checker message order in the program state dump (PR #235091)

DonĂ¡t Nagy via cfe-commits cfe-commits at lists.llvm.org
Mon Oct 26 03:33:08 PDT 2026


================
@@ -858,11 +858,21 @@ void CheckerManager::runCheckersForPrintStateJson(raw_ostream &Out,
   ++Space;
   bool HasMessage = false;
 
-  // Store the last CheckerTag.
-  const void *LastCT = nullptr;
+  std::vector<CheckerBackend *> CheckerBackends;
   for (const auto &CT : CheckerTags) {
+    CheckerBackend *CB = CT.second.get();
+    CheckerBackends.push_back(CB);
+  }
+  llvm::sort(CheckerBackends,
+             [](const CheckerBackend *First, const CheckerBackend *Last) {
+               return First->getDebugTag() < Last->getDebugTag();
+             });
+
+  // Store the last CheckerBackend.
----------------
NagyDonat wrote:

```suggestion
  // Store the last CheckerBackend that had a message, because we need to avoid
  // printing a comma after it.
```
The old comment was actively misleading: the last checker backend would be accessible as `*CheckerBackends.rbegin()` and then you wouldn't need this fiddly variable.

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


More information about the cfe-commits mailing list