aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/validation
diff options
Diffstat (limited to 'validation')
-rw-r--r--validation/eval/not-cast-bool.c14
-rw-r--r--validation/eval/not-cast-float.c14
-rw-r--r--validation/memops/kill-dead-store-parent0.c14
-rw-r--r--validation/memops/kill-dead-store-parent2.c25
-rw-r--r--validation/memops/kill-redundant-store0.c13
-rw-r--r--validation/optim/and-extendx.c24
-rw-r--r--validation/optim/bad-phisrc1.c15
-rw-r--r--validation/optim/bad-phisrc1a.c23
-rw-r--r--validation/optim/bad-phisrc2.c16
-rw-r--r--validation/optim/bad-phisrc3.c20
-rw-r--r--validation/optim/canonical-cmp-zero.c74
-rw-r--r--validation/optim/cmp-and-pow2.c12
-rw-r--r--validation/optim/multi-phisrc.c23
-rw-r--r--validation/optim/phi-count00.c27
-rw-r--r--validation/optim/range-check1.c16
-rw-r--r--validation/optim/range-check2.c14
-rw-r--r--validation/optim/trunc-not0.c20
-rw-r--r--validation/scheck/ko.c10
-rw-r--r--validation/scheck/ok.c22
-rwxr-xr-xvalidation/test-suite6
20 files changed, 378 insertions, 24 deletions
diff --git a/validation/eval/not-cast-bool.c b/validation/eval/not-cast-bool.c
new file mode 100644
index 00000000..acd8bbf2
--- /dev/null
+++ b/validation/eval/not-cast-bool.c
@@ -0,0 +1,14 @@
+static _Bool foo(void)
+{
+ unsigned char c = 1;
+ _Bool b = ~c;
+ return b;
+}
+
+/*
+ * check-name: not-cast-bool
+ * check-command: test-linearize -Wno-decl $file
+ *
+ * check-output-ignore
+ * check-output-returns: 1
+ */
diff --git a/validation/eval/not-cast-float.c b/validation/eval/not-cast-float.c
new file mode 100644
index 00000000..d474d69b
--- /dev/null
+++ b/validation/eval/not-cast-float.c
@@ -0,0 +1,14 @@
+static int foo(void)
+{
+ int i = 123;
+ float x = ~i;
+ return (x < 0);
+}
+
+/*
+ * check-name: eval-bool-zext-neg
+ * check-command: test-linearize -Wno-decl $file
+ *
+ * check-output-ignore
+ * check-output-returns: 1
+ */
diff --git a/validation/memops/kill-dead-store-parent0.c b/validation/memops/kill-dead-store-parent0.c
new file mode 100644
index 00000000..c1b2466c
--- /dev/null
+++ b/validation/memops/kill-dead-store-parent0.c
@@ -0,0 +1,14 @@
+void foo(int *ptr, int p)
+{
+ if (p)
+ *ptr = 1;
+ *ptr = 0;
+}
+
+/*
+ * check-name: kill-dead-store-parent0
+ * check-command: test-linearize -Wno-decl $file
+ *
+ * check-output-ignore
+ * check-output-pattern(1): store
+ */
diff --git a/validation/memops/kill-dead-store-parent2.c b/validation/memops/kill-dead-store-parent2.c
new file mode 100644
index 00000000..4f7b9dd9
--- /dev/null
+++ b/validation/memops/kill-dead-store-parent2.c
@@ -0,0 +1,25 @@
+int ladder02(int *ptr, int p, int x)
+{
+ *ptr = x++;
+ if (p)
+ goto l11;
+ else
+ goto l12;
+l11:
+ *ptr = x++;
+ goto l20;
+l12:
+ *ptr = x++;
+ goto l20;
+l20:
+ *ptr = x++;
+ return *ptr;
+}
+
+/*
+ * check-name: kill-dead-store-parent2
+ * check-command: test-linearize -Wno-decl $file
+ *
+ * check-output-ignore
+ * check-output-pattern(1): store
+ */
diff --git a/validation/memops/kill-redundant-store0.c b/validation/memops/kill-redundant-store0.c
new file mode 100644
index 00000000..8819938f
--- /dev/null
+++ b/validation/memops/kill-redundant-store0.c
@@ -0,0 +1,13 @@
+void foo(int *ptr)
+{
+ int i = *ptr;
+ *ptr = i;
+}
+
+/*
+ * check-name: kill-redundant-store0
+ * check-command: test-linearize -Wno-decl $file
+ *
+ * check-output-ignore
+ * check-output-excludes: store
+ */
diff --git a/validation/optim/and-extendx.c b/validation/optim/and-extendx.c
deleted file mode 100644
index 5c181c93..00000000
--- a/validation/optim/and-extendx.c
+++ /dev/null
@@ -1,24 +0,0 @@
-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-output-ignore
- * check-output-contains: and\\.64.*0x7fff
- */
diff --git a/validation/optim/bad-phisrc1.c b/validation/optim/bad-phisrc1.c
new file mode 100644
index 00000000..aa12dd0a
--- /dev/null
+++ b/validation/optim/bad-phisrc1.c
@@ -0,0 +1,15 @@
+void foo(int a, int b)
+{
+ if (b)
+ while ((a += 5) > a)
+ ;
+}
+
+/*
+ * check-name: bad-phisrc1
+ * check-command: test-linearize -Wno-decl $file
+ *
+ * check-output-ignore
+ * check-output-excludes: phi\\.
+ * check-output-excludes: phisource\\.
+ */
diff --git a/validation/optim/bad-phisrc1a.c b/validation/optim/bad-phisrc1a.c
new file mode 100644
index 00000000..b7519ee7
--- /dev/null
+++ b/validation/optim/bad-phisrc1a.c
@@ -0,0 +1,23 @@
+int def(void);
+
+int fun4(struct xfrm_state *net, int cnt)
+{
+ int err = 0;
+ if (err)
+ goto out;
+ for (; net;)
+ err = def();
+ if (cnt)
+out:
+ return err;
+ return 0;
+}
+
+/*
+ * check-name: bad-phisrc1a
+ * check-command: test-linearize -Wno-decl $file
+ *
+ * check-output-ignore
+ * check-output-contains: select\\.
+ */
+
diff --git a/validation/optim/bad-phisrc2.c b/validation/optim/bad-phisrc2.c
new file mode 100644
index 00000000..78eae288
--- /dev/null
+++ b/validation/optim/bad-phisrc2.c
@@ -0,0 +1,16 @@
+int bad_phisrc2(int p, int a, int r)
+{
+ if (p)
+ r = a;
+ else if (r)
+ ;
+ return r;
+}
+
+/*
+ * check-name: bad-phisrc2
+ * check-command: test-linearize -Wno-decl $file
+ *
+ * check-output-ignore
+ * check-output-contains: select\\.
+ */
diff --git a/validation/optim/bad-phisrc3.c b/validation/optim/bad-phisrc3.c
new file mode 100644
index 00000000..41537420
--- /dev/null
+++ b/validation/optim/bad-phisrc3.c
@@ -0,0 +1,20 @@
+void foo(void)
+{
+ int c = 1;
+ switch (3) {
+ case 0:
+ do {
+ ;
+ case 3: ;
+ } while (c++);
+ }
+}
+
+/*
+ * check-name: bad-phisrc3
+ * check-command: test-linearize -Wno-decl $file
+ *
+ * check-output-ignore
+ * check-output-pattern(2): phisrc\\.
+ * check-output-pattern(1): phi\\.
+ */
diff --git a/validation/optim/canonical-cmp-zero.c b/validation/optim/canonical-cmp-zero.c
new file mode 100644
index 00000000..e01a00e6
--- /dev/null
+++ b/validation/optim/canonical-cmp-zero.c
@@ -0,0 +1,74 @@
+int f00(int x) { return x >= 0; }
+int f01(int x) { return x > -1; }
+int f02(int x) { return x < 1; }
+int f03(int x) { return x <= 0; }
+
+int f10(int x) { return x < 16; }
+int f11(int x) { return x <= 15; }
+
+int f20(int x) { return x > -9; }
+int f21(int x) { return x >= -8; }
+
+/*
+ * check-name: canonical-cmp-zero
+ * check-command: test-linearize -Wno-decl $file
+ *
+ * check-output-start
+f00:
+.L0:
+ <entry-point>
+ setge.32 %r2 <- %arg1, $0
+ ret.32 %r2
+
+
+f01:
+.L2:
+ <entry-point>
+ setge.32 %r5 <- %arg1, $0
+ ret.32 %r5
+
+
+f02:
+.L4:
+ <entry-point>
+ setle.32 %r8 <- %arg1, $0
+ ret.32 %r8
+
+
+f03:
+.L6:
+ <entry-point>
+ setle.32 %r11 <- %arg1, $0
+ ret.32 %r11
+
+
+f10:
+.L8:
+ <entry-point>
+ setle.32 %r14 <- %arg1, $15
+ ret.32 %r14
+
+
+f11:
+.L10:
+ <entry-point>
+ setle.32 %r17 <- %arg1, $15
+ ret.32 %r17
+
+
+f20:
+.L12:
+ <entry-point>
+ setge.32 %r20 <- %arg1, $0xfffffff8
+ ret.32 %r20
+
+
+f21:
+.L14:
+ <entry-point>
+ setge.32 %r23 <- %arg1, $0xfffffff8
+ ret.32 %r23
+
+
+ * check-output-end
+ */
diff --git a/validation/optim/cmp-and-pow2.c b/validation/optim/cmp-and-pow2.c
new file mode 100644
index 00000000..01ba2537
--- /dev/null
+++ b/validation/optim/cmp-and-pow2.c
@@ -0,0 +1,12 @@
+#define M 32
+
+_Bool eq(int a) { return ((a & M) != M) == ((a & M) == 0); }
+_Bool ne(int a) { return ((a & M) == M) == ((a & M) != 0); }
+
+/*
+ * check-name: cmp-and-pow2
+ * check-command: test-linearize -Wno-decl $file
+ *
+ * check-output-ignore
+ * check-output-returns: 1
+ */
diff --git a/validation/optim/multi-phisrc.c b/validation/optim/multi-phisrc.c
new file mode 100644
index 00000000..ff31c083
--- /dev/null
+++ b/validation/optim/multi-phisrc.c
@@ -0,0 +1,23 @@
+void fun(void);
+
+void foo(int p, int a)
+{
+ if (p == p) {
+ switch (p) {
+ case 0:
+ break;
+ case 1:
+ a = 0;
+ }
+ }
+ if (a)
+ fun();
+}
+
+/*
+ * check-name: multi-phisrc
+ * check-command: test-linearize -Wno-decl $file
+ *
+ * check-output-ignore
+ * check-output-excludes: phi
+ */
diff --git a/validation/optim/phi-count00.c b/validation/optim/phi-count00.c
new file mode 100644
index 00000000..38db0eda
--- /dev/null
+++ b/validation/optim/phi-count00.c
@@ -0,0 +1,27 @@
+inline int inl(int d, int e, int f)
+{
+ switch (d) {
+ case 0:
+ return e;
+ case 1:
+ return f;
+ default:
+ return 0;
+ }
+}
+
+void foo(int a, int b, int c)
+{
+ while (1) {
+ if (inl(a, b, c))
+ break;
+ }
+}
+
+/*
+ * check-name: phi-count00
+ * check-command: test-linearize -Wno-decl $file
+ *
+ * check-output-ignore
+ * check-output-pattern(0,2): phisrc
+ */
diff --git a/validation/optim/range-check1.c b/validation/optim/range-check1.c
new file mode 100644
index 00000000..358da045
--- /dev/null
+++ b/validation/optim/range-check1.c
@@ -0,0 +1,16 @@
+#define N 1024
+
+_Bool check_ok(long i)
+{
+ return i >= 0 && i < N;
+}
+
+/*
+ * check-name: range-check1
+ * check-command: test-linearize -Wno-decl $file
+ *
+ * check-output-ignore
+ * check-output-contains: setbe\\..*0x3ff
+ * check-output-excludes: set[lga][te]\\.
+ * check-output-excludes: set[ab]\\.
+ */
diff --git a/validation/optim/range-check2.c b/validation/optim/range-check2.c
new file mode 100644
index 00000000..69c01b9d
--- /dev/null
+++ b/validation/optim/range-check2.c
@@ -0,0 +1,14 @@
+#define N 1024
+
+_Bool check_ok(int i)
+{
+ return (i >= 0 && i < N) == (((unsigned int)i) < N);
+}
+
+/*
+ * check-name: range-check2
+ * check-command: test-linearize -Wno-decl $file
+ *
+ * check-output-ignore
+ * check-output-returns: 1
+ */
diff --git a/validation/optim/trunc-not0.c b/validation/optim/trunc-not0.c
new file mode 100644
index 00000000..882b446d
--- /dev/null
+++ b/validation/optim/trunc-not0.c
@@ -0,0 +1,20 @@
+typedef __INT32_TYPE__ int32;
+typedef __INT64_TYPE__ int64;
+
+static _Bool sfoo(int64 a) { return ((int32) ~a) == (~ (int32)a); }
+static _Bool sbar(int64 a) { return (~(int32) ~a) == (int32)a; }
+
+
+typedef __UINT32_TYPE__ uint32;
+typedef __UINT64_TYPE__ uint64;
+
+static _Bool ufoo(uint64 a) { return ((uint32) ~a) == (~ (uint32)a); }
+static _Bool ubar(uint64 a) { return (~(uint32) ~a) == (uint32)a; }
+
+/*
+ * check-name: trunc-not0
+ * check-command: test-linearize -Wno-decl $file
+ *
+ * check-output-ignore
+ * check-output-returns: 1
+ */
diff --git a/validation/scheck/ko.c b/validation/scheck/ko.c
new file mode 100644
index 00000000..dbd861ea
--- /dev/null
+++ b/validation/scheck/ko.c
@@ -0,0 +1,10 @@
+static void ko(int x)
+{
+ __assert((~x) == (~0 + x));
+}
+
+/*
+ * check-name: scheck-ko
+ * check-command: scheck $file
+ * check-known-to-fail
+ */
diff --git a/validation/scheck/ok.c b/validation/scheck/ok.c
new file mode 100644
index 00000000..1e5314f2
--- /dev/null
+++ b/validation/scheck/ok.c
@@ -0,0 +1,22 @@
+static void ok(int x)
+{
+ __assert((~x) == (~0 - x)); // true but not simplified yet
+ __assert_eq(~x, ~0 - x);
+ __assert_const(x & 0, 0);
+}
+
+static void always(int x)
+{
+ __assert((x - x) == 0); // true and simplified
+}
+
+static void assumed(int x, int a, int b)
+{
+ __assume((a & ~b) == 0);
+ __assert_eq((x ^ a) | b, x | b);
+}
+
+/*
+ * check-name: scheck-ok
+ * check-command: scheck $file
+ */
diff --git a/validation/test-suite b/validation/test-suite
index 370cd35a..305edd1f 100755
--- a/validation/test-suite
+++ b/validation/test-suite
@@ -13,6 +13,9 @@ prog_name=`basename $0`
if [ ! -x "$default_path/sparse-llvm" ]; then
disabled_cmds="sparsec sparsei sparse-llvm sparse-llvm-dis"
fi
+if [ ! -x "$default_path/scheck" ]; then
+ disabled_cmds="$disabled_cmds scheck"
+fi
# flags:
# - some tests gave an unexpected result
@@ -514,6 +517,7 @@ echo " -f write a test known to fail"
echo " -l write a test for linearized code"
echo " -r write a test for linearized code returning 1"
echo " -p write a test for pre-processing"
+echo " -s write a test for symbolic checking"
echo
echo "argument(s):"
echo " file file containing the test case(s)"
@@ -545,6 +549,8 @@ do_format()
ret=1 ;;
-p)
def_cmd='sparse -E $file' ;;
+ -s)
+ def_cmd='scheck $file' ;;
help|-*)
do_format_help