commit 823f9039f1cad8093cd276cf003a42996d39b74a (tree)
parent 0e348d415f9039b44313232304aeea69c3228c0c
Author: Justus Klausecker <justus@klausecker.de>
Date: Fri, 6 Mar 2026 00:06:20 +0100
llvm: use atomic rmw to increment fuzzer pc counters
This change makes the fuzzer instrumentation emitted by Zig thread-safe.
Diffstat:
1 file changed, 1 insertion(+), 3 deletions(-)
diff --git a/src/codegen/llvm.zig b/src/codegen/llvm.zig
@@ -4872,10 +4872,8 @@ pub const FuncGen = struct {
const ptr = if (poi_index == 0) base_ptr else try self.wip.gep(.inbounds, .i8, base_ptr, &.{
try o.builder.intValue(.i32, poi_index),
}, "");
- const counter = try self.wip.load(.normal, .i8, ptr, .default, "");
const one = try o.builder.intValue(.i8, 1);
- const counter_incremented = try self.wip.bin(.add, counter, one, "");
- _ = try self.wip.store(.normal, counter_incremented, ptr, .default);
+ _ = try self.wip.atomicrmw(.normal, .add, ptr, one, self.sync_scope, .monotonic, .default, "");
// LLVM does not allow blockaddress on the entry block.
const pc = if (self.wip.cursor.block == .entry)