From 4cee1f7b9a6df9c890268eddc526e66dfa16f0ad Mon Sep 17 00:00:00 2001 From: e820 Date: Fri, 2 Jan 2026 23:16:08 +0100 Subject: [PATCH] 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 Co-authored-by: e820 Co-committed-by: e820 --- src/codegen/c.zig | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/codegen/c.zig b/src/codegen/c.zig index fba8806ecd3f379eeceb1823abfb319df3f40948..f55dd408b52460bad630bf4efd1a2f251a5b8d91 100644 --- 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]); -- 2.54.0