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 {...@@ -932,6 +932,7 @@ pub const Abi = enum {
932 .wiiu => .eabihf,932 .wiiu => .eabihf,
933 .gba => .eabi,933 .gba => .eabi,
934 .psx => .eabi,934 .psx => .eabi,
935 .ps3 => .ilp32,
935 .psp => .eabihf,936 .psp => .eabihf,
936 .vita => .eabihf,937 .vita => .eabihf,
937 .emscripten => .musl,938 .emscripten => .musl,
...@@ -951,7 +952,6 @@ pub const Abi = enum {...@@ -951,7 +952,6 @@ pub const Abi = enum {
951 .visionos,952 .visionos,
952 .watchos,953 .watchos,
953 .@"switch",954 .@"switch",
954 .ps3,
955 .ps4,955 .ps4,
956 .ps5,956 .ps5,
957 .amdhsa,957 .amdhsa,
...@@ -2135,6 +2135,7 @@ pub const Cpu = struct {...@@ -2135,6 +2135,7 @@ pub const Cpu = struct {
2135 .powerpc64 => switch (os.tag) {2135 .powerpc64 => switch (os.tag) {
2136 .linux, .freebsd => &powerpc.cpu.pwr8,2136 .linux, .freebsd => &powerpc.cpu.pwr8,
2137 .openbsd => &powerpc.cpu.pwr9,2137 .openbsd => &powerpc.cpu.pwr9,
2138 .ps3 => &powerpc.cpu.cell,
2138 else => generic(arch),2139 else => generic(arch),
2139 },2140 },
2140 .powerpc64le => &powerpc.cpu.ppc64le,2141 .powerpc64le => &powerpc.cpu.ppc64le,
...@@ -2468,6 +2469,9 @@ pub const DynamicLinker = struct {...@@ -2468,6 +2469,9 @@ pub const DynamicLinker = struct {
2468 .tvos,2469 .tvos,
2469 .visionos,2470 .visionos,
2470 .watchos,2471 .watchos,
2472
2473 .ps4,
2474 .ps5,
2471 => .arch_os,2475 => .arch_os,
24722476
2473 .hurd,2477 .hurd,
...@@ -2488,6 +2492,11 @@ pub const DynamicLinker = struct {...@@ -2488,6 +2492,11 @@ pub const DynamicLinker = struct {
2488 .@"switch",2492 .@"switch",
2489 .gba,2493 .gba,
24902494
2495 .psx,
2496 .ps3,
2497 .psp,
2498 .vita,
2499
2491 .emscripten,2500 .emscripten,
2492 .wasi,2501 .wasi,
24932502
...@@ -2500,13 +2509,6 @@ pub const DynamicLinker = struct {...@@ -2500,13 +2509,6 @@ pub const DynamicLinker = struct {
2500 .opengl,2509 .opengl,
2501 .vulkan,2510 .vulkan,
25022511
2503 .psx,
2504 .ps3,
2505 .ps4,
2506 .ps5,
2507 .psp,
2508 .vita,
2509
2510 .tios,2512 .tios,
2511 .ashetos,2513 .ashetos,
2512 => .none,2514 => .none,
...@@ -2909,8 +2911,10 @@ pub const DynamicLinker = struct {...@@ -2909,8 +2911,10 @@ pub const DynamicLinker = struct {
2909 else => none,2911 else => none,
2910 },2912 },
29112913
2912 // Operating systems in this list have been verified as not having a standard2914 .ps4,
2913 // dynamic linker path.2915 .ps5,
2916 => if (cpu.arch == .x86_64) init("/libexec/ld-elf.so.1") else none,
2917
2914 .freestanding,2918 .freestanding,
2915 .other,2919 .other,
29162920
...@@ -2926,6 +2930,7 @@ pub const DynamicLinker = struct {...@@ -2926,6 +2930,7 @@ pub const DynamicLinker = struct {
2926 .gba,2930 .gba,
29272931
2928 .psx,2932 .psx,
2933 .ps3,
2929 .psp,2934 .psp,
2930 .vita,2935 .vita,
29312936
...@@ -2944,13 +2949,6 @@ pub const DynamicLinker = struct {...@@ -2944,13 +2949,6 @@ pub const DynamicLinker = struct {
2944 .tios,2949 .tios,
2945 .ashetos,2950 .ashetos,
2946 => none,2951 => 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,
2954 } catch unreachable;2952 } catch unreachable;
2955 }2953 }
2956};2954};
...@@ -3137,38 +3135,39 @@ pub fn stackGrowth(target: *const Target) StackGrowth {...@@ -3137,38 +3135,39 @@ pub fn stackGrowth(target: *const Target) StackGrowth {
3137/// an option to override the default signedness e.g. GCC's -funsigned-char / -fsigned-char3135/// an option to override the default signedness e.g. GCC's -funsigned-char / -fsigned-char
3138/// Returns `null` if no C ABI is defined for this target.3136/// Returns `null` if no C ABI is defined for this target.
3139pub fn cCharSignedness(target: *const Target) ?std.builtin.Signedness {3137pub fn cCharSignedness(target: *const Target) ?std.builtin.Signedness {
3140 switch (target.os.tag) {3138 return switch (target.os.tag) {
3141 .opengl => return null,3139 .driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos => .signed,
3142 else => {},3140 .windows, .uefi => .signed,
3143 }3141 .ps3, .vita => .signed,
3144 if (target.os.tag.isDarwin() or target.os.tag == .windows or target.os.tag == .uefi) return .signed;3142 .opengl => null,
3145 return switch (target.cpu.arch) {3143 else => switch (target.cpu.arch) {
3146 .aarch64,3144 .aarch64,
3147 .aarch64_be,3145 .aarch64_be,
3148 .arm,3146 .arm,
3149 .armeb,3147 .armeb,
3150 .arc,3148 .arc,
3151 .arceb,3149 .arceb,
3152 .csky,3150 .csky,
3153 .ez80,3151 .ez80,
3154 .hexagon,3152 .hexagon,
3155 .msp430,3153 .msp430,
3156 .powerpc,3154 .powerpc,
3157 .powerpcle,3155 .powerpcle,
3158 .powerpc64,3156 .powerpc64,
3159 .powerpc64le,3157 .powerpc64le,
3160 .s390x,3158 .s390x,
3161 .riscv32,3159 .riscv32,
3162 .riscv32be,3160 .riscv32be,
3163 .riscv64,3161 .riscv64,
3164 .riscv64be,3162 .riscv64be,
3165 .thumb,3163 .thumb,
3166 .thumbeb,3164 .thumbeb,
3167 .xcore,3165 .xcore,
3168 .xtensa,3166 .xtensa,
3169 .xtensaeb,3167 .xtensaeb,
3170 => .unsigned,3168 => .unsigned,
3171 else => .signed,3169 else => .signed,
3170 },
3172 };3171 };
3173}3172}
31743173
...@@ -3204,6 +3203,7 @@ pub fn cTypeByteSize(t: *const Target, c_type: CType) ?u16 {...@@ -3204,6 +3203,7 @@ pub fn cTypeByteSize(t: *const Target, c_type: CType) ?u16 {
3204 => @divExact(cTypeBitSize(t, c_type) orelse return null, 8),3203 => @divExact(cTypeBitSize(t, c_type) orelse return null, 8),
32053204
3206 .longdouble => switch (cTypeBitSize(t, c_type) orelse return null) {3205 .longdouble => switch (cTypeBitSize(t, c_type) orelse return null) {
3206 32 => 4,
3207 64 => 8,3207 64 => 8,
3208 80 => @intCast(std.mem.alignForward(usize, 10, cTypeAlignment(t, c_type).?)),3208 80 => @intCast(std.mem.alignForward(usize, 10, cTypeAlignment(t, c_type).?)),
3209 128 => 16,3209 128 => 16,
...@@ -3240,30 +3240,6 @@ pub fn cTypeBitSize(target: *const Target, c_type: CType) ?u16 {...@@ -3240,30 +3240,6 @@ pub fn cTypeBitSize(target: *const Target, c_type: CType) ?u16 {
3240 .long, .ulong, .float => 32,3240 .long, .ulong, .float => 32,
3241 .double, .longdouble, .longlong, .ulonglong => 64,3241 .double, .longdouble, .longlong, .ulonglong => 64,
3242 },3242 },
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 },
3267 else => switch (c_type) {3243 else => switch (c_type) {
3268 .char => 8,3244 .char => 8,
3269 .short, .ushort => 16,3245 .short, .ushort => 16,
...@@ -3271,7 +3247,11 @@ pub fn cTypeBitSize(target: *const Target, c_type: CType) ?u16 {...@@ -3271,7 +3247,11 @@ pub fn cTypeBitSize(target: *const Target, c_type: CType) ?u16 {
3271 .long, .ulong => target.ptrBitWidth(),3247 .long, .ulong => target.ptrBitWidth(),
3272 .longlong, .ulonglong, .double => 64,3248 .longlong, .ulonglong, .double => 64,
3273 .longdouble => switch (target.cpu.arch) {3249 .longdouble => switch (target.cpu.arch) {
3274 .x86 => 80,3250 else => 64,
3251
3252 .x86,
3253 .x86_64,
3254 => 80,
32753255
3276 .alpha,3256 .alpha,
3277 .riscv32,3257 .riscv32,
...@@ -3280,11 +3260,14 @@ pub fn cTypeBitSize(target: *const Target, c_type: CType) ?u16 {...@@ -3280,11 +3260,14 @@ pub fn cTypeBitSize(target: *const Target, c_type: CType) ?u16 {
3280 .riscv64be,3260 .riscv64be,
3281 .aarch64,3261 .aarch64,
3282 .aarch64_be,3262 .aarch64_be,
3263 .mips64,
3264 .mips64el,
3283 .powerpc,3265 .powerpc,
3284 .powerpcle,3266 .powerpcle,
3285 .powerpc64,3267 .powerpc64,
3286 .powerpc64le,3268 .powerpc64le,
3287 .s390x,3269 .s390x,
3270 .sparc,
3288 .sparc64,3271 .sparc64,
3289 .wasm32,3272 .wasm32,
3290 .wasm64,3273 .wasm64,
...@@ -3292,13 +3275,12 @@ pub fn cTypeBitSize(target: *const Target, c_type: CType) ?u16 {...@@ -3292,13 +3275,12 @@ pub fn cTypeBitSize(target: *const Target, c_type: CType) ?u16 {
3292 .loongarch64,3275 .loongarch64,
3293 .ve,3276 .ve,
3294 => 128,3277 => 128,
3295
3296 else => 64,
3297 },3278 },
3298 },3279 },
3299 },3280 },
33003281
3301 .fuchsia,3282 .fuchsia,
3283 .managarm,
33023284
3303 .haiku,3285 .haiku,
3304 .hurd,3286 .hurd,
...@@ -3386,6 +3368,7 @@ pub fn cTypeBitSize(target: *const Target, c_type: CType) ?u16 {...@@ -3386,6 +3368,7 @@ pub fn cTypeBitSize(target: *const Target, c_type: CType) ?u16 {
3386 .s390x,3368 .s390x,
3387 .mips64,3369 .mips64,
3388 .mips64el,3370 .mips64el,
3371 .sparc,
3389 .sparc64,3372 .sparc64,
3390 .wasm32,3373 .wasm32,
3391 .wasm64,3374 .wasm64,
...@@ -3457,52 +3440,20 @@ pub fn cTypeBitSize(target: *const Target, c_type: CType) ?u16 {...@@ -3457,52 +3440,20 @@ pub fn cTypeBitSize(target: *const Target, c_type: CType) ?u16 {
3457 },3440 },
3458 },3441 },
34593442
3460 .nvcl, .cuda => switch (c_type) {3443 .cuda, .amdhsa, .amdpal, .mesa3d, .nvcl, .opencl, .vulkan => 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) {
3474 .char => 8,3444 .char => 8,
3475 .short, .ushort => 16,3445 .short, .ushort => 16,
3476 .int, .uint, .float => 32,3446 .int, .uint, .float => 32,
3477 .long, .ulong, .longlong, .ulonglong, .double => 64,3447 .long, .ulong => target.ptrBitWidth(),
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,
3496 .longlong, .ulonglong, .double, .longdouble => 64,3448 .longlong, .ulonglong, .double, .longdouble => 64,
3497 },3449 },
34983450
3499 .wiiu => switch (c_type) {3451 .gba, .@"3ds", .wiiu => switch (c_type) {
3500 .char => 8,3452 .char => 8,
3501 .short, .ushort => 16,3453 .short, .ushort => 16,
3502 .int, .uint, .float, .long, .ulong => 32,3454 .int, .uint, .float, .long, .ulong => 32,
3503 .longlong, .ulonglong, .double, .longdouble => 64,3455 .longlong, .ulonglong, .double, .longdouble => 64,
3504 },3456 },
3505
3506 .@"switch" => switch (c_type) {3457 .@"switch" => switch (c_type) {
3507 .char => 8,3458 .char => 8,
3508 .short, .ushort => 16,3459 .short, .ushort => 16,
...@@ -3511,14 +3462,7 @@ pub fn cTypeBitSize(target: *const Target, c_type: CType) ?u16 {...@@ -3511,14 +3462,7 @@ pub fn cTypeBitSize(target: *const Target, c_type: CType) ?u16 {
3511 .longdouble => 128,3462 .longdouble => 128,
3512 },3463 },
35133464
3514 .gba => switch (c_type) {3465 .psx, .ps3, .psp, .vita => 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) {
3522 .char => 8,3466 .char => 8,
3523 .short, .ushort => 16,3467 .short, .ushort => 16,
3524 .int, .uint, .long, .ulong, .float => 32,3468 .int, .uint, .long, .ulong, .float => 32,
...@@ -3528,17 +3472,10 @@ pub fn cTypeBitSize(target: *const Target, c_type: CType) ?u16 {...@@ -3528,17 +3472,10 @@ pub fn cTypeBitSize(target: *const Target, c_type: CType) ?u16 {
3528 .char => 8,3472 .char => 8,
3529 .short, .ushort => 16,3473 .short, .ushort => 16,
3530 .int, .uint, .float => 32,3474 .int, .uint, .float => 32,
3531 .long, .ulong => 64,3475 .long, .ulong, .longlong, .ulonglong, .double => 64,
3532 .longlong, .ulonglong, .double => 64,
3533 .longdouble => 80,3476 .longdouble => 80,
3534 },3477 },
3535 .psp, .vita => switch (c_type) {3478
3536 .char => 8,
3537 .short, .ushort => 16,
3538 .int, .uint, .float => 32,
3539 .long, .ulong => 64,
3540 .longlong, .ulonglong, .double, .longdouble => 64,
3541 },
3542 .tios => switch (c_type) {3479 .tios => switch (c_type) {
3543 .char => 8,3480 .char => 8,
3544 .short, .ushort => 16,3481 .short, .ushort => 16,
...@@ -3548,10 +3485,6 @@ pub fn cTypeBitSize(target: *const Target, c_type: CType) ?u16 {...@@ -3548,10 +3485,6 @@ pub fn cTypeBitSize(target: *const Target, c_type: CType) ?u16 {
3548 },3485 },
35493486
3550 .opengl => null,3487 .opengl => null,
3551
3552 .ps3,
3553 .managarm,
3554 => @panic("specify the C integer and float type sizes for this OS"),
3555 };3488 };
3556}3489}
35573490
...@@ -3608,8 +3541,6 @@ pub fn cTypeAlignment(target: *const Target, c_type: CType) ?u16 {...@@ -3608,8 +3541,6 @@ pub fn cTypeAlignment(target: *const Target, c_type: CType) ?u16 {
3608 .sheb,3541 .sheb,
3609 .x86,3542 .x86,
3610 .xcore,3543 .xcore,
3611 .xtensa,
3612 .xtensaeb,
3613 => 4,3544 => 4,
36143545
3615 .amdgcn,3546 .amdgcn,
...@@ -3630,6 +3561,8 @@ pub fn cTypeAlignment(target: *const Target, c_type: CType) ?u16 {...@@ -3630,6 +3561,8 @@ pub fn cTypeAlignment(target: *const Target, c_type: CType) ?u16 {
3630 .sparc,3561 .sparc,
3631 .thumb,3562 .thumb,
3632 .thumbeb,3563 .thumbeb,
3564 .xtensa,
3565 .xtensaeb,
3633 => 8,3566 => 8,
36343567
3635 .aarch64,3568 .aarch64,
lib/std/c.zig+1-1
...@@ -11294,7 +11294,7 @@ else if (native_os.isDarwin())...@@ -11294,7 +11294,7 @@ else if (native_os.isDarwin())
11294 c_longdouble11294 c_longdouble
11295else11295else
11296 extern struct {11296 extern struct {
11297 a: c_longlong,11297 a: c_longlong align(if (native_arch == .x86) 8 else @alignOf(c_longlong)),
11298 b: c_longdouble,11298 b: c_longdouble,
11299 };11299 };
1130011300
test/llvm_targets.zig+1-1
...@@ -206,7 +206,7 @@ const targets = [_]std.Target.Query{...@@ -206,7 +206,7 @@ const targets = [_]std.Target.Query{
206 .{ .cpu_arch = .powerpc64, .os_tag = .linux, .abi = .musl },206 .{ .cpu_arch = .powerpc64, .os_tag = .linux, .abi = .musl },
207 .{ .cpu_arch = .powerpc64, .os_tag = .linux, .abi = .none },207 .{ .cpu_arch = .powerpc64, .os_tag = .linux, .abi = .none },
208 .{ .cpu_arch = .powerpc64, .os_tag = .openbsd, .abi = .none },208 .{ .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 },
210 .{ .cpu_arch = .powerpc64, .os_tag = .rtems, .abi = .none },210 .{ .cpu_arch = .powerpc64, .os_tag = .rtems, .abi = .none },
211211
212 .{ .cpu_arch = .powerpc64le, .os_tag = .freebsd, .abi = .none },212 .{ .cpu_arch = .powerpc64le, .os_tag = .freebsd, .abi = .none },