Skip to content

Commit

Permalink
Auto merge of #11517 - mojave2:issue-11426, r=Alexendoo
Browse files Browse the repository at this point in the history
fix ICE by `u64::try_from(<u128>)`

changelog: Fix the ICE in [`cast_possible_truncation`], when the `Shr` bits is larger than `u64::MAX`

fix #11426
  • Loading branch information
bors committed Sep 18, 2023
2 parents c92de58 + 3665a41 commit 2a0795f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 1 addition & 1 deletion clippy_lints/src/casts/cast_possible_truncation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ fn apply_reductions(cx: &LateContext<'_>, nbits: u64, expr: &Expr<'_>, signed: b
.unwrap_or(u64::max_value())
.min(apply_reductions(cx, nbits, left, signed)),
BinOpKind::Shr => apply_reductions(cx, nbits, left, signed)
.saturating_sub(constant_int(cx, right).map_or(0, |s| u64::try_from(s).expect("shift too high"))),
.saturating_sub(constant_int(cx, right).map_or(0, |s| u64::try_from(s).unwrap_or_default())),
_ => nbits,
},
ExprKind::MethodCall(method, left, [right], _) => {
Expand Down
4 changes: 4 additions & 0 deletions tests/ui/cast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -361,3 +361,7 @@ fn avoid_subtract_overflow(q: u32) {
//~^ ERROR: casting `u32` to `u8` may truncate the value
c as usize;
}

fn issue11426() {
(&42u8 >> 0xa9008fb6c9d81e42_0e25730562a601c8_u128) as usize;
}

0 comments on commit 2a0795f

Please sign in to comment.