Skip to content

Commit 28695bf

Browse files
committed
Auto merge of rust-lang#130497 - saethlin:alloc-zeroed-is-unstable, r=bjorn3
read_volatile __rust_no_alloc_shim_is_unstable in alloc_zeroed It was pointed out in rust-lang#128854 (comment) that the magic volatile read was probably missing from `alloc_zeroed`. I can't find any mention of `alloc_zeroed` on rust-lang#86844, so it looks like this was just missed initially.
2 parents b19bf06 + d740b8d commit 28695bf

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

alloc/src/alloc.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,13 @@ pub unsafe fn realloc(ptr: *mut u8, layout: Layout, new_size: usize) -> *mut u8
171171
#[inline]
172172
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
173173
pub unsafe fn alloc_zeroed(layout: Layout) -> *mut u8 {
174-
unsafe { __rust_alloc_zeroed(layout.size(), layout.align()) }
174+
unsafe {
175+
// Make sure we don't accidentally allow omitting the allocator shim in
176+
// stable code until it is actually stabilized.
177+
core::ptr::read_volatile(&__rust_no_alloc_shim_is_unstable);
178+
179+
__rust_alloc_zeroed(layout.size(), layout.align())
180+
}
175181
}
176182

177183
#[cfg(not(test))]

0 commit comments

Comments
 (0)