linux-sparse.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Chris Li <sparse@chrisli.org>
To: Dan Carpenter <dan.carpenter@linaro.org>
Cc: Uros Bizjak <ubizjak@gmail.com>,
	Sparse Mailing-list <linux-sparse@vger.kernel.org>
Subject: Re: [PATCH v2] symbol: preserve address space qualifiers with typeof()
Date: Mon, 1 Dec 2025 19:23:32 +0400	[thread overview]
Message-ID: <CACePvbWmmOED+5bAKT5SfA1c0YqN2v-wEEim6X-uHT8H-qaGHg@mail.gmail.com> (raw)
In-Reply-To: <aQC_tw-8gLpf00yH@stanley.mountain>

Hi Dan,

Thanks for the patch. Sorry for the late reply. Super busy recently.
Now I am back and catching up on my back logs.

On Tue, Oct 28, 2025 at 5:06 PM Dan Carpenter <dan.carpenter@linaro.org> wrote:
>
> When we're parsing typeof(var) we then preserve the address space
> qualifiers as well.  Otherwise it leads to warnings like this:
>
> "warning: cast removes address space '__seg_gs' of expression"
>
> Reported-by: Uros Bizjak <ubizjak@gmail.com>
> Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>

Your patch makes one of the known to fail tests passed. I took the
liberty to add the following change to make validation check happy:
diff --git a/validation/typeof-addresspace.c b/validation/typeof-addresspace.c
index a94f77a3..34ac3089 100644
--- a/validation/typeof-addresspace.c
+++ b/validation/typeof-addresspace.c
@@ -16,5 +16,4 @@ static void test_as(void)

 /*
  * check-name: typeof-addresspace.c
- * check-known-to-fail
  */

Applied to sparse-dev.

Chris

> ---
> v2: Fix a NULL dereference because "base" can be NULL.  Sorry for not
> running the validation/ tests...  :(
>
>  symbol.c | 7 ++++++-
>  1 file changed, 6 insertions(+), 1 deletion(-)
>
> diff --git a/symbol.c b/symbol.c
> index 7060acb666d9..a42289226650 100644
> --- a/symbol.c
> +++ b/symbol.c
> @@ -544,9 +544,12 @@ static struct symbol *examine_pointer_type(struct symbol *sym)
>  static struct symbol *examine_typeof_helper(struct symbol *sym, bool qual)
>  {
>         struct symbol *base = evaluate_expression(sym->initializer);
> +       struct ident *as = NULL;
>         unsigned long mod = 0;
>
> -       if (!base)
> +       if (base)
> +               as = base->ctype.as;
> +       else
>                 base = &bad_ctype;
>         if (base->type == SYM_NODE) {
>                 mod |= base->ctype.modifiers & MOD_TYPEOF;
> @@ -559,6 +562,8 @@ static struct symbol *examine_typeof_helper(struct symbol *sym, bool qual)
>         sym->type = SYM_NODE;
>         sym->ctype.modifiers = mod;
>         sym->ctype.base_type = base;
> +       if (qual)
> +               sym->ctype.as = as;
>         return examine_node_type(sym);
>  }
>
> --
> 2.51.0
>

      reply	other threads:[~2025-12-01 15:23 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-10-28 13:05 [PATCH v2] symbol: preserve address space qualifiers with typeof() Dan Carpenter
2025-12-01 15:23 ` Chris Li [this message]

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=CACePvbWmmOED+5bAKT5SfA1c0YqN2v-wEEim6X-uHT8H-qaGHg@mail.gmail.com \
    --to=sparse@chrisli.org \
    --cc=dan.carpenter@linaro.org \
    --cc=linux-sparse@vger.kernel.org \
    --cc=ubizjak@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
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).