Repository navigation
fix(mir-lower): back every payload pointer leaf with its own ptr slot in enum slot map - #472
Merged
Merged
Conversation
… in enum slot map
A niche-Option whose payload carries more than one pointer -- e.g.
<[T]>::split_at_mut_checked's Option<(&mut [T], &mut [T])>, two fat slice
pointers {ptr, len, ptr, len} -- failed to lower:
enum slot map: `...` has overlapping pointer and non-identical storage at
byte N; refusing to erase LLVM pointer provenance
build_enum_slot_map backed at most one pointer with a real ptr slot (the niche
carrier). A second pointer leaf had no provenance-preserving slot: it would land
in [N x i8] filler and load back as integer bytes, erasing provenance, so the
code failed closed.
Replace the exact-equality pointer_storage_matches_claims gate with
analyze_pointer_overlap, which admits a payload when every pointer leaf that
coincides with an existing claim reuses it AND each remaining leaf lands on
otherwise-unclaimed bytes, returning those extra leaves. The call site then adds
one fresh ptr slot per extra leaf, so every payload pointer round-trips through a
real ptr field with provenance intact. A pointer punned against non-pointer bits
at the same bytes (a genuine ptr/int union) still fails closed -- there is no
single LLVM slot type that is both provenance-carrying and integer-exact.
Two enum-slot-map tests that asserted a conservative reject for representable
layouts (a pointer beside a pointer carrier; a pointer beside an integer niche
carrier) now assert the accepted {ptr, ...} shape; a new test covers the
split_at_mut_checked Option<(&mut [T], &mut [T])> layout. The genuine ptr/int
union tests still reject.
Signed-off-by: Nils Homer <[email protected]>
Exercises Option<(&mut [T], &mut [T])> from split_at_mut_checked -- the two-pointer niche payload the enum slot map now backs with a ptr slot per pointer. Thread 0 bumps both halves through the returned slices and the host verifies both, so a dropped or provenance-stripped second pointer fails the test, not just a codegen abort. Signed-off-by: Nils Homer <[email protected]>
The fmt CI lane checks example crates; one assert_eq! line in the host verification exceeded the width and needed the standard rewrap.
Collaborator
|
LGTM, this was quite the find - whichever side of a genuine Verified on an RTX 5090: |
nihalpasham
approved these changes
Jul 25, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
A niche-
Optionwhose payload carries more than one pointer fails to lower:The concrete trigger is
<[T]>::split_at_mut_checked, which returnsOption<(&mut [T], &mut [T])>— a payload of two fat slice pointers{ptr, len, ptr, len}with theNoneniche in the first data pointer. This blocks any device kernel that splits a mutable slice.Root cause
build_enum_slot_mapmodels an enum's storage as a flat LLVM struct of byte "claims". For pointer provenance to survive the memory round-trip (convert_construct_enumstores the payload at its byte offset, then loads the enum-struct type back), every pointer leaf must be backed by a realptrslot at its offset — a pointer that lands in[N x i8]filler loads back as integer bytes with no provenance.The slot map backed at most one pointer with a
ptrslot: the niche carrier. The oldpointer_storage_matches_claimsgate required the payload's pointer leaves to exactly equal the overlapping claims' pointer leaves, so a second pointer leaf (with no slot) failed closed. That correctly refused to strip provenance, but also rejected layouts that are perfectly representable — the second pointer just needs its own slot.The fix
Replace the exact-equality gate with
analyze_pointer_overlap, which admits a pointer-bearing payload when:It returns those extra leaves, and the call site adds one fresh
ptrslot per extra leaf. SoOption<(&mut [T], &mut [T])>lowers to{ptr@0, [pad], ptr@16, [pad]}— both slice pointers backed, provenance intact, the payload still slotless and round-tripping through memory.A pointer punned against non-pointer bits at the same bytes (a genuine
ptr/intunion) still fails closed — there is no single LLVM slot type that is both provenance-carrying and integer-exact. That case remains a separate, deliberately-unsolved design question.Testing
cargo test -p mir-lower→ 136 passed, 0 failed. Two enum-slot-map tests that asserted a conservative reject for representable layouts (a pointer beside a pointer carrier; a pointer beside an integer niche carrier) now assert the accepted{ptr, …}shape; a newenum_slot_map_backs_split_at_mut_slice_paircovers the exactOption<(&mut [T], &mut [T])>layout. The genuineptr/intunion tests still reject.examples/split_at_mut— thread 0 splits a buffer viasplit_at_mut_checked, bumps both halves through the two returned slices, and the host verifies both (a dropped/provenance-stripped second pointer fails the check, not just a codegen abort). Runs on a T4:fe4791d)cargo oxide run split_at_mutrefusing to erase LLVM pointer provenancePASS(host-verified)rustfmt --checkclean;cargo clippy -p mir-lowerclean.spine_hitproc, which callssplit_at_mut_checked) compiling to PTX.Commits
fix(mir-lower): back every payload pointer leaf with its own ptr slot in enum slot maptest(examples): add split_at_mut regression example🤖 Drafted with Claude (Anthropic); authored and DCO-signed by Nils Homer.