zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit 6de339d5d3deb4c7a1585288888f8e788e489eb6 (tree)
parent 1bca158c6e0a4f301cef18db705d89de78c86bcb
Author: Bingwu Zhang <xtex@aosc.io>
Date:   Sat, 18 Oct 2025 21:29:25 +0800

cbe: fix MIPS register names in inline assembly

Zig uses "rN" for MIPS register clobbers which are more
ergonomic and easier to write (.rN vs. .@"$N").
However, GCC and Clang uses "$N".

Bug: #25613
Signed-off-by: Bingwu Zhang <xtex@xtexx.eu.org>

Diffstat:
Acrt.c | 0
Msrc/codegen/c.zig | 14++++++++++++++
2 files changed, 14 insertions(+), 0 deletions(-)

diff --git a/crt.c b/crt.c diff --git a/src/codegen/c.zig b/src/codegen/c.zig @@ -5770,6 +5770,20 @@ fn airAsm(f: *Function, inst: Air.Inst.Index) !CValue { .bool_true => { const name = struct_type.structFieldName(i, zcu).toSlice(ip).?; assert(name.len != 0); + + const target = &f.object.dg.mod.resolved_target.result; + if (target.cpu.arch.isMIPS() and name[0] == 'r') { + // GCC uses "$N" for register names instead of "rN" used by Zig. + var c_name_buf: [4]u8 = undefined; + const c_name = (&c_name_buf)[0..name.len]; + @memcpy(c_name, name); + c_name_buf[0] = '$'; + + try w.print(" {f}", .{fmtStringLiteral(c_name, null)}); + (try w.writableArray(1))[0] = ','; + continue; + } + try w.print(" {f}", .{fmtStringLiteral(name, null)}); (try w.writableArray(1))[0] = ','; },