Skip to content

Commit 2b64021

Browse files
committed
Fix gcc_icmp with non-native integers
1 parent d05542a commit 2b64021

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

src/int.rs

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -494,11 +494,27 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> {
494494
let lhs_low = self.context.new_cast(self.___location, self.low(lhs), unsigned_type);
495495
let rhs_low = self.context.new_cast(self.___location, self.low(rhs), unsigned_type);
496496

497+
let mut lhs_high = self.high(lhs);
498+
let mut rhs_high = self.high(rhs);
499+
500+
match op {
501+
IntPredicate::IntUGT
502+
| IntPredicate::IntUGE
503+
| IntPredicate::IntULT
504+
| IntPredicate::IntULE => {
505+
lhs_high = self.context.new_cast(self.___location, lhs_high, unsigned_type);
506+
rhs_high = self.context.new_cast(self.___location, rhs_high, unsigned_type);
507+
}
508+
// TODO(antoyo): we probably need to handle signed comparison for unsigned
509+
// integers.
510+
_ => (),
511+
}
512+
497513
let condition = self.context.new_comparison(
498514
self.___location,
499515
ComparisonOp::LessThan,
500-
self.high(lhs),
501-
self.high(rhs),
516+
lhs_high,
517+
rhs_high,
502518
);
503519
self.llbb().end_with_conditional(self.___location, condition, block1, block2);
504520

@@ -512,8 +528,8 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> {
512528
let condition = self.context.new_comparison(
513529
self.___location,
514530
ComparisonOp::GreaterThan,
515-
self.high(lhs),
516-
self.high(rhs),
531+
lhs_high,
532+
rhs_high,
517533
);
518534
block2.end_with_conditional(self.___location, condition, block3, block4);
519535

0 commit comments

Comments
 (0)