[clang] [analyzer] Model GCC 'cleanup' attribute function calls (PR #221110)

Arseniy Zaostrovnykh via cfe-commits cfe-commits at lists.llvm.org
Fri Sep 11 03:04:42 PDT 2026


================
@@ -35,3 +35,19 @@ void leak_through_cleanup_frame(void) {
   p = malloc(10); // expected-note {{Memory is allocated}}
 } // expected-warning {{Potential leak of memory pointed to by 'p'}}
   // expected-note at -1 {{Potential leak of memory pointed to by 'p'}}
+
+//===----------------------------------------------------------------------===//
+// With the attribute split across lines, the "Calling ..." note is anchored
+// at the `cleanup` keyword, not at the function name on the next line.
+//===----------------------------------------------------------------------===//
+
+static void multiline_cleanup(int **p) {
+  **p = 1; // expected-warning {{Dereference of null pointer}}
+           // expected-note at -1 {{Dereference of null pointer}}
+}
+
+void null_deref_in_multiline_cleanup_attr(void) {
+  int *p __attribute__((cleanup( // expected-note {{Calling 'multiline_cleanup'}}
+      multiline_cleanup)));
+  p = 0; // expected-note {{Null pointer value stored to 'p'}}
+}
----------------
necto wrote:

I read "multiple_cleanup" as it either cleans up multiple resources, or there are multiple clean up functions. here I guess it should actually mean that the attribute is split into multiple lines

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


More information about the cfe-commits mailing list