aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/validation
diff options
authorDan Carpenter <dan.carpenter@linaro.org>2025-10-28 16:32:08 +0300
committerChris Li <chriscli@google.com>2025-12-01 19:17:45 +0400
commit27b34d720c4a06a90ed1982e91e1c049471f12e2 (patch)
tree76b02ed86615d8b134accf111bd94b822fad9ef7 /validation
parentfbdde3127b83e6d09e0ba808d7925dd84407f3c6 (diff)
downloadsparse-dev-27b34d720c4a06a90ed1982e91e1c049471f12e2.tar.gz
validation: add check for typeof() and address spaces
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> Signed-off-by: Chris Li <chriscli@google.com>
Diffstat (limited to 'validation')
-rw-r--r--validation/typeof-as.c32
1 files changed, 32 insertions, 0 deletions
diff --git a/validation/typeof-as.c b/validation/typeof-as.c
new file mode 100644
index 00000000..69d515b7
--- /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
+ */