cproc

Unnamed repository; edit this file 'description' to name the repository.
git clone git://git.nihaljere.xyz/cproc
Log | Files | Refs | Submodules | README | LICENSE

commit 4a17a825e5944041bbcd4aed6a85fb7590247a62
parent 87200240f61e16f289cdabd678a6950386998ced
Author: Michael Forney <mforney@mforney.org>
Date:   Tue, 12 Mar 2019 00:41:54 -0700

Revert "Zero uninitialized decls/returns."

This reverts commit 7722c7593a1a249e1a6d98d84afdff3cb086ca81.

This causes problems with large stack allocations, such as
https://github.com/madler/pigz/blob/fe822cb435622c43f491013da77b127e9fe851a9/pigz.c#L3403-L3405

Diffstat:
Mqbe.c | 11+++--------
Mtests/compatible-function-types.qbe | 2--
Mtests/for-loop.qbe | 1-
Mtests/local-align.qbe | 7-------
Mtests/subtract-pointer.qbe | 2--
Mtests/typedef-name.qbe | 1-
Mtests/varargs.qbe | 22++++++++--------------
7 files changed, 11 insertions(+), 35 deletions(-)

diff --git 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); diff --git a/tests/compatible-function-types.qbe b/tests/compatible-function-types.qbe @@ -8,10 +8,8 @@ export function $f5(w %.1, d %.3) { @start.3 %.2 =l alloc4 4 - storew 0, %.2 storew %.1, %.2 %.4 =l alloc8 8 - storel 0, %.4 stored %.3, %.4 @body.4 ret diff --git a/tests/for-loop.qbe b/tests/for-loop.qbe @@ -4,7 +4,6 @@ function $f() { %.1 =l alloc4 4 @body.2 storew 0, %.1 - storew 0, %.1 @for_cond.3 %.2 =w loadsw %.1 %.3 =w csltw %.2, 10 diff --git a/tests/local-align.qbe b/tests/local-align.qbe @@ -3,12 +3,5 @@ function $f() { @start.1 %.1 =l alloc16 4 @body.2 - storeb 0, %.1 - %.2 =l add %.1, 1 - storeb 0, %.2 - %.3 =l add %.1, 2 - storeb 0, %.3 - %.4 =l add %.1, 3 - storeb 0, %.4 ret } diff --git a/tests/subtract-pointer.qbe b/tests/subtract-pointer.qbe @@ -2,10 +2,8 @@ export function $f(l %.1, l %.3) { @start.1 %.2 =l alloc8 8 - storel 0, %.2 storel %.1, %.2 %.4 =l alloc8 8 - storel 0, %.4 storel %.3, %.4 @body.2 %.5 =l loadl %.2 diff --git a/tests/typedef-name.qbe b/tests/typedef-name.qbe @@ -3,6 +3,5 @@ function $f() { @start.1 %.1 =l alloc8 8 @body.2 - storel 0, %.1 ret } diff --git a/tests/varargs.qbe b/tests/varargs.qbe @@ -2,26 +2,20 @@ export function $f(w %.1, ...) { @start.1 %.2 =l alloc4 4 - storew 0, %.2 storew %.1, %.2 %.3 =l alloc8 24 @body.2 - storel 0, %.3 - %.4 =l add %.3, 8 - storel 0, %.4 - %.5 =l add %.3, 16 - storel 0, %.5 vastart %.3 @while_cond.3 - %.6 =w loadsw %.2 - jnz %.6, @while_body.4, @while_join.5 + %.4 =w loadsw %.2 + jnz %.4, @while_body.4, @while_join.5 @while_body.4 - %.7 =w vaarg %.3 - %.8 =s vaarg %.3 - %.9 =l vaarg %.3 - %.10 =w loadsw %.2 - %.11 =w sub %.10, 1 - storew %.11, %.2 + %.5 =w vaarg %.3 + %.6 =s vaarg %.3 + %.7 =l vaarg %.3 + %.8 =w loadsw %.2 + %.9 =w sub %.8, 1 + storew %.9, %.2 jmp @while_cond.3 @while_join.5 ret