Skip to content

-Z valid-value-checks: raw pointer dereference of a dyn Trait pointee is reported as unsupported #5215

Description

@feliperodri

With -Z valid-value-checks, any harness that reads through a raw pointer to a trait object fails on an unsupported check, so the property can't be claimed for code that uses dyn Trait. In verify-rust-std this blocks every downcast, downcast_unchecked and dyn Any deref harness of the Box challenge (model-checking/verify-rust-std#639): 10 of its 71 harnesses, and the only ones left failing once #5205 lands.

use std::any::Any;

#[kani::proof]
fn downcast_box_dyn_any() {
    let b: Box<dyn Any> = Box::new(kani::any::<i32>());
    let _ = b.downcast::<i32>();
}

This verifies without the flag. With -Z valid-value-checks, on Kani 53cb531 and on #5205 rebased onto main (053e0f5):

Failed Checks: Kani currently doesn't support checking validity of `raw pointer dereference` for `dyn std::any::Any`
 File: ".../library/alloc/src/boxed/convert.rs", line 314, in std::boxed::convert::<impl std::boxed::Box<dyn std::any::Any>>::downcast_any::<i32>

The report comes from check_place_value and the deref path in kani-compiler/src/kani_middle/transform/check_values.rs: ty_validity_per_offset returns Err for a dyn pointee, whose concrete type is only known from the vtable. Here the flagged dereference is T::type_id(&this) in downcast_any, which dereferences the Box<dyn Any> to make the type_id call. That doesn't produce a value of the unknown concrete type: the cast back to a concrete type happens afterwards, in cast_unchecked, and that's where a validity check would apply.

One option is to skip the check for a dyn pointee at the dereference, and check validity when the pointer is cast to a concrete type. I haven't looked at whether the vtable could be used instead.

Related: #2998 (tracking issue), #5205.

Activity

  1. added
    [F] Spurious Failure
    Z-UnstableFeature
    on Nov 25, 2026
  2. added theissue type on Nov 25, 2026
  3. self-assigned this
    on Nov 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Z-UnstableFeature[F] Spurious Failure

Type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions