diff options
| author | Antoni Boucher <bouanto@zoho.com> | 2025-04-15 12:51:28 -0400 |
|---|---|---|
| committer | Antoni Boucher <bouanto@zoho.com> | 2025-04-17 08:50:06 -0400 |
| commit | 4b5940ad77cf9a95cf78bef1ecc6fa84ef1fc0ce (patch) | |
| tree | 61b9d3f3770823afb047303c1bc06c2c9a562e2b /src | |
| parent | 0d773175cc41901f1a558a9b45239c67c3fa0df6 (diff) | |
| download | rust-4b5940ad77cf9a95cf78bef1ecc6fa84ef1fc0ce.tar.gz rust-4b5940ad77cf9a95cf78bef1ecc6fa84ef1fc0ce.zip | |
Fix overflow operations
Diffstat (limited to 'src')
| -rw-r--r-- | src/int.rs | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/src/int.rs b/src/int.rs index b5fcb534747..9b5b0fde6e2 100644 --- a/src/int.rs +++ b/src/int.rs @@ -404,7 +404,7 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> { let ret_indirect = matches!(fn_abi.ret.mode, PassMode::Indirect { .. }); - let result = if ret_indirect { + let call = if ret_indirect { let res_value = self.current_func().new_local(self.location, res_type, "result_value"); let res_addr = res_value.get_address(self.location); let res_param_type = res_type.make_pointer(); @@ -432,8 +432,17 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> { ); self.context.new_call(self.location, func, &[lhs, rhs, overflow_addr]) }; - - (result, self.context.new_cast(self.location, overflow_value, self.bool_type).to_rvalue()) + // NOTE: we must assign the result of the operation to a variable at this point to make + // sure it will be evaluated by libgccjit now. + // Otherwise, it will only be evaluated when the rvalue for the call is used somewhere else + // and overflow_value will not be initialized at the correct point in the program. + let result = self.current_func().new_local(self.location, res_type, "result"); + self.block.add_assignment(self.location, result, call); + + ( + result.to_rvalue(), + self.context.new_cast(self.location, overflow_value, self.bool_type).to_rvalue(), + ) } pub fn gcc_icmp( @@ -865,6 +874,7 @@ impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> { let value_type = value.get_type(); if self.is_native_int_type_or_bool(dest_typ) && self.is_native_int_type_or_bool(value_type) { + // TODO: use self.location. self.context.new_cast(None, value, dest_typ) } else if self.is_native_int_type_or_bool(dest_typ) { self.context.new_cast(None, self.low(value), dest_typ) |
