Skip to content

ICE: internal compiler error[E0391]: cycle detected when computing function signature of impl #132430

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 Oct 31, 2024 · 2 comments · May be fixed by #141877 or #142134
Open
Labels
A-ABI Area: Concerning the application binary interface (ABI) A-diagnostics Area: Messages for errors, warnings, and lints C-bug Category: This is a bug. F-cmse_nonsecure_entry `#![feature(cmse_nonsecure_entry)]` I-cycle Issue: A query cycle occurred while none was expected I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ S-bug-has-test Status: This bug is tracked inside the repo by a `known-bug` test. S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue 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: --edition=2018 --crate-type=lib
#![feature(cmse_nonsecure_entry)]
struct Test;

impl Test {
    pub async unsafe extern "C-cmse-nonsecure-entry" fn test(val: &str) {}
}

original:

struct Test;

impl Test {
    pub async unsafe extern "C-cmse-nonsecure-entry" fn test(val: &str) {

    }
}

Version information

rustc 1.84.0-nightly (a0d98ff0e 2024-10-31)
binary: rustc
commit-hash: a0d98ff0e5b6e1f2c63fd26f68484792621b235c
commit-date: 2024-10-31
host: x86_64-unknown-linux-gnu
release: 1.84.0-nightly
LLVM version: 19.1.1

Command:
/home/matthias/.rustup/toolchains/master/bin/rustc -Zcrate-attr=feature(cmse_nonsecure_entry) --edition=2018 --crate-type=lib

Program output

warning: struct `Test` is never constructed
 --> /tmp/icemaker_global_tempdir.q2k4BBLCKuN9/rustc_testrunner_tmpdir_reporting.5aASWsrfzxJL/mvce.rs:1:8
  |
1 | struct Test;
  |        ^^^^
  |
  = note: `#[warn(dead_code)]` on by default

warning: associated function `test` is never used
 --> /tmp/icemaker_global_tempdir.q2k4BBLCKuN9/rustc_testrunner_tmpdir_reporting.5aASWsrfzxJL/mvce.rs:4:57
  |
