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: invalid shift: TryFromIntError(())', src/tools/clippy/clippy_utils/src/consts.rs:504:70 #9463

Closed
matthiaskrgr opened this issue Sep 11, 2022 · 0 comments · Fixed by #9464
Labels
C-bug Category: Clippy is not doing the correct thing I-ICE Issue: Clippy panicked, giving an Internal Compilation Error (ICE) ❄️

Comments

@matthiaskrgr
Copy link
Member

matthiaskrgr commented Sep 11, 2022

Summary

// build-fail
// compile-flags: -C debug-assertions

#![deny(arithmetic_overflow, const_err)] 
fn main() {
    let _x = -1_i32 >> -1;
    //~^ ERROR: this arithmetic operation will overflow
}

Version

No crash:

rustc 1.65.0-nightly (1d37ed661 2022-09-09)
binary: rustc
commit-hash: 1d37ed661a6922e7a167609b8cd7eb31e972b19b
commit-date: 2022-09-09
host: x86_64-unknown-linux-gnu
release: 1.65.0-nightly
LLVM version: 15.0.0

Crash:

rustc 1.65.0-nightly (4a6ac3c22 2022-09-10)
binary: rustc
commit-hash: 4a6ac3c225d6322caaf0ef86623cddc74e5260c6
commit-date: 2022-09-10
host: x86_64-unknown-linux-gnu
release: 1.65.0-nightly
LLVM version: 15.0.0

Error output

Backtrace

error: this arithmetic operation will overflow
--> ./overflowing-rsh-2.rs:6:14
|
6 |     let _x = -1_i32 >> -1;
|              ^^^^^^^^^^^^ attempt to shift right by `-1_i32`, which would overflow
|
note: the lint level is defined here
--> ./overflowing-rsh-2.rs:4:9
|
4 | #![deny(arithmetic_overflow, const_err)]
|         ^^^^^^^^^^^^^^^^^^^

thread 'rustc' panicked at 'invalid shift: TryFromIntError(())', src/tools/clippy/clippy_utils/src/consts.rs:504:70
stack backtrace:
 0:     0x7f0057666eb0 - std::backtrace_rs::backtrace::libunwind::trace::hffebe9af44a285ae
                             at /rustc/4a6ac3c225d6322caaf0ef86623cddc74e5260c6/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
 1:     0x7f0057666eb0 - std::backtrace_rs::backtrace::trace_unsynchronized::h5f1df8699f866a1e
                             at /rustc/4a6ac3c225d6322caaf0ef86623cddc74e5260c6/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
 2:     0x7f0057666eb0 - std::sys_common::backtrace::_print_fmt::hbf9548b95f55007f
                             at /rustc/4a6ac3c225d6322caaf0ef86623cddc74e5260c6/library/std/src/sys_common/backtrace.rs:66:5
 3:     0x7f0057666eb0 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h831e2cbc80659f2e
                             at /rustc/4a6ac3c225d6322caaf0ef86623cddc74e5260c6/library/std/src/sys_common/backtrace.rs:45:22
 4:     0x7f00576c1f0e - core::fmt::write::hcc48e1340092f7c6
                             at /rustc/4a6ac3c225d6322caaf0ef86623cddc74e5260c6/library/core/src/fmt/mod.rs:1202:17
 5:     0x7f0057657795 - std::io::Write::write_fmt::hd9759edc8b01704c
                             at /rustc/4a6ac3c225d6322caaf0ef86623cddc74e5260c6/library/std/src/io/mod.rs:1679:15
 6:     0x7f0057669b63 - std::sys_common::backtrace::_print::h2ef35ed3a5352698
                             at /rustc/4a6ac3c225d6322caaf0ef86623cddc74e5260c6/library/std/src/sys_common/backtrace.rs:48:5
 7:     0x7f0057669b63 - std::sys_common::backtrace::print::hbd1bd686e432b66e
                             at /rustc/4a6ac3c225d6322caaf0ef86623cddc74e5260c6/library/std/src/sys_common/backtrace.rs:35:9
 8:     0x7f0057669b63 - std::panicking::default_hook::{{closure}}::h027d49a2a365c05a
                             at /rustc/4a6ac3c225d6322caaf0ef86623cddc74e5260c6/library/std/src/panicking.rs:295:22
 9:     0x7f005766984f - std::panicking::default_hook::h79690a6d2a2c926d
                             at /rustc/4a6ac3c225d6322caaf0ef86623cddc74e5260c6/library/std/src/panicking.rs:314:9
