Skip to content

Commit ee17934

Browse files
committed
Sync from rust 065a1f5df9c2f1d93269e4d25a2acabbddb0db8d
2 parents c8620a3 + 7ba31b9 commit ee17934

File tree

4 files changed

+19
-28
lines changed

4 files changed

+19
-28
lines changed

src/base.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,7 @@ fn codegen_fn_body(fx: &mut FunctionCx<'_, '_, '_>, start_block: Block) {
442442
target,
443443
fn_span,
444444
unwind: _,
445-
from_hir_call: _,
445+
call_source: _,
446446
} => {
447447
fx.tcx.prof.generic_activity("codegen call").run(|| {
448448
crate::abi::codegen_terminator_call(

src/codegen_i128.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ pub(crate) fn maybe_codegen<'tcx>(
2222

2323
match bin_op {
2424
BinOp::BitAnd | BinOp::BitOr | BinOp::BitXor => None,
25-
BinOp::Add | BinOp::Sub => None,
26-
BinOp::Mul => {
25+
BinOp::Add | BinOp::AddUnchecked | BinOp::Sub | BinOp::SubUnchecked => None,
26+
BinOp::Mul | BinOp::MulUnchecked => {
2727
let args = [lhs.load_scalar(fx), rhs.load_scalar(fx)];
2828
let ret_val = fx.lib_call(
2929
"__multi3",
@@ -69,7 +69,7 @@ pub(crate) fn maybe_codegen<'tcx>(
6969
}
7070
}
7171
BinOp::Lt | BinOp::Le | BinOp::Eq | BinOp::Ge | BinOp::Gt | BinOp::Ne => None,
72-
BinOp::Shl | BinOp::Shr => None,
72+
BinOp::Shl | BinOp::ShlUnchecked | BinOp::Shr | BinOp::ShrUnchecked => None,
7373
}
7474
}
7575

@@ -131,9 +131,10 @@ pub(crate) fn maybe_codegen_checked<'tcx>(
131131
fx.lib_call(name, param_types, vec![], &args);
132132
Some(out_place.to_cvalue(fx))
133133
}
134+
BinOp::AddUnchecked | BinOp::SubUnchecked | BinOp::MulUnchecked => unreachable!(),
134135
BinOp::Offset => unreachable!("offset should only be used on pointers, not 128bit ints"),
135136
BinOp::Div | BinOp::Rem => unreachable!(),
136137
BinOp::Lt | BinOp::Le | BinOp::Eq | BinOp::Ge | BinOp::Gt | BinOp::Ne => unreachable!(),
137-
BinOp::Shl | BinOp::Shr => unreachable!(),
138+
BinOp::Shl | BinOp::ShlUnchecked | BinOp::Shr | BinOp::ShrUnchecked => unreachable!(),
138139
}
139140
}

src/intrinsics/mod.rs

+3-17
Original file line numberDiff line numberDiff line change
@@ -472,25 +472,11 @@ fn codegen_regular_intrinsic_call<'tcx>(
472472
ret.write_cvalue(fx, CValue::by_val(align, usize_layout));
473473
}
474474

475-
sym::unchecked_add
476-
| sym::unchecked_sub
477-
| sym::unchecked_mul
478-
| sym::exact_div
479-
| sym::unchecked_shl
480-
| sym::unchecked_shr => {
475+
sym::exact_div => {
481476
intrinsic_args!(fx, args => (x, y); intrinsic);
482477

483-
// FIXME trap on overflow
484-
let bin_op = match intrinsic {
485-
sym::unchecked_add => BinOp::Add,
486-
sym::unchecked_sub => BinOp::Sub,
487-
sym::unchecked_mul => BinOp::Mul,
488-
sym::exact_div => BinOp::Div,
489-
sym::unchecked_shl => BinOp::Shl,
490-
sym::unchecked_shr => BinOp::Shr,
491-
_ => unreachable!(),
492-
};
493-
let res = crate::num::codegen_int_binop(fx, bin_op, x, y);
478+
// FIXME trap on inexact
479+
let res = crate::num::codegen_int_binop(fx, BinOp::Div, x, y);
494480
ret.write_cvalue(fx, res);
495481
}
496482
sym::saturating_add | sym::saturating_sub => {

src/num.rs

+10-6
Original file line numberDiff line numberDiff line change
@@ -128,10 +128,11 @@ pub(crate) fn codegen_int_binop<'tcx>(
128128
let rhs = in_rhs.load_scalar(fx);
129129

130130
let b = fx.bcx.ins();
131+
// FIXME trap on overflow for the Unchecked versions
131132
let val = match bin_op {
132-
BinOp::Add => b.iadd(lhs, rhs),
133-
BinOp::Sub => b.isub(lhs, rhs),
134-
BinOp::Mul => b.imul(lhs, rhs),
133+
BinOp::Add | BinOp::AddUnchecked => b.iadd(lhs, rhs),
134+
BinOp::Sub | BinOp::SubUnchecked => b.isub(lhs, rhs),
135+
BinOp::Mul | BinOp::MulUnchecked => b.imul(lhs, rhs),
135136
BinOp::Div => {
136137
if signed {
137138
b.sdiv(lhs, rhs)
@@ -149,16 +150,19 @@ pub(crate) fn codegen_int_binop<'tcx>(
149150
BinOp::BitXor => b.bxor(lhs, rhs),
150151
BinOp::BitAnd => b.band(lhs, rhs),
151152
BinOp::BitOr => b.bor(lhs, rhs),
152-
BinOp::Shl => b.ishl(lhs, rhs),
153-
BinOp::Shr => {
153+
BinOp::Shl | BinOp::ShlUnchecked => b.ishl(lhs, rhs),
154+
BinOp::Shr | BinOp::ShrUnchecked => {
154155
if signed {
155156
b.sshr(lhs, rhs)
156157
} else {
157158
b.ushr(lhs, rhs)
158159
}
159160
}
161+
BinOp::Offset => unreachable!("Offset is not an integer operation"),
160162
// Compare binops handles by `codegen_binop`.
161-
_ => unreachable!("{:?}({:?}, {:?})", bin_op, in_lhs.layout().ty, in_rhs.layout().ty),
163+
BinOp::Eq | BinOp::Ne | BinOp::Lt | BinOp::Le | BinOp::Gt | BinOp::Ge => {
164+
unreachable!("{:?}({:?}, {:?})", bin_op, in_lhs.layout().ty, in_rhs.layout().ty);
165+
}
162166
};
163167

164168
CValue::by_val(val, in_lhs.layout())

0 commit comments

Comments
 (0)