Skip to content

Commit 59d223d

Browse files
committed
slightly cleaner, if more verbose, vtable handling in codegen backends
1 parent 3f24eb8 commit 59d223d

File tree

1 file changed

+5
-8
lines changed

1 file changed

+5
-8
lines changed

src/common.rs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -183,13 +183,6 @@ impl<'gcc, 'tcx> ConstMethods<'tcx> for CodegenCx<'gcc, 'tcx> {
183183
}
184184
Scalar::Ptr(ptr, _size) => {
185185
let (alloc_id, offset) = ptr.into_parts();
186-
// For vtables, get the underlying data allocation.
187-
let alloc_id = match self.tcx.global_alloc(alloc_id) {
188-
GlobalAlloc::VTable(ty, trait_ref) => {
189-
self.tcx.vtable_allocation((ty, trait_ref))
190-
}
191-
_ => alloc_id,
192-
};
193186
let base_addr =
194187
match self.tcx.global_alloc(alloc_id) {
195188
GlobalAlloc::Memory(alloc) => {
@@ -208,7 +201,11 @@ impl<'gcc, 'tcx> ConstMethods<'tcx> for CodegenCx<'gcc, 'tcx> {
208201
GlobalAlloc::Function(fn_instance) => {
209202
self.get_fn_addr(fn_instance)
210203
},
211-
GlobalAlloc::VTable(..) => panic!("vtables are already handled"),
204+
GlobalAlloc::VTable(ty, trait_ref) => {
205+
let alloc = self.tcx.global_alloc(self.tcx.vtable_allocation((ty, trait_ref))).unwrap_memory();
206+
let init = const_alloc_to_gcc(self, alloc);
207+
self.static_addr_of(init, alloc.inner().align, None)
208+
}
212209
GlobalAlloc::Static(def_id) => {
213210
assert!(self.tcx.is_static(def_id));
214211
self.get_static(def_id).get_address(None)

0 commit comments

Comments
 (0)