Skip to content

Commit bb339d4

Browse files
committed
Make size_of_val(slice) saturate
1 parent f4a7ce9 commit bb339d4

File tree

1 file changed

+7
-1
lines changed
  • compiler/rustc_codegen_ssa/src

1 file changed

+7
-1
lines changed

compiler/rustc_codegen_ssa/src/glue.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,14 @@ pub fn size_and_align_of_dst<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
3838
let unit = layout.field(bx, 0);
3939
// The info in this case is the length of the str, so the size is that
4040
// times the unit size.
41+
let (size, overflow) = bx.checked_binop(
42+
OverflowOp::Mul,
43+
bx.tcx().mk_mach_uint(UintTy::Usize),
44+
unit.size.bytes(),
45+
info.unwrap(),
46+
);
4147
(
42-
bx.mul(info.unwrap(), bx.const_usize(unit.size.bytes())),
48+
bx.select(overflow, bx.const_usize(usize::MAX), size),
4349
bx.const_usize(unit.align.abi.bytes()),
4450
)
4551
}

0 commit comments

Comments
 (0)