From 583704ebad684b74faa844262bd29cb260c8328a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8D=8Ddiohabara=E5=8D=8D?= Date: Tue, 25 Jul 2023 20:47:57 -0500 Subject: [PATCH] feat: allow void functions --- codegen.c | 4 +++- tests | 4 ++++ 2 files changed, 7 insertions(+), 1 deletion(-) 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; }