Skip to content

Commit 12105bc

Browse files
committed
Fix pointer comparison
1 parent af28dec commit 12105bc

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

src/int.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -389,18 +389,22 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> {
389389
};
390390
self.context.new_comparison(None, op, cmp, self.context.new_rvalue_from_int(self.int_type, limit))
391391
}
392+
else if a_type.get_pointee().is_some() && b_type.get_pointee().is_some() {
393+
// NOTE: gcc cannot compare pointers to different objects, but rustc does that, so cast them to usize.
394+
lhs = self.context.new_bitcast(None, lhs, self.usize_type);
395+
rhs = self.context.new_bitcast(None, rhs, self.usize_type);
396+
self.context.new_comparison(None, op.to_gcc_comparison(), lhs, rhs)
397+
}
392398
else {
393-
let left_type = lhs.get_type();
394-
let right_type = rhs.get_type();
395-
if left_type != right_type {
399+
if a_type != b_type {
396400
// NOTE: because libgccjit cannot compare function pointers.
397-
if left_type.dyncast_function_ptr_type().is_some() && right_type.dyncast_function_ptr_type().is_some() {
401+
if a_type.dyncast_function_ptr_type().is_some() && b_type.dyncast_function_ptr_type().is_some() {
398402
lhs = self.context.new_cast(None, lhs, self.usize_type.make_pointer());
399403
rhs = self.context.new_cast(None, rhs, self.usize_type.make_pointer());
400404
}
401405
// NOTE: hack because we try to cast a vector type to the same vector type.
402-
else if format!("{:?}", left_type) != format!("{:?}", right_type) {
403-
rhs = self.context.new_cast(None, rhs, left_type);
406+
else if format!("{:?}", a_type) != format!("{:?}", b_type) {
407+
rhs = self.context.new_cast(None, rhs, a_type);
404408
}
405409
}
406410
self.context.new_comparison(None, op.to_gcc_comparison(), lhs, rhs)

0 commit comments

Comments
 (0)