-
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.
Update rust toolchain to 2022-05-17 (#1209)
* Update rust toolchain to 2022-05-17 Status: Compilation succeeds but regression fails due to new intrinsic. Relevant changes: - rust-lang/rust#95837 - rust-lang/rust#95562 - rust-lang/rust#96883 * Implement new intrinsic ptr_offset_from_unsigned This new intrinsic is used in many different places in the standard library and it was failing some tests for vectors. * Apply suggestions from code review Co-authored-by: Adrian Palacios <73246657+adpaco-aws@users.noreply.github.com> * Address PR comments - Fix order of checks. - Improve error message. - Add comments to the new tests. Co-authored-by: Adrian Palacios <73246657+adpaco-aws@users.noreply.github.com>
- Loading branch information
1 parent
96c6b3b
commit 73e449c
Showing
13 changed files
with
140 additions
and
26 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
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
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
17 changes: 17 additions & 0 deletions
17
tests/expected/intrinsics/ptr_offset_from_unsigned/check_invariant_violation.rs
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,17 @@ | ||
// Copyright Kani Contributors | ||
// SPDX-License-Identifier: Apache-2.0 OR MIT | ||
//! Check that Kani correctly detects a safety violation when user tries to invoke the | ||
//! `ptr_offset_from_unsigned` intrinsic in the wrong order. | ||
#![feature(core_intrinsics)] | ||
use std::intrinsics::ptr_offset_from_unsigned; | ||
|
||
#[kani::proof] | ||
fn check_failure() { | ||
let a = [0; 5]; | ||
let ptr0: *const i32 = &a[0]; | ||
let ptr1: *const i32 = &a[1]; | ||
unsafe { | ||
let _distance = ptr_offset_from_unsigned(ptr0, ptr1); | ||
} | ||
} |
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 @@ | ||
Failed Checks: attempt to compute unsigned offset with negative distance |
32 changes: 32 additions & 0 deletions
32
tests/kani/Intrinsics/PtrOffsetFromUnsigned/check_unsigned_ptr_offset_from.rs
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,32 @@ | ||
// Copyright Kani Contributors | ||
// SPDX-License-Identifier: Apache-2.0 OR MIT | ||
//! Checks that the ptr_offset_from_unsigned intrinsic returns the expected results. | ||
#![feature(core_intrinsics)] | ||
use std::intrinsics::ptr_offset_from_unsigned; | ||
|
||
#[kani::proof] | ||
fn check_distance_i32() { | ||
let a = [0; 5]; | ||
let ptr0: *const i32 = &a[0]; | ||
let ptr1: *const i32 = &a[1]; | ||
let ptr2: *const i32 = &a[2]; | ||
unsafe { | ||
assert_eq!(ptr_offset_from_unsigned(ptr2, ptr0), 2); | ||
assert_eq!(ptr_offset_from_unsigned(ptr1, ptr0), 1); | ||
assert_eq!(ptr_offset_from_unsigned(ptr2, ptr2), 0); | ||
} | ||
} | ||
|
||
#[kani::proof] | ||
fn check_distance_i64() { | ||
let a = [0i64; 5]; | ||
let ptr0: *const i64 = &a[0]; | ||
let ptr1: *const i64 = &a[1]; | ||
let ptr2: *const i64 = &a[2]; | ||
unsafe { | ||
assert_eq!(ptr_offset_from_unsigned(ptr2, ptr0), 2); | ||
assert_eq!(ptr_offset_from_unsigned(ptr1, ptr0), 1); | ||
assert_eq!(ptr_offset_from_unsigned(ptr1, ptr1), 0); | ||
} | ||
} |
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
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