You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Transmute involving a shared-memory pointer is rejected (target-mode-dependent layout) #874
core::mem::transmute (and derived ops) on a value that contains a shared-memory
pointer (addrspace(3)) currently fails codegen with:
Transmute involving a shared-memory pointer is target-mode dependent (64-bit PTX/legacy, 32-bit modern NVVM) and is not yet supported
This blocks patterns like transmuting a SharedArray index handle, or reinterpreting a
shared-memory pointer, inside kernels.
Location
crates/mir-lower/src/convert/ops/cast.rs:525-532 — the guard in the transmute lowering
rejects any type that llvm_type_contains_pointer_in_address_space(..., SHARED).
Why it is hard today
In PTX/legacy mode a shared pointer is 64 bits; in modern NVVM (p3:32) it is 32 bits.
The general transmute path uses a target-agnostic 8-byte approximation, which cannot be
sound here, so the lowering bails out before choosing a size.
Proposed fix
Thread the active NVVM/PTX target mode into the cast lowering stage so the transmute can
pick the correct shared-pointer byte width (4 or 8) and rewrite the value as a sized
integer of the appropriate bit width, then bitcast back. Mirror the address-space
handling already done for generic/global pointers elsewhere in the same file.
Acceptance criteria (so a PR passes)
A kernel that transmutes a SharedArray handle / p3 pointer round-trips
(apply + undo == identity) on both p3:32 and 64-bit targets.
New unit coverage in crates/mir-lower mirroring the existing scalar/aggregate
transmute tests, plus a cargo oxide run example if warranted.
cargo test -p mir-lower and the workspace cargo check stay green.
Activity
fix(mir-lower): thread target mode into shared-pointer transmutes
fix(mir-lower): bridge shared-pointer transmutes through the generic …