diff options
| author | Yuki Okushi <huyuumi.dev@gmail.com> | 2019-11-15 18:36:31 +0900 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-11-15 18:36:31 +0900 |
| commit | e4d5f0596da62e9a14583d205027b69821dfc751 (patch) | |
| tree | 6bbf721e2fc50c5b9e03b258302d50d95b77deb7 | |
| parent | 1f43824a8b783c74418a0b2c8b962b61b546f952 (diff) | |
| parent | 6c9ba97d23254045b182edbb8a4448a8c25c7a76 (diff) | |
| download | rust-e4d5f0596da62e9a14583d205027b69821dfc751.tar.gz rust-e4d5f0596da62e9a14583d205027b69821dfc751.zip | |
Rollup merge of #66410 - RalfJung:miri-machine-max, r=oli-obk
miri: helper methods for max values of machine's usize/isize We recently wanted this in Miri. r? @oli-obk
| -rw-r--r-- | src/librustc/mir/interpret/pointer.rs | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/src/librustc/mir/interpret/pointer.rs b/src/librustc/mir/interpret/pointer.rs index 1bb4d9ea4d6..7c77b2c0711 100644 --- a/src/librustc/mir/interpret/pointer.rs +++ b/src/librustc/mir/interpret/pointer.rs @@ -1,4 +1,5 @@ use std::fmt::{self, Display}; +use std::convert::TryFrom; use crate::mir; use crate::ty::layout::{self, HasDataLayout, Size}; @@ -40,6 +41,18 @@ pub trait PointerArithmetic: layout::HasDataLayout { self.data_layout().pointer_size } + #[inline] + fn usize_max(&self) -> u64 { + let max_usize_plus_1 = 1u128 << self.pointer_size().bits(); + u64::try_from(max_usize_plus_1-1).unwrap() + } + + #[inline] + fn isize_max(&self) -> i64 { + let max_isize_plus_1 = 1u128 << (self.pointer_size().bits()-1); + i64::try_from(max_isize_plus_1-1).unwrap() + } + /// Helper function: truncate given value-"overflowed flag" pair to pointer size and /// update "overflowed flag" if there was an overflow. /// This should be called by all the other methods before returning! |
