Skip to content

rustc_public: stable FnAbi conversion ICEs on extern "sysv64" C-variadics #163233

Closed

Description

@feliperodri

There is a problem with the assertion at

assert!(!self.c_variadic || matches!(self.conv, CanonAbi::C));

If any tool using rustc_public calls rustc_public::mir::mono::Instance::fn_abi() to know "what's this function's calling-convention layout?" there is a check that says "if the function is variadic, the convention must be C," which is wrong. extern "sysv64" variadics are also legal Rust. The stable enum has a variant for this convention already (CallConvention::X86_64SysV). Here is a way to reproduce the issue below.

Environment

  • rustc 1.100.0-nightly (6bb1652a0 2026-09-22) (nightly-2026-09-23)
  • rustc-dev component installed
  • x86-64 host. On aarch64 rustc rejects extern "sysv64" with E0570, so the input does not build.

Files

fn_abi_ice.rs is the driver and it asks every function in the crate under compilation for its FnAbi.

#![feature(rustc_private)]

extern crate rustc_driver;
extern crate rustc_interface;
extern crate rustc_middle;
extern crate rustc_public;
extern crate rustc_session;

use rustc_public::CrateDef;
use rustc_public::mir::mono::Instance;
use rustc_public::run;
use std::convert::TryInto;
use std::ops::ControlFlow;

fn ask_every_function_for_its_abi() -> ControlFlow<()> {
    for item in rustc_public::all_local_items() {
        let Ok(instance) = TryInto::<Instance>::try_into(item) else { continue };
        println!("asking for the ABI of `{}`", instance.name());
        let _ = instance.fn_abi();
    }
    ControlFlow::Continue(())
}

fn main() {
    let args: Vec<String> = std::env::args().collect();
    let _ = run!(&args, ask_every_function_for_its_abi);
}

repro.rs is the input.

#[unsafe(naked)]
pub unsafe extern "sysv64" fn defined(_: u32, _: ...) -> u32 {
    core::arch::naked_asm!("")
}

unsafe extern "sysv64" {
    pub fn declared(_: u32, _: ...) -> u32;
}

control.rs is the same two shapes with the C convention + a plain function.

pub unsafe extern "C" fn defined_c(a: u32, _: ...) -> u32 { a }

unsafe extern "C" {
    pub fn declared_c(_: u32, _: ...) -> u32;
}

pub fn plain(a: u32) -> u32 { a }

Steps

$ rustc +nightly-2026-09-23 fn_abi_ice.rs -o fn_abi_ice

$ LD_LIBRARY_PATH=$(rustc +nightly-2026-09-23 --print target-libdir)/../lib \
      ./fn_abi_ice repro.rs --crate-type=lib
asking for the ABI of `repro::defined`

thread 'rustc' (13085) panicked at compiler/rustc_public/src/unstable/convert/stable/abi.rs:92:9:
assertion failed: !self.c_variadic || matches!(self.conv, CanonAbi::C)
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
$ echo $?
101
$ LD_LIBRARY_PATH=$(rustc +nightly-2026-09-23 --print target-libdir)/../lib \
      ./fn_abi_ice control.rs --crate-type=lib
asking for the ABI of `control::defined_c`
asking for the ABI of `control::plain`
$ echo $?
0

Expected: fn_abi() returns, or returns an Err, for repro.rs as it does for control.rs.

Actual: the assertion aborts compilation.

thread 'rustc' panicked at compiler/rustc_public/src/unstable/convert/stable/abi.rs:92:9:
assertion failed: !self.c_variadic || matches!(self.conv, CanonAbi::C)

Activity

  1. added
    needs-triage
    on Sep 23, 2026
  2. theemathas commented on Sep 24, 2026

    @theemathas
    Contributor

    Please note the LLM Policy.

    This issue is difficult to read and comprehend, as is typical of LLM writing.

  3. feliperodri commented on Sep 24, 2026

    @feliperodri
    Author

    I'll re-open with a better description.

  4. removed
    needs-triage
    on Sep 24, 2026
  5. feliperodri commented on Sep 26, 2026

    @feliperodri
    Author

    I re-opened the issue with a new description. @theemathas, is it more readable now?

  6. added
    C-bug
    needs-triage
    on Sep 26, 2026
  7. added
    I-ICE
    T-compiler
    and removed
    needs-triage
    on Oct 30, 2026
  8. added 2 commits that reference this issue on Nov 6, 2026
    b605a6b
    0ffe29c
  9. added a commit that references this issue on Nov 7, 2026
    6c0e257
  10. added a commit that references this issue on Nov 7, 2026
    3412205
  11. added a commit that references this issue on Nov 8, 2026
    d19f4ea
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugI-ICET-compiler

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions