Linux-Sparse Archive on lore.kernel.org
 help / color / Atom feed
From: Ramsay Jones <ramsay@ramsayjones.plus.com>
To: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>,
	linux-sparse@vger.kernel.org
Subject: Re: [PATCH 04/12] builtin: evaluate __sync_*_fetch*()
Date: Mon, 19 Oct 2020 00:59:01 +0100
Message-ID: <c19eba37-af33-a852-a286-a6ecf23d77ea@ramsayjones.plus.com> (raw)
In-Reply-To: <20201017225633.53274-5-luc.vanoostenryck@gmail.com>



On 17/10/2020 23:56, Luc Van Oostenryck wrote:
> Reuse the generic method for all these builtins.
> 
> Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
> ---
>  builtin.c                       | 26 +++++++++++++-------------
>  validation/builtin-sync-fetch.c | 24 ++++++++++++++++++++++++
>  2 files changed, 37 insertions(+), 13 deletions(-)
>  create mode 100644 validation/builtin-sync-fetch.c
> 
> diff --git a/builtin.c b/builtin.c
> index 880dd54f647e..5e490830e147 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 },

Hmm, I get that the return type is derived from the type of the first
argument, but I don't see where that return type is checked/assigned
to the function return type. :( So, why are these set to NULL, but ...

>  	{ "__sync_bool_compare_and_swap", &bool_ctype, 1, { vol_ptr, &dyntype, &dyntype }, .op = &atomic_op},

... this one isn't?

ATB,
Ramsay Jones


> -	{ "__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 000000000000..45139a3c8c3e
> --- /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
> + */
> 

  reply index

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-17 22:56 [PATCH 00/12] fix and complete the evaluation of atomic builtins Luc Van Oostenryck
2020-10-17 22:56 ` [PATCH 01/12] builtin: add generic .args method Luc Van Oostenryck
2020-10-17 22:56 ` [PATCH 02/12] builtin: add builtin type for volatile void * Luc Van Oostenryck
2020-10-17 22:56 ` [PATCH 03/12] builtin: make eval_sync_compare_and_swap() more generic Luc Van Oostenryck
2020-10-18 21:31   ` Ramsay Jones
2020-10-19  4:59     ` Luc Van Oostenryck
2020-10-17 22:56 ` [PATCH 04/12] builtin: evaluate __sync_*_fetch*() Luc Van Oostenryck
2020-10-18 23:59   ` Ramsay Jones [this message]
2020-10-19  4:44     ` Luc Van Oostenryck
2020-10-17 22:56 ` [PATCH 05/12] builtin: fix evaluation of __sync_lock_release Luc Van Oostenryck
2020-10-17 22:56 ` [PATCH 06/12] builtin: __sync_synchronize() too is variadic Luc Van Oostenryck
2020-10-17 22:56 ` [PATCH 07/12] builtin: add predefines for __ATOMIC_RELAXED & friends Luc Van Oostenryck
2020-10-17 22:56 ` [PATCH 08/12] builtin: add support for __atomic_add_fetch(), Luc Van Oostenryck
2020-10-17 22:56 ` [PATCH 09/12] builtin: add support for others generic atomic builtins Luc Van Oostenryck
2020-10-17 22:56 ` [PATCH 10/12] builtin: add builtin type: [volatile] pointer to bool Luc Van Oostenryck
2020-10-17 22:56 ` [PATCH 11/12] builtin: add support for __atomic_clear() Luc Van Oostenryck
2020-10-17 22:56 ` [PATCH 12/12] builtin: add support for remaining atomic builtins Luc Van Oostenryck

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=c19eba37-af33-a852-a286-a6ecf23d77ea@ramsayjones.plus.com \
    --to=ramsay@ramsayjones.plus.com \
    --cc=linux-sparse@vger.kernel.org \
    --cc=luc.vanoostenryck@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

Linux-Sparse Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-sparse/0 linux-sparse/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-sparse linux-sparse/ https://lore.kernel.org/linux-sparse \
		linux-sparse@vger.kernel.org
	public-inbox-index linux-sparse

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-sparse


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git