Skip to content

Update CBMC dependency to 6.5.0 #3936

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

Merged
merged 2 commits into from
Mar 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
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
11 changes: 0 additions & 11 deletions cprover_bindings/src/goto_program/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,6 @@ pub enum BuiltinFn {
Rintf,
Round,
Roundf,
RoundToIntegralF,
RoundToIntegral,
Sin,
Sinf,
Sqrt,
Expand Down Expand Up @@ -125,9 +123,6 @@ impl Display for BuiltinFn {
Rintf => "rintf",
Round => "round",
Roundf => "roundf",
// TODO remove the sort_of prefix once we move up from CBMC 6.4.1
RoundToIntegralF => "__sort_of_CPROVER_round_to_integralf",
RoundToIntegral => "__sort_of_CPROVER_round_to_integral",
Sin => "sin",
Sinf => "sinf",
Sqrt => "sqrt",
Expand Down Expand Up @@ -193,8 +188,6 @@ impl BuiltinFn {
Rintf => vec![Type::float()],
Round => vec![Type::double()],
Roundf => vec![Type::float()],
RoundToIntegralF => vec![Type::c_int(), Type::float()],
RoundToIntegral => vec![Type::c_int(), Type::double()],
Sin => vec![Type::double()],
Sinf => vec![Type::float()],
Sqrt => vec![Type::double()],
Expand Down Expand Up @@ -259,8 +252,6 @@ impl BuiltinFn {
Rintf => Type::float(),
Round => Type::double(),
Roundf => Type::float(),
RoundToIntegralF => Type::float(),
RoundToIntegral => Type::double(),
Sin => Type::double(),
Sinf => Type::float(),
Sqrt => Type::double(),
Expand Down Expand Up @@ -325,8 +316,6 @@ impl BuiltinFn {
Rintf,
Round,
Roundf,
RoundToIntegralF,
RoundToIntegral,
Sin,
Sinf,
Sqrt,
Expand Down
12 changes: 12 additions & 0 deletions cprover_bindings/src/goto_program/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ pub enum BinaryOperator {
Bitxor,
Div,
Equal,
FloatbvRoundToIntegral,
Ge,
Gt,
IeeeFloatEqual,
Expand Down Expand Up @@ -1029,6 +1030,7 @@ impl Expr {
"vector comparison operators must be typechecked by `typecheck_vector_cmp_expr`"
)
}
FloatbvRoundToIntegral => lhs.typ.is_floating_point() && rhs.typ.is_integer(),
}
}

Expand Down Expand Up @@ -1069,6 +1071,11 @@ impl Expr {
"return type for vector comparison operators depends on the place type"
)
}
FloatbvRoundToIntegral => {
unreachable!(
"return type for float-to-integer rounding operator depends on the place type"
)
}
}
}

Expand Down Expand Up @@ -1311,6 +1318,11 @@ impl Expr {
let cmp = self.clone().gt(e.clone());
cmp.ternary(self, e)
}

/// floating-point to integer rounding
pub fn floatbv_round_to_integral(f: Expr, rm: Expr, ret_typ: Type) -> Expr {
expr!(BinOp { op: FloatbvRoundToIntegral, lhs: f, rhs: rm }, ret_typ)
}
}

/// Constructors for self operations
Expand Down
2 changes: 2 additions & 0 deletions cprover_bindings/src/irep/irep_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -835,6 +835,7 @@ pub enum IrepId {
VectorLe,
VectorGt,
VectorLt,
FloatbvRoundToIntegral,
}

