-
Notifications
You must be signed in to change notification settings - Fork 100
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement proper function pointer handling for validity checks (#3606)
We previously had a `todo!()` for the validity check handling of function pointers. However, the validity check only cares about intrinsics calls, which can only be done directly. Thus, remove the `todo!()` and refactor the code so that it's clear why we don't care about that case. I added a test that I was working on when I bumped into this issue. By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 and MIT licenses.
- Loading branch information
Showing
3 changed files
with
71 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
2 of 2 cover properties satisfied | ||
|
||
Complete - 3 successfully verified harnesses, 0 failures, 3 total. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// Copyright Kani Contributors | ||
// SPDX-License-Identifier: Apache-2.0 OR MIT | ||
// kani-flags: -Z valid-value-checks -Z mem-predicates | ||
//! Check that Kani can identify invalid value when using `can_dereference` API. | ||
#[kani::proof] | ||
fn check_can_dereference_char() { | ||
let val: [u32; 2] = kani::any(); | ||
kani::cover!(kani::mem::can_dereference(&val as *const _ as *const [char; 2])); | ||
kani::cover!(!kani::mem::can_dereference(&val as *const _ as *const [char; 2])); | ||
} | ||
|
||
#[kani::proof] | ||
fn check_can_dereference_always_valid() { | ||
let val: [char; 2] = [kani::any(), kani::any()]; | ||
assert!(kani::mem::can_dereference(&val as *const _ as *const [u32; 2])); | ||
} | ||
|
||
#[kani::proof] | ||
fn check_can_dereference_always_invalid() { | ||
let val: [u8; 2] = kani::any(); | ||
kani::assume(val[0] > 1 || val[1] > 1); | ||
assert!(!kani::mem::can_dereference(&val as *const _ as *const [bool; 2])); | ||
} |