Skip to content

Conversation

@xtexx
Copy link
Contributor

@xtexx xtexx commented Oct 25, 2025

Clang crashes when I write "$w0" in clobbers (:

@xtexx xtexx changed the title cbe: fix MIPS fcc register names in inline assembly cbe: fix more MIPS register names in inline assembly Oct 25, 2025
@alexrp alexrp self-assigned this Oct 25, 2025
Comment on lines +5776 to +5795
if (name[0] == 'r') {
// C 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;
} else if (mem.startsWith(u8, name, "fcc") or name[0] == 'w' or name[0] == 'f') {
// C requires a "$" prefix before register names.
var c_name_buf: [6]u8 = undefined;
c_name_buf[0] = '$';
@memcpy((&c_name_buf)[1..][0..name.len], name);

try w.print(" {f}", .{fmtStringLiteral((&c_name_buf)[0 .. 1 + name.len], null)});
(try w.writableArray(1))[0] = ',';
continue;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some of my recent work led me to the realization that Alpha also uses $-prefixed registers... so we'll need this code for more targets.

To make it a bit more maintainable, I would suggest moving c_name_buf out of the target check and just giving it a "big enough" size like 64, renaming name to field_name, and then:

const name = if (target.cpu.arch.isMIPS())
    // ... write into c_name_buf and return a slice of it ...
else
    field_name;

Then we also don't need to duplicate the trailing writing logic.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants