[clang] [clang][analyzer] Simplify code of StreamChecker (NFC). (PR #79312)

Balazs Benics via cfe-commits cfe-commits at lists.llvm.org
Thu Jan 25 03:07:15 PST 2024


steakhal wrote:

> I'm seconding the suggestions of @steakhal, and in particular I agree with
> 
> > I'd also advise against using more callables bundled with CallDescriptions. They make debugging code more difficult, as the control-flow would become also data-dependent. I'd suggest other ways to generalize.
> 
> Instead of creating this shared framework that calls different callbacks depending on the checked function, consider keeping separate top-level evaluator functions that rely on a shared set of smaller tool-like helper functions.

One more not about composability.
In general, `addTransition` calls don't compose, thus limits reusability.
For example, `preReadWrite` should be reusable from other precondition handlers, such that the new one can just call `preReadWrite` and then do some other more specialized checks. However, once a handler calls `addTransition` we are done. We no longer can simply wrap it, aka. compose with other functionalities.
Consequently, I'd suggest to have some common pattern, such as return state pointers, or NULL if an error was reported. And leave the `addTransition` to the caller - if they chose to call it.

`eval*` handlers are more difficult to compose, given that they also need to bind the return value and apply their sideffects, but I believe we could achieve similar objectives there too (thus, have refined, composable handlers, combined in useful ways).

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


More information about the cfe-commits mailing list