make basic allocation functions track_caller in Miri for nicer backtr… · qinheping/verify-rust-std@dbf585c (original) (raw)
`@@ -89,6 +89,7 @@ pub use std::alloc::Global;
`
89
89
`#[stable(feature = "global_alloc", since = "1.28.0")]
`
90
90
`#[must_use = "losing the pointer will leak memory"]
`
91
91
`#[inline]
`
``
92
`+
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
`
92
93
`pub unsafe fn alloc(layout: Layout) -> *mut u8 {
`
93
94
`unsafe {
`
94
95
`// Make sure we don't accidentally allow omitting the allocator shim in
`
`@@ -113,6 +114,7 @@ pub unsafe fn alloc(layout: Layout) -> *mut u8 {
`
113
114
`` /// See [GlobalAlloc::dealloc
].
``
114
115
`#[stable(feature = "global_alloc", since = "1.28.0")]
`
115
116
`#[inline]
`
``
117
`+
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
`
116
118
`pub unsafe fn dealloc(ptr: *mut u8, layout: Layout) {
`
117
119
`unsafe { __rust_dealloc(ptr, layout.size(), layout.align()) }
`
118
120
`}
`
`@@ -132,6 +134,7 @@ pub unsafe fn dealloc(ptr: *mut u8, layout: Layout) {
`
132
134
`#[stable(feature = "global_alloc", since = "1.28.0")]
`
133
135
`#[must_use = "losing the pointer will leak memory"]
`
134
136
`#[inline]
`
``
137
`+
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
`
135
138
`pub unsafe fn realloc(ptr: *mut u8, layout: Layout, new_size: usize) -> *mut u8 {
`
136
139
`unsafe { __rust_realloc(ptr, layout.size(), layout.align(), new_size) }
`
137
140
`}
`
`@@ -166,13 +169,15 @@ pub unsafe fn realloc(ptr: *mut u8, layout: Layout, new_size: usize) -> *mut u8
`
166
169
`#[stable(feature = "global_alloc", since = "1.28.0")]
`
167
170
`#[must_use = "losing the pointer will leak memory"]
`
168
171
`#[inline]
`
``
172
`+
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
`
169
173
`pub unsafe fn alloc_zeroed(layout: Layout) -> *mut u8 {
`
170
174
`unsafe { __rust_alloc_zeroed(layout.size(), layout.align()) }
`
171
175
`}
`
172
176
``
173
177
`#[cfg(not(test))]
`
174
178
`impl Global {
`
175
179
`#[inline]
`
``
180
`+
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
`
176
181
`fn alloc_impl(&self, layout: Layout, zeroed: bool) -> Result<NonNull<[u8]>, AllocError> {
`
177
182
`match layout.size() {
`
178
183
`0 => Ok(NonNull::slice_from_raw_parts(layout.dangling(), 0)),
`
`@@ -187,6 +192,7 @@ impl Global {
`
187
192
``
188
193
`` // SAFETY: Same as Allocator::grow
``
189
194
`#[inline]
`
``
195
`+
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
`
190
196
`unsafe fn grow_impl(
`
191
197
`&self,
`
192
198
`ptr: NonNull,
`
`@@ -237,16 +243,19 @@ impl Global {
`
237
243
`#[cfg(not(test))]
`
238
244
`unsafe impl Allocator for Global {
`
239
245
`#[inline]
`
``
246
`+
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
`
240
247
`fn allocate(&self, layout: Layout) -> Result<NonNull<[u8]>, AllocError> {
`
241
248
`self.alloc_impl(layout, false)
`
242
249
`}
`
243
250
``
244
251
`#[inline]
`
``
252
`+
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
`
245
253
`fn allocate_zeroed(&self, layout: Layout) -> Result<NonNull<[u8]>, AllocError> {
`
246
254
`self.alloc_impl(layout, true)
`
247
255
`}
`
248
256
``
249
257
`#[inline]
`
``
258
`+
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
`
250
259
`unsafe fn deallocate(&self, ptr: NonNull, layout: Layout) {
`
251
260
`if layout.size() != 0 {
`
252
261
`` // SAFETY: layout
is non-zero in size,
``
`@@ -256,6 +265,7 @@ unsafe impl Allocator for Global {
`
256
265
`}
`
257
266
``
258
267
`#[inline]
`
``
268
`+
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
`
259
269
`unsafe fn grow(
`
260
270
`&self,
`
261
271
`ptr: NonNull,
`
`@@ -267,6 +277,7 @@ unsafe impl Allocator for Global {
`
267
277
`}
`
268
278
``
269
279
`#[inline]
`
``
280
`+
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
`
270
281
`unsafe fn grow_zeroed(
`
271
282
`&self,
`
272
283
`ptr: NonNull,
`
`@@ -278,6 +289,7 @@ unsafe impl Allocator for Global {
`
278
289
`}
`
279
290
``
280
291
`#[inline]
`
``
292
`+
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
`
281
293
`unsafe fn shrink(
`
282
294
`&self,
`
283
295
`ptr: NonNull,
`
`@@ -325,6 +337,7 @@ unsafe impl Allocator for Global {
`
325
337
`#[cfg(all(not(no_global_oom_handling), not(test)))]
`
326
338
`#[lang = "exchange_malloc"]
`
327
339
`#[inline]
`
``
340
`+
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
`
328
341
`unsafe fn exchange_malloc(size: usize, align: usize) -> *mut u8 {
`
329
342
`let layout = unsafe { Layout::from_size_align_unchecked(size, align) };
`
330
343
`match Global.allocate(layout) {
`