Merge pull request #810 from rust-lang/generic-checked-binop

Use generic builtin for saturating add/sub
This commit is contained in:
antoyo 2025-11-28 00:02:18 -05:00 committed by GitHub
commit 55bd9bf692
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1160,14 +1160,7 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> {
let res = func.new_local(self.location, result_type, "saturating_sum");
let supports_native_type = self.is_native_int_type(result_type);
let overflow = if supports_native_type {
let func_name = match width {
8 => "__builtin_add_overflow",
16 => "__builtin_add_overflow",
32 => "__builtin_sadd_overflow",
64 => "__builtin_saddll_overflow",
128 => "__builtin_add_overflow",
_ => unreachable!(),
};
let func_name = "__builtin_add_overflow";
let overflow_func = self.context.get_builtin_function(func_name);
self.overflow_call(overflow_func, &[lhs, rhs, res.get_address(self.location)], None)
} else {
@ -1231,14 +1224,7 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> {
let res = func.new_local(self.location, result_type, "saturating_diff");
let supports_native_type = self.is_native_int_type(result_type);
let overflow = if supports_native_type {
let func_name = match width {
8 => "__builtin_sub_overflow",
16 => "__builtin_sub_overflow",
32 => "__builtin_ssub_overflow",
64 => "__builtin_ssubll_overflow",
128 => "__builtin_sub_overflow",
_ => unreachable!(),
};
let func_name = "__builtin_sub_overflow";
let overflow_func = self.context.get_builtin_function(func_name);
self.overflow_call(overflow_func, &[lhs, rhs, res.get_address(self.location)], None)
} else {