diff options
| author | Dylan DPC <dylan.dpc@gmail.com> | 2020-03-02 13:42:37 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-03-02 13:42:37 +0100 |
| commit | f548a387a40b4a0d24ae16280930624100ccc7d5 (patch) | |
| tree | 34c488765edfd689f4c77f9d875fa504808a6ecb | |
| parent | ffb6d75314e325991044f5f8ed5c1f85901f79fc (diff) | |
| parent | 1b0bb35ca3cd8e80c9255eefb1e35381ec9aa73a (diff) | |
| download | rust-f548a387a40b4a0d24ae16280930624100ccc7d5.tar.gz rust-f548a387a40b4a0d24ae16280930624100ccc7d5.zip | |
Rollup merge of #69544 - lqd:unrevert-67174, r=Mark-Simulacrum
Unrevert "Remove `checked_add` in `Layout::repeat`" This reapplies @kraai's original `libcore::alloc::Layout::repeat` change from #67174 which was temporarily reverted in #69241. Now that the proper LLVM fix has been cherry-picked, we can unrevert the revert. This change was originally reviewed by @hanna-kruppe on the initial PR. cc @RalfJung
| -rw-r--r-- | src/libcore/alloc.rs | 12 |
1 files changed, 5 insertions, 7 deletions
diff --git a/src/libcore/alloc.rs b/src/libcore/alloc.rs index a04e75bc7ce..71f7f971eab 100644 --- a/src/libcore/alloc.rs +++ b/src/libcore/alloc.rs @@ -241,13 +241,11 @@ impl Layout { #[unstable(feature = "alloc_layout_extra", issue = "55724")] #[inline] pub fn repeat(&self, n: usize) -> Result<(Self, usize), LayoutErr> { - // Warning, removing the checked_add here led to segfaults in #67174. Further - // analysis in #69225 seems to indicate that this is an LTO-related - // miscompilation, so #67174 might be able to be reapplied in the future. - let padded_size = self - .size() - .checked_add(self.padding_needed_for(self.align())) - .ok_or(LayoutErr { private: () })?; + // This cannot overflow. Quoting from the invariant of Layout: + // > `size`, when rounded up to the nearest multiple of `align`, + // > must not overflow (i.e., the rounded value must be less than + // > `usize::MAX`) + let padded_size = self.size() + self.padding_needed_for(self.align()); let alloc_size = padded_size.checked_mul(n).ok_or(LayoutErr { private: () })?; unsafe { |
