rust-lang / rust-lang/rustc_codegen_gcc

Failed to build `core` crate with `-C opt-level=0`

Open
#789 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Rust
Stars
1.2k
Forks
105
Avg merge
8h 20m
Merged PRs (30d)
14

Description

In one environment, I use RUSTFLAGS="-C opt-level=0 -C debuginfo=0". Building rustc with this when using rustc_codegen_gcc, I get a failure to build core:

thread 'rustc' (75759) panicked at /rustc-dev/67c208e9eec6b5add33b94f593fe18b23bf9fa3c/compiler/rustc_codegen_ssa/src/mir/rvalue.rs:1034:5:
assertion `left == right` failed
  left: __int32_t  __attribute__((aligned(4))) *  __attribute__((aligned(8)))
 right: void *
stack backtrace:
   0: __rustc::rust_begin_unwind
   1: core::panicking::panic_fmt.localalias
   2: core::panicking::assert_failed_inner
   3: core::panicking::assert_failed::<gccjit::types::Type, gccjit::types::Type>
   4: rustc_codegen_ssa::mir::rvalue::transmute_scalar::<rustc_codegen_gcc::builder::Builder>
   5: <rustc_codegen_ssa::mir::FunctionCx<rustc_codegen_gcc::builder::Builder>>::codegen_transmute_operand
   6: <rustc_codegen_ssa::mir::FunctionCx<rustc_codegen_gcc::builder::Builder>>::codegen_rvalue_operand
   7: <rustc_codegen_ssa::mir::FunctionCx<rustc_codegen_gcc::builder::Builder>>::codegen_statement
   8: <rustc_codegen_ssa::mir::FunctionCx<rustc_codegen_gcc::builder::Builder>>::codegen_block.localalias
   9: rustc_codegen_ssa::mir::codegen_mir::<rustc_codegen_gcc::builder::Builder>
  10: rustc_codegen_ssa::base::codegen_instance::<rustc_codegen_gcc::builder::Builder>
  11: <rustc_middle::mir::mono::MonoItem as rustc_codegen_ssa::mono_item::MonoItemExt>::define::<rustc_codegen_gcc::builder::Builder>
  12: rustc_codegen_gcc::base::compile_codegen_unit::module_codegen
  13: <rustc_query_system::dep_graph::graph::DepGraph<rustc_middle::dep_graph::DepsType>>::with_task::<rustc_middle::ty::context::TyCtxt, (rustc_span::symbol::Symbol, rustc_codegen_gcc::LockedTargetInfo), rustc_codegen_ssa::ModuleCodegen<rustc_codegen_gcc::GccContext>>
  14: rustc_codegen_gcc::base::compile_codegen_unit
  15: <rustc_codegen_gcc::GccCodegenBackend as rustc_codegen_ssa::traits::backend::ExtraBackendMethods>::compile_codegen_unit
  16: rustc_codegen_ssa::base::codegen_crate::<rustc_codegen_gcc::GccCodegenBackend>
  17: <rustc_codegen_gcc::GccCodegenBackend as rustc_codegen_ssa::traits::backend::CodegenBackend>::codegen_crate
  18: rustc_interface::passes::start_codegen::{closure#0}
  19: <rustc_session::session::Session>::time::<alloc::boxed::Box<dyn core::any::Any>, rustc_interface::passes::start_codegen::{closure#0}>
  20: rustc_interface::passes::start_codegen
  21: <rustc_interface::queries::Linker>::codegen_and_build_linker
  22: rustc_driver_impl::run_compiler::{closure#0}::{closure#2}
  23: rustc_interface::passes::create_and_enter_global_ctxt::<core::option::Option<rustc_interface::queries::Linker>, rustc_driver_impl::run_compiler::{closure#0}::{closure#2}>::{closure#2}::{closure#0}
  24: <rustc_middle::ty::context::GlobalCtxt>::enter::<rustc_interface::passes::create_and_enter_global_ctxt<core::option::Option<rustc_interface::queries::Linker>, rustc_driver_impl::run_compiler::{closure#0}::{closure#2}>::{closure#2}::{closure#0}, core::option::Option<rustc_interface::queries::Linker>>::{closure#1}
  25: rustc_middle::ty::context::tls::enter_context::<<rustc_middle::ty::context::GlobalCtxt>::enter<rustc_interface::passes::create_and_enter_global_ctxt<core::option::Option<rustc_interface::queries::Linker>, rustc_driver_impl::run_compiler::{closure#0}::{closure#2}>::{closure#2}::{closure#0}, core::option::Option<rustc_interface::queries::Linker>>::{closure#1}, core::option::Option<rustc_interface::queries::Linker>>::{closure#0}
  26: <std::thread::local::LocalKey<core::cell::Cell<*const ()>>>::try_with::<rustc_middle::ty::context::tls::enter_context<<rustc_middle::ty::context::GlobalCtxt>::enter<rustc_interface::passes::create_and_enter_global_ctxt<core::option::Option<rustc_interface::queries::Linker>, rustc_driver_impl::run_compiler::{closure#0}::{closure#2}>::{closure#2}::{closure#0}, core::option::Option<rustc_interface::queries::Linker>>::{closure#1}, core::option::Option<rustc_interface::queries::Linker>>::{closure#0}, core::option::Option<rustc_interface::queries::Linker>>.localalias
  27: <std::thread::local::LocalKey<core::cell::Cell<*const ()>>>::with::<rustc_middle::ty::context::tls::enter_context<<rustc_middle::ty::context::GlobalCtxt>::enter<rustc_interface::passes::create_and_enter_global_ctxt<core::option::Option<rustc_interface::queries::Linker>, rustc_driver_impl::run_compiler::{closure#0}::{closure#2}>::{closure#2}::{closure#0}, core::option::Option<rustc_interface::queries::Linker>>::{closure#1}, core::option::Option<rustc_interface::queries::Linker>>::{closure#0}, core::option::Option<rustc_interface::queries::Linker>>
  28: rustc_middle::ty::context::tls::enter_context::<<rustc_middle::ty::context::GlobalCtxt>::enter<rustc_interface::passes::create_and_enter_global_ctxt<core::option::Option<rustc_interface::queries::Linker>, rustc_driver_impl::run_compiler::{closure#0}::{closure#2}>::{closure#2}::{closure#0}, core::option::Option<rustc_interface::queries::Linker>>::{closure#1}, core::option::Option<rustc_interface::queries::Linker>>
  29: <rustc_middle::ty::context::GlobalCtxt>::enter::<rustc_interface::passes::create_and_enter_global_ctxt<core::option::Option<rustc_interface::queries::Linker>, rustc_driver_impl::run_compiler::{closure#0}::{closure#2}>::{closure#2}::{closure#0}, core::option::Option<rustc_interface::queries::Linker>>.localalias
  30: <rustc_middle::ty::context::TyCtxt>::create_global_ctxt::<core::option::Option<rustc_interface::queries::Linker>, rustc_interface::passes::create_and_enter_global_ctxt<core::option::Option<rustc_interface::queries::Linker>, rustc_driver_impl::run_compiler::{closure#0}::{closure#2}>::{closure#2}::{closure#0}>
  31: rustc_interface::passes::create_and_enter_global_ctxt::<core::option::Option<rustc_interface::queries::Linker>, rustc_driver_impl::run_compiler::{closure#0}::{closure#2}>::{closure#2}
  32: <rustc_interface::passes::create_and_enter_global_ctxt<core::option::Option<rustc_interface::queries::Linker>, rustc_driver_impl::run_compiler::{closure#0}::{closure#2}>::{closure#2} as core::ops::function::FnOnce<(&rustc_session::session::Session, rustc_middle::ty::context::CurrentGcx, alloc::sync::Arc<rustc_data_structures::jobserver::Proxy>, &std::sync::once_lock::OnceLock<rustc_middle::ty::context::GlobalCtxt>, &rustc_data_structures::sync::worker_local::WorkerLocal<rustc_middle::arena::Arena>, &rustc_data_structures::sync::worker_local::WorkerLocal<rustc_hir::Arena>, rustc_driver_impl::run_compiler::{closure#0}::{closure#2})>>::call_once::{shim:vtable#0}
  33: <alloc::boxed::Box<dyn for<'a> core::ops::function::FnOnce<(&'a rustc_session::session::Session, rustc_middle::ty::context::CurrentGcx, alloc::sync::Arc<rustc_data_structures::jobserver::Proxy>, &'a std::sync::once_lock::OnceLock<rustc_middle::ty::context::GlobalCtxt<'a>>, &'a rustc_data_structures::sync::worker_local::WorkerLocal<rustc_middle::arena::Arena<'a>>, &'a rustc_data_structures::sync::worker_local::WorkerLocal<rustc_hir::Arena<'a>>, rustc_driver_impl::run_compiler::{closure#0}::{closure#2}), Output = core::option::Option<rustc_interface::queries::Linker>>> as core::ops::function::FnOnce<(&rustc_session::session::Session, rustc_middle::ty::context::CurrentGcx, alloc::sync::Arc<rustc_data_structures::jobserver::Proxy>, &std::sync::once_lock::OnceLock<rustc_middle::ty::context::GlobalCtxt>, &rustc_data_structures::sync::worker_local::WorkerLocal<rustc_middle::arena::Arena>, &rustc_data_structures::sync::worker_local::WorkerLocal<rustc_hir::Arena>, rustc_driver_impl::run_compiler::{closure#0}::{closure#2})>>::call_once
  34: rustc_interface::passes::create_and_enter_global_ctxt::<core::option::Option<rustc_interface::queries::Linker>, rustc_driver_impl::run_compiler::{closure#0}::{closure#2}>
  35: rustc_driver_impl::run_compiler::{closure#0}
  36: rustc_interface::interface::run_compiler::<(), rustc_driver_impl::run_compiler::{closure#0}>::{closure#1}::{closure#0}.localalias
  37: <core::panic::unwind_safe::AssertUnwindSafe<rustc_interface::interface::run_compiler<(), rustc_driver_impl::run_compiler::{closure#0}>::{closure#1}::{closure#0}> as core::ops::function::FnOnce<()>>::call_once
  38: std::panicking::catch_unwind::do_call::<core::panic::unwind_safe::AssertUnwindSafe<rustc_interface::interface::run_compiler<(), rustc_driver_impl::run_compiler::{closure#0}>::{closure#1}::{closure#0}>, ()>
  39: __rust_try
  40: std::panic::catch_unwind::<core::panic::unwind_safe::AssertUnwindSafe<rustc_interface::interface::run_compiler<(), rustc_driver_impl::run_compiler::{closure#0}>::{closure#1}::{closure#0}>, ()>
  41: rustc_interface::interface::run_compiler::<(), rustc_driver_impl::run_compiler::{closure#0}>::{closure#1}
  42: rustc_interface::util::run_in_thread_pool_with_globals::<rustc_interface::interface::run_compiler<(), rustc_driver_impl::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}.localalias
  43: rustc_interface::util::run_in_thread_with_globals::<rustc_interface::util::run_in_thread_pool_with_globals<rustc_interface::interface::run_compiler<(), rustc_driver_impl::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}::{closure#0}
  44: <scoped_tls::ScopedKey<rustc_span::SessionGlobals>>::set::<rustc_interface::util::run_in_thread_with_globals<rustc_interface::util::run_in_thread_pool_with_globals<rustc_interface::interface::run_compiler<(), rustc_driver_impl::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}::{closure#0}, ()>
  45: rustc_span::create_session_globals_then::<(), rustc_interface::util::run_in_thread_with_globals<rustc_interface::util::run_in_thread_pool_with_globals<rustc_interface::interface::run_compiler<(), rustc_driver_impl::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}::{closure#0}>
  46: rustc_interface::util::run_in_thread_with_globals::<rustc_interface::util::run_in_thread_pool_with_globals<rustc_interface::interface::run_compiler<(), rustc_driver_impl::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

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: please attach the file at `/var/tmp/portage/dev-lang/rust-1.91.0_beta20251009/work/rustc-beta-src/rustc-ice-2025-10-27T12_31_28-75726.txt` to your bug report

note: compiler flags: --crate-type lib -C opt-level=3 -C embed-bitcode=no -C codegen-units=1 -C linker=x86_64-pc-linux-gnu-gcc -C opt-level=0 -C debuginfo=0 -C symbol-mangling-version=legacy -Z unstable-options -Z macro-backtrace -C split-debuginfo=off -C prefer-dynamic -Z inline-mir -Z inline-mir-preserve-debug -Z mir_strip_debuginfo=locals-in-tiny-functions -C link-args=-Wl,-z,origin -C link-args=-Wl,-rpath,$ORIGIN/../lib -C embed-bitcode=yes -C lto=off -Z unstable-options -C force-frame-pointers=non-leaf -Z crate-attr=doc(html_root_url="https://doc.rust-lang.org/nightly/") -Z binary-dep-depinfo -Z force-unstable-if-unmarked
note: some of the compiler flags provided by cargo are hidden

query stack during panic:
end of query stack

Did not run successfully: exit status: 101
LD_LIBRARY_PATH="/var/tmp/portage/dev-lang/rust-1.91.0_beta20251009/work/rustc-beta-src/build/x86_64-unknown-linux-gnu/stage1/lib:/var/tmp/portage/dev-lang/rust-1.91.0_beta20251009/work/rustc-beta-src/build/x86_64-unknown-linux-gnu/stage1-std/release/deps" "/var/tmp/portage/dev-lang/rust-1.91.0_beta20251009/work/rustc-beta-src/build/x86_64-unknown-linux-gnu/stage1/bin/rustc" "--crate-name" "core" "--edition=2024" "library/core/src/lib.rs" "--error-format=json" "--json=diagnostic-rendered-ansi,artifacts,future-incompat" "--crate-type" "lib" "--emit=dep-info,metadata,link" "-C" "opt-level=3" "-C" "embed-bitcode=no" "-C" "codegen-units=1" "--warn=unexpected_cfgs" "--check-cfg" "cfg(no_fp_fmt_parse)" "--check-cfg" "cfg(feature, values(any()))" "--check-cfg" "cfg(target_has_reliable_f16)" "--check-cfg" "cfg(target_has_reliable_f16_math)" "--check-cfg" "cfg(target_has_reliable_f128)" "--check-cfg" "cfg(target_has_reliable_f128_math)" "--check-cfg" "cfg(docsrs,test)" "--check-cfg" "cfg(feature, values(\"debug_refcell\", \"optimize_for_size\", \"panic_immediate_abort\"))" "-C" "metadata=e4c2771f4ac279b7" "-C" "extra-filename=-847cdeb8a8d320b3" "--out-dir" "/var/tmp/portage/dev-lang/rust-1.91.0_beta20251009/work/rustc-beta-src/build/x86_64-unknown-linux-gnu/stage1-std/x86_64-unknown-linux-gnu/release/deps" "--target" "x86_64-unknown-linux-gnu" "-C" "linker=x86_64-pc-linux-gnu-gcc" "-L" "dependency=/var/tmp/portage/dev-lang/rust-1.91.0_beta20251009/work/rustc-beta-src/build/x86_64-unknown-linux-gnu/stage1-std/x86_64-unknown-linux-gnu/release/deps" "-L" "dependency=/var/tmp/portage/dev-lang/rust-1.91.0_beta20251009/work/rustc-beta-src/build/x86_64-unknown-linux-gnu/stage1-std/release/deps" "-C" "opt-level=0" "-C" "debuginfo=0" "-Lnative=/usr/lib/llvm/21/lib64" "-Csymbol-mangling-version=legacy" "--check-cfg=cfg(feature,values(any()))" "-Zunstable-options" "-Zmacro-backtrace" "-Csplit-debuginfo=off" "-Cprefer-dynamic" "-Zinline-mir" "-Zinline-mir-preserve-debug" "-Zmir_strip_debuginfo=locals-in-tiny-functions" "-Clink-args=-Wl,-z,origin" "-Clink-args=-Wl,-rpath,$ORIGIN/../lib" "-Alinker-messages" "-Cembed-bitcode=yes" "-Clto=off" "-Zunstable-options" "-Cforce-frame-pointers=non-leaf" "-Zcrate-attr=doc(html_root_url=\"https://doc.rust-lang.org/nightly/\")" "-Z" "binary-dep-depinfo" "-Wrust_2018_idioms" "-Wunused_lifetimes" "-Dwarnings" "--sysroot" "/var/tmp/portage/dev-lang/rust-1.91.0_beta20251009/work/rustc-beta-src/build/x86_64-unknown-linux-gnu/stage1" "--remap-path-prefix" "/var/tmp/portage/dev-lang/rust-1.91.0_beta20251009/work/rustc-beta-src=/rustc/67c208e9eec6b5add33b94f593fe18b23bf9fa3c" "--remap-path-prefix" "/var/tmp/portage/dev-lang/rust-1.91.0_beta20251009/work/rustc-beta-src/vendor=/rust/deps" "-Z" "force-unstable-if-unmarked"
-------------
error: could not compile `core` (lib)

Caused by:
  process didn't exit successfully: `CARGO=/usr/lib/rust/1.91.0/bin/cargo CARGO_CRATE_NAME=core CARGO_MANIFEST_DIR=/var/tmp/portage/dev-lang/rust-1.91.0_beta20251009/work/rustc-beta-src/library/core CARGO_MANIFEST_PATH=/var/tmp/portage/dev-lang/rust-1.91.0_beta20251009/work/rustc-beta-src/library/core/Cargo.toml CARGO_PKG_AUTHORS='' CARGO_PKG_DESCRIPTION='The Rust Core Library' CARGO_PKG_HOMEPAGE='' CARGO_PKG_LICENSE='MIT OR Apache-2.0' CARGO_PKG_LICENSE_FILE='' CARGO_PKG_NAME=core CARGO_PKG_README='' CARGO_PKG_REPOSITORY='https://github.com/rust-lang/rust.git' CARGO_PKG_RUST_VERSION='' CARGO_PKG_VERSION=0.0.0 CARGO_PKG_VERSION_MAJOR=0 CARGO_PKG_VERSION_MINOR=0 CARGO_PKG_VERSION_PATCH=0 CARGO_PKG_VERSION_PRE='' LD_LIBRARY_PATH=/var/tmp/portage/dev-lang/rust-1.91.0_beta20251009/work/rustc-beta-src/build/x86_64-unknown-linux-gnu/stage1-std/release/deps /var/tmp/portage/dev-lang/rust-1.91.0_beta20251009/work/rustc-beta-src/build/bootstrap/debug/rustc /var/tmp/portage/dev-lang/rust-1.91.0_beta20251009/work/rustc-beta-src/build/bootstrap/debug/rustc --crate-name core --edition=2024 library/core/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --crate-type lib --emit=dep-info,metadata,link -C opt-level=3 -C embed-bitcode=no -C codegen-units=1 --warn=unexpected_cfgs --check-cfg 'cfg(no_fp_fmt_parse)' --check-cfg 'cfg(feature, values(any()))' --check-cfg 'cfg(target_has_reliable_f16)' --check-cfg 'cfg(target_has_reliable_f16_math)' --check-cfg 'cfg(target_has_reliable_f128)' --check-cfg 'cfg(target_has_reliable_f128_math)' --check-cfg 'cfg(docsrs,test)' --check-cfg 'cfg(feature, values("debug_refcell", "optimize_for_size", "panic_immediate_abort"))' -C metadata=e4c2771f4ac279b7 -C extra-filename=-847cdeb8a8d320b3 --out-dir /var/tmp/portage/dev-lang/rust-1.91.0_beta20251009/work/rustc-beta-src/build/x86_64-unknown-linux-gnu/stage1-std/x86_64-unknown-linux-gnu/release/deps --target x86_64-unknown-linux-gnu -C linker=x86_64-pc-linux-gnu-gcc -L dependency=/var/tmp/portage/dev-lang/rust-1.91.0_beta20251009/work/rustc-beta-src/build/x86_64-unknown-linux-gnu/stage1-std/x86_64-unknown-linux-gnu/release/deps -L dependency=/var/tmp/portage/dev-lang/rust-1.91.0_beta20251009/work/rustc-beta-src/build/x86_64-unknown-linux-gnu/stage1-std/release/deps -C opt-level=0 -C debuginfo=0 -Lnative=/usr/lib/llvm/21/lib64 -Csymbol-mangling-version=legacy '--check-cfg=cfg(feature,values(any()))' -Zunstable-options -Zmacro-backtrace -Csplit-debuginfo=off -Cprefer-dynamic -Zinline-mir -Zinline-mir-preserve-debug -Zmir_strip_debuginfo=locals-in-tiny-functions -Clink-args=-Wl,-z,origin '-Clink-args=-Wl,-rpath,$ORIGIN/../lib' -Alinker-messages -Cembed-bitcode=yes -Clto=off -Zunstable-options -Cforce-frame-pointers=non-leaf '-Zcrate-attr=doc(html_root_url="https://doc.rust-lang.org/nightly/")' -Z binary-dep-depinfo` (exit status: 101)

It works OK with rustc_codegen_llvm.

$ rustc -vV
rustc 1.91.0-nightly (067965d6c 2025-10-27) (gentoo)
binary: rustc
commit-hash: 067965d6cc76bfd49637f46d05ae2111bbd2f121
commit-date: 2025-10-27
host: x86_64-unknown-linux-gnu
release: 1.91.0-nightly

This is with the rust 1.91.0 beta from 20251009 and github.com/rust-lang/rust from b93730ce97c738bdb9209aa973d3fc6fd4ce1d81.

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

Reproduce the failure while building library/core/src/lib.rs with rustc_codegen_gcc and the reported RUSTFLAGS. Start at rustc_codegen_ssa/src/mir/rvalue.rs:1034, especially transmute_scalar, and trace the type mismatch shown in the panic. Done means the core crate builds without this compiler panic under -C opt-level=0.

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.