authorgravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2022-06-30 16:39:54+03:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2022-07-01 10:22:25+03:00
log3014a0d5f1dcbcfdcec3852ffd54f3c589fe3e83
tree8e6311a666306be796683feda8b22411752a4f36
parent6d24c40b6e79176b05ec735adcecfd346b03f059

Sema: validate callconv


14 files changed, 103 insertions(+), 74 deletions(-)

src/Sema.zig+40
...@@ -7007,6 +7007,7 @@ fn funcCommon(...@@ -7007,6 +7007,7 @@ fn funcCommon(
7007 noalias_bits: u32,7007 noalias_bits: u32,
7008) CompileError!Air.Inst.Ref {7008) CompileError!Air.Inst.Ref {
7009 const ret_ty_src: LazySrcLoc = .{ .node_offset_fn_type_ret_ty = src_node_offset };7009 const ret_ty_src: LazySrcLoc = .{ .node_offset_fn_type_ret_ty = src_node_offset };
7010 const cc_src: LazySrcLoc = .{ .node_offset_fn_type_cc = src_node_offset };
70107011
7011 var is_generic = bare_return_type.tag() == .generic_poison or7012 var is_generic = bare_return_type.tag() == .generic_poison or
7012 alignment == null or7013 alignment == null or
...@@ -7109,6 +7110,45 @@ fn funcCommon(...@@ -7109,6 +7110,45 @@ fn funcCommon(
7109 const cc_workaround = cc orelse .Unspecified;7110 const cc_workaround = cc orelse .Unspecified;
7110 const align_workaround = alignment orelse 0;7111 const align_workaround = alignment orelse 0;
71117112
7113 const arch = sema.mod.getTarget().cpu.arch;
7114 if (switch (cc_workaround) {
7115 .Unspecified, .C, .Naked, .Async, .Inline => null,
7116 .Interrupt => switch (arch) {
7117 .i386, .x86_64, .avr, .msp430 => null,
7118 else => @as([]const u8, "i386, x86_64, AVR, and MSP430"),
7119 },
7120 .Signal => switch (arch) {
7121 .avr => null,
7122 else => @as([]const u8, "AVR"),
7123 },
7124 .Stdcall, .Fastcall, .Thiscall => switch (arch) {
7125 .i386 => null,
7126 else => @as([]const u8, "i386"),
7127 },
7128 .Vectorcall => switch (arch) {
7129 .i386, .aarch64, .aarch64_be, .aarch64_32 => null,
7130 else => @as([]const u8, "i386 and AArch64"),
7131 },
7132 .APCS, .AAPCS, .AAPCSVFP => switch (arch) {
7133 .arm, .armeb, .aarch64, .aarch64_be, .aarch64_32 => null,
7134 else => @as([]const u8, "ARM"),
7135 },
7136 .SysV, .Win64 => switch (arch) {
7137 .x86_64 => null,
7138 else => @as([]const u8, "x86_64"),
7139 },
7140 .PtxKernel => switch (arch) {
7141 .nvptx, .nvptx64 => null,
7142 else => @as([]const u8, "nvptx and nvptx64"),
7143 },
7144 }) |allowed_platform| {
7145 return sema.fail(block, cc_src, "callconv '{s}' is only available on {s}, not {s}", .{
7146 @tagName(cc_workaround),
7147 allowed_platform,
7148 @tagName(arch),
7149 });
7150 }
7151
7112 break :fn_ty try Type.Tag.function.create(sema.arena, .{7152 break :fn_ty try Type.Tag.function.create(sema.arena, .{
7113 .param_types = param_types,7153 .param_types = param_types,
7114 .comptime_params = comptime_params.ptr,7154 .comptime_params = comptime_params.ptr,
test/cases/compile_errors/bogus_compile_var.zig created+8
...@@ -0,0 +1,8 @@
1const x = @import("builtin").bogus;
2export fn entry() usize { return @sizeOf(@TypeOf(x)); }
3
4// error
5// backend=stage2
6// target=native
7//
8// :1:29: error: struct 'builtin.builtin' has no member named 'bogus'
test/cases/compile_errors/callconv_apcs_aapcs_aapcsvfp_on_unsupported_platform.zig created+11
...@@ -0,0 +1,11 @@
1export fn entry1() callconv(.APCS) void {}
2export fn entry2() callconv(.AAPCS) void {}
3export fn entry3() callconv(.AAPCSVFP) void {}
4
5// error
6// backend=stage2
7// target=x86_64-linux-none
8//
9// :1:30: error: callconv 'APCS' is only available on ARM, not x86_64
10// :2:30: error: callconv 'AAPCS' is only available on ARM, not x86_64
11// :3:30: error: callconv 'AAPCSVFP' is only available on ARM, not x86_64
test/cases/compile_errors/callconv_interrupt_on_unsupported_platform.zig created+7
...@@ -0,0 +1,7 @@
1export fn entry() callconv(.Interrupt) void {}
2
3// error
4// backend=stage2
5// target=aarch64-linux-none
6//
7// :1:29: error: callconv 'Interrupt' is only available on i386, x86_64, AVR, and MSP430, not aarch64
test/cases/compile_errors/callconv_signal_on_unsupported_platform.zig created+7
...@@ -0,0 +1,7 @@
1export fn entry() callconv(.Signal) void {}
2
3// error
4// backend=stage2
5// target=x86_64-linux-none
6//
7// :1:29: error: callconv 'Signal' is only available on AVR, not x86_64
test/cases/compile_errors/callconv_stdcall_fastcall_thiscall_on_unsupported_platform.zig created+23
...@@ -0,0 +1,23 @@
1const F1 = fn () callconv(.Stdcall) void;
2const F2 = fn () callconv(.Fastcall) void;
3const F3 = fn () callconv(.Thiscall) void;
4export fn entry1() void {
5 var a: F1 = undefined;
6 _ = a;
7}
8export fn entry2() void {
9 var a: F2 = undefined;
10 _ = a;
11}
12export fn entry3() void {
13 var a: F3 = undefined;
14 _ = a;
15}
16
17// error
18// backend=stage2
19// target=x86_64-linux-none
20//
21// :1:28: error: callconv 'Stdcall' is only available on i386, not x86_64
22// :2:28: error: callconv 'Fastcall' is only available on i386, not x86_64
23// :3:28: error: callconv 'Thiscall' is only available on i386, not x86_64
test/cases/compile_errors/callconv_vectorcall_on_unsupported_platform.zig created+7
...@@ -0,0 +1,7 @@
1export fn entry() callconv(.Vectorcall) void {}
2
3// error
4// backend=stage2
5// target=x86_64-linux-none
6//
7// :1:29: error: callconv 'Vectorcall' is only available on i386 and AArch64, not x86_64
test/cases/compile_errors/stage1/obj/bogus_compile_var.zig deleted-8
...@@ -1,8 +0,0 @@
1const x = @import("builtin").bogus;
2export fn entry() usize { return @sizeOf(@TypeOf(x)); }
3
4// error
5// backend=stage1
6// target=native
7//
8// tmp.zig:1:29: error: container 'builtin' has no member called 'bogus'
test/cases/compile_errors/stage1/obj/callconv_apcs_aapcs_aapcsvfp_on_unsupported_platform.zig deleted-11
...@@ -1,11 +0,0 @@
1export fn entry1() callconv(.APCS) void {}
2export fn entry2() callconv(.AAPCS) void {}
3export fn entry3() callconv(.AAPCSVFP) void {}
4
5// error
6// backend=stage1
7// target=x86_64-linux-none
8//
9// tmp.zig:1:29: error: callconv 'APCS' is only available on ARM, not x86_64
10// tmp.zig:2:29: error: callconv 'AAPCS' is only available on ARM, not x86_64
11// tmp.zig:3:29: error: callconv 'AAPCSVFP' is only available on ARM, not x86_64
test/cases/compile_errors/stage1/obj/callconv_interrupt_on_unsupported_platform.zig deleted-7
...@@ -1,7 +0,0 @@
1export fn entry() callconv(.Interrupt) void {}
2
3// error
4// backend=stage1
5// target=aarch64-linux-none
6//
7// tmp.zig:1:28: error: callconv 'Interrupt' is only available on x86, x86_64, AVR, and MSP430, not aarch64
test/cases/compile_errors/stage1/obj/callconv_signal_on_unsupported_platform.zig deleted-7
...@@ -1,7 +0,0 @@
1export fn entry() callconv(.Signal) void {}
2
3// error
4// backend=stage1
5// target=x86_64-linux-none
6//
7// tmp.zig:1:28: error: callconv 'Signal' is only available on AVR, not x86_64
test/cases/compile_errors/stage1/obj/callconv_stdcall_fastcall_thiscall_on_unsupported_platform-0.zig deleted-23
...@@ -1,23 +0,0 @@
1const F1 = fn () callconv(.Stdcall) void;
2const F2 = fn () callconv(.Fastcall) void;
3const F3 = fn () callconv(.Thiscall) void;
4export fn entry1() void {
5 var a: F1 = undefined;
6 _ = a;
7}
8export fn entry2() void {
9 var a: F2 = undefined;
10 _ = a;
11}
12export fn entry3() void {
13 var a: F3 = undefined;
14 _ = a;
15}
16
17// error
18// backend=stage1
19// target=x86_64-linux-none
20//
21// tmp.zig:1:27: error: callconv 'Stdcall' is only available on x86, not x86_64
22// tmp.zig:2:27: error: callconv 'Fastcall' is only available on x86, not x86_64
23// tmp.zig:3:27: error: callconv 'Thiscall' is only available on x86, not x86_64
test/cases/compile_errors/stage1/obj/callconv_stdcall_fastcall_thiscall_on_unsupported_platform-1.zig deleted-11
...@@ -1,11 +0,0 @@
1export fn entry1() callconv(.Stdcall) void {}
2export fn entry2() callconv(.Fastcall) void {}
3export fn entry3() callconv(.Thiscall) void {}
4
5// error
6// backend=stage1
7// target=x86_64-linux-none
8//
9// tmp.zig:1:29: error: callconv 'Stdcall' is only available on x86, not x86_64
10// tmp.zig:2:29: error: callconv 'Fastcall' is only available on x86, not x86_64
11// tmp.zig:3:29: error: callconv 'Thiscall' is only available on x86, not x86_64
test/cases/compile_errors/stage1/obj/callconv_vectorcall_on_unsupported_platform.zig deleted-7
...@@ -1,7 +0,0 @@
1export fn entry() callconv(.Vectorcall) void {}
2
3// error
4// backend=stage1
5// target=x86_64-linux-none
6//
7// tmp.zig:1:28: error: callconv 'Vectorcall' is only available on x86 and AArch64, not x86_64