From 0afd50e8524aee0e9f23d4881bc7cac687c23ddf Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Wed, 15 May 2024 08:22:53 +0200 Subject: [PATCH] MIR operators: clarify Shl/Shr handling of negative offsets --- compiler/rustc_middle/src/mir/syntax.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/compiler/rustc_middle/src/mir/syntax.rs b/compiler/rustc_middle/src/mir/syntax.rs index 4278ce823d0e0..e124b478f4193 100644 --- a/compiler/rustc_middle/src/mir/syntax.rs +++ b/compiler/rustc_middle/src/mir/syntax.rs @@ -1480,13 +1480,17 @@ pub enum BinOp { BitOr, /// The `<<` operator (shift left) /// - /// The offset is truncated to the size of the first operand and made unsigned before shifting. + /// The offset is (uniquely) determined as follows: + /// - it is "equal modulo LHS::BITS" to the RHS + /// - it is in the range `0..LHS::BITS` Shl, /// Like `Shl`, but is UB if the RHS >= LHS::BITS or RHS < 0 ShlUnchecked, /// The `>>` operator (shift right) /// - /// The offset is truncated to the size of the first operand and made unsigned before shifting. + /// The offset is (uniquely) determined as follows: + /// - it is "equal modulo LHS::BITS" to the RHS + /// - it is in the range `0..LHS::BITS` /// /// This is an arithmetic shift if the LHS is signed /// and a logical shift if the LHS is unsigned.