Skip to content

Kani crashes when casting Rc<dyn Trait + Sync> to Rc<dyn Trait>. #1528

Closed

Description

@celinval

I tried this code (see tests/kani/DynTrait/unsized_rc_cast_fixme.rs):

// Copyright Kani Contributors
// SPDX-License-Identifier: Apache-2.0 OR MIT
//! Check that we can cast between two unsized objects.
//! This fix-me is derived from unsized_rc_cast.rs and it should be merged with the original test.
use std::rc::Rc;

trait Byte {
    fn eq(&self, byte: u8) -> bool;
}

impl Byte for u8 {
    fn eq(&self, byte: u8) -> bool {
        *self == byte
    }
}

fn all_zero_rc(num: Rc<dyn Byte>) -> bool {
    num.eq(0x0)
}

#[kani::proof]
fn check_rc() {
    let num: u8 = kani::any();
    kani::assume(num != 0);
    let rc: Rc<dyn Byte + Sync> = Rc::new(num);
    assert!(!all_zero_rc(rc));
}

using the following command line invocation:

kani unsized_rc_cast_fixme

with Kani version:

I expected to see this happen: Verification succeed

Instead, this happened: Kani crashes during compilation.
thread 'rustc' panicked at 'Type std::rc::RcBox<dyn Byte> must be a trait type (a dynamic type)', kani-compiler/src/codegen_cprover_gotoc/codegen/typ.rs:594:9
stack backtrace:
   0:     0x7f85e38c1b70 - std::backtrace_rs::backtrace::libunwind::trace::h83eef7e1b99ceac2
                               at /rustc/fe3342816a282949f014caa05ea2e669ff9d3d3c/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   1:     0x7f85e38c1b70 - std::backtrace_rs::backtrace::trace_unsynchronized::h11443e110f08dce7
                               at /rustc/fe3342816a282949f014caa05ea2e669ff9d3d3c/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x7f85e38c1b70 - std::sys_common::backtrace::_print_fmt::h98d30f5880b6fe77
                               at /rustc/fe3342816a282949f014caa05ea2e669ff9d3d3c/library/std/src/sys_common/backtrace.rs:66:5
   3:     0x7f85e38c1b70 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::hb3fb4cc2aa6407b5
                               at /rustc/fe3342816a282949f014caa05ea2e669ff9d3d3c/library/std/src/sys_common/backtrace.rs:45:22
   4:     0x7f85e391cf7c - core::fmt::write::h4e85f46dfec88905
                               at /rustc/fe3342816a282949f014caa05ea2e669ff9d3d3c/library/core/src/fmt/mod.rs:1198:17
   5:     0x7f85e38b2dc5 - std::io::Write::write_fmt::h9357fcb2dba5c229
                               at /rustc/fe3342816a282949f014caa05ea2e669ff9d3d3c/library/std/src/io/mod.rs:1672:15
   6:     0x7f85e38c4841 - std::sys_common::backtrace::_print::h8e18b949553d004a
                               at /rustc/fe3342816a282949f014caa05ea2e669ff9d3d3c/library/std/src/sys_common/backtrace.rs:48:5
   7:     0x7f85e38c4841 - std::sys_common::backtrace::print::h60d8e98dad938672
                               at /rustc/fe3342816a282949f014caa05ea2e669ff9d3d3c/library/std/src/sys_common/backtrace.rs:35:9
   8:     0x7f85e38c4841 - std::panicking::default_hook::{{closure}}::hbe18146ce199bf86
                               at /rustc/fe3342816a282949f014caa05ea2e669ff9d3d3c/library/std/src/panicking.rs:295:22
   9:     0x7f85e38c4513 - std::panicking::default_hook::h1d233b95c05e4774
                               at /rustc/fe3342816a282949f014caa05ea2e669ff9d3d3c/library/std/src/panicking.rs:314:9
  10:     0x5630b3638973 - <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call::h06d7e8619750c5fb
                               at /rustc/fe3342816a282949f014caa05ea2e669ff9d3d3c/library/alloc/src/boxed.rs:1949:9
  11:     0x5630b3668c76 - kani_compiler::session::PANIC_HOOK::{{closure}}::{{closure}}::h3fa1aa41f2fc8dbe
                               at /home/ANT.AMAZON.COM/celinval/workspace/kani-project/kani/kani-compiler/src/session.rs:28:13
  12:     0x5630b3638973 - <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call::h06d7e8619750c5fb
                               at /rustc/fe3342816a282949f014caa05ea2e669ff9d3d3c/library/alloc/src/boxed.rs:1949:9
  13:     0x5630b36625cb - kani_compiler::codegen_cprover_gotoc::utils::debug::DEFAULT_HOOK::{{closure}}::{{closure}}::hee8544a8a4048c7a
                               at /home/ANT.AMAZON.COM/celinval/workspace/kani-project/kani/kani-compiler/src/codegen_cprover_gotoc/utils/debug.rs:35:13
  14:     0x7f85e38c5076 - std::panicking::rust_panic_with_hook::h4bd240a94f5d8396
                               at /rustc/fe3342816a282949f014caa05ea2e669ff9d3d3c/library/std/src/panicking.rs:702:17
  15:     0x7f85e38c4ec7 - std::panicking::begin_panic_handler::{{closure}}::hd2974ad90d6aceb2
                               at /rustc/fe3342816a282949f014caa05ea2e669ff9d3d3c/library/std/src/panicking.rs:588:13
  16:     0x7f85e38c2094 - std::sys_common::backtrace::__rust_end_short_backtrace::h47aa8b9750307fbb
                               at /rustc/fe3342816a282949f014caa05ea2e669ff9d3d3c/library/std/src/sys_common/backtrace.rs:138:18
  17:     0x7f85e38c4bf2 - rust_begin_unwind
                               at /rustc/fe3342816a282949f014caa05ea2e669ff9d3d3c/library/std/src/panicking.rs:584:5
  18:     0x7f85e3919a53 - core::panicking::panic_fmt::h6e77553746513d00
                               at /rustc/fe3342816a282949f014caa05ea2e669ff9d3d3c/library/core/src/panicking.rs:142:14
  19:     0x5630b355249c - kani_compiler::codegen_cprover_gotoc::codegen::typ::<impl kani_compiler::codegen_cprover_gotoc::context::goto_ctx::GotocCtx>::normalized_trait_name::he5ee9874df4fc37f
                               at /home/ANT.AMAZON.COM/celinval/workspace/kani-project/kani/kani-compiler/src/codegen_cprover_gotoc/codegen/typ.rs:594:9
  20:     0x5630b35524e8 - kani_compiler::codegen_cprover_gotoc::codegen::typ::<impl kani_compiler::codegen_cprover_gotoc::context::goto_ctx::GotocCtx>::vtable_name::h72e6acc0d7a7d8bb
                               at /home/ANT.AMAZON.COM/celinval/workspace/kani-project/kani/kani-compiler/src/codegen_cprover_gotoc/codegen/typ.rs:606:31
  21:     0x5630b353608f - kani_compiler::codegen_cprover_gotoc::codegen::rvalue::<impl kani_compiler::codegen_cprover_gotoc::context::goto_ctx::GotocCtx>::cast_unsized_dyn_trait_to_unsized_dyn_trait::h7395bff081753169
                               at /home/ANT.AMAZON.COM/celinval/workspace/kani-project/kani/kani-compiler/src/codegen_cprover_gotoc/codegen/rvalue.rs:1031:27
  22:     0x5630b352fd37 - kani_compiler::codegen_cprover_gotoc::codegen::rvalue::<impl kani_compiler::codegen_cprover_gotoc::context::goto_ctx::GotocCtx>::cast_to_unsized_expr::ha4014a17d5a38262
                               at /home/ANT.AMAZON.COM/celinval/workspace/kani-project/kani/kani-compiler/src/codegen_cprover_gotoc/codegen/rvalue.rs:757:13
  23:     0x5630b35394cd - kani_compiler::codegen_cprover_gotoc::codegen::rvalue::<impl kani_compiler::codegen_cprover_gotoc::context::goto_ctx::GotocCtx>::cast_adt_to_unsized_adt::h55cb16365d83f71e
                               at /home/ANT.AMAZON.COM/celinval/workspace/kani-project/kani/kani-compiler/src/codegen_cprover_gotoc/codegen/rvalue.rs:1204:33
  24:     0x5630b35369b0 - kani_compiler::codegen_cprover_gotoc::codegen::rvalue::<impl kani_compiler::codegen_cprover_gotoc::context::goto_ctx::GotocCtx>::cast_expr_to_unsized_expr::h6419afd17161c1cf
                               at /home/ANT.AMAZON.COM/celinval/workspace/kani-project/kani/kani-compiler/src/codegen_cprover_gotoc/codegen/rvalue.rs:1065:17
  25:     0x5630b352fcc0 - kani_compiler::codegen_cprover_gotoc::codegen::rvalue::<impl kani_compiler::codegen_cprover_gotoc::context::goto_ctx::GotocCtx>::cast_to_unsized_expr::ha4014a17d5a38262
                               at /home/ANT.AMAZON.COM/celinval/workspace/kani-project/kani/kani-compiler/src/codegen_cprover_gotoc/codegen/rvalue.rs:765:13
  26:     0x5630b35394cd - kani_compiler::codegen_cprover_gotoc::codegen::rvalue::<impl kani_compiler::codegen_cprover_gotoc::context::goto_ctx::GotocCtx>::cast_adt_to_unsized_adt::h55cb16365d83f71e
                               at /home/ANT.AMAZON.COM/celinval/workspace/kani-project/kani/kani-compiler/src/codegen_cprover_gotoc/codegen/rvalue.rs:1204:33
  27:     0x5630b35369b0 - kani_compiler::codegen_cprover_gotoc::codegen::rvalue::<impl kani_compiler::codegen_cprover_gotoc::context::goto_ctx::GotocCtx>::cast_expr_to_unsized_expr::h6419afd17161c1cf
                               at /home/ANT.AMAZON.COM/celinval/workspace/kani-project/kani/kani-compiler/src/codegen_cprover_gotoc/codegen/rvalue.rs:1065:17
  28:     0x5630b352fcc0 - kani_compiler::codegen_cprover_gotoc::codegen::rvalue::<impl kani_compiler::codegen_cprover_gotoc::context::goto_ctx::GotocCtx>::cast_to_unsized_expr::ha4014a17d5a38262
                               at /home/ANT.AMAZON.COM/celinval/workspace/kani-project/kani/kani-compiler/src/codegen_cprover_gotoc/codegen/rvalue.rs:765:13
  29:     0x5630b352f72f - kani_compiler::codegen_cprover_gotoc::codegen::rvalue::<impl kani_compiler::codegen_cprover_gotoc::context::goto_ctx::GotocCtx>::codegen_pointer_cast::haa95f0ce2a9fa0fd
                               at /home/ANT.AMAZON.COM/celinval/workspace/kani-project/kani/kani-compiler/src/codegen_cprover_gotoc/codegen/rvalue.rs:742:17
  30:     0x5630b352a6e8 - kani_compiler::codegen_cprover_gotoc::codegen::rvalue::<impl kani_compiler::codegen_cprover_gotoc::context::goto_ctx::GotocCtx>::codegen_rvalue::h976ccba2b2861d5b
                               at /home/ANT.AMAZON.COM/celinval/workspace/kani-project/kani/kani-compiler/src/codegen_cprover_gotoc/codegen/rvalue.rs:416:17
  31:     0x5630b353e94e - kani_compiler::codegen_cprover_gotoc::codegen::statement::<impl kani_compiler::codegen_cprover_gotoc::context::goto_ctx::GotocCtx>::codegen_statement::ha8b4f64dfed41b72
                               at /home/ANT.AMAZON.COM/celinval/workspace/kani-project/kani/kani-compiler/src/codegen_cprover_gotoc/codegen/statement.rs:57:33
  32:     0x5630b34ac165 - kani_compiler::codegen_cprover_gotoc::codegen::block::<impl kani_compiler::codegen_cprover_gotoc::context::goto_ctx::GotocCtx>::codegen_block::hcb41c1769601ab16
                               at /home/ANT.AMAZON.COM/celinval/workspace/kani-project/kani/kani-compiler/src/codegen_cprover_gotoc/codegen/block.rs:31:32
  33:     0x5630b35db372 - kani_compiler::codegen_cprover_gotoc::codegen::function::<impl kani_compiler::codegen_cprover_gotoc::context::goto_ctx::GotocCtx>::codegen_function::{{closure}}::hf96592b71ad3be56
                               at /home/ANT.AMAZON.COM/celinval/workspace/kani-project/kani/kani-compiler/src/codegen_cprover_gotoc/codegen/function.rs:115:71
  34:     0x5630b34a5289 - core::iter::traits::iterator::Iterator::for_each::call::{{closure}}::h0f9febb904a9d47b
                               at /rustc/fe3342816a282949f014caa05ea2e669ff9d3d3c/library/core/src/iter/traits/iterator.rs:828:29
  35:     0x5630b36a3064 - core::iter::adapters::map::map_fold::{{closure}}::h884ae8f099985ec8
                               at /rustc/fe3342816a282949f014caa05ea2e669ff9d3d3c/library/core/src/iter/adapters/map.rs:84:21
  36:     0x5630b344002a - <core::iter::adapters::enumerate::Enumerate<I> as core::iter::traits::iterator::Iterator>::fold::enumerate::{{closure}}::h64ab89c77c736942
                               at /rustc/fe3342816a282949f014caa05ea2e669ff9d3d3c/library/core/src/iter/adapters/enumerate.rs:106:27
  37:     0x5630b3617b39 - core::iter::traits::iterator::Iterator::fold::he345b8a93543f4c2
                               at /rustc/fe3342816a282949f014caa05ea2e669ff9d3d3c/library/core/src/iter/traits/iterator.rs:2414:21
  38:     0x5630b343fbed - <core::iter::adapters::enumerate::Enumerate<I> as core::iter::traits::iterator::Iterator>::fold::h33a1bc12bba5ddf9
                               at /rustc/fe3342816a282949f014caa05ea2e669ff9d3d3c/library/core/src/iter/adapters/enumerate.rs:112:9
  39:     0x5630b369b72d - <core::iter::adapters::map::Map<I,F> as core::iter::traits::iterator::Iterator>::fold::h7ccef10e77a33756
                               at /rustc/fe3342816a282949f014caa05ea2e669ff9d3d3c/library/core/src/iter/adapters/map.rs:124:9
  40:     0x5630b369f780 - core::iter::traits::iterator::Iterator::for_each::he9f8035723720684
                               at /rustc/fe3342816a282949f014caa05ea2e669ff9d3d3c/library/core/src/iter/traits/iterator.rs:831:9
  41:     0x5630b34ae0f9 - kani_compiler::codegen_cprover_gotoc::codegen::function::<impl kani_compiler::codegen_cprover_gotoc::context::goto_ctx::GotocCtx>::codegen_function::h808c8efae8f43e8c
                               at /home/ANT.AMAZON.COM/celinval/workspace/kani-project/kani/kani-compiler/src/codegen_cprover_gotoc/codegen/function.rs:115:13
  42:     0x5630b34a63eb - <kani_compiler::codegen_cprover_gotoc::compiler_interface::GotocCodegenBackend as rustc_codegen_ssa::traits::backend::CodegenBackend>::codegen_crate::{{closure}}::h1958136bef9997f9
                               at /home/ANT.AMAZON.COM/celinval/workspace/kani-project/kani/kani-compiler/src/codegen_cprover_gotoc/compiler_interface.rs:112:35
  43:     0x5630b36637db - kani_compiler::codegen_cprover_gotoc::utils::debug::<impl kani_compiler::codegen_cprover_gotoc::context::goto_ctx::GotocCtx>::call_with_panic_debug_info::{{closure}}::h4a1c1e75c6a862ab
                               at /home/ANT.AMAZON.COM/celinval/workspace/kani-project/kani/kani-compiler/src/codegen_cprover_gotoc/utils/debug.rs:68:13
  44:     0x5630b3450365 - std::thread::local::LocalKey<T>::try_with::he885724476cb73fa
                               at /rustc/fe3342816a282949f014caa05ea2e669ff9d3d3c/library/std/src/thread/local.rs:445:16
  45:     0x5630b344f4aa - std::thread::local::LocalKey<T>::with::h476ddaba734ad6df
                               at /rustc/fe3342816a282949f014caa05ea2e669ff9d3d3c/library/std/src/thread/local.rs:421:9
  46:     0x5630b360fd73 - kani_compiler::codegen_cprover_gotoc::utils::debug::<impl kani_compiler::codegen_cprover_gotoc::context::goto_ctx::GotocCtx>::call_with_panic_debug_info::h473af97f87c01250
                               at /home/ANT.AMAZON.COM/celinval/workspace/kani-project/kani/kani-compiler/src/codegen_cprover_gotoc/utils/debug.rs:65:9
  47:     0x5630b35dd5bd - <kani_compiler::codegen_cprover_gotoc::compiler_interface::GotocCodegenBackend as rustc_codegen_ssa::traits::backend::CodegenBackend>::codegen_crate::hd0b3df620caae12c
                               at /home/ANT.AMAZON.COM/celinval/workspace/kani-project/kani/kani-compiler/src/codegen_cprover_gotoc/compiler_interface.rs:111:25
  48:     0x7f85e1b0d89c - <rustc_session[4b1bded813f18a1a]::session::Session>::time::<alloc[5e249fce5ebefa79]::boxed::Box<dyn core[cdc6a31a4cbccd39]::any::Any>, rustc_interface[507fe53e0572d3d2]::passes::start_codegen::{closure#0}>
  49:     0x7f85e1b0d1c3 - <rustc_interface[507fe53e0572d3d2]::passes::QueryContext>::enter::<<rustc_interface[507fe53e0572d3d2]::queries::Queries>::ongoing_codegen::{closure#0}::{closure#0}, core[cdc6a31a4cbccd39]::result::Result<alloc[5e249fce5ebefa79]::boxed::Box<dyn core[cdc6a31a4cbccd39]::any::Any>, rustc_errors[fcb91965fb6576e9]::ErrorGuaranteed>>
  50:     0x7f85e1b055a3 - <rustc_interface[507fe53e0572d3d2]::queries::Queries>::ongoing_codegen
  51:     0x7f85e1b04333 - <rustc_interface[507fe53e0572d3d2]::interface::Compiler>::enter::<rustc_driver[8b04a589e2b44e89]::run_compiler::{closure#1}::{closure#2}, core[cdc6a31a4cbccd39]::result::Result<core[cdc6a31a4cbccd39]::option::Option<rustc_interface[507fe53e0572d3d2]::queries::Linker>, rustc_errors[fcb91965fb6576e9]::ErrorGuaranteed>>
  52:     0x7f85e1af7d2a - rustc_span[6e576ba6dd4e221]::with_source_map::<core[cdc6a31a4cbccd39]::result::Result<(), rustc_errors[fcb91965fb6576e9]::ErrorGuaranteed>, rustc_interface[507fe53e0572d3d2]::interface::create_compiler_and_run<core[cdc6a31a4cbccd39]::result::Result<(), rustc_errors[fcb91965fb6576e9]::ErrorGuaranteed>, rustc_driver[8b04a589e2b44e89]::run_compiler::{closure#1}>::{closure#1}>
  53:     0x7f85e1af7700 - rustc_interface[507fe53e0572d3d2]::interface::create_compiler_and_run::<core[cdc6a31a4cbccd39]::result::Result<(), rustc_errors[fcb91965fb6576e9]::ErrorGuaranteed>, rustc_driver[8b04a589e2b44e89]::run_compiler::{closure#1}>
  54:     0x7f85e1af5a71 - <scoped_tls[5bea244f1759cc4a]::ScopedKey<rustc_span[6e576ba6dd4e221]::SessionGlobals>>::set::<rustc_interface[507fe53e0572d3d2]::interface::run_compiler<core[cdc6a31a4cbccd39]::result::Result<(), rustc_errors[fcb91965fb6576e9]::ErrorGuaranteed>, rustc_driver[8b04a589e2b44e89]::run_compiler::{closure#1}>::{closure#0}, core[cdc6a31a4cbccd39]::result::Result<(), rustc_errors[fcb91965fb6576e9]::ErrorGuaranteed>>
  55:     0x7f85e1af575f - std[470ad8214e061e82]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[507fe53e0572d3d2]::util::run_in_thread_pool_with_globals<rustc_interface[507fe53e0572d3d2]::interface::run_compiler<core[cdc6a31a4cbccd39]::result::Result<(), rustc_errors[fcb91965fb6576e9]::ErrorGuaranteed>, rustc_driver[8b04a589e2b44e89]::run_compiler::{closure#1}>::{closure#0}, core[cdc6a31a4cbccd39]::result::Result<(), rustc_errors[fcb91965fb6576e9]::ErrorGuaranteed>>::{closure#0}, core[cdc6a31a4cbccd39]::result::Result<(), rustc_errors[fcb91965fb6576e9]::ErrorGuaranteed>>
  56:     0x7f85e214e599 - <<std[470ad8214e061e82]::thread::Builder>::spawn_unchecked_<rustc_interface[507fe53e0572d3d2]::util::run_in_thread_pool_with_globals<rustc_interface[507fe53e0572d3d2]::interface::run_compiler<core[cdc6a31a4cbccd39]::result::Result<(), rustc_errors[fcb91965fb6576e9]::ErrorGuaranteed>, rustc_driver[8b04a589e2b44e89]::run_compiler::{closure#1}>::{closure#0}, core[cdc6a31a4cbccd39]::result::Result<(), rustc_errors[fcb91965fb6576e9]::ErrorGuaranteed>>::{closure#0}, core[cdc6a31a4cbccd39]::result::Result<(), rustc_errors[fcb91965fb6576e9]::ErrorGuaranteed>>::{closure#1} as core[cdc6a31a4cbccd39]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  57:     0x7f85e38cecb3 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::hd91dcbcc80c66aa0
                               at /rustc/fe3342816a282949f014caa05ea2e669ff9d3d3c/library/alloc/src/boxed.rs:1935:9
  58:     0x7f85e38cecb3 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h36fdba9d16140431
                               at /rustc/fe3342816a282949f014caa05ea2e669ff9d3d3c/library/alloc/src/boxed.rs:1935:9
  59:     0x7f85e38cecb3 - std::sys::unix::thread::Thread::new::thread_start::h3bd76bb7cb4b4d75
                               at /rustc/fe3342816a282949f014caa05ea2e669ff9d3d3c/library/std/src/sys/unix/thread.rs:108:17
  60:     0x7f85df7086db - start_thread
                               at /build/glibc-CVJwZb/glibc-2.27/nptl/pthread_create.c:463
  61:     0x7f85df09361f - clone
                               at /build/glibc-CVJwZb/glibc-2.27/misc/../sysdeps/unix/sysv/linux/x86_64/clone.S:95
  62:                0x0 - <unknown>

Metadata

Metadata

Assignees

Labels

[C] Bug

Type

No type

Projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions