linux-sparse.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] symbol: preserve address space qualifiers with typeof()
@ 2025-10-28 13:05 Dan Carpenter
  2025-12-01 15:23 ` Chris Li
  0 siblings, 1 reply; 2+ messages in thread
From: Dan Carpenter @ 2025-10-28 13:05 UTC (permalink / raw)
  To: Uros Bizjak, Chris Li; +Cc: Sparse Mailing-list

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>
---
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


^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2025-12-01 15:23 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-10-28 13:05 [PATCH v2] symbol: preserve address space qualifiers with typeof() Dan Carpenter
2025-12-01 15:23 ` Chris Li

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).