Skip to content

Add preconditions for disjoint_bitor #347

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .github/workflows/kani.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,15 @@ jobs:
# possible functions as that may take a lot longer than expected. Instead,
# explicitly list all functions (or prefixes thereof) the proofs of which
# are known to pass.
# Notes:
# - We use >::disjoint_bitor (and >::unchecked_disjoint_bitor) as pattern
# as whitespace is not supported, cf.
# https://github.com/model-checking/kani/issues/4046
- name: Run Kani Verification
run: |
scripts/run-kani.sh --run autoharness --kani-args \
--include-pattern ">::disjoint_bitor" \
--include-pattern ">::unchecked_disjoint_bitor" \
--include-pattern alloc::layout::Layout::from_size_align \
--include-pattern ascii::ascii_char::AsciiChar::from_u8 \
--include-pattern char::convert::from_u32_unchecked \
Expand Down
6 changes: 6 additions & 0 deletions library/core/src/intrinsics/fallback.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@
)]
#![allow(missing_docs)]

use safety::requires;

#[cfg(kani)]
use crate::kani;

#[const_trait]
#[rustc_const_unstable(feature = "core_intrinsics_fallbacks", issue = "none")]
pub trait CarryingMulAdd: Copy + 'static {
Expand Down Expand Up @@ -132,6 +137,7 @@ macro_rules! impl_disjoint_bitor {
impl const DisjointBitOr for $t {
#[cfg_attr(miri, track_caller)]
#[inline]
#[requires((self & other) == zero!($t))]
unsafe fn disjoint_bitor(self, other: Self) -> Self {
// Note that the assume here is required for UB detection in Miri!

Expand Down
1 change: 1 addition & 0 deletions library/core/src/num/uint_macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1265,6 +1265,7 @@ macro_rules! uint_impl {
#[unstable(feature = "disjoint_bitor", issue = "135758")]
#[rustc_const_unstable(feature = "disjoint_bitor", issue = "135758")]
#[inline]
#[requires((self & other) == 0)]
pub const unsafe fn unchecked_disjoint_bitor(self, other: Self) -> Self {
assert_unsafe_precondition!(
check_language_ub,
Expand Down
Loading