[clang] [analyzer] Allow recursive functions to be trivial. (PR #91876)
Mital Ashok via cfe-commits
cfe-commits at lists.llvm.org
Sun May 12 11:46:58 PDT 2024
MitalAshok wrote:
You should add a test for mutually recursive functions. I suspect something like this doesn't work:
```c++
int non_trivial();
int f(bool b) { return g(!b) + non_trivial(); }
int g(bool b) { return b ? f(b) : 1; }
getFieldTrivial().f(true); // expected-warning {{...}}
getFieldTrivial().g(true); // expected-warning {{...}}
```
Since when analyzing `f`, `f` enters the cache as trivial, `g` is analyzed and sees `f` in the cache as trivial, so `g` is marked trivial, but then `f` is marked as non-trivial (so `g` should have been marked as non-trivial, but is marked trivial).
If that is an issue, one way to do this "properly" would be to create a graph, and a function is non-trivial if it has a path to a non-trivial function (this might be too expensive to implement directly). Or we could special case simple recursion only, by changing `TrivialFunctionAnalysisVisitor` to not call `isTrivialImpl` for the current function only.
https://github.com/llvm/llvm-project/pull/91876
More information about the cfe-commits
mailing list