summaryrefslogtreecommitdiff
path: root/compiler/rustc_abi
diff options
context:
space:
mode:
authorOli Scherer <git-spam-no-reply9815368754983@oli-obk.de>2022-11-07 10:26:14 +0000
committerOli Scherer <git-spam-no-reply9815368754983@oli-obk.de>2022-11-25 08:39:11 +0000
commitd7f5d784d7dd759944ddb8c224544b6f89c9fdc8 (patch)
treed21ce8a6eb313cfcf886e011c4f64a1c3eaedf64 /compiler/rustc_abi
parentfcb1f1874f8c1b40b2ba5228a905c7875b21ce88 (diff)
downloadrust-d7f5d784d7dd759944ddb8c224544b6f89c9fdc8.tar.gz
Simplify and document range layout computation
Diffstat (limited to 'compiler/rustc_abi')
-rw-r--r--compiler/rustc_abi/src/layout.rs24
1 files changed, 11 insertions, 13 deletions
diff --git a/compiler/rustc_abi/src/layout.rs b/compiler/rustc_abi/src/layout.rs
index 39ea7a85be6..11e7b80f85e 100644
--- a/compiler/rustc_abi/src/layout.rs
+++ b/compiler/rustc_abi/src/layout.rs
@@ -382,28 +382,26 @@ pub trait LayoutCalculator {
let (start, end) = scalar_valid_range;
match st.abi {
Abi::Scalar(ref mut scalar) | Abi::ScalarPair(ref mut scalar, _) => {
- // the asserts ensure that we are not using the
- // `#[rustc_layout_scalar_valid_range(n)]`
- // attribute to widen the range of anything as that would probably
- // result in UB somewhere
- // FIXME(eddyb) the asserts are probably not needed,
- // as larger validity ranges would result in missed
+ // Enlarging validity ranges would result in missed
// optimizations, *not* wrongly assuming the inner
- // value is valid. e.g. unions enlarge validity ranges,
+ // value is valid. e.g. unions already enlarge validity ranges,
// because the values may be uninitialized.
+ //
+ // Because of that we only check that the start and end
+ // of the range is representable with this scalar type.
+
+ let max_value = scalar.size(dl).unsigned_int_max();
if let Bound::Included(start) = start {
// FIXME(eddyb) this might be incorrect - it doesn't
// account for wrap-around (end < start) ranges.
- let valid_range = scalar.valid_range_mut();
- assert!(valid_range.start <= start);
- valid_range.start = start;
+ assert!(start <= max_value, "{start} > {max_value}");
+ scalar.valid_range_mut().start = start;
}
if let Bound::Included(end) = end {
// FIXME(eddyb) this might be incorrect - it doesn't
// account for wrap-around (end < start) ranges.
- let valid_range = scalar.valid_range_mut();
- assert!(valid_range.end >= end);
- valid_range.end = end;
+ assert!(end <= max_value, "{end} > {max_value}");
+ scalar.valid_range_mut().end = end;
}
// Update `largest_niche` if we have introduced a larger niche.