hir-trans: Don't generate code for unreachable operands in short-circuiting logical operations.
This commit is contained in:
parent
b33240e2cc
commit
4a3f9b8962
|
@ -1695,11 +1695,13 @@ fn trans_scalar_binop<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
|
||||||
}
|
}
|
||||||
|
|
||||||
// refinement types would obviate the need for this
|
// refinement types would obviate the need for this
|
||||||
|
#[derive(Clone, Copy)]
|
||||||
enum lazy_binop_ty {
|
enum lazy_binop_ty {
|
||||||
lazy_and,
|
lazy_and,
|
||||||
lazy_or,
|
lazy_or,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
fn trans_lazy_binop<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
|
fn trans_lazy_binop<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
|
||||||
binop_expr: &hir::Expr,
|
binop_expr: &hir::Expr,
|
||||||
op: lazy_binop_ty,
|
op: lazy_binop_ty,
|
||||||
|
@ -1717,6 +1719,17 @@ fn trans_lazy_binop<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
|
||||||
return immediate_rvalue_bcx(past_lhs, lhs, binop_ty).to_expr_datumblock();
|
return immediate_rvalue_bcx(past_lhs, lhs, binop_ty).to_expr_datumblock();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If the rhs can never be reached, don't generate code for it.
|
||||||
|
if let Some(cond_val) = const_to_opt_uint(lhs) {
|
||||||
|
match (cond_val, op) {
|
||||||
|
(0, lazy_and) |
|
||||||
|
(1, lazy_or) => {
|
||||||
|
return immediate_rvalue_bcx(past_lhs, lhs, binop_ty).to_expr_datumblock();
|
||||||
|
}
|
||||||
|
_ => { /* continue */ }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let join = fcx.new_id_block("join", binop_expr.id);
|
let join = fcx.new_id_block("join", binop_expr.id);
|
||||||
let before_rhs = fcx.new_id_block("before_rhs", b.id);
|
let before_rhs = fcx.new_id_block("before_rhs", b.id);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue