rust-lang / rust-lang/rustc_codegen_cranelift

ICE: `naked_asm!` unreachable

Open
#1,690 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Rust
Stars
2.1k
Forks
157
Avg merge
1d 19h
Merged PRs (30d)
3

Description

auto-reduced (treereduce-rust):

//@compile-flags: -Zcodegen-backend=cranelift
#![feature(asm_const_ptr)]
use std::arch::{asm, global_asm, naked_asm};

#[unsafe(naked)]
extern "system" fn naked() {
    unsafe {
        naked_asm!("ret /* {} */", const &0);
    }
}

fn main() {
    naked();
}

original:

//@ only-x86_64

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

global_asm!("/* {} */", const &0);
//~^ ERROR using pointers in asm `const` operand is experimental

#[unsafe(naked)]
extern "system" fn naked() {
    unsafe {
        naked_asm!("ret /* {} */", const &0);
        //~^ ERROR using pointers in asm `const` operand is experimental
    }
}

fn main() {
    naked();
    unsafe {
        asm!("/* {} */", const &0);
        //~^ ERROR using pointers in asm `const` operand is experimental
    }
}

Version information

rustc 1.99.0-nightly (a04c7a037 2026-08-11)
binary: rustc
commit-hash: a04c7a037d59b6dedc9f921e84e391f13a257aa4
commit-date: 2026-08-11
host: x86_64-unknown-linux-gnu
release: 1.99.0-nightly
LLVM version: 23.1.0

Possibly related line of code:
https://github.com/rust-lang/rust/blob/a04c7a037d59b6dedc9f921e84e391f13a257aa4/compiler/rustc_codegen_cranelift/src/global_asm.rs#L140-L152

Command:
/home/matthias/.rustup/toolchains/master/bin/rustc -Zcodegen-backend=cranelift -Zcrate-attr=feature(asm_const_ptr)

Program output

warning: unused imports: `asm` and `global_asm`
 --> /tmp/icemaker_global_tempdir.KbBkuV4MJKpM/rustc_testrunner_tmpdir_reporting.EKgaEUGDTD6K/mvce.rs:1:17
  |
1 | use std::arch::{asm, global_asm, naked_asm};
  |                 ^^^  ^^^^^^^^^^
  |
  = note: `#[warn(unused_imports)]` (part of `#[warn(unused)]`) on by default

warning: unnecessary `unsafe` block
 --> /tmp/icemaker_global_tempdir.KbBkuV4MJKpM/rustc_testrunner_tmpdir_reporting.EKgaEUGDTD6K/mvce.rs:5:5
  |
