Skip to content

rustc_codegen_cranelift/src/inline_asm.rs:139:67: 'called Option::unwrap() on a None value' #1548

Closed
@matthiaskrgr

Description

@matthiaskrgr

File is tests/ui/asm/issue-97490.rs

auto-reduced (treereduce-rust):

//@compile-flags: -Zcodegen-backend=cranelift
pub type Yes = fn() -> !;

fn main() {
    unsafe {
        let yes = &6 as *const _ as *const Yes;
        core::arch::asm!("call {}", in(reg) yes, options(noreturn));
    }
}

original:

//@ check-pass
//@ only-x86_64
//@ needs-asm-support

pub type Yes = extern "sysv64" fn(&'static u8) -> !;

fn main() {
    unsafe {
        let yes = &6 as *const _ as *const Yes;
        core::arch::asm!("call {}", in(reg) yes, options(noreturn));
    }
}

Version information

rustc 1.85.0-nightly (37e74596c 2024-12-18)
binary: rustc
commit-hash: 37e74596c0b59e81b9ac58657f92297ef4ccb7ef
commit-date: 2024-12-18
host: x86_64-unknown-linux-gnu
release: 1.85.0-nightly
LLVM version: 19.1.5

Possibly related line of code:
https://github.com/rust-lang/rust/blob/37e74596c0b59e81b9ac58657f92297ef4ccb7ef/compiler/rustc_codegen_cranelift/src/inline_asm.rs#L133-L145

Command:
/home/matthias/.rustup/toolchains/master/bin/rustc -Zcodegen-backend=cranelift

Program output

thread 'rustc' panicked at compiler/rustc_codegen_cranelift/src/inline_asm.rs:139:67:
called `Option::unwrap()` on a `None` value
stack backtrace:
   0:     0x726d12d6adfa - <std::sys::backtrace::BacktraceLock::print::DisplayBacktrace as core::fmt::Display>::fmt::h1d419b96e2493e26
   1:     0x726d13413dbc - core::fmt::write::h0b57abd5d724d91d
   2:     0x726d14381d51 - std::io::Write::write_fmt::h802bf4a45e08aa2d
   3:     0x726d12d6ac52 - std::sys::backtrace::BacktraceLock::print::h29c99003d56731ba
   4:     0x726d12d6d14a - std::panicking::default_hook::{{closure}}::hcb2b551adcb74182
   5:     0x726d12d6cf93 - std::panicking::default_hook::h85e04cddeb7ce6ed
   6:     0x726d11ed98c8 - std[6ff18fa302d30141]::panicking::update_hook::<alloc[711343b0859624ae]::boxed::Box<rustc_driver_impl[8d99f66bc3884647]::install_ice_hook::{closure#0}>>::{closure#0}
   7:     0x726d12d6d948 - std::panicking::rust_panic_with_hook::hcdbeca566cd4661e
   8:     0x726d12d6d606 - std::panicking::begin_panic_handler::{{closure}}::h8f039a5f814c67f3
   9:     0x726d12d6b299 - std::sys::backtrace::__rust_end_short_backtrace::hb25806a4985c7a54
  10:     0x726d12d6d2fd - rust_begin_unwind
  11:     0x726d0f9b0e80 - core::panicking::panic_fmt::h50e148c508ad086f
  12:     0x726d1060eefc - core::panicking::panic::h6beb881f744aa2aa
  13:     0x726d1089e4e9 - core::option::unwrap_failed::hc50c9889c93832ef
  14:     0x726d04041e1f - rustc_codegen_cranelift[d57ac2c89507235b]::base::codegen_fn_body
  15:     0x726d0402ff96 - rustc_codegen_cranelift[d57ac2c89507235b]::base::codegen_fn
  16:     0x726d04054881 - rustc_codegen_cranelift[d57ac2c89507235b]::driver::aot::codegen_cgu_content
  17:     0x726d04056f88 - rustc_codegen_cranelift[d57ac2c89507235b]::driver::aot::module_codegen
  18:     0x726d040627eb - rustc_codegen_cranelift[d57ac2c89507235b]::driver::aot::run_aot::{closure#3}::{closure#0}
  19:     0x726d04000239 - <core[81f20be6a9f9564c]::iter::adapters::filter_map::FilterMap<alloc[711343b0859624ae]::vec::into_iter::IntoIter<(usize, &rustc_middle[9c7ab4e9add10f55]::mir::mono::CodegenUnit)>, rustc_data_structures[8139e0af6646de16]::sync::parallel::par_map<(usize, &rustc_middle[9c7ab4e9add10f55]::mir::mono::CodegenUnit), alloc[711343b0859624ae]::vec::Vec<(usize, &rustc_middle[9c7ab4e9add10f55]::mir::mono::CodegenUnit)>, rustc_codegen_cranelift[d57ac2c89507235b]::driver::aot::OngoingModuleCodegen, alloc[711343b0859624ae]::vec::Vec<rustc_codegen_cranelift[d57ac2c89507235b]::driver::aot::OngoingModuleCodegen>, rustc_codegen_cranelift[d57ac2c89507235b]::driver::aot::run_aot::{closure#3}::{closure#0}>::{closure#0}::{closure#1}> as core[81f20be6a9f9564c]::iter::traits::iterator::Iterator>::next
  20:     0x726d0405e048 - rustc_codegen_cranelift[d57ac2c89507235b]::driver::aot::run_aot
  21:     0x726d0408de5e - <rustc_codegen_cranelift[d57ac2c89507235b]::CraneliftCodegenBackend as rustc_codegen_ssa[7f4907f107dcb8dc]::traits::backend::CodegenBackend>::codegen_crate
  22:     0x726d143da124 - <rustc_interface[72cf5c0d50897366]::queries::Linker>::codegen_and_build_linker
  23:     0x726d14394092 - rustc_interface[72cf5c0d50897366]::passes::create_and_enter_global_ctxt::<core[81f20be6a9f9564c]::option::Option<rustc_interface[72cf5c0d50897366]::queries::Linker>, rustc_driver_impl[8d99f66bc3884647]::run_compiler::{closure#0}::{closure#2}>::{closure#2}::{closure#0}
  24:     0x726d1440e103 - rustc_interface[72cf5c0d50897366]::interface::run_compiler::<(), rustc_driver_impl[8d99f66bc3884647]::run_compiler::{closure#0}>::{closure#1}
  25:     0x726d14315047 - std[6ff18fa302d30141]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[72cf5c0d50897366]::util::run_in_thread_with_globals<rustc_interface[72cf5c0d50897366]::util::run_in_thread_pool_with_globals<rustc_interface[72cf5c0d50897366]::interface::run_compiler<(), rustc_driver_impl[8d99f66bc3884647]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>
  26:     0x726d143154dc - <<std[6ff18fa302d30141]::thread::Builder>::spawn_unchecked_<rustc_interface[72cf5c0d50897366]::util::run_in_thread_with_globals<rustc_interface[72cf5c0d50897366]::util::run_in_thread_pool_with_globals<rustc_interface[72cf5c0d50897366]::interface::run_compiler<(), rustc_driver_impl[8d99f66bc3884647]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>::{closure#1} as core[81f20be6a9f9564c]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  27:     0x726d14316ac1 - std::sys::pal::unix::thread::Thread::new::thread_start::h53013642de68d0e4
  28:     0x726d0e6a339d - <unknown>
  29:     0x726d0e72849c - <unknown>
  30:                0x0 - <unknown>

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 make sure that you have updated to the latest nightly

note: rustc 1.85.0-nightly (37e74596c 2024-12-18) running on x86_64-unknown-linux-gnu

note: compiler flags: -Z codegen-backend=cranelift -Z dump-mir-dir=dir

query stack during panic:
end of query stack

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions