From 8f361faffc93f89d1025d9ca729d76cd7850ad99 Mon Sep 17 00:00:00 2001 From: Jack Palevich Date: Thu, 30 Jul 2009 16:19:43 -0700 Subject: [PATCH] Fix bad ARM code generation for '||' and '&&' operators. Add tests of '&', '&&', '|' and '||' operators. --- libacc/acc.cpp | 3 ++- libacc/tests/data/film.c | 53 ++++++++++++++++++++++++++++++++++++++++ libacc/tests/test.py | 5 ++++ 3 files changed, 60 insertions(+), 1 deletion(-) create mode 100644 libacc/tests/data/film.c diff --git a/libacc/acc.cpp b/libacc/acc.cpp index 7739e2d7b..0bb0c5efa 100644 --- a/libacc/acc.cpp +++ b/libacc/acc.cpp @@ -4131,9 +4131,10 @@ class Compiler : public ErrorSink { if (a && level > 8) { a = pGen->gtst(t == OP_LOGICAL_OR, a); pGen->li(t != OP_LOGICAL_OR); - pGen->gjmp(5); /* jmp $ + 5 (sizeof li, FIXME for ARM) */ + int b = pGen->gjmp(0); pGen->gsym(a); pGen->li(t == OP_LOGICAL_OR); + pGen->gsym(b); } } } diff --git a/libacc/tests/data/film.c b/libacc/tests/data/film.c new file mode 100644 index 000000000..00c2d3604 --- /dev/null +++ b/libacc/tests/data/film.c @@ -0,0 +1,53 @@ +// Test logical and bitwise AND and OR + +int test(int x, int y) { + int v = x || y; + return v; +} + +int test2(int x, int y) { + if(x | y) { + return 1; + } else { + return 0; + } +} + +int test3(int x, int y) { + int v = x && y; + return v; +} + +int test4(int x, int y) { + if(x & y) { + return 1; + } else { + return 0; + } +} + +int main(int index) +{ + int x,y; + printf("testing...\n"); + int totalBad = 0; + for(y = 0; y < 2; y++) { + for(x = 0; x < 2; x++) { + int a = test(x,y); + int b = test2(x,y); + if (a != b) { + printf("Results differ: OR x=%d y=%d a=%d b=%d\n", x, y, a, b); + totalBad++; + } + a = test3(x,y); + b = test4(x,y); + if (a != b) { + printf("Results differ: AND x=%d y=%d a=%d b=%d\n", x, y, a, b); + totalBad++; + } + } + } + printf("Total bad: %d\n", totalBad); + return 0; +} + diff --git a/libacc/tests/test.py b/libacc/tests/test.py index c79674671..31b832999 100644 --- a/libacc/tests/test.py +++ b/libacc/tests/test.py @@ -324,6 +324,11 @@ result: 0""", """Literals: 1 -1 0 """) + def testFilm (self): + self.compileCheck(["-R", "data/film.c"], """Executing compiled code: +result: 0""", """testing... +Total bad: 0 +""") if __name__ == '__main__': if not outputCanRun(): print "Many tests are expected to fail, because acc is not a 32-bit x86 Linux executable."