Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 8f361faf authored by Jack Palevich's avatar Jack Palevich
Browse files

Fix bad ARM code generation for '||' and '&&' operators.

Add tests of '&', '&&', '|' and '||' operators.
parent 9f51a269
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -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);
            }
        }
    }
+53 −0
Original line number Diff line number Diff line
// 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;
}
+5 −0
Original line number Diff line number Diff line
@@ -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."