[PATCH 02/16] add testcases for casts & bitfield insertion/extraction

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



There is several difficulties some related to unclear semantic
of our IR instructions and/or type evaluation.

Add testcases trying to cover this area.

Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@xxxxxxxxx>
---
 validation/linear/bitfield-inc.c       | 17 +++++++++
 validation/linear/bitfield-preinc.c    | 18 ++++++++++
 validation/linear/bitfield-store.c     | 22 ++++++++++++
 validation/optim/and-extend.c          | 28 +++++++++++++++
 validation/optim/and-extendx.c         | 25 +++++++++++++
 validation/optim/and-lsr.c             | 16 +++++++++
 validation/optim/and-trunc.c           | 21 +++++++++++
 validation/optim/ext-trunc-greater.c   | 18 ++++++++++
 validation/optim/ext-trunc-same.c      | 20 +++++++++++
 validation/optim/ext-trunc-smaller.c   | 19 ++++++++++
 validation/optim/mask-lsr.c            | 15 ++++++++
 validation/optim/mask-out.c            | 13 +++++++
 validation/optim/sext-sext.c           | 13 +++++++
 validation/optim/sext.c                | 15 ++++++++
 validation/optim/shift-zext.c          | 13 +++++++
 validation/optim/store-load-bitfield.c | 50 ++++++++++++++++++++++++++
 validation/optim/trunc-mask-zext.c     | 14 ++++++++
 validation/optim/zext-and.c            | 13 +++++++
 validation/optim/zext-and1.c           | 13 +++++++
 validation/optim/zext-sext.c           | 14 ++++++++
 validation/optim/zext-zext.c           | 14 ++++++++
 21 files changed, 391 insertions(+)
 create mode 100644 validation/linear/bitfield-inc.c
 create mode 100644 validation/linear/bitfield-preinc.c
 create mode 100644 validation/linear/bitfield-store.c
 create mode 100644 validation/optim/and-extend.c
 create mode 100644 validation/optim/and-extendx.c
 create mode 100644 validation/optim/and-lsr.c
 create mode 100644 validation/optim/and-trunc.c
 create mode 100644 validation/optim/ext-trunc-greater.c
 create mode 100644 validation/optim/ext-trunc-same.c
 create mode 100644 validation/optim/ext-trunc-smaller.c
 create mode 100644 validation/optim/mask-lsr.c
 create mode 100644 validation/optim/mask-out.c
 create mode 100644 validation/optim/sext-sext.c
 create mode 100644 validation/optim/sext.c
 create mode 100644 validation/optim/shift-zext.c
 create mode 100644 validation/optim/store-load-bitfield.c
 create mode 100644 validation/optim/trunc-mask-zext.c
 create mode 100644 validation/optim/zext-and.c
 create mode 100644 validation/optim/zext-and1.c
 create mode 100644 validation/optim/zext-sext.c
 create mode 100644 validation/optim/zext-zext.c

