summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/cmocka.h24
-rw-r--r--src/cmocka.c2
2 files changed, 26 insertions, 0 deletions
diff --git a/include/cmocka.h b/include/cmocka.h
index 193af52..70dd603 100644
--- a/include/cmocka.h
+++ b/include/cmocka.h
@@ -152,6 +152,28 @@ int __stdcall IsDebuggerPresent();
#define CMOCKA_NORETURN
#endif
+/**
+ * @def CMOCKA_NO_ACCESS_ATTRIBUTE
+ *
+ * Function attribute that tells the compiler that we never access the value
+ * of a/b, just the pointer address.
+ *
+ * Without this, newer compilers like GCC-12 will print
+ * `-Wmaybe-uninitialized` warnings.
+ *
+ * @see
+ * https://gcc.gnu.org/onlinedocs/gcc-12.2.0/gcc/Common-Function-Attributes.html#Common-Function-Attributes
+ */
+#ifdef __has_attribute
+#if __has_attribute(access)
+#define CMOCKA_NO_ACCESS_ATTRIBUTE \
+ __attribute__((access(none, 1), access(none, 2)))
+#endif
+#endif
+#ifndef CMOCKA_NO_ACCESS_ATTRIBUTE
+#define CMOCKA_NO_ACCESS_ATTRIBUTE
+#endif
+
#define WILL_RETURN_ALWAYS -1
#define WILL_RETURN_ONCE -2
@@ -2923,10 +2945,12 @@ void _assert_uint_not_equal(const uintmax_t a,
const uintmax_t b,
const char * const file,
const int line);
+CMOCKA_NO_ACCESS_ATTRIBUTE
void _assert_ptr_equal(const void *a,
const void *b,
const char *const file,
const int line);
+CMOCKA_NO_ACCESS_ATTRIBUTE
void _assert_ptr_not_equal(const void *a,
const void *b,
const char *const file,
diff --git a/src/cmocka.c b/src/cmocka.c
index 211c315..43652d6 100644
--- a/src/cmocka.c
+++ b/src/cmocka.c
@@ -1365,6 +1365,7 @@ static bool int_values_not_equal_display_error(const intmax_t left,
/* Returns 1 if the specified pointers are equal. If the pointers are not equal
* an error is displayed and 0 is returned. */
+CMOCKA_NO_ACCESS_ATTRIBUTE
static bool ptr_values_equal_display_error(const void *left, const void *right)
{
const bool equal = left == right;
@@ -1376,6 +1377,7 @@ static bool ptr_values_equal_display_error(const void *left, const void *right)
/* Returns 1 if the specified pointers are equal. If the pointers are not equal
* an error is displayed and 0 is returned. */
+CMOCKA_NO_ACCESS_ATTRIBUTE
static bool ptr_values_not_equal_display_error(const void *left,
const void *right)
{