diff --git a/compiler/rustc_codegen_ssa/src/glue.rs b/compiler/rustc_codegen_ssa/src/glue.rs index 694f5434e9afd..a63a547d8c938 100644 --- a/compiler/rustc_codegen_ssa/src/glue.rs +++ b/compiler/rustc_codegen_ssa/src/glue.rs @@ -5,7 +5,7 @@ use crate::common::IntPredicate; use crate::meth; use crate::traits::*; -use rustc_middle::ty::{self, Ty}; +use rustc_middle::ty::{self, Ty, UintTy}; use rustc_target::abi::WrappingRange; pub fn size_and_align_of_dst<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>( @@ -38,8 +38,15 @@ pub fn size_and_align_of_dst<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>( let unit = layout.field(bx, 0); // The info in this case is the length of the str, so the size is that // times the unit size. + let (size, overflow) = bx.checked_binop( + OverflowOp::Mul, + bx.tcx().mk_mach_uint(UintTy::Usize), + bx.const_usize(unit.size.bytes()), + info.unwrap(), + ); + let ptr_max = bx.data_layout().pointer_size.truncate(u128::MAX) as u64; ( - bx.mul(info.unwrap(), bx.const_usize(unit.size.bytes())), + bx.select(overflow, bx.const_usize(ptr_max), size), bx.const_usize(unit.align.abi.bytes()), ) }