Skip to content
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

ICE: expression is not a valid constant Adt(AdtExpr ..) #138130

Closed
matthiaskrgr opened this issue Mar 6, 2025 · 1 comment · Fixed by #138138
Closed

ICE: expression is not a valid constant Adt(AdtExpr ..) #138130

matthiaskrgr opened this issue Mar 6, 2025 · 1 comment · Fixed by #138138
Assignees
Labels
C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. 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=2024
use core::arch::asm;

fn uwu() {
    unsafe {
        asm!(
            "/* {0} */",
            sym None::<&mut ()>
        );
    }
}

original:

use core::arch::asm;

fn uwu() {
    unsafe {
        asm!(
            "/* {0} */",
            sym None::<&mut ()>
        );
    }
}

fn uwu() {
    unsafe {
        asm!();
    }
}

Version information

rustc 1.87.0-nightly (e6af292f9 2025-03-06)
binary: rustc
commit-hash: e6af292f91f21f12ac1aab6825efb7e1e3381cbb
commit-date: 2025-03-06
host: x86_64-unknown-linux-gnu
release: 1.87.0-nightly
LLVM version: 20.1.0

Possibly related line of code:

ExprKind::StaticRef { alloc_id, ty, .. } => {
let const_val = ConstValue::Scalar(Scalar::from_pointer(alloc_id.into(), &tcx));
let const_ = Const::Val(const_val, ty);
ConstOperand { span, user_ty: None, const_ }
}
_ => span_bug!(span, "expression is not a valid constant {:?}", kind),
}
}
#[instrument(skip(tcx, lit_input))]
fn lit_to_mir_constant<'tcx>(tcx: TyCtxt<'tcx>, lit_input: LitToConstInput<'tcx>) -> Const<'tcx> {
let LitToConstInput { lit, ty, neg } = lit_input;

Command:
/home/matthias/.rustup/toolchains/master/bin/rustc --edition=2024

Program output

error[E0601]: `main` function not found in crate `mvce`
  --> /tmp/icemaker_global_tempdir.Q0R9e8KRLgkQ/rustc_testrunner_tmpdir_reporting.nDdLfaJNcttG/mvce.rs:10:2
   |
10 | }
   |  ^ consider adding a `main` function to `/tmp/icemaker_global_tempdir.Q0R9e8KRLgkQ/rustc_testrunner_tmpdir_reporting.nDdLfaJNcttG/mvce.rs`

error: invalid `sym` operand
 --> /tmp/icemaker_global_tempdir.Q0R9e8KRLgkQ/rustc_testrunner_tmpdir_reporting.nDdLfaJNcttG/mvce.rs:7:13
  |
7 |             sym None::<&mut ()>
  |             ^^^^^^^^^^^^^^^^^^^ is an `Option<&mut ()>`
  |
  = help: `sym` operands must refer to either a function or a static

error: internal compiler error: compiler/rustc_mir_build/src/builder/expr/as_constant.rs:96:14: expression is not a valid constant Adt(AdtExpr { adt_def: std::option::Option, variant_index: 0, args: [&'{erased} mut ()], user_ty: Some(Canonical { value: UserType { kind: TypeOf(DefId(2:48840 ~ core[07b1]::option::Option::None::{constructor#0}), UserArgs { args: [&'^0 mut ()], user_self_ty: None }), bounds: [] }, max_universe: U0, variables: [CanonicalVarInfo { kind: Region(U0) }] }), fields: [], base: None })
 --> /tmp/icemaker_global_tempdir.Q0R9e8KRLgkQ/rustc_testrunner_tmpdir_reporting.nDdLfaJNcttG/mvce.rs:7:13
  |
7 |             sym None::<&mut ()>
  |             ^^^^^^^^^^^^^^^^^^^


