Skip to content

ICE: Kani crashes when there's an access to SIMD field in a generic context #2659

Closed

Description

@celinval

I tried this code:

// simd.rs
#![feature(portable_simd, repr_simd)]

use std::simd::SimdElement;

mod array_based {
    use super::*;

    #[repr(simd)]
    struct CustomSimd<T: SimdElement, const LANES: usize>([T; LANES]);

    fn check_fields<T: SimdElement + PartialEq, const LANES: usize>(
        simd: CustomSimd<T, LANES>,
        expected: [T; LANES],
    ) {
        assert_eq!(simd.0, expected);
    }

    #[kani::proof]
    fn check_field_access() {
        let data: [u8; 16] = kani::any();
        let vec = CustomSimd(data.clone());
        check_fields(vec, data);
    }
}

using the following command line invocation:

kani simd.rs

with Kani version: 0.33.0 (dev)

I expected to see this happen: Verification should succeed

Instead, this happened: Kani compiler crashed.

edit: Backtrace
Kani Rust Verifier 0.33.0 (standalone)
thread 'rustc' panicked at 'internal error: entered unreachable code: monomorphization bug', kani-compiler/src/codegen_cprover_gotoc/codegen/typ.rs:816:47
stack backtrace:
   0: rust_begin_unwind
             at /rustc/f4b80cacf93ca216c75f6ae12f4b9dec19eba42f/library/std/src/panicking.rs:593:5
   1: core::panicking::panic_fmt
             at /rustc/f4b80cacf93ca216c75f6ae12f4b9dec19eba42f/library/core/src/panicking.rs:67:14
   2: kani_compiler::codegen_cprover_gotoc::codegen::typ::<impl kani_compiler::codegen_cprover_gotoc::context::goto_ctx::GotocCtx>::codegen_ty_inner
             at /workspace/kani-project/kani/kani-compiler/src/codegen_cprover_gotoc/codegen/typ.rs:816:47
   3: kani_compiler::codegen_cprover_gotoc::codegen::typ::<impl kani_compiler::codegen_cprover_gotoc::context::goto_ctx::GotocCtx>::codegen_ty
             at /workspace/kani-project/kani/kani-compiler/src/codegen_cprover_gotoc/codegen/typ.rs:741:24
   4: kani_compiler::codegen_cprover_gotoc::codegen::typ::<impl kani_compiler::codegen_cprover_gotoc::context::goto_ctx::GotocCtx>::codegen_ty_raw_array
             at /workspace/kani-project/kani/kani-compiler/src/codegen_cprover_gotoc/codegen/typ.rs:687:21
   5: kani_compiler::codegen_cprover_gotoc::codegen::typ::<impl kani_compiler::codegen_cprover_gotoc::context::goto_ctx::GotocCtx>::codegen_ty_inner
             at /workspace/kani-project/kani/kani-compiler/src/codegen_cprover_gotoc/codegen/typ.rs:774:35
   6: kani_compiler::codegen_cprover_gotoc::codegen::typ::<impl kani_compiler::codegen_cprover_gotoc::context::goto_ctx::GotocCtx>::codegen_ty
             at /workspace/kani-project/kani/kani-compiler/src/codegen_cprover_gotoc/codegen/typ.rs:741:24
   7: kani_compiler::codegen_cprover_gotoc::codegen::place::<impl kani_compiler::codegen_cprover_gotoc::context::goto_ctx::GotocCtx>::codegen_simd_field
             at /workspace/kani-project/kani/kani-compiler/src/codegen_cprover_gotoc/codegen/place.rs:346:29
   8: kani_compiler::codegen_cprover_gotoc::codegen::place::<impl kani_compiler::codegen_cprover_gotoc::context::goto_ctx::GotocCtx>::codegen_field
             at /workspace/kani-project/kani/kani-compiler/src/codegen_cprover_gotoc/codegen/place.rs:273:64
   9: kani_compiler::codegen_cprover_gotoc::codegen::place::<impl kani_compiler::codegen_cprover_gotoc::context::goto_ctx::GotocCtx>::codegen_projection
             at /workspace/kani-project/kani/kani-compiler/src/codegen_cprover_gotoc/codegen/place.rs:476:21
  10: kani_compiler::codegen_cprover_gotoc::codegen::place::<impl kani_compiler::codegen_cprover_gotoc::context::goto_ctx::GotocCtx>::codegen_place::{{closure}}
             at /workspace/kani-project/kani/kani-compiler/src/codegen_cprover_gotoc/codegen/place.rs:665:53
  11: core::iter::adapters::copied::copy_fold::{{closure}}
             at /rustc/f4b80cacf93ca216c75f6ae12f4b9dec19eba42f/library/core/src/iter/adapters/copied.rs:32:22
  12: <core::slice::iter::Iter<T> as core::iter::traits::iterator::Iterator>::fold
             at /rustc/f4b80cacf93ca216c75f6ae12f4b9dec19eba42f/library/core/src/slice/iter/macros.rs:215:27
  13: <core::iter::adapters::copied::Copied<I> as core::iter::traits::iterator::Iterator>::fold
             at /rustc/f4b80cacf93ca216c75f6ae12f4b9dec19eba42f/library/core/src/iter/adapters/copied.rs:77:9
  14: kani_compiler::codegen_cprover_gotoc::codegen::place::<impl kani_compiler::codegen_cprover_gotoc::context::goto_ctx::GotocCtx>::codegen_place
             at /workspace/kani-project/kani/kani-compiler/src/codegen_cprover_gotoc/codegen/place.rs:662:22
  15: kani_compiler::codegen_cprover_gotoc::codegen::place::<impl kani_compiler::codegen_cprover_gotoc::context::goto_ctx::GotocCtx>::codegen_place_ref
             at /workspace/kani-project/kani/kani-compiler/src/codegen_cprover_gotoc/codegen/place.rs:623:72
  16: kani_compiler::codegen_cprover_gotoc::codegen::rvalue::<impl kani_compiler::codegen_cprover_gotoc::context::goto_ctx::GotocCtx>::codegen_rvalue
             at /workspace/kani-project/kani/kani-compiler/src/codegen_cprover_gotoc/codegen/rvalue.rs:681:63
  17: kani_compiler::codegen_cprover_gotoc::codegen::statement::<impl kani_compiler::codegen_cprover_gotoc::context::goto_ctx::GotocCtx>::codegen_statement
             at /workspace/kani-project/kani/kani-compiler/src/codegen_cprover_gotoc/codegen/statement.rs:54:33
  18: kani_compiler::codegen_cprover_gotoc::codegen::block::<impl kani_compiler::codegen_cprover_gotoc::context::goto_ctx::GotocCtx>::codegen_block
             at /workspace/kani-project/kani/kani-compiler/src/codegen_cprover_gotoc/codegen/block.rs:39:29
  19: kani_compiler::codegen_cprover_gotoc::codegen::function::<impl kani_compiler::codegen_cprover_gotoc::context::goto_ctx::GotocCtx>::codegen_function::{{closure}}
             at /workspace/kani-project/kani/kani-compiler/src/codegen_cprover_gotoc/codegen/function.rs:84:57
  20: core::iter::traits::iterator::Iterator::for_each::call::{{closure}}
             at /rustc/f4b80cacf93ca216c75f6ae12f4b9dec19eba42f/library/core/src/iter/traits/iterator.rs:853:29
  21: core::iter::adapters::map::map_fold::{{closure}}
             at /rustc/f4b80cacf93ca216c75f6ae12f4b9dec19eba42f/library/core/src/iter/adapters/map.rs:84:21
  22: <core::slice::iter::Iter<T> as core::iter::traits::iterator::Iterator>::fold
             at /rustc/f4b80cacf93ca216c75f6ae12f4b9dec19eba42f/library/core/src/slice/iter/macros.rs:215:27
  23: <core::iter::adapters::map::Map<I,F> as core::iter::traits::iterator::Iterator>::fold
             at /rustc/f4b80cacf93ca216c75f6ae12f4b9dec19eba42f/library/core/src/iter/adapters/map.rs:124:9
  24: core::iter::traits::iterator::Iterator::for_each
             at /rustc/f4b80cacf93ca216c75f6ae12f4b9dec19eba42f/library/core/src/iter/traits/iterator.rs:856:9
  25: kani_compiler::codegen_cprover_gotoc::codegen::function::<impl kani_compiler::codegen_cprover_gotoc::context::goto_ctx::GotocCtx>::codegen_function
             at /workspace/kani-project/kani/kani-compiler/src/codegen_cprover_gotoc/codegen/function.rs:84:13
  26: kani_compiler::codegen_cprover_gotoc::compiler_interface::GotocCodegenBackend::codegen_items::{{closure}}::{{closure}}
             at /workspace/kani-project/kani/kani-compiler/src/codegen_cprover_gotoc/compiler_interface.rs:127:39
  27: kani_compiler::codegen_cprover_gotoc::utils::debug::<impl kani_compiler::codegen_cprover_gotoc::context::goto_ctx::GotocCtx>::call_with_panic_debug_info::{{closure}}
             at /workspace/kani-project/kani/kani-compiler/src/codegen_cprover_gotoc/utils/debug.rs:68:13
  28: std::thread::local::LocalKey<T>::try_with
             at /rustc/f4b80cacf93ca216c75f6ae12f4b9dec19eba42f/library/std/src/thread/local.rs:270:16
  29: std::thread::local::LocalKey<T>::with
             at /rustc/f4b80cacf93ca216c75f6ae12f4b9dec19eba42f/library/std/src/thread/local.rs:246:9
  30: kani_compiler::codegen_cprover_gotoc::utils::debug::<impl kani_compiler::codegen_cprover_gotoc::context::goto_ctx::GotocCtx>::call_with_panic_debug_info
             at /workspace/kani-project/kani/kani-compiler/src/codegen_cprover_gotoc/utils/debug.rs:65:9
  31: kani_compiler::codegen_cprover_gotoc::compiler_interface::GotocCodegenBackend::codegen_items::{{closure}}
             at /workspace/kani-project/kani/kani-compiler/src/codegen_cprover_gotoc/compiler_interface.rs:126:29
  32: kani_compiler::codegen_cprover_gotoc::compiler_interface::with_timer
             at /workspace/kani-project/kani/kani-compiler/src/codegen_cprover_gotoc/compiler_interface.rs:738:15
  33: kani_compiler::codegen_cprover_gotoc::compiler_interface::GotocCodegenBackend::codegen_items
             at /workspace/kani-project/kani/kani-compiler/src/codegen_cprover_gotoc/compiler_interface.rs:96:9
  34: <kani_compiler::codegen_cprover_gotoc::compiler_interface::GotocCodegenBackend as rustc_codegen_ssa::traits::backend::CodegenBackend>::codegen_crate
             at /workspace/kani-project/kani/kani-compiler/src/codegen_cprover_gotoc/compiler_interface.rs:242:25
  35: <rustc_session::session::Session>::time::<alloc::boxed::Box<dyn core::any::Any>, rustc_interface::passes::start_codegen::{closure#0}>
  36: rustc_interface::passes::start_codegen
  37: <rustc_middle::ty::context::GlobalCtxt>::enter::<<rustc_interface::queries::Queries>::ongoing_codegen::{closure#0}, core::result::Result<alloc::boxed::Box<dyn core::any::Any>, rustc_span::ErrorGuaranteed>>
  38: <rustc_interface::interface::Compiler>::enter::<rustc_driver_impl::run_compiler::{closure#1}::{closure#2}, core::result::Result<core::option::Option<rustc_interface::queries::Linker>, rustc_span::ErrorGuaranteed>>
  39: rustc_span::set_source_map::<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_interface::interface::run_compiler<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_driver_impl::run_compiler::{closure#1}>::{closure#0}::{closure#0}>
  40: <scoped_tls::ScopedKey<rustc_span::SessionGlobals>>::set::<rustc_interface::interface::run_compiler<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_driver_impl::run_compiler::{closure#1}>::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

Kani unexpectedly panicked during compilation.
Please file an issue here: https://github.com/model-checking/kani/issues/new?labels=bug&template=bug_report.md

[Kani] current codegen item: codegen_function: array_based::check_fields::<u8, 16>
_RINvNtCs6EQ0jD6M6ta_14generic_access11array_based12check_fieldshKj10_EB4_
[Kani] current codegen location: Loc { file: "/workspace/kani-project/kani/tests/kani/SIMD/generic_access.rs", function: None, start_line: 15, start_col: Some(5), end_line: 18, end_col: Some(6) }
error: /workspace/kani-project/kani/target/kani/bin/kani-compiler exited with status exit status: 101

Activity

  1. added
    [C] Bug
    on Aug 3, 2023
  2. self-assigned this
    on Aug 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

[C] Bug[F] Crash

Type

No type

Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions