Skip to content

Commit fff9316

Browse files
authored
Upgrade toolchain to 2025-08-10 (#4289)
Culprit PR: rust-lang/rust#144192 The upstream PR adds a new generic argument `U` for some atomic intrinsics, so our tests need to include those. Solely changing the tests to infer the generic argument makes compilation succeed, but [this `atomic_xor` harness](https://github.com/model-checking/kani/blob/41849d25092483d1dd92d472cc8c457908903927/tests/kani/Intrinsics/Atomic/Stable/AtomicPtr/main.rs#L70) fails with this error: ``` thread 'rustc' (1068557) panicked at cprover_bindings/src/goto_program/expr.rs:1147:9: BinaryOperation Expression does not typecheck Bitor Expr { value: Dereference(Expr { value: Symbol { identifier: "_RINvNtNtCslIVxtpUQXYK_4core4sync6atomic9atomic_orOxjECs63P9ci4LCSm_4main::1::var_1::dst" }, typ: Pointer { typ: Pointer { typ: Signedbv { width: 64 } } }, location: None, size_of_annotation: None }), typ: Pointer { typ: Signedbv { width: 64 } }, location: None, size_of_annotation: None } Expr { value: Symbol { identifier: "_RINvNtNtCslIVxtpUQXYK_4core4sync6atomic9atomic_orOxjECs63P9ci4LCSm_4main::1::var_2::val" }, typ: CInteger(SizeT), location: None, size_of_annotation: None } note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace Kani unexpectedly panicked during compilation. Please file an issue here: https://github.com/model-checking/kani/issues/new?labels=bug&template=bug_report.md [Kani] current codegen item: codegen_function: std::sync::atomic::atomic_or::<*mut i64, usize> _RINvNtNtCslIVxtpUQXYK_4core4sync6atomic9atomic_orOxjECs63P9ci4LCSm_4main [Kani] current codegen location: Loc { file: "/Users/cmzech/.rustup/toolchains/nightly-2025-08-10-aarch64-apple-darwin/lib/rustlib/src/rust/library/core/src/sync/atomic.rs", function: None, start_line: 4183, start_col: Some(1), end_line: 4183, end_col: Some(81), pragmas: [] } ``` This happens because `codegen_atomic_binop` currently handles the case where `T` is a pointer by checking if `var2` is a pointer, then casting `var1` and `var2` to `size_t`: https://github.com/model-checking/kani/blob/41849d25092483d1dd92d472cc8c457908903927/kani-compiler/src/codegen_cprover_gotoc/codegen/intrinsic.rs#L241-L245 But rust-lang/rust#144192 makes this change to `fetch_xor`: ```diff diff --git a/library/core/src/sync/atomic.rs b/library/core/src/sync/atomic.rs index 546f3d91a80..44a6895f90a 100644 --- a/library/core/src/sync/atomic.rs +++ b/library/core/src/sync/atomic.rs pub fn fetch_xor(&self, val: usize, order: Ordering) -> *mut T { // SAFETY: data races are prevented by atomic intrinsics. - unsafe { atomic_xor(self.p.get(), core::ptr::without_provenance_mut(val), order).cast() } + unsafe { atomic_xor(self.p.get(), val, order).cast() } } ``` since `var2` is no longer a pointer, we hit the else case, and thus the solution from #3047 no longer takes effect. The solution is to instead check if `var1` is a pointer. We also remove the cast of `var2` to a size_t, since per the new documentation: > `U` must be the same as `T` if that is an integer type, or `usize` if `T` is a pointer type. `U` is guaranteed to be a `usize` if `T` is a pointer, and we [codegen usizes as `size_t`s already](https://github.com/model-checking/kani/blob/41849d25092483d1dd92d472cc8c457908903927/kani-compiler/src/codegen_cprover_gotoc/codegen/typ.rs#L713 ). Resolves #4284 By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 and MIT licenses.
1 parent ef1fdb1 commit fff9316

File tree

9 files changed

+44
-42
lines changed

9 files changed

+44
-42
lines changed

kani-compiler/src/codegen_cprover_gotoc/codegen/intrinsic.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -217,14 +217,16 @@ impl GotocCtx<'_> {
217217
// -------------------------
218218
//
219219
// In fetch functions of atomic_ptr such as https://doc.rust-lang.org/std/sync/atomic/struct.AtomicPtr.html#method.fetch_byte_add,
220-
// the type of var2 can be pointer (invalid_mut).
221-
// In such case, atomic binops are transformed as follows to avoid typecheck failure.
220+
// the type of var1 is a pointer.
221+
// In this case, var2 is guaranteed to be a usize,
222+
// c.f. https://github.com/rust-lang/rust/blob/a1531335fe2807715fff569904d99602022643a7/library/core/src/intrinsics/mod.rs#L203
223+
// We transform such binops as follows to avoid typecheck failure.
222224
// -------------------------
223225
// var = atomic_op(var1, var2)
224226
// -------------------------
225227
// unsigned char tmp;
226228
// tmp = *var1;
227-
// *var1 = (typeof var1)op((size_t)*var1, (size_t)var2);
229+
// *var1 = (typeof var1)op((size_t)*var1, var2);
228230
// var = tmp;
229231
// -------------------------
230232
//
@@ -238,9 +240,9 @@ impl GotocCtx<'_> {
238240
let (tmp, decl_stmt) =
239241
self.decl_temp_variable(var1.typ().clone(), Some(var1.to_owned()), loc);
240242
let var2 = fargs.remove(0);
241-
let op_expr = if var2.typ().is_pointer() {
243+
let op_expr = if var1.typ().is_pointer() {
242244
(var1.clone().cast_to(Type::c_size_t()))
243-
.$op(var2.cast_to(Type::c_size_t()))
245+
.$op(var2)
244246
.with_location(loc)
245247
.cast_to(var1.typ().clone())
246248
} else {

rust-toolchain.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
# SPDX-License-Identifier: Apache-2.0 OR MIT
33

44
[toolchain]
5-
channel = "nightly-2025-08-09"
5+
channel = "nightly-2025-08-10"
66
components = ["llvm-tools", "rustc-dev", "rust-src", "rustfmt"]

tests/kani/Intrinsics/Atomic/Stable/AtomicPtr/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
// Specifically, it checks that Kani correctly handles atomic_ptr's fetch methods, in which the second argument is a pointer type.
66
// These methods were not correctly handled as explained in https://github.com/model-checking/kani/issues/3042.
77

8-
#![feature(strict_provenance_atomic_ptr, strict_provenance)]
8+
#![feature(strict_provenance_atomic_ptr)]
99
use std::sync::atomic::{AtomicPtr, Ordering};
1010

1111
#[kani::proof]

tests/kani/Intrinsics/Atomic/Unstable/AtomicAdd/main.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@ fn main() {
2525
let c = 1 as u8;
2626

2727
unsafe {
28-
let x1 = atomic_xadd::<_, { AtomicOrdering::SeqCst }>(ptr_a1, b);
29-
let x2 = atomic_xadd::<_, { AtomicOrdering::Acquire }>(ptr_a2, b);
30-
let x3 = atomic_xadd::<_, { AtomicOrdering::AcqRel }>(ptr_a3, b);
31-
let x4 = atomic_xadd::<_, { AtomicOrdering::Release }>(ptr_a4, b);
32-
let x5 = atomic_xadd::<_, { AtomicOrdering::Relaxed }>(ptr_a5, b);
28+
let x1 = atomic_xadd::<_, _, { AtomicOrdering::SeqCst }>(ptr_a1, b);
29+
let x2 = atomic_xadd::<_, _, { AtomicOrdering::Acquire }>(ptr_a2, b);
30+
let x3 = atomic_xadd::<_, _, { AtomicOrdering::AcqRel }>(ptr_a3, b);
31+
let x4 = atomic_xadd::<_, _, { AtomicOrdering::Release }>(ptr_a4, b);
32+
let x5 = atomic_xadd::<_, _, { AtomicOrdering::Relaxed }>(ptr_a5, b);
3333

3434
assert!(x1 == 0);
3535
assert!(x2 == 0);

tests/kani/Intrinsics/Atomic/Unstable/AtomicAnd/main.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ fn main() {
2424
let b = 0 as u8;
2525

2626
unsafe {
27-
let x1 = atomic_and::<_, { AtomicOrdering::SeqCst }>(ptr_a1, b);
28-
let x2 = atomic_and::<_, { AtomicOrdering::Acquire }>(ptr_a2, b);
29-
let x3 = atomic_and::<_, { AtomicOrdering::AcqRel }>(ptr_a3, b);
30-
let x4 = atomic_and::<_, { AtomicOrdering::Release }>(ptr_a4, b);
31-
let x5 = atomic_and::<_, { AtomicOrdering::Relaxed }>(ptr_a5, b);
27+
let x1 = atomic_and::<_, _, { AtomicOrdering::SeqCst }>(ptr_a1, b);
28+
let x2 = atomic_and::<_, _, { AtomicOrdering::Acquire }>(ptr_a2, b);
29+
let x3 = atomic_and::<_, _, { AtomicOrdering::AcqRel }>(ptr_a3, b);
30+
let x4 = atomic_and::<_, _, { AtomicOrdering::Release }>(ptr_a4, b);
31+
let x5 = atomic_and::<_, _, { AtomicOrdering::Relaxed }>(ptr_a5, b);
3232

3333
assert!(x1 == 1);
3434
assert!(x2 == 1);

tests/kani/Intrinsics/Atomic/Unstable/AtomicNand/main.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ fn main() {
2424
let b = u8::MAX as u8;
2525

2626
unsafe {
27-
let x1 = atomic_nand::<_, { AtomicOrdering::SeqCst }>(ptr_a1, b);
28-
let x2 = atomic_nand::<_, { AtomicOrdering::Acquire }>(ptr_a2, b);
29-
let x3 = atomic_nand::<_, { AtomicOrdering::AcqRel }>(ptr_a3, b);
30-
let x4 = atomic_nand::<_, { AtomicOrdering::Release }>(ptr_a4, b);
31-
let x5 = atomic_nand::<_, { AtomicOrdering::Relaxed }>(ptr_a5, b);
27+
let x1 = atomic_nand::<_, _, { AtomicOrdering::SeqCst }>(ptr_a1, b);
28+
let x2 = atomic_nand::<_, _, { AtomicOrdering::Acquire }>(ptr_a2, b);
29+
let x3 = atomic_nand::<_, _, { AtomicOrdering::AcqRel }>(ptr_a3, b);
30+
let x4 = atomic_nand::<_, _, { AtomicOrdering::Release }>(ptr_a4, b);
31+
let x5 = atomic_nand::<_, _, { AtomicOrdering::Relaxed }>(ptr_a5, b);
3232

3333
assert!(x1 == 0);
3434
assert!(x2 == 0);
@@ -42,11 +42,11 @@ fn main() {
4242
assert!(*ptr_a4 == b);
4343
assert!(*ptr_a5 == b);
4444

45-
let x1 = atomic_nand::<_, { AtomicOrdering::SeqCst }>(ptr_a1, b);
46-
let x2 = atomic_nand::<_, { AtomicOrdering::Acquire }>(ptr_a2, b);
47-
let x3 = atomic_nand::<_, { AtomicOrdering::AcqRel }>(ptr_a3, b);
48-
let x4 = atomic_nand::<_, { AtomicOrdering::Release }>(ptr_a4, b);
49-
let x5 = atomic_nand::<_, { AtomicOrdering::Relaxed }>(ptr_a5, b);
45+
let x1 = atomic_nand::<_, _, { AtomicOrdering::SeqCst }>(ptr_a1, b);
46+
let x2 = atomic_nand::<_, _, { AtomicOrdering::Acquire }>(ptr_a2, b);
47+
let x3 = atomic_nand::<_, _, { AtomicOrdering::AcqRel }>(ptr_a3, b);
48+
let x4 = atomic_nand::<_, _, { AtomicOrdering::Release }>(ptr_a4, b);
49+
let x5 = atomic_nand::<_, _, { AtomicOrdering::Relaxed }>(ptr_a5, b);
5050

5151
assert!(x1 == b);
5252
assert!(x2 == b);

tests/kani/Intrinsics/Atomic/Unstable/AtomicOr/main.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@ fn main() {
2525
let c = 1 as u8;
2626

2727
unsafe {
28-
let x1 = atomic_or::<_, { AtomicOrdering::SeqCst }>(ptr_a1, b);
29-
let x2 = atomic_or::<_, { AtomicOrdering::Acquire }>(ptr_a2, b);
30-
let x3 = atomic_or::<_, { AtomicOrdering::AcqRel }>(ptr_a3, b);
31-
let x4 = atomic_or::<_, { AtomicOrdering::Release }>(ptr_a4, b);
32-
let x5 = atomic_or::<_, { AtomicOrdering::Relaxed }>(ptr_a5, b);
28+
let x1 = atomic_or::<_, _, { AtomicOrdering::SeqCst }>(ptr_a1, b);
29+
let x2 = atomic_or::<_, _, { AtomicOrdering::Acquire }>(ptr_a2, b);
30+
let x3 = atomic_or::<_, _, { AtomicOrdering::AcqRel }>(ptr_a3, b);
31+
let x4 = atomic_or::<_, _, { AtomicOrdering::Release }>(ptr_a4, b);
32+
let x5 = atomic_or::<_, _, { AtomicOrdering::Relaxed }>(ptr_a5, b);
3333

3434
assert!(x1 == 1);
3535
assert!(x2 == 1);

tests/kani/Intrinsics/Atomic/Unstable/AtomicSub/main.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@ fn main() {
2525
let c = 0 as u8;
2626

2727
unsafe {
28-
let x1 = atomic_xsub::<_, { AtomicOrdering::SeqCst }>(ptr_a1, b);
29-
let x2 = atomic_xsub::<_, { AtomicOrdering::Acquire }>(ptr_a2, b);
30-
let x3 = atomic_xsub::<_, { AtomicOrdering::AcqRel }>(ptr_a3, b);
31-
let x4 = atomic_xsub::<_, { AtomicOrdering::Release }>(ptr_a4, b);
32-
let x5 = atomic_xsub::<_, { AtomicOrdering::Relaxed }>(ptr_a5, b);
28+
let x1 = atomic_xsub::<_, _, { AtomicOrdering::SeqCst }>(ptr_a1, b);
29+
let x2 = atomic_xsub::<_, _, { AtomicOrdering::Acquire }>(ptr_a2, b);
30+
let x3 = atomic_xsub::<_, _, { AtomicOrdering::AcqRel }>(ptr_a3, b);
31+
let x4 = atomic_xsub::<_, _, { AtomicOrdering::Release }>(ptr_a4, b);
32+
let x5 = atomic_xsub::<_, _, { AtomicOrdering::Relaxed }>(ptr_a5, b);
3333

3434
assert!(x1 == 1);
3535
assert!(x2 == 1);

tests/kani/Intrinsics/Atomic/Unstable/AtomicXor/main.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ fn main() {
2424
let b = 1 as u8;
2525

2626
unsafe {
27-
let x1 = atomic_xor::<_, { AtomicOrdering::SeqCst }>(ptr_a1, b);
28-
let x2 = atomic_xor::<_, { AtomicOrdering::Acquire }>(ptr_a2, b);
29-
let x3 = atomic_xor::<_, { AtomicOrdering::AcqRel }>(ptr_a3, b);
30-
let x4 = atomic_xor::<_, { AtomicOrdering::Release }>(ptr_a4, b);
31-
let x5 = atomic_xor::<_, { AtomicOrdering::Relaxed }>(ptr_a5, b);
27+
let x1 = atomic_xor::<_, _, { AtomicOrdering::SeqCst }>(ptr_a1, b);
28+
let x2 = atomic_xor::<_, _, { AtomicOrdering::Acquire }>(ptr_a2, b);
29+
let x3 = atomic_xor::<_, _, { AtomicOrdering::AcqRel }>(ptr_a3, b);
30+
let x4 = atomic_xor::<_, _, { AtomicOrdering::Release }>(ptr_a4, b);
31+
let x5 = atomic_xor::<_, _, { AtomicOrdering::Relaxed }>(ptr_a5, b);
3232

3333
assert!(x1 == 1);
3434
assert!(x2 == 1);

0 commit comments

Comments
 (0)