]> git.ipfire.org Git - thirdparty/kmod.git/commitdiff
shared: Ignore clang-analyzer on cleanup attribute
authorLucas De Marchi <lucas.de.marchi@gmail.com>
Sat, 9 Nov 2024 22:53:22 +0000 (16:53 -0600)
committerLucas De Marchi <lucas.de.marchi@gmail.com>
Tue, 12 Nov 2024 00:11:11 +0000 (18:11 -0600)
When using the cleanup attribute we know we are not leaking that
allocation. Most of the time the assignment is together with the
declaration, so we can simplify additional clang annotations by making
the cleanup attribute imply clang::suppress.

In cases declaration and assignment are not together, provide
_clang_suppress_alloc_ to annotate the code. That is only defined for
clang analyzer.

Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/233
shared/macro.h

index 28ec61af64b4431969f8b15167a9fbf684799be5..2def79f2b6b2bbc2cc77c2643e08046ac412dd74 100644 (file)
 #define _must_check_ __attribute__((warn_unused_result))
 #define _printf_format_(a, b) __attribute__((format(printf, a, b)))
 #define _always_inline_ __inline__ __attribute__((always_inline))
+
+#if defined(__clang_analyzer__)
+#define _clang_suppress_ __attribute__((suppress))
+#define _clang_suppress_alloc_ __attribute__((suppress))
+#else
+#define _clang_suppress_
+#define _clang_suppress_alloc_
+#endif
+
 #define _nonnull_(...) __attribute__((nonnull(__VA_ARGS__)))
 #define _nonnull_all_ __attribute__((nonnull))
 
-#define _cleanup_(x) __attribute__((cleanup(x)))
+#define _cleanup_(x) _clang_suppress_alloc_ __attribute__((cleanup(x)))
 
 static inline void freep(void *p)
 {