aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/validation
diff options
Diffstat (limited to 'validation')
-rw-r--r--validation/flex-array-align.c18
-rw-r--r--validation/flex-array-array.c15
-rw-r--r--validation/flex-array-error.c26
-rw-r--r--validation/flex-array-nested.c29
-rw-r--r--validation/flex-array-sizeof.c18
-rw-r--r--validation/flex-array-union-array-no.c9
-rw-r--r--validation/flex-array-union-array-yes.c11
-rw-r--r--validation/flex-array-union-array.h11
8 files changed, 137 insertions, 0 deletions
diff --git a/validation/flex-array-align.c b/validation/flex-array-align.c
new file mode 100644
index 00000000..9f28942a
--- /dev/null
+++ b/validation/flex-array-align.c
@@ -0,0 +1,18 @@
+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-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..921a0698
--- /dev/null
+++ b/validation/flex-array-array.c
@@ -0,0 +1,15 @@
+struct s {
+ int i;
+ long f[];
+};
+
+static struct s a[2];
+
+/*
+ * check-name: flex-array-array
+ * check-command: sparse -Wflexible-array-array $file
+ *
+ * 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..2b7e6953
--- /dev/null
+++ b/validation/flex-array-error.c
@@ -0,0 +1,26 @@
+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-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..63767683
--- /dev/null
+++ b/validation/flex-array-nested.c
@@ -0,0 +1,29 @@
+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-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-sizeof.c b/validation/flex-array-sizeof.c
new file mode 100644
index 00000000..05394e19
--- /dev/null
+++ b/validation/flex-array-sizeof.c
@@ -0,0 +1,18 @@
+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-error-start
+flex-array-sizeof.c:8:16: warning: using sizeof on a flexible structure
+ * check-error-end
+ */
diff --git a/validation/flex-array-union-array-no.c b/validation/flex-array-union-array-no.c
new file mode 100644
index 00000000..5a1de787
--- /dev/null
+++ b/validation/flex-array-union-array-no.c
@@ -0,0 +1,9 @@
+#include "flex-array-union-array.h"
+
+/*
+ * check-name: flex-array-union-no
+ * check-command: sparse -Wflexible-array-array -Wno-flexible-array-union $file
+ *
+ * check-error-start
+ * check-error-end
+ */
diff --git a/validation/flex-array-union-array-yes.c b/validation/flex-array-union-array-yes.c
new file mode 100644
index 00000000..c2b71d65
--- /dev/null
+++ b/validation/flex-array-union-array-yes.c
@@ -0,0 +1,11 @@
+#include "flex-array-union-array.h"
+
+/*
+ * check-name: flex-array-union-yes
+ * check-command: sparse -Wflexible-array-array -Wflexible-array-union $file
+ *
+ * check-error-start
+flex-array-union-array-yes.c: note: in included file:
+flex-array-union-array.h:11:17: warning: array of flexible structures
+ * check-error-end
+ */
diff --git a/validation/flex-array-union-array.h b/validation/flex-array-union-array.h
new file mode 100644
index 00000000..b2a74d1a
--- /dev/null
+++ b/validation/flex-array-union-array.h
@@ -0,0 +1,11 @@
+struct s_flex {
+ int i;
+ long f[];
+};
+
+union s {
+ struct s_flex flex;
+ char buf[200];
+};
+
+static union s a[2];