Skip to content

ICE: abi_map: None #142107

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

Open
matthiaskrgr opened this issue Jun 6, 2025 · 5 comments · May be fixed by #142134
Open

ICE: abi_map: None #142107

matthiaskrgr opened this issue Jun 6, 2025 · 5 comments · May be fixed by #142134
Labels
A-ABI Area: Concerning the application binary interface (ABI) C-bug Category: This is a bug. 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

auto-reduced (treereduce-rust):

//@compile-flags: -Clink-dead-code=true
#![feature(extended_varargs_abi_support)]
fn aapcs(f: extern "aapcs" fn(usize, ...)) {
    f(22, 44);
}

fn main() {}

original:

//@ only-arm
//@ build-pass
#![allow(named_arguments_used_positionally)]

fn aapcs(f: extern "aapcs" fn(usize, ...)) {
    f(22, 44);
}

fn main() {}

Version information

rustc 1.89.0-nightly (cf423712b 2025-06-05)
binary: rustc
commit-hash: cf423712b9e95e9f6ec84b1ecb3d125e55ac8d56
commit-date: 2025-06-05
host: x86_64-unknown-linux-gnu
release: 1.89.0-nightly
LLVM version: 20.1.5

Possibly related line of code:

Self::Direct(abi) | Self::Deprecated(abi) => Some(abi),
Self::Invalid => None,
}
}
pub fn unwrap(self) -> CanonAbi {
self.into_option().unwrap()
}
pub fn is_mapped(self) -> bool {
self.into_option().is_some()
}
}

Command:
/home/matthias/.rustup/toolchains/master/bin/rustc -Clink-dead-code=true -Zcrate-attr=feature(extended_varargs_abi_support)

Program output

warning: the calling convention "aapcs" is not supported on this target
 --> /tmp/icemaker_global_tempdir.H2Ee9GDZaH3Q/rustc_testrunner_tmpdir_reporting.Q8z8e0R93hNQ/mvce.rs:1:13
  |
