cgen: default the hi bound of a slice/str-field slice, both stages

x.slicefield[:] / x.strfield[2:] emitted MOVQ $0 for the omitted hi
bound on BOTH stages (N_IDENT-gated dispatch; symmetric, so byte
identity never caught it) in all four sites: cgexpr N_SLICE + pushargs
(cstage), cgslice + pushargsrev (wwstage). The new arm re-evaluates
the pure field read for its {ptr,len,cap} header and takes .len,
covering local, viaptr, dot-chain, (*p), arr[i], and global inners.
Call inners still loud-reject upstream. Sibling of the #252/#257
array-field arms.
This commit is contained in:
2026-08-08 00:29:51 +09:00
parent cc22abfc04
commit 66251cc52b
7 changed files with 190 additions and 6 deletions

View File

@@ -782,9 +782,16 @@ fn pushargsrev(c: *cgen, arg: *syntax.node, param: *syntax.node, memphase: bool,
emitline("\tMOVQ\t$");
emitint(dotbu.alen: i64);
emitline(", AX\n");
} else { if (dotbu != nil && (dotbu.kind == syntax.tykind.TY_SLICE
|| dotbu.kind == syntax.tykind.TY_STR)) {
// slice/str FIELD base — the arg twin of the cgslice
// default-hi arm; same re-eval-for-header rationale.
// Cstage twin: cgen.c pushargs N_SLICE.
cgexpr(c, base);
emitline("\tMOVQ\tBX, AX\n");
} else {
emitline("\tMOVQ\t$0, AX\n");
};};};};
};};};};};
emitline("\tPUSHQ\tAX\n");
// lo (default 0) → AX
if (lo != nil) { cgexpr(c, lo); }