Struct initialization with union

From: Xavier Del Campo Romero <xavi92_at_disroot.org>
Date: Thu, 24 Apr 2025 23:55:40 +0200

Hi,

scc (commit d0ec99aa) fails to compile the following minimalistic example:


$ cat union.c
struct a {
    int a;

    union b {
        int a;
    } u;
};

int main()
{
    struct a a = {0};

    return 0;
}
$ scc union.c
scc-cc:cc1: internal error

Below there is a tentative fix:

diff --git a/src/cmd/scc-cc/cc1/code.c b/src/cmd/scc-cc/cc1/code.c
index 9c7f5e75..32ce31ac 100644
--- a/src/cmd/scc-cc/cc1/code.c
+++ b/src/cmd/scc-cc/cc1/code.c
_at_@ -391,7 +391,8 @@ emitdesig(Node *np, Type *tp, SIZET *addr)
                break;
        case UNION:
                aux = (sym) ? sym->u.init[0] : NULL;
- emitdesig(aux, aux->type, addr);
+ p = tp->p.fields[0]->type;
+ emitdesig(aux, p, addr);
                emitpadding(tp, addr);
                break;
        case STRUCT:

Best regards,

--
Xavier Del Campo Romero





--
To unsubscribe send a mail to scc-dev+unsubscribe_at_simple-cc.org
Received on Thu 24 Apr 2025 - 23:55:40 CEST

This archive was generated by hypermail 2.3.0 : Fri 25 Apr 2025 - 00:00:01 CEST