aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/validation
diff options
authorLuc Van Oostenryck <luc.vanoostenryck@gmail.com>2020-09-26 00:04:07 +0200
committerLuc Van Oostenryck <luc.vanoostenryck@gmail.com>2020-10-01 00:44:49 +0200
commit644f20bb0e0aa76480f6c4c2d3d38001dd289626 (patch)
treec4d6205fc2c2de265dbb659cd432f2cfb271907a /validation
parent24bdaac6682c36f5f7878321e8f9eb02c0993572 (diff)
downloadsparse-dev-644f20bb0e0aa76480f6c4c2d3d38001dd289626.tar.gz
flex-array: add testcases
Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
Diffstat (limited to 'validation')
-rw-r--r--validation/flex-array-align.c19
-rw-r--r--validation/flex-array-array.c16
-rw-r--r--validation/flex-array-error.c27
-rw-r--r--validation/flex-array-nested.c30
-rw-r--r--validation/flex-array-padding.c22
-rw-r--r--validation/flex-array-sizeof.c19
6 files changed, 133 insertions, 0 deletions
diff --git a/validation/flex-array-align.c b/validation/flex-array-align.c
new file mode 100644
index 00000000..0cc67ab3
--- /dev/null
+++ b/validation/flex-array-align.c
@@ -0,0 +1,19 @@
+struct s {
+ __INT32_TYPE__ x;
+ __INT16_TYPE__ y;
+ unsigned char f[];
+};
+
+static int foo(struct s *s)
+{
+ return (sizeof(*s) << 16) | __builtin_offsetof(typeof(*s), f);
+}
+
+/*
+ * check-name: flex-array-align
+ * check-command: test-linearize -Wno-flexible-array-sizeof $file
+ * check-known-to-fail
+ *
+ * check-output-ignore
+ * check-output-contains: ret\\..*\\$0x80006
+ */
diff --git a/validation/flex-array-array.c b/validation/flex-array-array.c
new file mode 100644
index 00000000..bda80d7a
--- /dev/null
+++ b/validation/flex-array-array.c
@@ -0,0 +1,16 @@
+struct s {
+ int i;
+ long f[];
+};
+
+static struct s a[2];
+
+/*
+ * check-name: flex-array-array
+ * check-command: sparse -Wflexible-array-array $file
+ * check-known-to-fail
+ *
+ * check-error-start
+flex-array-array.c:6:18: warning: array of flexible structures
+ * check-error-end
+ */
diff --git a/validation/flex-array-error.c b/validation/flex-array-error.c
new file mode 100644
index 00000000..89601e42
--- /dev/null
+++ b/validation/flex-array-error.c
@@ -0,0 +1,27 @@
+struct s {
+ int i;
+ long f[];
+ int j;
+};
+
+union u {
+ int i;
+ long f[];
+};
+
+// trigger the examination of the offending types
+static int foo(struct s *s, union u *u)
+{
+ return __builtin_offsetof(typeof(*s), i)
+ + __builtin_offsetof(typeof(*u), i);
+}
+
+/*
+ * check-name: flex-array-error
+ * check-known-to-fail
+ *
+ * check-error-start
+flex-array-error.c:3:14: error: flexible array member 'f' is not last
+flex-array-error.c:9:14: error: flexible array member 'f' in a union
+ * check-error-end
+ */
diff --git a/validation/flex-array-nested.c b/validation/flex-array-nested.c
new file mode 100644
index 00000000..3503c329
--- /dev/null
+++ b/validation/flex-array-nested.c
@@ -0,0 +1,30 @@
+struct f {
+ int i;
+ long f[];
+};
+
+struct s {
+ struct f f;
+};
+
+union u {
+ struct f f;
+};
+
+// trigger the examination of the offending types
+static int foo(struct s *s, union u *u)
+{
+ return __builtin_offsetof(typeof(*s), f)
+ + __builtin_offsetof(typeof(*u), f);
+}
+
+/*
+ * check-name: flex-array-nested
+ * check-command: sparse -Wflexible-array-nested $file
+ * check-known-to-fail
+ *
+ * check-error-start
+flex-array-nested.c:6:8: warning: nested flexible arrays
+flex-array-nested.c:10:7: warning: nested flexible arrays
+ * check-error-end
+ */
diff --git a/validation/flex-array-padding.c b/validation/flex-array-padding.c
new file mode 100644
index 00000000..2ba77971
--- /dev/null
+++ b/validation/flex-array-padding.c
@@ -0,0 +1,22 @@
+struct s {
+ __INT32_TYPE__ x;
+ __INT16_TYPE__ y;
+ unsigned char f[];
+};
+
+static int foo(struct s *s)
+{
+ return __builtin_offsetof(typeof(*s), f);
+}
+
+/*
+ * check-name: flex-array-padding
+ * check-command: test-linearize -Wflexible-array-padding $file
+ * check-known-to-fail
+ *
+ * check-output-ignore
+ *
+ * check-error-start
+flex-array-padding.c:4:23: warning: flexible array member has padding
+ * check-error-end
+ */
diff --git a/validation/flex-array-sizeof.c b/validation/flex-array-sizeof.c
new file mode 100644
index 00000000..3359509d
--- /dev/null
+++ b/validation/flex-array-sizeof.c
@@ -0,0 +1,19 @@
+struct s {
+ int i;
+ long f[];
+};
+
+static int foo(struct s *s)
+{
+ return sizeof(*s);
+}
+
+/*
+ * check-name: flex-array-sizeof
+ * check-command: sparse -Wflexible-array-sizeof $file
+ * check-known-to-fail
+ *
+ * check-error-start
+flex-array-sizeof.c:8:16: warning: using sizeof on a flexible structure
+ * check-error-end
+ */