Skip to content

Commit

Permalink
Sema: add and improve some callconv compile errors
Browse files Browse the repository at this point in the history
  • Loading branch information
mlugg committed Oct 19, 2024
1 parent 73f4c68 commit 8d5ac6b
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 13 deletions.
18 changes: 15 additions & 3 deletions src/Sema.zig
Original file line number Diff line number Diff line change
Expand Up @@ -10195,6 +10195,18 @@ fn finishFunc(
return sema.failWithOwnedErrorMsg(block, msg);
}

validate_incoming_stack_align: {
const a: u64 = switch (cc_resolved) {
inline else => |payload| if (@TypeOf(payload) != void and @hasField(@TypeOf(payload), "incoming_stack_alignment"))
payload.incoming_stack_alignment orelse break :validate_incoming_stack_align
else
break :validate_incoming_stack_align,
};
if (!std.math.isPowerOfTwo(a)) {
return sema.fail(block, cc_src, "calling convention incoming stack alignment '{d}' is not a power of two", .{a});
}
}

switch (cc_resolved) {
.x86_64_interrupt,
.x86_interrupt,
Expand All @@ -10211,7 +10223,7 @@ fn finishFunc(
return sema.fail(block, ret_ty_src, "function with calling convention '{s}' must return 'void' or 'noreturn'", .{@tagName(cc_resolved)});
},
.@"inline" => if (is_noinline) {
return sema.fail(block, cc_src, "'noinline' function cannot have callconv 'inline'", .{});
return sema.fail(block, cc_src, "'noinline' function cannot have calling convention 'inline'", .{});
},
else => {},
}
Expand All @@ -10231,12 +10243,12 @@ fn finishFunc(
}
}
};
return sema.fail(block, cc_src, "callconv '{s}' only available on architectures {}", .{
return sema.fail(block, cc_src, "calling convention '{s}' only available on architectures {}", .{
@tagName(cc_resolved),
ArchListFormatter{ .archs = allowed_archs },
});
},
.bad_backend => |bad_backend| return sema.fail(block, cc_src, "callconv '{s}' not supported by compiler backend '{s}'", .{
.bad_backend => |bad_backend| return sema.fail(block, cc_src, "calling convention '{s}' not supported by compiler backend '{s}'", .{
@tagName(cc_resolved),
@tagName(bad_backend),
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ export fn entry3() callconv(.AAPCSVFP) void {}
// error
// target=x86_64-linux-none
//
// :1:30: error: callconv 'arm_apcs' only available on architectures 'arm', 'armeb', 'thumb', 'thumbeb'
// :2:30: error: callconv 'arm_aapcs' only available on architectures 'arm', 'armeb', 'thumb', 'thumbeb'
// :3:30: error: callconv 'arm_aapcs_vfp' only available on architectures 'arm', 'armeb', 'thumb', 'thumbeb'
// :1:30: error: calling convention 'arm_apcs' only available on architectures 'arm', 'armeb', 'thumb', 'thumbeb'
// :2:30: error: calling convention 'arm_aapcs' only available on architectures 'arm', 'armeb', 'thumb', 'thumbeb'
// :3:30: error: calling convention 'arm_aapcs_vfp' only available on architectures 'arm', 'armeb', 'thumb', 'thumbeb'
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ export fn entry() callconv(.Interrupt) void {}
// backend=stage2
// target=aarch64-linux-none
//
// :1:29: error: callconv 'Interrupt' is only available on x86, x86_64, AVR, and MSP430, not aarch64
// :1:29: error: calling convention 'Interrupt' is only available on x86, x86_64, AVR, and MSP430, not aarch64
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ export fn entry() callconv(.avr_signal) void {}
// backend=stage2
// target=x86_64-linux-none
//
// :1:29: error: callconv 'avr_signal' only available on architectures 'avr'
// :1:29: error: calling convention 'avr_signal' only available on architectures 'avr'
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ export fn entry3() void {
// backend=stage2
// target=x86_64-linux-none
//
// :1:28: error: callconv 'x86_stdcall' only available on architectures 'x86'
// :2:28: error: callconv 'x86_fastcall' only available on architectures 'x86'
// :3:28: error: callconv 'x86_thiscall' only available on architectures 'x86'
// :1:28: error: calling convention 'x86_stdcall' only available on architectures 'x86'
// :2:28: error: calling convention 'x86_fastcall' only available on architectures 'x86'
// :3:28: error: calling convention 'x86_thiscall' only available on architectures 'x86'
2 changes: 1 addition & 1 deletion test/cases/compile_errors/invalid_func_for_callconv.zig
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ export fn signal_ret() callconv(.Signal) noreturn {}
// :3:51: error: 'x86_64_interrupt' calling convention supports up to 2 parameters, found 3
// :4:69: error: function with calling convention 'x86_64_interrupt' must return 'void' or 'noreturn'
// :8:24: error: parameters are not allowed with 'avr_signal' calling convention
// :9:34: error: callconv 'avr_signal' only available on architectures 'avr'
// :9:34: error: calling convention 'avr_signal' only available on architectures 'avr'
2 changes: 1 addition & 1 deletion test/cases/compile_errors/noinline_fn_cc_inline.zig
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ comptime {
// backend=stage2
// target=native
//
// :1:29: error: 'noinline' function cannot have callconv 'inline'
// :1:29: error: 'noinline' function cannot have calling convention 'inline'

0 comments on commit 8d5ac6b

Please sign in to comment.