Panic on `std::f64::<impl f64>::log2`
Opened this issue · 1 comments
Issue
MIRAI panics when std::f64::<impl f64>::log2
is met.
I encountered this issue while analyzing Artichoke, more specifically its spinoso-math module.
However, it can be reproduced by the following simple code:
fn log2(value: f64) -> f64 {
value.log2()
}
fn main() {
println!("Hello, {}!", log2(2.0));
}
I suspect this is due to the fact that log functions are wrapped (https://github.com/rust-lang/rust/blob/10a98e8bff0b1335e7f0f1ea0453ee0765ae96fe/library/std/src/sys/mod.rs#L95):
#[cfg(not(test))]
#[cfg(not(any(target_os = "solaris", target_os = "illumos")))]
#[inline]
pub fn log_wrapper<F: Fn(f64) -> f64>(n: f64, log_fn: F) -> f64 {
log_fn(n)
}
because MIRAI tries to run a log function on the function itself, believing that it is a type error.
Steps to Reproduce
Create a new project with main.rs
:
fn log2(value: f64) -> f64 {
value.log2()
}
fn main() {
println!("Hello, {}!", log2(2.0));
}
and run
RUSTC_WRAPPER=../MIRAI/target/debug/mirai cargo build
Expected Behavior
Analyze it without panicking.
Actual Results
It panics:
Compiling test-log2f64 v0.1.0 (/Users/jay/Developer/RustProjects/benchmark/contrib/test-log2f64)
thread 'rustc' panicked at checker/src/constant_domain.rs:667:18:
internal error: entered unreachable code: invalid argument for intrinsic StdIntrinsicsLog2f64
stack backtrace:
0: 0x1066d70c4 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h2e9954773bfb0d12
1: 0x10672ace0 - core::fmt::write::h362ae95ace996b8b
2: 0x1066cca40 - std::io::Write::write_fmt::h5cbcacf0a52b50a3
3: 0x1066d6f04 - std::sys_common::backtrace::print::he8c5c5298b85adc1
4: 0x1066d9c78 - std::panicking::panic_hook_with_disk_dump::{{closure}}::hdb4ce58c9cadc802
5: 0x1066d9978 - std::panicking::panic_hook_with_disk_dump::h493c10eb8f8ae921
6: 0x10eba903c - rustc_driver_impl[f519250b47aaf4da]::install_ice_hook::{closure#0}
7: 0x1066da488 - std::panicking::rust_panic_with_hook::h3e3a3c0b72b094d6
8: 0x1066da250 - std::panicking::begin_panic_handler::{{closure}}::hf656d590e2bebbae
9: 0x1066d7550 - std::sys_common::backtrace::__rust_end_short_backtrace::hbff5da812bf097a7
10: 0x1066d9fac - _rust_begin_unwind
11: 0x106755e80 - core::panicking::panic_fmt::h372a6717d900bfe9
12: 0x1010741f0 - mirai::constant_domain::ConstantDomain::intrinsic_floating_point_unary::hbaf39fcfa1ec556f
at /Users/jay/Developer/RustProjects/benchmark/contrib/MIRAI/checker/src/constant_domain.rs:667:18
13: 0x100fdf3c0 - <alloc::rc::Rc<mirai::abstract_value::AbstractValue> as mirai::abstract_value::AbstractValueTrait>::intrinsic_floating_point_unary::h08e04e6700852e62
at /Users/jay/Developer/RustProjects/benchmark/contrib/MIRAI/checker/src/abstract_value.rs:3292:30
14: 0x100ff11c8 - <alloc::rc::Rc<mirai::abstract_value::AbstractValue> as mirai::abstract_value::AbstractValueTrait>::refine_parameters_and_paths::h8fa96ae44ced2b34
at /Users/jay/Developer/RustProjects/benchmark/contrib/MIRAI/checker/src/abstract_value.rs:6122:74
15: 0x101043aa0 - mirai::body_visitor::BodyVisitor::transfer_and_refine::h5b6524dec5df4be9
at /Users/jay/Developer/RustProjects/benchmark/contrib/MIRAI/checker/src/body_visitor.rs:1211:30
16: 0x100ecfe6c - mirai::call_visitor::CallVisitor::transfer_and_refine_normal_return_state::haca2e61bb35fc151
at /Users/jay/Developer/RustProjects/benchmark/contrib/MIRAI/checker/src/call_visitor.rs:2929:13
17: 0x100ecdfec - mirai::call_visitor::CallVisitor::transfer_and_refine_into_current_environment::hd058eafbe61ade06
at /Users/jay/Developer/RustProjects/benchmark/contrib/MIRAI/checker/src/call_visitor.rs:2580:9
18: 0x10109cf00 - mirai::block_visitor::BlockVisitor::visit_call::h0de2be9b90c3e153
at /Users/jay/Developer/RustProjects/benchmark/contrib/MIRAI/checker/src/block_visitor.rs:766:13
19: 0x101099524 - mirai::block_visitor::BlockVisitor::visit_terminator::h32eb141d992b789b
at /Users/jay/Developer/RustProjects/benchmark/contrib/MIRAI/checker/src/block_visitor.rs:311:18
20: 0x101097a14 - mirai::block_visitor::BlockVisitor::visit_basic_block::h572cedf80e54d46e
at /Users/jay/Developer/RustProjects/benchmark/contrib/MIRAI/checker/src/block_visitor.rs:105:13
21: 0x100e89f38 - mirai::fixed_point_visitor::FixedPointVisitor::visit_basic_block::h06033db9f37b6b26
at /Users/jay/Developer/RustProjects/benchmark/contrib/MIRAI/checker/src/fixed_point_visitor.rs:130:9
22: 0x100e898f8 - mirai::fixed_point_visitor::FixedPointVisitor::visit_blocks::hd8355ec349109012
at /Users/jay/Developer/RustProjects/benchmark/contrib/MIRAI/checker/src/fixed_point_visitor.rs:82:21
23: 0x10103cae0 - mirai::body_visitor::BodyVisitor::visit_body::ha1c8625aaaeeda2d
at /Users/jay/Developer/RustProjects/benchmark/contrib/MIRAI/checker/src/body_visitor.rs:217:9
24: 0x100ebb950 - mirai::call_visitor::CallVisitor::create_and_cache_function_summary::h0eb78b1df418f415
at /Users/jay/Developer/RustProjects/benchmark/contrib/MIRAI/checker/src/call_visitor.rs:141:31
25: 0x100ebdab0 - mirai::call_visitor::CallVisitor::get_function_summary::h25beec6b84c3510e
at /Users/jay/Developer/RustProjects/benchmark/contrib/MIRAI/checker/src/call_visitor.rs:382:21
26: 0x10109cd64 - mirai::block_visitor::BlockVisitor::visit_call::h0de2be9b90c3e153
at /Users/jay/Developer/RustProjects/benchmark/contrib/MIRAI/checker/src/block_visitor.rs:736:32
27: 0x101099524 - mirai::block_visitor::BlockVisitor::visit_terminator::h32eb141d992b789b
at /Users/jay/Developer/RustProjects/benchmark/contrib/MIRAI/checker/src/block_visitor.rs:311:18
28: 0x101097a14 - mirai::block_visitor::BlockVisitor::visit_basic_block::h572cedf80e54d46e
at /Users/jay/Developer/RustProjects/benchmark/contrib/MIRAI/checker/src/block_visitor.rs:105:13
29: 0x100e89f38 - mirai::fixed_point_visitor::FixedPointVisitor::visit_basic_block::h06033db9f37b6b26
at /Users/jay/Developer/RustProjects/benchmark/contrib/MIRAI/checker/src/fixed_point_visitor.rs:130:9
30: 0x100e898f8 - mirai::fixed_point_visitor::FixedPointVisitor::visit_blocks::hd8355ec349109012
at /Users/jay/Developer/RustProjects/benchmark/contrib/MIRAI/checker/src/fixed_point_visitor.rs:82:21
31: 0x10103cae0 - mirai::body_visitor::BodyVisitor::visit_body::ha1c8625aaaeeda2d
at /Users/jay/Developer/RustProjects/benchmark/contrib/MIRAI/checker/src/body_visitor.rs:217:9
32: 0x100ebb950 - mirai::call_visitor::CallVisitor::create_and_cache_function_summary::h0eb78b1df418f415
at /Users/jay/Developer/RustProjects/benchmark/contrib/MIRAI/checker/src/call_visitor.rs:141:31
33: 0x100ebdab0 - mirai::call_visitor::CallVisitor::get_function_summary::h25beec6b84c3510e
at /Users/jay/Developer/RustProjects/benchmark/contrib/MIRAI/checker/src/call_visitor.rs:382:21
34: 0x10109cd64 - mirai::block_visitor::BlockVisitor::visit_call::h0de2be9b90c3e153
at /Users/jay/Developer/RustProjects/benchmark/contrib/MIRAI/checker/src/block_visitor.rs:736:32
35: 0x101099524 - mirai::block_visitor::BlockVisitor::visit_terminator::h32eb141d992b789b
at /Users/jay/Developer/RustProjects/benchmark/contrib/MIRAI/checker/src/block_visitor.rs:311:18
36: 0x101097a14 - mirai::block_visitor::BlockVisitor::visit_basic_block::h572cedf80e54d46e
at /Users/jay/Developer/RustProjects/benchmark/contrib/MIRAI/checker/src/block_visitor.rs:105:13
37: 0x100e89f38 - mirai::fixed_point_visitor::FixedPointVisitor::visit_basic_block::h06033db9f37b6b26
at /Users/jay/Developer/RustProjects/benchmark/contrib/MIRAI/checker/src/fixed_point_visitor.rs:130:9
38: 0x100e898f8 - mirai::fixed_point_visitor::FixedPointVisitor::visit_blocks::hd8355ec349109012
at /Users/jay/Developer/RustProjects/benchmark/contrib/MIRAI/checker/src/fixed_point_visitor.rs:82:21
39: 0x10103cae0 - mirai::body_visitor::BodyVisitor::visit_body::ha1c8625aaaeeda2d
at /Users/jay/Developer/RustProjects/benchmark/contrib/MIRAI/checker/src/body_visitor.rs:217:9
40: 0x100e8df24 - mirai::crate_visitor::CrateVisitor::analyze_body::{{closure}}::ha294e3e8adeb2738
at /Users/jay/Developer/RustProjects/benchmark/contrib/MIRAI/checker/src/crate_visitor.rs:185:23
41: 0x100e8424c - mirai::crate_visitor::CrateVisitor::analyze_body::hd49743381c0c135c
at /Users/jay/Developer/RustProjects/benchmark/contrib/MIRAI/checker/src/crate_visitor.rs:173:5
42: 0x100e8d66c - mirai::crate_visitor::CrateVisitor::analyze_some_bodies::{{closure}}::h1662b2539d623381
at /Users/jay/Developer/RustProjects/benchmark/contrib/MIRAI/checker/src/crate_visitor.rs:127:13
43: 0x100e83e4c - mirai::crate_visitor::CrateVisitor::analyze_some_bodies::h7937093482ce1f29
at /Users/jay/Developer/RustProjects/benchmark/contrib/MIRAI/checker/src/crate_visitor.rs:71:5
44: 0x100f0aafc - mirai::callbacks::MiraiCallbacks::analyze_with_mirai::{{closure}}::h43f94abecba15127
at /Users/jay/Developer/RustProjects/benchmark/contrib/MIRAI/checker/src/callbacks.rs:172:9
45: 0x10102b068 - mirai::callbacks::MiraiCallbacks::analyze_with_mirai::hacaab8748300ed7f
at /Users/jay/Developer/RustProjects/benchmark/contrib/MIRAI/checker/src/callbacks.rs:131:5
46: 0x100f0a3b0 - <mirai::callbacks::MiraiCallbacks as rustc_driver_impl::Callbacks>::after_analysis::{{closure}}::{{closure}}::ha48d9fd1f75db12c
at /Users/jay/Developer/RustProjects/benchmark/contrib/MIRAI/checker/src/callbacks.rs:118:26
47: 0x10115b1c0 - rustc_middle::ty::context::GlobalCtxt::enter::{{closure}}::h27d37b6a0d4891df
at /rustc/8ed4537d7c238eb77509d82445cf1cb861a3b5ff/compiler/rustc_middle/src/ty/context.rs:595:37
48: 0x1010b89e0 - rustc_middle::ty::context::tls::enter_context::{{closure}}::hd38dbaa3d9a43a08
at /rustc/8ed4537d7c238eb77509d82445cf1cb861a3b5ff/compiler/rustc_middle/src/ty/context/tls.rs:82:9
49: 0x1010631b4 - std::thread::local::LocalKey<T>::try_with::h3da8fa328efeb3e8
at /rustc/8ed4537d7c238eb77509d82445cf1cb861a3b5ff/library/std/src/thread/local.rs:270:16
50: 0x10115b14c - std::thread::local::LocalKey<T>::with::h785ab93035ec42a8
at /rustc/8ed4537d7c238eb77509d82445cf1cb861a3b5ff/library/std/src/thread/local.rs:246:9
51: 0x10115b14c - rustc_middle::ty::context::tls::enter_context::h6fd5ca8e1894b838
at /rustc/8ed4537d7c238eb77509d82445cf1cb861a3b5ff/compiler/rustc_middle/src/ty/context/tls.rs:79:9
52: 0x10115b14c - rustc_middle::ty::context::GlobalCtxt::enter::h771528b25d90c769
at /rustc/8ed4537d7c238eb77509d82445cf1cb861a3b5ff/compiler/rustc_middle/src/ty/context.rs:595:9
53: 0x100f9a2a8 - rustc_interface::queries::QueryResult<&rustc_middle::ty::context::GlobalCtxt>::enter::he6b254f3b5c58e04
at /rustc/8ed4537d7c238eb77509d82445cf1cb861a3b5ff/compiler/rustc_interface/src/queries.rs:71:9
54: 0x100f0a30c - <mirai::callbacks::MiraiCallbacks as rustc_driver_impl::Callbacks>::after_analysis::{{closure}}::hebffbd5da728d3d8
at /Users/jay/Developer/RustProjects/benchmark/contrib/MIRAI/checker/src/callbacks.rs:115:9
55: 0x10102af34 - <mirai::callbacks::MiraiCallbacks as rustc_driver_impl::Callbacks>::after_analysis::h55363b1d0091c115
at /Users/jay/Developer/RustProjects/benchmark/contrib/MIRAI/checker/src/callbacks.rs:98:5
56: 0x10ebca9d4 - <rustc_interface[3f9b0856dc8a1b35]::interface::Compiler>::enter::<rustc_driver_impl[f519250b47aaf4da]::run_compiler::{closure#1}::{closure#2}, core[35629bdc4bb5a94b]::result::Result<core[35629bdc4bb5a94b]::option::Option<rustc_interface[3f9b0856dc8a1b35]::queries::Linker>, rustc_span[b75a20f38cbca3e5]::ErrorGuaranteed>>
57: 0x10ebeb85c - std[ab688d881d6d7b60]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[3f9b0856dc8a1b35]::util::run_in_thread_with_globals<rustc_interface[3f9b0856dc8a1b35]::interface::run_compiler<core[35629bdc4bb5a94b]::result::Result<(), rustc_span[b75a20f38cbca3e5]::ErrorGuaranteed>, rustc_driver_impl[f519250b47aaf4da]::run_compiler::{closure#1}>::{closure#0}, core[35629bdc4bb5a94b]::result::Result<(), rustc_span[b75a20f38cbca3e5]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[35629bdc4bb5a94b]::result::Result<(), rustc_span[b75a20f38cbca3e5]::ErrorGuaranteed>>
58: 0x10ebed604 - <<std[ab688d881d6d7b60]::thread::Builder>::spawn_unchecked_<rustc_interface[3f9b0856dc8a1b35]::util::run_in_thread_with_globals<rustc_interface[3f9b0856dc8a1b35]::interface::run_compiler<core[35629bdc4bb5a94b]::result::Result<(), rustc_span[b75a20f38cbca3e5]::ErrorGuaranteed>, rustc_driver_impl[f519250b47aaf4da]::run_compiler::{closure#1}>::{closure#0}, core[35629bdc4bb5a94b]::result::Result<(), rustc_span[b75a20f38cbca3e5]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[35629bdc4bb5a94b]::result::Result<(), rustc_span[b75a20f38cbca3e5]::ErrorGuaranteed>>::{closure#1} as core[35629bdc4bb5a94b]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
59: 0x1066e3204 - std::sys::unix::thread::Thread::new::thread_start::h9678d3dce1b2bcfc
60: 0x18bb2f034 - __pthread_joiner_wake
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 attach the file at `/Users/jay/Developer/RustProjects/benchmark/contrib/test-log2f64/rustc-ice-2023-11-19T12:21:28.052305Z-40969.txt` to your bug report
note: compiler flags: --crate-type bin -C embed-bitcode=no -C debuginfo=2 -C split-debuginfo=unpacked -C incremental=[REDACTED]
note: some of the compiler flags provided by cargo are hidden
query stack during panic:
end of query stack
error: could not compile `test-log2f64` (bin "test-log2f64")
Environment
OS: macOS Sonoma 14.0
CPU: Apple M1 Pro
Rust version (rustc 1.74.0-nightly (8ed4537d7 2023-09-09))
MIRAI: a94a8c7 (the most recent version)
The MWE can be as simple as
fn main() {
2.0f64.log2();
}
It's somehow refining (old(param_1): F64).StdIntrinsicsLog2f64()
(which corresponds to value.log2()
) into (&(param_2)).StdIntrinsicsLog2f64()
(which probably corresponds to log2.log2()
), and this doesn't seem right...
[2023-11-19T14:38:38Z DEBUG mirai::abstract_value] refine_parameters_and_paths(self: (old(param_1): F64).StdIntrinsicsLog2f64(),args: [(&(param_2), &(param_2)), (local_4(7).0, old(param_1): F64)],result: Some(result),pre_env: {param_2.func: DefId(1:10805 ~ std[ab68]::sys::log2f64), local_4(7).0: old(param_1): F64, param_1: old(param_1): F64, local_3(5): &(param_2)},post_env: {param_2.func: DefId(1:10805 ~ std[ab68]::sys::log2f64), local_4(7).0: old(param_1): F64, param_1: old(param_1): F64, local_3(5): &(param_2)},fresh: 2000000)
[2023-11-19T14:38:38Z DEBUG mirai::abstract_value] refine_parameters_and_paths(self: old(param_1): F64,args: [(&(param_2), &(param_2)), (local_4(7).0, old(param_1): F64)],result: Some(result),pre_env: {param_2.func: DefId(1:10805 ~ std[ab68]::sys::log2f64), local_4(7).0: old(param_1): F64, param_1: old(param_1): F64, local_3(5): &(param_2)},post_env: {param_2.func: DefId(1:10805 ~ std[ab68]::sys::log2f64), local_4(7).0: old(param_1): F64, param_1: old(param_1): F64, local_3(5): &(param_2)},fresh: 2000000)
[2023-11-19T14:38:38Z DEBUG mirai::abstract_value] refining InitialParameterValue param_1 F64
[2023-11-19T14:38:38Z DEBUG mirai::path] refine_parameters_and_paths(self: param_1,args: [(&(param_2), &(param_2)), (local_4(7).0, old(param_1): F64)],result: Some(result),pre_env: {param_2.func: DefId(1:10805 ~ std[ab68]::sys::log2f64), local_4(7).0: old(param_1): F64, param_1: old(param_1): F64, local_3(5): &(param_2)},post_env: {param_2.func: DefId(1:10805 ~ std[ab68]::sys::log2f64), local_4(7).0: old(param_1): F64, param_1: old(param_1): F64, local_3(5): &(param_2)},fresh: 2000000)
[2023-11-19T14:38:38Z DEBUG mirai::abstract_value] refine_parameters_and_paths() => &(param_2)
[2023-11-19T14:38:38Z INFO mirai::abstract_value] intrinsic_floating_point_unary(self: &(param_2),name: StdIntrinsicsLog2f64)
[2023-11-19T14:38:38Z DEBUG mirai::abstract_value] refine_parameters_and_paths() => (&(param_2)).StdIntrinsicsLog2f64()