implement contains_zero method
This commit is contained in:
parent
d50abd0249
commit
70433955f4
3 changed files with 12 additions and 9 deletions
|
@ -462,7 +462,6 @@ impl BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
|
||||||
load: &'ll Value,
|
load: &'ll Value,
|
||||||
scalar: &abi::Scalar,
|
scalar: &abi::Scalar,
|
||||||
) {
|
) {
|
||||||
let vr = scalar.valid_range;
|
|
||||||
match scalar.value {
|
match scalar.value {
|
||||||
abi::Int(..) => {
|
abi::Int(..) => {
|
||||||
let range = scalar.valid_range_exclusive(bx);
|
let range = scalar.valid_range_exclusive(bx);
|
||||||
|
@ -470,7 +469,7 @@ impl BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
|
||||||
bx.range_metadata(load, range);
|
bx.range_metadata(load, range);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
abi::Pointer if vr.start < vr.end && !vr.contains(0) => {
|
abi::Pointer if !scalar.valid_range.contains_zero() => {
|
||||||
bx.nonnull_metadata(load);
|
bx.nonnull_metadata(load);
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
|
|
|
@ -2857,11 +2857,9 @@ where
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if scalar.valid_range.start < scalar.valid_range.end {
|
if !scalar.valid_range.contains_zero() {
|
||||||
if scalar.valid_range.start > 0 {
|
|
||||||
attrs.set(ArgAttribute::NonNull);
|
attrs.set(ArgAttribute::NonNull);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if let Some(pointee) = layout.pointee_info_at(cx, offset) {
|
if let Some(pointee) = layout.pointee_info_at(cx, offset) {
|
||||||
if let Some(kind) = pointee.safe {
|
if let Some(kind) = pointee.safe {
|
||||||
|
|
|
@ -688,7 +688,7 @@ impl Primitive {
|
||||||
///
|
///
|
||||||
/// This is intended specifically to mirror LLVM’s `!range` metadata,
|
/// This is intended specifically to mirror LLVM’s `!range` metadata,
|
||||||
/// semantics.
|
/// semantics.
|
||||||
#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)]
|
#[derive(Clone, PartialEq, Eq, Hash, Debug)]
|
||||||
#[derive(HashStable_Generic)]
|
#[derive(HashStable_Generic)]
|
||||||
pub struct AllocationRange {
|
pub struct AllocationRange {
|
||||||
pub start: u128,
|
pub start: u128,
|
||||||
|
@ -705,6 +705,13 @@ impl AllocationRange {
|
||||||
self.start <= v || v <= self.end
|
self.start <= v || v <= self.end
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Returns `true` if zero is contained in the range.
|
||||||
|
/// Equal to `range.contains(0)` but should be faster.
|
||||||
|
#[inline]
|
||||||
|
pub fn contains_zero(&self) -> bool {
|
||||||
|
!(self.start <= self.end && self.start != 0)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Information about one scalar component of a Rust type.
|
/// Information about one scalar component of a Rust type.
|
||||||
|
@ -1222,9 +1229,8 @@ impl<'a, Ty> TyAndLayout<'a, Ty> {
|
||||||
{
|
{
|
||||||
let scalar_allows_raw_init = move |s: &Scalar| -> bool {
|
let scalar_allows_raw_init = move |s: &Scalar| -> bool {
|
||||||
if zero {
|
if zero {
|
||||||
let range = &s.valid_range;
|
|
||||||
// The range must contain 0.
|
// The range must contain 0.
|
||||||
range.contains(0) || (range.start > range.end) // wrap-around allows 0
|
s.valid_range.contains_zero()
|
||||||
} else {
|
} else {
|
||||||
// The range must include all values. `valid_range_exclusive` handles
|
// The range must include all values. `valid_range_exclusive` handles
|
||||||
// the wrap-around using target arithmetic; with wrap-around then the full
|
// the wrap-around using target arithmetic; with wrap-around then the full
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue