diff options
Diffstat (limited to 'compiler')
| -rw-r--r-- | compiler/rustc_abi/src/lib.rs | 12 | ||||
| -rw-r--r-- | compiler/rustc_codegen_ssa/src/glue.rs | 3 | ||||
| -rw-r--r-- | compiler/rustc_codegen_ssa/src/mir/intrinsic.rs | 12 |
3 files changed, 24 insertions, 3 deletions
diff --git a/compiler/rustc_abi/src/lib.rs b/compiler/rustc_abi/src/lib.rs index e14c9ea9a5d..27b8377a9e0 100644 --- a/compiler/rustc_abi/src/lib.rs +++ b/compiler/rustc_abi/src/lib.rs @@ -775,6 +775,18 @@ impl Integer { } } + /// Returns the largest signed value that can be represented by this Integer. + #[inline] + pub fn signed_max(self) -> i128 { + match self { + I8 => i8::MAX as i128, + I16 => i16::MAX as i128, + I32 => i32::MAX as i128, + I64 => i64::MAX as i128, + I128 => i128::MAX, + } + } + /// Finds the smallest Integer type which can represent the signed value. #[inline] pub fn fit_signed(x: i128) -> Integer { diff --git a/compiler/rustc_codegen_ssa/src/glue.rs b/compiler/rustc_codegen_ssa/src/glue.rs index 6015d48deca..0f6e6032f9b 100644 --- a/compiler/rustc_codegen_ssa/src/glue.rs +++ b/compiler/rustc_codegen_ssa/src/glue.rs @@ -29,6 +29,9 @@ pub fn size_and_align_of_dst<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>( let align = meth::VirtualIndex::from_index(ty::COMMON_VTABLE_ENTRIES_ALIGN) .get_usize(bx, vtable); + // Size is always <= isize::MAX. + let size_bound = bx.data_layout().ptr_sized_integer().signed_max() as u128; + bx.range_metadata(size, WrappingRange { start: 0, end: size_bound }); // Alignment is always nonzero. bx.range_metadata(align, WrappingRange { start: 1, end: !0 }); diff --git a/compiler/rustc_codegen_ssa/src/mir/intrinsic.rs b/compiler/rustc_codegen_ssa/src/mir/intrinsic.rs index 215edbe02c0..a75609260ed 100644 --- a/compiler/rustc_codegen_ssa/src/mir/intrinsic.rs +++ b/compiler/rustc_codegen_ssa/src/mir/intrinsic.rs @@ -110,10 +110,16 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { _ => bug!(), }; let value = meth::VirtualIndex::from_index(idx).get_usize(bx, vtable); - if name == sym::vtable_align { + match name { + // Size is always <= isize::MAX. + sym::vtable_size => { + let size_bound = bx.data_layout().ptr_sized_integer().signed_max() as u128; + bx.range_metadata(value, WrappingRange { start: 0, end: size_bound }); + }, // Alignment is always nonzero. - bx.range_metadata(value, WrappingRange { start: 1, end: !0 }); - }; + sym::vtable_align => bx.range_metadata(value, WrappingRange { start: 1, end: !0 }), + _ => {} + } value } sym::pref_align_of |
