aboutsummaryrefslogtreecommitdiff
path: root/qbe.c
diff options
context:
space:
mode:
Diffstat (limited to 'qbe.c')
-rw-r--r--qbe.c11
1 files changed, 3 insertions, 8 deletions
diff --git a/qbe.c b/qbe.c
index 8daf023..a20851d 100644
--- a/qbe.c
+++ b/qbe.c
@@ -422,13 +422,6 @@ funcjnz(struct function *f, struct value *v, struct value *l1, struct value *l2)
void
funcret(struct function *f, struct value *v)
{
- struct declaration *d;
-
- if (!v && f->type->base->kind != TYPEVOID) {
- d = mkdecl(DECLOBJECT, f->type->base, LINKNONE);
- funcinit(f, d, NULL);
- v = funcload(f, d->type, d->value);
- }
funcinst(f, IRET, NULL, v);
f->end->terminated = true;
}
@@ -891,6 +884,8 @@ funcinit(struct function *func, struct declaration *d, struct initializer *init)
size_t i;
funcalloc(func, d);
+ if (!init)
+ return;
for (; init; init = init->next) {
zero(func, d->value, d->type->align, offset, init->start);
if (init->expr->kind == EXPRSTRING) {
@@ -1101,7 +1096,7 @@ emitfunc(struct function *f, bool global)
size_t n;
if (!f->end->terminated)
- funcret(f, NULL);
+ funcret(f, strcmp(f->name, "main") == 0 ? mkintconst(&i32, 0) : NULL);
if (global)
puts("export");
fputs("function ", stdout);