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: asm const cannot be resolved #121099

Closed
matthiaskrgr opened this issue Feb 14, 2024 · 6 comments · Fixed by #122691
Closed

ice: asm const cannot be resolved #121099

matthiaskrgr opened this issue Feb 14, 2024 · 6 comments · Fixed by #122691
Assignees
Labels
A-inline-assembly Area: inline asm!(..) C-bug Category: This is a bug. F-asm `#![feature(asm)]` (not `llvm_asm`) F-inline_const Inline constants (aka: const blocks, const expressions, anonymous constants) 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.

Comments

@matthiaskrgr
Copy link
Member

matthiaskrgr commented Feb 14, 2024

auto-reduced (treereduce-rust):

#![feature(asm_const)]

use std::arch::{asm, global_asm};

fn main() {}

global_asm!("/* {} */", const 1 / 0);

original:

// only-aarch64
// run-pass
// needs-asm-support

#![feature(asm_const)]

use std::arch::{asm, global_asm};

fn const_generic<const X: usize>() -> usize {
    unsafe {
        let a: usize;
        asm!("mov {}, {}", out(reg) a, const X);
        a
    }
}

const fn constfn(x: usize) -> usize {
    x
}

fn main() {
    unsafe {
        let a: usize;
        asm!("mov {}, {}", out(reg) a, const 5);
        assert_eq!(a, 5);

        let b: usize;
        asm!("mov {}, {}", out(reg) b, const constfn(5));
        assert_eq!(b, 5);

        let c: usize;
        asm!("mov {}, {}", out(reg) c, const constfn(5) + constfn(5));
        assert_eq!(c, 10);
    }

    let d = const_generic::<5>();
    assert_eq!(d, 5);
}

global_asm!("mov x0, {}", const 5);
global_asm!("mov x0, {}", const constfn(5));
global_asm!("/* {} */", const 1 / 0);

Version information

rustc 1.78.0-nightly (340bb19fe 2024-02-14)
binary: rustc
commit-hash: 340bb19fea20fd5f9357bbfac542fad84fc7ea2b
commit-date: 2024-02-14
host: x86_64-unknown-linux-gnu
release: 1.78.0-nightly
LLVM version: 18.1.0

Command:
/home/matthias/.rustup/toolchains/master/bin/rustc

Program output

warning: unused import: `asm`
 --> /tmp/icemaker_global_tempdir.2zj7DJPZrPS9/rustc_testrunner_tmpdir_reporting.NjtF3y0XkmX4/mvce.rs:3:17
  |
3 | use std::arch::{asm, global_asm};
  |                 ^^^
  |
  = note: `#[warn(unused_imports)]` on by default

error[E0080]: evaluation of constant value failed
 --> /tmp/icemaker_global_tempdir.2zj7DJPZrPS9/rustc_testrunner_tmpdir_reporting.NjtF3y0XkmX4/mvce.rs:7:31
  |
7 | global_asm!("/* {} */", const 1 / 0);
  |                               ^^^^^ attempt to divide `1_i32` by zero

error: internal compiler error: /rustc/340bb19fea20fd5f9357bbfac542fad84fc7ea2b/compiler/rustc_codegen_ssa/src/mono_item.rs:47:41: asm const cannot be resolved
 --> /tmp/icemaker_global_tempdir.2zj7DJPZrPS9/rustc_testrunner_tmpdir_reporting.NjtF3y0XkmX4/mvce.rs:7:25
  |
7 | global_asm!("/* {} */", const 1 / 0);
  |                         ^^^^^^^^^^^

