Fix bad ARM code generation for '||' and '&&' operators.
Add tests of '&', '&&', '|' and '||' operators.
diff --git a/libacc/acc.cpp b/libacc/acc.cpp
index 7739e2d..0bb0c5e 100644
--- a/libacc/acc.cpp
+++ b/libacc/acc.cpp
@@ -4131,9 +4131,10 @@
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 0000000..00c2d36
--- /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 c796746..31b8329 100644
--- a/libacc/tests/test.py
+++ b/libacc/tests/test.py
@@ -324,6 +324,11 @@
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."