-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Avoid overflow in GVN constant indexing. #119052
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
104 changes: 104 additions & 0 deletions
104
tests/mir-opt/gvn.constant_index_overflow.GVN.panic-abort.diff
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
- // MIR for `constant_index_overflow` before GVN | ||
+ // MIR for `constant_index_overflow` after GVN | ||
|
||
fn constant_index_overflow(_1: &[T]) -> () { | ||
debug x => _1; | ||
let mut _0: (); | ||
let _2: usize; | ||
let mut _4: bool; | ||
let mut _5: usize; | ||
let mut _6: usize; | ||
let mut _7: &[T]; | ||
let _8: usize; | ||
let mut _9: usize; | ||
let mut _10: bool; | ||
let _11: usize; | ||
let mut _12: usize; | ||
let mut _13: bool; | ||
let mut _14: T; | ||
scope 1 { | ||
debug a => _2; | ||
let _3: T; | ||
scope 2 { | ||
debug b => _3; | ||
} | ||
} | ||
|
||
bb0: { | ||
- StorageLive(_2); | ||
- _2 = const _ as usize (IntToInt); | ||
+ nop; | ||
+ _2 = const usize::MAX; | ||
StorageLive(_3); | ||
StorageLive(_4); | ||
StorageLive(_5); | ||
- _5 = _2; | ||
+ _5 = const usize::MAX; | ||
StorageLive(_6); | ||
StorageLive(_7); | ||
_7 = &(*_1); | ||
_6 = core::slice::<impl [T]>::len(move _7) -> [return: bb1, unwind unreachable]; | ||
} | ||
|
||
bb1: { | ||
StorageDead(_7); | ||
- _4 = Lt(move _5, move _6); | ||
+ _4 = Lt(const usize::MAX, move _6); | ||
switchInt(move _4) -> [0: bb4, otherwise: bb2]; | ||
} | ||
|
||
bb2: { | ||
StorageDead(_6); | ||
StorageDead(_5); | ||
StorageLive(_8); | ||
- _8 = _2; | ||
+ _8 = const usize::MAX; | ||
_9 = Len((*_1)); | ||
- _10 = Lt(_8, _9); | ||
- assert(move _10, "index out of bounds: the length is {} but the index is {}", move _9, _8) -> [success: bb3, unwind unreachable]; | ||
+ _10 = Lt(const usize::MAX, _9); | ||
+ assert(move _10, "index out of bounds: the length is {} but the index is {}", move _9, const usize::MAX) -> [success: bb3, unwind unreachable]; | ||
} | ||
|
||
bb3: { | ||
- _3 = (*_1)[_8]; | ||
+ _3 = (*_1)[_2]; | ||
StorageDead(_8); | ||
goto -> bb6; | ||
} | ||
|
||
bb4: { | ||
StorageDead(_6); | ||
StorageDead(_5); | ||
StorageLive(_11); | ||
_11 = const 0_usize; | ||
_12 = Len((*_1)); | ||
- _13 = Lt(_11, _12); | ||
- assert(move _13, "index out of bounds: the length is {} but the index is {}", move _12, _11) -> [success: bb5, unwind unreachable]; | ||
+ _13 = Lt(const 0_usize, _12); | ||
+ assert(move _13, "index out of bounds: the length is {} but the index is {}", move _12, const 0_usize) -> [success: bb5, unwind unreachable]; | ||
} | ||
|
||
bb5: { | ||
- _3 = (*_1)[_11]; | ||
+ _3 = (*_1)[0 of 1]; | ||
StorageDead(_11); | ||
goto -> bb6; | ||
} | ||
|
||
bb6: { | ||
StorageDead(_4); | ||
StorageLive(_14); | ||
_14 = _3; | ||
_0 = opaque::<T>(move _14) -> [return: bb7, unwind unreachable]; | ||
} | ||
|
||
bb7: { | ||
StorageDead(_14); | ||
StorageDead(_3); | ||
- StorageDead(_2); | ||
+ nop; | ||
return; | ||
} | ||
} | ||
|
104 changes: 104 additions & 0 deletions
104
tests/mir-opt/gvn.constant_index_overflow.GVN.panic-unwind.diff
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
- // MIR for `constant_index_overflow` before GVN | ||
+ // MIR for `constant_index_overflow` after GVN | ||
|
||
fn constant_index_overflow(_1: &[T]) -> () { | ||
debug x => _1; | ||
let mut _0: (); | ||
let _2: usize; | ||
let mut _4: bool; | ||
let mut _5: usize; | ||
let mut _6: usize; | ||
let mut _7: &[T]; | ||
let _8: usize; | ||
let mut _9: usize; | ||
let mut _10: bool; | ||
let _11: usize; | ||
let mut _12: usize; | ||
let mut _13: bool; | ||
let mut _14: T; | ||
scope 1 { | ||
debug a => _2; | ||
let _3: T; | ||
scope 2 { | ||
debug b => _3; | ||
} | ||
} | ||
|
||
bb0: { | ||
- StorageLive(_2); | ||
- _2 = const _ as usize (IntToInt); | ||
+ nop; | ||
+ _2 = const usize::MAX; | ||
StorageLive(_3); | ||
StorageLive(_4); | ||
StorageLive(_5); | ||
- _5 = _2; | ||
+ _5 = const usize::MAX; | ||
StorageLive(_6); | ||
StorageLive(_7); | ||
_7 = &(*_1); | ||
_6 = core::slice::<impl [T]>::len(move _7) -> [return: bb1, unwind continue]; | ||
} | ||
|
||
bb1: { | ||
StorageDead(_7); | ||
- _4 = Lt(move _5, move _6); | ||
+ _4 = Lt(const usize::MAX, move _6); | ||
switchInt(move _4) -> [0: bb4, otherwise: bb2]; | ||
} | ||
|
||
bb2: { | ||
StorageDead(_6); | ||
StorageDead(_5); | ||
StorageLive(_8); | ||
- _8 = _2; | ||
+ _8 = const usize::MAX; | ||
_9 = Len((*_1)); | ||
- _10 = Lt(_8, _9); | ||
- assert(move _10, "index out of bounds: the length is {} but the index is {}", move _9, _8) -> [success: bb3, unwind continue]; | ||
+ _10 = Lt(const usize::MAX, _9); | ||
+ assert(move _10, "index out of bounds: the length is {} but the index is {}", move _9, const usize::MAX) -> [success: bb3, unwind continue]; | ||
} | ||
|
||
bb3: { | ||
- _3 = (*_1)[_8]; | ||
+ _3 = (*_1)[_2]; | ||
StorageDead(_8); | ||
goto -> bb6; | ||
} | ||
|
||
bb4: { | ||
StorageDead(_6); | ||
StorageDead(_5); | ||
StorageLive(_11); | ||
_11 = const 0_usize; | ||
_12 = Len((*_1)); | ||
- _13 = Lt(_11, _12); | ||
- assert(move _13, "index out of bounds: the length is {} but the index is {}", move _12, _11) -> [success: bb5, unwind continue]; | ||
+ _13 = Lt(const 0_usize, _12); | ||
+ assert(move _13, "index out of bounds: the length is {} but the index is {}", move _12, const 0_usize) -> [success: bb5, unwind continue]; | ||
} | ||
|
||
bb5: { | ||
- _3 = (*_1)[_11]; | ||
+ _3 = (*_1)[0 of 1]; | ||
StorageDead(_11); | ||
goto -> bb6; | ||
} | ||
|
||
bb6: { | ||
StorageDead(_4); | ||
StorageLive(_14); | ||
_14 = _3; | ||
_0 = opaque::<T>(move _14) -> [return: bb7, unwind continue]; | ||
} | ||
|
||
bb7: { | ||
StorageDead(_14); | ||
StorageDead(_3); | ||
- StorageDead(_2); | ||
+ nop; | ||
return; | ||
} | ||
} | ||
|
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
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.
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.
Do you know why
ConstantIndex
storesmin_length
instead of, e.g., the "max index" of the last value?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.
Well I guess it doesn't make sense to index at
usize::MAX
anyways.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.
min_length
comes from slice match. I supposed it's easier to compute from the length of the pattern.