Skip to content

Commit 13014d9

Browse files
Add preconditions for disjoint_bitor (#347)
Uses the verbatim SAFETY comment as precondition to avoid spurious proof failures. By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 and MIT licenses. --------- Co-authored-by: Carolyn Zech <[email protected]>
1 parent 9414fee commit 13014d9

File tree

3 files changed

+13
-0
lines changed

3 files changed

+13
-0
lines changed

.github/workflows/kani.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,15 @@ jobs:
7878
# possible functions as that may take a lot longer than expected. Instead,
7979
# explicitly list all functions (or prefixes thereof) the proofs of which
8080
# are known to pass.
81+
# Notes:
82+
# - We use >::disjoint_bitor (and >::unchecked_disjoint_bitor) as pattern
83+
# as whitespace is not supported, cf.
84+
# https://github.com/model-checking/kani/issues/4046
8185
- name: Run Kani Verification
8286
run: |
8387
scripts/run-kani.sh --run autoharness --kani-args \
88+
--include-pattern ">::disjoint_bitor" \
89+
--include-pattern ">::unchecked_disjoint_bitor" \
8490
--include-pattern alloc::__default_lib_allocator:: \
8591
--include-pattern alloc::layout::Layout::from_size_align \
8692
--include-pattern ascii::ascii_char::AsciiChar::from_u8 \

library/core/src/intrinsics/fallback.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@
77
)]
88
#![allow(missing_docs)]
99

10+
use safety::requires;
11+
12+
#[cfg(kani)]
13+
use crate::kani;
14+
1015
#[const_trait]
1116
#[rustc_const_unstable(feature = "core_intrinsics_fallbacks", issue = "none")]
1217
pub trait CarryingMulAdd: Copy + 'static {
@@ -132,6 +137,7 @@ macro_rules! impl_disjoint_bitor {
132137
impl const DisjointBitOr for $t {
133138
#[cfg_attr(miri, track_caller)]
134139
#[inline]
140+
#[requires((self & other) == zero!($t))]
135141
unsafe fn disjoint_bitor(self, other: Self) -> Self {
136142
// Note that the assume here is required for UB detection in Miri!
137143

library/core/src/num/uint_macros.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1265,6 +1265,7 @@ macro_rules! uint_impl {
12651265
#[unstable(feature = "disjoint_bitor", issue = "135758")]
12661266
#[rustc_const_unstable(feature = "disjoint_bitor", issue = "135758")]
12671267
#[inline]
1268+
#[requires((self & other) == 0)]
12681269
pub const unsafe fn unchecked_disjoint_bitor(self, other: Self) -> Self {
12691270
assert_unsafe_precondition!(
12701271
check_language_ub,

0 commit comments

Comments
 (0)