issue 0152 RESOLVED: byte-promote sub-byte (Atomic(bool)) atomic load/store
LLVM rejects a sub-byte atomic memory access (must be byte-sized), so Atomic(bool) — bool lowers to i1 — failed verification on load/store. The atomic emitters in src/backend/llvm/ops.zig now perform a sub-byte access in its byte storage type (i8) and trunc/zext the value at the boundary (new atomicByteType helper: i8 for .bool, null otherwise). rmw/cmpxchg are left as-is on purpose — a bool rmw/CAS is rejected at the sx level (integer-only), so a sub-byte element never reaches those emitters. Regression test examples/1705-atomics-bool-byte-promoted.sx. Suite green 729/0. Unblocks Future.canceled: Atomic(bool) in the B1.2 async layer.
This commit is contained in:
20
examples/1705-atomics-bool-byte-promoted.sx
Normal file
20
examples/1705-atomics-bool-byte-promoted.sx
Normal file
@@ -0,0 +1,20 @@
|
||||
// Atomic(bool) — a sub-byte (i1) element atomically loaded/stored. LLVM
|
||||
// rejects a sub-byte atomic ("atomic memory access' size must be byte-
|
||||
// sized"), so codegen performs the access in the byte storage type (i8)
|
||||
// and trunc/zext's the value at the boundary. (rmw/cmpxchg on a bool is
|
||||
// rejected at the sx level — integer-only — so only load/store apply.)
|
||||
// Regression (issue 0152): Atomic(bool) emitted an i1 atomic that failed
|
||||
// LLVM verification; Future.canceled: Atomic(bool) in the async layer hit it.
|
||||
#import "modules/std.sx";
|
||||
#import "modules/std/atomic.sx";
|
||||
|
||||
main :: () {
|
||||
a := Atomic(bool).init(false);
|
||||
print("init: {}\n", a.load(.acquire)); // false
|
||||
|
||||
a.store(true, .release);
|
||||
print("after store: {}\n", a.load(.acquire)); // true
|
||||
|
||||
a.store(false, .seq_cst);
|
||||
print("after reset: {}\n", a.load(.seq_cst)); // false
|
||||
}
|
||||
1
examples/expected/1705-atomics-bool-byte-promoted.exit
Normal file
1
examples/expected/1705-atomics-bool-byte-promoted.exit
Normal file
@@ -0,0 +1 @@
|
||||
0
|
||||
1
examples/expected/1705-atomics-bool-byte-promoted.stderr
Normal file
1
examples/expected/1705-atomics-bool-byte-promoted.stderr
Normal file
@@ -0,0 +1 @@
|
||||
|
||||
3
examples/expected/1705-atomics-bool-byte-promoted.stdout
Normal file
3
examples/expected/1705-atomics-bool-byte-promoted.stdout
Normal file
@@ -0,0 +1,3 @@
|
||||
init: false
|
||||
after store: true
|
||||
after reset: false
|
||||
Reference in New Issue
Block a user