rust-clippy icon indicating copy to clipboard operation
rust-clippy copied to clipboard

index out of bounds when compiling my os

Open jasondyoungberg opened this issue 1 year ago • 9 comments

Summary

Running cargo clippy on https://github.com/jasondyoungberg/my-os/tree/b1875e12124b634e9cb90b9d5cce4bb8b327826d causes an error

rustc-ice-2024-05-25T15_13_29-5792.txt

Version

rustc 1.80.0-nightly (36153f1a4 2024-05-24)
binary: rustc
commit-hash: 36153f1a4e3162f0a143c7b3e468ecb3beb0008e
commit-date: 2024-05-24
host: x86_64-pc-windows-msvc
release: 1.80.0-nightly
LLVM version: 18.1.6

Error output

Backtrace

cargo :    Compiling bootloader v0.11.7
At line:1 char:1
+ cargo clippy 2> log.txt
+ ~~~~~~~~~~~~~~~~~~~~~~~
  + CategoryInfo          : NotSpecified: (   Compiling bootloader v0.11.7:String) [], RemoteException
  + FullyQualifiedErrorId : NativeCommandError

 Compiling kernel v0.1.0 (C:\Users\jason\code\my-os\kernel)
WARN rustc_codegen_ssa::mir::locals Unexpected initial operand type: expected x86_64::structures::idt::InterruptStackFrame, found !.See 
<https://github.com/rust-lang/rust/issues/114858>.
thread 'rustc' panicked at /rustc/36153f1a4e3162f0a143c7b3e468ecb3beb0008e\compiler\rustc_codegen_ssa\src\mir\statement.rs:55:63:
index out of bounds: the len is 3 but the index is 3
stack backtrace:
 0:     0x7fff0ed33aed - std::backtrace_rs::backtrace::dbghelp64::trace
                             at /rustc/36153f1a4e3162f0a143c7b3e468ecb3beb0008e/library\std\src\..\..\backtrace\src\backtrace\dbghelp64.rs:91
 1:     0x7fff0ed33aed - std::backtrace_rs::backtrace::trace_unsynchronized
                             at /rustc/36153f1a4e3162f0a143c7b3e468ecb3beb0008e/library\std\src\..\..\backtrace\src\backtrace\mod.rs:66
 2:     0x7fff0ed33aed - std::sys_common::backtrace::_print_fmt
                             at /rustc/36153f1a4e3162f0a143c7b3e468ecb3beb0008e/library\std\src\sys_common\backtrace.rs:68
 3:     0x7fff0ed33aed - std::sys_common::backtrace::_print::impl$0::fmt
                             at /rustc/36153f1a4e3162f0a143c7b3e468ecb3beb0008e/library\std\src\sys_common\backtrace.rs:44
 4:     0x7fff0ed64a69 - core::fmt::rt::Argument::fmt
                             at /rustc/36153f1a4e3162f0a143c7b3e468ecb3beb0008e/library\core\src\fmt\rt.rs:165
 5:     0x7fff0ed64a69 - core::fmt::write
                             at /rustc/36153f1a4e3162f0a143c7b3e468ecb3beb0008e/library\core\src\fmt\mod.rs:1172
 6:     0x7fff0ed2a3c1 - std::io::Write::write_fmt<std::sys::pal::windows::stdio::Stderr>
                             at /rustc/36153f1a4e3162f0a143c7b3e468ecb3beb0008e/library\std\src\io\mod.rs:1835
 7:     0x7fff0ed338c6 - std::sys_common::backtrace::print
                             at /rustc/36153f1a4e3162f0a143c7b3e468ecb3beb0008e/library\std\src\sys_common\backtrace.rs:34
 8:     0x7fff0ed36a98 - std::panicking::default_hook::closure$1
                             at /rustc/36153f1a4e3162f0a143c7b3e468ecb3beb0008e/library\std\src\panicking.rs:271
 9:     0x7fff0ed36746 - std::panicking::default_hook
                             at /rustc/36153f1a4e3162f0a143c7b3e468ecb3beb0008e/library\std\src\panicking.rs:298
10:     0x7ffefd62cecc - memchr
11:     0x7fff0ed370c7 - alloc::boxed::impl$50::call
                             at /rustc/36153f1a4e3162f0a143c7b3e468ecb3beb0008e/library\alloc\src\boxed.rs:2077
