[clang] [analyzer] Fix false positive for stack-addr leak on simple param ptr (PR #107003)

Balazs Benics via cfe-commits cfe-commits at lists.llvm.org
Tue Sep 3 05:06:40 PDT 2024


================
@@ -791,3 +791,58 @@ void global_ptr_to_ptr() {
   *global_pp = nullptr;
 }
 } // namespace leaking_via_indirect_global_invalidated
+
+namespace not_leaking_via_simple_ptr {
+void simple_ptr(const char *p) {
+  char tmp;
+  p = &tmp; // no-warning
+}
+
+void ref_ptr(const char *&p) {
+  char tmp;
+  p = &tmp; // expected-warning{{variable 'tmp' is still referred to by the caller variable 'p'}}
+}
+
+struct S {
+  const char *p;
----------------
steakhal wrote:

Ah, yes. Makes sense! All good then.

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


More information about the cfe-commits mailing list