aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/validation/mem2reg
diff options
Diffstat (limited to 'validation/mem2reg')
-rw-r--r--validation/mem2reg/alias-distinct.c17
-rw-r--r--validation/mem2reg/alias-mixed.c30
-rw-r--r--validation/mem2reg/alias-same.c17
-rw-r--r--validation/mem2reg/cond-expr.c1
-rw-r--r--validation/mem2reg/cond-expr5.c6
-rw-r--r--validation/mem2reg/init-global-array.c12
-rw-r--r--validation/mem2reg/init-local-array.c13
-rw-r--r--validation/mem2reg/killed-insn.c15
-rw-r--r--validation/mem2reg/loop02-global.c2
-rw-r--r--validation/mem2reg/missing-return.c34
-rw-r--r--validation/mem2reg/reload-aliasing.c41
-rw-r--r--validation/mem2reg/store-deadborn.c9
-rw-r--r--validation/mem2reg/stray-phisrc.c25
-rw-r--r--validation/mem2reg/struct.c32
-rw-r--r--validation/mem2reg/undef00.c14
-rw-r--r--validation/mem2reg/undef01.c16
-rw-r--r--validation/mem2reg/unused-var.c23
17 files changed, 278 insertions, 29 deletions
diff --git a/validation/mem2reg/alias-distinct.c b/validation/mem2reg/alias-distinct.c
new file mode 100644
index 00000000..42937b24
--- /dev/null
+++ b/validation/mem2reg/alias-distinct.c
@@ -0,0 +1,17 @@
+extern int g;
+extern int h;
+
+static int foo(void)
+{
+ g = 1;
+ h = 2;
+ return g == 1;
+}
+
+/*
+ * check-name: alias distinct symbols
+ * check-command: test-linearize $file
+ * check-output-ignore
+ *
+ * check-output-contains: ret\\..* *\\$1
+ */
diff --git a/validation/mem2reg/alias-mixed.c b/validation/mem2reg/alias-mixed.c
new file mode 100644
index 00000000..0cfbe36b
--- /dev/null
+++ b/validation/mem2reg/alias-mixed.c
@@ -0,0 +1,30 @@
+extern int g;
+
+
+static int foo(int *p)
+{
+ *p = 1;
+ g = 2;
+ return *p == 1;
+}
+
+static int bar(int *p)
+{
+ g = 1;
+ *p = 2;
+ return g == 1;
+}
+
+static void test(void)
+{
+ foo(&g);
+ bar(&g);
+}
+
+/*
+ * check-name: alias symbol/pointer
+ * check-command: test-linearize $file
+ * check-output-ignore
+ *
+ * check-output-excludes: ret\\..* *\\$1
+ */
diff --git a/validation/mem2reg/alias-same.c b/validation/mem2reg/alias-same.c
new file mode 100644
index 00000000..55cf4244
--- /dev/null
+++ b/validation/mem2reg/alias-same.c
@@ -0,0 +1,17 @@
+extern int g;
+
+
+static int foo(void)
+{
+ g = 1;
+ g = 2;
+ return g != 1;
+}
+
+/*
+ * check-name: alias same symbols
+ * check-command: test-linearize $file
+ * check-output-ignore
+ *
+ * check-output-contains: ret\\..* *\\$1
+ */
diff --git a/validation/mem2reg/cond-expr.c b/validation/mem2reg/cond-expr.c
index f38564ef..8acb00ac 100644
--- a/validation/mem2reg/cond-expr.c
+++ b/validation/mem2reg/cond-expr.c
@@ -10,4 +10,5 @@ int foo(int a, int b, int c)
* check-command: test-linearize -Wno-decl -fdump-ir=mem2reg $file
* check-output-ignore
* check-output-pattern(2): phi\\.
+ * check-output-pattern(3): phisrc\\.
*/
diff --git a/validation/mem2reg/cond-expr5.c b/validation/mem2reg/cond-expr5.c
index 6c1e1c34..62ac6c15 100644
--- a/validation/mem2reg/cond-expr5.c
+++ b/validation/mem2reg/cond-expr5.c
@@ -11,8 +11,12 @@ int foo(int p, int q, int a)
/*
* check-name: cond-expr5
* check-command: test-linearize -Wno-decl -fdump-ir=mem2reg $file
+ * check-known-to-fail
+ *
* check-output-ignore
* check-output-excludes: load\\.
* check-output-excludes: store\\.
- * check-output-pattern(2): phi\\.
+ * check-output-excludes: phi\\..*, .*, .*
+ * check-output-pattern(3): phi\\.
+ * check-output-pattern(5): phisrc\\.
*/
diff --git a/validation/mem2reg/init-global-array.c b/validation/mem2reg/init-global-array.c
index aea4135a..51ca50e3 100644
--- a/validation/mem2reg/init-global-array.c
+++ b/validation/mem2reg/init-global-array.c
@@ -1,8 +1,11 @@
-struct {
+struct s {
int a[2];
-} s;
+};
-int sarray(void)
+
+static struct s s;
+
+static int sarray(void)
{
s.a[1] = 1;
return s.a[1];
@@ -10,8 +13,9 @@ int sarray(void)
/*
* check-name: init global array
- * check-command: test-linearize -Wno-decl -fdump-ir=mem2reg $file
+ * check-command: test-linearize $file
* check-output-ignore
* check-output-excludes: load\\.
* check-output-pattern(1): store\\.
+ * check-output-pattern(1): ret.32 *\\$1
*/
diff --git a/validation/mem2reg/init-local-array.c b/validation/mem2reg/init-local-array.c
index 2ac53bc7..639a74f1 100644
--- a/validation/mem2reg/init-local-array.c
+++ b/validation/mem2reg/init-local-array.c
@@ -1,25 +1,28 @@
-int array(void)
+static int array(void)
{
int a[2];
a[1] = 1;
+ a[0] = 0;
return a[1];
}
-int sarray(void)
+static int sarray(void)
{
struct {
int a[2];
} s;
s.a[1] = 1;
+ s.a[0] = 0;
return s.a[1];
}
/*
* check-name: init local array
- * check-command: test-linearize -Wno-decl -fdump-ir=mem2reg $file
+ * check-command: test-linearize $file
* check-output-ignore
- * check-output-excludes: load\\.
- * check-output-excludes: store\\.
+ * check-output-excludes: load
+ * check-output-excludes: store
+ * check-output-pattern(2): ret.32 *\\$1
*/
diff --git a/validation/mem2reg/killed-insn.c b/validation/mem2reg/killed-insn.c
deleted file mode 100644
index adbef980..00000000
--- a/validation/mem2reg/killed-insn.c
+++ /dev/null
@@ -1,15 +0,0 @@
-static int g;
-static void foo(void)
-{
- int a[2] = { };
- a;
- a[1] = g;
-}
-
-/*
- * check-name: killed-insn
- * check-command: test-linearize -fdump-ir=mem2reg $file
- *
- * check-output-ignore
- * check-output-excludes: store\\.
- */
diff --git a/validation/mem2reg/loop02-global.c b/validation/mem2reg/loop02-global.c
index a0a8b42b..b627b33d 100644
--- a/validation/mem2reg/loop02-global.c
+++ b/validation/mem2reg/loop02-global.c
@@ -16,7 +16,7 @@ int foo(void)
/*
* check-name: loop02 global
- * check-command: test-linearize -Wno-decl -fdump-ir=mem2reg $file
+ * check-command: test-linearize -Wno-decl $file
* check-output-ignore
* check-output-excludes: load\\.
*/
diff --git a/validation/mem2reg/missing-return.c b/validation/mem2reg/missing-return.c
new file mode 100644
index 00000000..06f6e4d5
--- /dev/null
+++ b/validation/mem2reg/missing-return.c
@@ -0,0 +1,34 @@
+int f1(void)
+{
+ if (1)
+ return 1;
+}
+
+int f0(void)
+{
+ if (0)
+ return 0;
+}
+
+int fx(int p)
+{
+ if (p)
+ return 0;
+}
+
+int bar(int p)
+{
+ if (p)
+ return 0;
+ p++;
+}
+
+/*
+ * check-name: missing-return
+ * check-command: test-linearize -m32 -fdump-ir=mem2reg -Wno-decl $file
+ * check-known-to-fail
+ *
+ * check-output-ignore
+ * check-output-pattern(1): ret.32 *\\$1
+ * check-output-pattern(3): ret.32 *UNDEF
+ */
diff --git a/validation/mem2reg/reload-aliasing.c b/validation/mem2reg/reload-aliasing.c
new file mode 100644
index 00000000..3aad317b
--- /dev/null
+++ b/validation/mem2reg/reload-aliasing.c
@@ -0,0 +1,41 @@
+extern int g, h;
+
+void f00(int *s)
+{
+ g = *s;
+ h = *s;
+}
+
+void f01(int *a, int *b, int *s)
+{
+ *a = *s;
+ *b = *s;
+}
+
+/*
+ * check-name: reload-aliasing.c
+ * check-command: test-linearize -Wno-decl $file
+ *
+ * check-output-start
+f00:
+.L0:
+ <entry-point>
+ load.32 %r2 <- 0[%arg1]
+ store.32 %r2 -> 0[g]
+ load.32 %r4 <- 0[%arg1]
+ store.32 %r4 -> 0[h]
+ ret
+
+
+f01:
+.L2:
+ <entry-point>
+ load.32 %r6 <- 0[%arg3]
+ store.32 %r6 -> 0[%arg1]
+ load.32 %r9 <- 0[%arg3]
+ store.32 %r9 -> 0[%arg2]
+ ret
+
+
+ * check-output-end
+ */
diff --git a/validation/mem2reg/store-deadborn.c b/validation/mem2reg/store-deadborn.c
new file mode 100644
index 00000000..cca34d59
--- /dev/null
+++ b/validation/mem2reg/store-deadborn.c
@@ -0,0 +1,9 @@
+static void foo(int a)
+{
+ return;
+ a = 0;
+}
+
+/*
+ * check-name: store-deadborn
+ */
diff --git a/validation/mem2reg/stray-phisrc.c b/validation/mem2reg/stray-phisrc.c
new file mode 100644
index 00000000..e9f35c89
--- /dev/null
+++ b/validation/mem2reg/stray-phisrc.c
@@ -0,0 +1,25 @@
+static int foo(int **g)
+{
+ int i = 1;
+ int *a[2];
+ int **p;
+
+ a[1] = &i;
+ if (g)
+ p = g;
+ else
+ p = &a[0];
+ p += 1; // will point to a[1] = &i
+ if (!g)
+ **p = 0;
+ return i;
+}
+
+/*
+ * check-name: stray phisrc
+ * check-command: test-linearize -Wno-decl $file
+ * check-known-to-fail
+ *
+ * check-output-ignore
+ * check-output-excludes: phisrc\\.
+ */
diff --git a/validation/mem2reg/struct.c b/validation/mem2reg/struct.c
new file mode 100644
index 00000000..13962a8e
--- /dev/null
+++ b/validation/mem2reg/struct.c
@@ -0,0 +1,32 @@
+struct s {
+ int a;
+ int b;
+};
+
+int f0(void)
+{
+ struct s s;
+
+ s.a = 0;
+ s.b = 1;
+
+ return s.a;
+}
+
+int f1(void)
+{
+ struct s s;
+
+ s.a = 1;
+ s.b = 0;
+
+ return s.b;
+}
+
+/*
+ * check-name: struct
+ * check-command: test-linearize -Wno-decl $file
+ *
+ * check-output-ignore
+ * check-output-pattern(2): ret.32 *\\$0
+ */
diff --git a/validation/mem2reg/undef00.c b/validation/mem2reg/undef00.c
index ba9ba915..27f0aaa8 100644
--- a/validation/mem2reg/undef00.c
+++ b/validation/mem2reg/undef00.c
@@ -1,14 +1,22 @@
-void bad0(void)
+static int badr(void)
{
int *a;
- *a++;
+ return *a;
+}
+
+static void badw(int v)
+{
+ int *a;
+ *a = v;
}
/*
* check-name: undef00
- * check-command: test-linearize -Wno-decl -fdump-ir=mem2reg $file
+ * check-command: test-linearize -fdump-ir=mem2reg $file
* check-known-to-fail
* check-output-ignore
* check-output-pattern(1): load\\.
* check-output-pattern(1): load\\..*\\[UNDEF\\]
+ * check-output-pattern(1): store\\.
+ * check-output-pattern(1): store\\..*\\[UNDEF\\]
*/
diff --git a/validation/mem2reg/undef01.c b/validation/mem2reg/undef01.c
new file mode 100644
index 00000000..985c73d6
--- /dev/null
+++ b/validation/mem2reg/undef01.c
@@ -0,0 +1,16 @@
+static void foo(void)
+{
+ int *b;
+ for (;;)
+ *b++ = 0;
+}
+
+/*
+ * check-name: undef01
+ * check-command: sparse -Wmaybe-uninitialized $file
+ * check-known-to-fail
+ *
+ * check-error-start
+crazy04.c:3:13: warning: variable 'b' may be uninitialized
+ * check-error-end
+ */
diff --git a/validation/mem2reg/unused-var.c b/validation/mem2reg/unused-var.c
new file mode 100644
index 00000000..ac394582
--- /dev/null
+++ b/validation/mem2reg/unused-var.c
@@ -0,0 +1,23 @@
+int foo(int a)
+{
+ switch (a) {
+ int u = 1;
+
+ default:
+ return a;
+ }
+}
+
+/*
+ * check-name: unused-var
+ * check-command: test-linearize -Wno-decl $file
+ *
+ * check-output-start
+foo:
+.L0:
+ <entry-point>
+ ret.32 %arg1
+
+
+ * check-output-end
+ */