12:     0x7fff0ed370c7 - std::panicking::rust_panic_with_hook
                             at /rustc/36153f1a4e3162f0a143c7b3e468ecb3beb0008e/library\std\src\panicking.rs:799
13:     0x7fff0ed36f57 - std::panicking::begin_panic_handler::closure$0
                             at /rustc/36153f1a4e3162f0a143c7b3e468ecb3beb0008e/library\std\src\panicking.rs:664
14:     0x7fff0ed3445f - std::sys_common::backtrace::__rust_end_short_backtrace<std::panicking::begin_panic_handler::closure_env$0,never$>
                             at /rustc/36153f1a4e3162f0a143c7b3e468ecb3beb0008e/library\std\src\sys_common\backtrace.rs:171
15:     0x7fff0ed36c08 - std::panicking::begin_panic_handler
                             at /rustc/36153f1a4e3162f0a143c7b3e468ecb3beb0008e/library\std\src\panicking.rs:652
16:     0x7fff0ed8e3c4 - core::panicking::panic_fmt
                             at /rustc/36153f1a4e3162f0a143c7b3e468ecb3beb0008e/library\core\src\panicking.rs:72
17:     0x7fff0ed8e5be - core::panicking::panic_bounds_check
                             at /rustc/36153f1a4e3162f0a143c7b3e468ecb3beb0008e/library\core\src\panicking.rs:274
18:     0x7ffefc2d3829 - <rustc_interface[3b2f34fc053ae530]::passes::LintStoreExpandImpl as 
rustc_expand[638ba64908faf932]::base::LintStoreExpand>::pre_expansion_lint
19:     0x7ffefc324cf3 - <rustc_target[33c3778ab090726f]::abi::call::FnAbi<rustc_middle[da93cb5b5717e1e9]::ty::Ty> as 
rustc_codegen_llvm[cdc59ea1597e007a]::abi::FnAbiLlvmExt>::apply_attrs_callsite
20:     0x7ffef9529507 - llvm::DenseMap<llvm::StructType * 
__ptr64,llvm::detail::DenseSetEmpty,llvm::IRMover::StructTypeKeyInfo,llvm::detail::DenseSetPair<llvm::StructType * __ptr64> >::~DenseMap<llvm::StructType 
* __ptr64,llvm::detail::DenseSetEmpty,llvm::IRMover::StructTypeKeyI
21:     0x7ffef958e5ac - <rustc_codegen_llvm[cdc59ea1597e007a]::LlvmCodegenBackend as 
rustc_codegen_ssa[b8f77a53df86994d]::traits::backend::ExtraBackendMethods>::compile_codegen_unit
22:     0x7ffef9511802 - llvm::DenseMap<llvm::StructType * 
__ptr64,llvm::detail::DenseSetEmpty,llvm::IRMover::StructTypeKeyInfo,llvm::detail::DenseSetPair<llvm::StructType * __ptr64> >::~DenseMap<llvm::StructType 
* __ptr64,llvm::detail::DenseSetEmpty,llvm::IRMover::StructTypeKeyI
23:     0x7ffef95910f1 - <rustc_codegen_llvm[cdc59ea1597e007a]::LlvmCodegenBackend as 
rustc_codegen_ssa[b8f77a53df86994d]::traits::backend::CodegenBackend>::codegen_crate
24:     0x7ffef94daab3 - rustc_interface[3b2f34fc053ae530]::passes::start_codegen
25:     0x7ffef94e3c60 - <rustc_interface[3b2f34fc053ae530]::queries::Queries>::codegen_and_build_linker
26:     0x7ffef9493c2e - llvm::function_ref<void __cdecl(llvm::Value const * 
__ptr64)>::callback_fn<`llvm::Value::stripInBoundsOffsets'::`1'::<lambda_1_1> >
27:     0x7ffef9490def - llvm::function_ref<void __cdecl(llvm::Value const * 
__ptr64)>::callback_fn<`llvm::Value::stripInBoundsOffsets'::`1'::<lambda_1_1> >
28:     0x7ffef9498c49 - llvm::function_ref<void __cdecl(llvm::Value const * 
__ptr64)>::callback_fn<`llvm::Value::stripInBoundsOffsets'::`1'::<lambda_1_1> >
29:     0x7fff0ed4811d - alloc::boxed::impl$48::call_once
                             at /rustc/36153f1a4e3162f0a143c7b3e468ecb3beb0008e/library\alloc\src\boxed.rs:2063
