rust-lang / rust

Empowering everyone to build reliable and efficient software.
https://www.rust-lang.org
Other
97.35k stars 12.59k forks source link

ICE "Unexpected free regions in MIR" with asm_const, missing constant, async, and lifetime parameter #117877

Open jruderman opened 10 months ago

jruderman commented 10 months ago

Found with a modified fuzz-rustc

Code

#![feature(asm_const)]

use std::arch::asm;

async unsafe fn foo<'a>() {
    asm!("/* {0} */", const N);
}

fn main() {}

Requires rustc built with debug assertions enabled

Requires --edition=2021 for async

Error output

error[E0425]: cannot find value N in this scope

thread 'rustc' panicked at compiler/rustc_mir_build/src/build/mod.rs:96:5: Unexpected free regions in MIR

Full output including backtrace ``` error[E0425]: cannot find value `N` in this scope --> a1.rs:6:29 | 6 | asm!("/* {0} */", const N); | ^ not found in this scope | help: you might be missing a const parameter | 5 | async unsafe fn foo<'a, const N: /* Type */>() { | +++++++++++++++++++++ thread 'rustc' panicked at compiler/rustc_mir_build/src/build/mod.rs:96:5: Unexpected free regions in MIR: Body { basic_blocks: BasicBlocks { basic_blocks: [BasicBlockData { statements: [StorageLive(_3), _3 = const ()], terminator: Some(Terminator { source_info: SourceInfo { span: a1.rs:6:5: 6:31 (#0), scope: scope[0] }, kind: asm!("/* {0} */", const const _, options((empty))) -> [return: bb1, unwind unreachable] }), is_cleanup: false }, BasicBlockData { statements: [StorageDead(_3), _0 = const ()], terminator: Some(Terminator { source_info: SourceInfo { span: a1.rs:7:1: 7:2 (#99), scope: scope[0] }, kind: drop(_1) -> [return: bb2, unwind: bb3] }), is_cleanup: false }, BasicBlockData { statements: [], terminator: Some(Terminator { source_info: SourceInfo { span: a1.rs:7:2: 7:2 (#0), scope: scope[0] }, kind: return }), is_cleanup: false }, BasicBlockData { statements: [], terminator: Some(Terminator { source_info: SourceInfo { span: a1.rs:5:27: 7:2 (#0), scope: scope[0] }, kind: resume }), is_cleanup: true }], cache: Cache { predecessors: OnceLock(), switch_sources: OnceLock(), is_cyclic: OnceLock(), reverse_postorder: OnceLock(), dominators: OnceLock() } }, phase: Built, pass_count: 0, source: MirSource { instance: Item(DefId(0:6 ~ a1[ee4d]::foo::{closure#0})), promoted: None }, source_scopes: [SourceScopeData { span: a1.rs:5:27: 7:2 (#0), parent_scope: None, inlined: None, inlined_parent_scope: None, local_data: Set(SourceScopeLocalData { lint_root: HirId(DefId(0:4 ~ a1[ee4d]::foo).14), safety: Safe }) }], coroutine: Some(CoroutineInfo { yield_ty: Some(()), coroutine_drop: None, coroutine_layout: None, coroutine_kind: Async(Fn) }), local_decls: [LocalDecl { mutability: Mut, local_info: Set(Boring), ty: (), user_ty: None, source_info: SourceInfo { span: a1.rs:5:27: 7:2 (#0), scope: scope[0] } }, LocalDecl { mutability: Mut, local_info: Set(Boring), ty: Coroutine(DefId(0:6 ~ a1[ee4d]::foo::{closure#0}), [ReErased, std::future::ResumeTy, (), (), CoroutineWitness(DefId(0:6 ~ a1[ee4d]::foo::{closure#0}), [ReErased]), ()], Static), user_ty: None, source_info: SourceInfo { span: a1.rs:5:27: 7:2 (#0), scope: scope[0] } }, LocalDecl { mutability: Mut, local_info: Set(User(Var(VarBindingForm { binding_mode: BindByValue(Mut), opt_ty_info: Some(a1.rs:5:27: 7:2 (#98)), opt_match_place: Some((None, a1.rs:5:27: 7:2 (#0))), pat_span: a1.rs:5:27: 7:2 (#0) }))), ty: std::future::ResumeTy, user_ty: None, source_info: SourceInfo { span: a1.rs:5:27: 7:2 (#0), scope: scope[0] } }, LocalDecl { mutability: Not, local_info: Set(Boring), ty: (), user_ty: None, source_info: SourceInfo { span: a1.rs:6:5: 6:31 (#0), scope: scope[0] } }], user_type_annotations: [], arg_count: 2, spread_arg: Some(_2), var_debug_info: [_task_context => _2], span: a1.rs:5:27: 7:2 (#0), required_consts: [], is_polymorphic: false, injection_phase: None, tainted_by_errors: None, function_coverage_info: None } stack backtrace: 0: 0x10e3489c7 - ::fmt::h32be08e4a73e3127 1: 0x10e3cf41b - core::fmt::write::h4c5ea57c49d24c93 2: 0x10e342a08 - std::io::Write::write_fmt::haa537118f333bb71 3: 0x10e348805 - std::sys_common::backtrace::print::h49c807e14db1ec16 4: 0x10e30def5 - std::panicking::default_hook::{{closure}}::h2b7bc953cf5d346a 5: 0x10e30dcdf - std::panicking::default_hook::h31b936663a54995c 6: 0x1213b470b - as core[141871ccc4260175]::ops::function::Fn<(&dyn for<'a, 'b> core[141871ccc4260175]::ops::function::Fn<(&'a core[141871ccc4260175]::panic::panic_info::PanicInfo<'b>,), Output = ()> + core[141871ccc4260175]::marker::Send + core[141871ccc4260175]::marker::Sync, &core[141871ccc4260175]::panic::panic_info::PanicInfo)>>::call 7: 0x10e30e623 - std::panicking::rust_panic_with_hook::h15d5ee8b9f2b330f 8: 0x10e32bafa - std::panicking::begin_panic_handler::{{closure}}::haa22ae33ba8c5851 9: 0x10e32ba29 - std::sys_common::backtrace::__rust_end_short_backtrace::hb6bd07feb4607006 10: 0x10e30dfed - _rust_begin_unwind 11: 0x10e3e8485 - core::panicking::panic_fmt::h6bceaa1f01563255 12: 0x12501d57e - rustc_mir_build[43102d1e30c3b96d]::build::mir_built 13: 0x125577cc9 - rustc_query_impl[66bd3ce17fc8e1a5]::plumbing::__rust_begin_short_backtrace::> 14: 0x12559e71d - >::call_once 15: 0x1256a43e9 - >>::with::>, false, false, false>, rustc_query_impl[66bd3ce17fc8e1a5]::plumbing::QueryCtxt>::{closure#0}, rustc_middle[705d4043bf578f72]::query::erase::Erased<[u8; 8usize]>>::{closure#0}, rustc_middle[705d4043bf578f72]::query::erase::Erased<[u8; 8usize]>> 16: 0x12595a034 - rustc_query_system[6ba621b623e07609]::query::plumbing::try_execute_query::>, false, false, false>, rustc_query_impl[66bd3ce17fc8e1a5]::plumbing::QueryCtxt, false> 17: 0x12572d8c3 - rustc_query_impl[66bd3ce17fc8e1a5]::query_impl::mir_built::get_query_non_incr::__rust_end_short_backtrace 18: 0x12483f2a7 - rustc_middle[705d4043bf578f72]::query::plumbing::query_get_at::>> 19: 0x124840801 - rustc_mir_transform[68f8150185f640cd]::check_unsafety::unsafety_check_result 20: 0x125568819 - rustc_query_impl[66bd3ce17fc8e1a5]::plumbing::__rust_begin_short_backtrace::> 21: 0x125718bed - >::call_once 22: 0x1256a43e9 - >>::with::>, false, false, false>, rustc_query_impl[66bd3ce17fc8e1a5]::plumbing::QueryCtxt>::{closure#0}, rustc_middle[705d4043bf578f72]::query::erase::Erased<[u8; 8usize]>>::{closure#0}, rustc_middle[705d4043bf578f72]::query::erase::Erased<[u8; 8usize]>> 23: 0x12595a034 - rustc_query_system[6ba621b623e07609]::query::plumbing::try_execute_query::>, false, false, false>, rustc_query_impl[66bd3ce17fc8e1a5]::plumbing::QueryCtxt, false> 24: 0x12583e623 - rustc_query_impl[66bd3ce17fc8e1a5]::query_impl::unsafety_check_result::get_query_non_incr::__rust_end_short_backtrace 25: 0x12483f2a7 - rustc_middle[705d4043bf578f72]::query::plumbing::query_get_at::>> 26: 0x12483f68c - ::visit_rvalue 27: 0x12467ad72 - ::visit_body 28: 0x124840af9 - rustc_mir_transform[68f8150185f640cd]::check_unsafety::unsafety_check_result 29: 0x125568819 - rustc_query_impl[66bd3ce17fc8e1a5]::plumbing::__rust_begin_short_backtrace::> 30: 0x125718bed - >::call_once 31: 0x1256a43e9 - >>::with::>, false, false, false>, rustc_query_impl[66bd3ce17fc8e1a5]::plumbing::QueryCtxt>::{closure#0}, rustc_middle[705d4043bf578f72]::query::erase::Erased<[u8; 8usize]>>::{closure#0}, rustc_middle[705d4043bf578f72]::query::erase::Erased<[u8; 8usize]>> 32: 0x12595a034 - rustc_query_system[6ba621b623e07609]::query::plumbing::try_execute_query::>, false, false, false>, rustc_query_impl[66bd3ce17fc8e1a5]::plumbing::QueryCtxt, false> 33: 0x12583e623 - rustc_query_impl[66bd3ce17fc8e1a5]::query_impl::unsafety_check_result::get_query_non_incr::__rust_end_short_backtrace 34: 0x1248cb735 - rustc_middle[705d4043bf578f72]::query::plumbing::query_ensure::>> 35: 0x1248ce763 - rustc_mir_transform[68f8150185f640cd]::mir_const 36: 0x125577e99 - rustc_query_impl[66bd3ce17fc8e1a5]::plumbing::__rust_begin_short_backtrace::> 37: 0x1255945cd - >::call_once 38: 0x1256a43e9 - >>::with::>, false, false, false>, rustc_query_impl[66bd3ce17fc8e1a5]::plumbing::QueryCtxt>::{closure#0}, rustc_middle[705d4043bf578f72]::query::erase::Erased<[u8; 8usize]>>::{closure#0}, rustc_middle[705d4043bf578f72]::query::erase::Erased<[u8; 8usize]>> 39: 0x12595a034 - rustc_query_system[6ba621b623e07609]::query::plumbing::try_execute_query::>, false, false, false>, rustc_query_impl[66bd3ce17fc8e1a5]::plumbing::QueryCtxt, false> 40: 0x12557a303 - rustc_query_impl[66bd3ce17fc8e1a5]::query_impl::mir_const::get_query_non_incr::__rust_end_short_backtrace 41: 0x1248cbd47 - rustc_middle[705d4043bf578f72]::query::plumbing::query_get_at::>> 42: 0x1248cebd6 - rustc_mir_transform[68f8150185f640cd]::mir_promoted 43: 0x125554e5e - rustc_query_impl[66bd3ce17fc8e1a5]::plumbing::__rust_begin_short_backtrace::> 44: 0x12563d8db - >::call_once 45: 0x1256a3f4d - >>::with::>, false, false, false>, rustc_query_impl[66bd3ce17fc8e1a5]::plumbing::QueryCtxt>::{closure#0}, rustc_middle[705d4043bf578f72]::query::erase::Erased<[u8; 16usize]>>::{closure#0}, rustc_middle[705d4043bf578f72]::query::erase::Erased<[u8; 16usize]>> 46: 0x12594f1e0 - rustc_query_system[6ba621b623e07609]::query::plumbing::try_execute_query::>, false, false, false>, rustc_query_impl[66bd3ce17fc8e1a5]::plumbing::QueryCtxt, false> 47: 0x12583cbe6 - rustc_query_impl[66bd3ce17fc8e1a5]::query_impl::mir_promoted::get_query_non_incr::__rust_end_short_backtrace 48: 0x12515f221 - rustc_borrowck[4bda8550cd926c82]::mir_borrowck 49: 0x125554aa9 - rustc_query_impl[66bd3ce17fc8e1a5]::plumbing::__rust_begin_short_backtrace::> 50: 0x12557933d - >::call_once 51: 0x1256a43e9 - >>::with::>, false, false, false>, rustc_query_impl[66bd3ce17fc8e1a5]::plumbing::QueryCtxt>::{closure#0}, rustc_middle[705d4043bf578f72]::query::erase::Erased<[u8; 8usize]>>::{closure#0}, rustc_middle[705d4043bf578f72]::query::erase::Erased<[u8; 8usize]>> 52: 0x12595a034 - rustc_query_system[6ba621b623e07609]::query::plumbing::try_execute_query::>, false, false, false>, rustc_query_impl[66bd3ce17fc8e1a5]::plumbing::QueryCtxt, false> 53: 0x1255f62c3 - rustc_query_impl[66bd3ce17fc8e1a5]::query_impl::mir_borrowck::get_query_non_incr::__rust_end_short_backtrace 54: 0x124435ce7 - rustc_middle[705d4043bf578f72]::query::plumbing::query_get_at::>> 55: 0x1244366ee - rustc_hir_analysis[96041911c6860bb9]::collect::type_of::opaque::find_opaque_ty_constraints_for_rpit 56: 0x1245b72d3 - rustc_hir_analysis[96041911c6860bb9]::collect::type_of::type_of_opaque 57: 0x125558cee - rustc_query_impl[66bd3ce17fc8e1a5]::plumbing::__rust_begin_short_backtrace::> 58: 0x1258429a0 - >::call_once 59: 0x1256a2e8d - >>::with::>, false, false, false>, rustc_query_impl[66bd3ce17fc8e1a5]::plumbing::QueryCtxt>::{closure#0}, rustc_middle[705d4043bf578f72]::query::erase::Erased<[u8; 8usize]>>::{closure#0}, rustc_middle[705d4043bf578f72]::query::erase::Erased<[u8; 8usize]>> 60: 0x125910a7c - rustc_query_system[6ba621b623e07609]::query::plumbing::try_execute_query::>, false, false, false>, rustc_query_impl[66bd3ce17fc8e1a5]::plumbing::QueryCtxt, false> 61: 0x1255ee453 - rustc_query_impl[66bd3ce17fc8e1a5]::query_impl::type_of_opaque::get_query_non_incr::__rust_end_short_backtrace 62: 0x1245b453f - rustc_middle[705d4043bf578f72]::query::plumbing::query_get_at::>> 63: 0x1245b5668 - rustc_hir_analysis[96041911c6860bb9]::collect::type_of::type_of 64: 0x1255760bb - rustc_query_impl[66bd3ce17fc8e1a5]::plumbing::__rust_begin_short_backtrace::> 65: 0x1257d0b40 - >::call_once 66: 0x1256a2e8d - >>::with::>, false, false, false>, rustc_query_impl[66bd3ce17fc8e1a5]::plumbing::QueryCtxt>::{closure#0}, rustc_middle[705d4043bf578f72]::query::erase::Erased<[u8; 8usize]>>::{closure#0}, rustc_middle[705d4043bf578f72]::query::erase::Erased<[u8; 8usize]>> 67: 0x125910a7c - rustc_query_system[6ba621b623e07609]::query::plumbing::try_execute_query::>, false, false, false>, rustc_query_impl[66bd3ce17fc8e1a5]::plumbing::QueryCtxt, false> 68: 0x125820823 - rustc_query_impl[66bd3ce17fc8e1a5]::query_impl::type_of::get_query_non_incr::__rust_end_short_backtrace 69: 0x12451f00f - rustc_middle[705d4043bf578f72]::query::plumbing::query_get_at::>> 70: 0x1245217f1 - rustc_hir_analysis[96041911c6860bb9]::check::check::check_item_type 71: 0x12452ab6a - rustc_hir_analysis[96041911c6860bb9]::check::check::check_mod_item_types 72: 0x1255655e9 - rustc_query_impl[66bd3ce17fc8e1a5]::plumbing::__rust_begin_short_backtrace::> 73: 0x1255fceed - >::call_once 74: 0x1256a2599 - >>::with::>, false, false, false>, rustc_query_impl[66bd3ce17fc8e1a5]::plumbing::QueryCtxt>::{closure#0}, rustc_middle[705d4043bf578f72]::query::erase::Erased<[u8; 0usize]>>::{closure#0}, rustc_middle[705d4043bf578f72]::query::erase::Erased<[u8; 0usize]>> 75: 0x1258fa64f - rustc_query_system[6ba621b623e07609]::query::plumbing::try_execute_query::>, false, false, false>, rustc_query_impl[66bd3ce17fc8e1a5]::plumbing::QueryCtxt, false> 76: 0x125801894 - rustc_query_impl[66bd3ce17fc8e1a5]::query_impl::check_mod_item_types::get_query_non_incr::__rust_end_short_backtrace 77: 0x1243e3f35 - rustc_middle[705d4043bf578f72]::query::plumbing::query_ensure::>> 78: 0x1243e39dd - ::for_each_module:: 79: 0x124493cbd - ::time::<(), rustc_hir_analysis[96041911c6860bb9]::check_crate::{closure#5}> 80: 0x1243db682 - rustc_hir_analysis[96041911c6860bb9]::check_crate 81: 0x1214f3cce - rustc_interface[b2b6b70544aa9d1]::passes::analysis 82: 0x125576287 - rustc_query_impl[66bd3ce17fc8e1a5]::plumbing::__rust_begin_short_backtrace::> 83: 0x125774caa - >::call_once 84: 0x1256a088f - >>::with::>, false, false, false>, rustc_query_impl[66bd3ce17fc8e1a5]::plumbing::QueryCtxt>::{closure#0}, rustc_middle[705d4043bf578f72]::query::erase::Erased<[u8; 1usize]>>::{closure#0}, rustc_middle[705d4043bf578f72]::query::erase::Erased<[u8; 1usize]>> 85: 0x1258c5704 - rustc_query_system[6ba621b623e07609]::query::plumbing::try_execute_query::>, false, false, false>, rustc_query_impl[66bd3ce17fc8e1a5]::plumbing::QueryCtxt, false> 86: 0x12570ddab - rustc_query_impl[66bd3ce17fc8e1a5]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace 87: 0x12133c391 - >>::with::::enter>::{closure#0}, core[141871ccc4260175]::result::Result<(), rustc_span[307fc47b90714165]::ErrorGuaranteed>>::{closure#0}, core[141871ccc4260175]::result::Result<(), rustc_span[307fc47b90714165]::ErrorGuaranteed>> 88: 0x12130eb0b - ::enter::> 89: 0x12131a123 - ::enter::, rustc_span[307fc47b90714165]::ErrorGuaranteed>> 90: 0x1213960bc - rustc_span[307fc47b90714165]::set_source_map::, rustc_interface[b2b6b70544aa9d1]::interface::run_compiler, rustc_driver_impl[620352f41765b051]::run_compiler::{closure#1}>::{closure#0}::{closure#0}> 91: 0x1213282a5 - >::set::, rustc_driver_impl[620352f41765b051]::run_compiler::{closure#1}>::{closure#0}, core[141871ccc4260175]::result::Result<(), rustc_span[307fc47b90714165]::ErrorGuaranteed>>::{closure#0}, core[141871ccc4260175]::result::Result<(), rustc_span[307fc47b90714165]::ErrorGuaranteed>> 92: 0x121396b51 - rustc_span[307fc47b90714165]::create_session_globals_then::, rustc_interface[b2b6b70544aa9d1]::util::run_in_thread_pool_with_globals, rustc_driver_impl[620352f41765b051]::run_compiler::{closure#1}>::{closure#0}, core[141871ccc4260175]::result::Result<(), rustc_span[307fc47b90714165]::ErrorGuaranteed>>::{closure#0}> 93: 0x121327585 - std[44644296588160fc]::sys_common::backtrace::__rust_begin_short_backtrace::, rustc_driver_impl[620352f41765b051]::run_compiler::{closure#1}>::{closure#0}, core[141871ccc4260175]::result::Result<(), rustc_span[307fc47b90714165]::ErrorGuaranteed>>::{closure#0}, core[141871ccc4260175]::result::Result<(), rustc_span[307fc47b90714165]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[141871ccc4260175]::result::Result<(), rustc_span[307fc47b90714165]::ErrorGuaranteed>> 94: 0x121338070 - std[44644296588160fc]::panicking::try::, core[141871ccc4260175]::panic::unwind_safe::AssertUnwindSafe<::spawn_unchecked_, rustc_driver_impl[620352f41765b051]::run_compiler::{closure#1}>::{closure#0}, core[141871ccc4260175]::result::Result<(), rustc_span[307fc47b90714165]::ErrorGuaranteed>>::{closure#0}, core[141871ccc4260175]::result::Result<(), rustc_span[307fc47b90714165]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[141871ccc4260175]::result::Result<(), rustc_span[307fc47b90714165]::ErrorGuaranteed>>::{closure#1}::{closure#0}>> 95: 0x1212f7d3e - <::spawn_unchecked_, rustc_driver_impl[620352f41765b051]::run_compiler::{closure#1}>::{closure#0}, core[141871ccc4260175]::result::Result<(), rustc_span[307fc47b90714165]::ErrorGuaranteed>>::{closure#0}, core[141871ccc4260175]::result::Result<(), rustc_span[307fc47b90714165]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[141871ccc4260175]::result::Result<(), rustc_span[307fc47b90714165]::ErrorGuaranteed>>::{closure#1} as core[141871ccc4260175]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0} 96: 0x10e31250d - as core::ops::function::FnOnce>::call_once::h62100a6d16b121b3 97: 0x10e31c37f - std::sys::unix::thread::Thread::new::thread_start::h990ef5ebf967521b 98: 0x7ff81e7c04e1 - __pthread_start error: 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: please attach the file at `/Users/jruderman/code/tt/rustc-ice-2023-11-13T15_01_15-61509.txt` to your bug report query stack during panic: #0 [mir_built] building MIR for `foo::{closure#0}` #1 [unsafety_check_result] unsafety-checking `foo::{closure#0}` #2 [unsafety_check_result] unsafety-checking `foo` #3 [mir_const] preparing `foo` for borrow checking #4 [mir_promoted] promoting constants in MIR for `foo` #5 [mir_borrowck] borrow-checking `foo` #6 [type_of_opaque] computing type of opaque `foo::{opaque#0}` #7 [type_of] computing type of `foo::{opaque#0}` #8 [check_mod_item_types] checking item types in top-level module #9 [analysis] running analysis passes on this crate end of query stack error: aborting due to previous error For more information about this error, try `rustc --explain E0425`. ```

Version

stage1 built from 891c6eebe697a7da6e38214e6acebb883b557d4b on x86_64-apple-darwin

@rustbot label +F-asm +requires-debug-assertions

jruderman commented 10 months ago

Also ICEs with sym in place of const.

Amanieu commented 5 months ago

Seems to be fixed on the latest nightly.

matthiaskrgr commented 3 months ago

nightly

you're probably missing debug assertions?