* [PATCH] sparse: add built-in atomic memory access identifiers
[not found] ` <e92f5ecc-097b-401b-8554-6d3ada6be667@linaro.org>
@ 2013-12-11 21:00 ` Kim Phillips
2013-12-21 17:22 ` Christopher Li
0 siblings, 1 reply; 2+ messages in thread
From: Kim Phillips @ 2013-12-11 21:00 UTC (permalink / raw)
To: linux-sparse
Cc: lng-odp, bill.fischofer, petri.savolainen, mike.holmes,
Christopher Li
this patch stops sparse from complaining about them not being
defined:
source/odp_spinlock.c:41:10: error: undefined identifier '__sync_lock_release'
source/odp_spinlock.c:54:10: error: undefined identifier '__sync_lock_release'
./odp_atomic.h:112:16: error: undefined identifier '__sync_fetch_and_add'
Reported-by: Mike Holmes <mike.holmes@linaro.org>
Signed-off-by: Kim Phillips <kim.phillips@linaro.org>
---
also available here:
git://git.linaro.org/people/kim.phillips/sparse.git
lib.c | 21 +++++++++++++++++++--
validation/builtin_atomic.c | 28 ++++++++++++++++++++++++++++
2 files changed, 47 insertions(+), 2 deletions(-)
create mode 100644 validation/builtin_atomic.c
diff --git a/lib.c b/lib.c
index fe20f93..bf3e91c 100644
--- a/lib.c
+++ b/lib.c
@@ -777,6 +777,25 @@ void declare_builtin_functions(void)
add_pre_buffer("extern unsigned int __builtin_bswap32(unsigned int);\n");
add_pre_buffer("extern unsigned long long __builtin_bswap64(unsigned long long);\n");
+ /* And atomic memory access functions.. */
+ add_pre_buffer("extern int __sync_fetch_and_add(void *, ...);\n");
+ add_pre_buffer("extern int __sync_fetch_and_sub(void *, ...);\n");
+ add_pre_buffer("extern int __sync_fetch_and_or(void *, ...);\n");
+ add_pre_buffer("extern int __sync_fetch_and_and(void *, ...);\n");
+ add_pre_buffer("extern int __sync_fetch_and_xor(void *, ...);\n");
+ add_pre_buffer("extern int __sync_fetch_and_nand(void *, ...);\n");
+ add_pre_buffer("extern int __sync_add_and_fetch(void *, ...);\n");
+ add_pre_buffer("extern int __sync_sub_and_fetch(void *, ...);\n");
+ add_pre_buffer("extern int __sync_or_and_fetch(void *, ...);\n");
+ add_pre_buffer("extern int __sync_and_and_fetch(void *, ...);\n");
+ add_pre_buffer("extern int __sync_xor_and_fetch(void *, ...);\n");
+ add_pre_buffer("extern int __sync_nand_and_fetch(void *, ...);\n");
+ add_pre_buffer("extern int __sync_bool_compare_and_swap(void *, ...);\n");
+ add_pre_buffer("extern int __sync_val_compare_and_swap(void *, ...);\n");
+ add_pre_buffer("extern void __sync_synchronize();\n");
+ add_pre_buffer("extern int __sync_lock_test_and_set(void *, ...);\n");
+ add_pre_buffer("extern void __sync_lock_release(void *, ...);\n");
+
/* And some random ones.. */
add_pre_buffer("extern void *__builtin_return_address(unsigned int);\n");
add_pre_buffer("extern void *__builtin_extract_return_addr(void *);\n");
@@ -794,8 +813,6 @@ void declare_builtin_functions(void)
add_pre_buffer("extern long __builtin_labs(long);\n");
add_pre_buffer("extern double __builtin_fabs(double);\n");
add_pre_buffer("extern __SIZE_TYPE__ __builtin_va_arg_pack_len(void);\n");
- add_pre_buffer("extern void __sync_synchronize();\n");
- add_pre_buffer("extern int __sync_bool_compare_and_swap(void *, ...);\n");
/* Add Blackfin-specific stuff */
add_pre_buffer(
diff --git a/validation/builtin_atomic.c b/validation/builtin_atomic.c
new file mode 100644
index 0000000..e56321a
--- /dev/null
+++ b/validation/builtin_atomic.c
@@ -0,0 +1,28 @@
+static void fn(void)
+{
+ static int i, *ptr = (void *)0;
+
+ i = __sync_fetch_and_add(ptr, 0);
+ i = __sync_fetch_and_sub(ptr, 0);
+ i = __sync_fetch_and_or(ptr, 0);
+ i = __sync_fetch_and_and(ptr, 0);
+ i = __sync_fetch_and_xor(ptr, 0);
+ i = __sync_fetch_and_nand(ptr, 0);
+ i = __sync_add_and_fetch(ptr, 0);
+ i = __sync_sub_and_fetch(ptr, 0);
+ i = __sync_or_and_fetch(ptr, 0);
+ i = __sync_and_and_fetch(ptr, 0);
+ i = __sync_xor_and_fetch(ptr, 0);
+ i = __sync_nand_and_fetch(ptr, 0);
+ i = __sync_bool_compare_and_swap(ptr, 0, 1);
+ i = __sync_val_compare_and_swap(ptr, 0, 1);
+ __sync_synchronize();
+ i = __sync_lock_test_and_set(ptr, 0);
+ __sync_lock_release(ptr);
+}
+
+/*
+ * check-name: __builtin_atomic
+ * check-error-start
+ * check-error-end
+ */
--
1.8.5.1
^ permalink raw reply related [flat|nested] 2+ messages in thread