authorgravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2024-10-17 09:09:35+01:00
committergravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2024-10-19 19:46:07+01:00
log8d5ac6bdeaef032b2beaeea4bfa4a5bfac9b8263
tree1a2192b257026c9af4059436e31f68bbb0d5b47e
parent73f4c680054a1a4e067f0719676f61f175d81a13
signaturelock-open Commit is signed but in an unrecognized format.

Sema: add and improve some callconv compile errors


7 files changed, 25 insertions(+), 13 deletions(-)

src/Sema.zig+15-3
...@@ -10195,6 +10195,18 @@ fn finishFunc(...@@ -10195,6 +10195,18 @@ fn finishFunc(
10195 return sema.failWithOwnedErrorMsg(block, msg);10195 return sema.failWithOwnedErrorMsg(block, msg);
10196 }10196 }
1019710197
10198 validate_incoming_stack_align: {
10199 const a: u64 = switch (cc_resolved) {
10200 inline else => |payload| if (@TypeOf(payload) != void and @hasField(@TypeOf(payload), "incoming_stack_alignment"))
10201 payload.incoming_stack_alignment orelse break :validate_incoming_stack_align
10202 else
10203 break :validate_incoming_stack_align,
10204 };
10205 if (!std.math.isPowerOfTwo(a)) {
10206 return sema.fail(block, cc_src, "calling convention incoming stack alignment '{d}' is not a power of two", .{a});
10207 }
10208 }
10209
10198 switch (cc_resolved) {10210 switch (cc_resolved) {
10199 .x86_64_interrupt,10211 .x86_64_interrupt,
10200 .x86_interrupt,10212 .x86_interrupt,
...@@ -10211,7 +10223,7 @@ fn finishFunc(...@@ -10211,7 +10223,7 @@ fn finishFunc(
10211 return sema.fail(block, ret_ty_src, "function with calling convention '{s}' must return 'void' or 'noreturn'", .{@tagName(cc_resolved)});10223 return sema.fail(block, ret_ty_src, "function with calling convention '{s}' must return 'void' or 'noreturn'", .{@tagName(cc_resolved)});
10212 },10224 },
10213 .@"inline" => if (is_noinline) {10225 .@"inline" => if (is_noinline) {
10214 return sema.fail(block, cc_src, "'noinline' function cannot have callconv 'inline'", .{});10226 return sema.fail(block, cc_src, "'noinline' function cannot have calling convention 'inline'", .{});
10215 },10227 },
10216 else => {},10228 else => {},
10217 }10229 }
...@@ -10231,12 +10243,12 @@ fn finishFunc(...@@ -10231,12 +10243,12 @@ fn finishFunc(
10231 }10243 }
10232 }10244 }
10233 };10245 };
10234 return sema.fail(block, cc_src, "callconv '{s}' only available on architectures {}", .{10246 return sema.fail(block, cc_src, "calling convention '{s}' only available on architectures {}", .{
10235 @tagName(cc_resolved),10247 @tagName(cc_resolved),
10236 ArchListFormatter{ .archs = allowed_archs },10248 ArchListFormatter{ .archs = allowed_archs },
10237 });10249 });
10238 },10250 },
10239 .bad_backend => |bad_backend| return sema.fail(block, cc_src, "callconv '{s}' not supported by compiler backend '{s}'", .{10251 .bad_backend => |bad_backend| return sema.fail(block, cc_src, "calling convention '{s}' not supported by compiler backend '{s}'", .{
10240 @tagName(cc_resolved),10252 @tagName(cc_resolved),
10241 @tagName(bad_backend),10253 @tagName(bad_backend),
10242 }),10254 }),
test/cases/compile_errors/callconv_apcs_aapcs_aapcsvfp_on_unsupported_platform.zig+3-3
...@@ -5,6 +5,6 @@ export fn entry3() callconv(.AAPCSVFP) void {}...@@ -5,6 +5,6 @@ export fn entry3() callconv(.AAPCSVFP) void {}
5// error5// error
6// target=x86_64-linux-none6// target=x86_64-linux-none
7//7//
8// :1:30: error: callconv 'arm_apcs' only available on architectures 'arm', 'armeb', 'thumb', 'thumbeb'8// :1:30: error: calling convention 'arm_apcs' only available on architectures 'arm', 'armeb', 'thumb', 'thumbeb'
9// :2:30: error: callconv 'arm_aapcs' only available on architectures 'arm', 'armeb', 'thumb', 'thumbeb'9// :2:30: error: calling convention 'arm_aapcs' only available on architectures 'arm', 'armeb', 'thumb', 'thumbeb'
10// :3:30: error: callconv 'arm_aapcs_vfp' only available on architectures 'arm', 'armeb', 'thumb', 'thumbeb'10// :3:30: error: calling convention 'arm_aapcs_vfp' only available on architectures 'arm', 'armeb', 'thumb', 'thumbeb'
test/cases/compile_errors/callconv_interrupt_on_unsupported_platform.zig+1-1
...@@ -4,4 +4,4 @@ export fn entry() callconv(.Interrupt) void {}...@@ -4,4 +4,4 @@ export fn entry() callconv(.Interrupt) void {}
4// backend=stage24// backend=stage2
5// target=aarch64-linux-none5// target=aarch64-linux-none
6//6//
7// :1:29: error: callconv 'Interrupt' is only available on x86, x86_64, AVR, and MSP430, not aarch647// :1:29: error: calling convention 'Interrupt' is only available on x86, x86_64, AVR, and MSP430, not aarch64
test/cases/compile_errors/callconv_signal_on_unsupported_platform.zig+1-1
...@@ -4,4 +4,4 @@ export fn entry() callconv(.avr_signal) void {}...@@ -4,4 +4,4 @@ export fn entry() callconv(.avr_signal) void {}
4// backend=stage24// backend=stage2
5// target=x86_64-linux-none5// target=x86_64-linux-none
6//6//
7// :1:29: error: callconv 'avr_signal' only available on architectures 'avr'7// :1:29: error: calling convention 'avr_signal' only available on architectures 'avr'
test/cases/compile_errors/callconv_stdcall_fastcall_thiscall_on_unsupported_platform.zig+3-3
...@@ -18,6 +18,6 @@ export fn entry3() void {...@@ -18,6 +18,6 @@ export fn entry3() void {
18// backend=stage218// backend=stage2
19// target=x86_64-linux-none19// target=x86_64-linux-none
20//20//
21// :1:28: error: callconv 'x86_stdcall' only available on architectures 'x86'21// :1:28: error: calling convention 'x86_stdcall' only available on architectures 'x86'
22// :2:28: error: callconv 'x86_fastcall' only available on architectures 'x86'22// :2:28: error: calling convention 'x86_fastcall' only available on architectures 'x86'
23// :3:28: error: callconv 'x86_thiscall' only available on architectures 'x86'23// :3:28: error: calling convention 'x86_thiscall' only available on architectures 'x86'
test/cases/compile_errors/invalid_func_for_callconv.zig+1-1
...@@ -16,4 +16,4 @@ export fn signal_ret() callconv(.Signal) noreturn {}...@@ -16,4 +16,4 @@ export fn signal_ret() callconv(.Signal) noreturn {}
16// :3:51: error: 'x86_64_interrupt' calling convention supports up to 2 parameters, found 316// :3:51: error: 'x86_64_interrupt' calling convention supports up to 2 parameters, found 3
17// :4:69: error: function with calling convention 'x86_64_interrupt' must return 'void' or 'noreturn'17// :4:69: error: function with calling convention 'x86_64_interrupt' must return 'void' or 'noreturn'
18// :8:24: error: parameters are not allowed with 'avr_signal' calling convention18// :8:24: error: parameters are not allowed with 'avr_signal' calling convention
19// :9:34: error: callconv 'avr_signal' only available on architectures 'avr'19// :9:34: error: calling convention 'avr_signal' only available on architectures 'avr'
test/cases/compile_errors/noinline_fn_cc_inline.zig+1-1
...@@ -8,4 +8,4 @@ comptime {...@@ -8,4 +8,4 @@ comptime {
8// backend=stage28// backend=stage2
9// target=native9// target=native
10//10//
11// :1:29: error: 'noinline' function cannot have callconv 'inline'11// :1:29: error: 'noinline' function cannot have calling convention 'inline'