| author | |
| committer | |
| log | bb296ab9b9752893eb362ed951c4ce344214eb96 |
| tree | dbf68b07b7bd48f7822d79ceb86def073e111e9f |
| parent | bdb1e9c9cf97520e41c8aff94553d5140a79dac7 |
std declarations, llvm lowering, c_abi test, compiler warning test
Co-authored-by: yarn <aethnem@gmail.com>10 files changed, 66 insertions(+), 0 deletions(-)
lib/std/Target.zig+2| ... | ... | @@ -1793,6 +1793,7 @@ pub const Cpu = struct { |
| 1793 | 1793 | .x86_64_regcall_v4_win, |
| 1794 | 1794 | .x86_64_vectorcall, |
| 1795 | 1795 | .x86_64_interrupt, |
| 1796 | .x86_64_preserve_none, | |
| 1796 | 1797 | => &.{.x86_64}, |
| 1797 | 1798 | |
| 1798 | 1799 | .x86_sysv, |
| ... | ... | @@ -1819,6 +1820,7 @@ pub const Cpu = struct { |
| 1819 | 1820 | .aarch64_aapcs_win, |
| 1820 | 1821 | .aarch64_vfabi, |
| 1821 | 1822 | .aarch64_vfabi_sve, |
| 1823 | .aarch64_preserve_none, | |
| 1822 | 1824 | => &.{ .aarch64, .aarch64_be }, |
| 1823 | 1825 | |
| 1824 | 1826 | .alpha_osf, |
lib/std/lang.zig+2| ... | ... | @@ -210,6 +210,7 @@ pub const CallingConvention = union(enum(u8)) { |
| 210 | 210 | x86_64_regcall_v4_win: CommonOptions, |
| 211 | 211 | x86_64_vectorcall: CommonOptions, |
| 212 | 212 | x86_64_interrupt: CommonOptions, |
| 213 | x86_64_preserve_none: CommonOptions, | |
| 213 | 214 | |
| 214 | 215 | // Calling conventions for the `x86` architecture. |
| 215 | 216 | x86_sysv: X86RegparmOptions, |
| ... | ... | @@ -237,6 +238,7 @@ pub const CallingConvention = union(enum(u8)) { |
| 237 | 238 | aarch64_aapcs_win: CommonOptions, |
| 238 | 239 | aarch64_vfabi: CommonOptions, |
| 239 | 240 | aarch64_vfabi_sve: CommonOptions, |
| 241 | aarch64_preserve_none: CommonOptions, | |
| 240 | 242 | |
| 241 | 243 | /// The standard `alpha` calling convention. |
| 242 | 244 | alpha_osf: CommonOptions, |
lib/std/zig/llvm/Builder.zig+2| ... | ... | @@ -2749,6 +2749,7 @@ pub const CallConv = enum(u10) { |
| 2749 | 2749 | tailcc, |
| 2750 | 2750 | cfguard_checkcc, |
| 2751 | 2751 | swifttailcc, |
| 2752 | preserve_nonecc, | |
| 2752 | 2753 | |
| 2753 | 2754 | x86_stdcallcc = 64, |
| 2754 | 2755 | x86_fastcallcc, |
| ... | ... | @@ -2817,6 +2818,7 @@ pub const CallConv = enum(u10) { |
| 2817 | 2818 | .tailcc, |
| 2818 | 2819 | .cfguard_checkcc, |
| 2819 | 2820 | .swifttailcc, |
| 2821 | .preserve_nonecc, | |
| 2820 | 2822 | .x86_stdcallcc, |
| 2821 | 2823 | .x86_fastcallcc, |
| 2822 | 2824 | .arm_apcscc, |
src/Zcu.zig+2| ... | ... | @@ -4602,6 +4602,7 @@ pub fn callconvSupported(zcu: *Zcu, cc: std.lang.CallingConvention) union(enum) |
| 4602 | 4602 | .x86_64_regcall_v3_sysv, |
| 4603 | 4603 | .x86_64_regcall_v4_win, |
| 4604 | 4604 | .x86_64_interrupt, |
| 4605 | .x86_64_preserve_none, | |
| 4605 | 4606 | .x86_fastcall, |
| 4606 | 4607 | .x86_thiscall, |
| 4607 | 4608 | .x86_vectorcall, |
| ... | ... | @@ -4610,6 +4611,7 @@ pub fn callconvSupported(zcu: *Zcu, cc: std.lang.CallingConvention) union(enum) |
| 4610 | 4611 | .x86_interrupt, |
| 4611 | 4612 | .aarch64_vfabi, |
| 4612 | 4613 | .aarch64_vfabi_sve, |
| 4614 | .aarch64_preserve_none, | |
| 4613 | 4615 | .arm_aapcs, |
| 4614 | 4616 | .csky_interrupt, |
| 4615 | 4617 | .riscv64_lp64_v, |
src/codegen/c/type.zig+6| ... | ... | @@ -62,6 +62,8 @@ pub const CType = union(enum) { |
| 62 | 62 | |
| 63 | 63 | regcall, |
| 64 | 64 | |
| 65 | preserve_none, | |
| 66 | ||
| 65 | 67 | aarch64_vector_pcs, |
| 66 | 68 | aarch64_sve_pcs, |
| 67 | 69 | |
| ... | ... | @@ -138,6 +140,10 @@ pub const CType = union(enum) { |
| 138 | 140 | .x86_regcall_v4_win, |
| 139 | 141 | => .regcall, |
| 140 | 142 | |
| 143 | .x86_64_preserve_none, | |
| 144 | .aarch64_preserve_none, | |
| 145 | => .preserve_none, | |
| 146 | ||
| 141 | 147 | .aarch64_vfabi => .aarch64_vector_pcs, |
| 142 | 148 | .aarch64_vfabi_sve => .aarch64_sve_pcs, |
| 143 | 149 |
src/codegen/llvm.zig+2| ... | ... | @@ -4558,6 +4558,7 @@ pub fn toLlvmCallConvTag(cc_tag: std.lang.CallingConvention.Tag, target: *const |
| 4558 | 4558 | null, |
| 4559 | 4559 | .x86_64_vectorcall => .x86_vectorcallcc, |
| 4560 | 4560 | .x86_64_interrupt => .x86_intrcc, |
| 4561 | .x86_64_preserve_none => .preserve_nonecc, | |
| 4561 | 4562 | .x86_stdcall => .x86_stdcallcc, |
| 4562 | 4563 | .x86_fastcall => .x86_fastcallcc, |
| 4563 | 4564 | .x86_thiscall => .x86_thiscallcc, |
| ... | ... | @@ -4573,6 +4574,7 @@ pub fn toLlvmCallConvTag(cc_tag: std.lang.CallingConvention.Tag, target: *const |
| 4573 | 4574 | .x86_interrupt => .x86_intrcc, |
| 4574 | 4575 | .aarch64_vfabi => .aarch64_vector_pcs, |
| 4575 | 4576 | .aarch64_vfabi_sve => .aarch64_sve_vector_pcs, |
| 4577 | .aarch64_preserve_none => .preserve_nonecc, | |
| 4576 | 4578 | .arm_aapcs => .arm_aapcscc, |
| 4577 | 4579 | .arm_aapcs_vfp => .arm_aapcs_vfpcc, |
| 4578 | 4580 | .riscv64_lp64_v => .riscv_vectorcallcc, |
src/link/Dwarf.zig+2| ... | ... | @@ -4152,6 +4152,7 @@ fn updateConstInner(dwarf: *Dwarf, pt: Zcu.PerThread, debug_const_index: link.Co |
| 4152 | 4152 | .x86_64_regcall_v4_win => .LLVM_X86RegCall, |
| 4153 | 4153 | .x86_64_vectorcall => .LLVM_vectorcall, |
| 4154 | 4154 | .x86_sysv, .x86_win, .x86_mingw => .normal, |
| 4155 | .x86_64_preserve_none => .LLVM_PreserveNone, | |
| 4155 | 4156 | .x86_stdcall => .BORLAND_stdcall, |
| 4156 | 4157 | .x86_fastcall => .BORLAND_msfastcall, |
| 4157 | 4158 | .x86_thiscall => .BORLAND_thiscall, |
| ... | ... | @@ -4165,6 +4166,7 @@ fn updateConstInner(dwarf: *Dwarf, pt: Zcu.PerThread, debug_const_index: link.Co |
| 4165 | 4166 | .aarch64_aapcs_win => .normal, |
| 4166 | 4167 | .aarch64_vfabi => .LLVM_AAPCS, |
| 4167 | 4168 | .aarch64_vfabi_sve => .LLVM_AAPCS, |
| 4169 | .aarch64_preserve_none => .LLVM_PreserveNone, | |
| 4168 | 4170 | |
| 4169 | 4171 | .arm_aapcs => .LLVM_AAPCS, |
| 4170 | 4172 | .arm_aapcs_vfp => .LLVM_AAPCS_VFP, |
test/c_abi/cfuncs.c+10| ... | ... | @@ -16488,6 +16488,16 @@ struct ByRef __attribute__((sysv_abi)) c_explict_sys_v(struct ByRef in) { |
| 16488 | 16488 | } |
| 16489 | 16489 | #endif |
| 16490 | 16490 | |
| 16491 | #if defined __x86_64__ || defined __aarch64__ | |
| 16492 | int __attribute__((preserve_none)) c_preserve_none(int x) { | |
| 16493 | return x + 1; | |
| 16494 | } | |
| 16495 | int __attribute__((preserve_none)) zig_preserve_none(int); | |
| 16496 | void c_preserve_none_check(void) { | |
| 16497 | assert_or_panic(zig_preserve_none(41) == 42); | |
| 16498 | } | |
| 16499 | #endif | |
| 16500 | ||
| 16491 | 16501 | struct byval_tail_callsite_attr_Point { |
| 16492 | 16502 | double x; |
| 16493 | 16503 | double y; |
test/c_abi/main.zig+22| ... | ... | @@ -17798,3 +17798,25 @@ test "win64 varargs" { |
| 17798 | 17798 | @as(Opv, .{}), |
| 17799 | 17799 | ); |
| 17800 | 17800 | } |
| 17801 | ||
| 17802 | const preserve_none_cc: ?std.lang.CallingConvention = if (builtin.zig_backend != .stage2_llvm) | |
| 17803 | null | |
| 17804 | else switch (builtin.cpu.arch) { | |
| 17805 | .x86_64 => .{ .x86_64_preserve_none = .{} }, | |
| 17806 | .aarch64, .aarch64_be => .{ .aarch64_preserve_none = .{} }, | |
| 17807 | else => null, | |
| 17808 | }; | |
| 17809 | ||
| 17810 | export fn zig_preserve_none(x: i32) callconv(preserve_none_cc orelse .c) i32 { | |
| 17811 | return x + 1; | |
| 17812 | } | |
| 17813 | ||
| 17814 | test "preserve_none calling convention" { | |
| 17815 | if (preserve_none_cc == null) return error.SkipZigTest; | |
| 17816 | const static = struct { | |
| 17817 | extern fn c_preserve_none(x: i32) callconv(preserve_none_cc.?) i32; | |
| 17818 | extern fn c_preserve_none_check() void; | |
| 17819 | }; | |
| 17820 | try expect(static.c_preserve_none(41) == 42); | |
| 17821 | static.c_preserve_none_check(); | |
| 17822 | } |
test/cases/compile_errors/callconv_preserve_none_on_unsupported_platform.zig created+16| ... | ... | @@ -0,0 +1,16 @@ |
| 1 | const F1 = fn () callconv(.{ .x86_64_preserve_none = .{} }) void; | |
| 2 | const F2 = fn () callconv(.{ .aarch64_preserve_none = .{} }) void; | |
| 3 | export fn entry1() void { | |
| 4 | const a: F1 = undefined; | |
| 5 | _ = a; | |
| 6 | } | |
| 7 | export fn entry2() void { | |
| 8 | const a: F2 = undefined; | |
| 9 | _ = a; | |
| 10 | } | |
| 11 | ||
| 12 | // error | |
| 13 | // target=riscv64-linux-none | |
| 14 | // | |
| 15 | // :1:28: error: calling convention 'x86_64_preserve_none' only available on architectures 'x86_64' | |
| 16 | // :2:28: error: calling convention 'aarch64_preserve_none' only available on architectures 'aarch64', 'aarch64_be' |