[clang] [clang][StaticAnalyzer] Crash on loop unrolling mode (PR #82089)

Balazs Benics via cfe-commits cfe-commits at lists.llvm.org
Wed Feb 21 23:46:31 PST 2024


================
@@ -0,0 +1,11 @@
+// RUN: %clang_analyze_cc1 -analyzer-checker=core -analyzer-config unroll-loops=true -verify %s
+
+void test_escaping_on_var_before_switch_case_no_crash(int c) {
+  switch (c) {
+    int i; // expected error{{Reached root without finding the declaration of VD}}
+    case 0: {
+      for (i = 0; i < 16; i++) {}
+      break;
+    }
+  }
+}
----------------
steakhal wrote:

It took me some time to realize that its not a verify expectation.
BTW in this shape, this test fails.

```suggestion
// RUN: %clang_analyze_cc1 -analyzer-checker=core -analyzer-config unroll-loops=true -verify %s
// expected-no-diagnostics

void test_escaping_on_var_before_switch_case_no_crash(int c) {
  // https://github.com/llvm/llvm-project/issues/68819
  switch (c) {
    int i; // no-crash: The declaration of `i` is found here.
    case 0: {
      for (i = 0; i < 16; i++) {}
      break;
    }
  }
}
```

I'd also suggest to rename the test file to highlight that this is only for loop unrolling. Or maybe even better, just append this to the end of `clang/test/Analysis/loop-unrolling.cpp`.

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


More information about the cfe-commits mailing list