aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorLuc Van Oostenryck <luc.vanoostenryck@gmail.com>2020-10-09 20:06:39 +0200
committerLuc Van Oostenryck <luc.vanoostenryck@gmail.com>2020-10-19 18:07:33 +0200
commit53149d7bd249ff04368bee83985f8570a82b2fd5 (patch)
treeefd99f7c4a7440f96f7716f9b8fa9d90dd1521ef
parent2b75d15ea289e7ece5228c3765d29c0d2115c793 (diff)
downloadsparse-53149d7bd249ff04368bee83985f8570a82b2fd5.tar.gz
builtin: evaluate __sync_*_fetch*()
Reuse the generic method for all these builtins. Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
-rw-r--r--builtin.c26
-rw-r--r--validation/builtin-sync-fetch.c24
2 files changed, 37 insertions, 13 deletions
diff --git a/builtin.c b/builtin.c
index a1c92572..bd12d565 100644
--- a/builtin.c
+++ b/builtin.c
@@ -627,23 +627,23 @@ static const struct builtin_fn builtins_common[] = {
{ "__builtin___vsnprintf_chk", &int_ctype, 0, { &string_ctype, size_t_ctype, &int_ctype, size_t_ctype, &const_string_ctype, va_list_ctype }},
{ "__builtin___vsprintf_chk", &int_ctype, 0, { &string_ctype, &int_ctype, size_t_ctype, &const_string_ctype, va_list_ctype }},
- { "__sync_add_and_fetch", &int_ctype, 1, { &ptr_ctype }},
- { "__sync_and_and_fetch", &int_ctype, 1, { &ptr_ctype }},
+ { "__sync_add_and_fetch", NULL, 1, { vol_ptr, &dyntype }, .op = &atomic_op },
+ { "__sync_and_and_fetch", NULL, 1, { vol_ptr, &dyntype }, .op = &atomic_op },
{ "__sync_bool_compare_and_swap", &bool_ctype, 1, { vol_ptr, &dyntype, &dyntype }, .op = &atomic_op},
- { "__sync_fetch_and_add", &int_ctype, 1, { &ptr_ctype }},
- { "__sync_fetch_and_and", &int_ctype, 1, { &ptr_ctype }},
- { "__sync_fetch_and_nand", &int_ctype, 1, { &ptr_ctype }},
- { "__sync_fetch_and_or", &int_ctype, 1, { &ptr_ctype }},
- { "__sync_fetch_and_sub", &int_ctype, 1, { &ptr_ctype }},
- { "__sync_fetch_and_xor", &int_ctype, 1, { &ptr_ctype }},
+ { "__sync_fetch_and_add", NULL, 1, { vol_ptr, &dyntype }, .op = &atomic_op },
+ { "__sync_fetch_and_and", NULL, 1, { vol_ptr, &dyntype }, .op = &atomic_op },
+ { "__sync_fetch_and_nand", NULL, 1, { vol_ptr, &dyntype }, .op = &atomic_op },
+ { "__sync_fetch_and_or", NULL, 1, { vol_ptr, &dyntype }, .op = &atomic_op },
+ { "__sync_fetch_and_sub", NULL, 1, { vol_ptr, &dyntype }, .op = &atomic_op },
+ { "__sync_fetch_and_xor", NULL, 1, { vol_ptr, &dyntype }, .op = &atomic_op },
{ "__sync_lock_release", &void_ctype, 1, { &ptr_ctype }},
- { "__sync_lock_test_and_set", &int_ctype, 1, { &ptr_ctype }},
- { "__sync_nand_and_fetch", &int_ctype, 1, { &ptr_ctype }},
- { "__sync_or_and_fetch", &int_ctype, 1, { &ptr_ctype }},
- { "__sync_sub_and_fetch", &int_ctype, 1, { &ptr_ctype }},
+ { "__sync_lock_test_and_set", NULL, 1, { vol_ptr, &dyntype }, .op = &atomic_op },
+ { "__sync_nand_and_fetch", NULL, 1, { vol_ptr, &dyntype }, .op = &atomic_op },
+ { "__sync_or_and_fetch", NULL, 1, { vol_ptr, &dyntype }, .op = &atomic_op },
+ { "__sync_sub_and_fetch", NULL, 1, { vol_ptr, &dyntype }, .op = &atomic_op },
{ "__sync_synchronize", &void_ctype, 0 },
{ "__sync_val_compare_and_swap", NULL, 1, { vol_ptr, &dyntype, &dyntype }, .op = &atomic_op },
- { "__sync_xor_and_fetch", &int_ctype, 1, { &ptr_ctype }},
+ { "__sync_xor_and_fetch", NULL, 1, { vol_ptr, &dyntype }, .op = &atomic_op },
{ }
};
diff --git a/validation/builtin-sync-fetch.c b/validation/builtin-sync-fetch.c
new file mode 100644
index 00000000..45139a3c
--- /dev/null
+++ b/validation/builtin-sync-fetch.c
@@ -0,0 +1,24 @@
+static int ok_int(int *ptr, int val)
+{
+ return __sync_add_and_fetch(ptr, val);
+}
+
+static long* ok_ptr(long **ptr, long *val)
+{
+ return __sync_add_and_fetch(ptr, val);
+}
+
+static void chk_ret_ok(long *ptr, long val)
+{
+ _Static_assert([typeof(__sync_add_and_fetch(ptr, val))] == [long], "");
+}
+
+static int chk_val(int *ptr, long val)
+{
+ // OK: val is converted to an int
+ return __sync_add_and_fetch(ptr, val);
+}
+
+/*
+ * check-name: builtin-sync-fetch
+ */