zig

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

commit 4cee1f7b9a6df9c890268eddc526e66dfa16f0ad (tree)
parent 53ebfde6b433ebdb28d4989a345e8d34abf049b7
Author: e820 <e820@noreply.codeberg.org>
Date:   Fri,  2 Jan 2026 23:16:08 +0100

Forgo `const` qualifiers on `register` locals generated by asm (#30645)

See https://codeberg.org/ziglang/zig/issues/30637 for details.

Works around https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86673

Co-authored-by: Laurin-Luis Lehning <65224843+e820@users.noreply.github.com>
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/30645
Reviewed-by: Andrew Kelley <andrewrk@noreply.codeberg.org>
Co-authored-by: e820 <e820@noreply.codeberg.org>
Co-committed-by: e820 <e820@noreply.codeberg.org>

Diffstat:
Msrc/codegen/c.zig | 4+++-
1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/src/codegen/c.zig b/src/codegen/c.zig @@ -5529,7 +5529,9 @@ fn airAsm(f: *Function, inst: Air.Inst.Index) !CValue { .alignas = CType.AlignAs.fromAbiAlignment(input_ty.abiAlignment(zcu)), }); try f.allocs.put(gpa, input_local.new_local, false); - try f.object.dg.renderTypeAndName(w, input_ty, input_local, Const, .none, .complete); + // Do not render the declaration as `const` qualified if we're generating an + // explicit `register` local, as GCC will ignore the constraint completely. + try f.object.dg.renderTypeAndName(w, input_ty, input_local, if (is_reg) .{} else Const, .none, .complete); if (is_reg) { try w.writeAll(" __asm(\""); try w.writeAll(constraint["{".len .. constraint.len - "}".len]);