forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of rust-lang#76844 - simonvandel:fix-76803, r=wesleywiser
Fix rust-lang#76803 miscompilation Fixes rust-lang#76803 Seems like it was an oversight that the discriminant value being set was not compared to the target value from the SwitchInt, as a comment says this is a requirement for the optimization to be sound. r? `@wesleywiser` since you are probably familiar with the optimization and made rust-lang#76837 to workaround the bug
- Loading branch information
Showing
4 changed files
with
96 additions
and
35 deletions.
There are no files selected for viewing
This file contains 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
28 changes: 28 additions & 0 deletions
28
src/test/mir-opt/76803_regression.encode.SimplifyBranchSame.diff
This file contains 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,28 @@ | ||
- // MIR for `encode` before SimplifyBranchSame | ||
+ // MIR for `encode` after SimplifyBranchSame | ||
|
||
fn encode(_1: Type) -> Type { | ||
debug v => _1; // in scope 0 at $DIR/76803_regression.rs:10:15: 10:16 | ||
let mut _0: Type; // return place in scope 0 at $DIR/76803_regression.rs:10:27: 10:31 | ||
let mut _2: isize; // in scope 0 at $DIR/76803_regression.rs:12:9: 12:16 | ||
|
||
bb0: { | ||
_2 = discriminant(_1); // scope 0 at $DIR/76803_regression.rs:12:9: 12:16 | ||
switchInt(move _2) -> [0_isize: bb2, otherwise: bb1]; // scope 0 at $DIR/76803_regression.rs:12:9: 12:16 | ||
} | ||
|
||
bb1: { | ||
_0 = move _1; // scope 0 at $DIR/76803_regression.rs:13:14: 13:15 | ||
goto -> bb3; // scope 0 at $DIR/76803_regression.rs:11:5: 14:6 | ||
} | ||
|
||
bb2: { | ||
discriminant(_0) = 1; // scope 0 at $DIR/76803_regression.rs:12:20: 12:27 | ||
goto -> bb3; // scope 0 at $DIR/76803_regression.rs:11:5: 14:6 | ||
} | ||
|
||
bb3: { | ||
return; // scope 0 at $DIR/76803_regression.rs:15:2: 15:2 | ||
} | ||
} | ||
|
This file contains 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,19 @@ | ||
// compile-flags: -Z mir-opt-level=1 | ||
// EMIT_MIR 76803_regression.encode.SimplifyBranchSame.diff | ||
|
||
#[derive(Debug, Eq, PartialEq)] | ||
pub enum Type { | ||
A, | ||
B, | ||
} | ||
|
||
pub fn encode(v: Type) -> Type { | ||
match v { | ||
Type::A => Type::B, | ||
_ => v, | ||
} | ||
} | ||
|
||
fn main() { | ||
assert_eq!(Type::B, encode(Type::A)); | ||
} |
This file contains 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