@@ -165,50 +165,27 @@ pub fn unsized_info<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
165
165
cx. tcx ( ) . vtable_trait_upcasting_coercion_new_vptr_slot ( ( source, target) ) ;
166
166
167
167
if let Some ( entry_idx) = vptr_entry_idx {
168
- let ptr_ty = cx. type_i8p ( ) ;
168
+ let ptr_ty = cx. type_ptr ( ) ;
169
169
let ptr_align = cx. tcx ( ) . data_layout . pointer_align . abi ;
170
- let vtable_ptr_ty = vtable_ptr_ty ( cx, target, target_dyn_kind) ;
171
- let llvtable = bx. pointercast ( old_info, bx. type_ptr_to ( ptr_ty) ) ;
172
170
let gep = bx. inbounds_gep (
173
171
ptr_ty,
174
- llvtable ,
172
+ old_info ,
175
173
& [ bx. const_usize ( u64:: try_from ( entry_idx) . unwrap ( ) ) ] ,
176
174
) ;
177
175
let new_vptr = bx. load ( ptr_ty, gep, ptr_align) ;
178
176
bx. nonnull_metadata ( new_vptr) ;
179
177
// VTable loads are invariant.
180
178
bx. set_invariant_load ( new_vptr) ;
181
- bx . pointercast ( new_vptr, vtable_ptr_ty )
179
+ new_vptr
182
180
} else {
183
181
old_info
184
182
}
185
183
}
186
- ( _, & ty:: Dynamic ( ref data, _, target_dyn_kind) ) => {
187
- let vtable_ptr_ty = vtable_ptr_ty ( cx, target, target_dyn_kind) ;
188
- cx. const_ptrcast ( meth:: get_vtable ( cx, source, data. principal ( ) ) , vtable_ptr_ty)
189
- }
184
+ ( _, & ty:: Dynamic ( ref data, _, _) ) => meth:: get_vtable ( cx, source, data. principal ( ) ) ,
190
185
_ => bug ! ( "unsized_info: invalid unsizing {:?} -> {:?}" , source, target) ,
191
186
}
192
187
}
193
188
194
- // Returns the vtable pointer type of a `dyn` or `dyn*` type
195
- fn vtable_ptr_ty < ' tcx , Cx : CodegenMethods < ' tcx > > (
196
- cx : & Cx ,
197
- target : Ty < ' tcx > ,
198
- kind : ty:: DynKind ,
199
- ) -> <Cx as BackendTypes >:: Type {
200
- cx. scalar_pair_element_backend_type (
201
- cx. layout_of ( match kind {
202
- // vtable is the second field of `*mut dyn Trait`
203
- ty:: Dyn => Ty :: new_mut_ptr ( cx. tcx ( ) , target) ,
204
- // vtable is the second field of `dyn* Trait`
205
- ty:: DynStar => target,
206
- } ) ,
207
- 1 ,
208
- true ,
209
- )
210
- }
211
-
212
189
/// Coerces `src` to `dst_ty`. `src_ty` must be a pointer.
213
190
pub fn unsize_ptr < ' a , ' tcx , Bx : BuilderMethods < ' a , ' tcx > > (
214
191
bx : & mut Bx ,
@@ -222,8 +199,7 @@ pub fn unsize_ptr<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
222
199
( & ty:: Ref ( _, a, _) , & ty:: Ref ( _, b, _) | & ty:: RawPtr ( ty:: TypeAndMut { ty : b, .. } ) )
223
200
| ( & ty:: RawPtr ( ty:: TypeAndMut { ty : a, .. } ) , & ty:: RawPtr ( ty:: TypeAndMut { ty : b, .. } ) ) => {
224
201
assert_eq ! ( bx. cx( ) . type_is_sized( a) , old_info. is_none( ) ) ;
225
- let ptr_ty = bx. cx ( ) . type_ptr_to ( bx. cx ( ) . backend_type ( bx. cx ( ) . layout_of ( b) ) ) ;
226
- ( bx. pointercast ( src, ptr_ty) , unsized_info ( bx, a, b, old_info) )
202
+ ( src, unsized_info ( bx, a, b, old_info) )
227
203
}
228
204
( & ty:: Adt ( def_a, _) , & ty:: Adt ( def_b, _) ) => {
229
205
assert_eq ! ( def_a, def_b) ;
@@ -248,11 +224,7 @@ pub fn unsize_ptr<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
248
224
assert_eq ! ( result, None ) ;
249
225
result = Some ( unsize_ptr ( bx, src, src_f. ty , dst_f. ty , old_info) ) ;
250
226
}
251
- let ( lldata, llextra) = result. unwrap ( ) ;
252
- let lldata_ty = bx. cx ( ) . scalar_pair_element_backend_type ( dst_layout, 0 , true ) ;
253
- let llextra_ty = bx. cx ( ) . scalar_pair_element_backend_type ( dst_layout, 1 , true ) ;
254
- // HACK(eddyb) have to bitcast pointers until LLVM removes pointee types.
255
- ( bx. bitcast ( lldata, lldata_ty) , bx. bitcast ( llextra, llextra_ty) )
227
+ result. unwrap ( )
256
228
}
257
229
_ => bug ! ( "unsize_ptr: called on bad types" ) ,
258
230
}
@@ -271,11 +243,9 @@ pub fn cast_to_dyn_star<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
271
243
matches!( dst_ty. kind( ) , ty:: Dynamic ( _, _, ty:: DynStar ) ) ,
272
244
"destination type must be a dyn*"
273
245
) ;
274
- // FIXME(dyn-star): We can remove this when all supported LLVMs use opaque ptrs only.
275
- let unit_ptr = bx. cx ( ) . type_ptr_to ( bx. cx ( ) . type_struct ( & [ ] , false ) ) ;
276
246
let src = match bx. cx ( ) . type_kind ( bx. cx ( ) . backend_type ( src_ty_and_layout) ) {
277
- TypeKind :: Pointer => bx . pointercast ( src, unit_ptr ) ,
278
- TypeKind :: Integer => bx. inttoptr ( src, unit_ptr ) ,
247
+ TypeKind :: Pointer => src,
248
+ TypeKind :: Integer => bx. inttoptr ( src, bx . type_ptr ( ) ) ,
279
249
// FIXME(dyn-star): We probably have to do a bitcast first, then inttoptr.
280
250
kind => bug ! ( "unexpected TypeKind for left-hand side of `dyn*` cast: {kind:?}" ) ,
281
251
} ;
@@ -398,11 +368,6 @@ pub fn memcpy_ty<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
398
368
if flags == MemFlags :: empty ( )
399
369
&& let Some ( bty) = bx. cx ( ) . scalar_copy_backend_type ( layout)
400
370
{
401
- // I look forward to only supporting opaque pointers
402
- let pty = bx. type_ptr_to ( bty) ;
403
- let src = bx. pointercast ( src, pty) ;
404
- let dst = bx. pointercast ( dst, pty) ;
405
-
406
371
let temp = bx. load ( bty, src, src_align) ;
407
372
bx. store ( temp, dst, dst_align) ;
408
373
} else {
@@ -456,7 +421,7 @@ pub fn maybe_create_entry_wrapper<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
456
421
// The entry function is either `int main(void)` or `int main(int argc, char **argv)`,
457
422
// depending on whether the target needs `argc` and `argv` to be passed in.
458
423
let llfty = if cx. sess ( ) . target . main_needs_argc_argv {
459
- cx. type_func ( & [ cx. type_int ( ) , cx. type_ptr_to ( cx . type_i8p ( ) ) ] , cx. type_int ( ) )
424
+ cx. type_func ( & [ cx. type_int ( ) , cx. type_ptr ( ) ] , cx. type_int ( ) )
460
425
} else {
461
426
cx. type_func ( & [ ] , cx. type_int ( ) )
462
427
} ;
@@ -490,7 +455,7 @@ pub fn maybe_create_entry_wrapper<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
490
455
bx. insert_reference_to_gdb_debug_scripts_section_global ( ) ;
491
456
492
457
let isize_ty = cx. type_isize ( ) ;
493
- let i8pp_ty = cx. type_ptr_to ( cx . type_i8p ( ) ) ;
458
+ let ptr_ty = cx. type_ptr ( ) ;
494
459
let ( arg_argc, arg_argv) = get_argc_argv ( cx, & mut bx) ;
495
460
496
461
let ( start_fn, start_ty, args) = if let EntryFnType :: Main { sigpipe } = entry_type {
@@ -509,12 +474,11 @@ pub fn maybe_create_entry_wrapper<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
509
474
let i8_ty = cx. type_i8 ( ) ;
510
475
let arg_sigpipe = bx. const_u8 ( sigpipe) ;
511
476
512
- let start_ty =
513
- cx. type_func ( & [ cx. val_ty ( rust_main) , isize_ty, i8pp_ty, i8_ty] , isize_ty) ;
477
+ let start_ty = cx. type_func ( & [ cx. val_ty ( rust_main) , isize_ty, ptr_ty, i8_ty] , isize_ty) ;
514
478
( start_fn, start_ty, vec ! [ rust_main, arg_argc, arg_argv, arg_sigpipe] )
515
479
} else {
516
480
debug ! ( "using user-defined start fn" ) ;
517
- let start_ty = cx. type_func ( & [ isize_ty, i8pp_ty ] , isize_ty) ;
481
+ let start_ty = cx. type_func ( & [ isize_ty, ptr_ty ] , isize_ty) ;
518
482
( rust_main, start_ty, vec ! [ arg_argc, arg_argv] )
519
483
} ;
520
484
@@ -541,7 +505,7 @@ fn get_argc_argv<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
541
505
} else {
542
506
// The Rust start function doesn't need `argc` and `argv`, so just pass zeros.
543
507
let arg_argc = bx. const_int ( cx. type_int ( ) , 0 ) ;
544
- let arg_argv = bx. const_null ( cx. type_ptr_to ( cx . type_i8p ( ) ) ) ;
508
+ let arg_argv = bx. const_null ( cx. type_ptr ( ) ) ;
545
509
( arg_argc, arg_argv)
546
510
}
547
511
}
0 commit comments