Skip to content

Support pointer provenance in enum constants #594

Closed

Description

@uurl

Description

Enum constants containing references or thin pointers cannot currently be imported without losing rustc pointer provenance.

For example:

static TARGETS: [u64; 2] = [
    0x1122_3344_5566_7788,
    0x8877_6655_4433_2211,
];

const VALUE: Option<&'static u64> = Some(&TARGETS[1]);

rustc represents the pointer field using two separate pieces of information:

  1. the bytes stored in the allocation, which encode the byte addend;
  2. a relocation entry identifying the target allocation.

The enum constant importer currently treats the enum as a byte image without preserving its enclosing allocation and provenance map. Following or discarding the relocation can therefore replace the pointer with the pointee contents, misclassify a niche-encoded variant, or otherwise lose the target allocation identity.

This affects both:

  • niche-encoded enums such as Option<&T>;
  • direct-tagged enums containing a reference payload.

Expected behavior

The importer should:

  • retain the enum's outer allocation while decoding the active variant;
  • use relocation overlap to distinguish a valid niche pointer from the null niche;
  • reconstruct direct thin-pointer fields from rustc relocation entries;
  • preserve non-zero byte addends into device statics;
  • reject unsupported or ambiguous relocation layouts instead of decoding them as ordinary bytes.

Scope

This issue covers direct thin references to device statics in enum constants.

The following cases may remain unsupported:

  • anonymous promoted allocations;
  • pointer relocations nested inside aggregate enum fields;
  • pointer and integer payloads sharing overlapping storage;
  • address-space-3 pointer layouts whose physical width depends on the selected exporter mode;
  • fat pointers with provenance.

Acceptance criteria

  • Option<&'static T> constants correctly distinguish Some from None.
  • Interior pointers into device statics preserve their byte addend.
  • Direct-tagged enums with reference payloads execute correctly on the GPU.
  • Unconsumed, partial, or ambiguous relocations fail closed.
  • A runtime regression example validates the generated GPU result.

Activity

  1. added
    bug
    codegen
    on Jul 31, 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

    bugcodegen

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions