Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Experiment: Make intrinsic::size_of(slice) saturate #95832

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions compiler/rustc_codegen_ssa/src/glue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>>(
Expand Down Expand Up @@ -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()),
)
}
Expand Down