aboutsummaryrefslogtreecommitdiff
path: root/lib/std/atomic
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2023-06-24 16:58:19 -0700
committerGitHub <noreply@github.com>2023-06-24 16:58:19 -0700
commit146b79af153bbd5dafda0ba12a040385c7fc58f8 (patch)
tree67e3db8b444d65c667e314770fc983a7fc8ba293 /lib/std/atomic
parent13853bef0df3c90633021850cc6d6abaeea03282 (diff)
parent21ac0beb436f49fe49c6982a872f2dc48e4bea5e (diff)
downloadzig-146b79af153bbd5dafda0ba12a040385c7fc58f8.tar.gz
zig-146b79af153bbd5dafda0ba12a040385c7fc58f8.zip
Merge pull request #16163 from mlugg/feat/builtins-infer-dest-ty
Infer destination type of cast builtins using result type
Diffstat (limited to 'lib/std/atomic')
-rw-r--r--lib/std/atomic/Atomic.zig20
-rw-r--r--lib/std/atomic/queue.zig2
-rw-r--r--lib/std/atomic/stack.zig2
3 files changed, 12 insertions, 12 deletions
diff --git a/lib/std/atomic/Atomic.zig b/lib/std/atomic/Atomic.zig
index c3f17421f3..b9e1b18f77 100644
--- a/lib/std/atomic/Atomic.zig
+++ b/lib/std/atomic/Atomic.zig
@@ -46,7 +46,7 @@ pub fn Atomic(comptime T: type) type {
extern "c" fn __tsan_release(addr: *anyopaque) void;
};
- const addr = @ptrCast(*anyopaque, self);
+ const addr = @as(*anyopaque, @ptrCast(self));
return switch (ordering) {
.Unordered, .Monotonic => @compileError(@tagName(ordering) ++ " only applies to atomic loads and stores"),
.Acquire => tsan.__tsan_acquire(addr),
@@ -307,7 +307,7 @@ pub fn Atomic(comptime T: type) type {
// TODO: emit appropriate tsan fence if compiling with tsan
_ = ordering;
- return @intCast(u1, old_bit);
+ return @as(u1, @intCast(old_bit));
}
});
};
@@ -392,8 +392,8 @@ test "Atomic.swap" {
try testing.expectEqual(a.load(.SeqCst), true);
var b = Atomic(?*u8).init(null);
- try testing.expectEqual(b.swap(@ptrFromInt(?*u8, @alignOf(u8)), ordering), null);
- try testing.expectEqual(b.load(.SeqCst), @ptrFromInt(?*u8, @alignOf(u8)));
+ try testing.expectEqual(b.swap(@as(?*u8, @ptrFromInt(@alignOf(u8))), ordering), null);
+ try testing.expectEqual(b.load(.SeqCst), @as(?*u8, @ptrFromInt(@alignOf(u8))));
}
}
@@ -544,7 +544,7 @@ test "Atomic.bitSet" {
var x = Atomic(Int).init(0);
for (0..@bitSizeOf(Int)) |bit_index| {
- const bit = @intCast(std.math.Log2Int(Int), bit_index);
+ const bit = @as(std.math.Log2Int(Int), @intCast(bit_index));
const mask = @as(Int, 1) << bit;
// setting the bit should change the bit
@@ -558,7 +558,7 @@ test "Atomic.bitSet" {
// all the previous bits should have not changed (still be set)
for (0..bit_index) |prev_bit_index| {
- const prev_bit = @intCast(std.math.Log2Int(Int), prev_bit_index);
+ const prev_bit = @as(std.math.Log2Int(Int), @intCast(prev_bit_index));
const prev_mask = @as(Int, 1) << prev_bit;
try testing.expect(x.load(.SeqCst) & prev_mask != 0);
}
@@ -573,7 +573,7 @@ test "Atomic.bitReset" {
var x = Atomic(Int).init(0);
for (0..@bitSizeOf(Int)) |bit_index| {
- const bit = @intCast(std.math.Log2Int(Int), bit_index);
+ const bit = @as(std.math.Log2Int(Int), @intCast(bit_index));
const mask = @as(Int, 1) << bit;
x.storeUnchecked(x.loadUnchecked() | mask);
@@ -588,7 +588,7 @@ test "Atomic.bitReset" {
// all the previous bits should have not changed (still be reset)
for (0..bit_index) |prev_bit_index| {
- const prev_bit = @intCast(std.math.Log2Int(Int), prev_bit_index);
+ const prev_bit = @as(std.math.Log2Int(Int), @intCast(prev_bit_index));
const prev_mask = @as(Int, 1) << prev_bit;
try testing.expect(x.load(.SeqCst) & prev_mask == 0);
}
@@ -603,7 +603,7 @@ test "Atomic.bitToggle" {
var x = Atomic(Int).init(0);
for (0..@bitSizeOf(Int)) |bit_index| {
- const bit = @intCast(std.math.Log2Int(Int), bit_index);
+ const bit = @as(std.math.Log2Int(Int), @intCast(bit_index));
const mask = @as(Int, 1) << bit;
// toggling the bit should change the bit
@@ -617,7 +617,7 @@ test "Atomic.bitToggle" {
// all the previous bits should have not changed (still be toggled back)
for (0..bit_index) |prev_bit_index| {
- const prev_bit = @intCast(std.math.Log2Int(Int), prev_bit_index);
+ const prev_bit = @as(std.math.Log2Int(Int), @intCast(prev_bit_index));
const prev_mask = @as(Int, 1) << prev_bit;
try testing.expect(x.load(.SeqCst) & prev_mask == 0);
}
diff --git a/lib/std/atomic/queue.zig b/lib/std/atomic/queue.zig
index 70cb293cf4..78eb746347 100644
--- a/lib/std/atomic/queue.zig
+++ b/lib/std/atomic/queue.zig
@@ -248,7 +248,7 @@ fn startPuts(ctx: *Context) u8 {
const random = prng.random();
while (put_count != 0) : (put_count -= 1) {
std.time.sleep(1); // let the os scheduler be our fuzz
- const x = @bitCast(i32, random.int(u32));
+ const x = @as(i32, @bitCast(random.int(u32)));
const node = ctx.allocator.create(Queue(i32).Node) catch unreachable;
node.* = .{
.prev = undefined,
diff --git a/lib/std/atomic/stack.zig b/lib/std/atomic/stack.zig
index 9ad7c76d81..1289217652 100644
--- a/lib/std/atomic/stack.zig
+++ b/lib/std/atomic/stack.zig
@@ -151,7 +151,7 @@ fn startPuts(ctx: *Context) u8 {
const random = prng.random();
while (put_count != 0) : (put_count -= 1) {
std.time.sleep(1); // let the os scheduler be our fuzz
- const x = @bitCast(i32, random.int(u32));
+ const x = @as(i32, @bitCast(random.int(u32)));
const node = ctx.allocator.create(Stack(i32).Node) catch unreachable;
node.* = Stack(i32).Node{
.next = undefined,