| author | |
| committer | |
| log | 070276d8f16667233e9d3a450a4e8d6db9183958 |
| tree | 64ccaaaa5a547d9e47e25378bb44716650803f48 |
| parent | ccdb1afa6ef81e1390623377a672efabaad45ba7 |
11 files changed, 96 insertions(+), 1 deletions(-)
lib/std/Target.zig+6| ... | ... | @@ -1850,6 +1850,7 @@ pub const Cpu = struct { |
| 1850 | 1850 | .x86_64_vectorcall, |
| 1851 | 1851 | .x86_64_interrupt, |
| 1852 | 1852 | .x86_64_preserve_none, |
| 1853 | .x86_64_preserve_most, | |
| 1853 | 1854 | => &.{.x86_64}, |
| 1854 | 1855 | |
| 1855 | 1856 | .x86_sysv, |
| ... | ... | @@ -1877,6 +1878,7 @@ pub const Cpu = struct { |
| 1877 | 1878 | .aarch64_vfabi, |
| 1878 | 1879 | .aarch64_vfabi_sve, |
| 1879 | 1880 | .aarch64_preserve_none, |
| 1881 | .aarch64_preserve_most, | |
| 1880 | 1882 | => &.{ .aarch64, .aarch64_be }, |
| 1881 | 1883 | |
| 1882 | 1884 | .alpha_osf, |
| ... | ... | @@ -1899,11 +1901,13 @@ pub const Cpu = struct { |
| 1899 | 1901 | .riscv64_lp64, |
| 1900 | 1902 | .riscv64_lp64_v, |
| 1901 | 1903 | .riscv64_interrupt, |
| 1904 | .riscv64_preserve_most, | |
| 1902 | 1905 | => &.{ .riscv64, .riscv64be }, |
| 1903 | 1906 | |
| 1904 | 1907 | .riscv32_ilp32, |
| 1905 | 1908 | .riscv32_ilp32_v, |
| 1906 | 1909 | .riscv32_interrupt, |
| 1910 | .riscv32_preserve_most, | |
| 1907 | 1911 | => &.{ .riscv32, .riscv32be }, |
| 1908 | 1912 | |
| 1909 | 1913 | .sparc64_sysv, |
| ... | ... | @@ -1962,10 +1966,12 @@ pub const Cpu = struct { |
| 1962 | 1966 | |
| 1963 | 1967 | .loongarch64_lp64, |
| 1964 | 1968 | .loongarch64_preserve_none, |
| 1969 | .loongarch64_preserve_most, | |
| 1965 | 1970 | => &.{.loongarch64}, |
| 1966 | 1971 | |
| 1967 | 1972 | .loongarch32_ilp32, |
| 1968 | 1973 | .loongarch32_preserve_none, |
| 1974 | .loongarch32_preserve_most, | |
| 1969 | 1975 | => &.{.loongarch32}, |
| 1970 | 1976 | |
| 1971 | 1977 | .m68k_sysv, |
lib/std/lang.zig+6| ... | ... | @@ -209,6 +209,7 @@ pub const CallingConvention = union(enum(u8)) { |
| 209 | 209 | x86_64_vectorcall: CommonOptions, |
| 210 | 210 | x86_64_interrupt: CommonOptions, |
| 211 | 211 | x86_64_preserve_none: CommonOptions, |
| 212 | x86_64_preserve_most: CommonOptions, | |
| 212 | 213 | |
| 213 | 214 | // Calling conventions for the `x86` architecture. |
| 214 | 215 | x86_sysv: X86RegparmOptions, |
| ... | ... | @@ -237,6 +238,7 @@ pub const CallingConvention = union(enum(u8)) { |
| 237 | 238 | aarch64_vfabi: CommonOptions, |
| 238 | 239 | aarch64_vfabi_sve: CommonOptions, |
| 239 | 240 | aarch64_preserve_none: CommonOptions, |
| 241 | aarch64_preserve_most: CommonOptions, | |
| 240 | 242 | |
| 241 | 243 | /// The standard `alpha` calling convention. |
| 242 | 244 | alpha_osf: CommonOptions, |
| ... | ... | @@ -261,11 +263,13 @@ pub const CallingConvention = union(enum(u8)) { |
| 261 | 263 | riscv64_lp64: CommonOptions, |
| 262 | 264 | riscv64_lp64_v: CommonOptions, |
| 263 | 265 | riscv64_interrupt: RiscvInterruptOptions, |
| 266 | riscv64_preserve_most: CommonOptions, | |
| 264 | 267 | |
| 265 | 268 | // Calling conventions for the `riscv32` architecture. |
| 266 | 269 | riscv32_ilp32: CommonOptions, |
| 267 | 270 | riscv32_ilp32_v: CommonOptions, |
| 268 | 271 | riscv32_interrupt: RiscvInterruptOptions, |
| 272 | riscv32_preserve_most: CommonOptions, | |
| 269 | 273 | |
| 270 | 274 | // Calling conventions for the `sparc64` architecture. |
| 271 | 275 | sparc64_sysv: CommonOptions, |
| ... | ... | @@ -323,10 +327,12 @@ pub const CallingConvention = union(enum(u8)) { |
| 323 | 327 | /// The standard `loongarch64` calling convention. |
| 324 | 328 | loongarch64_lp64: CommonOptions, |
| 325 | 329 | loongarch64_preserve_none: CommonOptions, |
| 330 | loongarch64_preserve_most: CommonOptions, | |
| 326 | 331 | |
| 327 | 332 | /// The standard `loongarch32` calling convention. |
| 328 | 333 | loongarch32_ilp32: CommonOptions, |
| 329 | 334 | loongarch32_preserve_none: CommonOptions, |
| 335 | loongarch32_preserve_most: CommonOptions, | |
| 330 | 336 | |
| 331 | 337 | // Calling conventions for the `m68k` architecture. |
| 332 | 338 | m68k_sysv: CommonOptions, |
src/Zcu.zig+6| ... | ... | @@ -4683,6 +4683,7 @@ pub fn callconvSupported(zcu: *Zcu, cc: std.lang.CallingConvention) union(enum) |
| 4683 | 4683 | .x86_64_regcall_v4_win, |
| 4684 | 4684 | .x86_64_interrupt, |
| 4685 | 4685 | .x86_64_preserve_none, |
| 4686 | .x86_64_preserve_most, | |
| 4686 | 4687 | .x86_fastcall, |
| 4687 | 4688 | .x86_thiscall, |
| 4688 | 4689 | .x86_vectorcall, |
| ... | ... | @@ -4692,6 +4693,7 @@ pub fn callconvSupported(zcu: *Zcu, cc: std.lang.CallingConvention) union(enum) |
| 4692 | 4693 | .aarch64_vfabi, |
| 4693 | 4694 | .aarch64_vfabi_sve, |
| 4694 | 4695 | .aarch64_preserve_none, |
| 4696 | .aarch64_preserve_most, | |
| 4695 | 4697 | .arm_aapcs, |
| 4696 | 4698 | .csky_interrupt, |
| 4697 | 4699 | .riscv64_lp64_v, |
| ... | ... | @@ -4713,6 +4715,10 @@ pub fn callconvSupported(zcu: *Zcu, cc: std.lang.CallingConvention) union(enum) |
| 4713 | 4715 | .ez80_tiflags, |
| 4714 | 4716 | .loongarch32_preserve_none, |
| 4715 | 4717 | .loongarch64_preserve_none, |
| 4718 | .riscv32_preserve_most, | |
| 4719 | .riscv64_preserve_most, | |
| 4720 | .loongarch32_preserve_most, | |
| 4721 | .loongarch64_preserve_most, | |
| 4716 | 4722 | .naked, |
| 4717 | 4723 | => true, // incoming stack alignment supported |
| 4718 | 4724 |
src/codegen/c/type.zig+9| ... | ... | @@ -63,6 +63,7 @@ pub const CType = union(enum) { |
| 63 | 63 | regcall, |
| 64 | 64 | |
| 65 | 65 | preserve_none, |
| 66 | preserve_most, | |
| 66 | 67 | |
| 67 | 68 | aarch64_vector_pcs, |
| 68 | 69 | aarch64_sve_pcs, |
| ... | ... | @@ -146,6 +147,14 @@ pub const CType = union(enum) { |
| 146 | 147 | .loongarch64_preserve_none, |
| 147 | 148 | => .preserve_none, |
| 148 | 149 | |
| 150 | .x86_64_preserve_most, | |
| 151 | .aarch64_preserve_most, | |
| 152 | .riscv32_preserve_most, | |
| 153 | .riscv64_preserve_most, | |
| 154 | .loongarch32_preserve_most, | |
| 155 | .loongarch64_preserve_most, | |
| 156 | => .preserve_most, | |
| 157 | ||
| 149 | 158 | .aarch64_vfabi => .aarch64_vector_pcs, |
| 150 | 159 | .aarch64_vfabi_sve => .aarch64_sve_pcs, |
| 151 | 160 |
src/codegen/llvm.zig+6| ... | ... | @@ -4304,6 +4304,7 @@ pub fn toLlvmCallConvTag(cc_tag: std.lang.CallingConvention.Tag, target: *const |
| 4304 | 4304 | .x86_64_vectorcall => .x86_vectorcallcc, |
| 4305 | 4305 | .x86_64_interrupt => .x86_intrcc, |
| 4306 | 4306 | .x86_64_preserve_none => .preserve_nonecc, |
| 4307 | .x86_64_preserve_most => .preserve_mostcc, | |
| 4307 | 4308 | .x86_stdcall => .x86_stdcallcc, |
| 4308 | 4309 | .x86_fastcall => .x86_fastcallcc, |
| 4309 | 4310 | .x86_thiscall => .x86_thiscallcc, |
| ... | ... | @@ -4320,6 +4321,7 @@ pub fn toLlvmCallConvTag(cc_tag: std.lang.CallingConvention.Tag, target: *const |
| 4320 | 4321 | .aarch64_vfabi => .aarch64_vector_pcs, |
| 4321 | 4322 | .aarch64_vfabi_sve => .aarch64_sve_vector_pcs, |
| 4322 | 4323 | .aarch64_preserve_none => .preserve_nonecc, |
| 4324 | .aarch64_preserve_most => .preserve_mostcc, | |
| 4323 | 4325 | .arm_aapcs => .arm_aapcscc, |
| 4324 | 4326 | .arm_aapcs_vfp => .arm_aapcs_vfpcc, |
| 4325 | 4327 | .riscv64_lp64_v => .riscv_vectorcallcc, |
| ... | ... | @@ -4336,6 +4338,10 @@ pub fn toLlvmCallConvTag(cc_tag: std.lang.CallingConvention.Tag, target: *const |
| 4336 | 4338 | .nvptx_kernel => .ptx_kernel, |
| 4337 | 4339 | .loongarch32_preserve_none => .preserve_nonecc, |
| 4338 | 4340 | .loongarch64_preserve_none => .preserve_nonecc, |
| 4341 | .riscv32_preserve_most => .preserve_mostcc, | |
| 4342 | .riscv64_preserve_most => .preserve_mostcc, | |
| 4343 | .loongarch32_preserve_most => .preserve_mostcc, | |
| 4344 | .loongarch64_preserve_most => .preserve_mostcc, | |
| 4339 | 4345 | |
| 4340 | 4346 | // Calling conventions which LLVM uses function attributes for. |
| 4341 | 4347 | .riscv64_interrupt, |
src/link/Dwarf.zig+7| ... | ... | @@ -4167,6 +4167,7 @@ fn updateConstInner(dwarf: *Dwarf, pt: Zcu.PerThread, debug_const_index: link.Co |
| 4167 | 4167 | .x86_64_vectorcall => .LLVM_vectorcall, |
| 4168 | 4168 | .x86_sysv, .x86_win, .x86_mingw => .normal, |
| 4169 | 4169 | .x86_64_preserve_none => .LLVM_PreserveNone, |
| 4170 | .x86_64_preserve_most => .LLVM_PreserveMost, | |
| 4170 | 4171 | .x86_stdcall => .BORLAND_stdcall, |
| 4171 | 4172 | .x86_fastcall => .BORLAND_msfastcall, |
| 4172 | 4173 | .x86_thiscall => .BORLAND_thiscall, |
| ... | ... | @@ -4181,6 +4182,7 @@ fn updateConstInner(dwarf: *Dwarf, pt: Zcu.PerThread, debug_const_index: link.Co |
| 4181 | 4182 | .aarch64_vfabi => .LLVM_AAPCS, |
| 4182 | 4183 | .aarch64_vfabi_sve => .LLVM_AAPCS, |
| 4183 | 4184 | .aarch64_preserve_none => .LLVM_PreserveNone, |
| 4185 | .aarch64_preserve_most => .LLVM_PreserveMost, | |
| 4184 | 4186 | |
| 4185 | 4187 | .arm_aapcs => .LLVM_AAPCS, |
| 4186 | 4188 | .arm_aapcs_vfp => .LLVM_AAPCS_VFP, |
| ... | ... | @@ -4192,6 +4194,11 @@ fn updateConstInner(dwarf: *Dwarf, pt: Zcu.PerThread, debug_const_index: link.Co |
| 4192 | 4194 | .loongarch32_preserve_none => .LLVM_PreserveNone, |
| 4193 | 4195 | .loongarch64_preserve_none => .LLVM_PreserveNone, |
| 4194 | 4196 | |
| 4197 | .riscv32_preserve_most => .LLVM_PreserveMost, | |
| 4198 | .riscv64_preserve_most => .LLVM_PreserveMost, | |
| 4199 | .loongarch32_preserve_most => .LLVM_PreserveMost, | |
| 4200 | .loongarch64_preserve_most => .LLVM_PreserveMost, | |
| 4201 | ||
| 4195 | 4202 | .m68k_rtd => .LLVM_M68kRTD, |
| 4196 | 4203 | |
| 4197 | 4204 | .sh_renesas => .GNU_renesas_sh, |
src/link/Dwarf2.zig+2| ... | ... | @@ -3276,6 +3276,7 @@ fn updateConstInner( |
| 3276 | 3276 | .x86_64_vectorcall => .LLVM_vectorcall, |
| 3277 | 3277 | .x86_sysv, .x86_win, .x86_mingw => .normal, |
| 3278 | 3278 | .x86_64_preserve_none => .LLVM_PreserveNone, |
| 3279 | .x86_64_preserve_most => .LLVM_PreserveMost, | |
| 3279 | 3280 | .x86_stdcall => .BORLAND_stdcall, |
| 3280 | 3281 | .x86_fastcall => .BORLAND_msfastcall, |
| 3281 | 3282 | .x86_thiscall => .BORLAND_thiscall, |
| ... | ... | @@ -3290,6 +3291,7 @@ fn updateConstInner( |
| 3290 | 3291 | .aarch64_vfabi => .LLVM_AAPCS, |
| 3291 | 3292 | .aarch64_vfabi_sve => .LLVM_AAPCS, |
| 3292 | 3293 | .aarch64_preserve_none => .LLVM_PreserveNone, |
| 3294 | .aarch64_preserve_most => .LLVM_PreserveMost, | |
| 3293 | 3295 | |
| 3294 | 3296 | .arm_aapcs => .LLVM_AAPCS, |
| 3295 | 3297 | .arm_aapcs_vfp => .LLVM_AAPCS_VFP, |
test/c_abi/cfuncs.c+10| ... | ... | @@ -16700,6 +16700,16 @@ void c_preserve_none_check(void) { |
| 16700 | 16700 | } |
| 16701 | 16701 | #endif |
| 16702 | 16702 | |
| 16703 | #if defined __x86_64__ || defined __aarch64__ || defined __riscv || defined __loongarch__ | |
| 16704 | int __attribute__((preserve_most)) c_preserve_most(int x) { | |
| 16705 | return x + 1; | |
| 16706 | } | |
| 16707 | int __attribute__((preserve_most)) zig_preserve_most(int); | |
| 16708 | void c_preserve_most_check(void) { | |
| 16709 | assert_or_panic(zig_preserve_most(41) == 42); | |
| 16710 | } | |
| 16711 | #endif | |
| 16712 | ||
| 16703 | 16713 | struct byval_tail_callsite_attr_Point { |
| 16704 | 16714 | double x; |
| 16705 | 16715 | double y; |
test/c_abi/main.zig+27| ... | ... | @@ -18162,3 +18162,30 @@ test "preserve_none calling convention" { |
| 18162 | 18162 | try expect(static.c_preserve_none(41) == 42); |
| 18163 | 18163 | static.c_preserve_none_check(); |
| 18164 | 18164 | } |
| 18165 | ||
| 18166 | const preserve_most_cc: ?std.lang.CallingConvention = if (builtin.zig_backend != .stage2_llvm) | |
| 18167 | null | |
| 18168 | else switch (builtin.cpu.arch) { | |
| 18169 | .x86_64 => .{ .x86_64_preserve_most = .{} }, | |
| 18170 | .aarch64, .aarch64_be => .{ .aarch64_preserve_most = .{} }, | |
| 18171 | // Supported in LLVM but not yet wired up in Clang. | |
| 18172 | // .riscv32, .riscv32be => .{ .riscv32_preserve_most = .{} }, | |
| 18173 | // .riscv64, .riscv64be => .{ .riscv64_preserve_most = .{} }, | |
| 18174 | // .loongarch32 => .{ .loongarch32_preserve_most = .{} }, | |
| 18175 | // .loongarch64 => .{ .loongarch64_preserve_most = .{} }, | |
| 18176 | else => null, | |
| 18177 | }; | |
| 18178 | ||
| 18179 | export fn zig_preserve_most(x: i32) callconv(preserve_most_cc orelse .c) i32 { | |
| 18180 | return x + 1; | |
| 18181 | } | |
| 18182 | ||
| 18183 | test "preserve_most calling convention" { | |
| 18184 | if (preserve_most_cc == null) return error.SkipZigTest; | |
| 18185 | const static = struct { | |
| 18186 | extern fn c_preserve_most(x: i32) callconv(preserve_most_cc.?) i32; | |
| 18187 | extern fn c_preserve_most_check() void; | |
| 18188 | }; | |
| 18189 | try expect(static.c_preserve_most(41) == 42); | |
| 18190 | static.c_preserve_most_check(); | |
| 18191 | } |
test/cases/compile_errors/callconv_preserve_most_on_unsupported_platform.zig created+16| ... | ... | @@ -0,0 +1,16 @@ |
| 1 | const F1 = fn () callconv(.{ .x86_64_preserve_most = .{} }) void; | |
| 2 | const F2 = fn () callconv(.{ .aarch64_preserve_most = .{} }) 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=wasm32-freestanding | |
| 14 | // | |
| 15 | // :1:28: error: calling convention 'x86_64_preserve_most' only available on architectures 'x86_64' | |
| 16 | // :2:28: error: calling convention 'aarch64_preserve_most' only available on architectures 'aarch64', 'aarch64_be' |
test/cases/compile_errors/callconv_preserve_none_on_unsupported_platform.zig+1-1| ... | ... | @@ -10,7 +10,7 @@ export fn entry2() void { |
| 10 | 10 | } |
| 11 | 11 | |
| 12 | 12 | // error |
| 13 | // target=riscv64-linux-none | |
| 13 | // target=wasm32-freestanding | |
| 14 | 14 | // |
| 15 | 15 | // :1:28: error: calling convention 'x86_64_preserve_none' only available on architectures 'x86_64' |
| 16 | 16 | // :2:28: error: calling convention 'aarch64_preserve_none' only available on architectures 'aarch64', 'aarch64_be' |