Skip to content

Commit f8dec3d

Browse files
authored
Rollup merge of #77047 - RalfJung:miri-dealloc, r=oli-obk
Miri: more informative deallocation error messages Make sure we show the affected AllocId. r? @oli-obk
2 parents 049ba0c + 731113b commit f8dec3d

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

compiler/rustc_mir/src/interpret/memory.rs

+8-4
Original file line numberDiff line numberDiff line change
@@ -285,9 +285,11 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
285285
None => {
286286
// Deallocating global memory -- always an error
287287
return Err(match self.tcx.get_global_alloc(ptr.alloc_id) {
288-
Some(GlobalAlloc::Function(..)) => err_ub_format!("deallocating a function"),
288+
Some(GlobalAlloc::Function(..)) => {
289+
err_ub_format!("deallocating {}, which is a function", ptr.alloc_id)
290+
}
289291
Some(GlobalAlloc::Static(..) | GlobalAlloc::Memory(..)) => {
290-
err_ub_format!("deallocating static memory")
292+
err_ub_format!("deallocating {}, which is static memory", ptr.alloc_id)
291293
}
292294
None => err_ub!(PointerUseAfterFree(ptr.alloc_id)),
293295
}
@@ -297,15 +299,17 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
297299

298300
if alloc_kind != kind {
299301
throw_ub_format!(
300-
"deallocating {} memory using {} deallocation operation",
302+
"deallocating {}, which is {} memory, using {} deallocation operation",
303+
ptr.alloc_id,
301304
alloc_kind,
302305
kind
303306
);
304307
}
305308
if let Some((size, align)) = old_size_and_align {
306309
if size != alloc.size || align != alloc.align {
307310
throw_ub_format!(
308-
"incorrect layout on deallocation: allocation has size {} and alignment {}, but gave size {} and alignment {}",
311+
"incorrect layout on deallocation: {} has size {} and alignment {}, but gave size {} and alignment {}",
312+
ptr.alloc_id,
309313
alloc.size.bytes(),
310314
alloc.align.bytes(),
311315
size.bytes(),

0 commit comments

Comments
 (0)