@@ -183,13 +183,6 @@ impl<'gcc, 'tcx> ConstMethods<'tcx> for CodegenCx<'gcc, 'tcx> {
183
183
}
184
184
Scalar :: Ptr ( ptr, _size) => {
185
185
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
- } ;
193
186
let base_addr =
194
187
match self . tcx . global_alloc ( alloc_id) {
195
188
GlobalAlloc :: Memory ( alloc) => {
@@ -208,7 +201,11 @@ impl<'gcc, 'tcx> ConstMethods<'tcx> for CodegenCx<'gcc, 'tcx> {
208
201
GlobalAlloc :: Function ( fn_instance) => {
209
202
self . get_fn_addr ( fn_instance)
210
203
} ,
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
+ }
212
209
GlobalAlloc :: Static ( def_id) => {
213
210
assert ! ( self . tcx. is_static( def_id) ) ;
214
211
self . get_static ( def_id) . get_address ( None )
0 commit comments