From 1b55ca18ef4d55b3152b107e56358b2b4022a2be Mon Sep 17 00:00:00 2001 From: Matthew Lugg Date: Wed, 22 Apr 2026 08:46:10 +0100 Subject: [PATCH] cbe: add missing cast of overflow arithmetic out pointer --- src/codegen/c.zig | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/codegen/c.zig b/src/codegen/c.zig index ee9e90ce80..885ca0aa1c 100644 --- a/src/codegen/c.zig +++ b/src/codegen/c.zig @@ -3497,9 +3497,27 @@ fn airOverflow(f: *Function, inst: Air.Inst.Index, operation: []const u8, info: try w.writeAll(operation); try w.writeAll("o_"); try f.dg.renderTypeForBuiltinFnName(w, scalar_ty); - try w.writeAll("(&"); + try w.writeByte('('); + + // '&dest', possibly preceded by a cast + switch (zcu.intern_pool.indexToKey(scalar_ty.toIntern())) { + .int_type => {}, // we already have a '[u]intX_t *' + .simple_type => { + // '&dest' will be something like a 'uintptr_t *', which might be a different C type to + // the equivalent sized integer (e.g. 'uint64_t *'), so we need a cast. We don't need a + // cast on the *operands* because they are passed by value (except for big integers, + // where this issue doesn't exist because no "simple" int type needs bigint repr). + try w.print("({s}int{d}_t *)", .{ + if (scalar_ty.isUnsignedInt(zcu)) "u" else "", + scalar_ty.abiSize(zcu) * 8, + }); + }, + else => unreachable, + } + try w.writeByte('&'); try f.writeCValueMember(w, local, .{ .field = 0 }); try v.elem(f, w); + try w.writeAll(", "); if (ref_arg) try w.writeByte('&'); try f.writeCValue(w, lhs, .other);