[clang] [analyzer] Detect dangling pointers passed to function calls (PR #211045)

via cfe-commits cfe-commits at lists.llvm.org
Wed Jul 22 07:34:11 PDT 2026


================
@@ -84,3 +84,31 @@ void test_case_seven() {
   // expected-warning at -1 {{Use of 'i' after its lifetime ended}}
   // expected-note at -2    {{Use of 'i' after its lifetime ended}}
 }
+
+void passing_dangling_ptr_to_opaque_func() {
+  int *ptr = nullptr;
+  {
+    int num = 5;
+    ptr = #
+  }
+  // expected-note at -1 {{'num' is destroyed here}}
+  escape(ptr);
+  // expected-warning at -1 {{Use of 'num' after its lifetime ended}}
+  // expected-note at -2    {{Use of 'num' after its lifetime ended}}
----------------
isuckatcs wrote:

Nit: we probably should not eagerly assume that the pointer is dereferenced, or at least add a note about it.

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


More information about the cfe-commits mailing list