3 | impl Test {
  | --------- associated function in this implementation
4 |     pub async unsafe extern "C-cmse-nonsecure-entry" fn test(val: &str) {}
  |                                                         ^^^^

warning: `extern` fn uses type `str`, which is not FFI-safe
 --> /tmp/icemaker_global_tempdir.q2k4BBLCKuN9/rustc_testrunner_tmpdir_reporting.5aASWsrfzxJL/mvce.rs:4:67
  |
4 |     pub async unsafe extern "C-cmse-nonsecure-entry" fn test(val: &str) {}
  |                                                                   ^^^^ not FFI-safe
  |
  = help: consider using `*const u8` and a length instead
  = note: string slices have no C equivalent
  = note: `#[warn(improper_ctypes_definitions)]` on by default

warning: `extern` fn uses type `impl Future<Output = ()>`, which is not FFI-safe
 --> /tmp/icemaker_global_tempdir.q2k4BBLCKuN9/rustc_testrunner_tmpdir_reporting.5aASWsrfzxJL/mvce.rs:4:5
  |
4 |     pub async unsafe extern "C-cmse-nonsecure-entry" fn test(val: &str) {}
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not FFI-safe
  |
  = note: opaque types have no C equivalent

warning: 4 warnings emitted

note: no errors encountered even though delayed bugs were created

note: those delayed bugs will now be shown as internal compiler errors

error: internal compiler error[E0391]: cycle detected when computing function signature of `<impl at /tmp/icemaker_global_tempdir.q2k4BBLCKuN9/rustc_testrunner_tmpdir_reporting.5aASWsrfzxJL/mvce.rs:3:1: 3:10>::test`
 --> /tmp/icemaker_global_tempdir.q2k4BBLCKuN9/rustc_testrunner_tmpdir_reporting.5aASWsrfzxJL/mvce.rs:4:5
  |
4 |     pub async unsafe extern "C-cmse-nonsecure-entry" fn test(val: &str) {}
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: ...which requires computing layout of `<impl at /tmp/icemaker_global_tempdir.q2k4BBLCKuN9/rustc_testrunner_tmpdir_reporting.5aASWsrfzxJL/mvce.rs:3:1: 3:10>::test::{opaque#0}`...
  = note: ...which requires normalizing `<impl at /tmp/icemaker_global_tempdir.q2k4BBLCKuN9/rustc_testrunner_tmpdir_reporting.5aASWsrfzxJL/mvce.rs:3:1: 3:10>::test::{opaque#0}`...
note: ...which requires computing type of `<impl at /tmp/icemaker_global_tempdir.q2k4BBLCKuN9/rustc_testrunner_tmpdir_reporting.5aASWsrfzxJL/mvce.rs:3:1: 3:10>::test::{opaque#0}`...
 --> /tmp/icemaker_global_tempdir.q2k4BBLCKuN9/rustc_testrunner_tmpdir_reporting.5aASWsrfzxJL/mvce.rs:4:5
  |
4 |     pub async unsafe extern "C-cmse-nonsecure-entry" fn test(val: &str) {}
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: ...which requires computing type of opaque `<impl at /tmp/icemaker_global_tempdir.q2k4BBLCKuN9/rustc_testrunner_tmpdir_reporting.5aASWsrfzxJL/mvce.rs:3:1: 3:10>::test::{opaque#0}`...
 --> /tmp/icemaker_global_tempdir.q2k4BBLCKuN9/rustc_testrunner_tmpdir_reporting.5aASWsrfzxJL/mvce.rs:4:5
  |
4 |     pub async unsafe extern "C-cmse-nonsecure-entry" fn test(val: &str) {}
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: ...which requires type-checking `<impl at /tmp/icemaker_global_tempdir.q2k4BBLCKuN9/rustc_testrunner_tmpdir_reporting.5aASWsrfzxJL/mvce.rs:3:1: 3:10>::test`...
 --> /tmp/icemaker_global_tempdir.q2k4BBLCKuN9/rustc_testrunner_tmpdir_reporting.5aASWsrfzxJL/mvce.rs:4:5
  |
4 |     pub async unsafe extern "C-cmse-nonsecure-entry" fn test(val: &str) {}
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: ...which requires computing the opaque types defined by `<impl at /tmp/icemaker_global_tempdir.q2k4BBLCKuN9/rustc_testrunner_tmpdir_reporting.5aASWsrfzxJL/mvce.rs:3:1: 3:10>::test`...
 --> /tmp/icemaker_global_tempdir.q2k4BBLCKuN9/rustc_testrunner_tmpdir_reporting.5aASWsrfzxJL/mvce.rs:4:5
  |
4 |     pub async unsafe extern "C-cmse-nonsecure-entry" fn test(val: &str) {}
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  = note: ...which again requires computing function signature of `<impl at /tmp/icemaker_global_tempdir.q2k4BBLCKuN9/rustc_testrunner_tmpdir_reporting.5aASWsrfzxJL/mvce.rs:3:1: 3:10>::test`, completing the cycle
note: cycle used when checking that `<impl at /tmp/icemaker_global_tempdir.q2k4BBLCKuN9/rustc_testrunner_tmpdir_reporting.5aASWsrfzxJL/mvce.rs:3:1: 3:10>::test` is well-formed
 --> /tmp/icemaker_global_tempdir.q2k4BBLCKuN9/rustc_testrunner_tmpdir_reporting.5aASWsrfzxJL/mvce.rs:4:5
  |
4 |     pub async unsafe extern "C-cmse-nonsecure-entry" fn test(val: &str) {}
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  = note: see https://rustc-dev-guide.rust-lang.org/overview.html#queries and https://rustc-dev-guide.rust-lang.org/query.html for more information
note: delayed at compiler/rustc_query_system/src/query/job.rs:596:16 - disabled backtrace
 --> /tmp/icemaker_global_tempdir.q2k4BBLCKuN9/rustc_testrunner_tmpdir_reporting.5aASWsrfzxJL/mvce.rs:4:5
  |
4 |     pub async unsafe extern "C-cmse-nonsecure-entry" fn test(val: &str) {}
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: internal compiler error[E0391]: cycle detected when computing function signature of `<impl at /tmp/icemaker_global_tempdir.q2k4BBLCKuN9/rustc_testrunner_tmpdir_reporting.5aASWsrfzxJL/mvce.rs:3:1: 3:10>::test`
 --> /tmp/icemaker_global_tempdir.q2k4BBLCKuN9/rustc_testrunner_tmpdir_reporting.5aASWsrfzxJL/mvce.rs:4:5
  |
4 |     pub async unsafe extern "C-cmse-nonsecure-entry" fn test(val: &str) {}
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: ...which requires computing layout of `<impl at /tmp/icemaker_global_tempdir.q2k4BBLCKuN9/rustc_testrunner_tmpdir_reporting.5aASWsrfzxJL/mvce.rs:3:1: 3:10>::test::{opaque#0}`...
  = note: ...which requires normalizing `<impl at /tmp/icemaker_global_tempdir.q2k4BBLCKuN9/rustc_testrunner_tmpdir_reporting.5aASWsrfzxJL/mvce.rs:3:1: 3:10>::test::{opaque#0}`...
note: ...which requires computing type of `<impl at /tmp/icemaker_global_tempdir.q2k4BBLCKuN9/rustc_testrunner_tmpdir_reporting.5aASWsrfzxJL/mvce.rs:3:1: 3:10>::test::{opaque#0}`...
 --> /tmp/icemaker_global_tempdir.q2k4BBLCKuN9/rustc_testrunner_tmpdir_reporting.5aASWsrfzxJL/mvce.rs:4:5
  |
4 |     pub async unsafe extern "C-cmse-nonsecure-entry" fn test(val: &str) {}
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: ...which requires computing type of opaque `<impl at /tmp/icemaker_global_tempdir.q2k4BBLCKuN9/rustc_testrunner_tmpdir_reporting.5aASWsrfzxJL/mvce.rs:3:1: 3:10>::test::{opaque#0}`...
 --> /tmp/icemaker_global_tempdir.q2k4BBLCKuN9/rustc_testrunner_tmpdir_reporting.5aASWsrfzxJL/mvce.rs:4:5
  |
4 |     pub async unsafe extern "C-cmse-nonsecure-entry" fn test(val: &str) {}
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: ...which requires type-checking `<impl at /tmp/icemaker_global_tempdir.q2k4BBLCKuN9/rustc_testrunner_tmpdir_reporting.5aASWsrfzxJL/mvce.rs:3:1: 3:10>::test`...
 --> /tmp/icemaker_global_tempdir.q2k4BBLCKuN9/rustc_testrunner_tmpdir_reporting.5aASWsrfzxJL/mvce.rs:4:5
  |
4 |     pub async unsafe extern "C-cmse-nonsecure-entry" fn test(val: &str) {}
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  = note: ...which again requires computing function signature of `<impl at /tmp/icemaker_global_tempdir.q2k4BBLCKuN9/rustc_testrunner_tmpdir_reporting.5aASWsrfzxJL/mvce.rs:3:1: 3:10>::test`, completing the cycle
note: cycle used when checking that `<impl at /tmp/icemaker_global_tempdir.q2k4BBLCKuN9/rustc_testrunner_tmpdir_reporting.5aASWsrfzxJL/mvce.rs:3:1: 3:10>::test` is well-formed
 --> /tmp/icemaker_global_tempdir.q2k4BBLCKuN9/rustc_testrunner_tmpdir_reporting.5aASWsrfzxJL/mvce.rs:4:5
  |
4 |     pub async unsafe extern "C-cmse-nonsecure-entry" fn test(val: &str) {}
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  = note: see https://rustc-dev-guide.rust-lang.org/overview.html#queries and https://rustc-dev-guide.rust-lang.org/query.html for more information
note: delayed at compiler/rustc_query_system/src/query/job.rs:596:16 - disabled backtrace
 --> /tmp/icemaker_global_tempdir.q2k4BBLCKuN9/rustc_testrunner_tmpdir_reporting.5aASWsrfzxJL/mvce.rs:4:5
  |
4 |     pub async unsafe extern "C-cmse-nonsecure-entry" fn test(val: &str) {}
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: internal compiler error[E0391]: cycle detected when computing function signature of `<impl at /tmp/icemaker_global_tempdir.q2k4BBLCKuN9/rustc_testrunner_tmpdir_reporting.5aASWsrfzxJL/mvce.rs:3:1: 3:10>::test`
 --> /tmp/icemaker_global_tempdir.q2k4BBLCKuN9/rustc_testrunner_tmpdir_reporting.5aASWsrfzxJL/mvce.rs:4:5
  |
4 |     pub async unsafe extern "C-cmse-nonsecure-entry" fn test(val: &str) {}
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: ...which requires computing layout of `<impl at /tmp/icemaker_global_tempdir.q2k4BBLCKuN9/rustc_testrunner_tmpdir_reporting.5aASWsrfzxJL/mvce.rs:3:1: 3:10>::test::{opaque#0}`...
  = note: ...which requires normalizing `<impl at /tmp/icemaker_global_tempdir.q2k4BBLCKuN9/rustc_testrunner_tmpdir_reporting.5aASWsrfzxJL/mvce.rs:3:1: 3:10>::test::{opaque#0}`...
note: ...which requires computing type of `<impl at /tmp/icemaker_global_tempdir.q2k4BBLCKuN9/rustc_testrunner_tmpdir_reporting.5aASWsrfzxJL/mvce.rs:3:1: 3:10>::test::{opaque#0}`...
 --> /tmp/icemaker_global_tempdir.q2k4BBLCKuN9/rustc_testrunner_tmpdir_reporting.5aASWsrfzxJL/mvce.rs:4:5
  |
4 |     pub async unsafe extern "C-cmse-nonsecure-entry" fn test(val: &str) {}
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: ...which requires computing type of opaque `<impl at /tmp/icemaker_global_tempdir.q2k4BBLCKuN9/rustc_testrunner_tmpdir_reporting.5aASWsrfzxJL/mvce.rs:3:1: 3:10>::test::{opaque#0}`...
 --> /tmp/icemaker_global_tempdir.q2k4BBLCKuN9/rustc_testrunner_tmpdir_reporting.5aASWsrfzxJL/mvce.rs:4:5
  |
4 |     pub async unsafe extern "C-cmse-nonsecure-entry" fn test(val: &str) {}
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: ...which requires borrow-checking `<impl at /tmp/icemaker_global_tempdir.q2k4BBLCKuN9/rustc_testrunner_tmpdir_reporting.5aASWsrfzxJL/mvce.rs:3:1: 3:10>::test`...
 --> /tmp/icemaker_global_tempdir.q2k4BBLCKuN9/rustc_testrunner_tmpdir_reporting.5aASWsrfzxJL/mvce.rs:4:5
  |
4 |     pub async unsafe extern "C-cmse-nonsecure-entry" fn test(val: &str) {}
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: ...which requires promoting constants in MIR for `<impl at /tmp/icemaker_global_tempdir.q2k4BBLCKuN9/rustc_testrunner_tmpdir_reporting.5aASWsrfzxJL/mvce.rs:3:1: 3:10>::test`...
 --> /tmp/icemaker_global_tempdir.q2k4BBLCKuN9/rustc_testrunner_tmpdir_reporting.5aASWsrfzxJL/mvce.rs:4:5
  |
4 |     pub async unsafe extern "C-cmse-nonsecure-entry" fn test(val: &str) {}
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: ...which requires checking if `<impl at /tmp/icemaker_global_tempdir.q2k4BBLCKuN9/rustc_testrunner_tmpdir_reporting.5aASWsrfzxJL/mvce.rs:3:1: 3:10>::test` contains FFI-unwind calls...
 --> /tmp/icemaker_global_tempdir.q2k4BBLCKuN9/rustc_testrunner_tmpdir_reporting.5aASWsrfzxJL/mvce.rs:4:5
  |
4 |     pub async unsafe extern "C-cmse-nonsecure-entry" fn test(val: &str) {}
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: ...which requires building MIR for `<impl at /tmp/icemaker_global_tempdir.q2k4BBLCKuN9/rustc_testrunner_tmpdir_reporting.5aASWsrfzxJL/mvce.rs:3:1: 3:10>::test`...
 --> /tmp/icemaker_global_tempdir.q2k4BBLCKuN9/rustc_testrunner_tmpdir_reporting.5aASWsrfzxJL/mvce.rs:4:5
  |
4 |     pub async unsafe extern "C-cmse-nonsecure-entry" fn test(val: &str) {}
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  = note: ...which again requires computing function signature of `<impl at /tmp/icemaker_global_tempdir.q2k4BBLCKuN9/rustc_testrunner_tmpdir_reporting.5aASWsrfzxJL/mvce.rs:3:1: 3:10>::test`, completing the cycle
note: cycle used when checking that `<impl at /tmp/icemaker_global_tempdir.q2k4BBLCKuN9/rustc_testrunner_tmpdir_reporting.5aASWsrfzxJL/mvce.rs:3:1: 3:10>::test` is well-formed
 --> /tmp/icemaker_global_tempdir.q2k4BBLCKuN9/rustc_testrunner_tmpdir_reporting.5aASWsrfzxJL/mvce.rs:4:5
  |
4 |     pub async unsafe extern "C-cmse-nonsecure-entry" fn test(val: &str) {}
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  = note: see https://rustc-dev-guide.rust-lang.org/overview.html#queries and https://rustc-dev-guide.rust-lang.org/query.html for more information
note: delayed at compiler/rustc_query_system/src/query/job.rs:596:16 - disabled backtrace
 --> /tmp/icemaker_global_tempdir.q2k4BBLCKuN9/rustc_testrunner_tmpdir_reporting.5aASWsrfzxJL/mvce.rs:4:5
  |
4 |     pub async unsafe extern "C-cmse-nonsecure-entry" fn test(val: &str) {}
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: internal compiler error[E0391]: cycle detected when computing function signature of `<impl at /tmp/icemaker_global_tempdir.q2k4BBLCKuN9/rustc_testrunner_tmpdir_reporting.5aASWsrfzxJL/mvce.rs:3:1: 3:10>::test`
 --> /tmp/icemaker_global_tempdir.q2k4BBLCKuN9/rustc_testrunner_tmpdir_reporting.5aASWsrfzxJL/mvce.rs:4:5
  |
4 |     pub async unsafe extern "C-cmse-nonsecure-entry" fn test(val: &str) {}
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: ...which requires computing layout of `<impl at /tmp/icemaker_global_tempdir.q2k4BBLCKuN9/rustc_testrunner_tmpdir_reporting.5aASWsrfzxJL/mvce.rs:3:1: 3:10>::test::{opaque#0}`...
  = note: ...which requires normalizing `<impl at /tmp/icemaker_global_tempdir.q2k4BBLCKuN9/rustc_testrunner_tmpdir_reporting.5aASWsrfzxJL/mvce.rs:3:1: 3:10>::test::{opaque#0}`...
note: ...which requires computing type of `<impl at /tmp/icemaker_global_tempdir.q2k4BBLCKuN9/rustc_testrunner_tmpdir_reporting.5aASWsrfzxJL/mvce.rs:3:1: 3:10>::test::{opaque#0}`...
 --> /tmp/icemaker_global_tempdir.q2k4BBLCKuN9/rustc_testrunner_tmpdir_reporting.5aASWsrfzxJL/mvce.rs:4:5
  |
4 |     pub async unsafe extern "C-cmse-nonsecure-entry" fn test(val: &str) {}
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: ...which requires computing type of opaque `<impl at /tmp/icemaker_global_tempdir.q2k4BBLCKuN9/rustc_testrunner_tmpdir_reporting.5aASWsrfzxJL/mvce.rs:3:1: 3:10>::test::{opaque#0}`...
 --> /tmp/icemaker_global_tempdir.q2k4BBLCKuN9/rustc_testrunner_tmpdir_reporting.5aASWsrfzxJL/mvce.rs:4:5
  |
4 |     pub async unsafe extern "C-cmse-nonsecure-entry" fn test(val: &str) {}
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: ...which requires borrow-checking `<impl at /tmp/icemaker_global_tempdir.q2k4BBLCKuN9/rustc_testrunner_tmpdir_reporting.5aASWsrfzxJL/mvce.rs:3:1: 3:10>::test`...
 --> /tmp/icemaker_global_tempdir.q2k4BBLCKuN9/rustc_testrunner_tmpdir_reporting.5aASWsrfzxJL/mvce.rs:4:5
  |
4 |     pub async unsafe extern "C-cmse-nonsecure-entry" fn test(val: &str) {}
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: ...which requires promoting constants in MIR for `<impl at /tmp/icemaker_global_tempdir.q2k4BBLCKuN9/rustc_testrunner_tmpdir_reporting.5aASWsrfzxJL/mvce.rs:3:1: 3:10>::test`...
 --> /tmp/icemaker_global_tempdir.q2k4BBLCKuN9/rustc_testrunner_tmpdir_reporting.5aASWsrfzxJL/mvce.rs:4:5
  |
4 |     pub async unsafe extern "C-cmse-nonsecure-entry" fn test(val: &str) {}
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: ...which requires checking if `<impl at /tmp/icemaker_global_tempdir.q2k4BBLCKuN9/rustc_testrunner_tmpdir_reporting.5aASWsrfzxJL/mvce.rs:3:1: 3:10>::test` contains FFI-unwind calls...
 --> /tmp/icemaker_global_tempdir.q2k4BBLCKuN9/rustc_testrunner_tmpdir_reporting.5aASWsrfzxJL/mvce.rs:4:5
  |
4 |     pub async unsafe extern "C-cmse-nonsecure-entry" fn test(val: &str) {}
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  = note: ...which again requires computing function signature of `<impl at /tmp/icemaker_global_tempdir.q2k4BBLCKuN9/rustc_testrunner_tmpdir_reporting.5aASWsrfzxJL/mvce.rs:3:1: 3:10>::test`, completing the cycle
note: cycle used when checking that `<impl at /tmp/icemaker_global_tempdir.q2k4BBLCKuN9/rustc_testrunner_tmpdir_reporting.5aASWsrfzxJL/mvce.rs:3:1: 3:10>::test` is well-formed
 --> /tmp/icemaker_global_tempdir.q2k4BBLCKuN9/rustc_testrunner_tmpdir_reporting.5aASWsrfzxJL/mvce.rs:4:5
  |
4 |     pub async unsafe extern "C-cmse-nonsecure-entry" fn test(val: &str) {}
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  = note: see https://rustc-dev-guide.rust-lang.org/overview.html#queries and https://rustc-dev-guide.rust-lang.org/query.html for more information
note: delayed at compiler/rustc_query_system/src/query/job.rs:596:16 - disabled backtrace
 --> /tmp/icemaker_global_tempdir.q2k4BBLCKuN9/rustc_testrunner_tmpdir_reporting.5aASWsrfzxJL/mvce.rs:4:5
  |
4 |     pub async unsafe extern "C-cmse-nonsecure-entry" fn test(val: &str) {}
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

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.84.0-nightly (a0d98ff0e 2024-10-31) running on x86_64-unknown-linux-gnu

note: compiler flags: -Z crate-attr=feature(cmse_nonsecure_entry) --crate-type lib -Z dump-mir-dir=dir

query stack during panic:
end of query stack

@rustbot label +F-cmse_nonsecure_entry

@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 Oct 31, 2024
@rustbot rustbot added needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. F-cmse_nonsecure_entry `#![feature(cmse_nonsecure_entry)]` labels Oct 31, 2024
@matthiaskrgr
Copy link
Member Author

#130747

@matthiaskrgr matthiaskrgr added the S-bug-has-test Status: This bug is tracked inside the repo by a `known-bug` test. label Nov 7, 2024
@jieyouxu jieyouxu added S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue A-diagnostics Area: Messages for errors, warnings, and lints I-cycle Issue: A query cycle occurred while none was expected 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 Nov 11, 2024
@jieyouxu
Copy link
Member

jieyouxu commented Nov 11, 2024

cc @folkertdev in case you want to look into it

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.
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) A-diagnostics Area: Messages for errors, warnings, and lints C-bug Category: This is a bug. F-cmse_nonsecure_entry `#![feature(cmse_nonsecure_entry)]` I-cycle Issue: A query cycle occurred while none was expected I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ S-bug-has-test Status: This bug is tracked inside the repo by a `known-bug` test. S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
3 participants