Skip to content

Commit 298002d

Browse files
authored
Fix issue with niches on signed values (rust-lang#1542)
1 parent 7e84b00 commit 298002d

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

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

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1308,13 +1308,19 @@ impl<'tcx> GotocCtx<'tcx> {
13081308
/// where "-" is wrapping subtraction, i.e., the result should be interpreted as
13091309
/// an unsigned value (2's complement).
13101310
fn wrapping_sub(expr: &Expr, constant: u64) -> Expr {
1311-
if constant == 0 {
1312-
// No need to subtract.
1311+
let unsigned_expr = if expr.typ().is_pointer() {
13131312
expr.clone()
13141313
} else {
13151314
let unsigned = expr.typ().to_unsigned().unwrap();
1316-
let constant = Expr::int_constant(constant, unsigned.clone());
1317-
expr.clone().cast_to(unsigned).sub(constant)
1315+
expr.clone().cast_to(unsigned)
1316+
};
1317+
if constant == 0 {
1318+
// No need to subtract.
1319+
// But we still need to make sure we return an unsigned value.
1320+
unsigned_expr
1321+
} else {
1322+
let constant = Expr::int_constant(constant, unsigned_expr.typ().clone());
1323+
unsigned_expr.sub(constant)
13181324
}
13191325
}
13201326

tests/kani/Arbitrary/nonzero_fixme.rs renamed to tests/kani/Arbitrary/nonzero.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
// SPDX-License-Identifier: Apache-2.0 OR MIT
33
//
44
//! Ensure that kani::any behaves correcty with NonZero types.
5-
//! This is currently failing due to some issue in the niche optimization.
6-
//! See <https://github.com/model-checking/kani/issues/1533> for more details.
75
86
use std::num::*;
97

0 commit comments

Comments
 (0)