diff options
12 files changed, 78 insertions, 49 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, diff --git a/test/cases/compile_errors/stage1/obj/bogus_compile_var.zig b/test/cases/compile_errors/bogus_compile_var.zig index 845d943c7d..28d8b1dba5 100644 --- a/test/cases/compile_errors/stage1/obj/bogus_compile_var.zig +++ b/test/cases/compile_errors/bogus_compile_var.zig @@ -2,7 +2,7 @@ const x = @import("builtin").bogus; export fn entry() usize { return @sizeOf(@TypeOf(x)); } // error -// backend=stage1 +// backend=stage2 // target=native // -// tmp.zig:1:29: error: container 'builtin' has no member called 'bogus' +// :1:29: error: struct 'builtin.builtin' has no member named 'bogus' diff --git a/test/cases/compile_errors/callconv_apcs_aapcs_aapcsvfp_on_unsupported_platform.zig b/test/cases/compile_errors/callconv_apcs_aapcs_aapcsvfp_on_unsupported_platform.zig new file mode 100644 index 0000000000..cc6fc59a1a --- /dev/null +++ b/test/cases/compile_errors/callconv_apcs_aapcs_aapcsvfp_on_unsupported_platform.zig @@ -0,0 +1,11 @@ +export fn entry1() callconv(.APCS) void {} +export fn entry2() callconv(.AAPCS) void {} +export fn entry3() callconv(.AAPCSVFP) void {} + +// error +// backend=stage2 +// target=x86_64-linux-none +// +// :1:30: error: callconv 'APCS' is only available on ARM, not x86_64 +// :2:30: error: callconv 'AAPCS' is only available on ARM, not x86_64 +// :3:30: error: callconv 'AAPCSVFP' is only available on ARM, not x86_64 diff --git a/test/cases/compile_errors/callconv_interrupt_on_unsupported_platform.zig b/test/cases/compile_errors/callconv_interrupt_on_unsupported_platform.zig new file mode 100644 index 0000000000..5f11fdcfa8 --- /dev/null +++ b/test/cases/compile_errors/callconv_interrupt_on_unsupported_platform.zig @@ -0,0 +1,7 @@ +export fn entry() callconv(.Interrupt) void {} + +// error +// backend=stage2 +// target=aarch64-linux-none +// +// :1:29: error: callconv 'Interrupt' is only available on i386, x86_64, AVR, and MSP430, not aarch64 diff --git a/test/cases/compile_errors/callconv_signal_on_unsupported_platform.zig b/test/cases/compile_errors/callconv_signal_on_unsupported_platform.zig new file mode 100644 index 0000000000..9233655e35 --- /dev/null +++ b/test/cases/compile_errors/callconv_signal_on_unsupported_platform.zig @@ -0,0 +1,7 @@ +export fn entry() callconv(.Signal) void {} + +// error +// backend=stage2 +// target=x86_64-linux-none +// +// :1:29: error: callconv 'Signal' is only available on AVR, not x86_64 diff --git a/test/cases/compile_errors/stage1/obj/callconv_stdcall_fastcall_thiscall_on_unsupported_platform-0.zig b/test/cases/compile_errors/callconv_stdcall_fastcall_thiscall_on_unsupported_platform.zig index f4994107cd..d22fd13e8a 100644 --- a/test/cases/compile_errors/stage1/obj/callconv_stdcall_fastcall_thiscall_on_unsupported_platform-0.zig +++ b/test/cases/compile_errors/callconv_stdcall_fastcall_thiscall_on_unsupported_platform.zig @@ -15,9 +15,9 @@ export fn entry3() void { } // error -// backend=stage1 +// backend=stage2 // target=x86_64-linux-none // -// tmp.zig:1:27: error: callconv 'Stdcall' is only available on x86, not x86_64 -// tmp.zig:2:27: error: callconv 'Fastcall' is only available on x86, not x86_64 -// tmp.zig:3:27: error: callconv 'Thiscall' is only available on x86, not x86_64 +// :1:28: error: callconv 'Stdcall' is only available on i386, not x86_64 +// :2:28: error: callconv 'Fastcall' is only available on i386, not x86_64 +// :3:28: error: callconv 'Thiscall' is only available on i386, not x86_64 diff --git a/test/cases/compile_errors/callconv_vectorcall_on_unsupported_platform.zig b/test/cases/compile_errors/callconv_vectorcall_on_unsupported_platform.zig new file mode 100644 index 0000000000..9c231a6ea8 --- /dev/null +++ b/test/cases/compile_errors/callconv_vectorcall_on_unsupported_platform.zig @@ -0,0 +1,7 @@ +export fn entry() callconv(.Vectorcall) void {} + +// error +// backend=stage2 +// target=x86_64-linux-none +// +// :1:29: error: callconv 'Vectorcall' is only available on i386 and AArch64, not x86_64 diff --git a/test/cases/compile_errors/stage1/obj/callconv_apcs_aapcs_aapcsvfp_on_unsupported_platform.zig b/test/cases/compile_errors/stage1/obj/callconv_apcs_aapcs_aapcsvfp_on_unsupported_platform.zig deleted file mode 100644 index fa06287803..0000000000 --- a/test/cases/compile_errors/stage1/obj/callconv_apcs_aapcs_aapcsvfp_on_unsupported_platform.zig +++ /dev/null @@ -1,11 +0,0 @@ -export fn entry1() callconv(.APCS) void {} -export fn entry2() callconv(.AAPCS) void {} -export fn entry3() callconv(.AAPCSVFP) void {} - -// error -// backend=stage1 -// target=x86_64-linux-none -// -// tmp.zig:1:29: error: callconv 'APCS' is only available on ARM, not x86_64 -// tmp.zig:2:29: error: callconv 'AAPCS' is only available on ARM, not x86_64 -// tmp.zig:3:29: error: callconv 'AAPCSVFP' is only available on ARM, not x86_64 diff --git a/test/cases/compile_errors/stage1/obj/callconv_interrupt_on_unsupported_platform.zig b/test/cases/compile_errors/stage1/obj/callconv_interrupt_on_unsupported_platform.zig deleted file mode 100644 index 8304fb90c1..0000000000 --- a/test/cases/compile_errors/stage1/obj/callconv_interrupt_on_unsupported_platform.zig +++ /dev/null @@ -1,7 +0,0 @@ -export fn entry() callconv(.Interrupt) void {} - -// error -// backend=stage1 -// target=aarch64-linux-none -// -// tmp.zig:1:28: error: callconv 'Interrupt' is only available on x86, x86_64, AVR, and MSP430, not aarch64 diff --git a/test/cases/compile_errors/stage1/obj/callconv_signal_on_unsupported_platform.zig b/test/cases/compile_errors/stage1/obj/callconv_signal_on_unsupported_platform.zig deleted file mode 100644 index 4b19b188fd..0000000000 --- a/test/cases/compile_errors/stage1/obj/callconv_signal_on_unsupported_platform.zig +++ /dev/null @@ -1,7 +0,0 @@ -export fn entry() callconv(.Signal) void {} - -// error -// backend=stage1 -// target=x86_64-linux-none -// -// tmp.zig:1:28: error: callconv 'Signal' is only available on AVR, not x86_64 diff --git a/test/cases/compile_errors/stage1/obj/callconv_stdcall_fastcall_thiscall_on_unsupported_platform-1.zig b/test/cases/compile_errors/stage1/obj/callconv_stdcall_fastcall_thiscall_on_unsupported_platform-1.zig deleted file mode 100644 index aa23f9ae51..0000000000 --- a/test/cases/compile_errors/stage1/obj/callconv_stdcall_fastcall_thiscall_on_unsupported_platform-1.zig +++ /dev/null @@ -1,11 +0,0 @@ -export fn entry1() callconv(.Stdcall) void {} -export fn entry2() callconv(.Fastcall) void {} -export fn entry3() callconv(.Thiscall) void {} - -// error -// backend=stage1 -// target=x86_64-linux-none -// -// tmp.zig:1:29: error: callconv 'Stdcall' is only available on x86, not x86_64 -// tmp.zig:2:29: error: callconv 'Fastcall' is only available on x86, not x86_64 -// tmp.zig:3:29: error: callconv 'Thiscall' is only available on x86, not x86_64 diff --git a/test/cases/compile_errors/stage1/obj/callconv_vectorcall_on_unsupported_platform.zig b/test/cases/compile_errors/stage1/obj/callconv_vectorcall_on_unsupported_platform.zig deleted file mode 100644 index e60e6ab42c..0000000000 --- a/test/cases/compile_errors/stage1/obj/callconv_vectorcall_on_unsupported_platform.zig +++ /dev/null @@ -1,7 +0,0 @@ -export fn entry() callconv(.Vectorcall) void {} - -// error -// backend=stage1 -// target=x86_64-linux-none -// -// tmp.zig:1:28: error: callconv 'Vectorcall' is only available on x86 and AArch64, not x86_64 |
