Skip to content

Commit f7dc9b5

Browse files
gooncreepermlugg
authored andcommitted
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
1 parent 4a1594f commit f7dc9b5

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

src/codegen/llvm.zig

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
const std = @import("std");
22
const builtin = @import("builtin");
33
const expect = std.testing.expect;
4-
const expectEqual = std.testing.expectEqual;
54

65
const 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

388394
fn testAtomicsWithType(comptime T: type, a: T, b: T) !void {

0 commit comments

Comments
 (0)