Skip to content

Commit 55bd9bf

Browse files
authored
Merge pull request #810 from rust-lang/generic-checked-binop
Use generic builtin for saturating add/sub
2 parents 05af078 + c1f50c0 commit 55bd9bf

File tree

1 file changed

+2
-16
lines changed

1 file changed

+2
-16
lines changed

src/intrinsic/mod.rs

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1160,14 +1160,7 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> {
11601160
let res = func.new_local(self.location, result_type, "saturating_sum");
11611161
let supports_native_type = self.is_native_int_type(result_type);
11621162
let overflow = if supports_native_type {
1163-
let func_name = match width {
1164-
8 => "__builtin_add_overflow",
1165-
16 => "__builtin_add_overflow",
1166-
32 => "__builtin_sadd_overflow",
1167-
64 => "__builtin_saddll_overflow",
1168-
128 => "__builtin_add_overflow",
1169-
_ => unreachable!(),
1170-
};
1163+
let func_name = "__builtin_add_overflow";
11711164
let overflow_func = self.context.get_builtin_function(func_name);
11721165
self.overflow_call(overflow_func, &[lhs, rhs, res.get_address(self.location)], None)
11731166
} else {
@@ -1231,14 +1224,7 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> {
12311224
let res = func.new_local(self.location, result_type, "saturating_diff");
12321225
let supports_native_type = self.is_native_int_type(result_type);
12331226
let overflow = if supports_native_type {
1234-
let func_name = match width {
1235-
8 => "__builtin_sub_overflow",
1236-
16 => "__builtin_sub_overflow",
1237-
32 => "__builtin_ssub_overflow",
1238-
64 => "__builtin_ssubll_overflow",
1239-
128 => "__builtin_sub_overflow",
1240-
_ => unreachable!(),
1241-
};
1227+
let func_name = "__builtin_sub_overflow";
12421228
let overflow_func = self.context.get_builtin_function(func_name);
12431229
self.overflow_call(overflow_func, &[lhs, rhs, res.get_address(self.location)], None)
12441230
} else {

0 commit comments

Comments
 (0)