diff --git a/validation/linear/bitfield-inc.c b/validation/linear/bitfield-inc.c
new file mode 100644
index 000000000..ed8efe7d7
--- /dev/null
+++ b/validation/linear/bitfield-inc.c
@@ -0,0 +1,17 @@
+struct s {
+	int f:5;
+};
+
+void inc(struct s *p)
+{
+	p->f++;
+}
+
+/*
+ * check-name: bitfield-inc
+ * check-command: test-linearize -Wno-decl $file
+ * check-known-to-fail
+ *
+ * check-output-ignore
+ * check-output-excludes: add\\.5
+ */
diff --git a/validation/linear/bitfield-preinc.c b/validation/linear/bitfield-preinc.c
new file mode 100644
index 000000000..783327ae8
--- /dev/null
+++ b/validation/linear/bitfield-preinc.c
@@ -0,0 +1,18 @@
+struct s {
+	int f:3;
+};
+
+int preinc(void)
+{
+	struct s s = { 7 };
+	return ++s.f;
+}
+
+/*
+ * check-name: bitfield-preinc
+ * check-description: ++X is equivalent to X+=1
+ * check-command: test-linearize -Wno-decl $file
+ *
+ * check-output-ignore
+ * check-output-contains: ret.32 *\\$0
+ */
diff --git a/validation/linear/bitfield-store.c b/validation/linear/bitfield-store.c
new file mode 100644
index 000000000..3d952c8de
--- /dev/null
+++ b/validation/linear/bitfield-store.c
@@ -0,0 +1,22 @@
+int foo(void)
+{
+	struct {
+		int a:8;
+		int b:16;
+		int c:8;
+	} s = { 0xff, 0x0000, 0xff };
+
+	return s.b = 0x56781234;
+}
+
+/*
+ * check-name: bitfield-store
+ * check-command: test-linearize -Wno-decl $file
+ *
+ * check-output-ignore
+ * check-output-contains: ret\\..*\\$0x1234
+ *
+ * check-error-start
+linear/bitfield-store.c:9:22: warning: cast truncates bits from constant value (56781234 becomes 1234)
+ * check-error-end
+ */
diff --git a/validation/optim/and-extend.c b/validation/optim/and-extend.c
new file mode 100644
index 000000000..fdcf470f0
--- /dev/null
+++ b/validation/optim/and-extend.c
@@ -0,0 +1,28 @@
+typedef unsigned short u16;
+typedef          short s16;
+typedef unsigned   int u32;
+typedef            int s32;
+
+u32 ufoo(u32 x)
+{
+	u16 i = ((u16)x) & 0x7fffU;
+	return i;
+}
+
+u32 sfoo(u32 x)
+{
+	s16 i = ((s16)x) & 0x7fff;
+	return i;
+}
+
+/*
+ * check-name: and-extend
+ * check-command: test-linearize -Wno-decl $file
+ * check-known-to-fail
+ *
+ * check-output-ignore
+ * check-output-excludes: trunc\\.
+ * check-output-excludes: zext\\.
+ * check-output-excludes: sext\\.
+ * check-output-contains: and\\.32.*0x7fff
+ */
diff --git a/validation/optim/and-extendx.c b/validation/optim/and-extendx.c
new file mode 100644
index 000000000..a580bd0d6
--- /dev/null
+++ b/validation/optim/and-extendx.c
@@ -0,0 +1,25 @@
+typedef unsigned short u16;
+typedef          short s16;
+typedef unsigned   int u32;
+typedef            int s32;
+typedef unsigned  long long u64;
+typedef           long long s64;
+
+u64 ufoo(int x)
+{
+	return x & 0x7fff;
+}
+
+u64 sfoo(int x)
+{
+	return x & 0x7fff;
+}
+
+/*
+ * check-name: and-extend
+ * check-command: test-linearize -Wno-decl $file
+ * check-known-to-fail
+ *
+ * check-output-ignore
+ * check-output-contains: and\\.64.*0x7fff
+ */
diff --git a/validation/optim/and-lsr.c b/validation/optim/and-lsr.c
new file mode 100644
index 000000000..df6b72f36
--- /dev/null
+++ b/validation/optim/and-lsr.c
@@ -0,0 +1,16 @@
+// (x & M) >> S to (x >> S) & (M >> S)
+
+unsigned int foo(unsigned int x)
+{
+	return (x & 0xffff) >> 12;
+}
+
+/*
+ * check-name: and-lsr
+ * check-command: test-linearize -Wno-decl $file
+ * check-known-to-fail
+ *
+ * check-output-ignore
+ * check-output-contains: and\\..*\\$15
+ * check-output-excludes: and\\..*\\$0xffff
+ */
diff --git a/validation/optim/and-trunc.c b/validation/optim/and-trunc.c
new file mode 100644
index 000000000..bcb80bbe0
--- /dev/null
+++ b/validation/optim/and-trunc.c
@@ -0,0 +1,21 @@
+short smask(short x)
+{
+	return x & (short) 0x7fff;
+}
+
+short umask(unsigned short x)
+{
+	return x & (unsigned short) 0x7fff;
+}
+
+/*
+ * check-name: and-trunc
+ * check-command: test-linearize -Wno-decl $file
+ * check-known-to-fail
+ *
+ * check-output-ignore
+ * check-output-excludes: sext\\.
+ * check-output-excludes: zext\\.
+ * check-output-excludes: trunc\\.
+ * check-output-contains: and\\.16
+ */
diff --git a/validation/optim/ext-trunc-greater.c b/validation/optim/ext-trunc-greater.c
new file mode 100644
index 000000000..bb19e17b0
--- /dev/null
+++ b/validation/optim/ext-trunc-greater.c
@@ -0,0 +1,18 @@
+short sgt(char x)
+{
+	return (int) x;
+}
+
+short ugt(unsigned char x)
+{
+	return (int) x;
+}
+
+/*
+ * check-name: ext-trunc-greater
+ * check-command: test-linearize -Wno-decl $file
+ * check-known-to-fail
+ *
+ * check-output-ignore
+ * check-output-excludes: trunc\\.
+ */
diff --git a/validation/optim/ext-trunc-same.c b/validation/optim/ext-trunc-same.c
new file mode 100644
index 000000000..634fdb87a
--- /dev/null
+++ b/validation/optim/ext-trunc-same.c
@@ -0,0 +1,20 @@
+short seq(short x)
+{
+	return (int) x;
+}
+
+short ueq(unsigned short x)
+{
+	return (int) x;
+}
+
+/*
+ * check-name: ext-trunc-same
+ * check-command: test-linearize -Wno-decl $file
+ * check-known-to-fail
+ *
+ * check-output-ignore
+ * check-output-excludes: trunc\\.
+ * check-output-excludes: sext\\.
+ * check-output-excludes: zext\\.
+ */
diff --git a/validation/optim/ext-trunc-smaller.c b/validation/optim/ext-trunc-smaller.c
new file mode 100644
index 000000000..a757a3adc
--- /dev/null
+++ b/validation/optim/ext-trunc-smaller.c
@@ -0,0 +1,19 @@
+char  slt(short x)
+{
+	return (int) x;
+}
+
+char  ult(unsigned short x)
+{
+	return (int) x;
+}
+
+/*
+ * check-name: ext-trunc-smaller
+ * check-command: test-linearize -Wno-decl $file
+ * check-known-to-fail
+ *
+ * check-output-ignore
+ * check-output-excludes: sext\\.
+ * check-output-excludes: zext\\.
+ */
diff --git a/validation/optim/mask-lsr.c b/validation/optim/mask-lsr.c
new file mode 100644
index 000000000..1d37c91e0
--- /dev/null
+++ b/validation/optim/mask-lsr.c
@@ -0,0 +1,15 @@
+// ((x & M) | y) >> S to (y >> S) when (M >> S) == 0
+
+unsigned int foo(unsigned int x, unsigned int y)
+{
+	return ((x & 0xff) | y) >> 8;
+}
+
+/*
+ * check-name: mask-lsr
+ * check-command: test-linearize -Wno-decl $file
+ * check-known-to-fail
+ *
+ * check-output-ignore
+ * check-output-excludes: %arg1
+ */
diff --git a/validation/optim/mask-out.c b/validation/optim/mask-out.c
new file mode 100644
index 000000000..bf116873e
--- /dev/null
+++ b/validation/optim/mask-out.c
@@ -0,0 +1,13 @@
+unsigned mask(unsigned a, unsigned b)
+{
+	return ((a & 0xffff0000) | b) & 0x0000ffff;
+}
+
+/*
+ * check-name: mask-out
+ * check-command: test-linearize -Wno-decl $file
+ * check-known-to-fail
+ *
+ * check-output-ignore
+ * check-output-excludes: %arg1
+ */
diff --git a/validation/optim/sext-sext.c b/validation/optim/sext-sext.c
new file mode 100644
index 000000000..3f7a0efc7
--- /dev/null
+++ b/validation/optim/sext-sext.c
@@ -0,0 +1,13 @@
+int foo(signed char offset)
+{
+	return (int)(short) offset;
+}
+
+/*
+ * check-name: sext-sext
+ * check-command: test-linearize -Wno-decl $file
+ * check-known-to-fail
+ *
+ * check-output-ignore
+ * check-output-pattern(1): sext\\.
+ */
diff --git a/validation/optim/sext.c b/validation/optim/sext.c
new file mode 100644
index 000000000..719730d50
--- /dev/null
+++ b/validation/optim/sext.c
@@ -0,0 +1,15 @@
+int sext(int x)
+{
+	return (x << 5) >> 5;
+}
+
+/*
+ * check-name: sext
+ * check-command: test-linearize -Wno-decl $file
+ * check-known-to-fail
+ *
+ * check-output-ignore
+ * check-output-contains: sext\\.$27
+ * check-output-excludes: asr\\.
+ * check-output-excludes: shl\\.
+ */
diff --git a/validation/optim/shift-zext.c b/validation/optim/shift-zext.c
new file mode 100644
index 000000000..070416f30
--- /dev/null
+++ b/validation/optim/shift-zext.c
@@ -0,0 +1,13 @@
+unsigned int foo(unsigned int x)
+{
+	return (x << 20) >> 20;
+}
+
+/*
+ * check-name: shift-zext
+ * check-command: test-linearize -Wno-decl $file
+ * check-known-to-fail
+ *
+ * check-output-ignore
+ * check-output-contains: and\\..*%arg1, \\$0xfff
+ */
diff --git a/validation/optim/store-load-bitfield.c b/validation/optim/store-load-bitfield.c
new file mode 100644
index 000000000..1d8ff2402
--- /dev/null
+++ b/validation/optim/store-load-bitfield.c
@@ -0,0 +1,50 @@
+int ufoo(unsigned int a)
+{
+	struct u {
+		unsigned int :2;
+		unsigned int a:3;
+	} bf;
+
+	bf.a = a;
+	return bf.a;
+}
+
+int sfoo(int a)
+{
+	struct s {
+		signed int :2;
+		signed int a:3;
+	} bf;
+
+	bf.a = a;
+	return bf.a;
+}
+
+/*
+ * check-name: optim store/load bitfields
+ * check-command: test-linearize -Wno-decl $file
+ *
+ * check-output-start
+ufoo:
+.L0:
+	<entry-point>
+	and.32      %r4 <- %arg1, $7
+	shl.32      %r5 <- %r4, $2
+	lsr.32      %r9 <- %r5, $2
+	and.32      %r11 <- %r9, $7
+	ret.32      %r11
+
+
+sfoo:
+.L2:
+	<entry-point>
+	and.32      %r16 <- %arg1, $7
+	shl.32      %r17 <- %r16, $2
+	lsr.32      %r21 <- %r17, $2
+	trunc.3     %r22 <- (32) %r21
+	sext.32     %r23 <- (3) %r22
+	ret.32      %r23
+
+
+ * check-output-end
+ */
diff --git a/validation/optim/trunc-mask-zext.c b/validation/optim/trunc-mask-zext.c
new file mode 100644
index 000000000..30ae5aeeb
--- /dev/null
+++ b/validation/optim/trunc-mask-zext.c
@@ -0,0 +1,14 @@
+unsigned long long foo(unsigned long long x)
+{
+	return (((unsigned int) x) & 0x7ffU);
+}
+
+/*
+ * check-name: trunc-mask-zext
+ * check-command: test-linearize -Wno-decl $file
+ * check-known-to-fail
+ *
+ * check-output-ignore
+ * check-output-excludes: trunc\\.
+ * check-output-excludes: zext\\.
+ */
diff --git a/validation/optim/zext-and.c b/validation/optim/zext-and.c
new file mode 100644
index 000000000..2f4f3c805
--- /dev/null
+++ b/validation/optim/zext-and.c
@@ -0,0 +1,13 @@
+unsigned int foo(unsigned char x)
+{
+	return (unsigned int)x & 0xffffU;
+}
+
+/*
+ * check-name: zext-and
+ * check-command: test-linearize -Wno-decl $file
+ * check-known-to-fail
+ *
+ * check-output-ignore
+ * check-output-excludes: and\\.
+ */
diff --git a/validation/optim/zext-and1.c b/validation/optim/zext-and1.c
new file mode 100644
index 000000000..2ad011034
--- /dev/null
+++ b/validation/optim/zext-and1.c
@@ -0,0 +1,13 @@
+unsigned int bar(unsigned char x)
+{
+	return (unsigned int)x & 0xff01U;
+}
+
+/*
+ * check-name: zext-and1
+ * check-command: test-linearize -Wno-decl $file
+ * check-known-to-fail
+ *
+ * check-output-ignore
+ * check-output-contains: and\\..*\\$1
+ */
diff --git a/validation/optim/zext-sext.c b/validation/optim/zext-sext.c
new file mode 100644
index 000000000..b0964b542
--- /dev/null
+++ b/validation/optim/zext-sext.c
@@ -0,0 +1,14 @@
+int foo(unsigned char offset)
+{
+	return (int)(short) offset;
+}
+
+/*
+ * check-name: zext-sext
+ * check-command: test-linearize -Wno-decl $file
+ * check-known-to-fail
+ *
+ * check-output-ignore
+ * check-output-excludes: sext\\.
+ * check-output-pattern(1): zext\\.
+ */
diff --git a/validation/optim/zext-zext.c b/validation/optim/zext-zext.c
new file mode 100644
index 000000000..b88a6cca8
--- /dev/null
+++ b/validation/optim/zext-zext.c
@@ -0,0 +1,14 @@
+int foo(unsigned char offset)
+{
+	return (int)(unsigned short) offset;
+}
+
+/*
+ * check-name: zext-zext
+ * check-command: test-linearize -Wno-decl $file
+ * check-known-to-fail
+ *
+ * check-output-ignore
+ * check-output-excludes: sext\\.
+ * check-output-pattern(1): zext\\.
+ */
-- 
2.18.0

--
To unsubscribe from this list: send the line "unsubscribe linux-sparse" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Newbies FAQ]     [LKML]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Trinity Fuzzer Tool]

  Powered by Linux