Repository: rust
Issue: ICE: intrinsicck: `index out of bounds: the len is 0 but the index is 0`
Labels: I-ICE,A-inline-assembly,T-compiler,A-SIMD,C-bug,S-bug-has-test

<!--
[31mICE[0m: Rustc ./a.rs '' 'thread 'rustc' panicked at compiler/rustc_hir_analysis/src/check/intrinsicck.rs:89:36: 'index out of bounds: the len is 0 but the index is 0'', 'thread 'rustc' panicked at compiler/rustc_hir_analysis/src/check/intrinsicck.rs:89:36: 'index out of bounds: the len is 0 but the index is 0''
File: /tmp/im/a.rs
-->

auto-reduced (treereduce-rust):
````rust
use std::arch::{asm, global_asm};

#[repr(simd)]
struct SimdNonCopy();

fn main() {
    unsafe {
        let x = 1;

        let _ = y;

        asm!("{}", in(xmm_reg) SimdNonCopy());
    }
}

````

<details><summary><strong>original code</strong></summary>
<p>

original:
````rust
//@ only-x86_64

#![feature(repr_simd, never_type)]

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

#[repr(simd)]
struct SimdNonCopy();

fn main() {
    unsafe {
        // Inputs must be initialized

        let x = 1;
        asm!("{}", in(reg) x);
        //~^ ERROR isn't initialized
        let mut y: u64;
        asm!("{}", inout(reg) y);
        //~^ ERROR isn't initialized
        let _ = y;

        // Outputs require mutable places

        let v: Vec<u64> = vec![0, 1, 2];
        //~^ ERROR is not declared as mutable
        asm!("{}", in(reg) v[0]);
        asm!("{}", out(reg) v[0]);
        asm!("{}", inout(reg) v[0]);

        // Register operands must be Copy

        asm!("{}", in(xmm_reg) SimdNonCopy([0.0, 0.0, 0.0, 0.0]));
        //~^ ERROR arguments for inline assembly must be copyable

        // Register operands must be integers, floats, SIMD vectors, pointers or
        // function pointers.

        asm!("{}", in(reg) 0i64);
        asm!("{}", in(deny) 0f64);
        asm!("{}", in(xmm_reg) std::arch::x86_64::_mm_setzero_ps());
        asm!("{}", in(reg) 0 as *const u8);
        asm!("{}", in(reg) 0 as *mut u8);
        asm!("{}", in(reg) main as fn());
        asm!("{}", in(reg) |x: i32| x);
        //~^ ERROR cannot use value of type
        asm!("{}", in(reg) 0i64);
        //~^ ERROR cannot use value of type `Vec<i32>` for inline assembly
        asm!("mm0", in(reg) (1, 2, 3));
        //~^ ERROR cannot use value of type `(i32, i32, i32)` for inline assembly
        asm!("", in("mm0") foo);
        //~^ ERROR cannot use value of type `[i32; 3]` for inline assembly

        // Register inputs (but not outputs) allow references and function types

        let mut f = main;
        let mut r = &mut 0;
        asm!("{}", in(reg) f);
        asm!("{}", in(xmm_reg) SimdNonCopy([0.0, 0.0, 0.0, 0.0]));
        //~^ ERROR cannot use value of type `fn() {main}` for inline assembly
        asm!("{}", in(reg) r);
        asm!("{}", inout(reg) r);
        //~^ ERROR cannot use value of type `&mut i32` for inline assembly
        let _ = (f, r);

        // Type checks ignore never type

        let u: ! = unreachable!();
        asm!("{}", in(reg) u);
    }
}

````
</p>
</details>

Version information
````
rustc 1.85.0-nightly (4790a435c 2024-12-15)
binary: rustc
commit-hash: 4790a435cbcb55c94ccdef51bf7a9b2e55824528
commit-date: 2024-12-15
host: x86_64-unknown-linux-gnu
release: 1.85.0-nightly
LLVM version: 19.1.5

````

Possibly related line of code:
https://github.com/rust-lang/rust/blob/4790a435cbcb55c94ccdef51bf7a9b2e55824528/compiler/rustc_hir_analysis/src/check/intrinsicck.rs#L83-L95

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

<details><summary><strong>Program output</strong></summary>
<p>

```
error[E0425]: cannot find value `y` in this scope
  --> /tmp/icemaker_global_tempdir.fOXZErRE56RX/rustc_testrunner_tmpdir_reporting.p9FlkAioN2KU/mvce.rs:10:17
   |
10 |         let _ = y;
   |                 ^ help: a local variable with a similar name exists: `x`

error[E0658]: SIMD types are experimental and possibly buggy
 --> /tmp/icemaker_global_tempdir.fOXZErRE56RX/rustc_testrunner_tmpdir_reporting.p9FlkAioN2KU/mvce.rs:3:1
  |
3 | #[repr(simd)]
  | ^^^^^^^^^^^^^
  |
  = note: see issue #27731 <https://github.com/rust-lang/rust/issues/27731> for more information
  = help: add `#![feature(repr_simd)]` to the crate attributes to enable
  = note: this compiler was built on 2024-12-15; consider upgrading it if it is out of date

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

error[E0075]: SIMD vector cannot be empty
 --> /tmp/icemaker_global_tempdir.fOXZErRE56RX/rustc_testrunner_tmpdir_reporting.p9FlkAioN2KU/mvce.rs:4:1
  |
4 | struct SimdNonCopy();
  | ^^^^^^^^^^^^^^^^^^

thread 'rustc' panicked at compiler/rustc_hir_analysis/src/check/intrinsicck.rs:89:36:
index out of bounds: the len is 0 but the index is 0
stack backtrace:
   0:     0x71b5da7a4c5a - <std::sys::backtrace::BacktraceLock::print::DisplayBacktrace as core::fmt::Display>::fmt::heb202b000efba683
   1:     0x71b5db013d66 - core::fmt::write::h4529572b8b32da24
   2:     0x71b5dc01db51 - std::io::Write::write_fmt::h1a906436cb206037
   3:     0x71b5da7a4ab2 - std::sys::backtrace::BacktraceLock::print::h934abc86fa2dd260
   4:     0x71b5da7a6faa - std::panicking::default_hook::{{closure}}::hfd4bbe50128406cd
   5:     0x71b5da7a6df3 - std::panicking::default_hook::h25fd19fcd22c2e04
   6:     0x71b5d98f9a68 - std[70002648da4681c1]::panicking::update_hook::<alloc[334d4c3039138aa]::boxed::Box<rustc_driver_impl[2cc745b14baadf]::install_ice_hook::{closure#0}>>::{closure#0}
   7:     0x71b5da7a7768 - std::panicking::rust_panic_with_hook::h3f6d3ded85336e6b
   8:     0x71b5da7a745a - std::panicking::begin_panic_handler::{{closure}}::h4686f34f41f48fef
   9:     0x71b5da7a50f9 - std::sys::backtrace::__rust_end_short_backtrace::h4d0c634afae53cc6
  10:     0x71b5da7a711d - rust_begin_unwind
  11:     0x71b5d73cf0c0 - core::panicking::panic_fmt::h5928a9348ea2bb6c
  12:     0x71b5d9120c16 - core::panicking::panic_bounds_check::ha0907f8c63a361ab
  13:     0x71b5d9a9eecc - <rustc_hir_analysis[4c68008ff0c7f4c4]::check::intrinsicck::InlineAsmCtxt>::get_asm_ty
  14:     0x71b5d9a9f067 - <rustc_hir_analysis[4c68008ff0c7f4c4]::check::intrinsicck::InlineAsmCtxt>::check_asm_operand_type
  15:     0x71b5d9aa0a0d - <rustc_hir_analysis[4c68008ff0c7f4c4]::check::intrinsicck::InlineAsmCtxt>::check_asm
  16:     0x71b5db21fad6 - rustc_hir_typeck[220f1b283db8da2]::typeck
  17:     0x71b5db21bafb - rustc_query_impl[98026ab69133ca5a]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[98026ab69133ca5a]::query_impl::typeck::dynamic_query::{closure#2}::{closure#0}, rustc_middle[4552a92c16cacd81]::query::erase::Erased<[u8; 8usize]>>
  18:     0x71b5db275711 - rustc_query_system[c5a9321c1b201b0d]::query::plumbing::try_execute_query::<rustc_query_impl[98026ab69133ca5a]::DynamicConfig<rustc_data_structures[41b15b2b138651fb]::vec_cache::VecCache<rustc_span[5501a71f8d28de35]::def_id::LocalDefId, rustc_middle[4552a92c16cacd81]::query::erase::Erased<[u8; 8usize]>, rustc_query_system[c5a9321c1b201b0d]::dep_graph::graph::DepNodeIndex>, false, false, false>, rustc_query_impl[98026ab69133ca5a]::plumbing::QueryCtxt, false>
  19:     0x71b5db2749cd - rustc_query_impl[98026ab69133ca5a]::query_impl::typeck::get_query_non_incr::__rust_end_short_backtrace
  20:     0x71b5db27467f - <rustc_middle[4552a92c16cacd81]::hir::map::Map>::par_body_owners::<rustc_hir_analysis[4c68008ff0c7f4c4]::check_crate::{closure#4}>::{closure#0}
  21:     0x71b5db272692 - rustc_hir_analysis[4c68008ff0c7f4c4]::check_crate
  22:     0x71b5db453502 - rustc_interface[cf66c2394d3c8572]::passes::run_required_analyses
  23:     0x71b5dc00c91e - rustc_interface[cf66c2394d3c8572]::passes::analysis
  24:     0x71b5dc00c8ef - rustc_query_impl[98026ab69133ca5a]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[98026ab69133ca5a]::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle[4552a92c16cacd81]::query::erase::Erased<[u8; 0usize]>>
  25:     0x71b5dc041015 - rustc_query_system[c5a9321c1b201b0d]::query::plumbing::try_execute_query::<rustc_query_impl[98026ab69133ca5a]::DynamicConfig<rustc_query_system[c5a9321c1b201b0d]::query::caches::SingleCache<rustc_middle[4552a92c16cacd81]::query::erase::Erased<[u8; 0usize]>>, false, false, false>, rustc_query_impl[98026ab69133ca5a]::plumbing::QueryCtxt, false>
  26:     0x71b5dc040d4e - rustc_query_impl[98026ab69133ca5a]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
  27:     0x71b5dc0b61b4 - rustc_interface[cf66c2394d3c8572]::interface::run_compiler::<(), rustc_driver_impl[2cc745b14baadf]::run_compiler::{closure#0}>::{closure#1}
  28:     0x71b5dbf685db - std[70002648da4681c1]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[cf66c2394d3c8572]::util::run_in_thread_with_globals<rustc_interface[cf66c2394d3c8572]::util::run_in_thread_pool_with_globals<rustc_interface[cf66c2394d3c8572]::interface::run_compiler<(), rustc_driver_impl[2cc745b14baadf]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>
  29:     0x71b5dbf68a90 - <<std[70002648da4681c1]::thread::Builder>::spawn_unchecked_<rustc_interface[cf66c2394d3c8572]::util::run_in_thread_with_globals<rustc_interface[cf66c2394d3c8572]::util::run_in_thread_pool_with_globals<rustc_interface[cf66c2394d3c8572]::interface::run_compiler<(), rustc_driver_impl[2cc745b14baadf]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>::{closure#1} as core[3b8d2fc2756ea0bb]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  30:     0x71b5dbf6a06f - std::sys::pal::unix::thread::Thread::new::thread_start::hdeaa41b2ac9b4ad7
  31:     0x71b5d60a339d - <unknown>
  32:     0x71b5d612849c - <unknown>
  33:                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.85.0-nightly (4790a435c 2024-12-15) running on x86_64-unknown-linux-gnu

query stack during panic:
#0 [typeck] type-checking `main`
#1 [analysis] running analysis passes on this crate
end of query stack
error: aborting due to 3 previous errors; 1 warning emitted

Some errors have detailed explanations: E0075, E0425, E0658.
For more information about an error, try `rustc --explain E0075`.

```

</p>
</details>

<!--
query stack:
#0 [typeck] type-checking `main`
#1 [analysis] running analysis passes on this crate

-->
@rustbot label +F-repr_simd +F-never_type