Skip to content
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

ICE: broken mir with -Zunsound-mir-opts: simplify arm identity #78628

Closed
matthiaskrgr opened this issue Nov 1, 2020 · 10 comments · Fixed by #107256
Closed

ICE: broken mir with -Zunsound-mir-opts: simplify arm identity #78628

matthiaskrgr opened this issue Nov 1, 2020 · 10 comments · Fixed by #107256
Labels
A-mir-opt Area: MIR optimizations C-bug Category: This is a bug. glacier ICE tracked in rust-lang/glacier. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ requires-nightly This issue requires a nightly compiler in some way. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@matthiaskrgr
Copy link
Member

Code

from ./src/test/ui/mir/issue-77359-simplify-arm-identity.rs

// run-pass

#![allow(dead_code)]

#[derive(Debug)]
enum MyEnum {
    Variant2,
    Variant3,
}

fn f(arg3: bool) -> MyStruct {
	match if arg3 { Some(MyEnum::Variant3) } else { None } {
		Some(t) => {
			let ah = t;
			return MyStruct(Some(ah));
		}
		_ => MyStruct(None)
	}
}

#[derive(Debug)]
struct MyStruct(Option<MyEnum>);

fn main() {
    f(true);
}

Meta

rustc --version --verbose:

rustc 1.49.0-nightly (1d5b7c3c9 2020-11-01)
binary: rustc
commit-hash: 1d5b7c3c96a86c96f1fbf1441475028df94d165a
commit-date: 2020-11-01
host: x86_64-unknown-linux-gnu
release: 1.49.0-nightly

Error output

error: internal compiler error: broken MIR in Item(WithOptConstParam { did: DefId(0:3 ~ issue_77359_simplify_arm_identity[317d]::f), const_param_did: None }) (end of phase Optimization) at bb5[0]:
use of local _5, which has no storage here
  --> ./src/test/ui/mir/issue-77359-simplify-arm-identity.rs:15:20
   |
15 |             return MyStruct(Some(ah));
   |                             ^^^^^^^^
   |
   = note: delayed at compiler/rustc_mir/src/transform/validate.rs:171:36

thread 'rustc' panicked at 'no errors encountered even though `delay_span_bug` issued', compiler/rustc_errors/src/lib.rs:958:13
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

error: internal compiler error: unexpected panic

note: the compiler unexpectedly panicked. this is a bug.

note: we would appreciate a bug report: https://github.com/rust-lang/rust/issues/new?labels=C-bug%2C+I-ICE%2C+T-compiler&template=ice.md

note: rustc 1.49.0-nightly (1d5b7c3c9 2020-11-01) running on x86_64-unknown-linux-gnu

note: compiler flags: -Z unsound-mir-opts

query stack during panic:
end of query stack
Backtrace

error: internal compiler error: broken MIR in Item(WithOptConstParam { did: DefId(0:3 ~ issue_77359_simplify_arm_identity[317d]::f), const_param_did: None }) (end of phase Optimization) at bb5[0]:
use of local _5, which has no storage here
  --> ./src/test/ui/mir/issue-77359-simplify-arm-identity.rs:15:20
   |
15 |             return MyStruct(Some(ah));
   |                             ^^^^^^^^
   |
   = note: delayed at compiler/rustc_mir/src/transform/validate.rs:171:36

