[clang] [analyzer] Allow recursive functions to be trivial. (PR #91876)

Artem Dergachev via cfe-commits cfe-commits at lists.llvm.org
Thu May 23 18:36:40 PDT 2024


================
@@ -231,6 +231,15 @@ class RefCounted {
   void method();
   void someFunction();
   int otherFunction();
+  unsigned recursiveTrivialFunction(int n) { return !n ? 1 : recursiveTrivialFunction(n - 1);  }
+  unsigned recursiveComplexFunction(int n) { return !n ? otherFunction() : recursiveComplexFunction(n - 1);  }
+  unsigned mutuallyRecursiveFunction1(int n) { return n < 0 ? 1 : (n % 2 ? mutuallyRecursiveFunction2(n - 2) : mutuallyRecursiveFunction1(n - 1)); }
+  unsigned mutuallyRecursiveFunction2(int n) { return n < 0 ? 1 : (n % 3 ? mutuallyRecursiveFunction2(n - 3) : mutuallyRecursiveFunction1(n - 2)); }
+  unsigned mutuallyRecursiveFunction3(int n) { return n < 0 ? 1 : (n % 5 ? mutuallyRecursiveFunction3(n - 5) : mutuallyRecursiveFunction4(n - 3)); }
+  unsigned mutuallyRecursiveFunction4(int n) { return n < 0 ? 1 : (n % 7 ? otherFunction() : mutuallyRecursiveFunction3(n - 3)); }
+  unsigned mutuallyRecursiveFunction5(unsigned n) { return n > 100 ? 2 : (n % 2 ? mutuallyRecursiveFunction5(n + 1) : mutuallyRecursiveFunction6(n + 2)); }
----------------
haoNoQ wrote:

I think it may be a good idea to add a direct test for @MitalAshok's example.
```c++
void foo() { bar(); something_non_trivial(); }
void bar() { foo(); }

void test() {
  foo();
  bar();
}
```
where none of the functions call themselves directly. I'm still not quite sure whether we're correctly confirming that `bar()` is non-trivial here, when we start the analysis from `foo()`.

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


More information about the cfe-commits mailing list