[clang] [Clang] enhance loop analysis to handle variable changes inside lambdas (PR #135573)
Aaron Ballman via cfe-commits
cfe-commits at lists.llvm.org
Mon May 19 05:59:28 PDT 2025
AaronBallman wrote:
> > I question if -Wloop-analysis should be completely rewritten using dataflow analysis, rather than AST based matching.
>
> should changes inside functions be handled in the following cases?
>
> https://github.com/llvm/llvm-project/blob/db0f754c5af8e6c96770533520bf8b17fc0dc977/clang/test/SemaCXX/warn-loop-analysis.cpp#L23
>
> https://github.com/llvm/llvm-project/blob/db0f754c5af8e6c96770533520bf8b17fc0dc977/clang/test/SemaCXX/warn-loop-analysis.cpp#L8
>
> > rewritten using dataflow analysis
>
> [`ExprMutationAnalyzer`](https://github.com/llvm/llvm-project/blob/main/clang/lib/Analysis/ExprMutationAnalyzer.cpp)?
>
> /cc @AaronBallman @zyn0217 @cor3ntin
Oh that's a fun case. I think the behavior of that test makes sense if there was no definition for `by_ref` because we'd want to assume the non-`const` reference parameter is modified. But because we can see the definition for `by_ref`, we know the body is empty and so the variable is not modified, and so issuing the diagnostic there would be reasonable. WDYT?
https://github.com/llvm/llvm-project/pull/135573
More information about the cfe-commits
mailing list