cgen: str index-stride via type table, not literal 1 (both stages)
Phase 2 step 2. The N_INDEX element-stride for str hardcoded esz=1;
route it through the type table (cstage ty_u8->size, wwstage
primtypesize("u8")) so str's element width tracks the u8 SSoT. When
the TY_STR collapse (Phase 2 step 5) folds str onto the slice-of-u8
path, these sites need no second edit. Byte-id-neutral: u8 size is 1,
so emitted stride is unchanged; full test (incl 990-997 byte-id
gates) green.
This commit is contained in:
@@ -2113,7 +2113,10 @@ cgexpr(Cg *c, Node *n, Local *locals)
|
||||
? bt->under : bt;
|
||||
int esz = (bu && bu->sub)
|
||||
? (int)bu->sub->size : 1;
|
||||
if (bu && bu->kind == TY_STR) esz = 1;
|
||||
/* str element is u8 — size via the type table
|
||||
* so #1's TY_STR collapse needs no second edit. */
|
||||
if (bu && bu->kind == TY_STR)
|
||||
esz = (int)ty_u8->size;
|
||||
cgexpr(c, idx, locals); /* idx → AX */
|
||||
if (esz > 1) {
|
||||
ins2(c, A_MOVQ, aimm(esz),
|
||||
@@ -6234,7 +6237,9 @@ cgexpr(Cg *c, Node *n, Local *locals)
|
||||
Type *eff = idx_eff(bt);
|
||||
int esz = 1;
|
||||
if (eff && eff->sub) esz = (int)eff->sub->size;
|
||||
if (u && u->kind == TY_STR) esz = 1;
|
||||
/* str element is u8 — size via the type table so #1's
|
||||
* TY_STR collapse needs no second edit. */
|
||||
if (u && u->kind == TY_STR) esz = (int)ty_u8->size;
|
||||
Type *esub = eff ? eff->sub : NULL;
|
||||
Type *esubu = (esub && esub->kind == TY_NAMED)
|
||||
? esub->under : esub;
|
||||
|
||||
@@ -11432,7 +11432,10 @@ fn elemsizeof(t: *node) i32 = {
|
||||
if (k == nkind.N_TARRAY) { elem = t.lhs; };
|
||||
if (k == nkind.N_TNAME) {
|
||||
let nm: str = t.str;
|
||||
if (streq(nm, "str")) { return 1; };
|
||||
// str element is u8 — size via the type table so #1's
|
||||
// TY_STR collapse needs no second edit. Cite cstage cgen.c
|
||||
// N_INDEX `esz = ty_u8->size`.
|
||||
if (streq(nm, "str")) { return primtypesize("u8"): i32; };
|
||||
// Indexing a primitive name (rare): element size = the prim.
|
||||
let ps: i32 = primsize(nm);
|
||||
if (ps > 0) { return ps; };
|
||||
|
||||
@@ -872,7 +872,10 @@ fn elemsizeof(t: *node) i32 = {
|
||||
if (k == nkind.N_TARRAY) { elem = t.lhs; };
|
||||
if (k == nkind.N_TNAME) {
|
||||
let nm: str = t.str;
|
||||
if (streq(nm, "str")) { return 1; };
|
||||
// str element is u8 — size via the type table so #1's
|
||||
// TY_STR collapse needs no second edit. Cite cstage cgen.c
|
||||
// N_INDEX `esz = ty_u8->size`.
|
||||
if (streq(nm, "str")) { return primtypesize("u8"): i32; };
|
||||
// Indexing a primitive name (rare): element size = the prim.
|
||||
let ps: i32 = primsize(nm);
|
||||
if (ps > 0) { return ps; };
|
||||
|
||||
@@ -11432,7 +11432,10 @@ fn elemsizeof(t: *node) i32 = {
|
||||
if (k == nkind.N_TARRAY) { elem = t.lhs; };
|
||||
if (k == nkind.N_TNAME) {
|
||||
let nm: str = t.str;
|
||||
if (streq(nm, "str")) { return 1; };
|
||||
// str element is u8 — size via the type table so #1's
|
||||
// TY_STR collapse needs no second edit. Cite cstage cgen.c
|
||||
// N_INDEX `esz = ty_u8->size`.
|
||||
if (streq(nm, "str")) { return primtypesize("u8"): i32; };
|
||||
// Indexing a primitive name (rare): element size = the prim.
|
||||
let ps: i32 = primsize(nm);
|
||||
if (ps > 0) { return ps; };
|
||||
|
||||
Reference in New Issue
Block a user