Skip to content

Commit 88c2f4f

Browse files
committedApr 2, 2024
Auto merge of #123385 - matthiaskrgr:rollup-v69vjbn, r=matthiaskrgr
Rollup of 8 pull requests Successful merges: - #123198 (Add fn const BuildHasherDefault::new) - #123226 (De-LLVM the unchecked shifts [MCP#693]) - #123302 (Make sure to insert `Sized` bound first into clauses list) - #123348 (rustdoc: add a couple of regression tests) - #123362 (Check that nested statics in thread locals are duplicated per thread.) - #123368 (CFI: Support non-general coroutines) - #123375 (rustdoc: synthetic auto trait impls: accept unresolved region vars for now) - #123378 (Update sysinfo to 0.30.8) Failed merges: - #123349 (Fix capture analysis for by-move closure bodies) r? `@ghost` `@rustbot` modify labels: rollup
2 parents a77322c + 31900b4 commit 88c2f4f

File tree

52 files changed

+679
-596
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+679
-596
lines changed
 

‎Cargo.lock

+2-2
Original file line numberDiff line numberDiff line change
@@ -5370,9 +5370,9 @@ dependencies = [
53705370

53715371
[[package]]
53725372
name = "sysinfo"
5373-
version = "0.30.7"
5373+
version = "0.30.8"
53745374
source = "registry+https://github.com/rust-lang/crates.io-index"
5375-
checksum = "0c385888ef380a852a16209afc8cfad22795dd8873d69c9a14d2e2088f118d18"
5375+
checksum = "4b1a378e48fb3ce3a5cf04359c456c9c98ff689bcf1c1bc6e6a31f247686f275"
53765376
dependencies = [
53775377
"cfg-if",
53785378
"core-foundation-sys",

‎compiler/rustc_codegen_ssa/src/base.rs

+31-4
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use crate::back::write::{
55
compute_per_cgu_lto_type, start_async_codegen, submit_codegened_module_to_llvm,
66
submit_post_lto_module_to_llvm, submit_pre_lto_module_to_llvm, ComputedLtoType, OngoingCodegen,
77
};
8-
use crate::common::{IntPredicate, RealPredicate, TypeKind};
8+
use crate::common::{self, IntPredicate, RealPredicate, TypeKind};
99
use crate::errors;
1010
use crate::meth;
1111
use crate::mir;
@@ -33,7 +33,7 @@ use rustc_middle::mir::mono::{CodegenUnit, CodegenUnitNameBuilder, MonoItem};
3333
use rustc_middle::query::Providers;
3434
use rustc_middle::ty::layout::{HasTyCtxt, LayoutOf, TyAndLayout};
3535
use rustc_middle::ty::{self, Instance, Ty, TyCtxt};
36-
use rustc_session::config::{self, CrateType, EntryFnType, OutputType};
36+
use rustc_session::config::{self, CrateType, EntryFnType, OptLevel, OutputType};
3737
use rustc_session::Session;
3838
use rustc_span::symbol::sym;
3939
use rustc_span::Symbol;
@@ -300,14 +300,35 @@ pub fn coerce_unsized_into<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
300300
}
301301
}
302302

303-
pub fn cast_shift_expr_rhs<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
303+
/// Returns `rhs` sufficiently masked, truncated, and/or extended so that
304+
/// it can be used to shift `lhs`.
305+
///
306+
/// Shifts in MIR are all allowed to have mismatched LHS & RHS types.
307+
/// The shift methods in `BuilderMethods`, however, are fully homogeneous
308+
/// (both parameters and the return type are all the same type).
309+
///
310+
/// If `is_unchecked` is false, this masks the RHS to ensure it stays in-bounds,
311+
/// as the `BuilderMethods` shifts are UB for out-of-bounds shift amounts.
312+
/// For 32- and 64-bit types, this matches the semantics
313+
/// of Java. (See related discussion on #1877 and #10183.)
314+
///
315+
/// If `is_unchecked` is true, this does no masking, and adds sufficient `assume`
316+
/// calls or operation flags to preserve as much freedom to optimize as possible.
317+
pub fn build_shift_expr_rhs<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
304318
bx: &mut Bx,
305319
lhs: Bx::Value,
306-
rhs: Bx::Value,
320+
mut rhs: Bx::Value,
321+
is_unchecked: bool,
307322
) -> Bx::Value {
308323
// Shifts may have any size int on the rhs
309324
let mut rhs_llty = bx.cx().val_ty(rhs);
310325
let mut lhs_llty = bx.cx().val_ty(lhs);
326+
327+
let mask = common::shift_mask_val(bx, lhs_llty, rhs_llty, false);
328+
if !is_unchecked {
329+
rhs = bx.and(rhs, mask);
330+
}
331+
311332
if bx.cx().type_kind(rhs_llty) == TypeKind::Vector {
312333
rhs_llty = bx.cx().element_type(rhs_llty)
313334
}
@@ -317,6 +338,12 @@ pub fn cast_shift_expr_rhs<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
317338
let rhs_sz = bx.cx().int_width(rhs_llty);
318339
let lhs_sz = bx.cx().int_width(lhs_llty);
319340
if lhs_sz < rhs_sz {
341+
if is_unchecked && bx.sess().opts.optimize != OptLevel::No {
342+
// FIXME: Use `trunc nuw` once that's available
343+
let inrange = bx.icmp(IntPredicate::IntULE, rhs, mask);
344+
bx.assume(inrange);
345+
}
346+
320347
bx.trunc(rhs, lhs_llty)
321348
} else if lhs_sz > rhs_sz {
322349
// We zero-extend even if the RHS is signed. So e.g. `(x: i32) << -1i8` will zero-extend the

0 commit comments

Comments
 (0)