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

Sema: catch error sets in atomic operations

also fix the struct test

2 files changed, 21 insertions(+), 3 deletions(-)

src/Zcu.zig+6-1
......@@ -3859,7 +3859,12 @@ pub fn atomicPtrAlignment(
38593859 }
38603860 return .none;
38613861 }
3862 if (ty.isAbiInt(zcu)) {
3862 if (switch (ty.zigTypeTag(zcu)) {
3863 .int, .@"enum" => true,
3864 .@"struct" => ty.containerLayout(zcu) == .@"packed",
3865 else => false,
3866 }) {
3867 assert(ty.isAbiInt(zcu));
38633868 const bit_count = ty.intInfo(zcu).bits;
38643869 if (bit_count > max_atomic_bits) {
38653870 diags.* = .{
test/cases/compile_errors/atomics_with_invalid_type.zig+15-2
......@@ -5,14 +5,27 @@ export fn float() void {
55
66const NormalStruct = struct { x: u32 };
77export fn normalStruct() void {
8 var x: NormalStruct = 0;
8 var x: NormalStruct = .{ .x = 0 };
99 _ = @cmpxchgWeak(NormalStruct, &x, .{ .x = 1 }, .{ .x = 2 }, .seq_cst, .seq_cst);
1010}
1111
12export fn anyError() void {
13 var x: anyerror = error.A;
14 _ = @cmpxchgWeak(anyerror, &x, error.A, error.B, .seq_cst, .seq_cst);
15}
16
17const ErrorSet = error{ A, B };
18export fn errorSet() void {
19 var x: ErrorSet = error.A;
20 _ = @cmpxchgWeak(ErrorSet, &x, error.A, error.B, .seq_cst, .seq_cst);
21}
22
1223// error
1324// backend=stage2
1425// target=native
1526//
1627// :3:22: error: expected bool, integer, enum, packed struct, or pointer type; found 'f32'
17// :8:27: error: expected type 'tmp.NormalStruct', found 'comptime_int'
28// :9:22: error: expected bool, integer, float, enum, packed struct, or pointer type; found 'tmp.NormalStruct'
1829// :6:22: note: struct declared here
30// :14:22: error: expected bool, integer, float, enum, packed struct, or pointer type; found 'anyerror'
31// :20:22: error: expected bool, integer, float, enum, packed struct, or pointer type; found 'error{A,B}'