thread 'rustc' panicked at compiler/rustc_mir_build/src/builder/expr/as_constant.rs:96:14:
Box<dyn Any>
stack backtrace:
   0:     0x75a8dd7da3e4 - <std::sys::backtrace::BacktraceLock::print::DisplayBacktrace as core::fmt::Display>::fmt::hecbb97f6adc64d07
   1:     0x75a8de005aa2 - core::fmt::write::h6fb605d03dbe2754
   2:     0x75a8df2d3b11 - std::io::Write::write_fmt::h0429c5405265d0fe
   3:     0x75a8dd7da242 - std::sys::backtrace::BacktraceLock::print::h96934b88340d81b1
   4:     0x75a8dd7dcb22 - std::panicking::default_hook::{{closure}}::hed00595bf072e829
   5:     0x75a8dd7dc714 - std::panicking::default_hook::h54845d08cc4c00b2
   6:     0x75a8dc9306c7 - std[c8fe94e2e6a595f7]::panicking::update_hook::<alloc[1de0a932518765a5]::boxed::Box<rustc_driver_impl[d6673cd08a515aef]::install_ice_hook::{closure#1}>>::{closure#0}
   7:     0x75a8dd7dd393 - std::panicking::rust_panic_with_hook::h113c728232b95451
   8:     0x75a8dc96cdd1 - std[c8fe94e2e6a595f7]::panicking::begin_panic::<rustc_errors[a5ce49d60be6fc0a]::ExplicitBug>::{closure#0}
   9:     0x75a8dc9611e6 - std[c8fe94e2e6a595f7]::sys::backtrace::__rust_end_short_backtrace::<std[c8fe94e2e6a595f7]::panicking::begin_panic<rustc_errors[a5ce49d60be6fc0a]::ExplicitBug>::{closure#0}, !>
  10:     0x75a8dc9611d3 - std[c8fe94e2e6a595f7]::panicking::begin_panic::<rustc_errors[a5ce49d60be6fc0a]::ExplicitBug>
  11:     0x75a8dc9767d1 - <rustc_errors[a5ce49d60be6fc0a]::diagnostic::BugAbort as rustc_errors[a5ce49d60be6fc0a]::diagnostic::EmissionGuarantee>::emit_producing_guarantee
  12:     0x75a8dcec6cac - <rustc_errors[a5ce49d60be6fc0a]::DiagCtxtHandle>::span_bug::<rustc_span[64a5b554609a9731]::span_encoding::Span, alloc[1de0a932518765a5]::string::String>
  13:     0x75a8dcf4dd0a - rustc_middle[659b125a344ae30d]::util::bug::opt_span_bug_fmt::<rustc_span[64a5b554609a9731]::span_encoding::Span>::{closure#0}
  14:     0x75a8dcf3560a - rustc_middle[659b125a344ae30d]::ty::context::tls::with_opt::<rustc_middle[659b125a344ae30d]::util::bug::opt_span_bug_fmt<rustc_span[64a5b554609a9731]::span_encoding::Span>::{closure#0}, !>::{closure#0}
  15:     0x75a8dcf3547b - rustc_middle[659b125a344ae30d]::ty::context::tls::with_context_opt::<rustc_middle[659b125a344ae30d]::ty::context::tls::with_opt<rustc_middle[659b125a344ae30d]::util::bug::opt_span_bug_fmt<rustc_span[64a5b554609a9731]::span_encoding::Span>::{closure#0}, !>::{closure#0}, !>
  16:     0x75a8db84d507 - rustc_middle[659b125a344ae30d]::util::bug::span_bug_fmt::<rustc_span[64a5b554609a9731]::span_encoding::Span>
  17:     0x75a8de2b863b - <rustc_mir_build[baa765b1395bc0bb]::builder::Builder>::as_constant
  18:     0x75a8de2d207c - <rustc_mir_build[baa765b1395bc0bb]::builder::Builder>::expr_into_dest
  19:     0x75a8de2b6c51 - <rustc_mir_build[baa765b1395bc0bb]::builder::Builder>::as_temp::{closure#0}
  20:     0x75a8de3c10a1 - <rustc_mir_build[baa765b1395bc0bb]::builder::Builder>::stmt_expr
  21:     0x75a8de3c128c - <rustc_mir_build[baa765b1395bc0bb]::builder::Builder>::stmt_expr
  22:     0x75a8da9e82e2 - <rustc_mir_build[baa765b1395bc0bb]::builder::Builder>::ast_block_stmts
  23:     0x75a8de2c7ccc - <rustc_mir_build[baa765b1395bc0bb]::builder::Builder>::expr_into_dest
  24:     0x75a8de2c991b - <rustc_mir_build[baa765b1395bc0bb]::builder::Builder>::expr_into_dest
  25:     0x75a8da9e8c60 - <rustc_mir_build[baa765b1395bc0bb]::builder::Builder>::ast_block_stmts
  26:     0x75a8de2c7ccc - <rustc_mir_build[baa765b1395bc0bb]::builder::Builder>::expr_into_dest
  27:     0x75a8de2c991b - <rustc_mir_build[baa765b1395bc0bb]::builder::Builder>::expr_into_dest
  28:     0x75a8deae59d8 - rustc_mir_build[baa765b1395bc0bb]::builder::build_mir
  29:     0x75a8de009ab6 - rustc_mir_transform[acaa9d1308dc1d90]::mir_built
  30:     0x75a8de009a87 - rustc_query_impl[e7623f81ec67c060]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[e7623f81ec67c060]::query_impl::mir_built::dynamic_query::{closure#2}::{closure#0}, rustc_middle[659b125a344ae30d]::query::erase::Erased<[u8; 8usize]>>
  31:     0x75a8de3ac98c - rustc_query_system[3f0ad7ad24ecba32]::query::plumbing::try_execute_query::<rustc_query_impl[e7623f81ec67c060]::DynamicConfig<rustc_data_structures[26227f1c624ab24f]::vec_cache::VecCache<rustc_span[64a5b554609a9731]::def_id::LocalDefId, rustc_middle[659b125a344ae30d]::query::erase::Erased<[u8; 8usize]>, rustc_query_system[3f0ad7ad24ecba32]::dep_graph::graph::DepNodeIndex>, false, false, false>, rustc_query_impl[e7623f81ec67c060]::plumbing::QueryCtxt, false>
  32:     0x75a8de3ac54c - rustc_query_impl[e7623f81ec67c060]::query_impl::mir_built::get_query_non_incr::__rust_end_short_backtrace
  33:     0x75a8dace65ba - rustc_mir_build[baa765b1395bc0bb]::check_unsafety::check_unsafety
  34:     0x75a8de49246b - rustc_query_impl[e7623f81ec67c060]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[e7623f81ec67c060]::query_impl::check_unsafety::dynamic_query::{closure#2}::{closure#0}, rustc_middle[659b125a344ae30d]::query::erase::Erased<[u8; 0usize]>>
  35:     0x75a8de49271d - rustc_query_system[3f0ad7ad24ecba32]::query::plumbing::try_execute_query::<rustc_query_impl[e7623f81ec67c060]::DynamicConfig<rustc_data_structures[26227f1c624ab24f]::vec_cache::VecCache<rustc_span[64a5b554609a9731]::def_id::LocalDefId, rustc_middle[659b125a344ae30d]::query::erase::Erased<[u8; 0usize]>, rustc_query_system[3f0ad7ad24ecba32]::dep_graph::graph::DepNodeIndex>, false, false, false>, rustc_query_impl[e7623f81ec67c060]::plumbing::QueryCtxt, false>
  36:     0x75a8de491a7f - rustc_query_impl[e7623f81ec67c060]::query_impl::check_unsafety::get_query_non_incr::__rust_end_short_backtrace
  37:     0x75a8de48fe1e - rustc_interface[27637195c005b57e]::passes::run_required_analyses
  38:     0x75a8def05d3a - rustc_interface[27637195c005b57e]::passes::analysis
  39:     0x75a8def05d19 - rustc_query_impl[e7623f81ec67c060]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[e7623f81ec67c060]::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle[659b125a344ae30d]::query::erase::Erased<[u8; 0usize]>>
  40:     0x75a8df01eb0b - rustc_query_system[3f0ad7ad24ecba32]::query::plumbing::try_execute_query::<rustc_query_impl[e7623f81ec67c060]::DynamicConfig<rustc_query_system[3f0ad7ad24ecba32]::query::caches::SingleCache<rustc_middle[659b125a344ae30d]::query::erase::Erased<[u8; 0usize]>>, false, false, false>, rustc_query_impl[e7623f81ec67c060]::plumbing::QueryCtxt, false>
  41:     0x75a8df01e7f9 - rustc_query_impl[e7623f81ec67c060]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
  42:     0x75a8df0438bd - rustc_interface[27637195c005b57e]::passes::create_and_enter_global_ctxt::<core[7b1631f15169ed9]::option::Option<rustc_interface[27637195c005b57e]::queries::Linker>, rustc_driver_impl[d6673cd08a515aef]::run_compiler::{closure#0}::{closure#2}>::{closure#2}::{closure#0}
  43:     0x75a8df0c0f0f - rustc_interface[27637195c005b57e]::interface::run_compiler::<(), rustc_driver_impl[d6673cd08a515aef]::run_compiler::{closure#0}>::{closure#1}
  44:     0x75a8def35d88 - std[c8fe94e2e6a595f7]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[27637195c005b57e]::util::run_in_thread_with_globals<rustc_interface[27637195c005b57e]::util::run_in_thread_pool_with_globals<rustc_interface[27637195c005b57e]::interface::run_compiler<(), rustc_driver_impl[d6673cd08a515aef]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>
  45:     0x75a8def36674 - <<std[c8fe94e2e6a595f7]::thread::Builder>::spawn_unchecked_<rustc_interface[27637195c005b57e]::util::run_in_thread_with_globals<rustc_interface[27637195c005b57e]::util::run_in_thread_pool_with_globals<rustc_interface[27637195c005b57e]::interface::run_compiler<(), rustc_driver_impl[d6673cd08a515aef]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>::{closure#1} as core[7b1631f15169ed9]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  46:     0x75a8def37a77 - std::sys::pal::unix::thread::Thread::new::thread_start::h5b44a9a0f1d97c81
  47:     0x75a8d90a370a - <unknown>
  48:     0x75a8d9127aac - <unknown>
  49:                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 (e6af292f9 2025-03-06) running on x86_64-unknown-linux-gnu

note: compiler flags: -Z dump-mir-dir=dir

query stack during panic:
#0 [mir_built] building MIR for `uwu`
#1 [check_unsafety] unsafety-checking `uwu`
#2 [analysis] running analysis passes on this crate
end of query stack
error: aborting due to 3 previous errors

For more information about this error, try `rustc --explain E0601`.

@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 Mar 6, 2025
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Mar 6, 2025
@matthiaskrgr
Copy link
Member Author

bisects to #137180

@compiler-errors compiler-errors self-assigned this Mar 6, 2025
@bors bors closed this as completed in 69c7e36 Mar 10, 2025
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Mar 10, 2025
Rollup merge of rust-lang#138138 - compiler-errors:inline-asm-tainting, r=oli-obk

Pass `InferCtxt` to `InlineAsmCtxt` to properly taint on error

Pass an `InferCtxt` into the `InlineAsmCtxt` so that we can use the right dcx to taint the infcx properly, so that we don't try to build invalid MIR for inline asm blocks.

Fixes rust-lang#138130

Shares the first commit with rust-lang#137502.

r? oli-obk
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. 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.

3 participants