diff options
| author | Antoni Boucher <bouanto@zoho.com> | 2023-10-12 17:06:29 -0400 |
|---|---|---|
| committer | Antoni Boucher <bouanto@zoho.com> | 2023-10-13 07:50:42 -0400 |
| commit | e3998b2d4633705eb4da278dcf5127f273e388ea (patch) | |
| tree | d04597ec3e9f8892a50fb4e4e8427417fcae86aa /src | |
| parent | 100dfced2067925df97cf203d696559be5c828b9 (diff) | |
| download | rust-e3998b2d4633705eb4da278dcf5127f273e388ea.tar.gz rust-e3998b2d4633705eb4da278dcf5127f273e388ea.zip | |
Handle unsigned comparison for signed integers
Diffstat (limited to 'src')
| -rw-r--r-- | src/int.rs | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/src/int.rs b/src/int.rs index 58e0dd56f38..5719f6a8cf5 100644 --- a/src/int.rs +++ b/src/int.rs @@ -415,6 +415,7 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> { IntPredicate::IntNE => { return self.context.new_comparison(None, ComparisonOp::NotEquals, cmp, self.context.new_rvalue_one(self.int_type)); }, + // TODO(antoyo): cast to u128 for unsigned comparison. See below. IntPredicate::IntUGT => (ComparisonOp::Equals, 2), IntPredicate::IntUGE => (ComparisonOp::GreaterThanEquals, 1), IntPredicate::IntULT => (ComparisonOp::Equals, 0), @@ -444,6 +445,18 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> { rhs = self.context.new_cast(None, rhs, a_type); } } + match op { + IntPredicate::IntUGT | IntPredicate::IntUGE | IntPredicate::IntULT | IntPredicate::IntULE => { + if !a_type.is_vector() { + let unsigned_type = a_type.to_unsigned(&self.cx); + lhs = self.context.new_cast(None, lhs, unsigned_type); + rhs = self.context.new_cast(None, rhs, unsigned_type); + } + }, + // TODO(antoyo): we probably need to handle signed comparison for unsigned + // integers. + _ => (), + } self.context.new_comparison(None, op.to_gcc_comparison(), lhs, rhs) } } |
