Commit b0d6c227d3

Kendall Condon <goon.pri.low@gmail.com>
2025-06-27 19:42:09
Sema: catch error sets in atomic operations
also fix the struct test
1 parent f7dc9b5
Changed files (2)
src
test
cases
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.* = .{
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}'