cgen: str N_INDEX read -> 3-word {ptr,len,cap} -- Phase 2 F2 (both stages)
str element value read at N_INDEX dropped the cap word (2-word ptr,len load); str is 24B {ptr,len,cap} since 1140a59. A new named helper cgslicehdr (both stages) loads the full 3-word header and is called by the N_INDEX str-element sites, kind-gated type_isstr/elemisstr -- never size==24, since str and slice collide at 24B. The base-targeting word loads last (clobber-safe). cstage==wwstage byte-identical. The #9 typeassert leaf is split out to F2b (it needs a wwstage spill twin first).
test/wcc/932: table-driven runtime .cap-survives probe over both N_INDEX base forms and both drivers; verified fail-before/pass-after. NNN<950 mirrors the 928 precedent -- the fixtures are self-contained (/tmp, no imports), so rule-14's selfhost-sibling race does not apply.
main.combined.ww regenerated via the canonical make path (md5-stable) and committed alongside source, per the 1140a59 precedent.
This commit is contained in:
@@ -1078,6 +1078,23 @@ label(Cg *c, const char *s)
|
||||
emit(c, p);
|
||||
}
|
||||
|
||||
/* cgslicehdr — load the 24B slice/str header at `base`+0 into the
|
||||
* (AX=ptr, BX=len, CX=cap) triple. `base` holds the element address;
|
||||
* the load that targets `base` destroys it, so that word is emitted
|
||||
* LAST. Order otherwise mirrors the slice-FIELD arm (len, cap, ptr).
|
||||
* Shared by the N_INDEX str-element arms (caller does the kind-gate)
|
||||
* and, later, the typeassert str-variant leaf (#9). */
|
||||
static void
|
||||
cgslicehdr(Cg *c, int base)
|
||||
{
|
||||
if (base != D_BX) ins2(c, A_MOVQ, amem(base, 8), areg(D_BX));
|
||||
if (base != D_CX) ins2(c, A_MOVQ, amem(base, 16), areg(D_CX));
|
||||
if (base != D_AX) ins2(c, A_MOVQ, amem(base, 0), areg(D_AX));
|
||||
if (base == D_BX) ins2(c, A_MOVQ, amem(base, 8), areg(D_BX));
|
||||
else if (base == D_CX) ins2(c, A_MOVQ, amem(base, 16), areg(D_CX));
|
||||
else if (base == D_AX) ins2(c, A_MOVQ, amem(base, 0), areg(D_AX));
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------ */
|
||||
/* per-fn local table: name → stack offset (positive = below FP) */
|
||||
|
||||
@@ -6257,12 +6274,13 @@ cgexpr(Cg *c, Node *n, Local *locals)
|
||||
ins2(c, A_MOVQ, amem(D_BP, off), areg(D_BX));
|
||||
}
|
||||
ins2(c, A_ADDQ, areg(D_AX), areg(D_BX));
|
||||
/* str element: load (ptr, len) into (AX, BX) so the
|
||||
* value flows through the str-rhs convention. */
|
||||
/* str element: load the full (ptr, len, cap) header
|
||||
* into (AX, BX, CX) — str is 24B since #1, so the cap
|
||||
* word must survive. Kind-gate on type_isstr, never
|
||||
* size==24 (slices are 24B too; a size gate bleeds into
|
||||
* the general >16B struct path, #10). Base is BX. */
|
||||
if (u->sub && type_isstr(u->sub)) {
|
||||
ins2(c, A_MOVQ, amem(D_BX, 8), areg(D_CX));
|
||||
ins2(c, A_MOVQ, amem(D_BX, 0), areg(D_AX));
|
||||
ins2(c, A_MOVQ, areg(D_CX), areg(D_BX));
|
||||
cgslicehdr(c, D_BX);
|
||||
break;
|
||||
}
|
||||
/* tagged element: load slot words into (AX=tag,
|
||||
@@ -6305,10 +6323,11 @@ cgexpr(Cg *c, Node *n, Local *locals)
|
||||
cgexpr(c, n->lhs, locals);
|
||||
ins1(c, A_POPQ, areg(D_BX));
|
||||
ins2(c, A_ADDQ, areg(D_BX), areg(D_AX));
|
||||
/* str element: load (ptr, len) into (AX, BX). */
|
||||
/* str element via fallback base: load the full (ptr, len,
|
||||
* cap) header into (AX, BX, CX). Kind-gate on type_isstr,
|
||||
* never size==24 (see Site A). Base is AX. */
|
||||
if (u && u->sub && type_isstr(u->sub)) {
|
||||
ins2(c, A_MOVQ, amem(D_AX, 8), areg(D_BX));
|
||||
ins2(c, A_MOVQ, amem(D_AX, 0), areg(D_AX));
|
||||
cgslicehdr(c, D_AX);
|
||||
break;
|
||||
}
|
||||
/* tagged element via fallback base: AX holds the element
|
||||
|
||||
Reference in New Issue
Block a user