Skip to content

Commit

Permalink
Rollup merge of rust-lang#69544 - lqd:unrevert-67174, r=Mark-Simulacrum
Browse files Browse the repository at this point in the history
Unrevert "Remove `checked_add` in `Layout::repeat`"

This reapplies @kraai's original `libcore::alloc::Layout::repeat` change from rust-lang#67174 which was temporarily reverted in rust-lang#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
  • Loading branch information
Dylan-DPC authored Mar 2, 2020
2 parents ffb6d75 + 1b0bb35 commit f548a38
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions src/libcore/alloc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit f548a38

Please sign in to comment.