mirror of
https://codeberg.org/ziglang/zig.git
synced 2025-12-06 13:54:21 +00:00
Sema: catch error sets in atomic operations
also fix the struct test
This commit is contained in:
parent
f7dc9b50ab
commit
b0d6c227d3
2 changed files with 21 additions and 3 deletions
|
|
@ -3859,7 +3859,12 @@ pub fn atomicPtrAlignment(
|
||||||
}
|
}
|
||||||
return .none;
|
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;
|
const bit_count = ty.intInfo(zcu).bits;
|
||||||
if (bit_count > max_atomic_bits) {
|
if (bit_count > max_atomic_bits) {
|
||||||
diags.* = .{
|
diags.* = .{
|
||||||
|
|
|
||||||
|
|
@ -5,14 +5,27 @@ export fn float() void {
|
||||||
|
|
||||||
const NormalStruct = struct { x: u32 };
|
const NormalStruct = struct { x: u32 };
|
||||||
export fn normalStruct() void {
|
export fn normalStruct() void {
|
||||||
var x: NormalStruct = 0;
|
var x: NormalStruct = .{ .x = 0 };
|
||||||
_ = @cmpxchgWeak(NormalStruct, &x, .{ .x = 1 }, .{ .x = 2 }, .seq_cst, .seq_cst);
|
_ = @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
|
// error
|
||||||
// backend=stage2
|
// backend=stage2
|
||||||
// target=native
|
// target=native
|
||||||
//
|
//
|
||||||
// :3:22: error: expected bool, integer, enum, packed struct, or pointer type; found 'f32'
|
// :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
|
// :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}'
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue