diff options
| author | Antoni Boucher <bouanto@zoho.com> | 2022-09-30 17:45:31 -0400 |
|---|---|---|
| committer | Antoni Boucher <bouanto@zoho.com> | 2022-09-30 18:23:37 -0400 |
| commit | 12105bc0d7664998f8caa45252cf8e8d1c2b38fc (patch) | |
| tree | 5b9280dbc69744dbde15c735f5082f1312cdf030 | |
| parent | af28dec7d151de3e0e00928ce66d51d8aaa3fbdb (diff) | |
| download | rust-12105bc0d7664998f8caa45252cf8e8d1c2b38fc.tar.gz rust-12105bc0d7664998f8caa45252cf8e8d1c2b38fc.zip | |
Fix pointer comparison
| -rw-r--r-- | src/int.rs | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/src/int.rs b/src/int.rs index 0c5dab00466..0cf1204791d 100644 --- a/src/int.rs +++ b/src/int.rs @@ -389,18 +389,22 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> { }; self.context.new_comparison(None, op, cmp, self.context.new_rvalue_from_int(self.int_type, limit)) } + else if a_type.get_pointee().is_some() && b_type.get_pointee().is_some() { + // NOTE: gcc cannot compare pointers to different objects, but rustc does that, so cast them to usize. + lhs = self.context.new_bitcast(None, lhs, self.usize_type); + rhs = self.context.new_bitcast(None, rhs, self.usize_type); + self.context.new_comparison(None, op.to_gcc_comparison(), lhs, rhs) + } else { - let left_type = lhs.get_type(); - let right_type = rhs.get_type(); - if left_type != right_type { + if a_type != b_type { // NOTE: because libgccjit cannot compare function pointers. - if left_type.dyncast_function_ptr_type().is_some() && right_type.dyncast_function_ptr_type().is_some() { + if a_type.dyncast_function_ptr_type().is_some() && b_type.dyncast_function_ptr_type().is_some() { lhs = self.context.new_cast(None, lhs, self.usize_type.make_pointer()); rhs = self.context.new_cast(None, rhs, self.usize_type.make_pointer()); } // NOTE: hack because we try to cast a vector type to the same vector type. - else if format!("{:?}", left_type) != format!("{:?}", right_type) { - rhs = self.context.new_cast(None, rhs, left_type); + else if format!("{:?}", a_type) != format!("{:?}", b_type) { + rhs = self.context.new_cast(None, rhs, a_type); } } self.context.new_comparison(None, op.to_gcc_comparison(), lhs, rhs) |
