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_cranelift/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_cranelift/src')
| -rw-r--r-- | compiler/rustc_codegen_cranelift/src/constant.rs | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/compiler/rustc_codegen_cranelift/src/constant.rs b/compiler/rustc_codegen_cranelift/src/constant.rs index 2380f3e1df0..b5a14348589 100644 --- a/compiler/rustc_codegen_cranelift/src/constant.rs +++ b/compiler/rustc_codegen_cranelift/src/constant.rs @@ -195,11 +195,6 @@ pub(crate) fn codegen_const_value<'tcx>( } Scalar::Ptr(ptr, _size) => { let (alloc_id, offset) = ptr.into_parts(); // we know the `offset` is relative - // For vtables, get the underlying data allocation. - let alloc_id = match fx.tcx.global_alloc(alloc_id) { - GlobalAlloc::VTable(ty, trait_ref) => fx.tcx.vtable_allocation((ty, trait_ref)), - _ => alloc_id, - }; let base_addr = match fx.tcx.global_alloc(alloc_id) { GlobalAlloc::Memory(alloc) => { let data_id = data_id_for_alloc_id( @@ -221,7 +216,20 @@ pub(crate) fn codegen_const_value<'tcx>( fx.module.declare_func_in_func(func_id, &mut fx.bcx.func); fx.bcx.ins().func_addr(fx.pointer_type, local_func_id) } - GlobalAlloc::VTable(..) => bug!("vtables are already handled"), + GlobalAlloc::VTable(ty, trait_ref) => { + let alloc_id = fx.tcx.vtable_allocation((ty, trait_ref)); + let alloc = fx.tcx.global_alloc(alloc_id).unwrap_memory(); + // FIXME: factor this common code with the `Memory` arm into a function? + let data_id = data_id_for_alloc_id( + &mut fx.constants_cx, + fx.module, + alloc_id, + alloc.inner().mutability, + ); + let local_data_id = + fx.module.declare_data_in_func(data_id, &mut fx.bcx.func); + fx.bcx.ins().global_value(fx.pointer_type, local_data_id) + } GlobalAlloc::Static(def_id) => { assert!(fx.tcx.is_static(def_id)); let data_id = data_id_for_static(fx.tcx, fx.module, def_id, false); |
