authorgravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2024-10-13 17:56:47+01:00
committergravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2024-10-19 19:15:23+01:00
log4be0cf30fc10420c2b5fa97a3b25a07b7a0ce7f3
tree0c239f9b68fbbc13ae94462756d466ef774a9772
parentec19086aa0491024622c444b0d9310560de9e6f0
signaturelock-open Commit is signed but in an unrecognized format.

test: update for `CallingConvention` changes

This also includes some compiler and std changes to correct error messages which weren't properly updated before.

41 files changed, 154 insertions(+), 195 deletions(-)

lib/std/Target.zig+1-1
......@@ -1612,7 +1612,7 @@ pub const Cpu = struct {
16121612
16131613 /// Returns the array of `Arch` to which a specific `std.builtin.CallingConvention` applies.
16141614 /// Asserts that `cc` is not `.auto`, `.@"async"`, `.naked`, or `.@"inline"`.
1615 pub fn fromCallconv(cc: std.builtin.CallingConvention) []const Arch {
1615 pub fn fromCallconv(cc: std.builtin.CallingConvention.Tag) []const Arch {
16161616 return switch (cc) {
16171617 .auto,
16181618 .@"async",
lib/std/builtin.zig+5-3
......@@ -173,7 +173,7 @@ pub const CallingConvention = union(enum(u8)) {
173173 /// Functions marked as `extern` or `export` are given this calling convention by default.
174174 pub const c = builtin.target.defaultCCallingConvention().?;
175175
176 pub const winapi: CallingConvention = switch (builtin.target.arch) {
176 pub const winapi: CallingConvention = switch (builtin.target.cpu.arch) {
177177 .x86_64 => .{ .x86_64_win = .{} },
178178 .x86 => .{ .x86_stdcall = .{} },
179179 .aarch64, .aarch64_be => .{ .aarch64_aapcs_win = .{} },
......@@ -481,7 +481,9 @@ pub const CallingConvention = union(enum(u8)) {
481481
482482 /// Returns the array of `std.Target.Cpu.Arch` to which this `CallingConvention` applies.
483483 /// Asserts that `cc` is not `.auto`, `.@"async"`, `.naked`, or `.@"inline"`.
484 pub const archs = std.Target.Cpu.Arch.fromCallconv;
484 pub fn archs(cc: CallingConvention) []const std.Target.Cpu.Arch {
485 return std.Target.Cpu.Arch.fromCallconv(cc);
486 }
485487
486488 pub fn eql(a: CallingConvention, b: CallingConvention) bool {
487489 return std.meta.eql(a, b);
......@@ -490,7 +492,7 @@ pub const CallingConvention = union(enum(u8)) {
490492 pub fn withStackAlign(cc: CallingConvention, incoming_stack_alignment: u64) CallingConvention {
491493 const tag: CallingConvention.Tag = cc;
492494 var result = cc;
493 @field(result, tag).incoming_stack_alignment = incoming_stack_alignment;
495 @field(result, @tagName(tag)).incoming_stack_alignment = incoming_stack_alignment;
494496 return result;
495497 }
496498};
src/Sema.zig+22-15
......@@ -9711,25 +9711,32 @@ fn callConvSupportsVarArgs(cc: std.builtin.CallingConvention.Tag) bool {
97119711}
97129712fn checkCallConvSupportsVarArgs(sema: *Sema, block: *Block, src: LazySrcLoc, cc: std.builtin.CallingConvention.Tag) CompileError!void {
97139713 const CallingConventionsSupportingVarArgsList = struct {
9714 pub fn format(_: @This(), comptime fmt: []const u8, options: std.fmt.FormatOptions, writer: anytype) !void {
9714 arch: std.Target.Cpu.Arch,
9715 pub fn format(ctx: @This(), comptime fmt: []const u8, options: std.fmt.FormatOptions, writer: anytype) !void {
97159716 _ = fmt;
97169717 _ = options;
9717 for (calling_conventions_supporting_var_args, 0..) |cc_inner, i| {
9718 if (i != 0)
9718 var first = true;
9719 for (calling_conventions_supporting_var_args) |cc_inner| {
9720 for (std.Target.Cpu.Arch.fromCallconv(cc_inner)) |supported_arch| {
9721 if (supported_arch == ctx.arch) break;
9722 } else continue; // callconv not supported by this arch
9723 if (!first) {
97199724 try writer.writeAll(", ");
9720 try writer.print("'.{s}'", .{@tagName(cc_inner)});
9725 }
9726 first = false;
9727 try writer.print("'{s}'", .{@tagName(cc_inner)});
97219728 }
97229729 }
97239730 };
97249731
97259732 if (!callConvSupportsVarArgs(cc)) {
9726 const msg = msg: {
9727 const msg = try sema.errMsg(src, "variadic function does not support '.{s}' calling convention", .{@tagName(cc)});
9733 return sema.failWithOwnedErrorMsg(block, msg: {
9734 const msg = try sema.errMsg(src, "variadic function does not support '{s}' calling convention", .{@tagName(cc)});
97289735 errdefer msg.destroy(sema.gpa);
9729 try sema.errNote(src, msg, "supported calling conventions: {}", .{CallingConventionsSupportingVarArgsList{}});
9736 const target = sema.pt.zcu.getTarget();
9737 try sema.errNote(src, msg, "supported calling conventions: {}", .{CallingConventionsSupportingVarArgsList{ .arch = target.cpu.arch }});
97309738 break :msg msg;
9731 };
9732 return sema.failWithOwnedErrorMsg(block, msg);
9739 });
97339740 }
97349741}
97359742
......@@ -9857,9 +9864,9 @@ fn funcCommon(
98579864 .x86_64_interrupt, .x86_interrupt => {
98589865 const err_code_size = target.ptrBitWidth();
98599866 switch (i) {
9860 0 => if (param_ty.zigTypeTag(zcu) != .pointer) return sema.fail(block, param_src, "first parameter of function with 'Interrupt' calling convention must be a pointer type", .{}),
9861 1 => if (param_ty.bitSize(zcu) != err_code_size) return sema.fail(block, param_src, "second parameter of function with 'Interrupt' calling convention must be a {d}-bit integer", .{err_code_size}),
9862 else => return sema.fail(block, param_src, "'Interrupt' calling convention supports up to 2 parameters, found {d}", .{i + 1}),
9867 0 => if (param_ty.zigTypeTag(zcu) != .pointer) return sema.fail(block, param_src, "first parameter of function with '{s}' calling convention must be a pointer type", .{@tagName(cc_resolved)}),
9868 1 => if (param_ty.bitSize(zcu) != err_code_size) return sema.fail(block, param_src, "second parameter of function with '{s}' calling convention must be a {d}-bit integer", .{ @tagName(cc_resolved), err_code_size }),
9869 else => return sema.fail(block, param_src, "'{s}' calling convention supports up to 2 parameters, found {d}", .{ @tagName(cc_resolved), i + 1 }),
98639870 }
98649871 },
98659872 .arm_interrupt,
......@@ -9870,8 +9877,8 @@ fn funcCommon(
98709877 .avr_interrupt,
98719878 .csky_interrupt,
98729879 .m68k_interrupt,
9873 => return sema.fail(block, param_src, "parameters are not allowed with 'Interrupt' calling convention", .{}),
9874 .avr_signal => return sema.fail(block, param_src, "parameters are not allowed with 'Signal' calling convention", .{}),
9880 => return sema.fail(block, param_src, "parameters are not allowed with '{s}' calling convention", .{@tagName(cc_resolved)}),
9881 .avr_signal => return sema.fail(block, param_src, "parameters are not allowed with '{s}' calling convention", .{@tagName(cc_resolved)}),
98759882 else => {},
98769883 }
98779884 }
......@@ -10220,7 +10227,7 @@ fn finishFunc(
1022010227 for (formatter.archs, 0..) |arch, i| {
1022110228 if (i != 0)
1022210229 try writer.writeAll(", ");
10223 try writer.print("'.{s}'", .{@tagName(arch)});
10230 try writer.print("'{s}'", .{@tagName(arch)});
1022410231 }
1022510232 }
1022610233 };
src/Type.zig+4-1
......@@ -397,7 +397,10 @@ pub fn print(ty: Type, writer: anytype, pt: Zcu.PerThread) @TypeOf(writer).Error
397397 break :print_cc;
398398 }
399399 }
400 try writer.print("callconv({any}) ", .{fn_info.cc});
400 switch (fn_info.cc) {
401 .auto, .@"async", .naked, .@"inline" => try writer.print("callconv(.{}) ", .{std.zig.fmtId(@tagName(fn_info.cc))}),
402 else => try writer.print("callconv({any}) ", .{fn_info.cc}),
403 }
401404 }
402405 if (fn_info.return_type == .generic_poison_type) {
403406 try writer.writeAll("anytype");
src/arch/riscv64/CodeGen.zig+2-1
......@@ -18,6 +18,7 @@ const Zcu = @import("../../Zcu.zig");
1818const Package = @import("../../Package.zig");
1919const InternPool = @import("../../InternPool.zig");
2020const Compilation = @import("../../Compilation.zig");
21const target_util = @import("../../target.zig");
2122const trace = @import("../../tracy.zig").trace;
2223const codegen = @import("../../codegen.zig");
2324
......@@ -821,7 +822,7 @@ pub fn generate(
821822 @intFromEnum(FrameIndex.stack_frame),
822823 FrameAlloc.init(.{
823824 .size = 0,
824 .alignment = func.analysisUnordered(ip).stack_alignment.max(.@"1"),
825 .alignment = .fromByteUnits(target_util.stackAlignment(function.target.*, fn_type.fnCallingConvention(zcu))),
825826 }),
826827 );
827828 function.frame_allocs.set(
src/arch/x86_64/CodeGen.zig+1-1
......@@ -873,7 +873,7 @@ pub fn generate(
873873 @intFromEnum(FrameIndex.stack_frame),
874874 FrameAlloc.init(.{
875875 .size = 0,
876 .alignment = target_util.stackAlignment(function.target.*, fn_type.fnCallingConvention(zcu)),
876 .alignment = .fromByteUnits(target_util.stackAlignment(function.target.*, fn_type.fnCallingConvention(zcu))),
877877 }),
878878 );
879879 function.frame_allocs.set(
test/behavior/align.zig-9
......@@ -210,15 +210,6 @@ test "alignment and size of structs with 128-bit fields" {
210210 }
211211}
212212
213test "alignstack" {
214 try expect(fnWithAlignedStack() == 1234);
215}
216
217fn fnWithAlignedStack() i32 {
218 @setAlignStack(256);
219 return 1234;
220}
221
222213test "implicitly decreasing slice alignment" {
223214 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
224215 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
test/behavior/builtin_functions_returning_void_or_noreturn.zig-1
......@@ -20,7 +20,6 @@ test {
2020 try testing.expectEqual({}, @memset(@as([*]u8, @ptrFromInt(1))[0..0], undefined));
2121 try testing.expectEqual(noreturn, @TypeOf(if (true) @panic("") else {}));
2222 try testing.expectEqual({}, @prefetch(&val, .{}));
23 try testing.expectEqual({}, @setAlignStack(16));
2423 try testing.expectEqual({}, @setEvalBranchQuota(0));
2524 try testing.expectEqual({}, @setFloatMode(.optimized));
2625 try testing.expectEqual({}, @setRuntimeSafety(true));
test/behavior/type_info.zig+4-4
......@@ -358,7 +358,7 @@ test "type info: function type info" {
358358fn testFunction() !void {
359359 const foo_fn_type = @TypeOf(typeInfoFoo);
360360 const foo_fn_info = @typeInfo(foo_fn_type);
361 try expect(foo_fn_info.@"fn".calling_convention == .C);
361 try expect(foo_fn_info.@"fn".calling_convention.eql(.c));
362362 try expect(!foo_fn_info.@"fn".is_generic);
363363 try expect(foo_fn_info.@"fn".params.len == 2);
364364 try expect(foo_fn_info.@"fn".is_var_args);
......@@ -374,7 +374,7 @@ fn testFunction() !void {
374374
375375 const aligned_foo_fn_type = @TypeOf(typeInfoFooAligned);
376376 const aligned_foo_fn_info = @typeInfo(aligned_foo_fn_type);
377 try expect(aligned_foo_fn_info.@"fn".calling_convention == .C);
377 try expect(aligned_foo_fn_info.@"fn".calling_convention.eql(.c));
378378 try expect(!aligned_foo_fn_info.@"fn".is_generic);
379379 try expect(aligned_foo_fn_info.@"fn".params.len == 2);
380380 try expect(aligned_foo_fn_info.@"fn".is_var_args);
......@@ -390,8 +390,8 @@ fn testFunction() !void {
390390 try expect(aligned_foo_ptr_fn_info.pointer.sentinel == null);
391391}
392392
393extern fn typeInfoFoo(a: usize, b: bool, ...) callconv(.C) usize;
394extern fn typeInfoFooAligned(a: usize, b: bool, ...) align(4) callconv(.C) usize;
393extern fn typeInfoFoo(a: usize, b: bool, ...) callconv(.c) usize;
394extern fn typeInfoFooAligned(a: usize, b: bool, ...) align(4) callconv(.c) usize;
395395
396396test "type info: generic function types" {
397397 const G1 = @typeInfo(@TypeOf(generic1));
test/behavior/typename.zig+3-3
......@@ -79,9 +79,9 @@ test "basic" {
7979 try expectEqualStrings("fn (comptime u32) void", @typeName(fn (comptime u32) void));
8080 try expectEqualStrings("fn (noalias []u8) void", @typeName(fn (noalias []u8) void));
8181
82 try expectEqualStrings("fn () callconv(.C) void", @typeName(fn () callconv(.C) void));
83 try expectEqualStrings("fn (...) callconv(.C) void", @typeName(fn (...) callconv(.C) void));
84 try expectEqualStrings("fn (u32, ...) callconv(.C) void", @typeName(fn (u32, ...) callconv(.C) void));
82 try expectEqualStrings("fn () callconv(.c) void", @typeName(fn () callconv(.c) void));
83 try expectEqualStrings("fn (...) callconv(.c) void", @typeName(fn (...) callconv(.c) void));
84 try expectEqualStrings("fn (u32, ...) callconv(.c) void", @typeName(fn (u32, ...) callconv(.c) void));
8585}
8686
8787test "top level decl" {
test/cases/compile_errors/array_in_c_exported_function.zig+3-4
......@@ -7,10 +7,9 @@ export fn zig_return_array() [10]u8 {
77}
88
99// error
10// backend=stage2
11// target=native
10// target=x86_64-linux
1211//
13// :1:21: error: parameter of type '[10]u8' not allowed in function with calling convention 'C'
12// :1:21: error: parameter of type '[10]u8' not allowed in function with calling convention 'x86_64_sysv'
1413// :1:21: note: arrays are not allowed as a parameter type
15// :5:30: error: return type '[10]u8' not allowed in function with calling convention 'C'
14// :5:30: error: return type '[10]u8' not allowed in function with calling convention 'x86_64_sysv'
1615// :5:30: note: arrays are not allowed as a return type
test/cases/compile_errors/assign_inline_fn_to_non-comptime_var.zig+1-1
......@@ -8,5 +8,5 @@ inline fn b() void {}
88// backend=stage2
99// target=native
1010//
11// :2:9: error: variable of type '*const fn () callconv(.Inline) void' must be const or comptime
11// :2:9: error: variable of type '*const fn () callconv(.@"inline") void' must be const or comptime
1212// :2:9: note: function has inline calling convention
test/cases/compile_errors/bitsize_of_packed_struct_checks_backing_int_ty.zig+1-1
......@@ -1,7 +1,7 @@
11const Foo = packed struct(u32) {
22 x: u1,
33};
4fn bar(_: Foo) callconv(.C) void {}
4fn bar(_: Foo) callconv(.c) void {}
55pub export fn entry() void {
66 bar(.{ .x = 0 });
77}
test/cases/compile_errors/callconv_apcs_aapcs_aapcsvfp_on_unsupported_platform.zig+3-4
......@@ -3,9 +3,8 @@ export fn entry2() callconv(.AAPCS) void {}
33export fn entry3() callconv(.AAPCSVFP) void {}
44
55// error
6// backend=stage2
76// target=x86_64-linux-none
87//
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
8// :1:30: error: callconv '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'
10// :3:30: error: callconv 'arm_aapcs_vfp' only available on architectures 'arm', 'armeb', 'thumb', 'thumbeb'
test/cases/compile_errors/callconv_signal_on_unsupported_platform.zig+2-2
......@@ -1,7 +1,7 @@
1export fn entry() callconv(.Signal) void {}
1export fn entry() callconv(.avr_signal) void {}
22
33// error
44// backend=stage2
55// target=x86_64-linux-none
66//
7// :1:29: error: callconv 'Signal' is only available on AVR, not x86_64
7// :1:29: error: callconv 'avr_signal' only available on architectures 'avr'
test/cases/compile_errors/callconv_stdcall_fastcall_thiscall_on_unsupported_platform.zig+6-6
......@@ -1,6 +1,6 @@
1const F1 = fn () callconv(.Stdcall) void;
2const F2 = fn () callconv(.Fastcall) void;
3const F3 = fn () callconv(.Thiscall) void;
1const F1 = fn () callconv(.{ .x86_stdcall = .{} }) void;
2const F2 = fn () callconv(.{ .x86_fastcall = .{} }) void;
3const F3 = fn () callconv(.{ .x86_thiscall = .{} }) void;
44export fn entry1() void {
55 const a: F1 = undefined;
66 _ = a;
......@@ -18,6 +18,6 @@ export fn entry3() void {
1818// backend=stage2
1919// target=x86_64-linux-none
2020//
21// :1:28: error: callconv 'Stdcall' is only available on x86, not x86_64
22// :2:28: error: callconv 'Fastcall' is only available on x86, not x86_64
23// :3:28: error: callconv 'Thiscall' is only available on x86, not x86_64
21// :1:28: error: callconv 'x86_stdcall' only available on architectures 'x86'
22// :2:28: error: callconv 'x86_fastcall' only available on architectures 'x86'
23// :3:28: error: callconv 'x86_thiscall' only available on architectures 'x86'
test/cases/compile_errors/callconv_vectorcall_on_unsupported_platform.zig deleted-7
......@@ -1,7 +0,0 @@
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 x86 and AArch64, not x86_64
test/cases/compile_errors/closure_get_depends_on_failed_decl.zig+1-1
......@@ -4,7 +4,7 @@ pub inline fn requestAdapter(
44 comptime callbackArg: fn () callconv(.Inline) void,
55) void {
66 _ = &(struct {
7 pub fn callback() callconv(.C) void {
7 pub fn callback() callconv(.c) void {
88 callbackArg();
99 }
1010 }).callback;
test/cases/compile_errors/export_function_with_comptime_parameter.zig+2-3
......@@ -3,7 +3,6 @@ export fn foo(comptime x: anytype, y: i32) i32 {
33}
44
55// error
6// backend=stage2
7// target=native
6// target=x86_64-linux
87//
9// :1:15: error: comptime parameters not allowed in function with calling convention 'C'
8// :1:15: error: comptime parameters not allowed in function with calling convention 'x86_64_sysv'
test/cases/compile_errors/export_generic_function.zig+2-3
......@@ -4,7 +4,6 @@ export fn foo(num: anytype) i32 {
44}
55
66// error
7// backend=stage2
8// target=native
7// target=x86_64-linux
98//
10// :1:15: error: generic parameters not allowed in function with calling convention 'C'
9// :1:15: error: generic parameters not allowed in function with calling convention 'x86_64_sysv'
test/cases/compile_errors/extern_function_pointer_mismatch.zig+3-4
......@@ -14,8 +14,7 @@ export fn entry() usize {
1414}
1515
1616// error
17// backend=stage2
18// target=native
17// target=x86_64-linux
1918//
20// :1:38: error: expected type 'fn (i32) i32', found 'fn (i32) callconv(.C) i32'
21// :1:38: note: calling convention 'C' cannot cast into calling convention 'Unspecified'
19// :1:38: error: expected type 'fn (i32) i32', found 'fn (i32) callconv(.c) i32'
20// :1:38: note: calling convention 'x86_64_sysv' cannot cast into calling convention 'auto'
test/cases/compile_errors/extern_function_with_comptime_parameter.zig+4-5
......@@ -15,9 +15,8 @@ comptime {
1515}
1616
1717// error
18// backend=stage2
19// target=native
18// target=x86_64-linux
2019//
21// :1:15: error: comptime parameters not allowed in function with calling convention 'C'
22// :5:30: error: comptime parameters not allowed in function with calling convention 'C'
23// :6:30: error: generic parameters not allowed in function with calling convention 'C'
20// :1:15: error: comptime parameters not allowed in function with calling convention 'x86_64_sysv'
21// :5:30: error: comptime parameters not allowed in function with calling convention 'x86_64_sysv'
22// :6:30: error: generic parameters not allowed in function with calling convention 'x86_64_sysv'
test/cases/compile_errors/function-only_builtins_outside_function.zig+12-17
......@@ -1,7 +1,3 @@
1comptime {
2 @setAlignStack(1);
3}
4
51comptime {
62 @branchHint(.cold);
73}
......@@ -54,16 +50,15 @@ comptime {
5450// backend=stage2
5551// target=native
5652//
57// :2:5: error: '@setAlignStack' outside function scope
58// :6:5: error: '@branchHint' outside function scope
59// :10:5: error: '@src' outside function scope
60// :14:5: error: '@returnAddress' outside function scope
61// :18:5: error: '@frameAddress' outside function scope
62// :22:5: error: '@breakpoint' outside function scope
63// :26:5: error: '@cVaArg' outside function scope
64// :30:5: error: '@cVaCopy' outside function scope
65// :34:5: error: '@cVaEnd' outside function scope
66// :38:5: error: '@cVaStart' outside function scope
67// :42:5: error: '@workItemId' outside function scope
68// :46:5: error: '@workGroupSize' outside function scope
69// :50:5: error: '@workGroupId' outside function scope
53// :2:5: error: '@branchHint' outside function scope
54// :6:5: error: '@src' outside function scope
55// :10:5: error: '@returnAddress' outside function scope
56// :14:5: error: '@frameAddress' outside function scope
57// :18:5: error: '@breakpoint' outside function scope
58// :22:5: error: '@cVaArg' outside function scope
59// :26:5: error: '@cVaCopy' outside function scope
60// :30:5: error: '@cVaEnd' outside function scope
61// :34:5: error: '@cVaStart' outside function scope
62// :38:5: error: '@workItemId' outside function scope
63// :42:5: error: '@workGroupSize' outside function scope
64// :46:5: error: '@workGroupId' outside function scope
test/cases/compile_errors/function_with_non-extern_non-packed_enum_parameter.zig+2-3
......@@ -4,10 +4,9 @@ export fn entry(foo: Foo) void {
44}
55
66// error
7// backend=stage2
8// target=native
7// target=x86_64-linux
98//
10// :2:17: error: parameter of type 'tmp.Foo' not allowed in function with calling convention 'C'
9// :2:17: error: parameter of type 'tmp.Foo' not allowed in function with calling convention 'x86_64_sysv'
1110// :2:17: note: enum tag type 'u2' is not extern compatible
1211// :2:17: note: only integers with 0, 8, 16, 32, 64 and 128 bits are extern compatible
1312// :1:13: note: enum declared here
test/cases/compile_errors/function_with_non-extern_non-packed_struct_parameter.zig+2-3
......@@ -8,9 +8,8 @@ export fn entry(foo: Foo) void {
88}
99
1010// error
11// backend=stage2
12// target=native
11// target=x86_64-linux
1312//
14// :6:17: error: parameter of type 'tmp.Foo' not allowed in function with calling convention 'C'
13// :6:17: error: parameter of type 'tmp.Foo' not allowed in function with calling convention 'x86_64_sysv'
1514// :6:17: note: only extern structs and ABI sized packed structs are extern compatible
1615// :1:13: note: struct declared here
test/cases/compile_errors/function_with_non-extern_non-packed_union_parameter.zig+2-3
......@@ -8,9 +8,8 @@ export fn entry(foo: Foo) void {
88}
99
1010// error
11// backend=stage2
12// target=native
11// target=x86_64-linux
1312//
14// :6:17: error: parameter of type 'tmp.Foo' not allowed in function with calling convention 'C'
13// :6:17: error: parameter of type 'tmp.Foo' not allowed in function with calling convention 'x86_64_sysv'
1514// :6:17: note: only extern unions and ABI sized packed unions are extern compatible
1615// :1:13: note: union declared here
test/cases/compile_errors/invalid_extern_function_call.zig+1-1
......@@ -1,4 +1,4 @@
1const x = @extern(*const fn () callconv(.C) void, .{ .name = "foo" });
1const x = @extern(*const fn () callconv(.c) void, .{ .name = "foo" });
22
33export fn entry0() void {
44 comptime x();
test/cases/compile_errors/invalid_func_for_callconv.zig+7-8
......@@ -9,12 +9,11 @@ export fn signal_param(_: u32) callconv(.Signal) void {}
99export fn signal_ret() callconv(.Signal) noreturn {}
1010
1111// error
12// backend=stage2
1312// target=x86_64-linux
14//
15// :1:28: error: first parameter of function with 'Interrupt' calling convention must be a pointer type
16// :2:43: error: second parameter of function with 'Interrupt' calling convention must be a 64-bit integer
17// :3:51: error: 'Interrupt' calling convention supports up to 2 parameters, found 3
18// :4:69: error: function with calling convention 'Interrupt' must return 'void' or 'noreturn'
19// :8:24: error: parameters are not allowed with 'Signal' calling convention
20// :9:34: error: callconv 'Signal' is only available on AVR, not x86_64
13//
14// :1:28: error: first parameter of function with 'x86_64_interrupt' calling convention must be a pointer type
15// :2:43: error: second parameter of function with 'x86_64_interrupt' calling convention must be a 64-bit integer
16// :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'
18// :8:24: error: parameters are not allowed with 'avr_signal' calling convention
19// :9:34: error: callconv 'avr_signal' only available on architectures 'avr'
test/cases/compile_errors/invalid_tail_call.zig+1-1
......@@ -9,4 +9,4 @@ pub export fn entry() void {
99// backend=llvm
1010// target=native
1111//
12// :5:5: error: unable to perform tail call: type of function being called 'fn (usize) void' does not match type of calling function 'fn () callconv(.C) void'
12// :5:5: error: unable to perform tail call: type of function being called 'fn (usize) void' does not match type of calling function 'fn () callconv(.c) void'
test/cases/compile_errors/invalid_variadic_function.zig+5-6
......@@ -13,11 +13,10 @@ comptime {
1313}
1414
1515// error
16// backend=stage2
17// target=native
16// target=x86_64-linux
1817//
19// :1:1: error: variadic function does not support '.Unspecified' calling convention
20// :1:1: note: supported calling conventions: '.C'
21// :1:1: error: variadic function does not support '.Inline' calling convention
22// :1:1: note: supported calling conventions: '.C'
18// :1:1: error: variadic function does not support 'auto' calling convention
19// :1:1: note: supported calling conventions: 'x86_64_sysv', 'x86_64_win'
20// :1:1: error: variadic function does not support 'inline' calling convention
21// :1:1: note: supported calling conventions: 'x86_64_sysv', 'x86_64_win'
2322// :2:1: error: generic function cannot be variadic
test/cases/compile_errors/noinline_fn_cc_inline.zig+2-3
......@@ -1,5 +1,4 @@
1const cc = .Inline;
2noinline fn foo() callconv(cc) void {}
1noinline fn foo() callconv(.@"inline") void {}
32
43comptime {
54 _ = foo;
......@@ -9,4 +8,4 @@ comptime {
98// backend=stage2
109// target=native
1110//
12// :2:28: error: 'noinline' function cannot have callconv 'Inline'
11// :1:29: error: 'noinline' function cannot have callconv 'inline'
test/cases/compile_errors/old_fn_ptr_in_extern_context.zig+4-4
......@@ -1,20 +1,20 @@
11const S = extern struct {
2 a: fn () callconv(.C) void,
2 a: fn () callconv(.c) void,
33};
44comptime {
55 _ = @sizeOf(S) == 1;
66}
77comptime {
8 _ = [*c][4]fn () callconv(.C) void;
8 _ = [*c][4]fn () callconv(.c) void;
99}
1010
1111// error
1212// backend=stage2
1313// target=native
1414//
15// :2:8: error: extern structs cannot contain fields of type 'fn () callconv(.C) void'
15// :2:8: error: extern structs cannot contain fields of type 'fn () callconv(.c) void'
1616// :2:8: note: type has no guaranteed in-memory representation
1717// :2:8: note: use '*const ' to make a function pointer type
18// :8:13: error: C pointers cannot point to non-C-ABI-compatible type '[4]fn () callconv(.C) void'
18// :8:13: error: C pointers cannot point to non-C-ABI-compatible type '[4]fn () callconv(.c) void'
1919// :8:13: note: type has no guaranteed in-memory representation
2020// :8:13: note: use '*const ' to make a function pointer type
test/cases/compile_errors/reify_type.Fn_with_is_var_args_true_and_non-C_callconv.zig+3-4
......@@ -12,8 +12,7 @@ comptime {
1212}
1313
1414// error
15// backend=stage2
16// target=native
15// target=x86_64-linux
1716//
18// :1:13: error: variadic function does not support '.Unspecified' calling convention
19// :1:13: note: supported calling conventions: '.C'
17// :1:13: error: variadic function does not support 'auto' calling convention
18// :1:13: note: supported calling conventions: 'x86_64_sysv', 'x86_64_win'
test/cases/compile_errors/runtime_@ptrFromInt_to_comptime_only_type.zig+2-2
......@@ -1,5 +1,5 @@
11const GuSettings = struct {
2 fin: ?fn (c_int) callconv(.C) void,
2 fin: ?fn (c_int) callconv(.c) void,
33};
44pub export fn callbackFin(id: c_int, arg: ?*anyopaque) void {
55 const settings: ?*GuSettings = @as(?*GuSettings, @ptrFromInt(@intFromPtr(arg)));
......@@ -13,4 +13,4 @@ pub export fn callbackFin(id: c_int, arg: ?*anyopaque) void {
1313//
1414// :5:54: error: pointer to comptime-only type '?*tmp.GuSettings' must be comptime-known, but operand is runtime-known
1515// :2:10: note: struct requires comptime because of this field
16// :2:10: note: use '*const fn (c_int) callconv(.C) void' for a function pointer type
16// :2:10: note: use '*const fn (c_int) callconv(.c) void' for a function pointer type
test/cases/compile_errors/setAlignStack_in_naked_function.zig deleted-9
......@@ -1,9 +0,0 @@
1export fn entry() callconv(.Naked) void {
2 @setAlignStack(16);
3}
4
5// error
6// backend=stage2
7// target=native
8//
9// :2:5: error: @setAlignStack in naked function
test/cases/compile_errors/setAlignStack_too_big.zig deleted-9
......@@ -1,9 +0,0 @@
1export fn entry() void {
2 @setAlignStack(511 + 1);
3}
4
5// error
6// backend=stage2
7// target=native
8//
9// :2:5: error: attempt to @setAlignStack(512); maximum is 256
test/cases/compile_errors/slice_used_as_extern_fn_param.zig+3-4
......@@ -1,11 +1,10 @@
1extern fn Text(str: []const u8, num: i32) callconv(.C) void;
1extern fn Text(str: []const u8, num: i32) callconv(.c) void;
22export fn entry() void {
33 _ = Text;
44}
55
66// error
7// backend=stage2
8// target=native
7// target=x86_64-linux
98//
10// :1:16: error: parameter of type '[]const u8' not allowed in function with calling convention 'C'
9// :1:16: error: parameter of type '[]const u8' not allowed in function with calling convention 'x86_64_sysv'
1110// :1:16: note: slices have no guaranteed in-memory representation
test/cases/compile_errors/type_mismatch_in_C_prototype_with_varargs.zig+2-2
......@@ -1,4 +1,4 @@
1const fn_ty = ?fn ([*c]u8, ...) callconv(.C) void;
1const fn_ty = ?fn ([*c]u8, ...) callconv(.c) void;
22extern fn fn_decl(fmt: [*:0]u8, ...) void;
33
44export fn main() void {
......@@ -10,6 +10,6 @@ export fn main() void {
1010// backend=stage2
1111// target=native
1212//
13// :5:22: error: expected type '?fn ([*c]u8, ...) callconv(.C) void', found 'fn ([*:0]u8, ...) callconv(.C) void'
13// :5:22: error: expected type '?fn ([*c]u8, ...) callconv(.c) void', found 'fn ([*:0]u8, ...) callconv(.c) void'
1414// :5:22: note: parameter 0 '[*:0]u8' cannot cast into '[*c]u8'
1515// :5:22: note: '[*c]u8' could have null values which are illegal in type '[*:0]u8'
test/cases/compile_errors/wrong_types_given_to_export.zig+1-1
......@@ -1,4 +1,4 @@
1fn entry() callconv(.C) void {}
1fn entry() callconv(.c) void {}
22comptime {
33 @export(&entry, .{ .name = "entry", .linkage = @as(u32, 1234) });
44}
test/cases/translate_c/static empty struct.c +1-1
......@@ -9,7 +9,7 @@ static inline void foo() {
99// c_frontend=clang
1010//
1111// pub const struct_empty_struct = extern struct {};
12// pub fn foo() callconv(.C) void {
12// pub fn foo() callconv(.c) void {
1313// const bar = struct {
1414// var static: struct_empty_struct = @import("std").mem.zeroes(struct_empty_struct);
1515// };
test/translate_c.zig+34-34
......@@ -484,11 +484,11 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
484484 \\ fnptr_attr_ty qux;
485485 \\};
486486 , &[_][]const u8{
487 \\pub const fnptr_ty = ?*const fn () callconv(.C) void;
488 \\pub const fnptr_attr_ty = ?*const fn () callconv(.C) void;
487 \\pub const fnptr_ty = ?*const fn () callconv(.c) void;
488 \\pub const fnptr_attr_ty = ?*const fn () callconv(.c) void;
489489 \\pub const struct_foo = extern struct {
490 \\ foo: ?*const fn () callconv(.C) void = @import("std").mem.zeroes(?*const fn () callconv(.C) void),
491 \\ bar: ?*const fn () callconv(.C) void = @import("std").mem.zeroes(?*const fn () callconv(.C) void),
490 \\ foo: ?*const fn () callconv(.c) void = @import("std").mem.zeroes(?*const fn () callconv(.c) void),
491 \\ bar: ?*const fn () callconv(.c) void = @import("std").mem.zeroes(?*const fn () callconv(.c) void),
492492 \\ baz: fnptr_ty = @import("std").mem.zeroes(fnptr_ty),
493493 \\ qux: fnptr_attr_ty = @import("std").mem.zeroes(fnptr_attr_ty),
494494 \\};
......@@ -735,7 +735,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
735735 \\static void bar(void) {}
736736 , &[_][]const u8{
737737 \\pub export fn foo() void {}
738 \\pub fn bar() callconv(.C) void {}
738 \\pub fn bar() callconv(.c) void {}
739739 });
740740
741741 cases.add("typedef void",
......@@ -769,7 +769,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
769769 \\pub export fn bar() void {
770770 \\ var func_ptr: ?*anyopaque = @as(?*anyopaque, @ptrCast(&foo));
771771 \\ _ = &func_ptr;
772 \\ var typed_func_ptr: ?*const fn () callconv(.C) void = @as(?*const fn () callconv(.C) void, @ptrFromInt(@as(c_ulong, @intCast(@intFromPtr(func_ptr)))));
772 \\ var typed_func_ptr: ?*const fn () callconv(.c) void = @as(?*const fn () callconv(.c) void, @ptrFromInt(@as(c_ulong, @intCast(@intFromPtr(func_ptr)))));
773773 \\ _ = &typed_func_ptr;
774774 \\}
775775 });
......@@ -839,9 +839,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
839839 \\ lws_callback_function *callback_http;
840840 \\};
841841 , &[_][]const u8{
842 \\pub const lws_callback_function = fn () callconv(.C) void;
842 \\pub const lws_callback_function = fn () callconv(.c) void;
843843 \\pub const struct_Foo = extern struct {
844 \\ func: ?*const fn () callconv(.C) void = @import("std").mem.zeroes(?*const fn () callconv(.C) void),
844 \\ func: ?*const fn () callconv(.c) void = @import("std").mem.zeroes(?*const fn () callconv(.c) void),
845845 \\ callback_http: ?*const lws_callback_function = @import("std").mem.zeroes(?*const lws_callback_function),
846846 \\};
847847 });
......@@ -867,7 +867,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
867867 \\};
868868 , &[_][]const u8{
869869 \\pub const struct_Foo = extern struct {
870 \\ derp: ?*const fn ([*c]struct_Foo) callconv(.C) void = @import("std").mem.zeroes(?*const fn ([*c]struct_Foo) callconv(.C) void),
870 \\ derp: ?*const fn ([*c]struct_Foo) callconv(.c) void = @import("std").mem.zeroes(?*const fn ([*c]struct_Foo) callconv(.c) void),
871871 \\};
872872 ,
873873 \\pub const Foo = struct_Foo;
......@@ -1111,7 +1111,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
11111111 cases.add("__cdecl doesn't mess up function pointers",
11121112 \\void foo(void (__cdecl *fn_ptr)(void));
11131113 , &[_][]const u8{
1114 \\pub extern fn foo(fn_ptr: ?*const fn () callconv(.C) void) void;
1114 \\pub extern fn foo(fn_ptr: ?*const fn () callconv(.c) void) void;
11151115 });
11161116
11171117 cases.add("void cast",
......@@ -1477,8 +1477,8 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
14771477 \\typedef void (*fn0)();
14781478 \\typedef void (*fn1)(char);
14791479 , &[_][]const u8{
1480 \\pub const fn0 = ?*const fn (...) callconv(.C) void;
1481 \\pub const fn1 = ?*const fn (u8) callconv(.C) void;
1480 \\pub const fn0 = ?*const fn (...) callconv(.c) void;
1481 \\pub const fn1 = ?*const fn (u8) callconv(.c) void;
14821482 });
14831483
14841484 cases.addWithTarget("Calling convention", .{
......@@ -1492,11 +1492,11 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
14921492 \\void __attribute__((cdecl)) foo4(float *a);
14931493 \\void __attribute__((thiscall)) foo5(float *a);
14941494 , &[_][]const u8{
1495 \\pub extern fn foo1(a: [*c]f32) callconv(.Fastcall) void;
1496 \\pub extern fn foo2(a: [*c]f32) callconv(.Stdcall) void;
1497 \\pub extern fn foo3(a: [*c]f32) callconv(.Vectorcall) void;
1495 \\pub extern fn foo1(a: [*c]f32) callconv(.{ .x86_fastcall = .{} }) void;
1496 \\pub extern fn foo2(a: [*c]f32) callconv(.{ .x86_stdcall = .{} }) void;
1497 \\pub extern fn foo3(a: [*c]f32) callconv(.{ .x86_vectorcall = .{} }) void;
14981498 \\pub extern fn foo4(a: [*c]f32) void;
1499 \\pub extern fn foo5(a: [*c]f32) callconv(.Thiscall) void;
1499 \\pub extern fn foo5(a: [*c]f32) callconv(.{ .x86_thiscall = .{} }) void;
15001500 });
15011501
15021502 cases.addWithTarget("Calling convention", std.Target.Query.parse(.{
......@@ -1506,8 +1506,8 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
15061506 \\void __attribute__((pcs("aapcs"))) foo1(float *a);
15071507 \\void __attribute__((pcs("aapcs-vfp"))) foo2(float *a);
15081508 , &[_][]const u8{
1509 \\pub extern fn foo1(a: [*c]f32) callconv(.AAPCS) void;
1510 \\pub extern fn foo2(a: [*c]f32) callconv(.AAPCSVFP) void;
1509 \\pub extern fn foo1(a: [*c]f32) callconv(.{ .arm_aapcs = .{} }) void;
1510 \\pub extern fn foo2(a: [*c]f32) callconv(.{ .arm_aapcs_vfp = .{} }) void;
15111511 });
15121512
15131513 cases.addWithTarget("Calling convention", std.Target.Query.parse(.{
......@@ -1516,7 +1516,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
15161516 }) catch unreachable,
15171517 \\void __attribute__((aarch64_vector_pcs)) foo1(float *a);
15181518 , &[_][]const u8{
1519 \\pub extern fn foo1(a: [*c]f32) callconv(.Vectorcall) void;
1519 \\pub extern fn foo1(a: [*c]f32) callconv(.{ .aarch64_vfabi = .{} }) void;
15201520 });
15211521
15221522 cases.add("Parameterless function prototypes",
......@@ -1533,8 +1533,8 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
15331533 \\pub export fn b() void {}
15341534 \\pub extern fn c(...) void;
15351535 \\pub extern fn d() void;
1536 \\pub fn e() callconv(.C) void {}
1537 \\pub fn f() callconv(.C) void {}
1536 \\pub fn e() callconv(.c) void {}
1537 \\pub fn f() callconv(.c) void {}
15381538 \\pub extern fn g() void;
15391539 \\pub extern fn h() void;
15401540 });
......@@ -1555,7 +1555,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
15551555 \\ char *arr1[10] ={0};
15561556 \\}
15571557 , &[_][]const u8{
1558 \\pub fn foo() callconv(.C) void {
1558 \\pub fn foo() callconv(.c) void {
15591559 \\ var arr: [10]u8 = [1]u8{
15601560 \\ 1,
15611561 \\ } ++ [1]u8{0} ** 9;
......@@ -1686,13 +1686,13 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
16861686 \\extern char (*fn_ptr2)(int, float);
16871687 \\#define bar fn_ptr2
16881688 , &[_][]const u8{
1689 \\pub extern var fn_ptr: ?*const fn () callconv(.C) void;
1689 \\pub extern var fn_ptr: ?*const fn () callconv(.c) void;
16901690 ,
16911691 \\pub inline fn foo() void {
16921692 \\ return fn_ptr.?();
16931693 \\}
16941694 ,
1695 \\pub extern var fn_ptr2: ?*const fn (c_int, f32) callconv(.C) u8;
1695 \\pub extern var fn_ptr2: ?*const fn (c_int, f32) callconv(.c) u8;
16961696 ,
16971697 \\pub inline fn bar(arg_1: c_int, arg_2: f32) u8 {
16981698 \\ return fn_ptr2.?(arg_1, arg_2);
......@@ -1714,8 +1714,8 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
17141714 \\#define glClearPFN PFNGLCLEARPROC
17151715 , &[_][]const u8{
17161716 \\pub const GLbitfield = c_uint;
1717 \\pub const PFNGLCLEARPROC = ?*const fn (GLbitfield) callconv(.C) void;
1718 \\pub const OpenGLProc = ?*const fn () callconv(.C) void;
1717 \\pub const PFNGLCLEARPROC = ?*const fn (GLbitfield) callconv(.c) void;
1718 \\pub const OpenGLProc = ?*const fn () callconv(.c) void;
17191719 \\const struct_unnamed_1 = extern struct {
17201720 \\ Clear: PFNGLCLEARPROC = @import("std").mem.zeroes(PFNGLCLEARPROC),
17211721 \\};
......@@ -2691,9 +2691,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
26912691 \\ return 0;
26922692 \\}
26932693 \\pub export fn bar() void {
2694 \\ var f: ?*const fn () callconv(.C) void = &foo;
2694 \\ var f: ?*const fn () callconv(.c) void = &foo;
26952695 \\ _ = &f;
2696 \\ var b: ?*const fn () callconv(.C) c_int = &baz;
2696 \\ var b: ?*const fn () callconv(.c) c_int = &baz;
26972697 \\ _ = &b;
26982698 \\ f.?();
26992699 \\ f.?();
......@@ -3048,8 +3048,8 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
30483048 \\ baz();
30493049 \\}
30503050 , &[_][]const u8{
3051 \\pub fn bar() callconv(.C) void {}
3052 \\pub export fn foo(arg_baz: ?*const fn () callconv(.C) [*c]c_int) void {
3051 \\pub fn bar() callconv(.c) void {}
3052 \\pub export fn foo(arg_baz: ?*const fn () callconv(.c) [*c]c_int) void {
30533053 \\ var baz = arg_baz;
30543054 \\ _ = &baz;
30553055 \\ bar();
......@@ -3112,7 +3112,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
31123112 \\ do {} while (0);
31133113 \\}
31143114 , &[_][]const u8{
3115 \\pub fn foo() callconv(.C) void {
3115 \\pub fn foo() callconv(.c) void {
31163116 \\ if (true) while (true) {
31173117 \\ if (!false) break;
31183118 \\ };
......@@ -3212,10 +3212,10 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
32123212 \\void c(void) {}
32133213 \\static void foo() {}
32143214 , &[_][]const u8{
3215 \\pub fn a() callconv(.C) void {}
3216 \\pub fn b() callconv(.C) void {}
3215 \\pub fn a() callconv(.c) void {}
3216 \\pub fn b() callconv(.c) void {}
32173217 \\pub export fn c() void {}
3218 \\pub fn foo() callconv(.C) void {}
3218 \\pub fn foo() callconv(.c) void {}
32193219 });
32203220
32213221 cases.add("casting away const and volatile",