@@ -165,50 +165,27 @@ pub fn unsized_info<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
165165 cx. tcx ( ) . vtable_trait_upcasting_coercion_new_vptr_slot ( ( source, target) ) ;
166166
167167 if let Some ( entry_idx) = vptr_entry_idx {
168- let ptr_ty = cx. type_i8p ( ) ;
168+ let ptr_ty = cx. type_ptr ( ) ;
169169 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) ) ;
172170 let gep = bx. inbounds_gep (
173171 ptr_ty,
174- llvtable ,
172+ old_info ,
175173 & [ bx. const_usize ( u64:: try_from ( entry_idx) . unwrap ( ) ) ] ,
176174 ) ;
177175 let new_vptr = bx. load ( ptr_ty, gep, ptr_align) ;
178176 bx. nonnull_metadata ( new_vptr) ;
179177 // VTable loads are invariant.
180178 bx. set_invariant_load ( new_vptr) ;
181- bx . pointercast ( new_vptr, vtable_ptr_ty )
179+ new_vptr
182180 } else {
183181 old_info
184182 }
185183 }
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 ( ) ) ,
190185 _ => bug ! ( "unsized_info: invalid unsizing {:?} -> {:?}" , source, target) ,
191186 }
192187}
193188
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-
212189/// Coerces `src` to `dst_ty`. `src_ty` must be a pointer.
213190pub fn unsize_ptr < ' a , ' tcx , Bx : BuilderMethods < ' a , ' tcx > > (
214191 bx : & mut Bx ,
@@ -222,8 +199,7 @@ pub fn unsize_ptr<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
222199 ( & ty:: Ref ( _, a, _) , & ty:: Ref ( _, b, _) | & ty:: RawPtr ( ty:: TypeAndMut { ty : b, .. } ) )
223200 | ( & ty:: RawPtr ( ty:: TypeAndMut { ty : a, .. } ) , & ty:: RawPtr ( ty:: TypeAndMut { ty : b, .. } ) ) => {
224201 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) )
227203 }
228204 ( & ty:: Adt ( def_a, _) , & ty:: Adt ( def_b, _) ) => {
229205 assert_eq ! ( def_a, def_b) ;
@@ -248,11 +224,7 @@ pub fn unsize_ptr<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
248224 assert_eq ! ( result, None ) ;
249225 result = Some ( unsize_ptr ( bx, src, src_f. ty , dst_f. ty , old_info) ) ;
250226 }
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 ( )
256228 }
257229 _ => bug ! ( "unsize_ptr: called on bad types" ) ,
258230 }
@@ -271,11 +243,9 @@ pub fn cast_to_dyn_star<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
271243 matches!( dst_ty. kind( ) , ty:: Dynamic ( _, _, ty:: DynStar ) ) ,
272244 "destination type must be a dyn*"
273245 ) ;
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 ) ) ;
276246 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 ( ) ) ,
279249 // FIXME(dyn-star): We probably have to do a bitcast first, then inttoptr.
280250 kind => bug ! ( "unexpected TypeKind for left-hand side of `dyn*` cast: {kind:?}" ) ,
281251 } ;
@@ -398,11 +368,6 @@ pub fn memcpy_ty<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
398368 if flags == MemFlags :: empty ( )
399369 && let Some ( bty) = bx. cx ( ) . scalar_copy_backend_type ( layout)
400370 {
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-
406371 let temp = bx. load ( bty, src, src_align) ;
407372 bx. store ( temp, dst, dst_align) ;
408373 } else {
@@ -456,7 +421,7 @@ pub fn maybe_create_entry_wrapper<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
456421 // The entry function is either `int main(void)` or `int main(int argc, char **argv)`,
457422 // depending on whether the target needs `argc` and `argv` to be passed in.
458423 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 ( ) )
460425 } else {
461426 cx. type_func ( & [ ] , cx. type_int ( ) )
462427 } ;
@@ -490,7 +455,7 @@ pub fn maybe_create_entry_wrapper<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
490455 bx. insert_reference_to_gdb_debug_scripts_section_global ( ) ;
491456
492457 let isize_ty = cx. type_isize ( ) ;
493- let i8pp_ty = cx. type_ptr_to ( cx . type_i8p ( ) ) ;
458+ let ptr_ty = cx. type_ptr ( ) ;
494459 let ( arg_argc, arg_argv) = get_argc_argv ( cx, & mut bx) ;
495460
496461 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>>(
509474 let i8_ty = cx. type_i8 ( ) ;
510475 let arg_sigpipe = bx. const_u8 ( sigpipe) ;
511476
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) ;
514478 ( start_fn, start_ty, vec ! [ rust_main, arg_argc, arg_argv, arg_sigpipe] )
515479 } else {
516480 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) ;
518482 ( rust_main, start_ty, vec ! [ arg_argc, arg_argv] )
519483 } ;
520484
@@ -541,7 +505,7 @@ fn get_argc_argv<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
541505 } else {
542506 // The Rust start function doesn't need `argc` and `argv`, so just pass zeros.
543507 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 ( ) ) ;
545509 ( arg_argc, arg_argv)
546510 }
547511}
0 commit comments