|
1 | 1 | use rustc::mir;
|
2 | 2 | use rustc::ty::{self, Ty};
|
3 |
| -use rustc::ty::layout::LayoutOf; |
| 3 | +use rustc::ty::layout::{LayoutOf, Size}; |
4 | 4 | use syntax::codemap::Span;
|
5 | 5 | use rustc_target::spec::abi::Abi;
|
6 | 6 |
|
7 |
| -use rustc::mir::interpret::EvalResult; |
| 7 | +use rustc::mir::interpret::{EvalResult, Scalar}; |
8 | 8 | use super::{EvalContext, Place, Machine, ValTy};
|
9 | 9 |
|
10 | 10 | use rustc_data_structures::indexed_vec::Idx;
|
@@ -41,13 +41,18 @@ impl<'a, 'mir, 'tcx, M: Machine<'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M> {
|
41 | 41 | let discr_prim = self.value_to_scalar(discr_val)?;
|
42 | 42 | let discr_layout = self.layout_of(discr_val.ty).unwrap();
|
43 | 43 | trace!("SwitchInt({:?}, {:#?})", discr_prim, discr_layout);
|
44 |
| - let discr_prim = discr_prim.to_bits(discr_layout.size)?; |
45 | 44 |
|
46 | 45 | // Branch to the `otherwise` case by default, if no match is found.
|
47 | 46 | let mut target_block = targets[targets.len() - 1];
|
48 | 47 |
|
49 | 48 | for (index, &const_int) in values.iter().enumerate() {
|
50 |
| - if discr_prim == const_int { |
| 49 | + // Compare using binary_op |
| 50 | + let const_int = Scalar::Bits { bits: const_int, defined: 128 }; |
| 51 | + let res = self.binary_op(mir::BinOp::Eq, |
| 52 | + discr_prim, discr_val.ty, |
| 53 | + const_int, discr_val.ty |
| 54 | + )?; |
| 55 | + if res.0.to_bits(Size::from_bytes(1))? != 0 { |
51 | 56 | target_block = targets[index];
|
52 | 57 | break;
|
53 | 58 | }
|
|
0 commit comments