thread 'rustc' panicked at 'no errors encountered even though `delay_span_bug` issued', compiler/rustc_errors/src/lib.rs:958:13
stack backtrace:
   0:     0x7ffaf14ba5f0 - std::backtrace_rs::backtrace::libunwind::trace::h448c56741b6011d3
                               at /rustc/1d5b7c3c96a86c96f1fbf1441475028df94d165a/library/std/src/../../backtrace/src/backtrace/libunwind.rs:100:5
   1:     0x7ffaf14ba5f0 - std::backtrace_rs::backtrace::trace_unsynchronized::h2d26397c5720fdbb
                               at /rustc/1d5b7c3c96a86c96f1fbf1441475028df94d165a/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x7ffaf14ba5f0 - std::sys_common::backtrace::_print_fmt::h720a2f61f75b9f58
                               at /rustc/1d5b7c3c96a86c96f1fbf1441475028df94d165a/library/std/src/sys_common/backtrace.rs:67:5
   3:     0x7ffaf14ba5f0 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h8d62bbfda6d5c836
                               at /rustc/1d5b7c3c96a86c96f1fbf1441475028df94d165a/library/std/src/sys_common/backtrace.rs:46:22
   4:     0x7ffaf152a52c - core::fmt::write::h1857a60b204f1b6a
                               at /rustc/1d5b7c3c96a86c96f1fbf1441475028df94d165a/library/core/src/fmt/mod.rs:1078:17
   5:     0x7ffaf14ac252 - std::io::Write::write_fmt::h16a9fe7680ac245c
                               at /rustc/1d5b7c3c96a86c96f1fbf1441475028df94d165a/library/std/src/io/mod.rs:1518:15
   6:     0x7ffaf14bf5a5 - std::sys_common::backtrace::_print::h9ba51a6db618de7d
                               at /rustc/1d5b7c3c96a86c96f1fbf1441475028df94d165a/library/std/src/sys_common/backtrace.rs:49:5
   7:     0x7ffaf14bf5a5 - std::sys_common::backtrace::print::h5f20e41c85e91716
                               at /rustc/1d5b7c3c96a86c96f1fbf1441475028df94d165a/library/std/src/sys_common/backtrace.rs:36:9
   8:     0x7ffaf14bf5a5 - std::panicking::default_hook::{{closure}}::h5b7294ca19e8edab
                               at /rustc/1d5b7c3c96a86c96f1fbf1441475028df94d165a/library/std/src/panicking.rs:208:50
   9:     0x7ffaf14bf248 - std::panicking::default_hook::hb3948d1f74b6ff4c
                               at /rustc/1d5b7c3c96a86c96f1fbf1441475028df94d165a/library/std/src/panicking.rs:227:9
  10:     0x7ffaf1d8e158 - rustc_driver::report_ice::h1ddbc5609a6e1f37
  11:     0x7ffaf14bfea6 - std::panicking::rust_panic_with_hook::h55d23fef0ad751bc
                               at /rustc/1d5b7c3c96a86c96f1fbf1441475028df94d165a/library/std/src/panicking.rs:597:17
  12:     0x7ffaf14bf9c7 - std::panicking::begin_panic_handler::{{closure}}::h56ae74c6dea6e141
                               at /rustc/1d5b7c3c96a86c96f1fbf1441475028df94d165a/library/std/src/panicking.rs:499:13
  13:     0x7ffaf14baa8c - std::sys_common::backtrace::__rust_end_short_backtrace::h3c4721f56689fae4
                               at /rustc/1d5b7c3c96a86c96f1fbf1441475028df94d165a/library/std/src/sys_common/backtrace.rs:141:18
  14:     0x7ffaf14bf929 - rust_begin_unwind
                               at /rustc/1d5b7c3c96a86c96f1fbf1441475028df94d165a/library/std/src/panicking.rs:495:5
  15:     0x7ffaf14bf8db - std::panicking::begin_panic_fmt::h447a9fe10c3ac155
                               at /rustc/1d5b7c3c96a86c96f1fbf1441475028df94d165a/library/std/src/panicking.rs:437:5
  16:     0x7ffaf4dff1c1 - rustc_errors::HandlerInner::flush_delayed::hcdae04493e012a6e
  17:     0x7ffaf4dfbb91 - <rustc_errors::HandlerInner as core::ops::drop::Drop>::drop::h27a485c12bfd5a8a
  18:     0x7ffaf1d9b606 - core::ptr::drop_in_place::hac2c86d61f6a657d
  19:     0x7ffaf1da0796 - <alloc::rc::Rc<T> as core::ops::drop::Drop>::drop::h60c965ef9381f1d3
  20:     0x7ffaf1d46b2d - core::ptr::drop_in_place::h11c56312c481deac
  21:     0x7ffaf1d36a2c - rustc_span::with_source_map::h4e49cbd9a39d01b4
  22:     0x7ffaf1da70c1 - scoped_tls::ScopedKey<T>::set::hca96dcfe1d32eebf
  23:     0x7ffaf1daed75 - std::sys_common::backtrace::__rust_begin_short_backtrace::h21cfd4855c5058aa
  24:     0x7ffaf1d17188 - core::ops::function::FnOnce::call_once{{vtable.shim}}::h2df6ccf8e166462a
  25:     0x7ffaf14ceeaa - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h9e7afb7a0a438236
                               at /rustc/1d5b7c3c96a86c96f1fbf1441475028df94d165a/library/alloc/src/boxed.rs:1307:9
  26:     0x7ffaf14ceeaa - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h70c646c4271337a1
                               at /rustc/1d5b7c3c96a86c96f1fbf1441475028df94d165a/library/alloc/src/boxed.rs:1307:9
  27:     0x7ffaf14ceeaa - std::sys::unix::thread::Thread::new::thread_start::h35d2b8d36f210d02
                               at /rustc/1d5b7c3c96a86c96f1fbf1441475028df94d165a/library/std/src/sys/unix/thread.rs:89:17
  28:     0x7ffaf13ca3e9 - start_thread
  29:     0x7ffaf12e7293 - __GI___clone
  30:                0x0 - <unknown>

