summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJack Palevich <jackpal@google.com>2009-07-30 16:19:43 -0700
committerJack Palevich <jackpal@google.com>2009-07-30 16:19:43 -0700
commit8f361faffc93f89d1025d9ca729d76cd7850ad99 (patch)
tree1965a34acd50959e3adaa660d21059a97795cf37
parent9f51a2696126c6db40d00c8183b26e89fb7e443e (diff)
downloadsystem_core-8f361faffc93f89d1025d9ca729d76cd7850ad99.tar.gz
system_core-8f361faffc93f89d1025d9ca729d76cd7850ad99.tar.bz2
system_core-8f361faffc93f89d1025d9ca729d76cd7850ad99.zip
Fix bad ARM code generation for '||' and '&&' operators.
Add tests of '&', '&&', '|' and '||' operators.
-rw-r--r--libacc/acc.cpp3
-rw-r--r--libacc/tests/data/film.c53
-rw-r--r--libacc/tests/test.py5
3 files changed, 60 insertions, 1 deletions
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."