Skip to content

Commit

Permalink
fix discriminant sign extension
Browse files Browse the repository at this point in the history
  • Loading branch information
RalfJung committed May 21, 2020
1 parent 963bf52 commit 94aa028
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/librustc_mir/interpret/intrinsics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,10 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
let place = self.deref_operand(args[0])?;
let discr_val = self.read_discriminant(place.into())?.0;
let scalar = match dest.layout.ty.kind {
ty::Int(_) => Scalar::from_int(discr_val as i128, dest.layout.size),
ty::Int(_) => Scalar::from_int(
self.sign_extend(discr_val, dest.layout) as i128,
dest.layout.size,
),
ty::Uint(_) => Scalar::from_uint(discr_val, dest.layout.size),
_ => bug!("invalid `discriminant_value` return layout: {:?}", dest.layout),
};
Expand Down

0 comments on commit 94aa028

Please sign in to comment.