diff --git a/codegen.c b/codegen.c index 9015600..92b60be 100644 --- a/codegen.c +++ b/codegen.c @@ -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: diff --git a/tests b/tests index a211ff2..35028df 100644 --- a/tests +++ b/tests @@ -62,6 +62,8 @@ int count() { int param_decay(int x[]) { return 0[x]; } +void voidfn() {} + int main() { assert(8, ({ int a = 3; @@ -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; }