aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorLuc Van Oostenryck <luc.vanoostenryck@gmail.com>2019-10-07 07:25:23 +0200
committerLuc Van Oostenryck <luc.vanoostenryck@gmail.com>2020-12-29 14:39:38 +0100
commit29cdbe161a46437751d14a72e2580c889f6f8a27 (patch)
treedc9d033192d1f3facd357cef4586725b99f59738
parent7d6cdc0350820a3ba8e583853ba350af118092e0 (diff)
downloadsparse-29cdbe161a46437751d14a72e2580c889f6f8a27.tar.gz
add testcases for packed structures
Currently, packed structs are not handled correctly. Add some testcases for them. Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
-rw-r--r--validation/packed-deref0.c24
-rw-r--r--validation/packed-struct.c33
2 files changed, 57 insertions, 0 deletions
diff --git a/validation/packed-deref0.c b/validation/packed-deref0.c
new file mode 100644
index 00000000..865ad68a
--- /dev/null
+++ b/validation/packed-deref0.c
@@ -0,0 +1,24 @@
+#define __packed __attribute__((packed))
+
+typedef struct {
+ __INT8_TYPE__ a;
+ __INT16_TYPE__ b;
+ __INT32_TYPE__ c;
+} __packed obj_t;
+
+_Static_assert(sizeof(obj_t) == 7, "sizeof packed struct");
+
+static void foo(obj_t *ptr, int val)
+{
+ ptr->c = val;
+}
+
+static void bar(obj_t o)
+{
+ foo(&o, 0);
+}
+
+/*
+ * check-name: packed-deref0
+ * check-known-to-fail
+ */
diff --git a/validation/packed-struct.c b/validation/packed-struct.c
new file mode 100644
index 00000000..e21d1153
--- /dev/null
+++ b/validation/packed-struct.c
@@ -0,0 +1,33 @@
+#define __packed __attribute__((packed))
+
+typedef unsigned char u8;
+typedef __UINT16_TYPE__ u16;
+typedef __UINT32_TYPE__ u32;
+typedef __UINT64_TYPE__ u64;
+
+struct a {
+ u8 a;
+ u8 b;
+ u16 c;
+} __packed;
+_Static_assert(__alignof(struct a) == 1, "align struct");
+_Static_assert( sizeof(struct a) == 4, " size struct");
+
+struct b {
+ u32 a;
+ u32 b;
+} __packed;
+_Static_assert(__alignof(struct b) == 1, "align struct");
+_Static_assert( sizeof(struct b) == 8, "size struct");
+
+struct c {
+ u16 a;
+ u32 b;
+} __packed;
+_Static_assert(__alignof(struct c) == 1, "align struct");
+_Static_assert( sizeof(struct c) == 6, "size struct");
+
+/*
+ * check-name: packed-struct
+ * check-known-to-fail
+ */