Re: [PATCH] validation: add check for typeof() and address spaces

Chris Li <[email protected]> Mon, 1 Dec 2025 19:24:05 +0400
Newsgroups org.kernel.vger.linux-sparse
Message-ID <CACePvbWG5iOtCRLRwtfHRSWt2sU65GZ72QDRHaS=p0PnUmh42Q@mail.gmail.com>
On Tue, Oct 28, 2025 at 5:32 PM Dan Carpenter <[email protected]> wrote:
>
> The typeof() key word should preserve the address space and
> typeof_unqual() should not.  Add a check to verify this works as
> expected.
>
> Signed-off-by: Dan Carpenter <[email protected]>

Applied to sparse-dev.

Chris

> ---
>  validation/typeof-as.c | 32 ++++++++++++++++++++++++++++++++
>  1 file changed, 32 insertions(+)
>  create mode 100644 validation/typeof-as.c
>
> diff --git a/validation/typeof-as.c b/validation/typeof-as.c
> new file mode 100644
> index 000000000000..563685281d92
> --- /dev/null
> +++ b/validation/typeof-as.c
> @@ -0,0 +1,32 @@
> +#define __seg_gs               __attribute__((address_space(__seg_gs)))
> +static int __seg_gs m;
> +
> +static int __seg_gs bad_manual (void)
> +{
> +       return (*(int *)&m);
> +}
> +
> +static int __seg_gs good_manual (void)
> +{
> +       return (*(int __seg_gs *)&m);
> +}
> +
> +static int bad_typeof (void)
> +{
> +       return (*(typeof_unqual(m) *)&m);
> +}
> +
> +static int __seg_gs good_typeof (void)
> +{
> +       return (*(volatile typeof(m) *)&m);
> +}
> +
> +/*
> + * check-name: typeof address space
> + * check-command: ./sparse typeof-as.c
> + *
> + * check-error-start
> +typeof-as.c:6:19: warning: cast removes address space '__seg_gs' of expression
> +typeof-as.c:16:19: warning: cast removes address space '__seg_gs' of expression
> + * check-error-end
> + */
> --
> 2.51.0
>