Fix an API of a function returning bool

x86-64 psABI says that only the least significant 8 bits are
significant if RAX has a return value of a function returning bool.
This commit is contained in:
Rui Ueyama 2019-08-24 16:22:25 +09:00
parent 8c7071a10b
commit d85319fa28
3 changed files with 10 additions and 0 deletions

View File

@ -527,6 +527,8 @@ static void gen(Node *node) {
printf(" call %s\n", node->funcname);
printf(" add rsp, 8\n");
printf(".L.end.%d:\n", seq);
if (node->ty->kind == TY_BOOL)
printf(" movzb rax, al\n");
printf(" push rax\n");
return;
}

6
tests
View File

@ -134,6 +134,9 @@ int counter() {
return i++ + j++;
}
_Bool true_fn();
_Bool false_fn();
int main() {
assert(8, ({ int a=3; int z=5; a+z; }), "int a=3; int z=5; a+z;");
@ -694,6 +697,9 @@ int main() {
assert(7, ({ int i=0; int j=0; do { j++; } while (i++ < 6); j; }), "int i=0; int j=0; do { j++; } while (i++ < 6); j;");
assert(4, ({ int i=0; int j=0; int k=0; do { if (++j > 3) break; continue; k++; } while (1); j; }), "int i=0; int j=0; int k=0; do { if (j++ > 3) break; continue; k++; } while (1); j;");
assert(1, true_fn(), "true_fn()");
assert(0, false_fn(), "false_fn()");
printf("OK\n");
return 0;
}

View File

@ -2,4 +2,6 @@
int ext1;
int *ext2;
int false_fn() { return 512; }
int true_fn() { return 513; }
int static_fn() { return 5; }