rust-lang / rust-lang/rust

ICE: cfi: encode_ty_name: unexpected `GlobalAsm`

Open
#138,262 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-control-flow-integrity C-bug I-ICE S-bug-has-test S-has-mcve T-compiler
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

auto-reduced (treereduce-rust):

//@compile-flags: -Zsanitizer=cfi -Ccodegen-units=1 -Clto -Clink-dead-code=true
fn foo<const N: usize>() {}

core::arch::global_asm!("/* {} */", sym foo::<{
    || {};
    0
}>);

fn main() {}

original:

//@ build-pass
//@ needs-asm-support

fn foo<const N: usize>() {}

core::arch::global_asm!("/* {} */", sym foo::<{
    || {};
    0
}>);

fn main() {}

Version information

rustc 1.87.0-nightly (a96fa317d 2025-03-09)
binary: rustc
commit-hash: a96fa317d78c78a9de996afd317603c6970efc0d
commit-date: 2025-03-09
host: x86_64-unknown-linux-gnu
release: 1.87.0-nightly
LLVM version: 20.1.0

Possibly related line of code:
https://github.com/rust-lang/rust/blob/a96fa317d78c78a9de996afd317603c6970efc0d/compiler/rustc_sanitizers/src/cfi/typeid/itanium_cxx_abi/encode.rs#L718-L730

Command:
/home/matthias/.rustup/toolchains/master/bin/rustc -Zsanitizer=cfi -Ccodegen-units=1 -Clto -Clink-dead-code=true

Program output

warning: unused closure that must be used
 --> /tmp/icemaker_global_tempdir.iOtSTAvEbK4I/rustc_testrunner_tmpdir_reporting.MYlyvXwRLFS1/mvce.rs:4:5
  |
4 |     || {};
  |     ^^^^^
  |
  = note: closures are lazy and do nothing unless called
  = note: `#[warn(unused_must_use)]` on by default

error: internal compiler error: compiler/rustc_sanitizers/src/cfi/typeid/itanium_cxx_abi/encode.rs:724:17: encode_ty_name: unexpected `GlobalAsm`


