diff mbox

sparse: add built-in atomic memory access identifiers

Message ID 20131211150013.e009efdb3fa2321f113a8a8d@linaro.org (mailing list archive)
State Mainlined, archived
Headers show

Commit Message

Kim Phillips Dec. 11, 2013, 9 p.m. UTC
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

Comments

Christopher Li Dec. 21, 2013, 5:22 p.m. UTC | #1
On Wed, Dec 11, 2013 at 1:00 PM, Kim Phillips <kim.phillips@linaro.org> wrote:
> 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>


Applied and pushed.

Chris
--
To unsubscribe from this list: send the line "unsubscribe linux-sparse" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

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
+ */