1 | fn aapcs(f: extern "aapcs" fn(usize, ...)) {
  |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
  = note: for more information, see issue #130260 <https://github.com/rust-lang/rust/issues/130260>
  = note: `#[warn(unsupported_fn_ptr_calling_conventions)]` on by default

warning: function `aapcs` is never used
 --> /tmp/icemaker_global_tempdir.H2Ee9GDZaH3Q/rustc_testrunner_tmpdir_reporting.Q8z8e0R93hNQ/mvce.rs:1:4
  |
1 | fn aapcs(f: extern "aapcs" fn(usize, ...)) {
  |    ^^^^^
  |
  = note: `#[warn(dead_code)]` on by default


thread 'rustc' panicked at compiler/rustc_target/src/spec/abi_map.rs:33:28:
called `Option::unwrap()` on a `None` value
stack backtrace:
   0:     0x741a3b4649e3 - <std::sys::backtrace::BacktraceLock::print::DisplayBacktrace as core::fmt::Display>::fmt::h2c72d8464c6e7078
   1:     0x741a3bc029f7 - core::fmt::write::h57fa85e1fefbdee0
   2:     0x741a3b45a753 - std::io::Write::write_fmt::hde18502dccfe8387
   3:     0x741a3b464842 - std::sys::backtrace::BacktraceLock::print::h142f1f2eb047aa28
   4:     0x741a3b46843a - std::panicking::default_hook::{{closure}}::h3ea40447870cd95c
   5:     0x741a3b467fbf - std::panicking::default_hook::h75e0b809b03fc60c
   6:     0x741a3a55d303 - std[126408c7f9fb25ab]::panicking::update_hook::<alloc[60ccada38a9f8a3b]::boxed::Box<rustc_driver_impl[9e08e94f90f4707c]::install_ice_hook::{closure#1}>>::{closure#0}
   7:     0x741a3b468cb3 - std::panicking::rust_panic_with_hook::hd9a1e74d4ae3efb9
   8:     0x741a3b468976 - std::panicking::begin_panic_handler::{{closure}}::h934ad1bd7ef79922
   9:     0x741a3b464eb9 - std::sys::backtrace::__rust_end_short_backtrace::hf7dfbc47684e5044
  10:     0x741a3b46866d - __rustc[3c591ca183ed768b]::rust_begin_unwind
  11:     0x741a37c74bc0 - core::panicking::panic_fmt::hc5cfb34418404b01
  12:     0x741a37eb986c - core::panicking::panic::h433cf0f2be091102
  13:     0x741a37c76519 - core::option::unwrap_failed::h380d4c1c07e438b4
  14:     0x741a3c1a831b - rustc_ty_utils[74b2f05863926281]::abi::fn_abi_new_uncached
  15:     0x741a3c1a05e7 - rustc_ty_utils[74b2f05863926281]::abi::fn_abi_of_fn_ptr
  16:     0x741a3c1a057a - rustc_query_impl[2ece3ecac821dbcb]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[2ece3ecac821dbcb]::query_impl::fn_abi_of_fn_ptr::dynamic_query::{closure#2}::{closure#0}, rustc_middle[2dfb1ec257bea9a6]::query::erase::Erased<[u8; 16usize]>>
  17:     0x741a3c1a0539 - <rustc_query_impl[2ece3ecac821dbcb]::query_impl::fn_abi_of_fn_ptr::dynamic_query::{closure#2} as core[dc170bfee6ea9f4c]::ops::function::FnOnce<(rustc_middle[2dfb1ec257bea9a6]::ty::context::TyCtxt, rustc_middle[2dfb1ec257bea9a6]::ty::PseudoCanonicalInput<(rustc_type_ir[981db32a513602bc]::binder::Binder<rustc_middle[2dfb1ec257bea9a6]::ty::context::TyCtxt, rustc_type_ir[981db32a513602bc]::ty_kind::FnSig<rustc_middle[2dfb1ec257bea9a6]::ty::context::TyCtxt>>, &rustc_middle[2dfb1ec257bea9a6]::ty::list::RawList<(), rustc_middle[2dfb1ec257bea9a6]::ty::Ty>)>)>>::call_once
  18:     0x741a3cf93395 - rustc_query_system[b7defdb8b233bb23]::query::plumbing::try_execute_query::<rustc_query_impl[2ece3ecac821dbcb]::DynamicConfig<rustc_query_system[b7defdb8b233bb23]::query::caches::DefaultCache<rustc_middle[2dfb1ec257bea9a6]::ty::PseudoCanonicalInput<(rustc_type_ir[981db32a513602bc]::binder::Binder<rustc_middle[2dfb1ec257bea9a6]::ty::context::TyCtxt, rustc_type_ir[981db32a513602bc]::ty_kind::FnSig<rustc_middle[2dfb1ec257bea9a6]::ty::context::TyCtxt>>, &rustc_middle[2dfb1ec257bea9a6]::ty::list::RawList<(), rustc_middle[2dfb1ec257bea9a6]::ty::Ty>)>, rustc_middle[2dfb1ec257bea9a6]::query::erase::Erased<[u8; 16usize]>>, false, false, false>, rustc_query_impl[2ece3ecac821dbcb]::plumbing::QueryCtxt, false>
  19:     0x741a3cf93006 - rustc_query_impl[2ece3ecac821dbcb]::query_impl::fn_abi_of_fn_ptr::get_query_non_incr::__rust_end_short_backtrace
  20:     0x741a391acc7b - rustc_monomorphize[d4a7340d772456de]::mono_checks::check_mono_item
  21:     0x741a3c564fa0 - rustc_query_impl[2ece3ecac821dbcb]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[2ece3ecac821dbcb]::query_impl::check_mono_item::dynamic_query::{closure#2}::{closure#0}, rustc_middle[2dfb1ec257bea9a6]::query::erase::Erased<[u8; 0usize]>>
  22:     0x741a3c5303b3 - rustc_query_system[b7defdb8b233bb23]::query::plumbing::try_execute_query::<rustc_query_impl[2ece3ecac821dbcb]::DynamicConfig<rustc_query_system[b7defdb8b233bb23]::query::caches::DefaultCache<rustc_middle[2dfb1ec257bea9a6]::ty::instance::Instance, rustc_middle[2dfb1ec257bea9a6]::query::erase::Erased<[u8; 0usize]>>, false, false, false>, rustc_query_impl[2ece3ecac821dbcb]::plumbing::QueryCtxt, false>
  23:     0x741a3c530051 - rustc_query_impl[2ece3ecac821dbcb]::query_impl::check_mono_item::get_query_non_incr::__rust_end_short_backtrace
  24:     0x741a3c53a554 - rustc_monomorphize[d4a7340d772456de]::collector::items_of_instance
  25:     0x741a3c53a3f2 - rustc_query_impl[2ece3ecac821dbcb]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[2ece3ecac821dbcb]::query_impl::items_of_instance::dynamic_query::{closure#2}::{closure#0}, rustc_middle[2dfb1ec257bea9a6]::query::erase::Erased<[u8; 32usize]>>
  26:     0x741a3c5512eb - rustc_query_system[b7defdb8b233bb23]::query::plumbing::try_execute_query::<rustc_query_impl[2ece3ecac821dbcb]::DynamicConfig<rustc_query_system[b7defdb8b233bb23]::query::caches::DefaultCache<(rustc_middle[2dfb1ec257bea9a6]::ty::instance::Instance, rustc_middle[2dfb1ec257bea9a6]::mir::mono::CollectionMode), rustc_middle[2dfb1ec257bea9a6]::query::erase::Erased<[u8; 32usize]>>, false, false, false>, rustc_query_impl[2ece3ecac821dbcb]::plumbing::QueryCtxt, false>
  27:     0x741a3c550f3f - rustc_query_impl[2ece3ecac821dbcb]::query_impl::items_of_instance::get_query_non_incr::__rust_end_short_backtrace
  28:     0x741a3c554181 - rustc_monomorphize[d4a7340d772456de]::collector::collect_items_rec
  29:     0x741a3c56ca61 - rustc_monomorphize[d4a7340d772456de]::collector::collect_crate_mono_items::{closure#1}::{closure#0}
  30:     0x741a3c34d172 - rustc_monomorphize[d4a7340d772456de]::partitioning::collect_and_partition_mono_items
  31:     0x741a3d000656 - rustc_query_impl[2ece3ecac821dbcb]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[2ece3ecac821dbcb]::query_impl::collect_and_partition_mono_items::dynamic_query::{closure#2}::{closure#0}, rustc_middle[2dfb1ec257bea9a6]::query::erase::Erased<[u8; 40usize]>>
  32:     0x741a3d000633 - <rustc_query_impl[2ece3ecac821dbcb]::query_impl::collect_and_partition_mono_items::dynamic_query::{closure#2} as core[dc170bfee6ea9f4c]::ops::function::FnOnce<(rustc_middle[2dfb1ec257bea9a6]::ty::context::TyCtxt, ())>>::call_once
  33:     0x741a3d000163 - rustc_query_system[b7defdb8b233bb23]::query::plumbing::try_execute_query::<rustc_query_impl[2ece3ecac821dbcb]::DynamicConfig<rustc_query_system[b7defdb8b233bb23]::query::caches::SingleCache<rustc_middle[2dfb1ec257bea9a6]::query::erase::Erased<[u8; 40usize]>>, false, false, false>, rustc_query_impl[2ece3ecac821dbcb]::plumbing::QueryCtxt, false>
  34:     0x741a3cffff03 - rustc_query_impl[2ece3ecac821dbcb]::query_impl::collect_and_partition_mono_items::get_query_non_incr::__rust_end_short_backtrace
  35:     0x741a3cd04da6 - <rustc_codegen_llvm[74920c8061377519]::LlvmCodegenBackend as rustc_codegen_ssa[4ebb316766ae7b2b]::traits::backend::CodegenBackend>::codegen_crate
  36:     0x741a3d0194a7 - <rustc_interface[1764bd4a174bd5e5]::queries::Linker>::codegen_and_build_linker
  37:     0x741a3d0171b0 - rustc_interface[1764bd4a174bd5e5]::passes::create_and_enter_global_ctxt::<core[dc170bfee6ea9f4c]::option::Option<rustc_interface[1764bd4a174bd5e5]::queries::Linker>, rustc_driver_impl[9e08e94f90f4707c]::run_compiler::{closure#0}::{closure#2}>::{closure#2}::{closure#0}
  38:     0x741a3ce633f0 - rustc_interface[1764bd4a174bd5e5]::interface::run_compiler::<(), rustc_driver_impl[9e08e94f90f4707c]::run_compiler::{closure#0}>::{closure#1}
  39:     0x741a3ccc7c3e - std[126408c7f9fb25ab]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[1764bd4a174bd5e5]::util::run_in_thread_with_globals<rustc_interface[1764bd4a174bd5e5]::util::run_in_thread_pool_with_globals<rustc_interface[1764bd4a174bd5e5]::interface::run_compiler<(), rustc_driver_impl[9e08e94f90f4707c]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>
  40:     0x741a3ccc7916 - <<std[126408c7f9fb25ab]::thread::Builder>::spawn_unchecked_<rustc_interface[1764bd4a174bd5e5]::util::run_in_thread_with_globals<rustc_interface[1764bd4a174bd5e5]::util::run_in_thread_pool_with_globals<rustc_interface[1764bd4a174bd5e5]::interface::run_compiler<(), rustc_driver_impl[9e08e94f90f4707c]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>::{closure#1} as core[dc170bfee6ea9f4c]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  41:     0x741a3ccc8ebd - std::sys::pal::unix::thread::Thread::new::thread_start::h5f39a95471057294
  42:     0x741a368a57eb - <unknown>
  43:     0x741a3692918c - <unknown>
  44:                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.89.0-nightly (cf423712b 2025-06-05) running on x86_64-unknown-linux-gnu

note: compiler flags: -C link-dead-code=true -Z crate-attr=feature(extended_varargs_abi_support) -Z dump-mir-dir=dir

query stack during panic:
#0 [fn_abi_of_fn_ptr] computing call ABI of `extern "aapcs" fn(usize, ...)` function pointers
#1 [check_mono_item] monomorphization-time checking
#2 [items_of_instance] collecting items used by `aapcs`
#3 [collect_and_partition_mono_items] collect_and_partition_mono_items
end of query stack
warning: 2 warnings emitted


@rustbot label +F-extended_varargs_abi_support

@matthiaskrgr matthiaskrgr added 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. C-bug Category: This is a bug. labels Jun 6, 2025
@rustbot rustbot added needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. F-extended_varargs_abi_support `#![feature(extended_varargs_abi_support)]` labels Jun 6, 2025
@workingjubilee
Copy link
Member

workingjubilee commented Jun 6, 2025

that is very not the related line of code, what matters is the caller. it also has nothing to do with that feature.

@workingjubilee
Copy link
Member

workingjubilee commented Jun 6, 2025

This is fixed by an already-open PR, #141877

@workingjubilee workingjubilee removed the F-extended_varargs_abi_support `#![feature(extended_varargs_abi_support)]` label Jun 6, 2025
@matthiaskrgr
Copy link
Member Author

bisects to #141569

@jieyouxu jieyouxu added A-ABI Area: Concerning the application binary interface (ABI) and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Jun 6, 2025
@bjorn3 bjorn3 added the requires-nightly This issue requires a nightly compiler in some way. label Jun 6, 2025
@workingjubilee
Copy link
Member

wait, -Clink-dead-code? I guess it doesn't then.

rust-bors bot added a commit that referenced this issue Jun 6, 2025
Reject `extern "{abi}"` when the target does not support it

## What

Promote [`unsupported_fn_ptr_calling_conventions`] from a warning to a hard error, making sure edge-cases will not escape. We now emit hard errors for every case we would return `Invalid` from `AbiMap::canonize_abi` during AST to HIR lowering. In particular, these architecture-specific ABIs now only compile on their architectures[^1]:
  - amdgpu: "gpu-kernel"
  - arm: "aapcs", "C-cmse-nonsecure-entry"
  - avr: "avr-interrupt", "avr-non-blocking-interrupt"
  - msp430: "msp430-interrupt"
  - nvptx64: "gpu-kernel", "ptx-kernel"
  - riscv32 and riscv64: "riscv-interrupt-machine", "riscv-interrupt-supervisor"
  - x86: "thiscall"
  - x86 and x86_64: "x86-interrupt"
  - x86_64: "sysv64", "win64"

The panoply of ABIs that are logically x86-specific but actually permitted on all Windows targets remain supported on Windows, as they were before. For non-Windows targets they error if the architecture does not match.

Moving the check into AST lowering **is itself a breaking change in rare cases**, above and beyond the cases rustc currently warns about. See "Why or Why Not" for details.

## How

We modify rustc_ast_lowering to prevent unsupported ABIs from leaking through the HIR without being checked for target support. Previously ad-hoc checking on various HIR items required making sure we check every HIR item which could contain an `extern "{abi}"` string. This is a losing proposition compared to gating the lowering itself.

As a consequence, unsupported ABI strings will now hard-error instead of triggering the FCW `unsupported_fn_ptr_calling_conventions`.

However, per #86232 this does cause errors for rare usages of `extern "{abi}"` that were theoretically possible to write in Rust source, without previous warning or error. For instance, trait declarations without impls were never checked. These are the exact kinds of leakages that this new approach prevents.

This differs from the following PRs:
- #141435 is orthogonal, as it adds a new lint for ABIs we have not warned on and are not touched by this PR
- #141877 is subsumed by this, in that this simply cuts out bad functionality instead of adding epicycles for stable code

## Why or Why Not

We already made the decision to issue the `unsupported_fn_ptr_calling_conventions` future compatibility warning. It has warned in dependencies since #135767, which reached stable with Rust 1.87. That was released on 2025 May 17, and it is now June. As we already had erred on these ABI strings in most other positions, and warn on stable for function pointer types, this breakage has had reasonable foreshadowing.

Upgrading the warning to an error addresses a real problem. In some cases the Rust compiler can attempt to actually compute the ABI for calling a function. We could accept this case and compute unsupported ABIs according to some other ABI, silently[^0]. However, this obviously exposes Rust to errors in codegen. We cannot lower directly to the "obvious" ABI and then trust code generators like LLVM to reliably error on these cases, either.

Refactoring the compiler so we could defer more ABI computations would be possible, but seems weakly motivated. Even if we succeeded, we would at minimum risk:
- exposing the "whack-a-mole" problem but "approaching linking" instead of "leaving AST"
- making it harder to reason about functions we *can* lower further
- complicating the compiler for no clear benefit

A deprecation cycle for the edge-cases could be implemented first, but it is not very useful for such marginal cases, like this trait declaration without a definition:
```rust
pub trait UsedToSneakBy {
    pub extern "gpu-kernel" fn sneaky();
}
```

Upon any impl, even for provided fn within trait declarations, e.g. `pub extern "gpu-kernel" fn sneaky() {}`, different HIR types were used which would, in fact, get checked. Likewise with anything with function pointers. Thus we would be discussing deprecation cycles for code that is impotent or forewarned[^2].

Implementing a deprecation cycle _is_ possible, but it would likely require emitting multiple of a functionally identical warning or error on code that would not have multiple warnings or errors before. It is also not clear to me we would not find **another**, even more marginal edge-case that slipped through, as "things slip through" is the motivation for checking earlier. Additional effort spent on additional warnings should require committing to a hard limit first.

r? lang

Fixes #86232
Fixes #132430
Fixes #138738
Fixes #142107

[`unsupported_fn_ptr_calling_conventions`]: #130260
[^1]: Some already will not compile, due to reaching ICEs or LLVM errors.
[^0]:  We already do this for all `AbiStr` we cannot parse, pretending they are `ExternAbi::Rust`, but we also emit an error to prevent reaching too far into codegen.
[^2]: It actually did appear in two cases in rustc's test suite because we are a collection of Rust edge-cases by the simple fact that we don't care if the code actually runs. These cases were excised in c1db989.
@matthiaskrgr
Copy link
Member Author

we can make that pub so that it isn't ignored

#![feature(extended_varargs_abi_support)]
#![crate_type="lib"]
pub fn aapcs(f: extern "aapcs" fn(usize, ...)) {
    f(22, 44);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-ABI Area: Concerning the application binary interface (ABI) C-bug Category: This is a bug. 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
Development

Successfully merging a pull request may close this issue.

5 participants