From f7693b3d897b90fd3bc2533be002dc0bdcd9f6c2 Mon Sep 17 00:00:00 2001 From: xleroy Date: Sat, 6 Oct 2012 15:46:47 +0000 Subject: 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 --- test/regression/Makefile | 4 +- test/regression/Results/compar | 4 ++ test/regression/compar.c | 80 ++++++++++++++++++++++++++++++++++++++ test/regression/seqops.c | 87 ++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 173 insertions(+), 2 deletions(-) create mode 100644 test/regression/Results/compar create mode 100644 test/regression/compar.c create mode 100644 test/regression/seqops.c (limited to 'test/regression') 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 + +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)); } -- cgit v1.2.3