Commit beb507a1ed

Alex Rønne Petersen <alex@alexrp.com>
2025-10-19 22:40:15
std.builtin: add CallingConvention.x86_64_x32
This was forgotten during the refactoring of std.builtin.CallingConvention. It mirrors mips64_n32 for MIPS.
1 parent a144194
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,
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 = .{} },
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,
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,
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'
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'