add testcases for packed bitfields
diff mbox

Message ID 20180416141234.77051-1-luc.vanoostenryck@gmail.com
State Superseded, archived
Headers show

Commit Message

Luc Van Oostenryck April 16, 2018, 2:12 p.m. UTC
Currently sparse ignore type attributes, like for example,
defining a packed structure.

Add a testcase for this.

Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
---
 validation/packed-bitfield.c | 65 ++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 65 insertions(+)
 create mode 100644 validation/packed-bitfield.c

Patch
diff mbox

diff --git a/validation/packed-bitfield.c b/validation/packed-bitfield.c
new file mode 100644
index 000000000..914b7f86a
--- /dev/null
+++ b/validation/packed-bitfield.c
@@ -0,0 +1,65 @@ 
+#define alignof(X)	__alignof__(X)
+#define __packed	__attribute__((packed))
+
+struct sa {
+	int a:7;
+	int c:10;
+	int b:2;
+} __packed;
+_Static_assert(alignof(struct sa) == 1, "alignof(struct sa)");
+
+struct __packed sb {
+	int a:7;
+	int c:10;
+	int b:2;
+};
+_Static_assert(alignof(struct sb) == 1, "alignof(struct sb)");
+
+static int get_size(void)
+{
+	return sizeof(struct sa);
+}
+
+static void chk_align(struct sa sa, struct sa *p)
+{
+	_Static_assert(__alignof__(sa) == 1, "alignof(sa)");
+	_Static_assert(__alignof__(*p) == 1, "alignof(*p)");
+}
+
+static int fp0(struct sa *sa)
+{
+	return sa->c;
+}
+
+static int fpx(struct sa *sa, int idx)
+{
+	return sa[idx].c;
+}
+
+static int fglobal(void)
+{
+	extern struct sa g;
+	return g.c;
+}
+
+static struct sa l;
+static int flocal(void)
+{
+	return l.c;
+}
+
+
+int main(void)
+{
+	extern void fun(struct sa *);
+	struct sa sa = { 0 };
+
+	fun(&sa);
+	return 0;
+}
+
+/*
+ * check-name: packed-bitfield
+ * check-command: sparse -m32 $file
+ * check-known-to-fail
+ */