Skip to content

Commit

Permalink
shared: Ignore clang-analyzer on cleanup attribute
Browse files Browse the repository at this point in the history
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 <[email protected]>
Link: #233
  • Loading branch information
lucasdemarchi committed Nov 12, 2024
1 parent 4063401 commit 317f89a
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion shared/macro.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down

0 comments on commit 317f89a

Please sign in to comment.