selfhost/cmd/wcc/cgen.ww: migrate 16 amalloc sites to alloc(T{...})!

Phase 0 batch 3b. collect* paths + intern + localadd/alloc/addstack.
Retires five rule-7 over-sized amalloc workarounds at :245 (enumtype
80→72), :265 (enummember), :918 (strlit), :1653 (fnret 80→72), :2060
(ffi) — alloc(T{...})! sizes from the type table, so the magic-byte
paranoia comments (the #35 block) go away with the literals.

Deferred: 3 internstrlit *u8 runtime-N buffers (#8), 4 LOOP_MAX/
DEFER_MAX fixed-max arrays at :541-546 (#9), 1 cgoutarena package-
global at :700 (#10).

Net -68 lines. Verified 132/132 + 995_self_rebuild byte-identity.
This commit is contained in:
2026-05-20 18:58:00 +09:00
parent 1798ef02ef
commit 65c92e2c8d
3 changed files with 66 additions and 270 deletions

View File

@@ -21178,11 +21178,7 @@ fn collectaliases(c: *cgen, file: *node) void = {
tnvoid.str = "void";
let bang: *node = newnode(c.a, nkind.N_TBANG, empty, 0, 0);
bang.lhs = tnvoid;
let nomemal: *aliasent = amalloc(c.a, 64u64): *aliasent;
nomemal.aname = "nomem";
nomemal.amod = empty;
nomemal.target = bang;
nomemal.aanext = nil;
let nomemal: *aliasent = alloc(aliasent{aname="nomem", amod=empty, target=bang, aanext=nil})!;
c.aliases = nomemal;
let d: *node = file.list;
for (d != nil) {
@@ -21190,11 +21186,7 @@ fn collectaliases(c: *cgen, file: *node) void = {
let body: *node = d.lhs;
if (body != nil) {
if (body.kind != nkind.N_TSTRUCT) {
let a: *aliasent = amalloc(c.a, 64u64): *aliasent;
a.aname = d.str;
a.amod = d.nmod;
a.target = body;
a.aanext = c.aliases;
let a: *aliasent = alloc(aliasent{aname=d.str, amod=d.nmod, target=body, aanext=c.aliases})!;
c.aliases = a;
};
};
@@ -21349,12 +21341,7 @@ fn collectenums(c: *cgen, file: *node) void = {
let body: *node = d.lhs;
if (body != nil) {
if (body.kind == nkind.N_TENUM) {
// #35: sizeof(enumtype) = 72 under str=24 ({str,str,*node,*enummember,*enumtype}); amalloc < struct corrupts the next slot.
let et: *enumtype = amalloc(c.a, 80u64): *enumtype;
et.ename = d.str;
et.emod = d.nmod;
et.storage = body.lhs;
et.members = nil;
let et: *enumtype = alloc(enumtype{ename=d.str, emod=d.nmod, storage=body.lhs, members=nil, etnext=nil})!;
let prev: u64 = (-1i64): u64;
let mhead: *enummember = nil;
let mtail: *enummember = nil;
@@ -21369,11 +21356,7 @@ fn collectenums(c: *cgen, file: *node) void = {
};
};
prev = val;
// #35: sizeof(enummember) = 40 under str=24 ({str,u64,*enummember}).
let em: *enummember = amalloc(c.a, 48u64): *enummember;
em.mname = m.str;
em.mval = val;
em.emnext = nil;
let em: *enummember = alloc(enummember{mname=m.str, mval=val, emnext=nil})!;
if (mhead == nil) { mhead = em; mtail = em; }
else { mtail.emnext = em; mtail = em; };
m = m.next;
@@ -21681,12 +21664,7 @@ fn localalloc(c: *cgen, name: str, sz: i32, tnode: *node) i32 = {
if ((asz & 7) != 0) { asz = (asz + 7) & ~7; };
c.frame += asz;
let off: i32 = 0 - c.frame;
let l: *local = amalloc(c.a, 48u64): *local;
l.name = name;
l.off = off;
l.sz = asz;
l.tnode = tnode;
l.lnext = c.locals;
let l: *local = alloc(local{name=name, off=off, sz=asz, tnode=tnode, lnext=c.locals})!;
c.locals = l;
return off;
};
@@ -21697,12 +21675,7 @@ fn localalloc(c: *cgen, name: str, sz: i32, tnode: *node) i32 = {
// etc. (after the saved RIP+BP). No spill instruction is emitted; the
// slot IS the caller's stack slot.
fn localaddstack(c: *cgen, name: str, tnode: *node, off: i32) void = {
let l: *local = amalloc(c.a, 48u64): *local;
l.name = name;
l.off = off;
l.sz = 0;
l.tnode = tnode;
l.lnext = c.locals;
let l: *local = alloc(local{name=name, off=off, sz=0, tnode=tnode, lnext=c.locals})!;
c.locals = l;
};
@@ -21751,12 +21724,7 @@ fn localadd(c: *cgen, name: str, sz: i32, tnode: *node) i32 = {
// block) and pin a parallel entry in c.atlocals so the
// allocation survives cgblock save/restore.
let off: i32 = localalloc(c, name, sz, tnode);
let at: *local = amalloc(c.a, 48u64): *local;
at.name = name;
at.off = off;
at.sz = asz;
at.tnode = tnode;
at.lnext = c.atlocals;
let at: *local = alloc(local{name=name, off=off, sz=asz, tnode=tnode, lnext=c.atlocals})!;
c.atlocals = at;
return off;
};
@@ -22022,11 +21990,7 @@ fn internstrlit(c: *cgen, bytes: str) str = {
let lab: str;
lab.ptr = p;
lab.len = total;
// #35: sizeof(strlit) = 56 under str=24 ({str,str,*strlit}).
let nw: *strlit = amalloc(c.a, 64u64): *strlit;
nw.label = lab;
nw.bytes = bytes;
nw.slnext = c.strlits;
let nw: *strlit = alloc(strlit{label=lab, bytes=bytes, slnext=c.strlits})!;
c.strlits = nw;
return lab;
};
@@ -22114,11 +22078,8 @@ fn collectlets(c: *cgen, file: *node) void = {
let nm: str = d.str;
if (nm.len > 0) {
if (letemitsize(c, d) > 0) {
let lv: *letvar = amalloc(c.a, 48u64): *letvar;
lv.name = nm;
lv.tnode = d.lhs;
lv.lvnext = c.lets;
c.lets = lv;
let lv: *letvar = alloc(letvar{name=nm, tnode=d.lhs, lvnext=c.lets})!;
c.lets = lv;
};
};
};
@@ -22757,13 +22718,7 @@ fn collectfnrets(c: *cgen, file: *node) void = {
let d: *node = file.list;
for (d != nil) {
if (d.kind == nkind.N_FNDECL) {
// #35: sizeof(fnret) = 72 under str=24 ({str,str,*node,*node,*fnret}); was the trigger that hung w6c_ww on the hangtest — frnext overflowed into the next amalloc, breaking fnretlookup's chain walk.
let f: *fnret = amalloc(c.a, 80u64): *fnret;
f.fname = d.str;
f.fmod = d.nmod;
f.rtype = d.lhs;
f.params = d.list;
f.frnext = c.fnrets;
let f: *fnret = alloc(fnret{fname=d.str, fmod=d.nmod, rtype=d.lhs, params=d.list, frnext=c.fnrets})!;
c.fnrets = f;
};
d = d.next;
@@ -22901,11 +22856,7 @@ fn collectdefs(c: *cgen, file: *node) void = {
let d: *node = file.list;
for (d != nil) {
if (d.kind == nkind.N_DEF) {
let e: *defent = amalloc(c.a, 64u64): *defent;
e.dname = d.str;
e.dmod = d.nmod;
e.drhs = d.rhs;
e.dnext = c.defs;
let e: *defent = alloc(defent{dname=d.str, dmod=d.nmod, drhs=d.rhs, dnext=c.defs})!;
c.defs = e;
};
d = d.next;
@@ -22998,9 +22949,6 @@ type modent = struct {
mnext: *modent,
};
// #35: sizeof(modent) = 56 under str=24 ({str,str,*modent}); each
// of the four amallocs below grew from 48 to 64 to keep mnext inside
// the slot.
fn collectmods(c: *cgen, file: *node) void = {
c.mods = nil;
if (file == nil) { return; };
@@ -23024,11 +22972,8 @@ fn collectmods(c: *cgen, file: *node) void = {
};
if (!isffi) {
if (!streq(d.str, "main")) {
let m: *modent = amalloc(c.a, 64u64): *modent;
m.mname = d.str;
m.nmod = d.nmod;
m.mnext = c.mods;
c.mods = m;
let m: *modent = alloc(modent{mname=d.str, nmod=d.nmod, mnext=c.mods})!;
c.mods = m;
};
};
};
@@ -23036,33 +22981,24 @@ fn collectmods(c: *cgen, file: *node) void = {
if (d.kind == nkind.N_DEF) {
if (d.exported == 0) {
if (d.nmod.len > 0) {
let m: *modent = amalloc(c.a, 64u64): *modent;
m.mname = d.str;
m.nmod = d.nmod;
m.mnext = c.mods;
c.mods = m;
let m: *modent = alloc(modent{mname=d.str, nmod=d.nmod, mnext=c.mods})!;
c.mods = m;
};
};
};
if (d.kind == nkind.N_TYPEDECL) {
if (d.exported == 0) {
if (d.nmod.len > 0) {
let m: *modent = amalloc(c.a, 64u64): *modent;
m.mname = d.str;
m.nmod = d.nmod;
m.mnext = c.mods;
c.mods = m;
let m: *modent = alloc(modent{mname=d.str, nmod=d.nmod, mnext=c.mods})!;
c.mods = m;
};
};
};
if (d.kind == nkind.N_LET) {
if (d.exported == 0) {
if (d.nmod.len > 0) {
let m: *modent = amalloc(c.a, 64u64): *modent;
m.mname = d.str;
m.nmod = d.nmod;
m.mnext = c.mods;
c.mods = m;
let m: *modent = alloc(modent{mname=d.str, nmod=d.nmod, mnext=c.mods})!;
c.mods = m;
};
};
};
@@ -23164,12 +23100,8 @@ fn fficollect(c: *cgen, file: *node) void = {
let symnode: *node = a.list;
if (symnode != nil) {
if (symnode.kind == nkind.N_STRLIT) {
// #35: sizeof(ffi) = 56 under str=24 ({str,str,*ffi}).
let f: *ffi = amalloc(c.a, 64u64): *ffi;
f.ident = d.str;
f.symbol = symnode.str;
f.fnext = c.ffis;
c.ffis = f;
let f: *ffi = alloc(ffi{ident=d.str, symbol=symnode.str, fnext=c.ffis})!;
c.ffis = f;
};
};
};

View File

@@ -70,11 +70,7 @@ fn collectaliases(c: *cgen, file: *node) void = {
tnvoid.str = "void";
let bang: *node = newnode(c.a, nkind.N_TBANG, empty, 0, 0);
bang.lhs = tnvoid;
let nomemal: *aliasent = amalloc(c.a, 64u64): *aliasent;
nomemal.aname = "nomem";
nomemal.amod = empty;
nomemal.target = bang;
nomemal.aanext = nil;
let nomemal: *aliasent = alloc(aliasent{aname="nomem", amod=empty, target=bang, aanext=nil})!;
c.aliases = nomemal;
let d: *node = file.list;
for (d != nil) {
@@ -82,11 +78,7 @@ fn collectaliases(c: *cgen, file: *node) void = {
let body: *node = d.lhs;
if (body != nil) {
if (body.kind != nkind.N_TSTRUCT) {
let a: *aliasent = amalloc(c.a, 64u64): *aliasent;
a.aname = d.str;
a.amod = d.nmod;
a.target = body;
a.aanext = c.aliases;
let a: *aliasent = alloc(aliasent{aname=d.str, amod=d.nmod, target=body, aanext=c.aliases})!;
c.aliases = a;
};
};
@@ -241,12 +233,7 @@ fn collectenums(c: *cgen, file: *node) void = {
let body: *node = d.lhs;
if (body != nil) {
if (body.kind == nkind.N_TENUM) {
// #35: sizeof(enumtype) = 72 under str=24 ({str,str,*node,*enummember,*enumtype}); amalloc < struct corrupts the next slot.
let et: *enumtype = amalloc(c.a, 80u64): *enumtype;
et.ename = d.str;
et.emod = d.nmod;
et.storage = body.lhs;
et.members = nil;
let et: *enumtype = alloc(enumtype{ename=d.str, emod=d.nmod, storage=body.lhs, members=nil, etnext=nil})!;
let prev: u64 = (-1i64): u64;
let mhead: *enummember = nil;
let mtail: *enummember = nil;
@@ -261,11 +248,7 @@ fn collectenums(c: *cgen, file: *node) void = {
};
};
prev = val;
// #35: sizeof(enummember) = 40 under str=24 ({str,u64,*enummember}).
let em: *enummember = amalloc(c.a, 48u64): *enummember;
em.mname = m.str;
em.mval = val;
em.emnext = nil;
let em: *enummember = alloc(enummember{mname=m.str, mval=val, emnext=nil})!;
if (mhead == nil) { mhead = em; mtail = em; }
else { mtail.emnext = em; mtail = em; };
m = m.next;
@@ -573,12 +556,7 @@ fn localalloc(c: *cgen, name: str, sz: i32, tnode: *node) i32 = {
if ((asz & 7) != 0) { asz = (asz + 7) & ~7; };
c.frame += asz;
let off: i32 = 0 - c.frame;
let l: *local = amalloc(c.a, 48u64): *local;
l.name = name;
l.off = off;
l.sz = asz;
l.tnode = tnode;
l.lnext = c.locals;
let l: *local = alloc(local{name=name, off=off, sz=asz, tnode=tnode, lnext=c.locals})!;
c.locals = l;
return off;
};
@@ -589,12 +567,7 @@ fn localalloc(c: *cgen, name: str, sz: i32, tnode: *node) i32 = {
// etc. (after the saved RIP+BP). No spill instruction is emitted; the
// slot IS the caller's stack slot.
fn localaddstack(c: *cgen, name: str, tnode: *node, off: i32) void = {
let l: *local = amalloc(c.a, 48u64): *local;
l.name = name;
l.off = off;
l.sz = 0;
l.tnode = tnode;
l.lnext = c.locals;
let l: *local = alloc(local{name=name, off=off, sz=0, tnode=tnode, lnext=c.locals})!;
c.locals = l;
};
@@ -643,12 +616,7 @@ fn localadd(c: *cgen, name: str, sz: i32, tnode: *node) i32 = {
// block) and pin a parallel entry in c.atlocals so the
// allocation survives cgblock save/restore.
let off: i32 = localalloc(c, name, sz, tnode);
let at: *local = amalloc(c.a, 48u64): *local;
at.name = name;
at.off = off;
at.sz = asz;
at.tnode = tnode;
at.lnext = c.atlocals;
let at: *local = alloc(local{name=name, off=off, sz=asz, tnode=tnode, lnext=c.atlocals})!;
c.atlocals = at;
return off;
};
@@ -914,11 +882,7 @@ fn internstrlit(c: *cgen, bytes: str) str = {
let lab: str;
lab.ptr = p;
lab.len = total;
// #35: sizeof(strlit) = 56 under str=24 ({str,str,*strlit}).
let nw: *strlit = amalloc(c.a, 64u64): *strlit;
nw.label = lab;
nw.bytes = bytes;
nw.slnext = c.strlits;
let nw: *strlit = alloc(strlit{label=lab, bytes=bytes, slnext=c.strlits})!;
c.strlits = nw;
return lab;
};
@@ -1006,11 +970,8 @@ fn collectlets(c: *cgen, file: *node) void = {
let nm: str = d.str;
if (nm.len > 0) {
if (letemitsize(c, d) > 0) {
let lv: *letvar = amalloc(c.a, 48u64): *letvar;
lv.name = nm;
lv.tnode = d.lhs;
lv.lvnext = c.lets;
c.lets = lv;
let lv: *letvar = alloc(letvar{name=nm, tnode=d.lhs, lvnext=c.lets})!;
c.lets = lv;
};
};
};
@@ -1649,13 +1610,7 @@ fn collectfnrets(c: *cgen, file: *node) void = {
let d: *node = file.list;
for (d != nil) {
if (d.kind == nkind.N_FNDECL) {
// #35: sizeof(fnret) = 72 under str=24 ({str,str,*node,*node,*fnret}); was the trigger that hung w6c_ww on the hangtest — frnext overflowed into the next amalloc, breaking fnretlookup's chain walk.
let f: *fnret = amalloc(c.a, 80u64): *fnret;
f.fname = d.str;
f.fmod = d.nmod;
f.rtype = d.lhs;
f.params = d.list;
f.frnext = c.fnrets;
let f: *fnret = alloc(fnret{fname=d.str, fmod=d.nmod, rtype=d.lhs, params=d.list, frnext=c.fnrets})!;
c.fnrets = f;
};
d = d.next;
@@ -1793,11 +1748,7 @@ fn collectdefs(c: *cgen, file: *node) void = {
let d: *node = file.list;
for (d != nil) {
if (d.kind == nkind.N_DEF) {
let e: *defent = amalloc(c.a, 64u64): *defent;
e.dname = d.str;
e.dmod = d.nmod;
e.drhs = d.rhs;
e.dnext = c.defs;
let e: *defent = alloc(defent{dname=d.str, dmod=d.nmod, drhs=d.rhs, dnext=c.defs})!;
c.defs = e;
};
d = d.next;
@@ -1890,9 +1841,6 @@ type modent = struct {
mnext: *modent,
};
// #35: sizeof(modent) = 56 under str=24 ({str,str,*modent}); each
// of the four amallocs below grew from 48 to 64 to keep mnext inside
// the slot.
fn collectmods(c: *cgen, file: *node) void = {
c.mods = nil;
if (file == nil) { return; };
@@ -1916,11 +1864,8 @@ fn collectmods(c: *cgen, file: *node) void = {
};
if (!isffi) {
if (!streq(d.str, "main")) {
let m: *modent = amalloc(c.a, 64u64): *modent;
m.mname = d.str;
m.nmod = d.nmod;
m.mnext = c.mods;
c.mods = m;
let m: *modent = alloc(modent{mname=d.str, nmod=d.nmod, mnext=c.mods})!;
c.mods = m;
};
};
};
@@ -1928,33 +1873,24 @@ fn collectmods(c: *cgen, file: *node) void = {
if (d.kind == nkind.N_DEF) {
if (d.exported == 0) {
if (d.nmod.len > 0) {
let m: *modent = amalloc(c.a, 64u64): *modent;
m.mname = d.str;
m.nmod = d.nmod;
m.mnext = c.mods;
c.mods = m;
let m: *modent = alloc(modent{mname=d.str, nmod=d.nmod, mnext=c.mods})!;
c.mods = m;
};
};
};
if (d.kind == nkind.N_TYPEDECL) {
if (d.exported == 0) {
if (d.nmod.len > 0) {
let m: *modent = amalloc(c.a, 64u64): *modent;
m.mname = d.str;
m.nmod = d.nmod;
m.mnext = c.mods;
c.mods = m;
let m: *modent = alloc(modent{mname=d.str, nmod=d.nmod, mnext=c.mods})!;
c.mods = m;
};
};
};
if (d.kind == nkind.N_LET) {
if (d.exported == 0) {
if (d.nmod.len > 0) {
let m: *modent = amalloc(c.a, 64u64): *modent;
m.mname = d.str;
m.nmod = d.nmod;
m.mnext = c.mods;
c.mods = m;
let m: *modent = alloc(modent{mname=d.str, nmod=d.nmod, mnext=c.mods})!;
c.mods = m;
};
};
};
@@ -2056,12 +1992,8 @@ fn fficollect(c: *cgen, file: *node) void = {
let symnode: *node = a.list;
if (symnode != nil) {
if (symnode.kind == nkind.N_STRLIT) {
// #35: sizeof(ffi) = 56 under str=24 ({str,str,*ffi}).
let f: *ffi = amalloc(c.a, 64u64): *ffi;
f.ident = d.str;
f.symbol = symnode.str;
f.fnext = c.ffis;
c.ffis = f;
let f: *ffi = alloc(ffi{ident=d.str, symbol=symnode.str, fnext=c.ffis})!;
c.ffis = f;
};
};
};

View File

@@ -21178,11 +21178,7 @@ fn collectaliases(c: *cgen, file: *node) void = {
tnvoid.str = "void";
let bang: *node = newnode(c.a, nkind.N_TBANG, empty, 0, 0);
bang.lhs = tnvoid;
let nomemal: *aliasent = amalloc(c.a, 64u64): *aliasent;
nomemal.aname = "nomem";
nomemal.amod = empty;
nomemal.target = bang;
nomemal.aanext = nil;
let nomemal: *aliasent = alloc(aliasent{aname="nomem", amod=empty, target=bang, aanext=nil})!;
c.aliases = nomemal;
let d: *node = file.list;
for (d != nil) {
@@ -21190,11 +21186,7 @@ fn collectaliases(c: *cgen, file: *node) void = {
let body: *node = d.lhs;
if (body != nil) {
if (body.kind != nkind.N_TSTRUCT) {
let a: *aliasent = amalloc(c.a, 64u64): *aliasent;
a.aname = d.str;
a.amod = d.nmod;
a.target = body;
a.aanext = c.aliases;
let a: *aliasent = alloc(aliasent{aname=d.str, amod=d.nmod, target=body, aanext=c.aliases})!;
c.aliases = a;
};
};
@@ -21349,12 +21341,7 @@ fn collectenums(c: *cgen, file: *node) void = {
let body: *node = d.lhs;
if (body != nil) {
if (body.kind == nkind.N_TENUM) {
// #35: sizeof(enumtype) = 72 under str=24 ({str,str,*node,*enummember,*enumtype}); amalloc < struct corrupts the next slot.
let et: *enumtype = amalloc(c.a, 80u64): *enumtype;
et.ename = d.str;
et.emod = d.nmod;
et.storage = body.lhs;
et.members = nil;
let et: *enumtype = alloc(enumtype{ename=d.str, emod=d.nmod, storage=body.lhs, members=nil, etnext=nil})!;
let prev: u64 = (-1i64): u64;
let mhead: *enummember = nil;
let mtail: *enummember = nil;
@@ -21369,11 +21356,7 @@ fn collectenums(c: *cgen, file: *node) void = {
};
};
prev = val;
// #35: sizeof(enummember) = 40 under str=24 ({str,u64,*enummember}).
let em: *enummember = amalloc(c.a, 48u64): *enummember;
em.mname = m.str;
em.mval = val;
em.emnext = nil;
let em: *enummember = alloc(enummember{mname=m.str, mval=val, emnext=nil})!;
if (mhead == nil) { mhead = em; mtail = em; }
else { mtail.emnext = em; mtail = em; };
m = m.next;
@@ -21681,12 +21664,7 @@ fn localalloc(c: *cgen, name: str, sz: i32, tnode: *node) i32 = {
if ((asz & 7) != 0) { asz = (asz + 7) & ~7; };
c.frame += asz;
let off: i32 = 0 - c.frame;
let l: *local = amalloc(c.a, 48u64): *local;
l.name = name;
l.off = off;
l.sz = asz;
l.tnode = tnode;
l.lnext = c.locals;
let l: *local = alloc(local{name=name, off=off, sz=asz, tnode=tnode, lnext=c.locals})!;
c.locals = l;
return off;
};
@@ -21697,12 +21675,7 @@ fn localalloc(c: *cgen, name: str, sz: i32, tnode: *node) i32 = {
// etc. (after the saved RIP+BP). No spill instruction is emitted; the
// slot IS the caller's stack slot.
fn localaddstack(c: *cgen, name: str, tnode: *node, off: i32) void = {
let l: *local = amalloc(c.a, 48u64): *local;
l.name = name;
l.off = off;
l.sz = 0;
l.tnode = tnode;
l.lnext = c.locals;
let l: *local = alloc(local{name=name, off=off, sz=0, tnode=tnode, lnext=c.locals})!;
c.locals = l;
};
@@ -21751,12 +21724,7 @@ fn localadd(c: *cgen, name: str, sz: i32, tnode: *node) i32 = {
// block) and pin a parallel entry in c.atlocals so the
// allocation survives cgblock save/restore.
let off: i32 = localalloc(c, name, sz, tnode);
let at: *local = amalloc(c.a, 48u64): *local;
at.name = name;
at.off = off;
at.sz = asz;
at.tnode = tnode;
at.lnext = c.atlocals;
let at: *local = alloc(local{name=name, off=off, sz=asz, tnode=tnode, lnext=c.atlocals})!;
c.atlocals = at;
return off;
};
@@ -22022,11 +21990,7 @@ fn internstrlit(c: *cgen, bytes: str) str = {
let lab: str;
lab.ptr = p;
lab.len = total;
// #35: sizeof(strlit) = 56 under str=24 ({str,str,*strlit}).
let nw: *strlit = amalloc(c.a, 64u64): *strlit;
nw.label = lab;
nw.bytes = bytes;
nw.slnext = c.strlits;
let nw: *strlit = alloc(strlit{label=lab, bytes=bytes, slnext=c.strlits})!;
c.strlits = nw;
return lab;
};
@@ -22114,11 +22078,8 @@ fn collectlets(c: *cgen, file: *node) void = {
let nm: str = d.str;
if (nm.len > 0) {
if (letemitsize(c, d) > 0) {
let lv: *letvar = amalloc(c.a, 48u64): *letvar;
lv.name = nm;
lv.tnode = d.lhs;
lv.lvnext = c.lets;
c.lets = lv;
let lv: *letvar = alloc(letvar{name=nm, tnode=d.lhs, lvnext=c.lets})!;
c.lets = lv;
};
};
};
@@ -22757,13 +22718,7 @@ fn collectfnrets(c: *cgen, file: *node) void = {
let d: *node = file.list;
for (d != nil) {
if (d.kind == nkind.N_FNDECL) {
// #35: sizeof(fnret) = 72 under str=24 ({str,str,*node,*node,*fnret}); was the trigger that hung w6c_ww on the hangtest — frnext overflowed into the next amalloc, breaking fnretlookup's chain walk.
let f: *fnret = amalloc(c.a, 80u64): *fnret;
f.fname = d.str;
f.fmod = d.nmod;
f.rtype = d.lhs;
f.params = d.list;
f.frnext = c.fnrets;
let f: *fnret = alloc(fnret{fname=d.str, fmod=d.nmod, rtype=d.lhs, params=d.list, frnext=c.fnrets})!;
c.fnrets = f;
};
d = d.next;
@@ -22901,11 +22856,7 @@ fn collectdefs(c: *cgen, file: *node) void = {
let d: *node = file.list;
for (d != nil) {
if (d.kind == nkind.N_DEF) {
let e: *defent = amalloc(c.a, 64u64): *defent;
e.dname = d.str;
e.dmod = d.nmod;
e.drhs = d.rhs;
e.dnext = c.defs;
let e: *defent = alloc(defent{dname=d.str, dmod=d.nmod, drhs=d.rhs, dnext=c.defs})!;
c.defs = e;
};
d = d.next;
@@ -22998,9 +22949,6 @@ type modent = struct {
mnext: *modent,
};
// #35: sizeof(modent) = 56 under str=24 ({str,str,*modent}); each
// of the four amallocs below grew from 48 to 64 to keep mnext inside
// the slot.
fn collectmods(c: *cgen, file: *node) void = {
c.mods = nil;
if (file == nil) { return; };
@@ -23024,11 +22972,8 @@ fn collectmods(c: *cgen, file: *node) void = {
};
if (!isffi) {
if (!streq(d.str, "main")) {
let m: *modent = amalloc(c.a, 64u64): *modent;
m.mname = d.str;
m.nmod = d.nmod;
m.mnext = c.mods;
c.mods = m;
let m: *modent = alloc(modent{mname=d.str, nmod=d.nmod, mnext=c.mods})!;
c.mods = m;
};
};
};
@@ -23036,33 +22981,24 @@ fn collectmods(c: *cgen, file: *node) void = {
if (d.kind == nkind.N_DEF) {
if (d.exported == 0) {
if (d.nmod.len > 0) {
let m: *modent = amalloc(c.a, 64u64): *modent;
m.mname = d.str;
m.nmod = d.nmod;
m.mnext = c.mods;
c.mods = m;
let m: *modent = alloc(modent{mname=d.str, nmod=d.nmod, mnext=c.mods})!;
c.mods = m;
};
};
};
if (d.kind == nkind.N_TYPEDECL) {
if (d.exported == 0) {
if (d.nmod.len > 0) {
let m: *modent = amalloc(c.a, 64u64): *modent;
m.mname = d.str;
m.nmod = d.nmod;
m.mnext = c.mods;
c.mods = m;
let m: *modent = alloc(modent{mname=d.str, nmod=d.nmod, mnext=c.mods})!;
c.mods = m;
};
};
};
if (d.kind == nkind.N_LET) {
if (d.exported == 0) {
if (d.nmod.len > 0) {
let m: *modent = amalloc(c.a, 64u64): *modent;
m.mname = d.str;
m.nmod = d.nmod;
m.mnext = c.mods;
c.mods = m;
let m: *modent = alloc(modent{mname=d.str, nmod=d.nmod, mnext=c.mods})!;
c.mods = m;
};
};
};
@@ -23164,12 +23100,8 @@ fn fficollect(c: *cgen, file: *node) void = {
let symnode: *node = a.list;
if (symnode != nil) {
if (symnode.kind == nkind.N_STRLIT) {
// #35: sizeof(ffi) = 56 under str=24 ({str,str,*ffi}).
let f: *ffi = amalloc(c.a, 64u64): *ffi;
f.ident = d.str;
f.symbol = symnode.str;
f.fnext = c.ffis;
c.ffis = f;
let f: *ffi = alloc(ffi{ident=d.str, symbol=symnode.str, fnext=c.ffis})!;
c.ffis = f;
};
};
};