[clang] [LifetimeSafety] Analyze blocks that cannot reach the exit in liveness (PR #240890)

Gábor Horváth via cfe-commits cfe-commits at lists.llvm.org
Wed Nov 11 03:59:45 PST 2026


================
@@ -339,6 +339,59 @@ void loop_with_break_gsl(bool cond) {
   v.use();      // expected-note {{later used here}}
 }
 
+void infinite_for_loop() {
+  MyObj safe;
+  MyObj* p = &safe;
+  {
+    MyObj s;
+    p = &s;     // expected-warning {{local variable 's' does not live long enough}}
+  }             // expected-note {{local variable 's' is destroyed here}}
+  for (;;)
+    use(*p);    // expected-note {{later used here}}
+}
+
+// GH222273
+void infinite_while_loop(bool cond) {
+  while (true) {
+    MyObj* p;
+    if (cond) {
+      MyObj s;
+      p = &s;   // expected-warning {{local variable 's' does not live long enough}}
+    }           // expected-note {{local variable 's' is destroyed here}}
+    use(*p);    // expected-note {{later used here}}
+  }
----------------
Xazax-hun wrote:

Added! 

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


More information about the cfe-commits mailing list