[clang] [analyzer] Fix VisitArrayInitLoopExpr, remove NodeBuilder (PR #196974)

Donát Nagy via cfe-commits cfe-commits at lists.llvm.org
Tue May 12 05:04:12 PDT 2026


NagyDonat wrote:

@isuckatcs This commit is part of a large refactoring project (already 20+ merged commits) to eliminate the `NodeBuilder` types from the static analyzer codebase. (I already removed the classes `StmtNodeBuilder`, `BranchNodeBuilder`, `SwitchNodeBuilder` and `IndirectGotoNodeBuilder` and perhaps halfway through the removal of the frequently used plain `NodeBuilder`s.)

This class hierarchy had contained lots of overengineered dead code and fulfilled three unrelated purposes:
- Providing access to a `NodeBuilderContext` which "knows" the current `LocationContext` and `CFGBlock`. (This information was used for e.g. conjuring symbols, but it isn't relevant for creating nodes.)
- Manging a set of `ExplodedNode`s. This performed set operations in an obscure and confusing way, with many pointless insert-and-then-remove sequences. As I'm refactoring the code I often clearly see that the developers didn't understand this logic, blindly followed the example of other code fragments and inserted (or copy-pasted) completely pointless `NodeBuilder` operations. (This is not the developers' fault: I only achieved a complete understanding of `NodeBuilder` logic after spending months on reading it and deleting dead code.)
- Actually making new `ExplodedNode`s. This is useful, but creating the `NodeBuilder` is a pointless boilerplate step – [a single method call](https://github.com/llvm/llvm-project/pull/182377) is sufficient to create a node.

> Also, how did this issue come up? Did you run some PreStmt checks on these expressions and received a wrong egraph? In that case please attach what that looked like with and without this patch, so it is easier to understand why the change was necessary considering that there are no tests to verify it.

I found this bug (and several other ones [[1]](https://github.com/llvm/llvm-project/pull/191168) [[2]](https://github.com/llvm/llvm-project/pull/187020) [[3]](https://github.com/llvm/llvm-project/pull/196313)) while I was refactoring the engine to get rid of `NodeBuilder`s.

As I describe in the commit message, there is no `PreStmt<ArrayInitLoop>` checker (neither upstream nor under private development AFAIK), so the buggy logic doesn't cause observable buggy behavior – but it is still buggy and we should still fix it.

--------

> IUC the patch itself is changing one word (`Pred` -> `Node`). This should be 1 commit with the `[analyzer]` tag.
> 
> The other changes are cosmetics, and should be combined into one `[NFC]` commit.

I feel that a single-word change is too small to be a standalone commit, so I prefer bundling it together in this PR (which will be squashed into a single commit) with the `NodeBuilder` removal (which was the original goal of touching this code). I can separate the bugfix and the NFC parts, if you really want.

@steakhal WDYT about this? Should I move the logic change into a separate commit?

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


More information about the cfe-commits mailing list