thread 'rustc' panicked at compiler/rustc_sanitizers/src/cfi/typeid/itanium_cxx_abi/encode.rs:724:17:
Box<dyn Any>
stack backtrace:
   0:     0x7b96bf7ba414 - <std::sys::backtrace::BacktraceLock::print::DisplayBacktrace as core::fmt::Display>::fmt::h52c7f0550840b8f9
   1:     0x7b96c0005bee - core::fmt::write::hee3b35a23fdf4ab3
   2:     0x7b96c1421e91 - std::io::Write::write_fmt::hf49dbaa0e19fcf6b
   3:     0x7b96bf7ba272 - std::sys::backtrace::BacktraceLock::print::hc7c25359d1b81c79
   4:     0x7b96bf7bcb98 - std::panicking::default_hook::{{closure}}::h384e40742b2d89cc
   5:     0x7b96bf7bc6b7 - std::panicking::default_hook::hdad5dc41d6be2842
   6:     0x7b96be90c93f - std[af3b6eacc99eae20]::panicking::update_hook::<alloc[63c0b52934c5697b]::boxed::Box<rustc_driver_impl[c2cc76304700d71f]::install_ice_hook::{closure#1}>>::{closure#0}
   7:     0x7b96bf7bd403 - std::panicking::rust_panic_with_hook::h45ecb165eb6636c0
   8:     0x7b96be949071 - std[af3b6eacc99eae20]::panicking::begin_panic::<rustc_errors[4dd87fb07da1f12a]::ExplicitBug>::{closure#0}
   9:     0x7b96be93d596 - std[af3b6eacc99eae20]::sys::backtrace::__rust_end_short_backtrace::<std[af3b6eacc99eae20]::panicking::begin_panic<rustc_errors[4dd87fb07da1f12a]::ExplicitBug>::{closure#0}, !>
  10:     0x7b96be93a12b - std[af3b6eacc99eae20]::panicking::begin_panic::<rustc_errors[4dd87fb07da1f12a]::ExplicitBug>
  11:     0x7b96be952bd1 - <rustc_errors[4dd87fb07da1f12a]::diagnostic::BugAbort as rustc_errors[4dd87fb07da1f12a]::diagnostic::EmissionGuarantee>::emit_producing_guarantee
  12:     0x7b96bef298da - rustc_middle[7aa79b75868ccd38]::util::bug::opt_span_bug_fmt::<rustc_span[6f95e09a31d512b0]::span_encoding::Span>::{closure#0}
  13:     0x7b96bef1143a - rustc_middle[7aa79b75868ccd38]::ty::context::tls::with_opt::<rustc_middle[7aa79b75868ccd38]::util::bug::opt_span_bug_fmt<rustc_span[6f95e09a31d512b0]::span_encoding::Span>::{closure#0}, !>::{closure#0}
  14:     0x7b96bef112ab - rustc_middle[7aa79b75868ccd38]::ty::context::tls::with_context_opt::<rustc_middle[7aa79b75868ccd38]::ty::context::tls::with_opt<rustc_middle[7aa79b75868ccd38]::util::bug::opt_span_bug_fmt<rustc_span[6f95e09a31d512b0]::span_encoding::Span>::{closure#0}, !>::{closure#0}, !>
  15:     0x7b96bd1d86b0 - rustc_middle[7aa79b75868ccd38]::util::bug::bug_fmt
  16:     0x7b96bf3d8775 - rustc_sanitizers[1669854f3a2b327]::cfi::typeid::itanium_cxx_abi::encode::encode_ty_name
  17:     0x7b96bf3d9ca5 - rustc_sanitizers[1669854f3a2b327]::cfi::typeid::itanium_cxx_abi::encode::encode_ty
  18:     0x7b96bf3daf47 - rustc_sanitizers[1669854f3a2b327]::cfi::typeid::itanium_cxx_abi::encode::encode_ty
  19:     0x7b96bf3dd01f - rustc_sanitizers[1669854f3a2b327]::cfi::typeid::itanium_cxx_abi::typeid_for_fnabi
  20:     0x7b96bf3de14e - rustc_sanitizers[1669854f3a2b327]::cfi::typeid::itanium_cxx_abi::typeid_for_instance
  21:     0x7b96c0eff636 - <rustc_codegen_llvm[d40da1db6194ee81]::context::GenericCx<rustc_codegen_llvm[d40da1db6194ee81]::context::FullCx> as rustc_codegen_ssa[f89046b61b918ef9]::traits::declare::PreDefineCodegenMethods>::predefine_fn
  22:     0x7b96c0f0132f - rustc_codegen_llvm[d40da1db6194ee81]::base::compile_codegen_unit::module_codegen
  23:     0x7b96c10882da - <rustc_codegen_llvm[d40da1db6194ee81]::LlvmCodegenBackend as rustc_codegen_ssa[f89046b61b918ef9]::traits::backend::ExtraBackendMethods>::compile_codegen_unit
  24:     0x7b96c1089b97 - <rustc_codegen_llvm[d40da1db6194ee81]::LlvmCodegenBackend as rustc_codegen_ssa[f89046b61b918ef9]::traits::backend::CodegenBackend>::codegen_crate
  25:     0x7b96c1149b23 - <rustc_interface[91d83e268fb48030]::queries::Linker>::codegen_and_build_linker
  26:     0x7b96c114752f - rustc_interface[91d83e268fb48030]::passes::create_and_enter_global_ctxt::<core[ed80027c49f06cd6]::option::Option<rustc_interface[91d83e268fb48030]::queries::Linker>, rustc_driver_impl[c2cc76304700d71f]::run_compiler::{closure#0}::{closure#2}>::{closure#2}::{closure#0}
  27:     0x7b96c11374ee - rustc_interface[91d83e268fb48030]::interface::run_compiler::<(), rustc_driver_impl[c2cc76304700d71f]::run_compiler::{closure#0}>::{closure#1}
  28:     0x7b96c0f71248 - std[af3b6eacc99eae20]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[91d83e268fb48030]::util::run_in_thread_with_globals<rustc_interface[91d83e268fb48030]::util::run_in_thread_pool_with_globals<rustc_interface[91d83e268fb48030]::interface::run_compiler<(), rustc_driver_impl[c2cc76304700d71f]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>
  29:     0x7b96c0f71b34 - <<std[af3b6eacc99eae20]::thread::Builder>::spawn_unchecked_<rustc_interface[91d83e268fb48030]::util::run_in_thread_with_globals<rustc_interface[91d83e268fb48030]::util::run_in_thread_pool_with_globals<rustc_interface[91d83e268fb48030]::interface::run_compiler<(), rustc_driver_impl[c2cc76304700d71f]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>::{closure#1} as core[ed80027c49f06cd6]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  30:     0x7b96c0f72f2b - std::sys::pal::unix::thread::Thread::new::thread_start::h3e3ca1693a666c64
  31:     0x7b96bb05e70a - <unknown>
  32:     0x7b96bb0e2aac - <unknown>
  33:                0x0 - <unknown>

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.87.0-nightly (a96fa317d 2025-03-09) running on x86_64-unknown-linux-gnu

note: compiler flags: -Z sanitizer=cfi -C codegen-units=1 -C lto -C link-dead-code=true -Z dump-mir-dir=dir

query stack during panic:
end of query stack
error: aborting due to 1 previous error; 1 warning emitted


Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with compiler/rustc_sanitizers/src/cfi/typeid/itanium_cxx_abi/encode.rs around line 724, then reproduce the reduced global_asm example using the listed CFI, LTO, codegen-unit, and link-dead-code flags. Done means the example no longer triggers the encode_ty_name GlobalAsm ICE.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.