10:     0x55582a374f6f - clippy_driver[dccc0ded73dd100c]::ICE_HOOK::{closure#0}::{closure#0}
11:     0x7f005766a39d - std::panicking::rust_panic_with_hook::h6e57e111267d9eb0
                             at /rustc/4a6ac3c225d6322caaf0ef86623cddc74e5260c6/library/std/src/panicking.rs:702:17
12:     0x7f005766a1f7 - std::panicking::begin_panic_handler::{{closure}}::h3180589f3d0529e4
                             at /rustc/4a6ac3c225d6322caaf0ef86623cddc74e5260c6/library/std/src/panicking.rs:588:13
13:     0x7f005766735c - std::sys_common::backtrace::__rust_end_short_backtrace::h7349f90c2a8b73b5
                             at /rustc/4a6ac3c225d6322caaf0ef86623cddc74e5260c6/library/std/src/sys_common/backtrace.rs:138:18
14:     0x7f0057669f12 - rust_begin_unwind
                             at /rustc/4a6ac3c225d6322caaf0ef86623cddc74e5260c6/library/std/src/panicking.rs:584:5
15:     0x7f00576beae3 - core::panicking::panic_fmt::h27e8e61c0d21bbc5
                             at /rustc/4a6ac3c225d6322caaf0ef86623cddc74e5260c6/library/core/src/panicking.rs:142:14
16:     0x7f00576bee63 - core::result::unwrap_failed::h1da2609a6bb91208
                             at /rustc/4a6ac3c225d6322caaf0ef86623cddc74e5260c6/library/core/src/result.rs:1785:5
17:     0x55582a7aee4a - <clippy_utils[56301b428e535c36]::consts::ConstEvalLateContext>::expr
18:     0x55582a7acc58 - clippy_utils[56301b428e535c36]::consts::constant_simple
19:     0x55582a57b7ad - <clippy_lints[5f9550c9315d01c1]::operators::arithmetic_side_effects::ArithmeticSideEffects as rustc_lint[495d3617f9379f45]::passes::LateLintPass>::check_expr
20:     0x7f005acbb824 - <rustc_lint[495d3617f9379f45]::early::EarlyLintPassObjects as rustc_lint[495d3617f9379f45]::passes::EarlyLintPass>::check_generic_arg
21:     0x7f0059f97713 - <rustc_lint[495d3617f9379f45]::late::LateContextAndPass<rustc_lint[495d3617f9379f45]::late::LateLintPassObjects> as rustc_hir[50804aaa44a1f98c]::intravisit::Visitor>::visit_expr
22:     0x7f0059f990eb - rustc_hir[50804aaa44a1f98c]::intravisit::walk_local::<rustc_lint[495d3617f9379f45]::late::LateContextAndPass<rustc_lint[495d3617f9379f45]::late::LateLintPassObjects>>
23:     0x7f0059f978ee - <rustc_lint[495d3617f9379f45]::late::LateContextAndPass<rustc_lint[495d3617f9379f45]::late::LateLintPassObjects> as rustc_hir[50804aaa44a1f98c]::intravisit::Visitor>::visit_local
24:     0x7f0059f9909a - rustc_hir[50804aaa44a1f98c]::intravisit::walk_block::<rustc_lint[495d3617f9379f45]::late::LateContextAndPass<rustc_lint[495d3617f9379f45]::late::LateLintPassObjects>>
25:     0x7f0059f97869 - <rustc_lint[495d3617f9379f45]::late::LateContextAndPass<rustc_lint[495d3617f9379f45]::late::LateLintPassObjects> as rustc_hir[50804aaa44a1f98c]::intravisit::Visitor>::visit_block
26:     0x7f0059f9771e - <rustc_lint[495d3617f9379f45]::late::LateContextAndPass<rustc_lint[495d3617f9379f45]::late::LateLintPassObjects> as rustc_hir[50804aaa44a1f98c]::intravisit::Visitor>::visit_expr
27:     0x7f0059f97bac - <rustc_lint[495d3617f9379f45]::late::LateContextAndPass<rustc_lint[495d3617f9379f45]::late::LateLintPassObjects> as rustc_hir[50804aaa44a1f98c]::intravisit::Visitor>::visit_nested_body
28:     0x7f0059f97dbe - <rustc_lint[495d3617f9379f45]::late::LateContextAndPass<rustc_lint[495d3617f9379f45]::late::LateLintPassObjects> as rustc_hir[50804aaa44a1f98c]::intravisit::Visitor>::visit_fn
29:     0x7f0059f9a74d - rustc_hir[50804aaa44a1f98c]::intravisit::walk_item::<rustc_lint[495d3617f9379f45]::late::LateContextAndPass<rustc_lint[495d3617f9379f45]::late::LateLintPassObjects>>
30:     0x7f0059f986ee - <rustc_lint[495d3617f9379f45]::late::LateContextAndPass<rustc_lint[495d3617f9379f45]::late::LateLintPassObjects> as rustc_hir[50804aaa44a1f98c]::intravisit::Visitor>::visit_nested_item
31:     0x7f0059f9a037 - rustc_hir[50804aaa44a1f98c]::intravisit::walk_mod::<rustc_lint[495d3617f9379f45]::late::LateContextAndPass<rustc_lint[495d3617f9379f45]::late::LateLintPassObjects>>
32:     0x7f0059f97633 - rustc_lint[495d3617f9379f45]::late::late_lint_pass_crate::<rustc_lint[495d3617f9379f45]::late::LateLintPassObjects>
33:     0x7f005920f621 - rustc_lint[495d3617f9379f45]::late::late_lint_crate::<rustc_lint[495d3617f9379f45]::BuiltinCombinedLateLintPass>
34:     0x7f005920dbd6 - <rustc_session[8dde2e4a2332595c]::session::Session>::time::<(), rustc_lint[495d3617f9379f45]::late::check_crate<rustc_lint[495d3617f9379f45]::BuiltinCombinedLateLintPass, rustc_interface[791128364b2744ed]::passes::analysis::{closure#5}::{closure#1}::{closure#2}::{closure#0}::{closure#0}>::{closure#0}::{closure#0}>
35:     0x7f005920dad9 - <rustc_session[8dde2e4a2332595c]::session::Session>::time::<(), rustc_interface[791128364b2744ed]::passes::analysis::{closure#5}::{closure#1}::{closure#2}::{closure#0}>
36:     0x7f005920d8cf - <core[2a038d950f9aeff9]::panic::unwind_safe::AssertUnwindSafe<rustc_interface[791128364b2744ed]::passes::analysis::{closure#5}::{closure#1}> as core[2a038d950f9aeff9]::ops::function::FnOnce<()>>::call_once
37:     0x7f005920ce9a - <rustc_session[8dde2e4a2332595c]::session::Session>::time::<(), rustc_interface[791128364b2744ed]::passes::analysis::{closure#5}>
38:     0x7f0059208fbc - rustc_interface[791128364b2744ed]::passes::analysis
39:     0x7f0059caa4fd - rustc_query_system[74c7bbb75199a8d3]::query::plumbing::try_execute_query::<rustc_query_impl[a1cd298c33c20aba]::plumbing::QueryCtxt, rustc_query_system[74c7bbb75199a8d3]::query::caches::DefaultCache<(), core[2a038d950f9aeff9]::result::Result<(), rustc_errors[7dea58b6bef02255]::ErrorGuaranteed>>>
40:     0x7f0059caa21c - rustc_query_system[74c7bbb75199a8d3]::query::plumbing::get_query::<rustc_query_impl[a1cd298c33c20aba]::queries::analysis, rustc_query_impl[a1cd298c33c20aba]::plumbing::QueryCtxt>
41:     0x7f0058caa297 - <rustc_interface[791128364b2744ed]::passes::QueryContext>::enter::<rustc_driver[a2213058975928eb]::run_compiler::{closure#1}::{closure#2}::{closure#3}, core[2a038d950f9aeff9]::result::Result<(), rustc_errors[7dea58b6bef02255]::ErrorGuaranteed>>
42:     0x7f0058c9dccc - rustc_interface[791128364b2744ed]::interface::create_compiler_and_run::<core[2a038d950f9aeff9]::result::Result<(), rustc_errors[7dea58b6bef02255]::ErrorGuaranteed>, rustc_driver[a2213058975928eb]::run_compiler::{closure#1}>
43:     0x7f0058c9c611 - <scoped_tls[87e0490d57c385e6]::ScopedKey<rustc_span[7677b77fc386f31]::SessionGlobals>>::set::<rustc_interface[791128364b2744ed]::interface::run_compiler<core[2a038d950f9aeff9]::result::Result<(), rustc_errors[7dea58b6bef02255]::ErrorGuaranteed>, rustc_driver[a2213058975928eb]::run_compiler::{closure#1}>::{closure#0}, core[2a038d950f9aeff9]::result::Result<(), rustc_errors[7dea58b6bef02255]::ErrorGuaranteed>>
44:     0x7f0058c9c2ff - std[1968192289ce0278]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[791128364b2744ed]::util::run_in_thread_pool_with_globals<rustc_interface[791128364b2744ed]::interface::run_compiler<core[2a038d950f9aeff9]::result::Result<(), rustc_errors[7dea58b6bef02255]::ErrorGuaranteed>, rustc_driver[a2213058975928eb]::run_compiler::{closure#1}>::{closure#0}, core[2a038d950f9aeff9]::result::Result<(), rustc_errors[7dea58b6bef02255]::ErrorGuaranteed>>::{closure#0}, core[2a038d950f9aeff9]::result::Result<(), rustc_errors[7dea58b6bef02255]::ErrorGuaranteed>>
45:     0x7f0059d41950 - <<std[1968192289ce0278]::thread::Builder>::spawn_unchecked_<rustc_interface[791128364b2744ed]::util::run_in_thread_pool_with_globals<rustc_interface[791128364b2744ed]::interface::run_compiler<core[2a038d950f9aeff9]::result::Result<(), rustc_errors[7dea58b6bef02255]::ErrorGuaranteed>, rustc_driver[a2213058975928eb]::run_compiler::{closure#1}>::{closure#0}, core[2a038d950f9aeff9]::result::Result<(), rustc_errors[7dea58b6bef02255]::ErrorGuaranteed>>::{closure#0}, core[2a038d950f9aeff9]::result::Result<(), rustc_errors[7dea58b6bef02255]::ErrorGuaranteed>>::{closure#1} as core[2a038d950f9aeff9]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
46:     0x7f0057674173 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::he6b603f20e9b52f6
                             at /rustc/4a6ac3c225d6322caaf0ef86623cddc74e5260c6/library/alloc/src/boxed.rs:1940:9
47:     0x7f0057674173 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h6e72292141abef13
                             at /rustc/4a6ac3c225d6322caaf0ef86623cddc74e5260c6/library/alloc/src/boxed.rs:1940:9
48:     0x7f0057674173 - std::sys::unix::thread::Thread::new::thread_start::h3f4ead44f8c04c46
                             at /rustc/4a6ac3c225d6322caaf0ef86623cddc74e5260c6/library/std/src/sys/unix/thread.rs:108:17
49:     0x7f00572ce78d - <unknown>
50:     0x7f005734f8e4 - clone
51:                0x0 - <unknown>

error: internal compiler error: unexpected panic

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

note: we would appreciate a bug report: https://github.com/rust-lang/rust-clippy/issues/new

note: Clippy version: clippy 0.1.65 (4a6ac3c 2022-09-10)

query stack during panic:
#0 [analysis] running analysis passes on this crate
end of query stack
error: aborting due to previous error

@matthiaskrgr matthiaskrgr added C-bug Category: Clippy is not doing the correct thing I-ICE Issue: Clippy panicked, giving an Internal Compilation Error (ICE) ❄️ labels Sep 11, 2022
bors added a commit that referenced this issue Sep 12, 2022
Don't panic on invalid shift while constfolding

Instead of panicking on invalid shifts while folding constants we simply give up. Fixes #9463

Notice the "attempt to shift right by `1316134912_u32`", which seems weird. AFAICS it comes from rustc itself.

changelog: none
@bors bors closed this as completed in 1e23c65 Sep 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: Clippy is not doing the correct thing I-ICE Issue: Clippy panicked, giving an Internal Compilation Error (ICE) ❄️
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant