Skip to content

Commit

Permalink
Rollup merge of rust-lang#57042 - pnkfelix:issue-57038-sidestep-ice-i…
Browse files Browse the repository at this point in the history
…n-fieldplacement-count, r=michaelwoerister

Don't call `FieldPlacement::count` when count is too large

Sidestep ICE in `FieldPlacement::count` by not calling it when count will not fit in host's usize.

(I briefly played with trying to fix this by changing `FieldPlacement::count` to return a `u64`. However, based on how `FieldPlacement` is used, it seems like this would be a largely pointless pursuit... I'm open to counter-arguments, however.)

Fix rust-lang#57038
  • Loading branch information
Centril committed Jan 12, 2019
2 parents 53aa8a1 + 0eacf2c commit 017f046
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/librustc/ty/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1842,7 +1842,11 @@ impl<'a, 'tcx> LayoutCx<'tcx, TyCtxt<'a, 'tcx, 'tcx>> {
return Ok(None);
}
}
if let FieldPlacement::Array { .. } = layout.fields {
if let FieldPlacement::Array { count: original_64_bit_count, .. } = layout.fields {
// rust-lang/rust#57038: avoid ICE within FieldPlacement::count when count too big
if original_64_bit_count > usize::max_value() as u64 {
return Err(LayoutError::SizeOverflow(layout.ty));
}
if layout.fields.count() > 0 {
return self.find_niche(layout.field(self, 0)?);
} else {
Expand Down

0 comments on commit 017f046

Please sign in to comment.