commit edd52bacc2a7fa76d3f10153ff387128e306af25
parent 54070fc62035fd14be6390d958d1a0411410b600
Author: Roberto E. Vargas Caballero <k0ga@shike2.net>
Date: Wed, 29 Apr 2026 13:16:44 +0200
cc2/qbe: Fix blit when assigning structs through pointers
All the assign ops in qbe have an implicit size, so the size of the
node was not required at all, but this is not true in the case
of structs. When structs were directly assigned, the size of the
blit operands and the size of the destine was the same, but this
is not true when we have pointers, were the size of the operand
node is the size of the pointer (in our case 8 bytes). The fix
is simple enough like adding the size of the operation in the
free operand of the assignment instruction.
Diffstat:
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/cmd/scc-cc/cc2/qbe/cgen.c b/src/cmd/scc-cc/cc2/qbe/cgen.c
@@ -521,7 +521,7 @@ assign(Node *np)
break;
}
- code(assignop(&np->type), l, r, NULL);
+ code(assignop(&np->type), l, r, tmpnode(&np->type, NULL));
return ret;
}
diff --git a/src/cmd/scc-cc/cc2/qbe/code.c b/src/cmd/scc-cc/cc2/qbe/code.c
@@ -479,7 +479,7 @@ binary(void)
static void
blit(void)
{
- Type *tp = &pc->to.u.sym->type;
+ Type *tp = &pc->from2.u.sym->type;
char to[ADDR_LEN], from[ADDR_LEN];
strcpy(to, addr2txt(&pc->to));