w6c+wwstage: agree on mixed-scalar tuple sret layout (#240)
An over-cap tuple mixing a scalar with slices/str (e.g. (int,[]u8,str),
56B) laid out differently in the two stages — gate-blind, since no
bootstrap path returns such a tuple. Two silent cs!=ww bugs, one per
ABI side:
- callee SEND (cstage cgen.c N_RETURN over-cap-tuple arm): foff
advanced by the LITERAL expression's type size. A bare int literal
element is stamped TY_UNTYPED_INT (size 0), so `e->type->size`
added 0 for a leading scalar — the next element clobbered it at
offset 0 and every trailing element packed 8 bytes low. wwstage
already sized from the return-type tuple (c.fnret.list), so the
callee frames diverged. Fix: size foff from cg_ret_type's tuple
params (rule-13 type table), aligning cstage to wwstage and to the
t.N reader's f->offset.
- caller RECEIVE (wwstage cgenstmt.ww cglet N_TTUPLE arm): the
in-cap register tuple-receive branch had no capacity gate, so a
56B over-cap tuple was received via AX/DX/CX/R8 (+ R8 fill)
instead of from the sret dest the callee wrote. cstage gates the
twin branch on `sz == 16 || sz == 32` and falls over-cap tuples
through to the sret receive. Fix: add the same size gate to
wwstage, aligning it to cstage.
Both stages now emit byte-identical asm and the value round-trips.
Regen w6c + wwdump combined.ww (cgenstmt embeds in both).
New 940_mixed_scalar_tuple_sret_run: leading/trailing/middle scalar
shapes, annotated + inferred let, each self-asserting every element
(scalar direct, slice/str via len) — both drivers exit 0 + cs==ww
byte-id (12/12).
This commit is contained in:
@@ -8839,11 +8839,27 @@ cgstmt(Cg *c, Node *n, Local **locals, int *frame)
|
||||
* wide element's cgexpr clobbers AX/BX/CX. Then reuse
|
||||
* the struct-sret epilogue. The CALL/receive side
|
||||
* stays loud-stopped (#10 Fold B). */
|
||||
/* #240: foff advances by the DECLARED return-type
|
||||
* element size (cg_ret_type tuple params), NOT the
|
||||
* literal expression's type. A bare int literal
|
||||
* element is stamped TY_UNTYPED_INT (size 0), so
|
||||
* `e->type->size` collapsed foff to 0 for a leading
|
||||
* scalar — the next element then clobbered it at
|
||||
* offset 0 and every trailing element packed 8 bytes
|
||||
* low, diverging from the t.N reader (f->offset) and
|
||||
* from wwstage (cgenstmt.ww walks c.fnret.list). */
|
||||
Type *rtt = type_chase_named(cg_ret_type);
|
||||
Tparam *pp = (rtt && rtt->kind == TY_TUPLE)
|
||||
? rtt->params : NULL;
|
||||
int foff = 0;
|
||||
for (Node *e = n->lhs->list; e; e = e->next) {
|
||||
int isflt = fld_isfloat(e->type, &f32);
|
||||
int wide = node_isstr(e) || node_isslice(e);
|
||||
int esz = e->type ? (int)e->type->size : 8;
|
||||
int esz = 8;
|
||||
if (pp && pp->type)
|
||||
esz = (int)pp->type->size;
|
||||
else if (e->type)
|
||||
esz = (int)e->type->size;
|
||||
cgexpr(c, e, *locals);
|
||||
ins2(c, A_MOVQ,
|
||||
amem(D_BP, cg_sret_arg_off), areg(D_DX));
|
||||
@@ -8861,6 +8877,7 @@ cgstmt(Cg *c, Node *n, Local **locals, int *frame)
|
||||
ins2(c, fldstoreop(e->type, esz),
|
||||
areg(D_AX), amem(D_DX, foff));
|
||||
foff += esz;
|
||||
if (pp) pp = pp->next;
|
||||
}
|
||||
ins2(c, A_MOVQ, amem(D_BP, cg_sret_arg_off),
|
||||
areg(D_AX));
|
||||
|
||||
Reference in New Issue
Block a user