30:     0x7fff0ed4811d - alloc::boxed::impl$48::call_once
                             at /rustc/36153f1a4e3162f0a143c7b3e468ecb3beb0008e/library\alloc\src\boxed.rs:2063
31:     0x7fff0ed4811d - std::sys::pal::windows::thread::impl$0::new::thread_start
                             at /rustc/36153f1a4e3162f0a143c7b3e468ecb3beb0008e/library\std\src\sys\pal\windows\thread.rs:52
32:     0x7fffdc76257d - BaseThreadInitThunk
33:     0x7fffdccaaa48 - RtlUserThreadStart

error: the compiler unexpectedly panicked. this is a bug.

note: we would appreciate a bug report: https://github.com/rust-lang/rust-clippy/issues/new?template=ice.yml

note: please make sure that you have updated to the latest nightly

note: please attach the file at `C:\Users\jason\code\my-os\rustc-ice-2024-05-25T15_13_29-5792.txt` to your bug report

note: compiler flags: --crate-type bin -C embed-bitcode=no -C debuginfo=2 -C incremental=[REDACTED]

note: some of the compiler flags provided by cargo are hidden

query stack during panic:
end of query stack
note: Clippy version: clippy 0.1.80 (36153f1a 2024-05-24)

error: could not compile `kernel` (bin "kernel")
warning: build failed, waiting for other jobs to finish...

jasondyoungberg avatar May 25 '24 15:05 jasondyoungberg

I've also tested some different versions, it looks like the error was introduced in nightly-2024-04-13.

nightly-2024-05-25: crash nightly-2024-05-24: crash nightly-2024-05-10: crash nightly-2024-05-01: crash nightly-2024-04-20: crash nightly-2024-04-16: crash nightly-2024-04-13: crash nightly-2024-04-12: success nightly-2024-04-11: success

jasondyoungberg avatar May 25 '24 15:05 jasondyoungberg

I don't think this is a clippy issue but rather a rustc issue, @blyxyas @y21 what do you think?

ghost avatar May 25 '24 19:05 ghost

Does this also happen with cargo check? That would give us a good lead :heart:

blyxyas avatar May 27 '24 16:05 blyxyas

Does this also happen with cargo check? That would give us a good lead ❤️

No, just clippy

jasondyoungberg avatar May 27 '24 18:05 jasondyoungberg

FWIW, this looks very similar to #12676, as well as the upstream issue rust-lang/rust#124375. With RUSTC_LOG=debug it looks like the crash happens while codegen'ing breakpoint_handler, which does look suspiciously similar to the code in the rustc issue, so might be related. The bisection above also matches with the date when those two issues were filed.

Seems very strange that this only happens in clippy. I also have no idea why clippy would want to touch the codegen backend like the backtrace suggests with the llvm frames. I sadly don't have time to properly investigate atm though..

y21 avatar May 27 '24 18:05 y21

Iirc in the flame graph @blyxyas shared on zulip in the bolt optimisations topic (https://rust-lang.zulipchat.com/user_uploads/4715/KEypA_Br149UjxNwduPDnfMN/image.png), some codegen is invoked before clippy executes, but the fact that cargo check — which is supposed to run the same initial steps — doesn't ICE is weird.

I will try to look more into this.

ghost avatar May 28 '24 10:05 ghost

IIRC Clippy disables MIR optimizations when running so codegen would be different than cargo check.

Jarcho avatar Sep 12 '24 15:09 Jarcho

@jasondyoungberg Is this still happening with Nightly Clippy? I've tried reproducing it and it seems that the commit you linked has some toolchain issues when removing the rust-toolchain file (which is necessary to know if nightly still ICEs)

blyxyas avatar Oct 01 '24 21:10 blyxyas

Removing the rust-toolchain and running cargo +nightly -Z bindeps clippy still ICEs

jasondyoungberg avatar Oct 05 '24 19:10 jasondyoungberg

After patching the code to compile this no longer occurs on 2025-01-11.

Jarcho avatar Mar 09 '25 15:03 Jarcho