authorgravatar for goon.pri.low@gmail.comKendall Condon <goon.pri.low@gmail.com> 2025-06-27 13:38:54-04:00
committergravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2025-07-30 09:56:38+01:00
logf7dc9b50ab1ebc9714b1fa1b9929ae5f778fed69
tree19272a0ab2ebb5f962d1a8cb878cca59562fb8c8
parent4a1594fbdebfeae989ff7c74be737b4879e1916e

llvm: fix atomic widening of packed structs

Additionally, disable failing big-endian atomic test also improve test paramaters to catch this when condition is removed also some other cleanups

2 files changed, 14 insertions(+), 6 deletions(-)

src/codegen/llvm.zig+3-1
......@@ -4339,9 +4339,11 @@ pub const Object = struct {
43394339 /// types to work around a LLVM deficiency when targeting ARM/AArch64.
43404340 fn getAtomicAbiType(o: *Object, pt: Zcu.PerThread, ty: Type, is_rmw_xchg: bool) Allocator.Error!Builder.Type {
43414341 const zcu = pt.zcu;
4342 const ip = &zcu.intern_pool;
43424343 const int_ty = switch (ty.zigTypeTag(zcu)) {
43434344 .int => ty,
43444345 .@"enum" => ty.intTagType(zcu),
4346 .@"struct" => Type.fromInterned(ip.loadStructType(ty.toIntern()).backingIntTypeUnordered(ip)),
43454347 .float => {
43464348 if (!is_rmw_xchg) return .none;
43474349 return o.builder.intType(@intCast(ty.abiSize(zcu) * 8));
......@@ -11424,7 +11426,7 @@ pub const FuncGen = struct {
1142411426
1142511427 if (workaround_disable_truncate) {
1142611428 // see https://github.com/llvm/llvm-project/issues/64222
11427 // disable the truncation codepath for larger that 32bits value - with this heuristic, the backend passes the test suite.
11429 // disable the truncation codepath for larger than 32bits value - with this heuristic, the backend passes the test suite.
1142811430 return try fg.wip.load(access_kind, payload_llvm_ty, payload_ptr, payload_alignment, "");
1142911431 }
1143011432
test/behavior/atomics.zig+11-5
......@@ -1,7 +1,6 @@
11const std = @import("std");
22const builtin = @import("builtin");
33const expect = std.testing.expect;
4const expectEqual = std.testing.expectEqual;
54
65const supports_128_bit_atomics = switch (builtin.cpu.arch) {
76 // TODO: Ideally this could be sync'd with the logic in Sema.
......@@ -364,25 +363,32 @@ test "atomics with different types" {
364363 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
365364 if (builtin.zig_backend == .stage2_spirv) return error.SkipZigTest;
366365 if (builtin.zig_backend == .stage2_riscv64) return error.SkipZigTest;
366 if (builtin.target.cpu.arch.endian() == .big) return error.SkipZigTest; // #24282
367367
368368 try testAtomicsWithType(bool, true, false);
369369
370370 try testAtomicsWithType(u1, 0, 1);
371 try testAtomicsWithType(i4, 0, 1);
372 try testAtomicsWithType(u5, 0, 1);
373 try testAtomicsWithType(i15, 0, 1);
374 try testAtomicsWithType(u24, 0, 1);
371 try testAtomicsWithType(i4, 2, 1);
372 try testAtomicsWithType(u5, 2, 1);
373 try testAtomicsWithType(i15, 2, 1);
374 try testAtomicsWithType(u24, 2, 1);
375375
376376 try testAtomicsWithType(u0, 0, 0);
377377 try testAtomicsWithType(i0, 0, 0);
378378
379379 try testAtomicsWithType(enum(u32) { x = 1234, y = 5678 }, .x, .y);
380 try testAtomicsWithType(enum(u19) { x = 1234, y = 5678 }, .x, .y);
380381
381382 try testAtomicsWithPackedStruct(
382383 packed struct { x: u7, y: u24, z: bool },
383384 .{ .x = 1, .y = 2, .z = true },
384385 .{ .x = 3, .y = 4, .z = false },
385386 );
387 try testAtomicsWithPackedStruct(
388 packed struct { x: u19, y: bool },
389 .{ .x = 1, .y = true },
390 .{ .x = 3, .y = false },
391 );
386392}
387393
388394fn testAtomicsWithType(comptime T: type, a: T, b: T) !void {