impl IrepId {
Expand Down Expand Up @@ -1717,6 +1718,7 @@ impl Display for IrepId {
IrepId::VectorLe => "vector-<=",
IrepId::VectorGt => "vector->",
IrepId::VectorLt => "vector-<",
IrepId::FloatbvRoundToIntegral => "floatbv_round_to_integral",
};
write!(f, "{s}")
}
Expand Down
1 change: 1 addition & 0 deletions cprover_bindings/src/irep/to_irep.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ impl ToIrepId for BinaryOperator {
BinaryOperator::Bitxor => IrepId::Bitxor,
BinaryOperator::Div => IrepId::Div,
BinaryOperator::Equal => IrepId::Equal,
BinaryOperator::FloatbvRoundToIntegral => IrepId::FloatbvRoundToIntegral,
BinaryOperator::Ge => IrepId::Ge,
BinaryOperator::Gt => IrepId::Gt,
BinaryOperator::IeeeFloatEqual => IrepId::IeeeFloatEqual,
Expand Down
35 changes: 10 additions & 25 deletions kani-compiler/src/codegen_cprover_gotoc/codegen/intrinsic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -427,20 +427,9 @@ impl GotocCtx<'_> {
Intrinsic::RotateRight => codegen_intrinsic_binop!(ror),
Intrinsic::RoundF32 => codegen_simple_intrinsic!(Roundf),
Intrinsic::RoundF64 => codegen_simple_intrinsic!(Round),
Intrinsic::RoundTiesEvenF32 => self.codegen_round_to_integral(
BuiltinFn::RoundToIntegralF,
cbmc::RoundingMode::ToNearest,
fargs,
place,
loc,
),
Intrinsic::RoundTiesEvenF64 => self.codegen_round_to_integral(
BuiltinFn::RoundToIntegral,
cbmc::RoundingMode::ToNearest,
fargs,
place,
loc,
),
Intrinsic::RoundTiesEvenF32 | Intrinsic::RoundTiesEvenF64 => {
self.codegen_round_to_integral(cbmc::RoundingMode::ToNearest, fargs, place, loc)
}
Intrinsic::SaturatingAdd => codegen_intrinsic_binop_with_mm!(saturating_add),
Intrinsic::SaturatingSub => codegen_intrinsic_binop_with_mm!(saturating_sub),
Intrinsic::SinF32 => codegen_simple_intrinsic!(Sinf),
Expand Down Expand Up @@ -648,24 +637,20 @@ impl GotocCtx<'_> {
dividend_is_int_min.and(divisor_is_minus_one).not()
}

// Builds a call to the round_to_integral CPROVER function with specified cbmc::RoundingMode.
// Builds a floatbv_round_to_integral expression with specified cbmc::RoundingMode.
fn codegen_round_to_integral(
&mut self,
function: BuiltinFn,
rounding_mode: cbmc::RoundingMode,
mut fargs: Vec<Expr>,
place: &Place,
loc: Location,
) -> Stmt {
assert!(function == BuiltinFn::RoundToIntegralF || function == BuiltinFn::RoundToIntegral);
let mm = self.symbol_table.machine_model();
fargs.insert(0, Expr::int_constant(rounding_mode, Type::c_int()));
let casted_fargs = Expr::cast_arguments_to_target_equivalent_function_parameter_types(
&function.as_expr(),
fargs,
mm,
);
let expr = function.call(casted_fargs, loc);
let place_ty = self.place_ty_stable(place);
let result_type = self.codegen_ty_stable(place_ty);
let f = fargs.remove(0);
assert!(fargs.is_empty());
let rm = Expr::int_constant(rounding_mode, Type::c_int());
let expr = Expr::floatbv_round_to_integral(f, rm, result_type);
self.codegen_expr_to_place_stable(place, expr, loc)
}

Expand Down
4 changes: 2 additions & 2 deletions kani-dependencies
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
CBMC_MAJOR="6"
CBMC_MINOR="4"
CBMC_VERSION="6.4.1"
CBMC_MINOR="5"
CBMC_VERSION="6.5.0"

KISSAT_VERSION="4.0.1"
2 changes: 1 addition & 1 deletion scripts/setup/macos/install_cbmc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ fi
# Install CBMC for macOS from CBMC tap
# https://github.com/diffblue/cbmc/blob/develop/doc/ADR/homebrew_tap.md
brew tap diffblue/cbmc
brew install diffblue/cbmc/cbmc@${CBMC_VERSION}
brew install --overwrite diffblue/cbmc/cbmc@${CBMC_VERSION}
Loading