5 |     unsafe {
  |     ^^^^^^ unnecessary `unsafe` block
  |
  = note: `#[warn(unused_unsafe)]` (part of `#[warn(unused)]`) on by default

error: asm! and global_asm! sym operands are not yet supported
 --> /tmp/icemaker_global_tempdir.KbBkuV4MJKpM/rustc_testrunner_tmpdir_reporting.EKgaEUGDTD6K/mvce.rs:6:28
  |
6 |         naked_asm!("ret /* {} */", const &0);
  |                            ^^


thread 'rustc' (632816) panicked at /rustc-dev/a04c7a037d59b6dedc9f921e84e391f13a257aa4/compiler/rustc_codegen_cranelift/src/global_asm.rs:146:69:
internal error: entered unreachable code
stack backtrace:
   0:     0x7f3037a76ae6 - <<std[448a6b8f3c6421af]::sys::backtrace::BacktraceLock>::print::DisplayBacktrace as core[faf7ed943a4f8e4f]::fmt::Display>::fmt
   1:     0x7f303800b823 - core[faf7ed943a4f8e4f]::fmt::write
   2:     0x7f3037a8ba0c - <std[448a6b8f3c6421af]::sys::stdio::unix::Stderr as core[faf7ed943a4f8e4f]::io::write::Write>::write_fmt
   3:     0x7f3037a49a4a - std[448a6b8f3c6421af]::panicking::default_hook::{closure#0}
   4:     0x7f3037a6a873 - std[448a6b8f3c6421af]::panicking::default_hook
   5:     0x7f30369fc7ea - std[448a6b8f3c6421af]::panicking::update_hook::<alloc[a52cb92b36bbf767]::boxed::Box<rustc_driver_impl[a86674e468a5c934]::install_ice_hook::{closure#1}>>::{closure#0}
   6:     0x7f3037a6ad12 - std[448a6b8f3c6421af]::panicking::panic_with_hook
   7:     0x7f3037a49b34 - std[448a6b8f3c6421af]::panicking::panic_handler::{closure#0}
   8:     0x7f3037a409e9 - std[448a6b8f3c6421af]::sys::backtrace::__rust_end_short_backtrace::<std[448a6b8f3c6421af]::panicking::panic_handler::{closure#0}, !>
   9:     0x7f3037a4b4dd - __rustc[ea1e64b7bd730d00]::rust_begin_unwind
  10:     0x7f30346c0a0c - core[faf7ed943a4f8e4f]::panicking::panic_fmt
  11:     0x7f3034cc98a2 - core[faf7ed943a4f8e4f]::panicking::panic
  12:     0x7f3024b11e6d - <rustc_codegen_cranelift[905dadbfd70718c8]::global_asm::GlobalAsmContext as rustc_codegen_ssa[2d44ee88eee97c4d]::traits::asm::AsmCodegenMethods>::codegen_global_asm
  13:     0x7f3024b03e6a - rustc_codegen_cranelift[905dadbfd70718c8]::driver::aot::codegen_cgu
  14:     0x7f3024aaa1fe - <rustc_codegen_cranelift[905dadbfd70718c8]::driver::aot::AotDriver as rustc_codegen_ssa[2d44ee88eee97c4d]::traits::backend::ExtraBackendMethods>::compile_codegen_unit::{closure#0}
  15:     0x7f3024b141ce - <rustc_codegen_cranelift[905dadbfd70718c8]::driver::aot::AotDriver as rustc_codegen_ssa[2d44ee88eee97c4d]::traits::backend::ExtraBackendMethods>::compile_codegen_unit
  16:     0x7f3024a77f62 - rustc_codegen_ssa[2d44ee88eee97c4d]::base::codegen_crate::<rustc_codegen_cranelift[905dadbfd70718c8]::driver::aot::AotDriver, rustc_codegen_cranelift[905dadbfd70718c8]::driver::aot::AotModule>
  17:     0x7f3024b2317f - <rustc_codegen_cranelift[905dadbfd70718c8]::CraneliftCodegenBackend as rustc_codegen_ssa[2d44ee88eee97c4d]::traits::backend::CodegenBackend>::codegen_crate
  18:     0x7f30392b16e5 - <rustc_interface[3209358e9030f33]::queries::Linker>::codegen_and_build_linker
  19:     0x7f30392a9097 - rustc_interface[3209358e9030f33]::interface::run_compiler::<(), rustc_driver_impl[a86674e468a5c934]::run_compiler::{closure#0}>::{closure#2}
  20:     0x7f30392784a4 - std[448a6b8f3c6421af]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[3209358e9030f33]::util::run_in_thread_with_globals<rustc_interface[3209358e9030f33]::util::run_in_thread_pool_with_globals<rustc_interface[3209358e9030f33]::interface::run_compiler<(), rustc_driver_impl[a86674e468a5c934]::run_compiler::{closure#0}>::{closure#2}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>
  21:     0x7f303927826d - <std[448a6b8f3c6421af]::thread::lifecycle::spawn_unchecked<rustc_interface[3209358e9030f33]::util::run_in_thread_with_globals<rustc_interface[3209358e9030f33]::util::run_in_thread_pool_with_globals<rustc_interface[3209358e9030f33]::interface::run_compiler<(), rustc_driver_impl[a86674e468a5c934]::run_compiler::{closure#0}>::{closure#2}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>::{closure#1} as core[faf7ed943a4f8e4f]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  22:     0x7f30393093ba - <std[448a6b8f3c6421af]::sys::thread::unix::Thread>::new::thread_start
  23:     0x7f3032897739 - <unknown>
  24:     0x7f303291bedc - <unknown>
  25:                0x0 - <unknown>

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: rustc 1.99.0-nightly (a04c7a037 2026-08-11) running on x86_64-unknown-linux-gnu

note: compiler flags: -Z codegen-backend=cranelift -Z crate-attr=feature(asm_const_ptr) -Z dump-mir-dir=dir

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


@rustbot label +F-asm_const_ptr

Contributor guide

No contributing guide indexed for this repository

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_codegen_cranelift/src/global_asm.rs around line 146 and reproduce the ICE with the reduced Rust example using the listed Cranelift compiler flags. Trace how the unsupported naked_asm! const pointer operand reaches codegen. Done means the reproducer reports an error without panicking or entering unreachable code.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
64/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.