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-22 10:08:48+02:00
log1b55ca18ef4d55b3152b107e56358b2b4022a2be
treec8315b7f31a30d01e83a01c911b24610cfed1415
parentcfde9303ff75322525746aa325026f0e12fb402c
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:...@@ -3497,9 +3497,27 @@ fn airOverflow(f: *Function, inst: Air.Inst.Index, operation: []const u8, info:
3497 try w.writeAll(operation);3497 try w.writeAll(operation);
3498 try w.writeAll("o_");3498 try w.writeAll("o_");
3499 try f.dg.renderTypeForBuiltinFnName(w, scalar_ty);3499 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('&');
3501 try f.writeCValueMember(w, local, .{ .field = 0 });3518 try f.writeCValueMember(w, local, .{ .field = 0 });
3502 try v.elem(f, w);3519 try v.elem(f, w);
3520
3503 try w.writeAll(", ");3521 try w.writeAll(", ");
3504 if (ref_arg) try w.writeByte('&');3522 if (ref_arg) try w.writeByte('&');
3505 try f.writeCValue(w, lhs, .other);3523 try f.writeCValue(w, lhs, .other);