From beb507a1edadb2829478d066b80ea62ed537157a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20R=C3=B8nne=20Petersen?= Date: Sun, 19 Oct 2025 22:40:15 +0200 Subject: [PATCH] std.builtin: add CallingConvention.x86_64_x32 This was forgotten during the refactoring of std.builtin.CallingConvention. It mirrors mips64_n32 for MIPS. --- lib/std/Target.zig | 6 +++++- lib/std/builtin.zig | 1 + src/Sema.zig | 1 + src/codegen/llvm.zig | 1 + test/cases/compile_errors/invalid_variadic_function.zig | 4 ++-- ...ify_type.Fn_with_is_var_args_true_and_non-C_callconv.zig | 2 +- 6 files changed, 11 insertions(+), 4 deletions(-) diff --git a/lib/std/Target.zig b/lib/std/Target.zig index 20d37b8939..b99e2b366e 100644 --- a/lib/std/Target.zig +++ b/lib/std/Target.zig @@ -1787,6 +1787,7 @@ pub const Cpu = struct { => unreachable, .x86_64_sysv, + .x86_64_x32, .x86_64_win, .x86_64_regcall_v3_sysv, .x86_64_regcall_v4_win, @@ -3632,7 +3633,10 @@ pub fn cCallingConvention(target: *const Target) ?std.builtin.CallingConvention return switch (target.cpu.arch) { .x86_64 => switch (target.os.tag) { .windows, .uefi => .{ .x86_64_win = .{} }, - else => .{ .x86_64_sysv = .{} }, + else => switch (target.abi) { + .gnuabin32, .muslabin32 => .{ .x86_64_x32 = .{} }, + else => .{ .x86_64_sysv = .{} }, + }, }, .x86 => switch (target.os.tag) { .windows, .uefi => .{ .x86_win = .{} }, diff --git a/lib/std/builtin.zig b/lib/std/builtin.zig index ed4a39b8bb..6feacbc8c8 100644 --- a/lib/std/builtin.zig +++ b/lib/std/builtin.zig @@ -204,6 +204,7 @@ pub const CallingConvention = union(enum(u8)) { // Calling conventions for the `x86_64` architecture. x86_64_sysv: CommonOptions, + x86_64_x32: CommonOptions, x86_64_win: CommonOptions, x86_64_regcall_v3_sysv: CommonOptions, x86_64_regcall_v4_win: CommonOptions, diff --git a/src/Sema.zig b/src/Sema.zig index be4b777eeb..47b5339222 100644 --- a/src/Sema.zig +++ b/src/Sema.zig @@ -9035,6 +9035,7 @@ pub fn handleExternLibName( /// functions or there are no more other calling conventions that support variadic functions. const calling_conventions_supporting_var_args = [_]std.builtin.CallingConvention.Tag{ .x86_64_sysv, + .x86_64_x32, .x86_64_win, .x86_sysv, .x86_win, diff --git a/src/codegen/llvm.zig b/src/codegen/llvm.zig index 8c6f5f973f..3b3febf27e 100644 --- a/src/codegen/llvm.zig +++ b/src/codegen/llvm.zig @@ -11919,6 +11919,7 @@ fn toLlvmCallConvTag(cc_tag: std.builtin.CallingConvention.Tag, target: *const s .x86_sysv, .x86_win, .x86_thiscall_mingw, + .x86_64_x32, .aarch64_aapcs, .aarch64_aapcs_darwin, .aarch64_aapcs_win, diff --git a/test/cases/compile_errors/invalid_variadic_function.zig b/test/cases/compile_errors/invalid_variadic_function.zig index 08e1eb0148..a5f2c2f893 100644 --- a/test/cases/compile_errors/invalid_variadic_function.zig +++ b/test/cases/compile_errors/invalid_variadic_function.zig @@ -12,6 +12,6 @@ comptime { // target=x86_64-linux // // :1:8: error: variadic function does not support 'auto' calling convention -// :1:8: note: supported calling conventions: 'x86_64_sysv', 'x86_64_win' +// :1:8: note: supported calling conventions: 'x86_64_sysv', 'x86_64_x32', 'x86_64_win' // :2:16: error: variadic function does not support 'inline' calling convention -// :2:16: note: supported calling conventions: 'x86_64_sysv', 'x86_64_win' +// :2:16: note: supported calling conventions: 'x86_64_sysv', 'x86_64_x32', 'x86_64_win' diff --git a/test/cases/compile_errors/reify_type.Fn_with_is_var_args_true_and_non-C_callconv.zig b/test/cases/compile_errors/reify_type.Fn_with_is_var_args_true_and_non-C_callconv.zig index e72dc41b6e..f74b89ae87 100644 --- a/test/cases/compile_errors/reify_type.Fn_with_is_var_args_true_and_non-C_callconv.zig +++ b/test/cases/compile_errors/reify_type.Fn_with_is_var_args_true_and_non-C_callconv.zig @@ -15,4 +15,4 @@ comptime { // target=x86_64-linux // // :1:13: error: variadic function does not support 'auto' calling convention -// :1:13: note: supported calling conventions: 'x86_64_sysv', 'x86_64_win' +// :1:13: note: supported calling conventions: 'x86_64_sysv', 'x86_64_x32', 'x86_64_win'