From: Dan Carpenter <dan.carpenter@linaro.org>
To: Chris Li <sparse@chrisli.org>, Uros Bizjak <ubizjak@gmail.com>
Cc: Sparse Mailing-list <linux-sparse@vger.kernel.org>
Subject: [PATCH] validation: add check for typeof() and address spaces
Date: Tue, 28 Oct 2025 16:32:08 +0300 [thread overview]
Message-ID: <aQDF2Ila2-LNmllC@stanley.mountain> (raw)
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 <dan.carpenter@linaro.org>
---
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
next reply other threads:[~2025-10-28 13:32 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-10-28 13:32 Dan Carpenter [this message]
2025-12-01 15:24 ` [PATCH] validation: add check for typeof() and address spaces Chris Li
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=aQDF2Ila2-LNmllC@stanley.mountain \
--to=dan.carpenter@linaro.org \
--cc=linux-sparse@vger.kernel.org \
--cc=sparse@chrisli.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.