diff options
author | Tavian Barnes <tavianator@tavianator.com> | 2023-11-09 15:16:04 -0500 |
---|---|---|
committer | Tavian Barnes <tavianator@tavianator.com> | 2023-11-09 15:35:40 -0500 |
commit | e25261a90222de75781726a93ab809c660208afd (patch) | |
tree | eed200bdebfd981821754a6bb154e3db30a109f5 /src/config.h | |
parent | c745df94a182b8a569cb833ecfbe8da33bf01f98 (diff) | |
download | bfs-e25261a90222de75781726a93ab809c660208afd.tar.xz |
config: Add (de)allocator attributes
Diffstat (limited to 'src/config.h')
-rw-r--r-- | src/config.h | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/src/config.h b/src/config.h index b95abaa..db62ef8 100644 --- a/src/config.h +++ b/src/config.h @@ -185,6 +185,17 @@ #endif /** + * Warn if a value is unused. + */ +#if __has_c_attribute(nodiscard) +# define attr_nodiscard [[nodiscard]] +#elif __has_attribute(nodiscard) +# define attr_nodiscard __attribute__((nodiscard)) +#else +# define attr_nodiscard +#endif + +/** * Hint to avoid inlining a function. */ #if __has_attribute(noinline) @@ -212,6 +223,44 @@ #endif /** + * Annotates allocator-like functions. + */ +#if __has_attribute(malloc) +# if __clang__ +# define attr_malloc(...) attr_nodiscard __attribute__((malloc)) +# else +# define attr_malloc(...) attr_nodiscard __attribute__((malloc(__VA_ARGS__))) +# endif +#else +# define attr_malloc(...) attr_nodiscard +#endif + +/** + * Specifies that a function returns allocations with a given alignment. + */ +#if __has_attribute(alloc_align) +# define attr_alloc_align(param) __attribute__((alloc_align(param))) +#else +# define attr_alloc_align(param) +#endif + +/** + * Specifies that a function returns allocations with a given size. + */ +#if __has_attribute(alloc_size) +# define attr_alloc_size(...) __attribute__((alloc_size(__VA_ARGS__))) +#else +# define attr_alloc_size(...) +#endif + +/** + * Shorthand for attr_alloc_align() and attr_alloc_size(). + */ +#define attr_aligned_alloc(align, ...) \ + attr_alloc_align(align) \ + attr_alloc_size(__VA_ARGS__) + +/** * Check if function multiversioning via GNU indirect functions (ifunc) is supported. */ #ifndef BFS_USE_TARGET_CLONES |