w6c+selfhost: cgen *p OP= v (was silent no-op)
`*p += 1` and the rest of the compound-deref family (-= *= |= &= ^=
<<= >>=) fell through the N_ASSIGN switch in both stages and emitted
nothing. The `*p = v` block was gated on TK_ASSIGN, the IDENT-compound
block required N_IDENT, and there was no N_UN/TK_STAR compound branch
between them. Test 994/995/997 byte-identity hid it: both stages
mis-compiled identically, so the diffs were clean.
Surfaced via fmt.println("hello") segfaulting in wwstage builds.
findvariadicparam in cgenutil.ww does `*nfixed_out += 1`; the drop
left nfixed at 0, so `fprint(fd, args...)` mis-counted variadic args,
gathered fd as a formattable element, and segfaulted on tagged
dispatch.
Adds the missing branch in cmd/w6c/cgen.c N_ASSIGN and
selfhost/cmd/wcc/cgenexpr.ww cgassign: eval rhs → push, eval ptr →
BX, sized+extended load (BX) → AX (MOVZBQ for 1B, MOVSXD/MOVL for 4B
by signedness, MOVQ for 8B), pop rhs → CX, combine via
ADDQ/SUBQ/IMULQ/ANDQ/ORQ/XORQ/SHLQ/SHRQ on CX,AX, sized store back.
TK_SLASHEQ stays the rhs-only fallback, matching the IDENT path.
Float and aggregate deref compounds still fall through — uncommon.
This commit is contained in:
@@ -10268,6 +10268,76 @@ fn cgassign(c: *cgen, n: *node) void = {
|
||||
};
|
||||
};
|
||||
};
|
||||
// `*p OP= v` — compound assign through a pointer deref. The
|
||||
// plain-assign branch above only fires for TK_ASSIGN; without
|
||||
// this, compound ops fall through and emit nothing (silent
|
||||
// no-op — exactly the trap that broke fmt.println). Mirror of
|
||||
// cmd/w6c/cgen.c's N_UN/TK_STAR compound branch.
|
||||
if (lhs != nil) {
|
||||
if (lhs.kind == nkind.N_UN) {
|
||||
if (lhs.op == tkind.TK_STAR) {
|
||||
if (n.op != tkind.TK_ASSIGN) {
|
||||
let inner: *node = lhs.lhs;
|
||||
let loadop: str = "MOVQ";
|
||||
let storeop: str = "MOVQ";
|
||||
if (inner != nil) {
|
||||
if (inner.kind == nkind.N_IDENT) {
|
||||
let lc: *local = localfindnode(c, inner.str);
|
||||
if (lc != nil) {
|
||||
let tn: *node = lc.tnode;
|
||||
if (tn != nil) {
|
||||
if (tn.kind == nkind.N_TPTR) {
|
||||
let pe: *node = tn.lhs;
|
||||
if (pe != nil) {
|
||||
if (pe.kind == nkind.N_TNAME) {
|
||||
let ps: i32 = primsize(pe.str);
|
||||
if (ps == 1) {
|
||||
loadop = "MOVZBQ";
|
||||
storeop = "MOVB";
|
||||
} else { if (ps == 4) {
|
||||
if (typenameissigned(pe.str)) {
|
||||
loadop = "MOVSXD";
|
||||
} else {
|
||||
loadop = "MOVL";
|
||||
};
|
||||
storeop = "MOVL";
|
||||
}; };
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
cgexpr(c, n.rhs);
|
||||
emitline("\tPUSHQ\tAX\n");
|
||||
cgexpr(c, inner);
|
||||
emitline("\tMOVQ\tAX, BX\n");
|
||||
emitline("\t");
|
||||
emitline(loadop);
|
||||
emitline("\t(BX), AX\n");
|
||||
emitline("\tPOPQ\tCX\n");
|
||||
let combineop: str = "MOVQ";
|
||||
if (n.op == tkind.TK_PLUSEQ) { combineop = "ADDQ"; }
|
||||
else { if (n.op == tkind.TK_MINUSEQ) { combineop = "SUBQ"; }
|
||||
else { if (n.op == tkind.TK_STAREQ) { combineop = "IMULQ"; }
|
||||
else { if (n.op == tkind.TK_AMPEQ) { combineop = "ANDQ"; }
|
||||
else { if (n.op == tkind.TK_PIPEEQ) { combineop = "ORQ"; }
|
||||
else { if (n.op == tkind.TK_CARETEQ) { combineop = "XORQ"; }
|
||||
else { if (n.op == tkind.TK_LSHIFTEQ) { combineop = "SHLQ"; }
|
||||
else { if (n.op == tkind.TK_RSHIFTEQ) { combineop = "SHRQ"; };
|
||||
}; }; }; }; }; }; };
|
||||
emitline("\t");
|
||||
emitline(combineop);
|
||||
emitline("\tCX, AX\n");
|
||||
emitline("\t");
|
||||
emitline(storeop);
|
||||
emitline("\tAX, (BX)\n");
|
||||
return;
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
// Array/slice/ptr index store: `arr[i] = v;`. Element size
|
||||
// from base.tnode picks MOVB vs MOVQ.
|
||||
if (lhs != nil) {
|
||||
|
||||
@@ -2574,6 +2574,76 @@ fn cgassign(c: *cgen, n: *node) void = {
|
||||
};
|
||||
};
|
||||
};
|
||||
// `*p OP= v` — compound assign through a pointer deref. The
|
||||
// plain-assign branch above only fires for TK_ASSIGN; without
|
||||
// this, compound ops fall through and emit nothing (silent
|
||||
// no-op — exactly the trap that broke fmt.println). Mirror of
|
||||
// cmd/w6c/cgen.c's N_UN/TK_STAR compound branch.
|
||||
if (lhs != nil) {
|
||||
if (lhs.kind == nkind.N_UN) {
|
||||
if (lhs.op == tkind.TK_STAR) {
|
||||
if (n.op != tkind.TK_ASSIGN) {
|
||||
let inner: *node = lhs.lhs;
|
||||
let loadop: str = "MOVQ";
|
||||
let storeop: str = "MOVQ";
|
||||
if (inner != nil) {
|
||||
if (inner.kind == nkind.N_IDENT) {
|
||||
let lc: *local = localfindnode(c, inner.str);
|
||||
if (lc != nil) {
|
||||
let tn: *node = lc.tnode;
|
||||
if (tn != nil) {
|
||||
if (tn.kind == nkind.N_TPTR) {
|
||||
let pe: *node = tn.lhs;
|
||||
if (pe != nil) {
|
||||
if (pe.kind == nkind.N_TNAME) {
|
||||
let ps: i32 = primsize(pe.str);
|
||||
if (ps == 1) {
|
||||
loadop = "MOVZBQ";
|
||||
storeop = "MOVB";
|
||||
} else { if (ps == 4) {
|
||||
if (typenameissigned(pe.str)) {
|
||||
loadop = "MOVSXD";
|
||||
} else {
|
||||
loadop = "MOVL";
|
||||
};
|
||||
storeop = "MOVL";
|
||||
}; };
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
cgexpr(c, n.rhs);
|
||||
emitline("\tPUSHQ\tAX\n");
|
||||
cgexpr(c, inner);
|
||||
emitline("\tMOVQ\tAX, BX\n");
|
||||
emitline("\t");
|
||||
emitline(loadop);
|
||||
emitline("\t(BX), AX\n");
|
||||
emitline("\tPOPQ\tCX\n");
|
||||
let combineop: str = "MOVQ";
|
||||
if (n.op == tkind.TK_PLUSEQ) { combineop = "ADDQ"; }
|
||||
else { if (n.op == tkind.TK_MINUSEQ) { combineop = "SUBQ"; }
|
||||
else { if (n.op == tkind.TK_STAREQ) { combineop = "IMULQ"; }
|
||||
else { if (n.op == tkind.TK_AMPEQ) { combineop = "ANDQ"; }
|
||||
else { if (n.op == tkind.TK_PIPEEQ) { combineop = "ORQ"; }
|
||||
else { if (n.op == tkind.TK_CARETEQ) { combineop = "XORQ"; }
|
||||
else { if (n.op == tkind.TK_LSHIFTEQ) { combineop = "SHLQ"; }
|
||||
else { if (n.op == tkind.TK_RSHIFTEQ) { combineop = "SHRQ"; };
|
||||
}; }; }; }; }; }; };
|
||||
emitline("\t");
|
||||
emitline(combineop);
|
||||
emitline("\tCX, AX\n");
|
||||
emitline("\t");
|
||||
emitline(storeop);
|
||||
emitline("\tAX, (BX)\n");
|
||||
return;
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
// Array/slice/ptr index store: `arr[i] = v;`. Element size
|
||||
// from base.tnode picks MOVB vs MOVQ.
|
||||
if (lhs != nil) {
|
||||
|
||||
@@ -10268,6 +10268,76 @@ fn cgassign(c: *cgen, n: *node) void = {
|
||||
};
|
||||
};
|
||||
};
|
||||
// `*p OP= v` — compound assign through a pointer deref. The
|
||||
// plain-assign branch above only fires for TK_ASSIGN; without
|
||||
// this, compound ops fall through and emit nothing (silent
|
||||
// no-op — exactly the trap that broke fmt.println). Mirror of
|
||||
// cmd/w6c/cgen.c's N_UN/TK_STAR compound branch.
|
||||
if (lhs != nil) {
|
||||
if (lhs.kind == nkind.N_UN) {
|
||||
if (lhs.op == tkind.TK_STAR) {
|
||||
if (n.op != tkind.TK_ASSIGN) {
|
||||
let inner: *node = lhs.lhs;
|
||||
let loadop: str = "MOVQ";
|
||||
let storeop: str = "MOVQ";
|
||||
if (inner != nil) {
|
||||
if (inner.kind == nkind.N_IDENT) {
|
||||
let lc: *local = localfindnode(c, inner.str);
|
||||
if (lc != nil) {
|
||||
let tn: *node = lc.tnode;
|
||||
if (tn != nil) {
|
||||
if (tn.kind == nkind.N_TPTR) {
|
||||
let pe: *node = tn.lhs;
|
||||
if (pe != nil) {
|
||||
if (pe.kind == nkind.N_TNAME) {
|
||||
let ps: i32 = primsize(pe.str);
|
||||
if (ps == 1) {
|
||||
loadop = "MOVZBQ";
|
||||
storeop = "MOVB";
|
||||
} else { if (ps == 4) {
|
||||
if (typenameissigned(pe.str)) {
|
||||
loadop = "MOVSXD";
|
||||
} else {
|
||||
loadop = "MOVL";
|
||||
};
|
||||
storeop = "MOVL";
|
||||
}; };
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
cgexpr(c, n.rhs);
|
||||
emitline("\tPUSHQ\tAX\n");
|
||||
cgexpr(c, inner);
|
||||
emitline("\tMOVQ\tAX, BX\n");
|
||||
emitline("\t");
|
||||
emitline(loadop);
|
||||
emitline("\t(BX), AX\n");
|
||||
emitline("\tPOPQ\tCX\n");
|
||||
let combineop: str = "MOVQ";
|
||||
if (n.op == tkind.TK_PLUSEQ) { combineop = "ADDQ"; }
|
||||
else { if (n.op == tkind.TK_MINUSEQ) { combineop = "SUBQ"; }
|
||||
else { if (n.op == tkind.TK_STAREQ) { combineop = "IMULQ"; }
|
||||
else { if (n.op == tkind.TK_AMPEQ) { combineop = "ANDQ"; }
|
||||
else { if (n.op == tkind.TK_PIPEEQ) { combineop = "ORQ"; }
|
||||
else { if (n.op == tkind.TK_CARETEQ) { combineop = "XORQ"; }
|
||||
else { if (n.op == tkind.TK_LSHIFTEQ) { combineop = "SHLQ"; }
|
||||
else { if (n.op == tkind.TK_RSHIFTEQ) { combineop = "SHRQ"; };
|
||||
}; }; }; }; }; }; };
|
||||
emitline("\t");
|
||||
emitline(combineop);
|
||||
emitline("\tCX, AX\n");
|
||||
emitline("\t");
|
||||
emitline(storeop);
|
||||
emitline("\tAX, (BX)\n");
|
||||
return;
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
// Array/slice/ptr index store: `arr[i] = v;`. Element size
|
||||
// from base.tnode picks MOVB vs MOVQ.
|
||||
if (lhs != nil) {
|
||||
|
||||
Reference in New Issue
Block a user