-
Notifications
You must be signed in to change notification settings - Fork 13.5k
Don't validate constants in const propagation #109521
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
Show all changes
4 commits
Select commit
Hold shift + click to select a range
6a8fcdc
Don't validate constants before propagation
tmiasko bc41973
Use trimmed paths in constantant validation errors
tmiasko 4adb8fb
Remove workaround for CastKind::Transmute from const prop
tmiasko d1bd1be
Use EMIT_MIR_FOR_EACH_BIT_WIDTH in transmute mir-opt test
tmiasko 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
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
File renamed without changes.
15 changes: 15 additions & 0 deletions
15
tests/mir-opt/const_prop/transmute.from_char.ConstProp.64bit.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,15 @@ | ||
- // MIR for `from_char` before ConstProp | ||
+ // MIR for `from_char` after ConstProp | ||
|
||
fn from_char() -> i32 { | ||
let mut _0: i32; // return place in scope 0 at $DIR/transmute.rs:+0:23: +0:26 | ||
scope 1 { | ||
} | ||
|
||
bb0: { | ||
- _0 = const 'R' as i32 (Transmute); // scope 1 at $DIR/transmute.rs:+1:14: +1:28 | ||
+ _0 = const 82_i32; // scope 1 at $DIR/transmute.rs:+1:14: +1:28 | ||
return; // scope 0 at $DIR/transmute.rs:+2:2: +2:2 | ||
} | ||
} | ||
|
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
15 changes: 15 additions & 0 deletions
15
tests/mir-opt/const_prop/transmute.invalid_bool.ConstProp.64bit.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,15 @@ | ||
- // MIR for `invalid_bool` before ConstProp | ||
+ // MIR for `invalid_bool` after ConstProp | ||
|
||
fn invalid_bool() -> bool { | ||
let mut _0: bool; // return place in scope 0 at $DIR/transmute.rs:+0:33: +0:37 | ||
scope 1 { | ||
} | ||
|
||
bb0: { | ||
- _0 = const -1_i8 as bool (Transmute); // scope 1 at $DIR/transmute.rs:+1:14: +1:30 | ||
+ _0 = const {transmute(0xff): bool}; // scope 1 at $DIR/transmute.rs:+1:14: +1:30 | ||
return; // scope 0 at $DIR/transmute.rs:+2:2: +2:2 | ||
} | ||
} | ||
|
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
15 changes: 15 additions & 0 deletions
15
tests/mir-opt/const_prop/transmute.invalid_char.ConstProp.64bit.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,15 @@ | ||
- // MIR for `invalid_char` before ConstProp | ||
+ // MIR for `invalid_char` after ConstProp | ||
|
||
fn invalid_char() -> char { | ||
let mut _0: char; // return place in scope 0 at $DIR/transmute.rs:+0:33: +0:37 | ||
scope 1 { | ||
} | ||
|
||
bb0: { | ||
- _0 = const _ as char (Transmute); // scope 1 at $DIR/transmute.rs:+1:14: +1:33 | ||
+ _0 = const {transmute(0x7fffffff): char}; // scope 1 at $DIR/transmute.rs:+1:14: +1:33 | ||
return; // scope 0 at $DIR/transmute.rs:+2:2: +2:2 | ||
} | ||
} | ||
|
File renamed without changes.
23 changes: 23 additions & 0 deletions
23
tests/mir-opt/const_prop/transmute.less_as_i8.ConstProp.64bit.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,23 @@ | ||
- // MIR for `less_as_i8` before ConstProp | ||
+ // MIR for `less_as_i8` after ConstProp | ||
|
||
fn less_as_i8() -> i8 { | ||
let mut _0: i8; // return place in scope 0 at $DIR/transmute.rs:+0:24: +0:26 | ||
let mut _1: std::cmp::Ordering; // in scope 0 at $DIR/transmute.rs:+1:24: +1:48 | ||
scope 1 { | ||
} | ||
|
||
bb0: { | ||
StorageLive(_1); // scope 1 at $DIR/transmute.rs:+1:24: +1:48 | ||
- _1 = Less; // scope 1 at $DIR/transmute.rs:+1:24: +1:48 | ||
- _0 = move _1 as i8 (Transmute); // scope 1 at $DIR/transmute.rs:+1:14: +1:49 | ||
+ _1 = const Less; // scope 1 at $DIR/transmute.rs:+1:24: +1:48 | ||
+ // mir::Constant | ||
+ // + span: no-location | ||
+ // + literal: Const { ty: std::cmp::Ordering, val: Value(Scalar(0xff)) } | ||
+ _0 = const -1_i8; // scope 1 at $DIR/transmute.rs:+1:14: +1:49 | ||
StorageDead(_1); // scope 1 at $DIR/transmute.rs:+1:48: +1:49 | ||
return; // scope 0 at $DIR/transmute.rs:+2:2: +2:2 | ||
} | ||
} | ||
|
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
File renamed without changes.
22 changes: 22 additions & 0 deletions
22
tests/mir-opt/const_prop/transmute.undef_union_as_integer.ConstProp.64bit.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,22 @@ | ||
- // MIR for `undef_union_as_integer` before ConstProp | ||
+ // MIR for `undef_union_as_integer` after ConstProp | ||
|
||
fn undef_union_as_integer() -> u32 { | ||
let mut _0: u32; // return place in scope 0 at $DIR/transmute.rs:+0:43: +0:46 | ||
let mut _1: undef_union_as_integer::Union32; // in scope 0 at $DIR/transmute.rs:+2:24: +2:44 | ||
let mut _2: (); // in scope 0 at $DIR/transmute.rs:+2:40: +2:42 | ||
scope 1 { | ||
} | ||
|
||
bb0: { | ||
StorageLive(_1); // scope 1 at $DIR/transmute.rs:+2:24: +2:44 | ||
StorageLive(_2); // scope 1 at $DIR/transmute.rs:+2:40: +2:42 | ||
_2 = (); // scope 1 at $DIR/transmute.rs:+2:40: +2:42 | ||
_1 = Union32 { value: move _2 }; // scope 1 at $DIR/transmute.rs:+2:24: +2:44 | ||
StorageDead(_2); // scope 1 at $DIR/transmute.rs:+2:43: +2:44 | ||
_0 = move _1 as u32 (Transmute); // scope 1 at $DIR/transmute.rs:+2:14: +2:45 | ||
StorageDead(_1); // scope 1 at $DIR/transmute.rs:+2:44: +2:45 | ||
return; // scope 0 at $DIR/transmute.rs:+3:2: +3:2 | ||
} | ||
} | ||
|
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
27 changes: 27 additions & 0 deletions
27
tests/mir-opt/const_prop/transmute.unreachable_box.ConstProp.64bit.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,27 @@ | ||
- // MIR for `unreachable_box` before ConstProp | ||
+ // MIR for `unreachable_box` after ConstProp | ||
|
||
fn unreachable_box() -> ! { | ||
let mut _0: !; // return place in scope 0 at $DIR/transmute.rs:+0:36: +0:37 | ||
let mut _1: !; // in scope 0 at $DIR/transmute.rs:+0:38: +3:2 | ||
let _2: std::boxed::Box<Never>; // in scope 0 at $DIR/transmute.rs:+1:9: +1:10 | ||
let mut _3: !; // in scope 0 at $DIR/transmute.rs:+2:5: +2:16 | ||
scope 1 { | ||
debug x => _2; // in scope 1 at $DIR/transmute.rs:+1:9: +1:10 | ||
} | ||
scope 2 { | ||
} | ||
|
||
bb0: { | ||
StorageLive(_1); // scope 0 at $DIR/transmute.rs:+0:38: +3:2 | ||
StorageLive(_2); // scope 0 at $DIR/transmute.rs:+1:9: +1:10 | ||
- _2 = const 1_usize as std::boxed::Box<Never> (Transmute); // scope 2 at $DIR/transmute.rs:+1:34: +1:52 | ||
+ _2 = const Box::<Never>(Unique::<Never> {{ pointer: NonNull::<Never> {{ pointer: {0x1 as *const Never} }}, _marker: PhantomData::<Never> }}, std::alloc::Global); // scope 2 at $DIR/transmute.rs:+1:34: +1:52 | ||
+ // mir::Constant | ||
+ // + span: no-location | ||
+ // + literal: Const { ty: Box<Never>, val: Value(Scalar(0x0000000000000001)) } | ||
StorageLive(_3); // scope 1 at $DIR/transmute.rs:+2:5: +2:16 | ||
unreachable; // scope 1 at $DIR/transmute.rs:+2:11: +2:13 | ||
} | ||
} | ||
|
File renamed without changes.
25 changes: 25 additions & 0 deletions
25
tests/mir-opt/const_prop/transmute.unreachable_direct.ConstProp.64bit.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,25 @@ | ||
- // MIR for `unreachable_direct` before ConstProp | ||
+ // MIR for `unreachable_direct` after ConstProp | ||
|
||
fn unreachable_direct() -> ! { | ||
let mut _0: !; // return place in scope 0 at $DIR/transmute.rs:+0:39: +0:40 | ||
let mut _1: !; // in scope 0 at $DIR/transmute.rs:+0:41: +3:2 | ||
let _2: Never; // in scope 0 at $DIR/transmute.rs:+1:9: +1:10 | ||
let mut _3: (); // in scope 0 at $DIR/transmute.rs:+1:39: +1:41 | ||
let mut _4: !; // in scope 0 at $DIR/transmute.rs:+2:5: +2:15 | ||
scope 1 { | ||
debug x => _2; // in scope 1 at $DIR/transmute.rs:+1:9: +1:10 | ||
} | ||
scope 2 { | ||
} | ||
|
||
bb0: { | ||
StorageLive(_1); // scope 0 at $DIR/transmute.rs:+0:41: +3:2 | ||
StorageLive(_2); // scope 0 at $DIR/transmute.rs:+1:9: +1:10 | ||
StorageLive(_3); // scope 2 at $DIR/transmute.rs:+1:39: +1:41 | ||
_3 = (); // scope 2 at $DIR/transmute.rs:+1:39: +1:41 | ||
_2 = move _3 as Never (Transmute); // scope 2 at $DIR/transmute.rs:+1:29: +1:42 | ||
unreachable; // scope 2 at $DIR/transmute.rs:+1:29: +1:42 | ||
} | ||
} | ||
|
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
31 changes: 31 additions & 0 deletions
31
tests/mir-opt/const_prop/transmute.unreachable_mut.ConstProp.64bit.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,31 @@ | ||
- // MIR for `unreachable_mut` before ConstProp | ||
+ // MIR for `unreachable_mut` after ConstProp | ||
|
||
fn unreachable_mut() -> ! { | ||
let mut _0: !; // return place in scope 0 at $DIR/transmute.rs:+0:36: +0:37 | ||
let mut _1: !; // in scope 0 at $DIR/transmute.rs:+0:38: +3:2 | ||
let _2: &mut Never; // in scope 0 at $DIR/transmute.rs:+1:9: +1:10 | ||
let mut _3: &mut Never; // in scope 0 at $DIR/transmute.rs:+1:34: +1:52 | ||
let mut _4: !; // in scope 0 at $DIR/transmute.rs:+2:5: +2:16 | ||
scope 1 { | ||
debug x => _2; // in scope 1 at $DIR/transmute.rs:+1:9: +1:10 | ||
} | ||
scope 2 { | ||
} | ||
|
||
bb0: { | ||
StorageLive(_1); // scope 0 at $DIR/transmute.rs:+0:38: +3:2 | ||
StorageLive(_2); // scope 0 at $DIR/transmute.rs:+1:9: +1:10 | ||
StorageLive(_3); // scope 0 at $DIR/transmute.rs:+1:34: +1:52 | ||
- _3 = const 1_usize as &mut Never (Transmute); // scope 2 at $DIR/transmute.rs:+1:34: +1:52 | ||
+ _3 = const {0x1 as &mut Never}; // scope 2 at $DIR/transmute.rs:+1:34: +1:52 | ||
+ // mir::Constant | ||
+ // + span: no-location | ||
+ // + literal: Const { ty: &mut Never, val: Value(Scalar(0x0000000000000001)) } | ||
_2 = &mut (*_3); // scope 0 at $DIR/transmute.rs:+1:34: +1:52 | ||
StorageDead(_3); // scope 0 at $DIR/transmute.rs:+1:54: +1:55 | ||
StorageLive(_4); // scope 1 at $DIR/transmute.rs:+2:5: +2:16 | ||
unreachable; // scope 1 at $DIR/transmute.rs:+2:11: +2:13 | ||
} | ||
} | ||
|
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
27 changes: 27 additions & 0 deletions
27
tests/mir-opt/const_prop/transmute.unreachable_ref.ConstProp.64bit.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,27 @@ | ||
- // MIR for `unreachable_ref` before ConstProp | ||
+ // MIR for `unreachable_ref` after ConstProp | ||
|
||
fn unreachable_ref() -> ! { | ||
let mut _0: !; // return place in scope 0 at $DIR/transmute.rs:+0:36: +0:37 | ||
let mut _1: !; // in scope 0 at $DIR/transmute.rs:+0:38: +3:2 | ||
let _2: &Never; // in scope 0 at $DIR/transmute.rs:+1:9: +1:10 | ||
let mut _3: !; // in scope 0 at $DIR/transmute.rs:+2:5: +2:16 | ||
scope 1 { | ||
debug x => _2; // in scope 1 at $DIR/transmute.rs:+1:9: +1:10 | ||
} | ||
scope 2 { | ||
} | ||
|
||
bb0: { | ||
StorageLive(_1); // scope 0 at $DIR/transmute.rs:+0:38: +3:2 | ||
StorageLive(_2); // scope 0 at $DIR/transmute.rs:+1:9: +1:10 | ||
- _2 = const 1_usize as &Never (Transmute); // scope 2 at $DIR/transmute.rs:+1:30: +1:48 | ||
+ _2 = const {0x1 as &Never}; // scope 2 at $DIR/transmute.rs:+1:30: +1:48 | ||
+ // mir::Constant | ||
+ // + span: no-location | ||
+ // + literal: Const { ty: &Never, val: Value(Scalar(0x0000000000000001)) } | ||
StorageLive(_3); // scope 1 at $DIR/transmute.rs:+2:5: +2:16 | ||
unreachable; // scope 1 at $DIR/transmute.rs:+2:11: +2:13 | ||
} | ||
} | ||
|
File renamed without changes.
15 changes: 15 additions & 0 deletions
15
tests/mir-opt/const_prop/transmute.valid_char.ConstProp.64bit.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,15 @@ | ||
- // MIR for `valid_char` before ConstProp | ||
+ // MIR for `valid_char` after ConstProp | ||
|
||
fn valid_char() -> char { | ||
let mut _0: char; // return place in scope 0 at $DIR/transmute.rs:+0:24: +0:28 | ||
scope 1 { | ||
} | ||
|
||
bb0: { | ||
- _0 = const 82_u32 as char (Transmute); // scope 1 at $DIR/transmute.rs:+1:14: +1:33 | ||
+ _0 = const 'R'; // scope 1 at $DIR/transmute.rs:+1:14: +1:33 | ||
return; // scope 0 at $DIR/transmute.rs:+2:2: +2:2 | ||
} | ||
} | ||
|
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.
Oh, I hadn't even realized that this was added in the validity checker. Happy to see it gone!