authorgravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2024-10-08 21:16:35+01:00
committergravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2024-10-19 19:15:23+01:00
logbc797a97b1f7476b620567ff32b7a396ebdb4c9c
tree368d8fbb1d1dd5fb0b84b8499392ec4f69ea2693
parent36405b9b43237960733a86d0b1eeac1bc047311c
signaturelock-open Commit is signed but in an unrecognized format.

std: update for new `CallingConvention`

The old `CallingConvention` type is replaced with the new `NewCallingConvention`. References to `NewCallingConvention` in the compiler are updated accordingly. In addition, a few parts of the standard library are updated to use the new type correctly.

19 files changed, 109 insertions(+), 160 deletions(-)

lib/std/Target.zig+2-2
...@@ -1612,7 +1612,7 @@ pub const Cpu = struct {...@@ -1612,7 +1612,7 @@ pub const Cpu = struct {
16121612
1613 /// Returns the array of `Arch` to which a specific `std.builtin.CallingConvention` applies.1613 /// Returns the array of `Arch` to which a specific `std.builtin.CallingConvention` applies.
1614 /// Asserts that `cc` is not `.auto`, `.@"async"`, `.naked`, or `.@"inline"`.1614 /// Asserts that `cc` is not `.auto`, `.@"async"`, `.naked`, or `.@"inline"`.
1615 pub fn fromCallconv(cc: std.builtin.NewCallingConvention) []const Arch {1615 pub fn fromCallconv(cc: std.builtin.CallingConvention) []const Arch {
1616 return switch (cc) {1616 return switch (cc) {
1617 .auto,1617 .auto,
1618 .@"async",1618 .@"async",
...@@ -3032,7 +3032,7 @@ pub fn cTypePreferredAlignment(target: Target, c_type: CType) u16 {...@@ -3032,7 +3032,7 @@ pub fn cTypePreferredAlignment(target: Target, c_type: CType) u16 {
3032 );3032 );
3033}3033}
30343034
3035pub fn defaultCCallingConvention(target: Target) ?std.builtin.NewCallingConvention {3035pub fn defaultCCallingConvention(target: Target) ?std.builtin.CallingConvention {
3036 return switch (target.cpu.arch) {3036 return switch (target.cpu.arch) {
3037 .x86_64 => switch (target.os.tag) {3037 .x86_64 => switch (target.os.tag) {
3038 .windows, .uefi => .{ .x86_64_win = .{} },3038 .windows, .uefi => .{ .x86_64_win = .{} },
lib/std/builtin.zig+31-76
...@@ -160,72 +160,20 @@ pub const OptimizeMode = enum {...@@ -160,72 +160,20 @@ pub const OptimizeMode = enum {
160/// Deprecated; use OptimizeMode.160/// Deprecated; use OptimizeMode.
161pub const Mode = OptimizeMode;161pub const Mode = OptimizeMode;
162162
163/// This data structure is used by the Zig language code generation and
164/// therefore must be kept in sync with the compiler implementation.
165pub const CallingConvention = enum(u8) {
166 /// This is the default Zig calling convention used when not using `export` on `fn`
167 /// and no other calling convention is specified.
168 Unspecified,
169 /// Matches the C ABI for the target.
170 /// This is the default calling convention when using `export` on `fn`
171 /// and no other calling convention is specified.
172 C,
173 /// This makes a function not have any function prologue or epilogue,
174 /// making the function itself uncallable in regular Zig code.
175 /// This can be useful when integrating with assembly.
176 Naked,
177 /// Functions with this calling convention are called asynchronously,
178 /// as if called as `async function()`.
179 Async,
180 /// Functions with this calling convention are inlined at all call sites.
181 Inline,
182 /// x86-only.
183 Interrupt,
184 Signal,
185 /// x86-only.
186 Stdcall,
187 /// x86-only.
188 Fastcall,
189 /// x86-only.
190 Vectorcall,
191 /// x86-only.
192 Thiscall,
193 /// ARM Procedure Call Standard (obsolete)
194 /// ARM-only.
195 APCS,
196 /// ARM Architecture Procedure Call Standard (current standard)
197 /// ARM-only.
198 AAPCS,
199 /// ARM Architecture Procedure Call Standard Vector Floating-Point
200 /// ARM-only.
201 AAPCSVFP,
202 /// x86-64-only.
203 SysV,
204 /// x86-64-only.
205 Win64,
206 /// AMD GPU, NVPTX, or SPIR-V kernel
207 Kernel,
208 // Vulkan-only
209 Fragment,
210 Vertex,
211};
212
213/// The calling convention of a function defines how arguments and return values are passed, as well163/// The calling convention of a function defines how arguments and return values are passed, as well
214/// as any other requirements which callers and callees must respect, such as register preservation164/// as any other requirements which callers and callees must respect, such as register preservation
215/// and stack alignment.165/// and stack alignment.
216///166///
217/// This data structure is used by the Zig language code generation and167/// This data structure is used by the Zig language code generation and
218/// therefore must be kept in sync with the compiler implementation.168/// therefore must be kept in sync with the compiler implementation.
219///169pub const CallingConvention = union(enum(u8)) {
220/// TODO: this will be renamed `CallingConvention` after an initial zig1.wasm update.170 pub const Tag = @typeInfo(CallingConvention).@"union".tag_type.?;
221pub const NewCallingConvention = union(enum(u8)) {
222 pub const Tag = @typeInfo(NewCallingConvention).@"union".tag_type.?;
223171
224 /// This is an alias for the default C calling convention for this target.172 /// This is an alias for the default C calling convention for this target.
225 /// Functions marked as `extern` or `export` are given this calling convention by default.173 /// Functions marked as `extern` or `export` are given this calling convention by default.
226 pub const c = builtin.target.defaultCCallingConvention().?;174 pub const c = builtin.target.defaultCCallingConvention().?;
227175
228 pub const winapi: NewCallingConvention = switch (builtin.target.arch) {176 pub const winapi: CallingConvention = switch (builtin.target.arch) {
229 .x86_64 => .{ .x86_64_win = .{} },177 .x86_64 => .{ .x86_64_win = .{} },
230 .x86 => .{ .x86_stdcall = .{} },178 .x86 => .{ .x86_stdcall = .{} },
231 .aarch64, .aarch64_be => .{ .aarch64_aapcs_win = .{} },179 .aarch64, .aarch64_be => .{ .aarch64_aapcs_win = .{} },
...@@ -233,7 +181,7 @@ pub const NewCallingConvention = union(enum(u8)) {...@@ -233,7 +181,7 @@ pub const NewCallingConvention = union(enum(u8)) {
233 else => unreachable,181 else => unreachable,
234 };182 };
235183
236 pub const kernel: NewCallingConvention = switch (builtin.target.cpu.arch) {184 pub const kernel: CallingConvention = switch (builtin.target.cpu.arch) {
237 .amdgcn => .amdgcn_kernel,185 .amdgcn => .amdgcn_kernel,
238 .nvptx, .nvptx64 => .nvptx_kernel,186 .nvptx, .nvptx64 => .nvptx_kernel,
239 .spirv, .spirv32, .spirv64 => .spirv_kernel,187 .spirv, .spirv32, .spirv64 => .spirv_kernel,
...@@ -241,53 +189,53 @@ pub const NewCallingConvention = union(enum(u8)) {...@@ -241,53 +189,53 @@ pub const NewCallingConvention = union(enum(u8)) {
241 };189 };
242190
243 /// Deprecated; use `.auto`.191 /// Deprecated; use `.auto`.
244 pub const Unspecified: NewCallingConvention = .auto;192 pub const Unspecified: CallingConvention = .auto;
245 /// Deprecated; use `.c`.193 /// Deprecated; use `.c`.
246 pub const C: NewCallingConvention = .c;194 pub const C: CallingConvention = .c;
247 /// Deprecated; use `.naked`.195 /// Deprecated; use `.naked`.
248 pub const Naked: NewCallingConvention = .naked;196 pub const Naked: CallingConvention = .naked;
249 /// Deprecated; use `.@"async"`.197 /// Deprecated; use `.@"async"`.
250 pub const Async: NewCallingConvention = .@"async";198 pub const Async: CallingConvention = .@"async";
251 /// Deprecated; use `.@"inline"`.199 /// Deprecated; use `.@"inline"`.
252 pub const Inline: NewCallingConvention = .@"inline";200 pub const Inline: CallingConvention = .@"inline";
253 /// Deprecated; use `.x86_64_interrupt`, `.x86_interrupt`, or `.avr_interrupt`.201 /// Deprecated; use `.x86_64_interrupt`, `.x86_interrupt`, or `.avr_interrupt`.
254 pub const Interrupt: NewCallingConvention = switch (builtin.target.cpu.arch) {202 pub const Interrupt: CallingConvention = switch (builtin.target.cpu.arch) {
255 .x86_64 => .{ .x86_64_interrupt = .{} },203 .x86_64 => .{ .x86_64_interrupt = .{} },
256 .x86 => .{ .x86_interrupt = .{} },204 .x86 => .{ .x86_interrupt = .{} },
257 .avr => .avr_interrupt,205 .avr => .avr_interrupt,
258 else => unreachable,206 else => unreachable,
259 };207 };
260 /// Deprecated; use `.avr_signal`.208 /// Deprecated; use `.avr_signal`.
261 pub const Signal: NewCallingConvention = .avr_signal;209 pub const Signal: CallingConvention = .avr_signal;
262 /// Deprecated; use `.x86_stdcall`.210 /// Deprecated; use `.x86_stdcall`.
263 pub const Stdcall: NewCallingConvention = .{ .x86_stdcall = .{} };211 pub const Stdcall: CallingConvention = .{ .x86_stdcall = .{} };
264 /// Deprecated; use `.x86_fastcall`.212 /// Deprecated; use `.x86_fastcall`.
265 pub const Fastcall: NewCallingConvention = .{ .x86_fastcall = .{} };213 pub const Fastcall: CallingConvention = .{ .x86_fastcall = .{} };
266 /// Deprecated; use `.x86_64_vectorcall`, `.x86_vectorcall`, or `aarch64_vfabi`.214 /// Deprecated; use `.x86_64_vectorcall`, `.x86_vectorcall`, or `aarch64_vfabi`.
267 pub const Vectorcall: NewCallingConvention = switch (builtin.target.cpu.arch) {215 pub const Vectorcall: CallingConvention = switch (builtin.target.cpu.arch) {
268 .x86_64 => .{ .x86_64_vectorcall = .{} },216 .x86_64 => .{ .x86_64_vectorcall = .{} },
269 .x86 => .{ .x86_vectorcall = .{} },217 .x86 => .{ .x86_vectorcall = .{} },
270 .aarch64, .aarch64_be => .{ .aarch64_vfabi = .{} },218 .aarch64, .aarch64_be => .{ .aarch64_vfabi = .{} },
271 else => unreachable,219 else => unreachable,
272 };220 };
273 /// Deprecated; use `.x86_thiscall`.221 /// Deprecated; use `.x86_thiscall`.
274 pub const Thiscall: NewCallingConvention = .{ .x86_thiscall = .{} };222 pub const Thiscall: CallingConvention = .{ .x86_thiscall = .{} };
275 /// Deprecated; use `.arm_apcs`.223 /// Deprecated; use `.arm_apcs`.
276 pub const APCS: NewCallingConvention = .{ .arm_apcs = .{} };224 pub const APCS: CallingConvention = .{ .arm_apcs = .{} };
277 /// Deprecated; use `.arm_aapcs`.225 /// Deprecated; use `.arm_aapcs`.
278 pub const AAPCS: NewCallingConvention = .{ .arm_aapcs = .{} };226 pub const AAPCS: CallingConvention = .{ .arm_aapcs = .{} };
279 /// Deprecated; use `.arm_aapcs_vfp`.227 /// Deprecated; use `.arm_aapcs_vfp`.
280 pub const AAPCSVFP: NewCallingConvention = .{ .arm_aapcs_vfp = .{} };228 pub const AAPCSVFP: CallingConvention = .{ .arm_aapcs_vfp = .{} };
281 /// Deprecated; use `.x86_64_sysv`.229 /// Deprecated; use `.x86_64_sysv`.
282 pub const SysV: NewCallingConvention = .{ .x86_64_sysv = .{} };230 pub const SysV: CallingConvention = .{ .x86_64_sysv = .{} };
283 /// Deprecated; use `.x86_64_win`.231 /// Deprecated; use `.x86_64_win`.
284 pub const Win64: NewCallingConvention = .{ .x86_64_win = .{} };232 pub const Win64: CallingConvention = .{ .x86_64_win = .{} };
285 /// Deprecated; use `.kernel`.233 /// Deprecated; use `.kernel`.
286 pub const Kernel: NewCallingConvention = .kernel;234 pub const Kernel: CallingConvention = .kernel;
287 /// Deprecated; use `.spirv_fragment`.235 /// Deprecated; use `.spirv_fragment`.
288 pub const Fragment: NewCallingConvention = .spirv_fragment;236 pub const Fragment: CallingConvention = .spirv_fragment;
289 /// Deprecated; use `.spirv_vertex`.237 /// Deprecated; use `.spirv_vertex`.
290 pub const Vertex: NewCallingConvention = .spirv_vertex;238 pub const Vertex: CallingConvention = .spirv_vertex;
291239
292 /// The default Zig calling convention when neither `export` nor `inline` is specified.240 /// The default Zig calling convention when neither `export` nor `inline` is specified.
293 /// This calling convention makes no guarantees about stack alignment, registers, etc.241 /// This calling convention makes no guarantees about stack alignment, registers, etc.
...@@ -535,9 +483,16 @@ pub const NewCallingConvention = union(enum(u8)) {...@@ -535,9 +483,16 @@ pub const NewCallingConvention = union(enum(u8)) {
535 /// Asserts that `cc` is not `.auto`, `.@"async"`, `.naked`, or `.@"inline"`.483 /// Asserts that `cc` is not `.auto`, `.@"async"`, `.naked`, or `.@"inline"`.
536 pub const archs = std.Target.Cpu.Arch.fromCallconv;484 pub const archs = std.Target.Cpu.Arch.fromCallconv;
537485
538 pub fn eql(a: NewCallingConvention, b: NewCallingConvention) bool {486 pub fn eql(a: CallingConvention, b: CallingConvention) bool {
539 return std.meta.eql(a, b);487 return std.meta.eql(a, b);
540 }488 }
489
490 pub fn withStackAlign(cc: CallingConvention, incoming_stack_alignment: u64) CallingConvention {
491 const tag: CallingConvention.Tag = cc;
492 var result = cc;
493 @field(result, tag).incoming_stack_alignment = incoming_stack_alignment;
494 return result;
495 }
541};496};
542497
543/// This data structure is used by the Zig language code generation and498/// This data structure is used by the Zig language code generation and
lib/std/crypto/25519/field.zig+3-3
...@@ -6,9 +6,9 @@ const NonCanonicalError = crypto.errors.NonCanonicalError;...@@ -6,9 +6,9 @@ const NonCanonicalError = crypto.errors.NonCanonicalError;
6const NotSquareError = crypto.errors.NotSquareError;6const NotSquareError = crypto.errors.NotSquareError;
77
8// Inline conditionally, when it can result in large code generation.8// Inline conditionally, when it can result in large code generation.
9const bloaty_inline = switch (builtin.mode) {9const bloaty_inline: std.builtin.CallingConvention = switch (builtin.mode) {
10 .ReleaseSafe, .ReleaseFast => .Inline,10 .ReleaseSafe, .ReleaseFast => .@"inline",
11 .Debug, .ReleaseSmall => .Unspecified,11 .Debug, .ReleaseSmall => .auto,
12};12};
1313
14pub const Fe = struct {14pub const Fe = struct {
lib/std/os/windows.zig+1-4
...@@ -2824,10 +2824,7 @@ pub const STD_OUTPUT_HANDLE = maxInt(DWORD) - 11 + 1;...@@ -2824,10 +2824,7 @@ pub const STD_OUTPUT_HANDLE = maxInt(DWORD) - 11 + 1;
2824/// The standard error device. Initially, this is the active console screen buffer, CONOUT$.2824/// The standard error device. Initially, this is the active console screen buffer, CONOUT$.
2825pub const STD_ERROR_HANDLE = maxInt(DWORD) - 12 + 1;2825pub const STD_ERROR_HANDLE = maxInt(DWORD) - 12 + 1;
28262826
2827pub const WINAPI: std.builtin.CallingConvention = if (native_arch == .x86)2827pub const WINAPI: std.builtin.CallingConvention = .winapi;
2828 .Stdcall
2829else
2830 .C;
28312828
2832pub const BOOL = c_int;2829pub const BOOL = c_int;
2833pub const BOOLEAN = BYTE;2830pub const BOOLEAN = BYTE;
lib/std/start.zig+4-7
...@@ -55,7 +55,7 @@ comptime {...@@ -55,7 +55,7 @@ comptime {
55 if (builtin.link_libc and @hasDecl(root, "main")) {55 if (builtin.link_libc and @hasDecl(root, "main")) {
56 if (native_arch.isWasm()) {56 if (native_arch.isWasm()) {
57 @export(&mainWithoutEnv, .{ .name = "main" });57 @export(&mainWithoutEnv, .{ .name = "main" });
58 } else if (@typeInfo(@TypeOf(root.main)).@"fn".calling_convention != .C) {58 } else if (!@typeInfo(@TypeOf(root.main)).@"fn".calling_convention.eql(.c)) {
59 @export(&main, .{ .name = "main" });59 @export(&main, .{ .name = "main" });
60 }60 }
61 } else if (native_os == .windows) {61 } else if (native_os == .windows) {
...@@ -102,12 +102,11 @@ fn main2() callconv(.C) c_int {...@@ -102,12 +102,11 @@ fn main2() callconv(.C) c_int {
102 return 0;102 return 0;
103}103}
104104
105fn _start2() callconv(.C) noreturn {105fn _start2() callconv(.withStackAlign(.c, 1)) noreturn {
106 callMain2();106 callMain2();
107}107}
108108
109fn callMain2() noreturn {109fn callMain2() noreturn {
110 @setAlignStack(16);
111 root.main();110 root.main();
112 exit2(0);111 exit2(0);
113}112}
...@@ -428,8 +427,7 @@ fn _start() callconv(.Naked) noreturn {...@@ -428,8 +427,7 @@ fn _start() callconv(.Naked) noreturn {
428 );427 );
429}428}
430429
431fn WinStartup() callconv(std.os.windows.WINAPI) noreturn {430fn WinStartup() callconv(.withStackAlign(.winapi, 1)) noreturn {
432 @setAlignStack(16);
433 if (!builtin.single_threaded and !builtin.link_libc) {431 if (!builtin.single_threaded and !builtin.link_libc) {
434 _ = @import("os/windows/tls.zig");432 _ = @import("os/windows/tls.zig");
435 }433 }
...@@ -439,8 +437,7 @@ fn WinStartup() callconv(std.os.windows.WINAPI) noreturn {...@@ -439,8 +437,7 @@ fn WinStartup() callconv(std.os.windows.WINAPI) noreturn {
439 std.os.windows.ntdll.RtlExitUserProcess(callMain());437 std.os.windows.ntdll.RtlExitUserProcess(callMain());
440}438}
441439
442fn wWinMainCRTStartup() callconv(std.os.windows.WINAPI) noreturn {440fn wWinMainCRTStartup() callconv(.withStackAlign(.winapi, 1)) noreturn {
443 @setAlignStack(16);
444 if (!builtin.single_threaded and !builtin.link_libc) {441 if (!builtin.single_threaded and !builtin.link_libc) {
445 _ = @import("os/windows/tls.zig");442 _ = @import("os/windows/tls.zig");
446 }443 }
src/InternPool.zig+20-20
...@@ -1988,7 +1988,7 @@ pub const Key = union(enum) {...@@ -1988,7 +1988,7 @@ pub const Key = union(enum) {
1988 /// Tells whether a parameter is noalias. See `paramIsNoalias` helper1988 /// Tells whether a parameter is noalias. See `paramIsNoalias` helper
1989 /// method for accessing this.1989 /// method for accessing this.
1990 noalias_bits: u32,1990 noalias_bits: u32,
1991 cc: std.builtin.NewCallingConvention,1991 cc: std.builtin.CallingConvention,
1992 is_var_args: bool,1992 is_var_args: bool,
1993 is_generic: bool,1993 is_generic: bool,
1994 is_noinline: bool,1994 is_noinline: bool,
...@@ -8526,7 +8526,7 @@ pub const GetFuncTypeKey = struct {...@@ -8526,7 +8526,7 @@ pub const GetFuncTypeKey = struct {
8526 comptime_bits: u32 = 0,8526 comptime_bits: u32 = 0,
8527 noalias_bits: u32 = 0,8527 noalias_bits: u32 = 0,
8528 /// `null` means generic.8528 /// `null` means generic.
8529 cc: ?std.builtin.NewCallingConvention = .auto,8529 cc: ?std.builtin.CallingConvention = .auto,
8530 is_var_args: bool = false,8530 is_var_args: bool = false,
8531 is_generic: bool = false,8531 is_generic: bool = false,
8532 is_noinline: bool = false,8532 is_noinline: bool = false,
...@@ -8668,7 +8668,7 @@ pub const GetFuncDeclKey = struct {...@@ -8668,7 +8668,7 @@ pub const GetFuncDeclKey = struct {
8668 rbrace_line: u32,8668 rbrace_line: u32,
8669 lbrace_column: u32,8669 lbrace_column: u32,
8670 rbrace_column: u32,8670 rbrace_column: u32,
8671 cc: ?std.builtin.NewCallingConvention,8671 cc: ?std.builtin.CallingConvention,
8672 is_noinline: bool,8672 is_noinline: bool,
8673};8673};
86748674
...@@ -8733,7 +8733,7 @@ pub const GetFuncDeclIesKey = struct {...@@ -8733,7 +8733,7 @@ pub const GetFuncDeclIesKey = struct {
8733 comptime_bits: u32,8733 comptime_bits: u32,
8734 bare_return_type: Index,8734 bare_return_type: Index,
8735 /// null means generic.8735 /// null means generic.
8736 cc: ?std.builtin.NewCallingConvention,8736 cc: ?std.builtin.CallingConvention,
8737 /// null means generic.8737 /// null means generic.
8738 alignment: ?Alignment,8738 alignment: ?Alignment,
8739 section_is_generic: bool,8739 section_is_generic: bool,
...@@ -8948,7 +8948,7 @@ pub const GetFuncInstanceKey = struct {...@@ -8948,7 +8948,7 @@ pub const GetFuncInstanceKey = struct {
8948 comptime_args: []const Index,8948 comptime_args: []const Index,
8949 noalias_bits: u32,8949 noalias_bits: u32,
8950 bare_return_type: Index,8950 bare_return_type: Index,
8951 cc: std.builtin.NewCallingConvention,8951 cc: std.builtin.CallingConvention,
8952 alignment: Alignment,8952 alignment: Alignment,
8953 section: OptionalNullTerminatedString,8953 section: OptionalNullTerminatedString,
8954 is_noinline: bool,8954 is_noinline: bool,
...@@ -12226,13 +12226,13 @@ pub fn getErrorValueIfExists(ip: *const InternPool, name: NullTerminatedString)...@@ -12226,13 +12226,13 @@ pub fn getErrorValueIfExists(ip: *const InternPool, name: NullTerminatedString)
12226}12226}
1222712227
12228const PackedCallingConvention = packed struct(u18) {12228const PackedCallingConvention = packed struct(u18) {
12229 tag: std.builtin.NewCallingConvention.Tag,12229 tag: std.builtin.CallingConvention.Tag,
12230 /// May be ignored depending on `tag`.12230 /// May be ignored depending on `tag`.
12231 incoming_stack_alignment: Alignment,12231 incoming_stack_alignment: Alignment,
12232 /// Interpretation depends on `tag`.12232 /// Interpretation depends on `tag`.
12233 extra: u4,12233 extra: u4,
1223412234
12235 fn pack(cc: std.builtin.NewCallingConvention) PackedCallingConvention {12235 fn pack(cc: std.builtin.CallingConvention) PackedCallingConvention {
12236 return switch (cc) {12236 return switch (cc) {
12237 inline else => |pl, tag| switch (@TypeOf(pl)) {12237 inline else => |pl, tag| switch (@TypeOf(pl)) {
12238 void => .{12238 void => .{
...@@ -12240,27 +12240,27 @@ const PackedCallingConvention = packed struct(u18) {...@@ -12240,27 +12240,27 @@ const PackedCallingConvention = packed struct(u18) {
12240 .incoming_stack_alignment = .none, // unused12240 .incoming_stack_alignment = .none, // unused
12241 .extra = 0, // unused12241 .extra = 0, // unused
12242 },12242 },
12243 std.builtin.NewCallingConvention.CommonOptions => .{12243 std.builtin.CallingConvention.CommonOptions => .{
12244 .tag = tag,12244 .tag = tag,
12245 .incoming_stack_alignment = .fromByteUnits(pl.incoming_stack_alignment orelse 0),12245 .incoming_stack_alignment = .fromByteUnits(pl.incoming_stack_alignment orelse 0),
12246 .extra = 0, // unused12246 .extra = 0, // unused
12247 },12247 },
12248 std.builtin.NewCallingConvention.X86RegparmOptions => .{12248 std.builtin.CallingConvention.X86RegparmOptions => .{
12249 .tag = tag,12249 .tag = tag,
12250 .incoming_stack_alignment = .fromByteUnits(pl.incoming_stack_alignment orelse 0),12250 .incoming_stack_alignment = .fromByteUnits(pl.incoming_stack_alignment orelse 0),
12251 .extra = pl.register_params,12251 .extra = pl.register_params,
12252 },12252 },
12253 std.builtin.NewCallingConvention.ArmInterruptOptions => .{12253 std.builtin.CallingConvention.ArmInterruptOptions => .{
12254 .tag = tag,12254 .tag = tag,
12255 .incoming_stack_alignment = .fromByteUnits(pl.incoming_stack_alignment orelse 0),12255 .incoming_stack_alignment = .fromByteUnits(pl.incoming_stack_alignment orelse 0),
12256 .extra = @intFromEnum(pl.type),12256 .extra = @intFromEnum(pl.type),
12257 },12257 },
12258 std.builtin.NewCallingConvention.MipsInterruptOptions => .{12258 std.builtin.CallingConvention.MipsInterruptOptions => .{
12259 .tag = tag,12259 .tag = tag,
12260 .incoming_stack_alignment = .fromByteUnits(pl.incoming_stack_alignment orelse 0),12260 .incoming_stack_alignment = .fromByteUnits(pl.incoming_stack_alignment orelse 0),
12261 .extra = @intFromEnum(pl.mode),12261 .extra = @intFromEnum(pl.mode),
12262 },12262 },
12263 std.builtin.NewCallingConvention.RiscvInterruptOptions => .{12263 std.builtin.CallingConvention.RiscvInterruptOptions => .{
12264 .tag = tag,12264 .tag = tag,
12265 .incoming_stack_alignment = .fromByteUnits(pl.incoming_stack_alignment orelse 0),12265 .incoming_stack_alignment = .fromByteUnits(pl.incoming_stack_alignment orelse 0),
12266 .extra = @intFromEnum(pl.level),12266 .extra = @intFromEnum(pl.level),
...@@ -12270,30 +12270,30 @@ const PackedCallingConvention = packed struct(u18) {...@@ -12270,30 +12270,30 @@ const PackedCallingConvention = packed struct(u18) {
12270 };12270 };
12271 }12271 }
1227212272
12273 fn unpack(cc: PackedCallingConvention) std.builtin.NewCallingConvention {12273 fn unpack(cc: PackedCallingConvention) std.builtin.CallingConvention {
12274 @setEvalBranchQuota(400_000);12274 @setEvalBranchQuota(400_000);
12275 return switch (cc.tag) {12275 return switch (cc.tag) {
12276 inline else => |tag| @unionInit(12276 inline else => |tag| @unionInit(
12277 std.builtin.NewCallingConvention,12277 std.builtin.CallingConvention,
12278 @tagName(tag),12278 @tagName(tag),
12279 switch (std.meta.FieldType(std.builtin.NewCallingConvention, tag)) {12279 switch (std.meta.FieldType(std.builtin.CallingConvention, tag)) {
12280 void => {},12280 void => {},
12281 std.builtin.NewCallingConvention.CommonOptions => .{12281 std.builtin.CallingConvention.CommonOptions => .{
12282 .incoming_stack_alignment = cc.incoming_stack_alignment.toByteUnits(),12282 .incoming_stack_alignment = cc.incoming_stack_alignment.toByteUnits(),
12283 },12283 },
12284 std.builtin.NewCallingConvention.X86RegparmOptions => .{12284 std.builtin.CallingConvention.X86RegparmOptions => .{
12285 .incoming_stack_alignment = cc.incoming_stack_alignment.toByteUnits(),12285 .incoming_stack_alignment = cc.incoming_stack_alignment.toByteUnits(),
12286 .register_params = @intCast(cc.extra),12286 .register_params = @intCast(cc.extra),
12287 },12287 },
12288 std.builtin.NewCallingConvention.ArmInterruptOptions => .{12288 std.builtin.CallingConvention.ArmInterruptOptions => .{
12289 .incoming_stack_alignment = cc.incoming_stack_alignment.toByteUnits(),12289 .incoming_stack_alignment = cc.incoming_stack_alignment.toByteUnits(),
12290 .type = @enumFromInt(cc.extra),12290 .type = @enumFromInt(cc.extra),
12291 },12291 },
12292 std.builtin.NewCallingConvention.MipsInterruptOptions => .{12292 std.builtin.CallingConvention.MipsInterruptOptions => .{
12293 .incoming_stack_alignment = cc.incoming_stack_alignment.toByteUnits(),12293 .incoming_stack_alignment = cc.incoming_stack_alignment.toByteUnits(),
12294 .mode = @enumFromInt(cc.extra),12294 .mode = @enumFromInt(cc.extra),
12295 },12295 },
12296 std.builtin.NewCallingConvention.RiscvInterruptOptions => .{12296 std.builtin.CallingConvention.RiscvInterruptOptions => .{
12297 .incoming_stack_alignment = cc.incoming_stack_alignment.toByteUnits(),12297 .incoming_stack_alignment = cc.incoming_stack_alignment.toByteUnits(),
12298 .level = @enumFromInt(cc.extra),12298 .level = @enumFromInt(cc.extra),
12299 },12299 },
src/Sema.zig+21-21
...@@ -2703,9 +2703,9 @@ fn analyzeValueAsCallconv(...@@ -2703,9 +2703,9 @@ fn analyzeValueAsCallconv(
2703 block: *Block,2703 block: *Block,
2704 src: LazySrcLoc,2704 src: LazySrcLoc,
2705 unresolved_val: Value,2705 unresolved_val: Value,
2706) !std.builtin.NewCallingConvention {2706) !std.builtin.CallingConvention {
2707 const resolved_val = try sema.resolveLazyValue(unresolved_val);2707 const resolved_val = try sema.resolveLazyValue(unresolved_val);
2708 return resolved_val.interpret(std.builtin.NewCallingConvention, sema.pt) catch |err| switch (err) {2708 return resolved_val.interpret(std.builtin.CallingConvention, sema.pt) catch |err| switch (err) {
2709 error.OutOfMemory => |e| return e,2709 error.OutOfMemory => |e| return e,
2710 error.UndefinedValue => return sema.failWithUseOfUndef(block, src),2710 error.UndefinedValue => return sema.failWithUseOfUndef(block, src),
2711 error.TypeMismatch => @panic("std.builtin is corrupt"),2711 error.TypeMismatch => @panic("std.builtin is corrupt"),
...@@ -9520,7 +9520,7 @@ fn zirFunc(...@@ -9520,7 +9520,7 @@ fn zirFunc(
9520 // If this instruction has a body, then it's a function declaration, and we decide9520 // If this instruction has a body, then it's a function declaration, and we decide
9521 // the callconv based on whether it is exported. Otherwise, the callconv defaults9521 // the callconv based on whether it is exported. Otherwise, the callconv defaults
9522 // to `.auto`.9522 // to `.auto`.
9523 const cc: std.builtin.NewCallingConvention = if (has_body) cc: {9523 const cc: std.builtin.CallingConvention = if (has_body) cc: {
9524 const func_decl_cau = if (sema.generic_owner != .none) cau: {9524 const func_decl_cau = if (sema.generic_owner != .none) cau: {
9525 const generic_owner_fn = zcu.funcInfo(sema.generic_owner);9525 const generic_owner_fn = zcu.funcInfo(sema.generic_owner);
9526 // The generic owner definitely has a `Cau` for the corresponding function declaration.9526 // The generic owner definitely has a `Cau` for the corresponding function declaration.
...@@ -9686,7 +9686,7 @@ fn handleExternLibName(...@@ -9686,7 +9686,7 @@ fn handleExternLibName(
9686/// These are calling conventions that are confirmed to work with variadic functions.9686/// These are calling conventions that are confirmed to work with variadic functions.
9687/// Any calling conventions not included here are either not yet verified to work with variadic9687/// Any calling conventions not included here are either not yet verified to work with variadic
9688/// functions or there are no more other calling conventions that support variadic functions.9688/// functions or there are no more other calling conventions that support variadic functions.
9689const calling_conventions_supporting_var_args = [_]std.builtin.NewCallingConvention.Tag{9689const calling_conventions_supporting_var_args = [_]std.builtin.CallingConvention.Tag{
9690 .x86_64_sysv,9690 .x86_64_sysv,
9691 .x86_64_win,9691 .x86_64_win,
9692 .x86_sysv,9692 .x86_sysv,
...@@ -9738,12 +9738,12 @@ const calling_conventions_supporting_var_args = [_]std.builtin.NewCallingConvent...@@ -9738,12 +9738,12 @@ const calling_conventions_supporting_var_args = [_]std.builtin.NewCallingConvent
9738 .xtensa_call0,9738 .xtensa_call0,
9739 .xtensa_windowed,9739 .xtensa_windowed,
9740};9740};
9741fn callConvSupportsVarArgs(cc: std.builtin.NewCallingConvention.Tag) bool {9741fn callConvSupportsVarArgs(cc: std.builtin.CallingConvention.Tag) bool {
9742 return for (calling_conventions_supporting_var_args) |supported_cc| {9742 return for (calling_conventions_supporting_var_args) |supported_cc| {
9743 if (cc == supported_cc) return true;9743 if (cc == supported_cc) return true;
9744 } else false;9744 } else false;
9745}9745}
9746fn checkCallConvSupportsVarArgs(sema: *Sema, block: *Block, src: LazySrcLoc, cc: std.builtin.NewCallingConvention.Tag) CompileError!void {9746fn checkCallConvSupportsVarArgs(sema: *Sema, block: *Block, src: LazySrcLoc, cc: std.builtin.CallingConvention.Tag) CompileError!void {
9747 const CallingConventionsSupportingVarArgsList = struct {9747 const CallingConventionsSupportingVarArgsList = struct {
9748 pub fn format(_: @This(), comptime fmt: []const u8, options: std.fmt.FormatOptions, writer: anytype) !void {9748 pub fn format(_: @This(), comptime fmt: []const u8, options: std.fmt.FormatOptions, writer: anytype) !void {
9749 _ = fmt;9749 _ = fmt;
...@@ -9784,7 +9784,7 @@ fn funcCommon(...@@ -9784,7 +9784,7 @@ fn funcCommon(
9784 address_space: ?std.builtin.AddressSpace,9784 address_space: ?std.builtin.AddressSpace,
9785 section: Section,9785 section: Section,
9786 /// null means generic poison9786 /// null means generic poison
9787 cc: ?std.builtin.NewCallingConvention,9787 cc: ?std.builtin.CallingConvention,
9788 /// this might be Type.generic_poison9788 /// this might be Type.generic_poison
9789 bare_return_type: Type,9789 bare_return_type: Type,
9790 var_args: bool,9790 var_args: bool,
...@@ -10141,7 +10141,7 @@ fn finishFunc(...@@ -10141,7 +10141,7 @@ fn finishFunc(
10141 ret_poison: bool,10141 ret_poison: bool,
10142 bare_return_type: Type,10142 bare_return_type: Type,
10143 ret_ty_src: LazySrcLoc,10143 ret_ty_src: LazySrcLoc,
10144 cc_resolved: std.builtin.NewCallingConvention,10144 cc_resolved: std.builtin.CallingConvention,
10145 is_source_decl: bool,10145 is_source_decl: bool,
10146 ret_ty_requires_comptime: bool,10146 ret_ty_requires_comptime: bool,
10147 func_inst: Zir.Inst.Index,10147 func_inst: Zir.Inst.Index,
...@@ -26744,7 +26744,7 @@ fn zirFuncFancy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A...@@ -26744,7 +26744,7 @@ fn zirFuncFancy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
26744 break :blk .{ .explicit = section_name };26744 break :blk .{ .explicit = section_name };
26745 } else .default;26745 } else .default;
2674626746
26747 const cc: ?std.builtin.NewCallingConvention = if (extra.data.bits.has_cc_body) blk: {26747 const cc: ?std.builtin.CallingConvention = if (extra.data.bits.has_cc_body) blk: {
26748 const body_len = sema.code.extra[extra_index];26748 const body_len = sema.code.extra[extra_index];
26749 extra_index += 1;26749 extra_index += 1;
26750 const body = sema.code.bodySlice(extra_index, body_len);26750 const body = sema.code.bodySlice(extra_index, body_len);
...@@ -27253,14 +27253,14 @@ fn zirBuiltinValue(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstD...@@ -27253,14 +27253,14 @@ fn zirBuiltinValue(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstD
27253 ) orelse @panic("std.builtin is corrupt");27253 ) orelse @panic("std.builtin is corrupt");
27254 },27254 },
27255 .calling_convention_inline => {27255 .calling_convention_inline => {
27256 comptime assert(@typeInfo(std.builtin.NewCallingConvention.Tag).@"enum".tag_type == u8);27256 comptime assert(@typeInfo(std.builtin.CallingConvention.Tag).@"enum".tag_type == u8);
27257 const callconv_ty = try sema.getBuiltinType("CallingConvention");27257 const callconv_ty = try sema.getBuiltinType("CallingConvention");
27258 const callconv_tag_ty = callconv_ty.unionTagType(zcu) orelse @panic("std.builtin is corrupt");27258 const callconv_tag_ty = callconv_ty.unionTagType(zcu) orelse @panic("std.builtin is corrupt");
27259 const inline_tag_val = try pt.enumValue(27259 const inline_tag_val = try pt.enumValue(
27260 callconv_tag_ty,27260 callconv_tag_ty,
27261 (try pt.intValue(27261 (try pt.intValue(
27262 Type.u8,27262 Type.u8,
27263 @intFromEnum(std.builtin.NewCallingConvention.@"inline"),27263 @intFromEnum(std.builtin.CallingConvention.@"inline"),
27264 )).toIntern(),27264 )).toIntern(),
27265 );27265 );
27266 return sema.coerce(block, callconv_ty, Air.internedToRef(inline_tag_val.toIntern()), src);27266 return sema.coerce(block, callconv_ty, Air.internedToRef(inline_tag_val.toIntern()), src);
...@@ -30621,8 +30621,8 @@ const InMemoryCoercionResult = union(enum) {...@@ -30621,8 +30621,8 @@ const InMemoryCoercionResult = union(enum) {
30621 };30621 };
3062230622
30623 const CC = struct {30623 const CC = struct {
30624 actual: std.builtin.NewCallingConvention,30624 actual: std.builtin.CallingConvention,
30625 wanted: std.builtin.NewCallingConvention,30625 wanted: std.builtin.CallingConvention,
30626 };30626 };
3062730627
30628 const BitRange = struct {30628 const BitRange = struct {
...@@ -31348,10 +31348,10 @@ fn coerceInMemoryAllowedFns(...@@ -31348,10 +31348,10 @@ fn coerceInMemoryAllowedFns(
3134831348
31349fn callconvCoerceAllowed(31349fn callconvCoerceAllowed(
31350 target: std.Target,31350 target: std.Target,
31351 src_cc: std.builtin.NewCallingConvention,31351 src_cc: std.builtin.CallingConvention,
31352 dest_cc: std.builtin.NewCallingConvention,31352 dest_cc: std.builtin.CallingConvention,
31353) bool {31353) bool {
31354 const Tag = std.builtin.NewCallingConvention.Tag;31354 const Tag = std.builtin.CallingConvention.Tag;
31355 if (@as(Tag, src_cc) != @as(Tag, dest_cc)) return false;31355 if (@as(Tag, src_cc) != @as(Tag, dest_cc)) return false;
3135631356
31357 switch (src_cc) {31357 switch (src_cc) {
...@@ -31364,17 +31364,17 @@ fn callconvCoerceAllowed(...@@ -31364,17 +31364,17 @@ fn callconvCoerceAllowed(
31364 if (dest_stack_align < src_stack_align) return false;31364 if (dest_stack_align < src_stack_align) return false;
31365 }31365 }
31366 switch (@TypeOf(src_data)) {31366 switch (@TypeOf(src_data)) {
31367 void, std.builtin.NewCallingConvention.CommonOptions => {},31367 void, std.builtin.CallingConvention.CommonOptions => {},
31368 std.builtin.NewCallingConvention.X86RegparmOptions => {31368 std.builtin.CallingConvention.X86RegparmOptions => {
31369 if (src_data.register_params != dest_data.register_params) return false;31369 if (src_data.register_params != dest_data.register_params) return false;
31370 },31370 },
31371 std.builtin.NewCallingConvention.ArmInterruptOptions => {31371 std.builtin.CallingConvention.ArmInterruptOptions => {
31372 if (src_data.type != dest_data.type) return false;31372 if (src_data.type != dest_data.type) return false;
31373 },31373 },
31374 std.builtin.NewCallingConvention.MipsInterruptOptions => {31374 std.builtin.CallingConvention.MipsInterruptOptions => {
31375 if (src_data.mode != dest_data.mode) return false;31375 if (src_data.mode != dest_data.mode) return false;
31376 },31376 },
31377 std.builtin.NewCallingConvention.RiscvInterruptOptions => {31377 std.builtin.CallingConvention.RiscvInterruptOptions => {
31378 if (src_data.level != dest_data.level) return false;31378 if (src_data.level != dest_data.level) return false;
31379 },31379 },
31380 else => comptime unreachable,31380 else => comptime unreachable,
src/Type.zig+1-1
...@@ -2493,7 +2493,7 @@ pub fn fnReturnType(ty: Type, zcu: *const Zcu) Type {...@@ -2493,7 +2493,7 @@ pub fn fnReturnType(ty: Type, zcu: *const Zcu) Type {
2493}2493}
24942494
2495/// Asserts the type is a function.2495/// Asserts the type is a function.
2496pub fn fnCallingConvention(ty: Type, zcu: *const Zcu) std.builtin.NewCallingConvention {2496pub fn fnCallingConvention(ty: Type, zcu: *const Zcu) std.builtin.CallingConvention {
2497 return zcu.intern_pool.indexToKey(ty.toIntern()).func_type.cc;2497 return zcu.intern_pool.indexToKey(ty.toIntern()).func_type.cc;
2498}2498}
24992499
src/Zcu.zig+1-1
...@@ -3540,7 +3540,7 @@ pub fn maybeUnresolveIes(zcu: *Zcu, func_index: InternPool.Index) !void {...@@ -3540,7 +3540,7 @@ pub fn maybeUnresolveIes(zcu: *Zcu, func_index: InternPool.Index) !void {
3540 }3540 }
3541}3541}
35423542
3543pub fn callconvSupported(zcu: *Zcu, cc: std.builtin.NewCallingConvention) union(enum) {3543pub fn callconvSupported(zcu: *Zcu, cc: std.builtin.CallingConvention) union(enum) {
3544 ok,3544 ok,
3545 bad_arch: []const std.Target.Cpu.Arch, // value is allowed archs for cc3545 bad_arch: []const std.Target.Cpu.Arch, // value is allowed archs for cc
3546 bad_backend: std.builtin.CompilerBackend, // value is current backend3546 bad_backend: std.builtin.CompilerBackend, // value is current backend
src/arch/riscv64/Lower.zig+1-1
...@@ -6,7 +6,7 @@ link_mode: std.builtin.LinkMode,...@@ -6,7 +6,7 @@ link_mode: std.builtin.LinkMode,
6pic: bool,6pic: bool,
7allocator: Allocator,7allocator: Allocator,
8mir: Mir,8mir: Mir,
9cc: std.builtin.NewCallingConvention,9cc: std.builtin.CallingConvention,
10err_msg: ?*ErrorMsg = null,10err_msg: ?*ErrorMsg = null,
11src_loc: Zcu.LazySrcLoc,11src_loc: Zcu.LazySrcLoc,
12result_insts_len: u8 = undefined,12result_insts_len: u8 = undefined,
src/arch/wasm/CodeGen.zig+3-3
...@@ -1145,7 +1145,7 @@ fn ensureAllocLocal(func: *CodeGen, ty: Type) InnerError!WValue {...@@ -1145,7 +1145,7 @@ fn ensureAllocLocal(func: *CodeGen, ty: Type) InnerError!WValue {
1145/// Memory is owned by the caller.1145/// Memory is owned by the caller.
1146fn genFunctype(1146fn genFunctype(
1147 gpa: Allocator,1147 gpa: Allocator,
1148 cc: std.builtin.NewCallingConvention,1148 cc: std.builtin.CallingConvention,
1149 params: []const InternPool.Index,1149 params: []const InternPool.Index,
1150 return_type: Type,1150 return_type: Type,
1151 pt: Zcu.PerThread,1151 pt: Zcu.PerThread,
...@@ -1408,7 +1408,7 @@ fn resolveCallingConventionValues(func: *CodeGen, fn_ty: Type) InnerError!CallWV...@@ -1408,7 +1408,7 @@ fn resolveCallingConventionValues(func: *CodeGen, fn_ty: Type) InnerError!CallWV
1408 return result;1408 return result;
1409}1409}
14101410
1411fn firstParamSRet(cc: std.builtin.NewCallingConvention, return_type: Type, pt: Zcu.PerThread, target: std.Target) bool {1411fn firstParamSRet(cc: std.builtin.CallingConvention, return_type: Type, pt: Zcu.PerThread, target: std.Target) bool {
1412 switch (cc) {1412 switch (cc) {
1413 .@"inline" => unreachable,1413 .@"inline" => unreachable,
1414 .auto => return isByRef(return_type, pt, target),1414 .auto => return isByRef(return_type, pt, target),
...@@ -1424,7 +1424,7 @@ fn firstParamSRet(cc: std.builtin.NewCallingConvention, return_type: Type, pt: Z...@@ -1424,7 +1424,7 @@ fn firstParamSRet(cc: std.builtin.NewCallingConvention, return_type: Type, pt: Z
14241424
1425/// Lowers a Zig type and its value based on a given calling convention to ensure1425/// Lowers a Zig type and its value based on a given calling convention to ensure
1426/// it matches the ABI.1426/// it matches the ABI.
1427fn lowerArg(func: *CodeGen, cc: std.builtin.NewCallingConvention, ty: Type, value: WValue) !void {1427fn lowerArg(func: *CodeGen, cc: std.builtin.CallingConvention, ty: Type, value: WValue) !void {
1428 if (cc != .wasm_watc) {1428 if (cc != .wasm_watc) {
1429 return func.lowerToStack(value);1429 return func.lowerToStack(value);
1430 }1430 }
src/arch/x86_64/CodeGen.zig+2-2
...@@ -2694,7 +2694,7 @@ fn setFrameLoc(...@@ -2694,7 +2694,7 @@ fn setFrameLoc(
2694 offset.* += self.frame_allocs.items(.abi_size)[frame_i];2694 offset.* += self.frame_allocs.items(.abi_size)[frame_i];
2695}2695}
26962696
2697fn computeFrameLayout(self: *Self, cc: std.builtin.NewCallingConvention) !FrameLayout {2697fn computeFrameLayout(self: *Self, cc: std.builtin.CallingConvention) !FrameLayout {
2698 const frame_allocs_len = self.frame_allocs.len;2698 const frame_allocs_len = self.frame_allocs.len;
2699 try self.frame_locs.resize(self.gpa, frame_allocs_len);2699 try self.frame_locs.resize(self.gpa, frame_allocs_len);
2700 const stack_frame_order = try self.gpa.alloc(FrameIndex, frame_allocs_len - FrameIndex.named_count);2700 const stack_frame_order = try self.gpa.alloc(FrameIndex, frame_allocs_len - FrameIndex.named_count);
...@@ -3006,7 +3006,7 @@ pub fn spillEflagsIfOccupied(self: *Self) !void {...@@ -3006,7 +3006,7 @@ pub fn spillEflagsIfOccupied(self: *Self) !void {
3006 }3006 }
3007}3007}
30083008
3009pub fn spillCallerPreservedRegs(self: *Self, cc: std.builtin.NewCallingConvention) !void {3009pub fn spillCallerPreservedRegs(self: *Self, cc: std.builtin.CallingConvention) !void {
3010 switch (cc) {3010 switch (cc) {
3011 .x86_64_sysv => try self.spillRegisters(abi.getCallerPreservedRegs(.{ .x86_64_sysv = .{} })),3011 .x86_64_sysv => try self.spillRegisters(abi.getCallerPreservedRegs(.{ .x86_64_sysv = .{} })),
3012 .x86_64_win => try self.spillRegisters(abi.getCallerPreservedRegs(.{ .x86_64_win = .{} })),3012 .x86_64_win => try self.spillRegisters(abi.getCallerPreservedRegs(.{ .x86_64_win = .{} })),
src/arch/x86_64/Lower.zig+1-1
...@@ -6,7 +6,7 @@ link_mode: std.builtin.LinkMode,...@@ -6,7 +6,7 @@ link_mode: std.builtin.LinkMode,
6pic: bool,6pic: bool,
7allocator: std.mem.Allocator,7allocator: std.mem.Allocator,
8mir: Mir,8mir: Mir,
9cc: std.builtin.NewCallingConvention,9cc: std.builtin.CallingConvention,
10err_msg: ?*Zcu.ErrorMsg = null,10err_msg: ?*Zcu.ErrorMsg = null,
11src_loc: Zcu.LazySrcLoc,11src_loc: Zcu.LazySrcLoc,
12result_insts_len: u8 = undefined,12result_insts_len: u8 = undefined,
src/arch/x86_64/abi.zig+8-8
...@@ -436,9 +436,9 @@ pub const Win64 = struct {...@@ -436,9 +436,9 @@ pub const Win64 = struct {
436};436};
437437
438pub fn resolveCallingConvention(438pub fn resolveCallingConvention(
439 cc: std.builtin.NewCallingConvention,439 cc: std.builtin.CallingConvention,
440 target: std.Target,440 target: std.Target,
441) std.builtin.NewCallingConvention {441) std.builtin.CallingConvention {
442 return switch (cc) {442 return switch (cc) {
443 .auto => switch (target.os.tag) {443 .auto => switch (target.os.tag) {
444 else => .{ .x86_64_sysv = .{} },444 else => .{ .x86_64_sysv = .{} },
...@@ -448,7 +448,7 @@ pub fn resolveCallingConvention(...@@ -448,7 +448,7 @@ pub fn resolveCallingConvention(
448 };448 };
449}449}
450450
451pub fn getCalleePreservedRegs(cc: std.builtin.NewCallingConvention) []const Register {451pub fn getCalleePreservedRegs(cc: std.builtin.CallingConvention) []const Register {
452 return switch (cc) {452 return switch (cc) {
453 .x86_64_sysv => &SysV.callee_preserved_regs,453 .x86_64_sysv => &SysV.callee_preserved_regs,
454 .x86_64_win => &Win64.callee_preserved_regs,454 .x86_64_win => &Win64.callee_preserved_regs,
...@@ -456,7 +456,7 @@ pub fn getCalleePreservedRegs(cc: std.builtin.NewCallingConvention) []const Regi...@@ -456,7 +456,7 @@ pub fn getCalleePreservedRegs(cc: std.builtin.NewCallingConvention) []const Regi
456 };456 };
457}457}
458458
459pub fn getCallerPreservedRegs(cc: std.builtin.NewCallingConvention) []const Register {459pub fn getCallerPreservedRegs(cc: std.builtin.CallingConvention) []const Register {
460 return switch (cc) {460 return switch (cc) {
461 .x86_64_sysv => &SysV.caller_preserved_regs,461 .x86_64_sysv => &SysV.caller_preserved_regs,
462 .x86_64_win => &Win64.caller_preserved_regs,462 .x86_64_win => &Win64.caller_preserved_regs,
...@@ -464,7 +464,7 @@ pub fn getCallerPreservedRegs(cc: std.builtin.NewCallingConvention) []const Regi...@@ -464,7 +464,7 @@ pub fn getCallerPreservedRegs(cc: std.builtin.NewCallingConvention) []const Regi
464 };464 };
465}465}
466466
467pub fn getCAbiIntParamRegs(cc: std.builtin.NewCallingConvention) []const Register {467pub fn getCAbiIntParamRegs(cc: std.builtin.CallingConvention) []const Register {
468 return switch (cc) {468 return switch (cc) {
469 .x86_64_sysv => &SysV.c_abi_int_param_regs,469 .x86_64_sysv => &SysV.c_abi_int_param_regs,
470 .x86_64_win => &Win64.c_abi_int_param_regs,470 .x86_64_win => &Win64.c_abi_int_param_regs,
...@@ -472,7 +472,7 @@ pub fn getCAbiIntParamRegs(cc: std.builtin.NewCallingConvention) []const Registe...@@ -472,7 +472,7 @@ pub fn getCAbiIntParamRegs(cc: std.builtin.NewCallingConvention) []const Registe
472 };472 };
473}473}
474474
475pub fn getCAbiSseParamRegs(cc: std.builtin.NewCallingConvention) []const Register {475pub fn getCAbiSseParamRegs(cc: std.builtin.CallingConvention) []const Register {
476 return switch (cc) {476 return switch (cc) {
477 .x86_64_sysv => &SysV.c_abi_sse_param_regs,477 .x86_64_sysv => &SysV.c_abi_sse_param_regs,
478 .x86_64_win => &Win64.c_abi_sse_param_regs,478 .x86_64_win => &Win64.c_abi_sse_param_regs,
...@@ -480,7 +480,7 @@ pub fn getCAbiSseParamRegs(cc: std.builtin.NewCallingConvention) []const Registe...@@ -480,7 +480,7 @@ pub fn getCAbiSseParamRegs(cc: std.builtin.NewCallingConvention) []const Registe
480 };480 };
481}481}
482482
483pub fn getCAbiIntReturnRegs(cc: std.builtin.NewCallingConvention) []const Register {483pub fn getCAbiIntReturnRegs(cc: std.builtin.CallingConvention) []const Register {
484 return switch (cc) {484 return switch (cc) {
485 .x86_64_sysv => &SysV.c_abi_int_return_regs,485 .x86_64_sysv => &SysV.c_abi_int_return_regs,
486 .x86_64_win => &Win64.c_abi_int_return_regs,486 .x86_64_win => &Win64.c_abi_int_return_regs,
...@@ -488,7 +488,7 @@ pub fn getCAbiIntReturnRegs(cc: std.builtin.NewCallingConvention) []const Regist...@@ -488,7 +488,7 @@ pub fn getCAbiIntReturnRegs(cc: std.builtin.NewCallingConvention) []const Regist
488 };488 };
489}489}
490490
491pub fn getCAbiSseReturnRegs(cc: std.builtin.NewCallingConvention) []const Register {491pub fn getCAbiSseReturnRegs(cc: std.builtin.CallingConvention) []const Register {
492 return switch (cc) {492 return switch (cc) {
493 .x86_64_sysv => &SysV.c_abi_sse_return_regs,493 .x86_64_sysv => &SysV.c_abi_sse_return_regs,
494 .x86_64_win => &Win64.c_abi_sse_return_regs,494 .x86_64_win => &Win64.c_abi_sse_return_regs,
src/codegen/c.zig+1-1
...@@ -7604,7 +7604,7 @@ fn writeMemoryOrder(w: anytype, order: std.builtin.AtomicOrder) !void {...@@ -7604,7 +7604,7 @@ fn writeMemoryOrder(w: anytype, order: std.builtin.AtomicOrder) !void {
7604 return w.writeAll(toMemoryOrder(order));7604 return w.writeAll(toMemoryOrder(order));
7605}7605}
76067606
7607fn toCallingConvention(cc: std.builtin.NewCallingConvention, zcu: *Zcu) ?[]const u8 {7607fn toCallingConvention(cc: std.builtin.CallingConvention, zcu: *Zcu) ?[]const u8 {
7608 return switch (cc) {7608 return switch (cc) {
7609 .auto, .naked => null,7609 .auto, .naked => null,
7610 .x86_stdcall => "stdcall",7610 .x86_stdcall => "stdcall",
src/codegen/llvm.zig+5-5
...@@ -11595,13 +11595,13 @@ const CallingConventionInfo = struct {...@@ -11595,13 +11595,13 @@ const CallingConventionInfo = struct {
11595 inreg_param_count: u2 = 0,11595 inreg_param_count: u2 = 0,
11596};11596};
1159711597
11598pub fn toLlvmCallConv(cc: std.builtin.NewCallingConvention, target: std.Target) ?CallingConventionInfo {11598pub fn toLlvmCallConv(cc: std.builtin.CallingConvention, target: std.Target) ?CallingConventionInfo {
11599 const llvm_cc = toLlvmCallConvTag(cc, target) orelse return null;11599 const llvm_cc = toLlvmCallConvTag(cc, target) orelse return null;
11600 const incoming_stack_alignment: ?u64, const register_params: u2 = switch (cc) {11600 const incoming_stack_alignment: ?u64, const register_params: u2 = switch (cc) {
11601 inline else => |pl| switch (@TypeOf(pl)) {11601 inline else => |pl| switch (@TypeOf(pl)) {
11602 void => .{ null, 0 },11602 void => .{ null, 0 },
11603 std.builtin.NewCallingConvention.CommonOptions => .{ pl.incoming_stack_alignment, 0 },11603 std.builtin.CallingConvention.CommonOptions => .{ pl.incoming_stack_alignment, 0 },
11604 std.builtin.NewCallingConvention.X86RegparmOptions => .{ pl.incoming_stack_alignment, pl.register_params },11604 std.builtin.CallingConvention.X86RegparmOptions => .{ pl.incoming_stack_alignment, pl.register_params },
11605 else => unreachable,11605 else => unreachable,
11606 },11606 },
11607 };11607 };
...@@ -11615,7 +11615,7 @@ pub fn toLlvmCallConv(cc: std.builtin.NewCallingConvention, target: std.Target)...@@ -11615,7 +11615,7 @@ pub fn toLlvmCallConv(cc: std.builtin.NewCallingConvention, target: std.Target)
11615 .inreg_param_count = register_params,11615 .inreg_param_count = register_params,
11616 };11616 };
11617}11617}
11618fn toLlvmCallConvTag(cc_tag: std.builtin.NewCallingConvention.Tag, target: std.Target) ?Builder.CallConv {11618fn toLlvmCallConvTag(cc_tag: std.builtin.CallingConvention.Tag, target: std.Target) ?Builder.CallConv {
11619 if (target.defaultCCallingConvention()) |default_c| {11619 if (target.defaultCCallingConvention()) |default_c| {
11620 if (cc_tag == default_c) {11620 if (cc_tag == default_c) {
11621 return .ccc;11621 return .ccc;
...@@ -12371,7 +12371,7 @@ fn iterateParamTypes(object: *Object, fn_info: InternPool.Key.FuncType) ParamTyp...@@ -12371,7 +12371,7 @@ fn iterateParamTypes(object: *Object, fn_info: InternPool.Key.FuncType) ParamTyp
12371}12371}
1237212372
12373fn ccAbiPromoteInt(12373fn ccAbiPromoteInt(
12374 cc: std.builtin.NewCallingConvention,12374 cc: std.builtin.CallingConvention,
12375 zcu: *Zcu,12375 zcu: *Zcu,
12376 ty: Type,12376 ty: Type,
12377) ?std.builtin.Signedness {12377) ?std.builtin.Signedness {
src/link/Coff.zig+2-2
...@@ -1485,12 +1485,12 @@ pub fn updateExports(...@@ -1485,12 +1485,12 @@ pub fn updateExports(
1485 const exported_ty = exported_nav.typeOf(ip);1485 const exported_ty = exported_nav.typeOf(ip);
1486 if (!ip.isFunctionType(exported_ty)) continue;1486 if (!ip.isFunctionType(exported_ty)) continue;
1487 const c_cc = target.defaultCCallingConvention().?;1487 const c_cc = target.defaultCCallingConvention().?;
1488 const winapi_cc: std.builtin.NewCallingConvention = switch (target.cpu.arch) {1488 const winapi_cc: std.builtin.CallingConvention = switch (target.cpu.arch) {
1489 .x86 => .{ .x86_stdcall = .{} },1489 .x86 => .{ .x86_stdcall = .{} },
1490 else => c_cc,1490 else => c_cc,
1491 };1491 };
1492 const exported_cc = Type.fromInterned(exported_ty).fnCallingConvention(zcu);1492 const exported_cc = Type.fromInterned(exported_ty).fnCallingConvention(zcu);
1493 const CcTag = std.builtin.NewCallingConvention.Tag;1493 const CcTag = std.builtin.CallingConvention.Tag;
1494 if (@as(CcTag, exported_cc) == @as(CcTag, c_cc) and exp.opts.name.eqlSlice("main", ip) and comp.config.link_libc) {1494 if (@as(CcTag, exported_cc) == @as(CcTag, c_cc) and exp.opts.name.eqlSlice("main", ip) and comp.config.link_libc) {
1495 zcu.stage1_flags.have_c_main = true;1495 zcu.stage1_flags.have_c_main = true;
1496 } else if (@as(CcTag, exported_cc) == @as(CcTag, winapi_cc) and target.os.tag == .windows) {1496 } else if (@as(CcTag, exported_cc) == @as(CcTag, winapi_cc) and target.os.tag == .windows) {
src/link/Dwarf.zig+1-1
...@@ -3400,7 +3400,7 @@ fn updateType(...@@ -3400,7 +3400,7 @@ fn updateType(
3400 try wip_nav.strp(name);3400 try wip_nav.strp(name);
3401 const cc: DW.CC = cc: {3401 const cc: DW.CC = cc: {
3402 if (zcu.getTarget().defaultCCallingConvention()) |cc| {3402 if (zcu.getTarget().defaultCCallingConvention()) |cc| {
3403 if (@as(std.builtin.NewCallingConvention.Tag, cc) == func_type.cc) {3403 if (@as(std.builtin.CallingConvention.Tag, cc) == func_type.cc) {
3404 break :cc .normal;3404 break :cc .normal;
3405 }3405 }
3406 }3406 }
src/target.zig+1-1
...@@ -544,7 +544,7 @@ pub fn compilerRtIntAbbrev(bits: u16) []const u8 {...@@ -544,7 +544,7 @@ pub fn compilerRtIntAbbrev(bits: u16) []const u8 {
544 };544 };
545}545}
546546
547pub fn fnCallConvAllowsZigTypes(cc: std.builtin.NewCallingConvention) bool {547pub fn fnCallConvAllowsZigTypes(cc: std.builtin.CallingConvention) bool {
548 return switch (cc) {548 return switch (cc) {
549 .auto, .@"async", .@"inline" => true,549 .auto, .@"async", .@"inline" => true,
550 // For now we want to authorize PTX kernel to use zig objects, even if550 // For now we want to authorize PTX kernel to use zig objects, even if