Skip to content

Commit

Permalink
Fix bounded_int_trim for signed types.
Browse files Browse the repository at this point in the history
  • Loading branch information
azteca1998 committed Dec 27, 2024
1 parent 0e4b9bf commit f225bbc
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/libfuncs/bounded_int.rs
Original file line number Diff line number Diff line change
Expand Up @@ -734,9 +734,14 @@ fn build_trim<'ctx, 'this>(
// and constraining their range a single value from either the lower or upper limit. However,
// since we're returning a `BoundedInt` we need to offset its internal representation
// accordingly.
let value = if info.trimmed_value == BigInt::ZERO {
let k1 = entry.const_int_from_type(context, location, 1, value.r#type())?;
entry.append_op_result(arith::subi(value, k1, location))?
let value = if info.trimmed_value <= BigInt::ZERO {
let offset = if info.trimmed_value == BigInt::ZERO {
entry.const_int_from_type(context, location, 1, value.r#type())?
} else {
entry.const_int_from_type(context, location, &info.trimmed_value + 1, value.r#type())?
};

entry.append_op_result(arith::subi(value, offset, location))?
} else {
value
};
Expand Down

0 comments on commit f225bbc

Please sign in to comment.