Skip to content

Commit 0ddff36

Browse files
author
Ellen Arteca
committed
allocation bytes alignment, and cleanup .gitmodules
1 parent bca203e commit 0ddff36

File tree

2 files changed

+6
-8
lines changed

2 files changed

+6
-8
lines changed

.gitmodules

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,3 @@
4141
[submodule "library/backtrace"]
4242
path = library/backtrace
4343
url = https://github.com/rust-lang/backtrace-rs.git
44-
[submodule "src/tools/miri/"]
45-
url = https://github.com/emarteca/miri
46-
branch = matt-alloc-hacks

compiler/rustc_middle/src/mir/interpret/allocation.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ impl<Prov> Allocation<Prov> {
218218

219219
let mut bytes = vec_align.into_boxed_slice();
220220
assert!(bytes.as_ptr() as u64 % align.bytes() == 0);
221-
bytes[..slice.len()].copy_from_slice(&slice);
221+
bytes.copy_from_slice(&slice);
222222

223223
Self {
224224
bytes,
@@ -285,10 +285,11 @@ impl Allocation {
285285
// Compute new pointer provenance, which also adjusts the bytes.
286286
// Realign the pointer
287287
let align_usize: usize = self.align.bytes().try_into().unwrap();
288-
let count_align = ((self.bytes.len() / align_usize) + 1)*align_usize;
289-
290-
let mut vec_align: Vec<u8> = Vec::with_capacity(count_align);
291-
vec_align.resize(count_align, 0);
288+
let layout = std::alloc::Layout::from_size_align(self.bytes.len(), align_usize).unwrap();
289+
let mut vec_align = unsafe {
290+
let buf = std::alloc::alloc(layout);
291+
Vec::from_raw_parts(buf as *mut u8, self.bytes.len(), self.bytes.len())
292+
};
292293
assert!(vec_align.as_ptr() as usize % align_usize == 0);
293294

294295
vec_align[..self.bytes.len()].copy_from_slice(&self.bytes);

0 commit comments

Comments
 (0)