Skip to content
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

Fix codegen_atomic_binop for atomic_ptr #3047

Merged
merged 5 commits into from
Feb 29, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
18 changes: 8 additions & 10 deletions kani-compiler/src/codegen_cprover_gotoc/codegen/intrinsic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,9 +240,9 @@ impl<'tcx> GotocCtx<'tcx> {
// var = tmp;
// -------------------------
//
// In fetch functions of atomic_ptr, the type of var2 can be pointer (invalid_mut).
// In fetch functions of atomic_ptr such as https://doc.rust-lang.org/std/sync/atomic/struct.AtomicPtr.html#method.fetch_byte_add,
// the type of var2 can be pointer (invalid_mut).
// In such case, atomic binops are transformed as follows to avoid typecheck failure.
//
// -------------------------
// var = atomic_op(var1, var2)
// -------------------------
Expand All @@ -262,20 +262,18 @@ impl<'tcx> GotocCtx<'tcx> {
let (tmp, decl_stmt) =
self.decl_temp_variable(var1.typ().clone(), Some(var1.to_owned()), loc);
let var2 = fargs.remove(0);
let op_expr: Expr;
if var2.typ().is_pointer() {
qinheping marked this conversation as resolved.
Show resolved Hide resolved
let op_expr = (var1.clone().cast_to(Type::c_size_t()))
op_expr = (var1.clone().cast_to(Type::c_size_t()))
.$op(var2.cast_to(Type::c_size_t()))
.with_location(loc)
.cast_to(var1.typ().clone());
let assign_stmt = (var1.clone()).assign(op_expr, loc);
let res_stmt = self.codegen_expr_to_place_stable(place, tmp.clone());
Stmt::atomic_block(vec![decl_stmt, assign_stmt, res_stmt], loc)
} else {
let op_expr = (var1.clone()).$op(var2).with_location(loc);
let assign_stmt = (var1.clone()).assign(op_expr, loc);
let res_stmt = self.codegen_expr_to_place_stable(place, tmp.clone());
Stmt::atomic_block(vec![decl_stmt, assign_stmt, res_stmt], loc)
op_expr = (var1.clone()).$op(var2).with_location(loc);
}
let assign_stmt = (var1.clone()).assign(op_expr, loc);
let res_stmt = self.codegen_expr_to_place_stable(place, tmp.clone());
Stmt::atomic_block(vec![decl_stmt, assign_stmt, res_stmt], loc)
}};
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
// Copyright Kani Contributors
// SPDX-License-Identifier: Apache-2.0 OR MIT
//
//! Test atomic intrinsics through the stable interface of atomic_ptr.

qinheping marked this conversation as resolved.
Show resolved Hide resolved
#![feature(strict_provenance_atomic_ptr, strict_provenance)]
use std::sync::atomic::{AtomicPtr, Ordering};

Expand Down
Loading