zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit 25096ed8936bb09e20589dda2bddeb09a24cfbaa (tree)
parent 8161e61548135dcbc2c3563a61b75c08c8f7cb2c
Author: Alex Rønne Petersen <alex@alexrp.com>
Date:   Wed,  7 Aug 2024 01:38:46 +0200

std.Target: Some corrections and additions to stackAlignment().

Sourced from LLVM and GCC backends and ABI documents.

Diffstat:
Mlib/std/Target.zig | 56++++++++++++++++++++++++++++++++------------------------
1 file changed, 32 insertions(+), 24 deletions(-)

diff --git a/lib/std/Target.zig b/lib/std/Target.zig @@ -1930,45 +1930,53 @@ pub fn ptrBitWidth(target: Target) u16 { } pub fn stackAlignment(target: Target) u16 { - return switch (target.cpu.arch) { - .m68k => 2, - .amdgcn => 4, - .x86 => switch (target.os.tag) { - .windows, .uefi => 4, - else => 16, - }, - .arm, - .armeb, - .thumb, - .thumbeb, + // Overrides for when the stack alignment is not equal to the pointer width. + switch (target.cpu.arch) { + .m68k, + => return 2, + .amdgcn, + => return 4, + .lanai, .mips, .mipsel, .sparc, - => 8, + => return 8, .aarch64, .aarch64_be, .bpfeb, .bpfel, + .loongarch32, + .loongarch64, .mips64, .mips64el, - .riscv64, .sparc64, - .x86_64, .ve, .wasm32, .wasm64, - .loongarch64, - => 16, - .riscv32, - => if (Target.riscv.featureSetHas(target.cpu.features, .e)) 4 else 16, - .powerpc64, - .powerpc64le, + => return 16, + // Some of the following prongs should really be testing the ABI (e.g. for Arm, it's APCS vs + // AAPCS16 vs AAPCS). But our current Abi enum is not able to handle that level of nuance. + .arm, + .armeb, + .thumb, + .thumbeb, => switch (target.os.tag) { - else => 8, - .linux => 16, + .netbsd => {}, + .watchos => return 16, + else => return 8, }, - else => @divExact(target.ptrBitWidth(), 8), - }; + .powerpc64, + .powerpc64le, + => if (target.os.tag == .linux or target.os.tag == .aix) return 16, + .riscv32, + .riscv64, + => if (!Target.riscv.featureSetHas(target.cpu.features, .e)) return 16, + .x86 => if (target.os.tag != .windows and target.os.tag != .uefi) return 16, + .x86_64 => return if (target.os.tag == .elfiamcu) 4 else 16, + else => {}, + } + + return @divExact(target.ptrBitWidth(), 8); } /// Default signedness of `char` for the native C compiler for this target