summaryrefslogtreecommitdiffstats
path: root/src/config.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/config.h')
-rw-r--r--src/config.h49
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