From: Lucas De Marchi Date: Sat, 9 Nov 2024 22:53:22 +0000 (-0600) Subject: shared: Ignore clang-analyzer on cleanup attribute X-Git-Tag: v34~115 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=317f89a59a428af714558f840cf7750a3900c8cd;p=thirdparty%2Fkmod.git shared: Ignore clang-analyzer on cleanup attribute 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 Link: https://github.com/kmod-project/kmod/pull/233 --- diff --git a/shared/macro.h b/shared/macro.h index 28ec61af..2def79f2 100644 --- a/shared/macro.h +++ b/shared/macro.h @@ -43,10 +43,19 @@ #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) {