aboutsummaryrefslogtreecommitdiff
path: root/src/Sema.zig
diff options
context:
space:
mode:
authorVeikka Tuominen <git@vexu.eu>2022-06-30 16:39:54 +0300
committerVeikka Tuominen <git@vexu.eu>2022-07-01 10:22:25 +0300
commit3014a0d5f1dcbcfdcec3852ffd54f3c589fe3e83 (patch)
tree8e6311a666306be796683feda8b22411752a4f36 /src/Sema.zig
parent6d24c40b6e79176b05ec735adcecfd346b03f059 (diff)
downloadzig-3014a0d5f1dcbcfdcec3852ffd54f3c589fe3e83.tar.gz
zig-3014a0d5f1dcbcfdcec3852ffd54f3c589fe3e83.zip
Sema: validate callconv
Diffstat (limited to 'src/Sema.zig')
-rw-r--r--src/Sema.zig40
1 files changed, 40 insertions, 0 deletions
diff --git a/src/Sema.zig b/src/Sema.zig
index 08372bf7b3..0d568f8b38 100644
--- a/src/Sema.zig
+++ b/src/Sema.zig
@@ -7007,6 +7007,7 @@ fn funcCommon(
noalias_bits: u32,
) CompileError!Air.Inst.Ref {
const ret_ty_src: LazySrcLoc = .{ .node_offset_fn_type_ret_ty = src_node_offset };
+ const cc_src: LazySrcLoc = .{ .node_offset_fn_type_cc = src_node_offset };
var is_generic = bare_return_type.tag() == .generic_poison or
alignment == null or
@@ -7109,6 +7110,45 @@ fn funcCommon(
const cc_workaround = cc orelse .Unspecified;
const align_workaround = alignment orelse 0;
+ const arch = sema.mod.getTarget().cpu.arch;
+ if (switch (cc_workaround) {
+ .Unspecified, .C, .Naked, .Async, .Inline => null,
+ .Interrupt => switch (arch) {
+ .i386, .x86_64, .avr, .msp430 => null,
+ else => @as([]const u8, "i386, x86_64, AVR, and MSP430"),
+ },
+ .Signal => switch (arch) {
+ .avr => null,
+ else => @as([]const u8, "AVR"),
+ },
+ .Stdcall, .Fastcall, .Thiscall => switch (arch) {
+ .i386 => null,
+ else => @as([]const u8, "i386"),
+ },
+ .Vectorcall => switch (arch) {
+ .i386, .aarch64, .aarch64_be, .aarch64_32 => null,
+ else => @as([]const u8, "i386 and AArch64"),
+ },
+ .APCS, .AAPCS, .AAPCSVFP => switch (arch) {
+ .arm, .armeb, .aarch64, .aarch64_be, .aarch64_32 => null,
+ else => @as([]const u8, "ARM"),
+ },
+ .SysV, .Win64 => switch (arch) {
+ .x86_64 => null,
+ else => @as([]const u8, "x86_64"),
+ },
+ .PtxKernel => switch (arch) {
+ .nvptx, .nvptx64 => null,
+ else => @as([]const u8, "nvptx and nvptx64"),
+ },
+ }) |allowed_platform| {
+ return sema.fail(block, cc_src, "callconv '{s}' is only available on {s}, not {s}", .{
+ @tagName(cc_workaround),
+ allowed_platform,
+ @tagName(arch),
+ });
+ }
+
break :fn_ty try Type.Tag.function.create(sema.arena, .{
.param_types = param_types,
.comptime_params = comptime_params.ptr,