Skip to content

Named-space pointers lose Rust address semantics when their representation is observed #625

Closed

Description

@niklebedenko

Named-space pointers lose Rust address semantics when their representation is observed

Problem

CUDA named address spaces use space-local pointer representations. Static
shared memory can therefore have a valid shared-space offset of zero, and
modern NVVM represents shared pointers with 32 bits even though Rust's logical
pointer and usize width is 64 bits.

cuda-oxide currently either rejects pointer-to-integer transmutes involving a
shared pointer or emits ptrtoint directly for other pointer-address casts.
Direct shared-pointer enum payloads are also rejected because their physical
width depends on the selected NVVM mode. These behaviors expose the named-space
representation where Rust expects one stable, non-null pointer value.

Why this matters

Core raw-pointer operations such as ptr::addr and is_null observe the
pointer as an integer. A valid shared allocation at local offset zero must not
be mistaken for null. Likewise, Rust enum layout remains 64-bit even when a
target-specific LLVM shared pointer is 32-bit, so device code needs a stable
physical representation for direct pointer payloads.

Expected behavior

Before a named-space pointer is exposed as an integer, cuda-oxide should cast
it to CUDA's generic address space, whose value includes the memory-space
identity. Direct shared-pointer enum fields should use that same generic
pointer as their physical storage while retaining the shared address space as
their semantic type at construction and extraction boundaries.

Acceptance criteria

  • Rust pointer-address exposure uses CUDA's generic representation for
    named-space pointers, without adding a redundant cast for generic pointers.
  • Target-specific operations that explicitly consume a native shared-space
    offset keep that representation instead of being genericized.
  • A static shared allocation at local offset zero has a nonzero ptr::addr()
    result and reports false from is_null() on the GPU.
  • Direct shared-pointer enum payloads use target-stable generic physical
    storage and round-trip back to their semantic shared pointer.
  • Nested shared-pointer aggregates, shared-space niche carriers, and reverse
    integer-to-shared transmutes continue to fail closed with focused coverage.

Activity

  1. added
    bug
    miscompile
    IR-lowering
    codegen
    on Aug 1, 2026
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

    IR-loweringbugcodegenmiscompile

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions