[clang] [analyzer] Skip LifetimeEnd nodes in getNextStmtForDiagnostics (PR #228045)

Arseniy Zaostrovnykh via cfe-commits cfe-commits at lists.llvm.org
Fri Oct 2 00:50:41 PDT 2026


================
@@ -0,0 +1,51 @@
+// RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.ExprInspection,alpha.core.DanglingPtrDeref -analyzer-config cfg-lifetime=true -analyzer-output=text -verify %s
+
+void clang_analyzer_warnIfReached();
+
+// Enabling CFG lifetime-end elements should not cause regression in the
+// path notes. The loop exit path note must point to the next executed
+// statmeent and not back to the loop.
+void testPathNotesWithLoopScopeEnd() {
+  int *p = nullptr;
+  for (int i = 0; i < 3; ++i) {
+  // expected-note at -1 3 {{Loop condition is true.  Entering loop body}}
+  // expected-note at -2   {{The value 2 is assigned to 'i'}}
+  // expected-note at -3   {{Loop condition is false. Execution continues on line 17}}
+    p = &i; // expected-note {{Value assigned to 'p'}}
+  }
+  // expected-note at -1 {{'i' is destroyed here}}
+  *p = 4;
+  // expected-warning at -1 {{Use of 'i' after its lifetime ended}}
+  // expected-note at -2    {{Use of 'i' after its lifetime ended}}
+}
+
+void testPathNotesWithBlockScopeEnd() {
+  int *p = nullptr;
+  {
+    int n = 0;
+    while (n < 3) {
+    // expected-note at -1 3 {{Loop condition is true.  Entering loop body}}
+    // expected-note at -2   {{Loop condition is false. Execution continues on line 34}}
+      p = &n; // expected-note {{Value assigned to 'p'}}
+      ++n;    // expected-note {{The value 2 is assigned to 'n'}}
+    }
+  }
+  // expected-note at -1 {{'n' is destroyed here}}
----------------
necto wrote:

```suggestion
  } // expected-note {{'n' is destroyed here}}
```

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


More information about the cfe-commits mailing list