[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:07 PDT 2026
https://github.com/NagyDonat commented:
LGTM overall, but I have some minor code quality suggestions.
Perhaps also consider rewriting this whole algorithm in a more straightforward and functional manner:
1. Declare a vector `std::vector<std::pair<std::string, std::string>> CheckerMsgs;`
2. Foreach `CT` in `CheckerTags`, calculate the corresponding message (with `printState`), and if it is nonempty, then push the pair `{CT->getDebugTag(), <the message>}` to Contents.
3. Sort `CheckerMsgs` (the default lexicographical order should be equivalent to what you're doing now).
4. Loop over `CheckerMsgs` and print its elements with JSON formatting.
You won't need `HasMessage` because you can test whether `CheckerMsgs` is empty. You won't need `LastCB` because you can access the last element of `CheckerMsgs` e.g. as `*CheckerMsgs.rbegin()`.
As this is just a debug printout, keeping the current tricky logic is also fine – decide whether you want to spend extra time on this rewrite.
https://github.com/llvm/llvm-project/pull/235091
More information about the cfe-commits
mailing list