[clang] [analyzer] Workaround for unintended slowdown (scope increase) (PR #136720)
Donát Nagy via cfe-commits
cfe-commits at lists.llvm.org
Wed Apr 23 06:21:55 PDT 2025
================
@@ -0,0 +1,198 @@
+// RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.ExprInspection -verify=expected,default %s
+// RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.ExprInspection -analyzer-config legacy-inlining-prevention=false -verify=expected,disabled %s
+
+int getNum(void); // Get an opaque number.
+
+void clang_analyzer_numTimesReached(void);
+void clang_analyzer_dump(int arg);
+
+//-----------------------------------------------------------------------------
+// Simple case: inlined function never reaches `analyzer-max-loop`.
+
+int inner_simple(void) {
+ clang_analyzer_numTimesReached(); // expected-warning {{2}}
+ return 42;
+}
+
+int outer_simple(void) {
+ int x = inner_simple();
+ int y = inner_simple();
+ return 53 / (x - y); // expected-warning {{Division by zero}}
+}
+
+//-----------------------------------------------------------------------------
+// Inlined function always reaches `analyzer-max-loop`.
+
+int inner_fixed_loop_1(void) {
+ int i;
+ clang_analyzer_numTimesReached(); // expected-warning {{1}}
+ for (i = 0; i < 10; i++);
+ clang_analyzer_numTimesReached(); // no-warning
----------------
NagyDonat wrote:
I would be careful with this FIXME -- if somebody follows it and fixes this issue (e.g. by enabling `unroll-loops` by default) we could get yet another large slowdown when less loops hit the `analyzer-max-loop` limit, less functions end on the "don't inline" list and more entry points spend their budget.
Obviously in an ideal world an empty loop like this shouldn't stop the analyzer – but we must replace this awkward loop-based inlining restriction with a more robust heuristic before we can do that.
https://github.com/llvm/llvm-project/pull/136720
More information about the cfe-commits
mailing list