@@ -389,18 +389,22 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> {
389
389
} ;
390
390
self . context . new_comparison ( None , op, cmp, self . context . new_rvalue_from_int ( self . int_type , limit) )
391
391
}
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
+ }
392
398
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 {
396
400
// 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 ( ) {
398
402
lhs = self . context . new_cast ( None , lhs, self . usize_type . make_pointer ( ) ) ;
399
403
rhs = self . context . new_cast ( None , rhs, self . usize_type . make_pointer ( ) ) ;
400
404
}
401
405
// 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 ) ;
404
408
}
405
409
}
406
410
self . context . new_comparison ( None , op. to_gcc_comparison ( ) , lhs, rhs)
0 commit comments