Repository navigation
fix(mir): preserve wrapping pointer-offset semantics - #612
Merged
nihalpasham merged 1 commit intoAug 1, 2026
Merged
Conversation
Signed-off-by: nik <[email protected]>
Collaborator
|
LGTM as-is. Gist:
Fix: Verified on hardware:
Merging; closes #611. |
nihalpasham
approved these changes
Aug 1, 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.
Closes #611.
fix(mir): preserve wrapping pointer-offset semantics
Summary
Safe raw-pointer wrapping methods previously failed device compilation because
rustc's
arith_offsetintrinsic was unsupported. This change carries thesource pointer-arithmetic contract through MIR and LLVM lowering: ordinary
offsets remain
getelementptr inbounds, while wrapping offsets become plaingetelementptr, preserving Rust's permitted address wrapping without addingLLVM poison semantics.
What changed
Pointer-arithmetic contract
inboundssemantic marker toMirPtrOffsetOp. Absence defaults totrue, preserving every existing producer's behavior.arith_offsetthrough one focused importerpath and stamps those operations as non-inbounds.
inboundsconditionally.pointee type rather than reconstructing it from the call name or result.
Coverage and related paths
default ordinary offsets are in-bounds and explicit wrapping offsets are not.
ptr_offset_fromexample so one GPU run checks positiveand negative wrapping offsets, aggregate scaling, const and mutable pointers,
zero-sized pointees, and
isize::MAXaddress wrapping.are never dereferenced.
unchanged. Open PR fix(mir): keep small runtime-indexed arrays in SSA #398's
DeferredGepand small-array scalarization changesare deliberately absent from this branch.
Known separate limitations
valid for that access under Rust's normal rules.
cast semantics.
New wrapping producers must set the marker explicitly.
optimization-pipeline policy.
Testing
bead880cwith only the regression present:scripts/smoketest.sh --only '^ptr_offset_from$' --no-colorfailed(
exit=101) becausestd::intrinsics::arith_offsetwas unsupported.scripts/smoketest.sh --only '^ptr_offset_from$' --no-colorpassed on anRTX 3080 (
sm_86), 1/1 example.test_mir_ptr_offset_verify,gep_inbounds_marker_controls_exported_pointer_semantics, andconvert_wrapping_ptr_offset_lowers_to_non_inbounds_gep.cargo test -p dialect-mir -p llvm-export -p mir-importer -p mir-lower --all-targetspassed, including 891 importer tests, 146 mir-lower unittests, and 76 mir-lower integration tests.
cargo clippy -p dialect-mir -p llvm-export -p mir-importer -p mir-lower --all-targets -- -D warningspassed.cargo fmt --checkandcargo clippy --all-targets -- -D warnings; repository formatting andgit diff --checkpass.Checklist
main, or its dependency is explicit.mainand passes on this branch.