thread 'rustc' panicked at /rustc/340bb19fea20fd5f9357bbfac542fad84fc7ea2b/compiler/rustc_middle/src/util/bug.rs:34:50:
Box<dyn Any>
stack backtrace:
   0:     0x7f70bbd8ce46 - std::backtrace_rs::backtrace::libunwind::trace::h741b35e6ebf0ea82
                               at /rustc/340bb19fea20fd5f9357bbfac542fad84fc7ea2b/library/std/src/../../backtrace/src/backtrace/libunwind.rs:104:5
   1:     0x7f70bbd8ce46 - std::backtrace_rs::backtrace::trace_unsynchronized::hf3b09a36cbdb818e
                               at /rustc/340bb19fea20fd5f9357bbfac542fad84fc7ea2b/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x7f70bbd8ce46 - std::sys_common::backtrace::_print_fmt::hd9ddcb56e855ae1f
                               at /rustc/340bb19fea20fd5f9357bbfac542fad84fc7ea2b/library/std/src/sys_common/backtrace.rs:68:5
   3:     0x7f70bbd8ce46 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h1d659f3f1b376713
                               at /rustc/340bb19fea20fd5f9357bbfac542fad84fc7ea2b/library/std/src/sys_common/backtrace.rs:44:22
   4:     0x7f70bbddd46c - core::fmt::rt::Argument::fmt::h268aa39b6fb00372
                               at /rustc/340bb19fea20fd5f9357bbfac542fad84fc7ea2b/library/core/src/fmt/rt.rs:142:9
   5:     0x7f70bbddd46c - core::fmt::write::h3ca4c8a121ee4a21
                               at /rustc/340bb19fea20fd5f9357bbfac542fad84fc7ea2b/library/core/src/fmt/mod.rs:1120:17
   6:     0x7f70bbd8087f - std::io::Write::write_fmt::hbae5643614f30ef5
                               at /rustc/340bb19fea20fd5f9357bbfac542fad84fc7ea2b/library/std/src/io/mod.rs:1854:15
   7:     0x7f70bbd8cbf4 - std::sys_common::backtrace::_print::h46251963e880a6db
                               at /rustc/340bb19fea20fd5f9357bbfac542fad84fc7ea2b/library/std/src/sys_common/backtrace.rs:47:5
   8:     0x7f70bbd8cbf4 - std::sys_common::backtrace::print::hf7d8eafd5758e700
                               at /rustc/340bb19fea20fd5f9357bbfac542fad84fc7ea2b/library/std/src/sys_common/backtrace.rs:34:9
   9:     0x7f70bbd8f93b - std::panicking::default_hook::{{closure}}::h762f7d01310422ff
  10:     0x7f70bbd8f689 - std::panicking::default_hook::h6bf045830ee7f539
                               at /rustc/340bb19fea20fd5f9357bbfac542fad84fc7ea2b/library/std/src/panicking.rs:292:9
  11:     0x7f70bebf2bac - std[3c399c9137e7035e]::panicking::update_hook::<alloc[b5118abce3d9b84a]::boxed::Box<rustc_driver_impl[aed52aad4ff697f9]::install_ice_hook::{closure#0}>>::{closure#0}
  12:     0x7f70bbd900a0 - <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call::h183d4d6c4a9f8452
                               at /rustc/340bb19fea20fd5f9357bbfac542fad84fc7ea2b/library/alloc/src/boxed.rs:2030:9
  13:     0x7f70bbd900a0 - std::panicking::rust_panic_with_hook::hf47919d70d1ff480
                               at /rustc/340bb19fea20fd5f9357bbfac542fad84fc7ea2b/library/std/src/panicking.rs:785:13
  14:     0x7f70bec20264 - std[3c399c9137e7035e]::panicking::begin_panic::<rustc_errors[b0a2db8db751489]::ExplicitBug>::{closure#0}
  15:     0x7f70bec1cbc6 - std[3c399c9137e7035e]::sys_common::backtrace::__rust_end_short_backtrace::<std[3c399c9137e7035e]::panicking::begin_panic<rustc_errors[b0a2db8db751489]::ExplicitBug>::{closure#0}, !>
  16:     0x7f70bec18146 - std[3c399c9137e7035e]::panicking::begin_panic::<rustc_errors[b0a2db8db751489]::ExplicitBug>
  17:     0x7f70bec2bdb1 - <rustc_errors[b0a2db8db751489]::diagnostic_builder::BugAbort as rustc_errors[b0a2db8db751489]::diagnostic_builder::EmissionGuarantee>::emit_producing_guarantee
  18:     0x7f70bea8c63d - rustc_middle[70484f9a8b697519]::util::bug::opt_span_bug_fmt::<rustc_span[193b94924c128396]::span_encoding::Span>::{closure#0}
  19:     0x7f70bea8ca5a - rustc_middle[70484f9a8b697519]::ty::context::tls::with_opt::<rustc_middle[70484f9a8b697519]::util::bug::opt_span_bug_fmt<rustc_span[193b94924c128396]::span_encoding::Span>::{closure#0}, !>::{closure#0}
  20:     0x7f70bea843e8 - rustc_middle[70484f9a8b697519]::ty::context::tls::with_context_opt::<rustc_middle[70484f9a8b697519]::ty::context::tls::with_opt<rustc_middle[70484f9a8b697519]::util::bug::opt_span_bug_fmt<rustc_span[193b94924c128396]::span_encoding::Span>::{closure#0}, !>::{closure#0}, !>
  21:     0x7f70bea826c4 - rustc_middle[70484f9a8b697519]::util::bug::span_bug_fmt::<rustc_span[193b94924c128396]::span_encoding::Span>
  22:     0x7f70c09e0200 - rustc_codegen_llvm[63f401253c7e1412]::base::compile_codegen_unit::module_codegen
  23:     0x7f70c0d26a93 - <rustc_codegen_llvm[63f401253c7e1412]::LlvmCodegenBackend as rustc_codegen_ssa[a586662d15c3dc2]::traits::backend::ExtraBackendMethods>::compile_codegen_unit
  24:     0x7f70c0dac1d7 - rustc_codegen_ssa[a586662d15c3dc2]::base::codegen_crate::<rustc_codegen_llvm[63f401253c7e1412]::LlvmCodegenBackend>
  25:     0x7f70c0dab935 - <rustc_codegen_llvm[63f401253c7e1412]::LlvmCodegenBackend as rustc_codegen_ssa[a586662d15c3dc2]::traits::backend::CodegenBackend>::codegen_crate
  26:     0x7f70c0ddc8ca - rustc_interface[85a46e65fd36dd64]::passes::start_codegen
  27:     0x7f70c0ddc098 - <rustc_interface[85a46e65fd36dd64]::queries::Queries>::codegen_and_build_linker
  28:     0x7f70c0c2e0a8 - rustc_interface[85a46e65fd36dd64]::interface::run_compiler::<core[7e3aa1eb1ad3b865]::result::Result<(), rustc_span[193b94924c128396]::ErrorGuaranteed>, rustc_driver_impl[aed52aad4ff697f9]::run_compiler::{closure#0}>::{closure#0}
  29:     0x7f70c0dc7b58 - std[3c399c9137e7035e]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[85a46e65fd36dd64]::util::run_in_thread_with_globals<rustc_interface[85a46e65fd36dd64]::util::run_in_thread_pool_with_globals<rustc_interface[85a46e65fd36dd64]::interface::run_compiler<core[7e3aa1eb1ad3b865]::result::Result<(), rustc_span[193b94924c128396]::ErrorGuaranteed>, rustc_driver_impl[aed52aad4ff697f9]::run_compiler::{closure#0}>::{closure#0}, core[7e3aa1eb1ad3b865]::result::Result<(), rustc_span[193b94924c128396]::ErrorGuaranteed>>::{closure#0}, core[7e3aa1eb1ad3b865]::result::Result<(), rustc_span[193b94924c128396]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[7e3aa1eb1ad3b865]::result::Result<(), rustc_span[193b94924c128396]::ErrorGuaranteed>>
  30:     0x7f70c0dc7984 - <<std[3c399c9137e7035e]::thread::Builder>::spawn_unchecked_<rustc_interface[85a46e65fd36dd64]::util::run_in_thread_with_globals<rustc_interface[85a46e65fd36dd64]::util::run_in_thread_pool_with_globals<rustc_interface[85a46e65fd36dd64]::interface::run_compiler<core[7e3aa1eb1ad3b865]::result::Result<(), rustc_span[193b94924c128396]::ErrorGuaranteed>, rustc_driver_impl[aed52aad4ff697f9]::run_compiler::{closure#0}>::{closure#0}, core[7e3aa1eb1ad3b865]::result::Result<(), rustc_span[193b94924c128396]::ErrorGuaranteed>>::{closure#0}, core[7e3aa1eb1ad3b865]::result::Result<(), rustc_span[193b94924c128396]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[7e3aa1eb1ad3b865]::result::Result<(), rustc_span[193b94924c128396]::ErrorGuaranteed>>::{closure#1} as core[7e3aa1eb1ad3b865]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  31:     0x7f70bbd991e5 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h1516af221a452bc1
                               at /rustc/340bb19fea20fd5f9357bbfac542fad84fc7ea2b/library/alloc/src/boxed.rs:2016:9
  32:     0x7f70bbd991e5 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::hff2a9d52ad89d581
                               at /rustc/340bb19fea20fd5f9357bbfac542fad84fc7ea2b/library/alloc/src/boxed.rs:2016:9
  33:     0x7f70bbd991e5 - std::sys::pal::unix::thread::Thread::new::thread_start::hf359248e8c5b2b25
                               at /rustc/340bb19fea20fd5f9357bbfac542fad84fc7ea2b/library/std/src/sys/pal/unix/thread.rs:108:17
  34:     0x7f70bbb809eb - <unknown>
  35:     0x7f70bbc047cc - <unknown>
  36:                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: rustc 1.78.0-nightly (340bb19fe 2024-02-14) running on x86_64-unknown-linux-gnu

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

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

@matthiaskrgr matthiaskrgr added 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. C-bug Category: This is a bug. labels Feb 14, 2024
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Feb 14, 2024
@matthiaskrgr
Copy link
Member Author

Regression in nightly-2021-12-16 lol

commit[0] 2021-12-14: Auto merge of #91902 - matthiaskrgr:rollup-hjjyhow, r=matthiaskrgr
commit[1] 2021-12-14: Auto merge of #91728 - Amanieu:stable_asm, r=joshtriplett
commit[2] 2021-12-15: Auto merge of #91933 - matthiaskrgr:rollup-cw9qolb, r=matthiaskrgr
commit[3] 2021-12-15: Auto merge of #91945 - matthiaskrgr:rollup-jszf9zp, r=matthiaskrgr
commit[4] 2021-12-15: Auto merge of #91752 - yaahc:track-caller-result, r=cuviper
commit[5] 2021-12-15: Auto merge of #91959 - matthiaskrgr:rollup-rhajuvw, r=matthiaskrgr
commit[6] 2021-12-15: Auto merge of #91962 - matthiaskrgr:rollup-2g082jw, r=matthiaskrgr
ERROR: no CI builds available between 404c847 and c5ecc15 within last 167 days
~/vcs/github/rust_bisect via 🦀 v1.78.0-nightly too

I would guess #91728 ? cc @Amanieu

@asquared31415
Copy link
Contributor

Doubt it, that's just when the stabilization happened, there's no meaningful changes there

@asquared31415
Copy link
Contributor

Actually bisects to #84107 which added support for const in global_asm!.

@jieyouxu
Copy link
Member

@rustbot label +F-asm +A-inline-assembly +F-inline_const -needs-triage

@rustbot rustbot added A-inline-assembly Area: inline asm!(..) F-asm `#![feature(asm)]` (not `llvm_asm`) F-inline_const Inline constants (aka: const blocks, const expressions, anonymous constants) and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Feb 14, 2024
@asquared31415
Copy link
Contributor

cc #93332

@veera-sivarajan
Copy link
Contributor

@rustbot claim

workingjubilee added a commit to workingjubilee/rustc that referenced this issue Mar 18, 2024
…manieu

Fix ICE: `global_asm!()` Don't Panic When Unable to Evaluate Constant

Fixes rust-lang#121099

A bit of an inelegant fix but given that the error is created only
after call to `const_eval_poly()` and that the calling function
cannot propagate the error anywhere else, the error has to be
explicitly handled inside `mono_item.rs`.

r? `@Amanieu`
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Mar 18, 2024
…manieu

Fix ICE: `global_asm!()` Don't Panic When Unable to Evaluate Constant

Fixes rust-lang#121099

A bit of an inelegant fix but given that the error is created only
after call to `const_eval_poly()` and that the calling function
cannot propagate the error anywhere else, the error has to be
explicitly handled inside `mono_item.rs`.

r? ``@Amanieu``
@bors bors closed this as completed in 2ad2492 Mar 19, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Mar 19, 2024
Rollup merge of rust-lang#122691 - veera-sivarajan:bugfix-121099, r=Amanieu

Fix ICE: `global_asm!()` Don't Panic When Unable to Evaluate Constant

Fixes rust-lang#121099

A bit of an inelegant fix but given that the error is created only
after call to `const_eval_poly()` and that the calling function
cannot propagate the error anywhere else, the error has to be
explicitly handled inside `mono_item.rs`.

r? `@Amanieu`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-inline-assembly Area: inline asm!(..) C-bug Category: This is a bug. F-asm `#![feature(asm)]` (not `llvm_asm`) F-inline_const Inline constants (aka: const blocks, const expressions, anonymous constants) 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.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants