From 29cdbe161a46437751d14a72e2580c889f6f8a27 Mon Sep 17 00:00:00 2001 From: Luc Van Oostenryck Date: Mon, 7 Oct 2019 07:25:23 +0200 Subject: add testcases for packed structures Currently, packed structs are not handled correctly. Add some testcases for them. Signed-off-by: Luc Van Oostenryck --- validation/packed-deref0.c | 24 ++++++++++++++++++++++++ validation/packed-struct.c | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+) create mode 100644 validation/packed-deref0.c create mode 100644 validation/packed-struct.c 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 + */ -- cgit 1.2.3-korg