aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorLuc Van Oostenryck <luc.vanoostenryck@gmail.com>2018-01-20 10:43:18 +0100
committerLuc Van Oostenryck <luc.vanoostenryck@gmail.com>2020-12-29 14:39:38 +0100
commit7d6cdc0350820a3ba8e583853ba350af118092e0 (patch)
treefc7b4ccb3307792dcfac7f184db8eb01fc9e4c2e
parent1d2355e60f36b49ca680c892b60bf8e4a7f59942 (diff)
downloadsparse-7d6cdc0350820a3ba8e583853ba350af118092e0.tar.gz
add testcases for type attributes
Currently, type attributes are not handled correctly. Add some testcases for them. Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
-rw-r--r--validation/type-attribute-align.c20
-rw-r--r--validation/type-attribute-as.c34
-rw-r--r--validation/type-attribute-mod.c22
-rw-r--r--validation/type-attribute-qual.c15
4 files changed, 91 insertions, 0 deletions
diff --git a/validation/type-attribute-align.c b/validation/type-attribute-align.c
new file mode 100644
index 00000000..d9358bff
--- /dev/null
+++ b/validation/type-attribute-align.c
@@ -0,0 +1,20 @@
+#define __aligned(N) __attribute__((aligned(N)))
+#define alignof(X) __alignof__(X)
+
+struct s {
+ short a, b, c;
+} __aligned(2*sizeof(short));
+
+static int fs(void) { return sizeof(struct s); }
+static int fa(void) { return alignof(struct s); }
+
+void main(void)
+{
+ _Static_assert( sizeof(struct s) == 4 * sizeof(short), "size");
+ _Static_assert(alignof(struct s) == 2 * sizeof(short), "alignment");
+}
+
+/*
+ * check-name: type-attribute-align
+ * check-known-to-fail
+ */
diff --git a/validation/type-attribute-as.c b/validation/type-attribute-as.c
new file mode 100644
index 00000000..b40b4e7d
--- /dev/null
+++ b/validation/type-attribute-as.c
@@ -0,0 +1,34 @@
+#define __as __attribute__((address_space(__as)))
+
+struct s {
+ int i;
+} __as;
+
+
+extern void use0(void *);
+extern void use1(void __as *);
+
+void main(void)
+{
+ struct s s;
+ int i;
+
+ use0(&s); // KO
+ use0(&i); // OK
+ use1(&s); // OK
+ use1(&i); // KO
+}
+
+/*
+ * check-name: type-attribute-as
+ * check-known-to-fail
+ *
+ * check-error-start
+type-attribute-as.c:16:15: warning: incorrect type in argument 1 (different address spaces)
+type-attribute-as.c:16:15: expected void *
+type-attribute-as.c:16:15: got struct s __as *
+type-attribute-as.c:19:15: warning: incorrect type in argument 1 (different address spaces)
+type-attribute-as.c:19:15: expected void __as *
+type-attribute-as.c:19:15: got int *
+ * check-error-end
+ */
diff --git a/validation/type-attribute-mod.c b/validation/type-attribute-mod.c
new file mode 100644
index 00000000..0e7b166a
--- /dev/null
+++ b/validation/type-attribute-mod.c
@@ -0,0 +1,22 @@
+#define __noderef __attribute__((noderef))
+
+struct s {
+ int i;
+} __noderef;
+
+
+void main(void)
+{
+ struct s s;
+
+ s.i = 0;
+}
+
+/*
+ * check-name: type-attribute-mod
+ * check-known-to-fail
+ *
+ * check-error-start
+type-attribute-mod.c:12:9: warning: dereference of noderef expression
+ * check-error-end
+ */
diff --git a/validation/type-attribute-qual.c b/validation/type-attribute-qual.c
new file mode 100644
index 00000000..62d8b98e
--- /dev/null
+++ b/validation/type-attribute-qual.c
@@ -0,0 +1,15 @@
+static const struct s {
+ int x;
+} map[2];
+
+static void foo(struct s *p, int v)
+{
+ p->x += v;
+}
+
+/*
+ * check-name: type-attribute-qual
+ * check-description: When declaring a type and a variable in the same
+ * declaration, ensure that type qualifiers apply to the variable
+ * and not to the type.
+ */