authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-08-06 14:55:15-07:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2024-08-06 14:55:15-07:00
logc8a226a42960297deb0b7bf270cc3ef3253f0c6d
tree835da0e073e0c76c0ec0e49a0ad5f3d7e59e0cc8
parentde1fb199091ef1b3ae53d4de0fc30fa958131c96
parentef502daafe2b4e216c68fe07ff05aa91d539b831
signaturebadge-check Signed by PGP key B5690EEEBB952194

Merge pull request #20960 from alexrp/size-align-fixes

`std.Target`: A bunch of C type size/alignment fixes

1 files changed, 21 insertions(+), 29 deletions(-)

lib/std/Target.zig+21-29
...@@ -1852,14 +1852,15 @@ pub fn ptrBitWidth_cpu_abi(cpu: Cpu, abi: Abi) u16 {...@@ -1852,14 +1852,15 @@ pub fn ptrBitWidth_cpu_abi(cpu: Cpu, abi: Abi) u16 {
1852 .kalimba,1852 .kalimba,
1853 .lanai,1853 .lanai,
1854 .wasm32,1854 .wasm32,
1855 .sparc,
1855 .spirv32,1856 .spirv32,
1856 .loongarch32,1857 .loongarch32,
1857 .dxil,
1858 .xtensa,1858 .xtensa,
1859 => 32,1859 => 32,
18601860
1861 .aarch64,1861 .aarch64,
1862 .aarch64_be,1862 .aarch64_be,
1863 .dxil,
1863 .mips64,1864 .mips64,
1864 .mips64el,1865 .mips64el,
1865 .powerpc64,1866 .powerpc64,
...@@ -1874,13 +1875,10 @@ pub fn ptrBitWidth_cpu_abi(cpu: Cpu, abi: Abi) u16 {...@@ -1874,13 +1875,10 @@ pub fn ptrBitWidth_cpu_abi(cpu: Cpu, abi: Abi) u16 {
1874 .sparc64,1875 .sparc64,
1875 .s390x,1876 .s390x,
1876 .ve,1877 .ve,
1878 .spirv,
1877 .spirv64,1879 .spirv64,
1878 .loongarch64,1880 .loongarch64,
1879 => 64,1881 => 64,
1880
1881 .sparc => if (std.Target.sparc.featureSetHas(cpu.features, .v9)) 64 else 32,
1882
1883 .spirv => @panic("TODO what should this value be?"),
1884 };1882 };
1885}1883}
18861884
...@@ -2061,12 +2059,12 @@ pub fn c_type_bit_size(target: Target, c_type: CType) u16 {...@@ -2061,12 +2059,12 @@ pub fn c_type_bit_size(target: Target, c_type: CType) u16 {
2061 .aarch64,2059 .aarch64,
2062 .aarch64_be,2060 .aarch64_be,
2063 .s390x,2061 .s390x,
2064 .sparc,
2065 .sparc64,2062 .sparc64,
2066 .wasm32,2063 .wasm32,
2067 .wasm64,2064 .wasm64,
2068 .loongarch32,2065 .loongarch32,
2069 .loongarch64,2066 .loongarch64,
2067 .ve,
2070 => return 128,2068 => return 128,
20712069
2072 else => return 64,2070 else => return 64,
...@@ -2167,12 +2165,12 @@ pub fn c_type_bit_size(target: Target, c_type: CType) u16 {...@@ -2167,12 +2165,12 @@ pub fn c_type_bit_size(target: Target, c_type: CType) u16 {
2167 .s390x,2165 .s390x,
2168 .mips64,2166 .mips64,
2169 .mips64el,2167 .mips64el,
2170 .sparc,
2171 .sparc64,2168 .sparc64,
2172 .wasm32,2169 .wasm32,
2173 .wasm64,2170 .wasm64,
2174 .loongarch32,2171 .loongarch32,
2175 .loongarch64,2172 .loongarch64,
2173 .ve,
2176 => return 128,2174 => return 128,
21772175
2178 else => return 64,2176 else => return 64,
...@@ -2252,23 +2250,20 @@ pub fn c_type_bit_size(target: Target, c_type: CType) u16 {...@@ -2252,23 +2250,20 @@ pub fn c_type_bit_size(target: Target, c_type: CType) u16 {
2252 .longdouble => return 64,2250 .longdouble => return 64,
2253 },2251 },
22542252
2255 .amdhsa, .amdpal => switch (c_type) {2253 .amdhsa, .amdpal, .mesa3d => switch (c_type) {
2256 .char => return 8,2254 .char => return 8,
2257 .short, .ushort => return 16,2255 .short, .ushort => return 16,
2258 .int, .uint, .float => return 32,2256 .int, .uint, .float => return 32,
2259 .long, .ulong, .longlong, .ulonglong, .double => return 64,2257 .long, .ulong, .longlong, .ulonglong, .double => return 64,
2260 .longdouble => return 128,2258 .longdouble => return 64,
2261 },2259 },
22622260
2263 .opencl, .vulkan => switch (c_type) {2261 .opencl, .vulkan => switch (c_type) {
2264 .char => return 8,2262 .char => return 8,
2265 .short, .ushort => return 16,2263 .short, .ushort => return 16,
2266 .int, .uint, .float => return 32,2264 .int, .uint, .float => return 32,
2267 .long, .ulong, .double => return 64,2265 .long, .ulong, .longlong, .ulonglong, .double => return 64,
2268 .longlong, .ulonglong => return 128,2266 .longdouble => return 64,
2269 // Note: The OpenCL specification does not guarantee a particular size for long double,
2270 // but clang uses 128 bits.
2271 .longdouble => return 128,
2272 },2267 },
22732268
2274 .ps4, .ps5 => switch (c_type) {2269 .ps4, .ps5 => switch (c_type) {
...@@ -2285,7 +2280,6 @@ pub fn c_type_bit_size(target: Target, c_type: CType) u16 {...@@ -2285,7 +2280,6 @@ pub fn c_type_bit_size(target: Target, c_type: CType) u16 {
2285 .rtems,2280 .rtems,
2286 .aix,2281 .aix,
2287 .elfiamcu,2282 .elfiamcu,
2288 .mesa3d,
2289 .contiki,2283 .contiki,
2290 .hermit,2284 .hermit,
2291 .hurd,2285 .hurd,
...@@ -2344,11 +2338,8 @@ pub fn c_type_alignment(target: Target, c_type: CType) u16 {...@@ -2344,11 +2338,8 @@ pub fn c_type_alignment(target: Target, c_type: CType) u16 {
2344 .csky,2338 .csky,
2345 .x86,2339 .x86,
2346 .xcore,2340 .xcore,
2347 .dxil,
2348 .loongarch32,2341 .loongarch32,
2349 .spirv32,
2350 .kalimba,2342 .kalimba,
2351 .ve,
2352 .spu_2,2343 .spu_2,
2353 .xtensa,2344 .xtensa,
2354 => 4,2345 => 4,
...@@ -2356,22 +2347,24 @@ pub fn c_type_alignment(target: Target, c_type: CType) u16 {...@@ -2356,22 +2347,24 @@ pub fn c_type_alignment(target: Target, c_type: CType) u16 {
2356 .amdgcn,2347 .amdgcn,
2357 .bpfel,2348 .bpfel,
2358 .bpfeb,2349 .bpfeb,
2350 .dxil,
2359 .hexagon,2351 .hexagon,
2360 .loongarch64,
2361 .m68k,2352 .m68k,
2362 .mips,2353 .mips,
2363 .mipsel,2354 .mipsel,
2364 .sparc,2355 .sparc,
2365 .sparc64,
2366 .lanai,2356 .lanai,
2367 .nvptx,2357 .nvptx,
2368 .nvptx64,2358 .nvptx64,
2369 .s390x,2359 .s390x,
2360 .spirv,
2361 .spirv32,
2370 .spirv64,2362 .spirv64,
2371 => 8,2363 => 8,
23722364
2373 .aarch64,2365 .aarch64,
2374 .aarch64_be,2366 .aarch64_be,
2367 .loongarch64,
2375 .mips64,2368 .mips64,
2376 .mips64el,2369 .mips64el,
2377 .powerpc,2370 .powerpc,
...@@ -2380,12 +2373,12 @@ pub fn c_type_alignment(target: Target, c_type: CType) u16 {...@@ -2380,12 +2373,12 @@ pub fn c_type_alignment(target: Target, c_type: CType) u16 {
2380 .powerpc64le,2373 .powerpc64le,
2381 .riscv32,2374 .riscv32,
2382 .riscv64,2375 .riscv64,
2376 .sparc64,
2383 .x86_64,2377 .x86_64,
2378 .ve,
2384 .wasm32,2379 .wasm32,
2385 .wasm64,2380 .wasm64,
2386 => 16,2381 => 16,
2387
2388 .spirv => @panic("TODO what should this value be?"),
2389 }),2382 }),
2390 );2383 );
2391}2384}
...@@ -2449,11 +2442,8 @@ pub fn c_type_preferred_alignment(target: Target, c_type: CType) u16 {...@@ -2449,11 +2442,8 @@ pub fn c_type_preferred_alignment(target: Target, c_type: CType) u16 {
24492442
2450 .csky,2443 .csky,
2451 .xcore,2444 .xcore,
2452 .dxil,
2453 .loongarch32,2445 .loongarch32,
2454 .spirv32,
2455 .kalimba,2446 .kalimba,
2456 .ve,
2457 .spu_2,2447 .spu_2,
2458 .xtensa,2448 .xtensa,
2459 => 4,2449 => 4,
...@@ -2467,23 +2457,25 @@ pub fn c_type_preferred_alignment(target: Target, c_type: CType) u16 {...@@ -2467,23 +2457,25 @@ pub fn c_type_preferred_alignment(target: Target, c_type: CType) u16 {
2467 .amdgcn,2457 .amdgcn,
2468 .bpfel,2458 .bpfel,
2469 .bpfeb,2459 .bpfeb,
2460 .dxil,
2470 .hexagon,2461 .hexagon,
2471 .x86,2462 .x86,
2472 .loongarch64,
2473 .m68k,2463 .m68k,
2474 .mips,2464 .mips,
2475 .mipsel,2465 .mipsel,
2476 .sparc,2466 .sparc,
2477 .sparc64,
2478 .lanai,2467 .lanai,
2479 .nvptx,2468 .nvptx,
2480 .nvptx64,2469 .nvptx64,
2481 .s390x,2470 .s390x,
2471 .spirv,
2472 .spirv32,
2482 .spirv64,2473 .spirv64,
2483 => 8,2474 => 8,
24842475
2485 .aarch64,2476 .aarch64,
2486 .aarch64_be,2477 .aarch64_be,
2478 .loongarch64,
2487 .mips64,2479 .mips64,
2488 .mips64el,2480 .mips64el,
2489 .powerpc,2481 .powerpc,
...@@ -2492,12 +2484,12 @@ pub fn c_type_preferred_alignment(target: Target, c_type: CType) u16 {...@@ -2492,12 +2484,12 @@ pub fn c_type_preferred_alignment(target: Target, c_type: CType) u16 {
2492 .powerpc64le,2484 .powerpc64le,
2493 .riscv32,2485 .riscv32,
2494 .riscv64,2486 .riscv64,
2487 .sparc64,
2495 .x86_64,2488 .x86_64,
2489 .ve,
2496 .wasm32,2490 .wasm32,
2497 .wasm64,2491 .wasm64,
2498 => 16,2492 => 16,
2499
2500 .spirv => @panic("TODO what should this value be?"),
2501 }),2493 }),
2502 );2494 );
2503}2495}