Skip to content

Commit 38a0b81

Browse files
committed
Auto merge of rust-lang#94679 - matthiaskrgr:rollup-9vd7w6a, r=matthiaskrgr
Rollup of 3 pull requests Successful merges: - rust-lang#94659 (explain why shift with signed offset works the way it does) - rust-lang#94671 (fix pin doc typo) - rust-lang#94672 (Improved error message for failed bitcode load) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents c38b8a8 + 0480a32 commit 38a0b81

File tree

4 files changed

+18
-6
lines changed

4 files changed

+18
-6
lines changed

compiler/rustc_codegen_llvm/src/back/lto.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ fn fat_lto(
317317
info!("linking {:?}", name);
318318
let data = bc_decoded.data();
319319
linker.add(data).map_err(|()| {
320-
let msg = format!("failed to load bc of {:?}", name);
320+
let msg = format!("failed to load bitcode of module {:?}", name);
321321
write::llvm_err(diag_handler, &msg)
322322
})?;
323323
serialized_bitcode.push(bc_decoded);

compiler/rustc_const_eval/src/interpret/operator.rs

+15-3
Original file line numberDiff line numberDiff line change
@@ -127,17 +127,29 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
127127

128128
// Shift ops can have an RHS with a different numeric type.
129129
if bin_op == Shl || bin_op == Shr {
130-
let signed = left_layout.abi.is_signed();
131130
let size = u128::from(left_layout.size.bits());
131+
// Even if `r` is signed, we treat it as if it was unsigned (i.e., we use its
132+
// zero-extended form). This matches the codegen backend:
133+
// <https://github.com/rust-lang/rust/blob/c274e4969f058b1c644243181ece9f829efa7594/compiler/rustc_codegen_ssa/src/base.rs#L315-L317>.
134+
// The overflow check is also ignorant to the sign:
135+
// <https://github.com/rust-lang/rust/blob/c274e4969f058b1c644243181ece9f829efa7594/compiler/rustc_codegen_ssa/src/mir/rvalue.rs#L728>.
136+
// This would behave rather strangely if we had integer types of size 256: a shift by
137+
// -1i8 would actually shift by 255, but that would *not* be considered overflowing. A
138+
// shift by -1i16 though would be considered overflowing. If we had integers of size
139+
// 512, then a shift by -1i8 would even produce a different result than one by -1i16:
140+
// the first shifts by 255, the latter by u16::MAX % 512 = 511. Lucky enough, our
141+
// integers are maximally 128bits wide, so negative shifts *always* overflow and we have
142+
// consistent results for the same value represented at different bit widths.
143+
assert!(size <= 128);
132144
let overflow = r >= size;
133145
// The shift offset is implicitly masked to the type size, to make sure this operation
134146
// is always defined. This is the one MIR operator that does *not* directly map to a
135147
// single LLVM operation. See
136-
// <https://github.com/rust-lang/rust/blob/a3b9405ae7bb6ab4e8103b414e75c44598a10fd2/compiler/rustc_codegen_ssa/src/common.rs#L131-L158>
148+
// <https://github.com/rust-lang/rust/blob/c274e4969f058b1c644243181ece9f829efa7594/compiler/rustc_codegen_ssa/src/common.rs#L131-L158>
137149
// for the corresponding truncation in our codegen backends.
138150
let r = r % size;
139151
let r = u32::try_from(r).unwrap(); // we masked so this will always fit
140-
let result = if signed {
152+
let result = if left_layout.abi.is_signed() {
141153
let l = self.sign_extend(l, left_layout) as i128;
142154
let result = match bin_op {
143155
Shl => l.checked_shl(r).unwrap(),

library/core/src/pin.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -954,7 +954,7 @@ impl<P, U> DispatchFromDyn<Pin<U>> for Pin<P> where P: DispatchFromDyn<U> {}
954954
/// stuff(pin!(Foo { /* … */ }));
955955
/// ```
956956
///
957-
/// ### Manually polling a `Future` (wihout `Unpin` bounds)
957+
/// ### Manually polling a `Future` (without `Unpin` bounds)
958958
///
959959
/// ```rust
960960
/// #![feature(pin_macro)]
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
warning: Linking globals named 'foo': symbol multiply defined!
22

3-
error: failed to load bc of "lto-duplicate-symbols2.lto_duplicate_symbols2.HASH-cgu.0.rcgu.o":
3+
error: failed to load bitcode of module "lto-duplicate-symbols2.lto_duplicate_symbols2.HASH-cgu.0.rcgu.o":
44

55
error: aborting due to previous error; 1 warning emitted
66

0 commit comments

Comments
 (0)