-
Notifications
You must be signed in to change notification settings - Fork 4
ptr_offset_from intrinsics
#885
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,137 @@ | ||
|
|
||
| ┌─ 1 (root, init) | ||
| │ #execTerminator ( terminator ( ... kind: terminatorKindCall ( ... func: operandC | ||
| │ span: 0 | ||
| │ | ||
| │ (296 steps) | ||
| ├─ 3 (split) | ||
| │ #selectBlock ( switchTargets ( ... branches: branch ( 0 , basicBlockIdx ( 8 ) ) | ||
| ┃ | ||
| ┃ (branch) | ||
| ┣━━┓ subst: .Subst | ||
| ┃ ┃ constraint: | ||
| ┃ ┃ 0 ==Int ARG_INT1:Int &Int 18446744073709551615 | ||
| ┃ │ | ||
| ┃ ├─ 4 | ||
| ┃ │ #selectBlock ( switchTargets ( ... branches: branch ( 0 , basicBlockIdx ( 8 ) ) | ||
| ┃ │ | ||
| ┃ │ (582 steps) | ||
| ┃ ├─ 6 (terminal) | ||
| ┃ │ #EndProgram ~> .K | ||
| ┃ │ | ||
| ┃ ┊ constraint: true | ||
| ┃ ┊ subst: ... | ||
| ┃ └─ 2 (leaf, target, terminal) | ||
| ┃ #EndProgram ~> .K | ||
| ┃ | ||
| ┗━━┓ subst: .Subst | ||
| ┃ constraint: | ||
| ┃ notBool 0 ==Int ARG_INT1:Int &Int 18446744073709551615 | ||
| │ | ||
| ├─ 5 | ||
| │ #selectBlock ( switchTargets ( ... branches: branch ( 0 , basicBlockIdx ( 8 ) ) | ||
| │ | ||
| │ (1 step) | ||
| ├─ 7 (split) | ||
| │ #selectBlock ( switchTargets ( ... branches: branch ( 1 , basicBlockIdx ( 7 ) ) | ||
| ┃ | ||
| ┃ (branch) | ||
| ┣━━┓ subst: .Subst | ||
| ┃ ┃ constraint: | ||
| ┃ ┃ 1 ==Int ARG_INT1:Int &Int 18446744073709551615 | ||
| ┃ │ | ||
| ┃ ├─ 8 | ||
| ┃ │ #selectBlock ( switchTargets ( ... branches: branch ( 1 , basicBlockIdx ( 7 ) ) | ||
| ┃ │ | ||
| ┃ │ (99 steps) | ||
| ┃ └─ 10 (stuck, leaf) | ||
| ┃ #ProgramError ( #UBErrorPtrOffsetDiff ( PtrLocal ( 1 , place ( ... local: local | ||
| ┃ | ||
| ┗━━┓ subst: .Subst | ||
| ┃ constraint: | ||
| ┃ notBool 1 ==Int ARG_INT1:Int &Int 18446744073709551615 | ||
| │ | ||
| ├─ 9 | ||
| │ #selectBlock ( switchTargets ( ... branches: branch ( 1 , basicBlockIdx ( 7 ) ) | ||
| │ | ||
| │ (1 step) | ||
| ├─ 11 (split) | ||
| │ #selectBlock ( switchTargets ( ... branches: branch ( 2 , basicBlockIdx ( 6 ) ) | ||
| ┃ | ||
| ┃ (branch) | ||
| ┣━━┓ subst: .Subst | ||
| ┃ ┃ constraint: | ||
| ┃ ┃ 2 ==Int ARG_INT1:Int &Int 18446744073709551615 | ||
| ┃ │ | ||
| ┃ ├─ 12 | ||
| ┃ │ #selectBlock ( switchTargets ( ... branches: branch ( 2 , basicBlockIdx ( 6 ) ) | ||
| ┃ │ | ||
| ┃ │ (99 steps) | ||
| ┃ └─ 14 (stuck, leaf) | ||
| ┃ #ProgramError ( #UBErrorPtrOffsetDiff ( PtrLocal ( 1 , place ( ... local: local | ||
| ┃ | ||
| ┗━━┓ subst: .Subst | ||
| ┃ constraint: | ||
| ┃ notBool 2 ==Int ARG_INT1:Int &Int 18446744073709551615 | ||
| │ | ||
| ├─ 13 | ||
| │ #selectBlock ( switchTargets ( ... branches: branch ( 2 , basicBlockIdx ( 6 ) ) | ||
| │ | ||
| │ (1 step) | ||
| ├─ 15 (split) | ||
| │ #selectBlock ( switchTargets ( ... branches: branch ( 3 , basicBlockIdx ( 5 ) ) | ||
| ┃ | ||
| ┃ (branch) | ||
| ┣━━┓ subst: .Subst | ||
| ┃ ┃ constraint: | ||
| ┃ ┃ 3 ==Int ARG_INT1:Int &Int 18446744073709551615 | ||
| ┃ │ | ||
| ┃ ├─ 16 | ||
| ┃ │ #selectBlock ( switchTargets ( ... branches: branch ( 3 , basicBlockIdx ( 5 ) ) | ||
| ┃ │ | ||
| ┃ │ (16 steps) | ||
| ┃ └─ 18 (stuck, leaf) | ||
| ┃ #ProgramError ( #UBErrorPtrOffsetDiff ( PtrLocal ( 0 , place ( ... local: local | ||
| ┃ | ||
| ┗━━┓ subst: .Subst | ||
| ┃ constraint: | ||
| ┃ notBool 3 ==Int ARG_INT1:Int &Int 18446744073709551615 | ||
| │ | ||
| ├─ 17 | ||
| │ #selectBlock ( switchTargets ( ... branches: branch ( 3 , basicBlockIdx ( 5 ) ) | ||
| │ | ||
| │ (1 step) | ||
| ├─ 19 (split) | ||
| │ #selectBlock ( switchTargets ( ... branches: branch ( 4 , basicBlockIdx ( 4 ) ) | ||
| ┃ | ||
| ┃ (branch) | ||
| ┣━━┓ subst: .Subst | ||
| ┃ ┃ constraint: | ||
| ┃ ┃ 4 ==Int ARG_INT1:Int &Int 18446744073709551615 | ||
| ┃ │ | ||
| ┃ ├─ 20 | ||
| ┃ │ #selectBlock ( switchTargets ( ... branches: branch ( 4 , basicBlockIdx ( 4 ) ) | ||
| ┃ │ | ||
| ┃ │ (68 steps) | ||
| ┃ └─ 22 (stuck, leaf) | ||
| ┃ #setUpCalleeData ( monoItemFn ( ... name: symbol ( "** UNKNOWN FUNCTION **" ) , | ||
| ┃ span: 32 | ||
| ┃ | ||
| ┗━━┓ subst: .Subst | ||
| ┃ constraint: | ||
| ┃ notBool 4 ==Int ARG_INT1:Int &Int 18446744073709551615 | ||
| │ | ||
| ├─ 21 | ||
| │ #selectBlock ( switchTargets ( ... branches: branch ( 4 , basicBlockIdx ( 4 ) ) | ||
| │ | ||
| │ (6 steps) | ||
| ├─ 23 (terminal) | ||
| │ #EndProgram ~> .K | ||
| │ | ||
| ┊ constraint: true | ||
| ┊ subst: ... | ||
| └─ 2 (leaf, target, terminal) | ||
| #EndProgram ~> .K | ||
|
|
||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| #![feature(core_intrinsics)] | ||
| use std::intrinsics::ptr_offset_from_unsigned; // core::ptr variant since 1.87.0, not for us | ||
|
|
||
| fn testing(mode: isize) { | ||
| let a = [1, 2, 3, 4, 5]; | ||
| let b = [6, 7, 8, 9, 10]; | ||
| let a_p = &a as *const i32; | ||
| let b_p = &b as *const i32; | ||
| let a1: *const i32 = &a[1]; | ||
| let a3: *const i32 = &a[3]; | ||
| let b1: *const i32 = &b[1]; | ||
|
|
||
| match mode { | ||
| 0 => unsafe { // correct and expected operation on pointers with offset | ||
| let a1_p = a_p.add(1); | ||
| assert_eq!(a1_p.offset_from(a_p), 1); | ||
| assert_eq!(a_p.offset_from(a1_p), -1); | ||
| assert_eq!(ptr_offset_from_unsigned(a1_p, a_p), 1); | ||
| }, | ||
| 1 => unsafe { // correct and expected operation on addresses within arrays | ||
| assert_eq!(a3.offset_from(a1), 2); | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This operation should pass but fails because of the problem with
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Others are passing all good? I see some other stuck branches in the proof tree above
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Cases 2..4 are intended to become stuck because they are undefined behaviour (although the |
||
| assert_eq!(a1.offset_from(a3), -2); | ||
| }, | ||
| 2 => unsafe { // different allocation | ||
| assert_eq!(a1.offset_from(b1), 0xdeadbeef); // UB | ||
| }, | ||
| 3 => unsafe { | ||
| // violating assumption of a3 > a1 | ||
| assert_eq!(ptr_offset_from_unsigned(a1, a3), 0xdeadbeef); // UB | ||
| }, | ||
| 4 => unsafe { | ||
| let unit_p: *const () = &(); | ||
| assert_eq!(unit_p.offset_from(unit_p), 0xdeadbeef); // panics | ||
| }, | ||
| _ => () | ||
| } | ||
| } | ||
|
|
||
|
|
||
| fn main() { | ||
| testing(0); | ||
| testing(4); | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The test program uncovered a problem caused by making a pointer from a reference with offset:
yields a pointer without size information nor offset in the metadata.
One would instead expect a pointer where the
ConstantIndexprojection is replaced by an offset, and the metadata indicates the original size of the array.The test program fails here because the two pointers have different projection instead of different offsets. It would be possible to add a rule to the intrinsic for this case but the problem lies deeper.
This should be addressed when working on #784 .