Skip to content

Commit 01ae84e

Browse files
committed
Merge remote-tracking branch 'origin/main' into autoharness-support
2 parents 83dfb82 + f1aaa87 commit 01ae84e

File tree

45 files changed

+234
-93
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+234
-93
lines changed

.github/workflows/kani.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,3 +158,30 @@ jobs:
158158
.addHeading('Kani List Output', 2)
159159
.addRaw(kaniOutput, false)
160160
.write();
161+
162+
run-autoharness-analyzer:
163+
name: Kani Autoharness Analyzer
164+
runs-on: ubuntu-latest
165+
steps:
166+
# Step 1: Check out the repository
167+
- name: Checkout Repository
168+
uses: actions/checkout@v4
169+
with:
170+
submodules: true
171+
172+
# Step 2: Run autoharness analyzer on the std library
173+
- name: Run Autoharness Analyzer
174+
run: scripts/run-kani.sh --run autoharness-analyzer
175+
176+
# Step 3: Add output to job summary
177+
- name: Add Autoharness Analyzer output to job summary
178+
run: |
179+
echo "# Autoharness Failure Summary" >> "$GITHUB_STEP_SUMMARY"
180+
echo "## Crate core, all functions" >> "$GITHUB_STEP_SUMMARY"
181+
cat autoharness_analyzer/core_autoharness_data.md >> "$GITHUB_STEP_SUMMARY"
182+
echo "## Crate core, unsafe functions" >> "$GITHUB_STEP_SUMMARY"
183+
cat autoharness_analyzer/core_autoharness_data.md >> "$GITHUB_STEP_SUMMARY"
184+
echo "## Crate std, all functions" >> "$GITHUB_STEP_SUMMARY"
185+
cat autoharness_analyzer/std_autoharness_data.md >> "$GITHUB_STEP_SUMMARY"
186+
echo "## Crate std, unsafe functions" >> "$GITHUB_STEP_SUMMARY"
187+
cat autoharness_analyzer/std_unsafe_autoharness_data.md >> "$GITHUB_STEP_SUMMARY"

doc/src/SUMMARY.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,4 @@
3131
- [15: Contracts and Tests for SIMD Intrinsics](./challenges/0015-intrinsics-simd.md)
3232
- [16: Verify the safety of Iterator functions](./challenges/0016-iter.md)
3333
- [17: Verify the safety of slice functions](./challenges/0017-slice.md)
34-
- [18: Verify the safety of slice iter functions](./challenges/0018-slice-iter-pt1.md)
34+
- [18: Verify the safety of slice iter functions](./challenges/0018-slice-iter.md)

library/Cargo.lock

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

library/alloc/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ bench = false
1616

1717
[dependencies]
1818
core = { path = "../core", public = true }
19-
compiler_builtins = { version = "=0.1.155", features = ['rustc-dep-of-std'] }
2019
safety = { path = "../contracts/safety" }
20+
compiler_builtins = { version = "=0.1.156", features = ['rustc-dep-of-std'] }
2121

2222
[features]
2323
compiler-builtins-mem = ['compiler_builtins/mem']

library/alloc/src/ffi/c_str.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -574,7 +574,7 @@ impl CString {
574574
#[stable(feature = "as_c_str", since = "1.20.0")]
575575
#[rustc_diagnostic_item = "cstring_as_c_str"]
576576
pub fn as_c_str(&self) -> &CStr {
577-
&*self
577+
unsafe { CStr::from_bytes_with_nul_unchecked(self.as_bytes_with_nul()) }
578578
}
579579

580580
/// Converts this `CString` into a boxed [`CStr`].
@@ -705,14 +705,14 @@ impl ops::Deref for CString {
705705

706706
#[inline]
707707
fn deref(&self) -> &CStr {
708-
unsafe { CStr::from_bytes_with_nul_unchecked(self.as_bytes_with_nul()) }
708+
self.as_c_str()
709709
}
710710
}
711711

712712
#[stable(feature = "rust1", since = "1.0.0")]
713713
impl fmt::Debug for CString {
714714
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
715-
fmt::Debug::fmt(&**self, f)
715+
fmt::Debug::fmt(self.as_c_str(), f)
716716
}
717717
}
718718

