diff --git a/src/Zcu.zig b/src/Zcu.zig index df35777231..c13f7aaac9 100644 --- a/src/Zcu.zig +++ b/src/Zcu.zig @@ -3859,7 +3859,12 @@ pub fn atomicPtrAlignment( } return .none; } - if (ty.isAbiInt(zcu)) { + if (switch (ty.zigTypeTag(zcu)) { + .int, .@"enum" => true, + .@"struct" => ty.containerLayout(zcu) == .@"packed", + else => false, + }) { + assert(ty.isAbiInt(zcu)); const bit_count = ty.intInfo(zcu).bits; if (bit_count > max_atomic_bits) { diags.* = .{ diff --git a/test/cases/compile_errors/atomics_with_invalid_type.zig b/test/cases/compile_errors/atomics_with_invalid_type.zig index 321cda3655..4643dc7543 100644 --- a/test/cases/compile_errors/atomics_with_invalid_type.zig +++ b/test/cases/compile_errors/atomics_with_invalid_type.zig @@ -5,14 +5,27 @@ export fn float() void { const NormalStruct = struct { x: u32 }; export fn normalStruct() void { - var x: NormalStruct = 0; + var x: NormalStruct = .{ .x = 0 }; _ = @cmpxchgWeak(NormalStruct, &x, .{ .x = 1 }, .{ .x = 2 }, .seq_cst, .seq_cst); } +export fn anyError() void { + var x: anyerror = error.A; + _ = @cmpxchgWeak(anyerror, &x, error.A, error.B, .seq_cst, .seq_cst); +} + +const ErrorSet = error{ A, B }; +export fn errorSet() void { + var x: ErrorSet = error.A; + _ = @cmpxchgWeak(ErrorSet, &x, error.A, error.B, .seq_cst, .seq_cst); +} + // error // backend=stage2 // target=native // // :3:22: error: expected bool, integer, enum, packed struct, or pointer type; found 'f32' -// :8:27: error: expected type 'tmp.NormalStruct', found 'comptime_int' +// :9:22: error: expected bool, integer, float, enum, packed struct, or pointer type; found 'tmp.NormalStruct' // :6:22: note: struct declared here +// :14:22: error: expected bool, integer, float, enum, packed struct, or pointer type; found 'anyerror' +// :20:22: error: expected bool, integer, float, enum, packed struct, or pointer type; found 'error{A,B}'