Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 55 additions & 4 deletions src/printer/mir_visitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -265,10 +265,61 @@ fn collect_alloc(
.insert(val, (opaque_placeholder_ty(), global_alloc.clone()));
}
}
GlobalAlloc::Static(_) | GlobalAlloc::VTable(_, _) => {
val_collector
.visited_allocs
.insert(val, (ty, global_alloc.clone()));
GlobalAlloc::Static(_) => {
// Keep builtin-deref behavior; recover only non-builtin-deref cases.
if kind.clone().builtin_deref(true).is_none() {
let prov_ty = get_prov_ty(ty, &offset);
debug_log_println!(
"DEBUG: GlobalAlloc::Static with non-builtin-deref type; alloc_id={:?}, ty={:?}, offset={}, kind={:?}, recovered_prov_ty={:?}",
val,
ty,
offset,
kind,
prov_ty
);
if let Some(p_ty) = prov_ty {
val_collector
.visited_allocs
.insert(val, (p_ty, global_alloc.clone()));
} else {
// Recovery failed: do not treat outer container `ty` as pointee.
val_collector
.visited_allocs
.insert(val, (opaque_placeholder_ty(), global_alloc.clone()));
}
} else {
val_collector
.visited_allocs
.insert(val, (ty, global_alloc.clone()));
}
}
GlobalAlloc::VTable(_, _) => {
// Same policy as Static: keep builtin-deref, recover non-builtin-deref.
if kind.clone().builtin_deref(true).is_none() {
let prov_ty = get_prov_ty(ty, &offset);
debug_log_println!(
"DEBUG: GlobalAlloc::VTable with non-builtin-deref type; alloc_id={:?}, ty={:?}, offset={}, kind={:?}, recovered_prov_ty={:?}",
val,
ty,
offset,
kind,
prov_ty
);
if let Some(p_ty) = prov_ty {
val_collector
.visited_allocs
.insert(val, (p_ty, global_alloc.clone()));
} else {
// Unknown is safer than wrong pointee type.
val_collector
.visited_allocs
.insert(val, (opaque_placeholder_ty(), global_alloc.clone()));
}
} else {
val_collector
.visited_allocs
.insert(val, (ty, global_alloc.clone()));
}
}
GlobalAlloc::Function(_) => {
if !kind.is_fn_ptr() {
Expand Down
2 changes: 2 additions & 0 deletions tests/integration/normalise-filter.jq
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,5 @@
( .types | map(select(.[0].FunType) | sort) )
] | flatten(1) )
}
# drop unstable compiler-internal ids that are unrelated to this regression
| walk(if type == "object" then del(.def_id) else . end)
9 changes: 9 additions & 0 deletions tests/integration/programs/static-vtable-nonbuiltin-deref.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
use std::fmt::Debug;

static S: u8 = 7;
const OBJS: [&'static dyn Debug; 1] = [&S as &dyn Debug];

fn main() {
// Keep trait-object constant usage so both Static and VTable allocs are emitted.
std::hint::black_box(OBJS[0]);
}
Loading