Skip to content

Commit

Permalink
Rollup merge of #70189 - RalfJung:is_signed, r=eddyb
Browse files Browse the repository at this point in the history
Abi::is_signed: assert that we are a Scalar

A bit more sanity checking, suggested by @eddyb. This makes this method actually "safer" than `TyS::is_signed`, so I made sure Miri consistently uses the `Abi` version.

Though I am not sure if this would have caught the mistake where the layout of a zero-sized enum was asked for its sign.

r? @eddyb
  • Loading branch information
Centril committed Mar 21, 2020
2 parents 832daf7 + 5930da4 commit 937ca43
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/librustc_mir/interpret/operand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -604,7 +604,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
.not_undef()
.and_then(|raw_discr| self.force_bits(raw_discr, discr_val.layout.size))
.map_err(|_| err_ub!(InvalidDiscriminant(raw_discr.erase_tag())))?;
let real_discr = if discr_val.layout.ty.is_signed() {
let real_discr = if discr_val.layout.abi.is_signed() {
// going from layout tag type to typeck discriminant type
// requires first sign extending with the discriminant layout
let sexted = sign_extend(bits_discr, discr_val.layout.size) as i128;
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_target/abi/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -751,7 +751,7 @@ impl Abi {
Primitive::Int(_, signed) => signed,
_ => false,
},
_ => false,
_ => panic!("`is_signed` on non-scalar ABI {:?}", self),
}
}

Expand Down

0 comments on commit 937ca43

Please sign in to comment.