Skip to content

Transmute involving a shared-memory pointer is rejected (target-mode-dependent layout) #874

Closed

Description

@Ayush7614

Background

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

  1. added a commit that references this issue on Aug 13, 2026
    7d2fc05
  2. added a commit that references this issue on Aug 14, 2026
    1f4d813
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions