-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Incorrect MIR optimizations at level 3: local incorrectly marked dead #76432
Comments
Could you describe affected rustc version and reproduction steps? |
The rustc version is commit e114d62, but most likely a nightly will also do it. To reproduce, run this in a Miri checkout:
|
The SimplifyComparisonIntegral introduces StorageDead for a local which didn't have any markers before. Currently this also makes the local dead on the entry to the function. Related to the issue #42371 about semantics of StorageLive without matching StorageDead (this would be the reverse). |
The LLVM docs for their version of
So just introducing a |
That is the doc for
|
oops sorry, yeah. We'd have to check the MIR here to see if it makes any sense at all; however, currently I think not just Miri but also our dataflow framework assumes that variables with any liveness annotations are initially dead. |
Diff for this case before/after SimplifyComparisonIntegral: --- dead.main-test.005-004.SimplifyComparisonIntegral.before.mir
+++ dead.main-test.005-004.SimplifyComparisonIntegral.after.mir
@@ -1,4 +1,4 @@
-// MIR for `test` before SimplifyComparisonIntegral
+// MIR for `test` after SimplifyComparisonIntegral
fn test(_1: T) -> () {
debug x => _1; // in scope 0 at dead.rs:4:43: 4:44
@@ -56,11 +56,12 @@
StorageLive(_9); // scope 1 at dead.rs:6:9: 9:10
_10 = Len((*_2)); // scope 1 at dead.rs:7:13: 7:37
_11 = const 3_usize; // scope 1 at dead.rs:7:13: 7:37
- _12 = Eq(move _10, const 3_usize); // scope 1 at dead.rs:7:13: 7:37
- switchInt(move _12) -> [false: bb1, otherwise: bb2]; // scope 1 at dead.rs:7:13: 7:37
+ nop; // scope 1 at dead.rs:7:13: 7:37
+ switchInt(move _10) -> [3_usize: bb2, otherwise: bb1]; // scope 1 at dead.rs:7:13: 7:37
}
bb1: {
+ StorageDead(_10); // scope 1 at dead.rs:7:13: 7:37
StorageLive(_22); // scope 1 at /rust/library/std/src/macros.rs:13:23: 13:52
begin_panic::<&str>(const "internal error: entered unreachable code"); // scope 1 at /rust/library/std/src/macros.rs:13:23: 13:52
// mir::Constant
@@ -75,6 +76,7 @@
}
bb2: {
+ StorageDead(_10); // scope 1 at dead.rs:7:13: 7:37
StorageLive(_13); // scope 1 at dead.rs:7:14: 7:20
_13 = &(*_2)[0 of 3]; // scope 1 at dead.rs:7:14: 7:20
StorageLive(_14); // scope 1 at dead.rs:7:22: 7:28 Note the cc @simonvandel -- along the lines of #75370 (comment), you could leave the |
Does this analysis ensure that I guess I am also surprised that an "integral comparison simplification" pass touches storage liveness. |
That part is my fault. I incorrectly assumed that there's a storagedead before the switch. Maybe there is one in some situations, idk, if there is, we should probably just not do the optimization instead of rewriting the storage markers. |
Should this be marked as I-unsound? |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
SimplifyComparisonIntegral: fix miscompilation Fixes rust-lang#76432 Only insert StorageDeads if we actually removed one. Fixes an issue where we added StorageDead to a place with no StorageLive r? @oli-obk
SimplifyComparisonIntegral: fix miscompilation Fixes rust-lang#76432 Only insert StorageDeads if we actually removed one. Fixes an issue where we added StorageDead to a place with no StorageLive r? @oli-obk
SimplifyComparisonIntegral: fix miscompilation Fixes rust-lang#76432 Only insert StorageDeads if we actually removed one. Fixes an issue where we added StorageDead to a place with no StorageLive r? @oli-obk
SimplifyComparisonIntegral: fix miscompilation Fixes rust-lang#76432 Only insert StorageDeads if we actually removed one. Fixes an issue where we added StorageDead to a place with no StorageLive r? @oli-obk
SimplifyComparisonIntegral: fix miscompilation Fixes rust-lang#76432 Only insert StorageDeads if we actually removed one. Fixes an issue where we added StorageDead to a place with no StorageLive r? @oli-obk
SimplifyComparisonIntegral: fix miscompilation Fixes rust-lang#76432 Only insert StorageDeads if we actually removed one. Fixes an issue where we added StorageDead to a place with no StorageLive r? @oli-obk
SimplifyComparisonIntegral: fix miscompilation Fixes rust-lang#76432 Only insert StorageDeads if we actually removed one. Fixes an issue where we added StorageDead to a place with no StorageLive r? `@oli-obk`
The following program runs fine in Miri on mir-opt-levels 0-2, but in level 3 it errors:
The error is:
Looks like something changes the liveness ranges of locals and it does so incorrectly.
Cc @rust-lang/wg-mir-opt
The text was updated successfully, but these errors were encountered: