Skip to content

Commit 02c7ba7

Browse files
committed
Add compile error tests for atomic feature detection
1 parent 266a0c1 commit 02c7ba7

7 files changed

+76
-8
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
export fn entry() void {
2+
var x: u32 = 0;
3+
_ = @atomicLoad(u32, &x, .monotonic);
4+
}
5+
6+
// error
7+
// target=wasm32-freestanding:baseline
8+
//
9+
// :3:16: error: 4-byte @atomicLoad on wasm32 requires the following missing CPU features: atomics
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
export fn entry() void {
2+
var x: u128 = 0;
3+
@cmpxchgWeak(u128, &x, 1, 2, .monotonic, .monotonic);
4+
}
5+
6+
// error
7+
// target=x86_64-native:baseline
8+
//
9+
// :3:16: error: 16-byte @cmpxchgWeak on x86_64 requires the following missing CPU features: cx16
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
export fn entry() void {
2+
var x: u32 = 0;
3+
@atomicRmw(u32, &x, .Min, 1, .monotonic);
4+
}
5+
6+
// error
7+
// target=wasm32-freestanding:bleeding_edge
8+
//
9+
// :3:16: error: @atoimcRmw(.Min) is not supported on wasm32
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
export fn valid() void {
2+
var x: u128 = 0;
3+
_ = @atomicRmw(u128, &x, .Xchg, 1, .monotonic);
4+
}
5+
export fn invalid() void {
6+
var x: u256 = 0;
7+
_ = @atomicRmw(u256, &x, .Xchg, 1, .monotonic);
8+
}
9+
10+
// error
11+
// target=aarch64-native
12+
//
13+
// ":7:16: error: {s} does not support @atomicRmw(.Xchg) on this type", .{arch}),
14+
// ":7:16: note: size of type is 32, but Xchg on {s} requires a value of size 1, 2, 4, 8, or 16", .{arch}),
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
export fn rmw() void {
2+
var x: u128 = 0;
3+
_ = @atomicRmw(u128, &x, .Xchg, 1, .monotonic);
4+
}
5+
export fn cmpxchg() void {
6+
var x: u256 = 0;
7+
_ = @cmpxchgWeak(u256, &x, 0, 1, .monotonic, .monotonic);
8+
}
9+
10+
// error
11+
// target=x86_64-native:x86_64_v2
12+
//
13+
// ":7:16: error: {s} does not support @atomicRmw(.Xchg) on this type", .{arch}),
14+
// ":7:16: note: size of type is 32, but Xchg on {s} requires a value of size 1, 2, 4, 8, or 16", .{arch}),
Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,24 @@
1-
export fn float() void {
1+
export fn floatCmpxchg() void {
22
var x: f32 = 0;
33
_ = @cmpxchgWeak(f32, &x, 1, 2, .seq_cst, .seq_cst);
44
}
55

66
const NormalStruct = struct { x: u32 };
7-
export fn normalStruct() void {
8-
var x: NormalStruct = 0;
7+
export fn normalStructCmpxchg() void {
8+
var x: NormalStruct = .{ .x = 0 };
99
_ = @cmpxchgWeak(NormalStruct, &x, .{ .x = 1 }, .{ .x = 2 }, .seq_cst, .seq_cst);
1010
}
1111

12+
export fn normalStructLoad() void {
13+
var x: NormalStruct = .{ .x = 0 };
14+
_ = @atomicLoad(NormalStruct, &x, .seq_cst);
15+
}
16+
1217
// error
13-
// backend=stage2
14-
// target=native
1518
//
16-
// :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'
19+
// :3:22: error: expected bool, integer, enum, error set, packed struct, or pointer type; found 'f32'
20+
// :3:22: note: floats are not supported for cmpxchg because float equality differs from bitwise equality
21+
// :9:22: error: expected bool, integer, enum, error set, packed struct, or pointer type; found 'tmp.NormalStruct'
22+
// :6:22: note: struct declared here
23+
// :14:21: error: expected bool, integer, float, enum, error set, packed struct, or pointer type; found 'tmp.NormalStruct'
1824
// :6:22: note: struct declared here

test/src/Cases.zig

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1069,7 +1069,14 @@ const TestManifest = struct {
10691069
fn getDefaultParser(comptime T: type) ParseFn(T) {
10701070
if (T == std.Target.Query) return struct {
10711071
fn parse(str: []const u8) anyerror!T {
1072-
return std.Target.Query.parse(.{ .arch_os_abi = str });
1072+
if (std.mem.indexOfScalar(u8, str, ':')) |idx| {
1073+
return std.Target.Query.parse(.{
1074+
.arch_os_abi = str[0..idx],
1075+
.cpu_features = str[idx + 1 ..],
1076+
});
1077+
} else {
1078+
return std.Target.Query.parse(.{ .arch_os_abi = str });
1079+
}
10731080
}
10741081
}.parse;
10751082

0 commit comments

Comments
 (0)