scc

simple c99 compiler
git clone git://git.simple-cc.org/scc
Log | Files | Refs | Submodules | README | LICENSE

commit f90d96846e1b756b01cb983b9e117cfb03dd755f
parent d95c5300d65d7416a1b0d31d34d648c6a1a70373
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Mon,  1 Nov 2021 09:24:21 +0100

cc1: Simplify not initilized fields

When a field is not specified in an initializer then
it is initialized to 0 casted to the correct type.
Since the code was not simplifying that expression
we had a cast that were not understood by cc2,
generating wrong code.

Diffstat:
Msrc/cmd/cc/cc1/code.c | 5++++-
1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/src/cmd/cc/cc1/code.c b/src/cmd/cc/cc1/code.c @@ -357,7 +357,10 @@ emitdesig(Node *np, Type *tp) case PTR: case INT: case ENUM: - aux = (sym) ? *sym->u.init : convert(constnode(zero), tp, 0); + if (sym) + aux = *sym->u.init; + else + aux = simplify(convert(constnode(zero), tp, 0)); emitexp(OEXPR, aux); break; case UNION: