Skip to content

Commit 4209eb5

Browse files
committed
fix(printer): avoid panic on non-builtin static/vtable alloc pointers
1 parent afb5944 commit 4209eb5

1 file changed

Lines changed: 57 additions & 4 deletions

File tree

src/printer/mir_visitor.rs

Lines changed: 57 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -265,10 +265,63 @@ fn collect_alloc(
265265
.insert(val, (opaque_placeholder_ty(), global_alloc.clone()));
266266
}
267267
}
268-
GlobalAlloc::Static(_) | GlobalAlloc::VTable(_, _) => {
269-
val_collector
270-
.visited_allocs
271-
.insert(val, (ty, global_alloc.clone()));
268+
GlobalAlloc::Static(_) => {
269+
// Keep established behavior for direct pointer/reference types.
270+
// Recovery is only for non-builtin-deref container paths.
271+
if kind.clone().builtin_deref(true).is_none() {
272+
let prov_ty = get_prov_ty(ty, &offset);
273+
debug_log_println!(
274+
"DEBUG: GlobalAlloc::Static with non-builtin-deref type; alloc_id={:?}, ty={:?}, offset={}, kind={:?}, recovered_prov_ty={:?}",
275+
val,
276+
ty,
277+
offset,
278+
kind,
279+
prov_ty
280+
);
281+
if let Some(p_ty) = prov_ty {
282+
val_collector
283+
.visited_allocs
284+
.insert(val, (p_ty, global_alloc.clone()));
285+
} else {
286+
// Unknown is safer than recording an incorrect outer container type.
287+
val_collector
288+
.visited_allocs
289+
.insert(val, (opaque_placeholder_ty(), global_alloc.clone()));
290+
}
291+
} else {
292+
val_collector
293+
.visited_allocs
294+
.insert(val, (ty, global_alloc.clone()));
295+
}
296+
}
297+
GlobalAlloc::VTable(_, _) => {
298+
// Same policy as static allocs: preserve direct-deref behavior,
299+
// recover only on the fallback path.
300+
if kind.clone().builtin_deref(true).is_none() {
301+
let prov_ty = get_prov_ty(ty, &offset);
302+
debug_log_println!(
303+
"DEBUG: GlobalAlloc::VTable with non-builtin-deref type; alloc_id={:?}, ty={:?}, offset={}, kind={:?}, recovered_prov_ty={:?}",
304+
val,
305+
ty,
306+
offset,
307+
kind,
308+
prov_ty
309+
);
310+
if let Some(p_ty) = prov_ty {
311+
val_collector
312+
.visited_allocs
313+
.insert(val, (p_ty, global_alloc.clone()));
314+
} else {
315+
// Unknown is safer than recording an incorrect outer container type.
316+
val_collector
317+
.visited_allocs
318+
.insert(val, (opaque_placeholder_ty(), global_alloc.clone()));
319+
}
320+
} else {
321+
val_collector
322+
.visited_allocs
323+
.insert(val, (ty, global_alloc.clone()));
324+
}
272325
}
273326
GlobalAlloc::Function(_) => {
274327
if !kind.is_fn_ptr() {

0 commit comments

Comments
 (0)