@@ -195,11 +195,6 @@ pub(crate) fn codegen_const_value<'tcx>(
195
195
}
196
196
Scalar :: Ptr ( ptr, _size) => {
197
197
let ( alloc_id, offset) = ptr. into_parts ( ) ; // we know the `offset` is relative
198
- // For vtables, get the underlying data allocation.
199
- let alloc_id = match fx. tcx . global_alloc ( alloc_id) {
200
- GlobalAlloc :: VTable ( ty, trait_ref) => fx. tcx . vtable_allocation ( ( ty, trait_ref) ) ,
201
- _ => alloc_id,
202
- } ;
203
198
let base_addr = match fx. tcx . global_alloc ( alloc_id) {
204
199
GlobalAlloc :: Memory ( alloc) => {
205
200
let data_id = data_id_for_alloc_id (
@@ -221,7 +216,20 @@ pub(crate) fn codegen_const_value<'tcx>(
221
216
fx. module . declare_func_in_func ( func_id, & mut fx. bcx . func ) ;
222
217
fx. bcx . ins ( ) . func_addr ( fx. pointer_type , local_func_id)
223
218
}
224
- GlobalAlloc :: VTable ( ..) => bug ! ( "vtables are already handled" ) ,
219
+ GlobalAlloc :: VTable ( ty, trait_ref) => {
220
+ let alloc_id = fx. tcx . vtable_allocation ( ( ty, trait_ref) ) ;
221
+ let alloc = fx. tcx . global_alloc ( alloc_id) . unwrap_memory ( ) ;
222
+ // FIXME: factor this common code with the `Memory` arm into a function?
223
+ let data_id = data_id_for_alloc_id (
224
+ & mut fx. constants_cx ,
225
+ fx. module ,
226
+ alloc_id,
227
+ alloc. inner ( ) . mutability ,
228
+ ) ;
229
+ let local_data_id =
230
+ fx. module . declare_data_in_func ( data_id, & mut fx. bcx . func ) ;
231
+ fx. bcx . ins ( ) . global_value ( fx. pointer_type , local_data_id)
232
+ }
225
233
GlobalAlloc :: Static ( def_id) => {
226
234
assert ! ( fx. tcx. is_static( def_id) ) ;
227
235
let data_id = data_id_for_static ( fx. tcx , fx. module , def_id, false ) ;
0 commit comments