Skip to content

Commit

Permalink
add method to obtain the ptr offset of a Scalar
Browse files Browse the repository at this point in the history
  • Loading branch information
RalfJung committed Nov 5, 2018
1 parent a0074ca commit 7b7c6ce
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/librustc/mir/interpret/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,19 @@ impl<'tcx, Tag> Scalar<Tag> {
}
}

/// Returns this pointers offset from the allocation base, or from NULL (for
/// integer pointers).
#[inline]
pub fn get_ptr_offset(self, cx: &impl HasDataLayout) -> Size {
match self {
Scalar::Bits { bits, size } => {
assert_eq!(size as u64, cx.pointer_size().bytes());
Size::from_bytes(bits as u64)
}
Scalar::Ptr(ptr) => ptr.offset,
}
}

#[inline]
pub fn is_null_ptr(self, cx: &impl HasDataLayout) -> bool {
match self {
Expand Down

0 comments on commit 7b7c6ce

Please sign in to comment.