@@ -303,6 +303,23 @@ impl<'ll, 'tcx, 'a> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
303
303
if changed {
304
304
v = transmute_llval ( self . llbuilder , self . cx , v, new_ty) ;
305
305
}
306
+ // Get the return type.
307
+ let sig = llvm:: LLVMGetElementType ( self . val_ty ( self . llfn ( ) ) ) ;
308
+ let return_ty = llvm:: LLVMGetReturnType ( sig) ;
309
+ // Check if new_ty & return_ty are different pointers.
310
+ // FIXME: get rid of this nonsense once we are past LLVM 7 and don't have
311
+ // to suffer from typed pointers.
312
+ if return_ty != new_ty
313
+ && llvm:: LLVMRustGetTypeKind ( return_ty) == llvm:: TypeKind :: Pointer
314
+ && llvm:: LLVMRustGetTypeKind ( new_ty) == llvm:: TypeKind :: Pointer
315
+ {
316
+ v = llvm:: LLVMBuildBitCast (
317
+ self . llbuilder ,
318
+ v,
319
+ return_ty,
320
+ c"return pointer adjust" . as_ptr ( ) ,
321
+ ) ;
322
+ }
306
323
llvm:: LLVMBuildRet ( self . llbuilder , v) ;
307
324
}
308
325
}
@@ -923,9 +940,17 @@ impl<'ll, 'tcx, 'a> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
923
940
}
924
941
925
942
/* Comparisons */
926
- fn icmp ( & mut self , op : IntPredicate , lhs : & ' ll Value , rhs : & ' ll Value ) -> & ' ll Value {
943
+ fn icmp ( & mut self , op : IntPredicate , mut lhs : & ' ll Value , rhs : & ' ll Value ) -> & ' ll Value {
927
944
trace ! ( "Icmp lhs: `{:?}`, rhs: `{:?}`" , lhs, rhs) ;
928
-
945
+ // FIXME(FractalFir): Once again, a bunch of nosense to make the LLVM typed pointers happy.
946
+ // Get rid of this as soon as we move past typed pointers.
947
+ let lhs_ty = self . val_ty ( lhs) ;
948
+ let rhs_ty = self . val_ty ( rhs) ;
949
+ if lhs_ty != rhs_ty {
950
+ lhs = unsafe {
951
+ llvm:: LLVMBuildBitCast ( self . llbuilder , lhs, rhs_ty, c"icmp_cast" . as_ptr ( ) )
952
+ } ;
953
+ }
929
954
unsafe {
930
955
let op = llvm:: IntPredicate :: from_generic ( op) ;
931
956
llvm:: LLVMBuildICmp ( self . llbuilder , op as c_uint , lhs, rhs, unnamed ( ) )
0 commit comments