authorgravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2026-04-22 08:46:10+01:00
committergravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2026-04-25 05:22:41+02:00
log31bc385a96b98858889837f8b8256b7e2bf7be4c
treee7b803668bb87b81679046d2bad5c5114efdbdcb
parent23bcb8148fb12d86b003708b6410d98a986d2d9f
signaturebadge-check Signed by SSH key SHA256:7B/LJ7bpR1eX8aCXSr4mtd5M45VMPKcx9zY8e95b5QM

cbe: add missing cast of overflow arithmetic out pointer


1 files changed, 19 insertions(+), 1 deletions(-)

src/codegen/c.zig+19-1
......@@ -3497,9 +3497,27 @@ fn airOverflow(f: *Function, inst: Air.Inst.Index, operation: []const u8, info:
34973497 try w.writeAll(operation);
34983498 try w.writeAll("o_");
34993499 try f.dg.renderTypeForBuiltinFnName(w, scalar_ty);
3500 try w.writeAll("(&");
3500 try w.writeByte('(');
3501
3502 // '&dest', possibly preceded by a cast
3503 switch (zcu.intern_pool.indexToKey(scalar_ty.toIntern())) {
3504 .int_type => {}, // we already have a '[u]intX_t *'
3505 .simple_type => {
3506 // '&dest' will be something like a 'uintptr_t *', which might be a different C type to
3507 // the equivalent sized integer (e.g. 'uint64_t *'), so we need a cast. We don't need a
3508 // cast on the *operands* because they are passed by value (except for big integers,
3509 // where this issue doesn't exist because no "simple" int type needs bigint repr).
3510 try w.print("({s}int{d}_t *)", .{
3511 if (scalar_ty.isUnsignedInt(zcu)) "u" else "",
3512 scalar_ty.abiSize(zcu) * 8,
3513 });
3514 },
3515 else => unreachable,
3516 }
3517 try w.writeByte('&');
35013518 try f.writeCValueMember(w, local, .{ .field = 0 });
35023519 try v.elem(f, w);
3520
35033521 try w.writeAll(", ");
35043522 if (ref_arg) try w.writeByte('&');
35053523 try f.writeCValue(w, lhs, .other);