diff options
author | Luc Van Oostenryck <luc.vanoostenryck@gmail.com> | 2020-10-09 20:06:39 +0200 |
---|---|---|
committer | Luc Van Oostenryck <luc.vanoostenryck@gmail.com> | 2020-10-19 18:07:33 +0200 |
commit | 53149d7bd249ff04368bee83985f8570a82b2fd5 (patch) | |
tree | efd99f7c4a7440f96f7716f9b8fa9d90dd1521ef | |
parent | 2b75d15ea289e7ece5228c3765d29c0d2115c793 (diff) | |
download | sparse-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.c | 26 | ||||
-rw-r--r-- | validation/builtin-sync-fetch.c | 24 |
2 files changed, 37 insertions, 13 deletions
@@ -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 + */ |