diff options
| author | Ralf Jung <post@ralfj.de> | 2022-07-19 20:19:15 -0400 |
|---|---|---|
| committer | Ralf Jung <post@ralfj.de> | 2022-07-20 17:12:07 -0400 |
| commit | adf6d37d83500f7a39f55c64f380e7dbdb221511 (patch) | |
| tree | 10df649771ff4daf0a0f23c14152f5edf2cad5b6 /compiler/rustc_codegen_llvm/src | |
| parent | 3dad266f4018a8356b8259012d09088520735b13 (diff) | |
| download | rust-adf6d37d83500f7a39f55c64f380e7dbdb221511.tar.gz rust-adf6d37d83500f7a39f55c64f380e7dbdb221511.zip | |
slightly cleaner, if more verbose, vtable handling in codegen backends
Diffstat (limited to 'compiler/rustc_codegen_llvm/src')
| -rw-r--r-- | compiler/rustc_codegen_llvm/src/common.rs | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/compiler/rustc_codegen_llvm/src/common.rs b/compiler/rustc_codegen_llvm/src/common.rs index f83b3597438..fb4da9a5f33 100644 --- a/compiler/rustc_codegen_llvm/src/common.rs +++ b/compiler/rustc_codegen_llvm/src/common.rs @@ -240,13 +240,6 @@ impl<'ll, 'tcx> ConstMethods<'tcx> for CodegenCx<'ll, 'tcx> { } Scalar::Ptr(ptr, _size) => { 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, base_addr_space) = match self.tcx.global_alloc(alloc_id) { GlobalAlloc::Memory(alloc) => { let init = const_alloc_to_llvm(self, alloc); @@ -264,7 +257,15 @@ impl<'ll, 'tcx> ConstMethods<'tcx> for CodegenCx<'ll, 'tcx> { self.get_fn_addr(fn_instance.polymorphize(self.tcx)), self.data_layout().instruction_address_space, ), - GlobalAlloc::VTable(..) => bug!("vtables are already handled"), + GlobalAlloc::VTable(ty, trait_ref) => { + let alloc = self + .tcx + .global_alloc(self.tcx.vtable_allocation((ty, trait_ref))) + .unwrap_memory(); + let init = const_alloc_to_llvm(self, alloc); + let value = self.static_addr_of(init, alloc.inner().align, None); + (value, AddressSpace::DATA) + } GlobalAlloc::Static(def_id) => { assert!(self.tcx.is_static(def_id)); assert!(!self.tcx.is_thread_local_static(def_id)); |
