summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorGravatar xleroy <xleroy@fca1b0fc-160b-0410-b1d3-a4f43f01ea2e>2012-10-06 15:46:47 +0000
committerGravatar xleroy <xleroy@fca1b0fc-160b-0410-b1d3-a4f43f01ea2e>2012-10-06 15:46:47 +0000
commitf7693b3d897b90fd3bc2533be002dc0bdcd9f6c2 (patch)
tree93ea9491693324d2d690c4236a2c88c3b461e225 /test
parent261ef24f7fd2ef443f73c468b9b1fa496371f3bf (diff)
Merge of branch seq-and-or. See Changelog for details.
git-svn-id: https://yquem.inria.fr/compcert/svn/compcert/trunk@2059 fca1b0fc-160b-0410-b1d3-a4f43f01ea2e
Diffstat (limited to 'test')
-rw-r--r--test/c/spectral.c2
-rw-r--r--test/cminor/almabench.cmp12
-rw-r--r--test/cminor/qsort.cm6
-rw-r--r--test/cminor/stopcopy.cmp3
-rw-r--r--test/regression/Makefile4
-rw-r--r--test/regression/Results/compar4
-rw-r--r--test/regression/compar.c80
-rw-r--r--test/regression/seqops.c87
8 files changed, 187 insertions, 11 deletions
diff --git a/test/c/spectral.c b/test/c/spectral.c
index 68579d9..29499fd 100644
--- a/test/c/spectral.c
+++ b/test/c/spectral.c
@@ -10,7 +10,7 @@
#include <stdlib.h>
#include <math.h>
-double eval_A(int i, int j) { return 1.0/((i+j)*(i+j+1)/2+i+1); }
+inline double eval_A(int i, int j) { return 1.0/((i+j)*(i+j+1)/2+i+1); }
void eval_A_times_u(int N, const double u[], double Au[])
{
diff --git a/test/cminor/almabench.cmp b/test/cminor/almabench.cmp
index bafcb5d..caedf8b 100644
--- a/test/cminor/almabench.cmp
+++ b/test/cminor/almabench.cmp
@@ -46,10 +46,12 @@ extern "fmod": float -> float -> float
"anpm"(a): float -> float
{
- var w;
+ var w, t;
w = fmod(a,TWOPI);
- if (absf(w) >=f PI)
- w = w -f ((a <f 0.0) ? -f TWOPI : TWOPI);
+ if (absf(w) >=f PI) {
+ if (a <f 0.0) { t = -f TWOPI; } else { t = TWOPI; }
+ w = w -f t;
+ }
return w;
}
@@ -109,8 +111,8 @@ extern "fmod": float -> float -> float
ae = ae +f dae;
k = k + 1;
- if ((k >= 10) || (absf(dae) <f 1e-12))
- exit;
+ if (k >= 10) exit;
+ if (absf(dae) <f 1e-12) exit;
} }}
ae2 = ae /f 2.0;
diff --git a/test/cminor/qsort.cm b/test/cminor/qsort.cm
index 004f8cd..8c73584 100644
--- a/test/cminor/qsort.cm
+++ b/test/cminor/qsort.cm
@@ -9,11 +9,13 @@
{{ loop {
if (! (i < j)) exit;
{{ loop {
- if (i >= hi || int32[a + i * 4] > pivot) exit;
+ if (i >= hi) exit;
+ if (int32[a + i * 4] > pivot) exit;
i = i + 1;
} }}
{{ loop {
- if (j <= lo || int32[a + j * 4] < pivot) exit;
+ if (j <= lo) exit;
+ if (int32[a + j * 4] < pivot) exit;
j = j - 1;
} }}
if (i < j) {
diff --git a/test/cminor/stopcopy.cmp b/test/cminor/stopcopy.cmp
index 9ac39be..eb2b3e1 100644
--- a/test/cminor/stopcopy.cmp
+++ b/test/cminor/stopcopy.cmp
@@ -174,8 +174,9 @@ extern "malloc" : int -> int
var from, to;
from = "malloc"(hsize) : int -> int;
+ if (from == 0) return -1;
to = "malloc"(hsize) : int -> int;
- if (from == 0 || to == 0) return -1;
+ if (to == 0) return -1;
int32["fromspace_start_ptr"] = from;
int32["fromspace_end_ptr"] = from + hsize;
int32["tospace_start_ptr"] = to;
diff --git a/test/regression/Makefile b/test/regression/Makefile
index 186bddd..a649f88 100644
--- a/test/regression/Makefile
+++ b/test/regression/Makefile
@@ -12,12 +12,12 @@ TESTS=attribs1 bitfields1 bitfields2 bitfields3 bitfields4 \
expr1 expr6 initializers volatile1 volatile2 volatile3 \
funct3 expr5 struct7 struct8 struct11 casts1 casts2 char1 \
sizeof1 sizeof2 packedstruct1 packedstruct2 \
- instrsel bool
+ instrsel bool compar
# Other tests: should compile to .s without errors (but expect warnings)
EXTRAS=annot1 commaprec expr2 expr3 expr4 extern1 funct2 funptr1 init1 \
init2 init3 init4 pragmas ptrs1 ptrs2 struct1 struct2 struct3 \
- struct4 struct5 struct6 struct9 struct10 types1
+ struct4 struct5 struct6 struct9 struct10 types1 seqops
# Test known to fail
FAILURES=funct1 varargs1
diff --git a/test/regression/Results/compar b/test/regression/Results/compar
new file mode 100644
index 0000000..da99076
--- /dev/null
+++ b/test/regression/Results/compar
@@ -0,0 +1,4 @@
+f(0, 0, 0) = 0x61f8
+g(0, 0, 0) = 0x1f86
+f(12, 1, "x") = 0xae07
+g(12, 1, "x") = 0xe075
diff --git a/test/regression/compar.c b/test/regression/compar.c
new file mode 100644
index 0000000..14ce34b
--- /dev/null
+++ b/test/regression/compar.c
@@ -0,0 +1,80 @@
+/* Code generation for comparisons */
+
+#include <stdio.h>
+
+unsigned int f(int x, unsigned int y, char * z)
+{
+ unsigned int r = 0;
+
+ /* Without explicit comparison */
+ if (x) r |= 1;
+ if (y) r |= 2;
+ if (z) r |= 4;
+
+ /* Negated comparisons */
+ if (!x) r |= 8;
+ if (!y) r |= 0x10;
+ if (!z) r |= 0x20;
+
+ /* Explicit comparisons against 0 */
+ if (x == 0) r |= 0x40;
+ if (y == 0) r |= 0x80;
+ if (z == 0) r |= 0x100;
+
+ if (x != 0) r |= 0x200;
+ if (y != 0) r |= 0x400;
+ if (z != 0) r |= 0x800;
+
+ /* With masks */
+ if (x & 1) r |= 0x1000;
+ if (!(x & 2)) r |= 0x2000;
+ if ((x & 4) == 0) r |= 0x4000;
+ if ((x & 8) != 0) r |= 0x8000;
+
+ return r;
+}
+
+/* Same, but we compute the boolean value of the tests */
+
+unsigned int g(int x, unsigned int y, char * z)
+{
+ unsigned int r = 0;
+
+#define MERGE(tst) r = (r << 1) | (tst)
+
+ /* Without explicit comparison */
+ MERGE((_Bool) x);
+ MERGE((_Bool) y);
+ MERGE((_Bool) z);
+
+ /* Negated comparisons */
+ MERGE((_Bool) !x);
+ MERGE((_Bool) !y);
+ MERGE((_Bool) !z);
+
+ /* Explicit comparisons against 0 */
+ MERGE(x == 0);
+ MERGE(y == 0);
+ MERGE(z == 0);
+
+ MERGE(x != 0);
+ MERGE(y != 0);
+ MERGE(z != 0);
+
+ /* With masks */
+ MERGE((_Bool) (x & 1));
+ MERGE(! (x & 2));
+ MERGE((x & 4) == 0);
+ MERGE((x & 8) != 0);
+
+ return r;
+}
+
+int main(void)
+{
+ printf("f(0, 0, 0) = 0x%x\n", f(0, 0, 0));
+ printf("g(0, 0, 0) = 0x%x\n", g(0, 0, 0));
+ printf("f(12, 1, \"x\") = 0x%x\n", f(12, 1, "x"));
+ printf("g(12, 1, \"x\") = 0x%x\n", g(12, 1, "x"));
+ return 0;
+}
diff --git a/test/regression/seqops.c b/test/regression/seqops.c
new file mode 100644
index 0000000..c9ee549
--- /dev/null
+++ b/test/regression/seqops.c
@@ -0,0 +1,87 @@
+int and1(int x, int y) { return x && y; }
+
+int and2(int x, int y) { return (x == 1) && (y > 0); }
+
+int and3(int x, int y) { if (x == 1 && y > 0) return 12; else return 16; }
+
+extern int f(int);
+
+int and4(int x, int y) { if (f(x) == 1 && f(y) > 0) return 12; else return 16; }
+
+int and5(int x, int y) {
+ int z;
+ if (x == 1 && y > 0) { z = f(x); return z; } else { return 0; }
+}
+
+int and6(int x)
+{
+ while (x >= 0 && f(x) < 0) x--;
+ return x;
+}
+
+int and3l(int x, int y, int z) { return (f(x) && f(y)) && f(z); }
+
+int and3r(int x, int y, int z) { return f(x) && (f(y) && f(z)); }
+
+int and4l(int x, int y, int z, int u) { return ((f(x) && f(y)) && f(z)) && f(u); }
+
+int and4r(int x, int y, int z, int u) { return f(x) && (f(y) && (f(z) && f(u))); }
+
+int and4b(int x, int y, int z, int u) { return (f(x) && f(y)) && (f(z) && f(u)); }
+
+int or1(int x, int y) { return x || y; }
+
+int or2(int x, int y) { return (x == 1) || (y > 0); }
+
+int or3(int x, int y) { if (x == 1 || y > 0) return 12; else return 16; }
+
+int or4(int x, int y) { if (f(x) == 1 || f(y) > 0) return 12; else return 16; }
+
+int or5(int x, int y) {
+ int z;
+ if (x == 1 || y > 0) { z = f(x); return z; } else { return 0; }
+}
+
+int or6(int x)
+{
+ while (x >= 0 || f(x) < 0) x--;
+ return x;
+}
+
+int or3l(int x, int y, int z) { return (f(x) || f(y)) || f(z); }
+
+int or3r(int x, int y, int z) { return f(x) || (f(y) || f(z)); }
+
+int or4l(int x, int y, int z, int u) { return ((f(x) || f(y)) || f(z)) || f(u); }
+
+int or4r(int x, int y, int z, int u) { return f(x) || (f(y) || (f(z) || f(u))); }
+
+int or4b(int x, int y, int z, int u) { return (f(x) || f(y)) || (f(z) || f(u)); }
+
+int mixed1(int x, int y, int z) { return z && (x || y); }
+
+int mixed2(int x, int y, int z) { return (x == 1 || y > 0) && (z < 0); }
+
+int mixed3(int x, int y, int z) { if (z && (x || y)) return 12; else return 16; }
+
+int mixed4(int x, int y, int z) { if ((f(x) || f(y)) && f(z)) return 12; else return 16; }
+
+int mixed5(int x, int y, int z) {
+ if ((x == 1 || y > 0) && z < 0) { z = f(x); return z; } else { return 0; }
+}
+
+int mixed6(int x)
+{
+ while (x == 0 || (x >= 0 && f(x) < 0)) x--;
+ return x;
+}
+
+int mixed3l(int x, int y, int z) { return (f(x) && f(y)) || f(z); }
+
+int mixed3r(int x, int y, int z) { return f(x) && (f(y) || f(z)); }
+
+int mixed4l(int x, int y, int z, int u) { return ((f(x) && f(y)) || f(z)) && f(u); }
+
+int mixed4r(int x, int y, int z, int u) { return f(x) && (f(y) || (f(z) && f(u))); }
+
+int mixed4b(int x, int y, int z, int u) { return (f(x) && f(y)) || (f(z) && f(u)); }