error: internal compiler error: unexpected panic

note: the compiler unexpectedly panicked. this is a bug.

note: we would appreciate a bug report: https://github.com/rust-lang/rust/issues/new?labels=C-bug%2C+I-ICE%2C+T-compiler&template=ice.md

note: rustc 1.49.0-nightly (1d5b7c3c9 2020-11-01) running on x86_64-unknown-linux-gnu

note: compiler flags: -Z unsound-mir-opts

query stack during panic:
end of query stack

@matthiaskrgr matthiaskrgr added C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Nov 1, 2020
@jonas-schievink
Copy link
Contributor

This is probably #77359

@jonas-schievink jonas-schievink added the A-mir-opt Area: MIR optimizations label Nov 1, 2020
@matthiaskrgr
Copy link
Member Author

Hm, the issue is already a couple of weeks old while I was not able to reproduce this one a few days ago.

@matthiaskrgr
Copy link
Member Author

This happens since a6403b0 🤔

@bjorn3

This comment has been minimized.

@rustbot rustbot added the requires-nightly This issue requires a nightly compiler in some way. label Nov 1, 2020
@tmiasko
Copy link
Contributor

tmiasko commented Nov 21, 2020

Yes, this is a duplicate of #77359. The changes from #78147 fixed the validator, so the bug is now correctly identified when incorrect transform is enabled with -Zunsound-mir-opts.

@Alexendoo
Copy link
Member

Alexendoo commented Mar 2, 2021

No longer ICEs on latest nightly, bisect shows since #78360

@Alexendoo Alexendoo added the E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. label Mar 2, 2021
@bjorn3
Copy link
Member

bjorn3 commented Mar 2, 2021

Does it still ICE if you enable optimizations?

@Alexendoo Alexendoo removed the E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. label Mar 2, 2021
@Alexendoo
Copy link
Member

It does, looks like it's still an ICE

@Alexendoo
Copy link
Member

This (and #77359) no longer ICE since #95125, seems to be the case for any opt level

cc @JakobDegen is that intentional or is #94177 still pending?

@JakobDegen
Copy link
Contributor

This is only the case because the changes to MIR make that opt completely broken and just never fire under any circumstances. #94177 needs to be revised because of that change, but the plan is still for it to fix these bugs for real

matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Jan 25, 2023
Delete `SimplifyArmIdentity` and `SimplifyBranchSame` mir opts

I had attempted to fix the first of these opts in rust-lang#94177 . However, despite that PR already being a full re-write, it still did not fix some of the core soundness issues. The optimizations that are attempted here are likely to be desirable, but I do not expect any of the currently written code to survive into a sound implementation. Deleting the code keeps us from having to maintain the passes in the meantime.

Closes rust-lang#77359 , closes rust-lang#72800 , closes rust-lang#78628

r? `@cjgillot`
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Jan 25, 2023
Delete `SimplifyArmIdentity` and `SimplifyBranchSame` mir opts

I had attempted to fix the first of these opts in rust-lang#94177 . However, despite that PR already being a full re-write, it still did not fix some of the core soundness issues. The optimizations that are attempted here are likely to be desirable, but I do not expect any of the currently written code to survive into a sound implementation. Deleting the code keeps us from having to maintain the passes in the meantime.

Closes rust-lang#77359 , closes rust-lang#72800 , closes rust-lang#78628

r? ``@cjgillot``
@bors bors closed this as completed in c2f46df Jan 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-mir-opt Area: MIR optimizations C-bug Category: This is a bug. glacier ICE tracked in rust-lang/glacier. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ requires-nightly This issue requires a nightly compiler in some way. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
8 participants