Skip to content

Commit e3998b2

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

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

Diff for: src/int.rs

+13
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,18 @@ 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+
if !a_type.is_vector() {
451+
let unsigned_type = a_type.to_unsigned(&self.cx);
452+
lhs = self.context.new_cast(None, lhs, unsigned_type);
453+
rhs = self.context.new_cast(None, rhs, unsigned_type);
454+
}
455+
},
456+
// TODO(antoyo): we probably need to handle signed comparison for unsigned
457+
// integers.
458+
_ => (),
459+
}
447460
self.context.new_comparison(None, op.to_gcc_comparison(), lhs, rhs)
448461
}
449462
}

0 commit comments

Comments
 (0)