library/alloctests/tests/c_str2.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,6 @@ fn build_with_zero2() {
3333
assert!(CString::new(vec![0]).is_err());
3434
}
3535

36-
#[test]
37-
fn formatted() {
38-
let s = CString::new(&b"abc\x01\x02\n\xE2\x80\xA6\xFF"[..]).unwrap();
39-
assert_eq!(format!("{s:?}"), r#""abc\x01\x02\n\xe2\x80\xa6\xff""#);
40-
}
41-
4236
#[test]
4337
fn borrowed() {
4438
unsafe {

library/core/src/any.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -772,8 +772,8 @@ impl hash::Hash for TypeId {
772772
// (especially given the previous point about the lower 64 bits being
773773
// high quality on their own).
774774
// - It is correct to do so -- only hashing a subset of `self` is still
775-
// with an `Eq` implementation that considers the entire value, as
776-
// ours does.
775+
// compatible with an `Eq` implementation that considers the entire
776+
// value, as ours does.
777777
self.t.1.hash(state);
778778
}
779779
}

library/core/src/arch.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ pub macro asm("assembly template", $(operands,)* $(options($(option),*))?) {
3232
///
3333
/// [Rust By Example]: https://doc.rust-lang.org/nightly/rust-by-example/unsafe/asm.html
3434
/// [reference]: https://doc.rust-lang.org/nightly/reference/inline-assembly.html
35-
#[unstable(feature = "naked_functions", issue = "90957")]
35+
#[stable(feature = "naked_functions", since = "CURRENT_RUSTC_VERSION")]
3636
#[rustc_builtin_macro]
3737
pub macro naked_asm("assembly template", $(operands,)* $(options($(option),*))?) {
3838
/* compiler built-in */

library/core/src/bstr/mod.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,7 @@ use crate::ops::{Deref, DerefMut, DerefPure};
3636
/// presented as hex escape sequences.
3737
///
3838
/// The `Display` implementation behaves as if the `ByteStr` were first lossily converted to a
39-
/// `str`, with invalid UTF-8 presented as the Unicode replacement character: �
40-
///
39+
/// `str`, with invalid UTF-8 presented as the Unicode replacement character (�).
4140
#[unstable(feature = "bstr", issue = "134915")]
4241
#[repr(transparent)]
4342
#[doc(alias = "BStr")]

library/core/src/ffi/c_str.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,6 @@ impl Error for FromBytesWithNulError {
157157
/// within the slice.
158158
///
159159
/// This error is created by the [`CStr::from_bytes_until_nul`] method.
160-
///
161160
#[derive(Clone, PartialEq, Eq, Debug)]
162161
#[stable(feature = "cstr_from_bytes_until_nul", since = "1.69.0")]
163162
pub struct FromBytesUntilNulError(());

library/core/src/intrinsics/simd.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ pub unsafe fn simd_shuffle<T, U, V>(x: T, y: T, idx: U) -> V;
304304
///
305305
/// `U` must be a vector of pointers to the element type of `T`, with the same length as `T`.
306306
///
307-
/// `V` must be a vector of signed integers with the same length as `T` (but any element size).
307+
/// `V` must be a vector of integers with the same length as `T` (but any element size).
308308
///
309309
/// For each pointer in `ptr`, if the corresponding value in `mask` is `!0`, read the pointer.
310310
/// Otherwise if the corresponding value in `mask` is `0`, return the corresponding value from
@@ -325,7 +325,7 @@ pub unsafe fn simd_gather<T, U, V>(val: T, ptr: U, mask: V) -> T;
325325
///
326326
/// `U` must be a vector of pointers to the element type of `T`, with the same length as `T`.
327327
///
328-
/// `V` must be a vector of signed integers with the same length as `T` (but any element size).
328+
/// `V` must be a vector of integers with the same length as `T` (but any element size).
329329
///
330330
/// For each pointer in `ptr`, if the corresponding value in `mask` is `!0`, write the
331331
/// corresponding value in `val` to the pointer.
@@ -349,7 +349,7 @@ pub unsafe fn simd_scatter<T, U, V>(val: T, ptr: U, mask: V);
349349
///
350350
/// `U` must be a pointer to the element type of `T`
351351
///
352-
/// `V` must be a vector of signed integers with the same length as `T` (but any element size).
352+
/// `V` must be a vector of integers with the same length as `T` (but any element size).
353353
///
354354
/// For each element, if the corresponding value in `mask` is `!0`, read the corresponding
355355
/// pointer offset from `ptr`.
@@ -372,7 +372,7 @@ pub unsafe fn simd_masked_load<V, U, T>(mask: V, ptr: U, val: T) -> T;
372372
///
373373
/// `U` must be a pointer to the element type of `T`
374374
///
375-
/// `V` must be a vector of signed integers with the same length as `T` (but any element size).
375+
/// `V` must be a vector of integers with the same length as `T` (but any element size).
376376
///
377377
/// For each element, if the corresponding value in `mask` is `!0`, write the corresponding
378378
/// value in `val` to the pointer offset from `ptr`.
@@ -556,7 +556,7 @@ pub unsafe fn simd_bitmask<T, U>(x: T) -> U;
556556
///
557557
/// `T` must be a vector.
558558
///
559-
/// `M` must be a signed integer vector with the same length as `T` (but any element size).
559+
/// `M` must be an integer vector with the same length as `T` (but any element size).
560560
///
561561
/// For each element, if the corresponding value in `mask` is `!0`, select the element from
562562
/// `if_true`. If the corresponding value in `mask` is `0`, select the element from

library/core/src/num/f128.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,9 @@ impl f128 {
151151
pub const RADIX: u32 = 2;
152152

153153
/// Number of significant digits in base 2.
154+
///
155+
/// Note that the size of the mantissa in the bitwise representation is one
156+
/// smaller than this since the leading 1 is not stored explicitly.
154157
#[unstable(feature = "f128", issue = "116909")]
155158
pub const MANTISSA_DIGITS: u32 = 113;
156159

library/core/src/num/f16.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,9 @@ impl f16 {
146146
pub const RADIX: u32 = 2;
147147

148148
/// Number of significant digits in base 2.
149+
///
150+
/// Note that the size of the mantissa in the bitwise representation is one
151+
/// smaller than this since the leading 1 is not stored explicitly.
149152
#[unstable(feature = "f16", issue = "116909")]
150153
pub const MANTISSA_DIGITS: u32 = 11;
151154

library/core/src/num/f32.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,9 @@ impl f32 {
396396
pub const RADIX: u32 = 2;
397397

398398
/// Number of significant digits in base 2.
399+
///
400+
/// Note that the size of the mantissa in the bitwise representation is one
401+
/// smaller than this since the leading 1 is not stored explicitly.
399402
#[stable(feature = "assoc_int_consts", since = "1.43.0")]
400403
pub const MANTISSA_DIGITS: u32 = 24;
401404

library/core/src/num/f64.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,9 @@ impl f64 {
396396
pub const RADIX: u32 = 2;
397397

398398
/// Number of significant digits in base 2.
399+
///
400+
/// Note that the size of the mantissa in the bitwise representation is one
401+
/// smaller than this since the leading 1 is not stored explicitly.
399402
#[stable(feature = "assoc_int_consts", since = "1.43.0")]
400403
pub const MANTISSA_DIGITS: u32 = 53;
401404
/// Approximate number of significant digits in base 10.

library/core/src/num/int_macros.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1589,6 +1589,7 @@ macro_rules! int_impl {
15891589
let mut base = self;
15901590
let mut acc: Self = 1;
15911591

1592+
#[safety::loop_invariant(true)]
15921593
loop {
15931594
if (exp & 1) == 1 {
15941595
acc = try_opt!(acc.checked_mul(base));
@@ -2299,6 +2300,7 @@ macro_rules! int_impl {
22992300
let mut acc: Self = 1;
23002301

23012302
if intrinsics::is_val_statically_known(exp) {
2303+
#[safety::loop_invariant(exp>=1)]
23022304
while exp > 1 {
23032305
if (exp & 1) == 1 {
23042306
acc = acc.wrapping_mul(base);
@@ -2316,6 +2318,7 @@ macro_rules! int_impl {
23162318
// at compile time. We can't use the same code for the constant
23172319
// exponent case because LLVM is currently unable to unroll
23182320
// this loop.
2321+
#[safety::loop_invariant(true)]
23192322
loop {
23202323
if (exp & 1) == 1 {
23212324
acc = acc.wrapping_mul(base);

library/core/src/num/saturating.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
//! Definitions of `Saturating<T>`.
22
33
use crate::fmt;
4+
#[cfg(kani)]
5+
use crate::kani;
46
use crate::ops::{
57
Add, AddAssign, BitAnd, BitAndAssign, BitOr, BitOrAssign, BitXor, BitXorAssign, Div, DivAssign,
68
Mul, MulAssign, Neg, Not, Rem, RemAssign, Sub, SubAssign,
@@ -37,6 +39,14 @@ use crate::ops::{
3739
#[rustc_diagnostic_item = "Saturating"]
3840
pub struct Saturating<T>(#[stable(feature = "saturating_int_impl", since = "1.74.0")] pub T);
3941

42+
#[cfg(kani)]
43+
#[stable(feature = "saturating_int_impl", since = "1.74.0")]
44+
impl<T: kani::Arbitrary> kani::Arbitrary for Saturating<T> {
45+
fn any() -> Self {
46+
Self { 0: kani::any() }
47+
}
48+
}
49+
4050
#[stable(feature = "saturating_int_impl", since = "1.74.0")]
4151
impl<T: fmt::Debug> fmt::Debug for Saturating<T> {
4252
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {

library/core/src/num/uint_macros.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1780,6 +1780,7 @@ macro_rules! uint_impl {
17801780
let mut base = self;
17811781
let mut acc: Self = 1;
17821782

1783+
#[safety::loop_invariant(true)]
17831784
loop {
17841785
if (exp & 1) == 1 {
17851786
acc = try_opt!(acc.checked_mul(base));
@@ -2349,6 +2350,7 @@ macro_rules! uint_impl {
23492350
let mut acc: Self = 1;
23502351

23512352
if intrinsics::is_val_statically_known(exp) {
2353+
#[safety::loop_invariant(exp>=1)]
23522354
while exp > 1 {
23532355
if (exp & 1) == 1 {
23542356
acc = acc.wrapping_mul(base);
@@ -2366,6 +2368,7 @@ macro_rules! uint_impl {
23662368
// at compile time. We can't use the same code for the constant
23672369
// exponent case because LLVM is currently unable to unroll
23682370
// this loop.
2371+
#[safety::loop_invariant(true)]
23692372
loop {
23702373
if (exp & 1) == 1 {
23712374
acc = acc.wrapping_mul(base);
@@ -3044,6 +3047,7 @@ macro_rules! uint_impl {
30443047
// Scratch space for storing results of overflowing_mul.
30453048
let mut r;
30463049

3050+
#[safety::loop_invariant(true)]
30473051
loop {
30483052
if (exp & 1) == 1 {
30493053
r = acc.overflowing_mul(base);

library/core/src/num/wrapping.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
//! Definitions of `Wrapping<T>`.
22
33
use crate::fmt;
4+
#[cfg(kani)]
5+
use crate::kani;
46
use crate::ops::{
57
Add, AddAssign, BitAnd, BitAndAssign, BitOr, BitOrAssign, BitXor, BitXorAssign, Div, DivAssign,
68
Mul, MulAssign, Neg, Not, Rem, RemAssign, Shl, ShlAssign, Shr, ShrAssign, Sub, SubAssign,
@@ -42,6 +44,14 @@ use crate::ops::{
4244
#[rustc_diagnostic_item = "Wrapping"]
4345
pub struct Wrapping<T>(#[stable(feature = "rust1", since = "1.0.0")] pub T);
4446

47+
#[cfg(kani)]
48+
#[stable(feature = "rust1", since = "1.0.0")]
49+
impl<T: kani::Arbitrary> kani::Arbitrary for Wrapping<T> {
50+
fn any() -> Self {
51+
Self { 0: kani::any() }
52+
}
53+
}
54+
4555
#[stable(feature = "rust1", since = "1.0.0")]
4656
impl<T: fmt::Debug> fmt::Debug for Wrapping<T> {
4757
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {

library/core/src/slice/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2814,7 +2814,7 @@ impl<T> [T] {
28142814
let half = size / 2;
28152815
let mid = base + half;
28162816

2817-
// SAFETY: the call is made safe by the following inconstants:
2817+
// SAFETY: the call is made safe by the following invariants:
28182818
// - `mid >= 0`: by definition
28192819
// - `mid < size`: `mid = size / 2 + size / 4 + size / 8 ...`
28202820
let cmp = f(unsafe { self.get_unchecked(mid) });

library/coretests/tests/ffi/cstr.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,9 @@ fn compares_as_u8s() {
1313
assert_eq!(Ord::cmp(a, b), Ord::cmp(a_bytes, b_bytes));
1414
assert_eq!(PartialOrd::partial_cmp(a, b), PartialOrd::partial_cmp(a_bytes, b_bytes));
1515
}
16+
17+
#[test]
18+
fn debug() {
19+
let s = c"abc\x01\x02\n\xE2\x80\xA6\xFF";
20+
assert_eq!(format!("{s:?}"), r#""abc\x01\x02\n\xe2\x80\xa6\xff""#);
21+
}

library/portable-simd/crates/core_simd/src/vector.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ use crate::simd::{
55
ptr::{SimdConstPtr, SimdMutPtr},
66
};
77

8+
#[cfg(kani)]
9+
use crate::kani;
10+
811
/// A SIMD vector with the shape of `[T; N]` but the operations of `T`.
912
///
1013
/// `Simd<T, N>` supports the operators (+, *, etc.) that `T` does in "elementwise" fashion.
@@ -100,6 +103,7 @@ use crate::simd::{
100103
// avoided, as it will likely become illegal on `#[repr(simd)]` structs in the future. It also
101104
// causes rustc to emit illegal LLVM IR in some cases.
102105
#[repr(simd, packed)]
106+
#[cfg_attr(kani, derive(kani::Arbitrary))]
103107
pub struct Simd<T, const N: usize>([T; N])
104108
where
105109
LaneCount<N>: SupportedLaneCount,

library/std/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ cfg-if = { version = "1.0", features = ['rustc-dep-of-std'] }
1818
panic_unwind = { path = "../panic_unwind", optional = true }
1919
panic_abort = { path = "../panic_abort" }
2020
core = { path = "../core", public = true }
21-
compiler_builtins = { version = "=0.1.155" }
21+
compiler_builtins = { version = "=0.1.156" }
2222
unwind = { path = "../unwind" }
2323
hashbrown = { version = "0.15", default-features = false, features = [
2424
'rustc-dep-of-std',
@@ -36,7 +36,7 @@ miniz_oxide = { version = "0.8.0", optional = true, default-features = false }
3636
addr2line = { version = "0.24.0", optional = true, default-features = false }
3737

3838
[target.'cfg(not(all(windows, target_env = "msvc")))'.dependencies]
39-
libc = { version = "0.2.171", default-features = false, features = [
39+
libc = { version = "0.2.172", default-features = false, features = [
4040
'rustc-dep-of-std',
4141
], public = true }
4242

0 commit comments

Comments
 (0)