about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMatthias Krüger <matthias.krueger@famsik.de>2024-03-13 20:01:55 +0100
committerGitHub <noreply@github.com>2024-03-13 20:01:55 +0100
commit96a41ce513f736c0cabc328155fcba1cb6c18f7b (patch)
tree74b39b28b863010b123affc441e4e192814edc87
parentcf795408744a6c802912506984c1fd759cd35eb6 (diff)
parente0488c0961e5ba693d19f6e1e3f4c9b20631353b (diff)
downloadrust-96a41ce513f736c0cabc328155fcba1cb6c18f7b.tar.gz
rust-96a41ce513f736c0cabc328155fcba1cb6c18f7b.zip
Rollup merge of #122426 - celinval:smir-fix-full, r=oli-obk
Fix StableMIR `WrappingRange::is_full` computation

`WrappingRange::is_full` computation assumed that to be full the range couldn't wrap, which is not necessarily true.

For example, a range of 1..=0 is a valid representation of a full wrapping range.
-rw-r--r--compiler/stable_mir/src/abi.rs2
1 files changed, 1 insertions, 1 deletions
diff --git a/compiler/stable_mir/src/abi.rs b/compiler/stable_mir/src/abi.rs
index 7fda9ceb79a..92bc2e34561 100644
--- a/compiler/stable_mir/src/abi.rs
+++ b/compiler/stable_mir/src/abi.rs
@@ -383,7 +383,7 @@ impl WrappingRange {
             return Err(error!("Expected size <= 128 bits, but found {} instead", size.bits()));
         };
         if self.start <= max_value && self.end <= max_value {
-            Ok(self.start == 0 && max_value == self.end)
+            Ok(self.start == (self.end.wrapping_add(1) & max_value))
         } else {
             Err(error!("Range `{self:?}` out of bounds for size `{}` bits.", size.bits()))
         }