1
Fork 0

add a Vtable kind of symbolic allocations

This commit is contained in:
Ralf Jung 2022-07-17 11:36:37 -04:00
parent bca7b0279f
commit 8f290184d2

View file

@ -183,6 +183,13 @@ impl<'gcc, 'tcx> ConstMethods<'tcx> for CodegenCx<'gcc, 'tcx> {
} }
Scalar::Ptr(ptr, _size) => { Scalar::Ptr(ptr, _size) => {
let (alloc_id, offset) = ptr.into_parts(); let (alloc_id, offset) = ptr.into_parts();
// For vtables, get the underlying data allocation.
let alloc_id = match self.tcx.global_alloc(alloc_id) {
GlobalAlloc::Vtable(ty, trait_ref) => {
self.tcx.vtable_allocation((ty, trait_ref))
}
_ => alloc_id,
};
let base_addr = let base_addr =
match self.tcx.global_alloc(alloc_id) { match self.tcx.global_alloc(alloc_id) {
GlobalAlloc::Memory(alloc) => { GlobalAlloc::Memory(alloc) => {
@ -201,6 +208,7 @@ impl<'gcc, 'tcx> ConstMethods<'tcx> for CodegenCx<'gcc, 'tcx> {
GlobalAlloc::Function(fn_instance) => { GlobalAlloc::Function(fn_instance) => {
self.get_fn_addr(fn_instance) self.get_fn_addr(fn_instance)
}, },
GlobalAlloc::Vtable(..) => panic!("vtables are already handled"),
GlobalAlloc::Static(def_id) => { GlobalAlloc::Static(def_id) => {
assert!(self.tcx.is_static(def_id)); assert!(self.tcx.is_static(def_id));
self.get_static(def_id).get_address(None) self.get_static(def_id).get_address(None)