Skip to content

Commit

Permalink
feat: allow void functions
Browse files Browse the repository at this point in the history
  • Loading branch information
diohabara committed Jul 26, 2023
1 parent 64b5565 commit 583704e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
4 changes: 3 additions & 1 deletion codegen.c
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,9 @@ void gen(Node *node) {
printf(".Lend%d:\n", seq);
printf(" push rax\n");

truncate(node->ty);
if (node->ty->kind != TY_VOID) {
truncate(node->ty);
}
return;
}
case ND_RETURN:
Expand Down
4 changes: 4 additions & 0 deletions tests
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ int count() {

int param_decay(int x[]) { return 0[x]; }

void voidfn() {}

int main() {
assert(8, ({
int a = 3;
Expand Down Expand Up @@ -808,6 +810,8 @@ int main() {
assert(4, ({ struct T *foo; struct T {int x;}; sizeof(struct T); }), "struct T *foo; struct T {int x;}; sizeof(struct T);");
assert(1, ({ struct T { struct T *next; int x; } a; struct T b; b.x=1; a.next=&b; a.next->x; }), "struct T { struct T *next; int x; } a; struct T b; b.x=1; a.next=&b; a.next->x;");

voidfn();

printf("OK\n");
return 0;
}

0 comments on commit 583704e

Please sign in to comment.