Skip to content

Commit efd081b

Browse files
committed
Handle unsigned comparison for signed integers
1 parent 100dfce commit efd081b

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

Diff for: src/int.rs

+11
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,7 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> {
415415
IntPredicate::IntNE => {
416416
return self.context.new_comparison(None, ComparisonOp::NotEquals, cmp, self.context.new_rvalue_one(self.int_type));
417417
},
418+
// TODO(antoyo): cast to u128 for unsigned comparison. See below.
418419
IntPredicate::IntUGT => (ComparisonOp::Equals, 2),
419420
IntPredicate::IntUGE => (ComparisonOp::GreaterThanEquals, 1),
420421
IntPredicate::IntULT => (ComparisonOp::Equals, 0),
@@ -444,6 +445,16 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> {
444445
rhs = self.context.new_cast(None, rhs, a_type);
445446
}
446447
}
448+
match op {
449+
IntPredicate::IntUGT | IntPredicate::IntUGE | IntPredicate::IntULT | IntPredicate::IntULE => {
450+
let unsigned_type = a_type.to_unsigned(&self.cx);
451+
lhs = self.context.new_cast(None, lhs, unsigned_type);
452+
rhs = self.context.new_cast(None, rhs, unsigned_type);
453+
},
454+
// TODO(antoyo): we probably need to handle signed comparison for unsigned
455+
// integers.
456+
_ => (),
457+
}
447458
self.context.new_comparison(None, op.to_gcc_comparison(), lhs, rhs)
448459
}
449460
}

0 commit comments

Comments
 (0)