authorgravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2026-10-17 05:21:17+02:00
committergravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2026-10-17 05:21:17+02:00
log9dd1d03c94fe7df997d13686dccdab2ff7420770
treede87c48d9946f01199e95fefbeb33c4be6ad6a58
parent1ab08d09cb123352ebc33e3510196ce95c9b7aa4
parenta6e456d746bc088a61958a982f331e1eec5c0687
signature Signed by SSH key SHA256:7B/LJ7bpR1eX8aCXSr4mtd5M45VMPKcx9zY8e95b5QM

Merge branch 'max-align-t'


3 files changed, 69 insertions(+), 136 deletions(-)

lib/std/Target.zig+67-134
......@@ -932,6 +932,7 @@ pub const Abi = enum {
932932 .wiiu => .eabihf,
933933 .gba => .eabi,
934934 .psx => .eabi,
935 .ps3 => .ilp32,
935936 .psp => .eabihf,
936937 .vita => .eabihf,
937938 .emscripten => .musl,
......@@ -951,7 +952,6 @@ pub const Abi = enum {
951952 .visionos,
952953 .watchos,
953954 .@"switch",
954 .ps3,
955955 .ps4,
956956 .ps5,
957957 .amdhsa,
......@@ -2135,6 +2135,7 @@ pub const Cpu = struct {
21352135 .powerpc64 => switch (os.tag) {
21362136 .linux, .freebsd => &powerpc.cpu.pwr8,
21372137 .openbsd => &powerpc.cpu.pwr9,
2138 .ps3 => &powerpc.cpu.cell,
21382139 else => generic(arch),
21392140 },
21402141 .powerpc64le => &powerpc.cpu.ppc64le,
......@@ -2468,6 +2469,9 @@ pub const DynamicLinker = struct {
24682469 .tvos,
24692470 .visionos,
24702471 .watchos,
2472
2473 .ps4,
2474 .ps5,
24712475 => .arch_os,
24722476
24732477 .hurd,
......@@ -2488,6 +2492,11 @@ pub const DynamicLinker = struct {
24882492 .@"switch",
24892493 .gba,
24902494
2495 .psx,
2496 .ps3,
2497 .psp,
2498 .vita,
2499
24912500 .emscripten,
24922501 .wasi,
24932502
......@@ -2500,13 +2509,6 @@ pub const DynamicLinker = struct {
25002509 .opengl,
25012510 .vulkan,
25022511
2503 .psx,
2504 .ps3,
2505 .ps4,
2506 .ps5,
2507 .psp,
2508 .vita,
2509
25102512 .tios,
25112513 .ashetos,
25122514 => .none,
......@@ -2909,8 +2911,10 @@ pub const DynamicLinker = struct {
29092911 else => none,
29102912 },
29112913
2912 // Operating systems in this list have been verified as not having a standard
2913 // dynamic linker path.
2914 .ps4,
2915 .ps5,
2916 => if (cpu.arch == .x86_64) init("/libexec/ld-elf.so.1") else none,
2917
29142918 .freestanding,
29152919 .other,
29162920
......@@ -2926,6 +2930,7 @@ pub const DynamicLinker = struct {
29262930 .gba,
29272931
29282932 .psx,
2933 .ps3,
29292934 .psp,
29302935 .vita,
29312936
......@@ -2944,13 +2949,6 @@ pub const DynamicLinker = struct {
29442949 .tios,
29452950 .ashetos,
29462951 => none,
2947
2948 // TODO go over each item in this list and either move it to the above list, or
2949 // implement the standard dynamic linker path code for it.
2950 .ps3,
2951 .ps4,
2952 .ps5,
2953 => none,
29542952 } catch unreachable;
29552953 }
29562954};
......@@ -3137,38 +3135,39 @@ pub fn stackGrowth(target: *const Target) StackGrowth {
31373135/// an option to override the default signedness e.g. GCC's -funsigned-char / -fsigned-char
31383136/// Returns `null` if no C ABI is defined for this target.
31393137pub fn cCharSignedness(target: *const Target) ?std.builtin.Signedness {
3140 switch (target.os.tag) {
3141 .opengl => return null,
3142 else => {},
3143 }
3144 if (target.os.tag.isDarwin() or target.os.tag == .windows or target.os.tag == .uefi) return .signed;
3145 return switch (target.cpu.arch) {
3146 .aarch64,
3147 .aarch64_be,
3148 .arm,
3149 .armeb,
3150 .arc,
3151 .arceb,
3152 .csky,
3153 .ez80,
3154 .hexagon,
3155 .msp430,
3156 .powerpc,
3157 .powerpcle,
3158 .powerpc64,
3159 .powerpc64le,
3160 .s390x,
3161 .riscv32,
3162 .riscv32be,
3163 .riscv64,
3164 .riscv64be,
3165 .thumb,
3166 .thumbeb,
3167 .xcore,
3168 .xtensa,
3169 .xtensaeb,
3170 => .unsigned,
3171 else => .signed,
3138 return switch (target.os.tag) {
3139 .driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos => .signed,
3140 .windows, .uefi => .signed,
3141 .ps3, .vita => .signed,
3142 .opengl => null,
3143 else => switch (target.cpu.arch) {
3144 .aarch64,
3145 .aarch64_be,
3146 .arm,
3147 .armeb,
3148 .arc,
3149 .arceb,
3150 .csky,
3151 .ez80,
3152 .hexagon,
3153 .msp430,
3154 .powerpc,
3155 .powerpcle,
3156 .powerpc64,
3157 .powerpc64le,
3158 .s390x,
3159 .riscv32,
3160 .riscv32be,
3161 .riscv64,
3162 .riscv64be,
3163 .thumb,
3164 .thumbeb,
3165 .xcore,
3166 .xtensa,
3167 .xtensaeb,
3168 => .unsigned,
3169 else => .signed,
3170 },
31723171 };
31733172}
31743173
......@@ -3204,6 +3203,7 @@ pub fn cTypeByteSize(t: *const Target, c_type: CType) ?u16 {
32043203 => @divExact(cTypeBitSize(t, c_type) orelse return null, 8),
32053204
32063205 .longdouble => switch (cTypeBitSize(t, c_type) orelse return null) {
3206 32 => 4,
32073207 64 => 8,
32083208 80 => @intCast(std.mem.alignForward(usize, 10, cTypeAlignment(t, c_type).?)),
32093209 128 => 16,
......@@ -3240,30 +3240,6 @@ pub fn cTypeBitSize(target: *const Target, c_type: CType) ?u16 {
32403240 .long, .ulong, .float => 32,
32413241 .double, .longdouble, .longlong, .ulonglong => 64,
32423242 },
3243 .mips64,
3244 .mips64el,
3245 => switch (c_type) {
3246 .char => 8,
3247 .short, .ushort => 16,
3248 .int, .uint, .float => 32,
3249 .long, .ulong => switch (target.abi) {
3250 .abin32 => 32,
3251 else => 64,
3252 },
3253 .longlong, .ulonglong, .double => 64,
3254 .longdouble => 128,
3255 },
3256 .x86_64 => switch (c_type) {
3257 .char => 8,
3258 .short, .ushort => 16,
3259 .int, .uint, .float => 32,
3260 .long, .ulong => switch (target.abi) {
3261 .x32 => 32,
3262 else => 64,
3263 },
3264 .longlong, .ulonglong, .double => 64,
3265 .longdouble => 80,
3266 },
32673243 else => switch (c_type) {
32683244 .char => 8,
32693245 .short, .ushort => 16,
......@@ -3271,7 +3247,11 @@ pub fn cTypeBitSize(target: *const Target, c_type: CType) ?u16 {
32713247 .long, .ulong => target.ptrBitWidth(),
32723248 .longlong, .ulonglong, .double => 64,
32733249 .longdouble => switch (target.cpu.arch) {
3274 .x86 => 80,
3250 else => 64,
3251
3252 .x86,
3253 .x86_64,
3254 => 80,
32753255
32763256 .alpha,
32773257 .riscv32,
......@@ -3280,11 +3260,14 @@ pub fn cTypeBitSize(target: *const Target, c_type: CType) ?u16 {
32803260 .riscv64be,
32813261 .aarch64,
32823262 .aarch64_be,
3263 .mips64,
3264 .mips64el,
32833265 .powerpc,
32843266 .powerpcle,
32853267 .powerpc64,
32863268 .powerpc64le,
32873269 .s390x,
3270 .sparc,
32883271 .sparc64,
32893272 .wasm32,
32903273 .wasm64,
......@@ -3292,13 +3275,12 @@ pub fn cTypeBitSize(target: *const Target, c_type: CType) ?u16 {
32923275 .loongarch64,
32933276 .ve,
32943277 => 128,
3295
3296 else => 64,
32973278 },
32983279 },
32993280 },
33003281
33013282 .fuchsia,
3283 .managarm,
33023284
33033285 .haiku,
33043286 .hurd,
......@@ -3386,6 +3368,7 @@ pub fn cTypeBitSize(target: *const Target, c_type: CType) ?u16 {
33863368 .s390x,
33873369 .mips64,
33883370 .mips64el,
3371 .sparc,
33893372 .sparc64,
33903373 .wasm32,
33913374 .wasm64,
......@@ -3457,52 +3440,20 @@ pub fn cTypeBitSize(target: *const Target, c_type: CType) ?u16 {
34573440 },
34583441 },
34593442
3460 .nvcl, .cuda => switch (c_type) {
3461 .char => 8,
3462 .short, .ushort => 16,
3463 .int, .uint, .float => 32,
3464 .long, .ulong => switch (target.cpu.arch) {
3465 .nvptx => 32,
3466 .nvptx64 => 64,
3467 else => 64,
3468 },
3469 .longlong, .ulonglong, .double => 64,
3470 .longdouble => 64,
3471 },
3472
3473 .amdhsa, .amdpal, .mesa3d => switch (c_type) {
3443 .cuda, .amdhsa, .amdpal, .mesa3d, .nvcl, .opencl, .vulkan => switch (c_type) {
34743444 .char => 8,
34753445 .short, .ushort => 16,
34763446 .int, .uint, .float => 32,
3477 .long, .ulong, .longlong, .ulonglong, .double => 64,
3478 .longdouble => 128,
3479 },
3480
3481 .opencl, .vulkan => switch (c_type) {
3482 .char => 8,
3483 .short, .ushort => 16,
3484 .int, .uint, .float => 32,
3485 .long, .ulong, .double => 64,
3486 .longlong, .ulonglong => 128,
3487 // Note: The OpenCL specification does not guarantee a particular size for long double,
3488 // but clang uses 128 bits.
3489 .longdouble => 128,
3490 },
3491
3492 .@"3ds" => switch (c_type) {
3493 .char => 8,
3494 .short, .ushort => 16,
3495 .int, .uint, .float, .long, .ulong => 32,
3447 .long, .ulong => target.ptrBitWidth(),
34963448 .longlong, .ulonglong, .double, .longdouble => 64,
34973449 },
34983450
3499 .wiiu => switch (c_type) {
3451 .gba, .@"3ds", .wiiu => switch (c_type) {
35003452 .char => 8,
35013453 .short, .ushort => 16,
35023454 .int, .uint, .float, .long, .ulong => 32,
35033455 .longlong, .ulonglong, .double, .longdouble => 64,
35043456 },
3505
35063457 .@"switch" => switch (c_type) {
35073458 .char => 8,
35083459 .short, .ushort => 16,
......@@ -3511,14 +3462,7 @@ pub fn cTypeBitSize(target: *const Target, c_type: CType) ?u16 {
35113462 .longdouble => 128,
35123463 },
35133464
3514 .gba => switch (c_type) {
3515 .char => return 8,
3516 .short, .ushort => return 16,
3517 .int, .uint, .long, .ulong, .float => return 32,
3518 .longlong, .ulonglong, .double, .longdouble => return 64,
3519 },
3520
3521 .psx => switch (c_type) {
3465 .psx, .ps3, .psp, .vita => switch (c_type) {
35223466 .char => 8,
35233467 .short, .ushort => 16,
35243468 .int, .uint, .long, .ulong, .float => 32,
......@@ -3528,17 +3472,10 @@ pub fn cTypeBitSize(target: *const Target, c_type: CType) ?u16 {
35283472 .char => 8,
35293473 .short, .ushort => 16,
35303474 .int, .uint, .float => 32,
3531 .long, .ulong => 64,
3532 .longlong, .ulonglong, .double => 64,
3475 .long, .ulong, .longlong, .ulonglong, .double => 64,
35333476 .longdouble => 80,
35343477 },
3535 .psp, .vita => switch (c_type) {
3536 .char => 8,
3537 .short, .ushort => 16,
3538 .int, .uint, .float => 32,
3539 .long, .ulong => 64,
3540 .longlong, .ulonglong, .double, .longdouble => 64,
3541 },
3478
35423479 .tios => switch (c_type) {
35433480 .char => 8,
35443481 .short, .ushort => 16,
......@@ -3548,10 +3485,6 @@ pub fn cTypeBitSize(target: *const Target, c_type: CType) ?u16 {
35483485 },
35493486
35503487 .opengl => null,
3551
3552 .ps3,
3553 .managarm,
3554 => @panic("specify the C integer and float type sizes for this OS"),
35553488 };
35563489}
35573490
......@@ -3608,8 +3541,6 @@ pub fn cTypeAlignment(target: *const Target, c_type: CType) ?u16 {
36083541 .sheb,
36093542 .x86,
36103543 .xcore,
3611 .xtensa,
3612 .xtensaeb,
36133544 => 4,
36143545
36153546 .amdgcn,
......@@ -3630,6 +3561,8 @@ pub fn cTypeAlignment(target: *const Target, c_type: CType) ?u16 {
36303561 .sparc,
36313562 .thumb,
36323563 .thumbeb,
3564 .xtensa,
3565 .xtensaeb,
36333566 => 8,
36343567
36353568 .aarch64,
lib/std/c.zig+1-1
......@@ -11294,7 +11294,7 @@ else if (native_os.isDarwin())
1129411294 c_longdouble
1129511295else
1129611296 extern struct {
11297 a: c_longlong,
11297 a: c_longlong align(if (native_arch == .x86) 8 else @alignOf(c_longlong)),
1129811298 b: c_longdouble,
1129911299 };
1130011300
test/llvm_targets.zig+1-1
......@@ -206,7 +206,7 @@ const targets = [_]std.Target.Query{
206206 .{ .cpu_arch = .powerpc64, .os_tag = .linux, .abi = .musl },
207207 .{ .cpu_arch = .powerpc64, .os_tag = .linux, .abi = .none },
208208 .{ .cpu_arch = .powerpc64, .os_tag = .openbsd, .abi = .none },
209 .{ .cpu_arch = .powerpc64, .os_tag = .ps3, .abi = .none },
209 .{ .cpu_arch = .powerpc64, .os_tag = .ps3, .abi = .ilp32 },
210210 .{ .cpu_arch = .powerpc64, .os_tag = .rtems, .abi = .none },
211211
212212 .{ .cpu_arch = .powerpc64le, .os_tag = .freebsd, .abi = .none },