From bf089331b4a9390d6a54b678c11559e56ca64563 Mon Sep 17 00:00:00 2001 From: csmoe Date: Sun, 6 Mar 2022 21:40:30 +0800 Subject: [PATCH 1/4] fix pin doc typo --- library/core/src/pin.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/core/src/pin.rs b/library/core/src/pin.rs index 775d2ded9daad..cef6a68b4d329 100644 --- a/library/core/src/pin.rs +++ b/library/core/src/pin.rs @@ -954,7 +954,7 @@ impl DispatchFromDyn> for Pin

where P: DispatchFromDyn {} /// stuff(pin!(Foo { /* … */ })); /// ``` /// -/// ### Manually polling a `Future` (wihout `Unpin` bounds) +/// ### Manually polling a `Future` (without `Unpin` bounds) /// /// ```rust /// #![feature(pin_macro)] From 65ec4dd9047d5d9a47122648feba4b4996d33540 Mon Sep 17 00:00:00 2001 From: Joe Date: Sun, 6 Mar 2022 15:25:05 +0100 Subject: [PATCH 2/4] Improved error message for failed bitcode load "bc" is an unnecessary shorthand that obfuscates the compilation error --- compiler/rustc_codegen_llvm/src/back/lto.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/rustc_codegen_llvm/src/back/lto.rs b/compiler/rustc_codegen_llvm/src/back/lto.rs index 6afa649b6de32..0f5b1c08ec2dc 100644 --- a/compiler/rustc_codegen_llvm/src/back/lto.rs +++ b/compiler/rustc_codegen_llvm/src/back/lto.rs @@ -317,7 +317,7 @@ fn fat_lto( info!("linking {:?}", name); let data = bc_decoded.data(); linker.add(data).map_err(|()| { - let msg = format!("failed to load bc of {:?}", name); + let msg = format!("failed to load bitcode of module {:?}", name); write::llvm_err(diag_handler, &msg) })?; serialized_bitcode.push(bc_decoded); From 0e604a7864268d1591a49e68a7155292c99c3662 Mon Sep 17 00:00:00 2001 From: Joe Date: Sun, 6 Mar 2022 16:14:07 +0100 Subject: [PATCH 3/4] Updated corresponding stderr --- src/test/ui/lto/lto-duplicate-symbols.stderr | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/ui/lto/lto-duplicate-symbols.stderr b/src/test/ui/lto/lto-duplicate-symbols.stderr index 50e6b81dcf4b4..f66afa94f4da7 100644 --- a/src/test/ui/lto/lto-duplicate-symbols.stderr +++ b/src/test/ui/lto/lto-duplicate-symbols.stderr @@ -1,6 +1,6 @@ warning: Linking globals named 'foo': symbol multiply defined! -error: failed to load bc of "lto-duplicate-symbols2.lto_duplicate_symbols2.HASH-cgu.0.rcgu.o": +error: failed to load bitcode of module "lto-duplicate-symbols2.lto_duplicate_symbols2.HASH-cgu.0.rcgu.o": error: aborting due to previous error; 1 warning emitted From dfc43df9377683e823ad6b07ea7f24538cd6e0c7 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Sat, 5 Mar 2022 22:47:31 -0500 Subject: [PATCH 4/4] explain why shift with signed offset works the way it does --- .../rustc_const_eval/src/interpret/operator.rs | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/compiler/rustc_const_eval/src/interpret/operator.rs b/compiler/rustc_const_eval/src/interpret/operator.rs index 079ce9f07b8e1..6dae9dc72b7b4 100644 --- a/compiler/rustc_const_eval/src/interpret/operator.rs +++ b/compiler/rustc_const_eval/src/interpret/operator.rs @@ -127,17 +127,29 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { // Shift ops can have an RHS with a different numeric type. if bin_op == Shl || bin_op == Shr { - let signed = left_layout.abi.is_signed(); let size = u128::from(left_layout.size.bits()); + // Even if `r` is signed, we treat it as if it was unsigned (i.e., we use its + // zero-extended form). This matches the codegen backend: + // . + // The overflow check is also ignorant to the sign: + // . + // This would behave rather strangely if we had integer types of size 256: a shift by + // -1i8 would actually shift by 255, but that would *not* be considered overflowing. A + // shift by -1i16 though would be considered overflowing. If we had integers of size + // 512, then a shift by -1i8 would even produce a different result than one by -1i16: + // the first shifts by 255, the latter by u16::MAX % 512 = 511. Lucky enough, our + // integers are maximally 128bits wide, so negative shifts *always* overflow and we have + // consistent results for the same value represented at different bit widths. + assert!(size <= 128); let overflow = r >= size; // The shift offset is implicitly masked to the type size, to make sure this operation // is always defined. This is the one MIR operator that does *not* directly map to a // single LLVM operation. See - // + // // for the corresponding truncation in our codegen backends. let r = r % size; let r = u32::try_from(r).unwrap(); // we masked so this will always fit - let result = if signed { + let result = if left_layout.abi.is_signed() { let l = self.sign_extend(l, left_layout) as i128; let result = match bin_op { Shl => l.checked_shl(r).unwrap(),