@@ -404,7 +404,7 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> {
404
404
405
405
let ret_indirect = matches ! ( fn_abi. ret. mode, PassMode :: Indirect { .. } ) ;
406
406
407
- let result = if ret_indirect {
407
+ let call = if ret_indirect {
408
408
let res_value = self . current_func ( ) . new_local ( self . location , res_type, "result_value" ) ;
409
409
let res_addr = res_value. get_address ( self . location ) ;
410
410
let res_param_type = res_type. make_pointer ( ) ;
@@ -432,8 +432,17 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> {
432
432
) ;
433
433
self . context . new_call ( self . location , func, & [ lhs, rhs, overflow_addr] )
434
434
} ;
435
-
436
- ( result, self . context . new_cast ( self . location , overflow_value, self . bool_type ) . to_rvalue ( ) )
435
+ // NOTE: we must assign the result of the operation to a variable at this point to make
436
+ // sure it will be evaluated by libgccjit now.
437
+ // Otherwise, it will only be evaluated when the rvalue for the call is used somewhere else
438
+ // and overflow_value will not be initialized at the correct point in the program.
439
+ let result = self . current_func ( ) . new_local ( self . location , res_type, "result" ) ;
440
+ self . block . add_assignment ( self . location , result, call) ;
441
+
442
+ (
443
+ result. to_rvalue ( ) ,
444
+ self . context . new_cast ( self . location , overflow_value, self . bool_type ) . to_rvalue ( ) ,
445
+ )
437
446
}
438
447
439
448
pub fn gcc_icmp (
@@ -865,6 +874,7 @@ impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> {
865
874
let value_type = value. get_type ( ) ;
866
875
if self . is_native_int_type_or_bool ( dest_typ) && self . is_native_int_type_or_bool ( value_type)
867
876
{
877
+ // TODO: use self.location.
868
878
self . context . new_cast ( None , value, dest_typ)
869
879
} else if self . is_native_int_type_or_bool ( dest_typ) {
870
880
self . context . new_cast ( None , self . low ( value) , dest_typ)
0 commit comments