@@ -39,7 +39,7 @@ fn fn_sig_for_fn_abi<'tcx>(
3939 tcx. thread_local_ptr_ty ( instance. def_id ( ) ) ,
4040 false ,
4141 hir:: Safety :: Safe ,
42- rustc_abi:: ExternAbi :: Unadjusted ,
42+ rustc_abi:: ExternAbi :: Rust ,
4343 ) ;
4444 }
4545
@@ -268,28 +268,29 @@ fn fn_abi_of_instance<'tcx>(
268268}
269269
270270// Handle safe Rust thin and wide pointers.
271- fn adjust_for_rust_scalar < ' tcx > (
271+ fn arg_attrs_for_rust_scalar < ' tcx > (
272272 cx : LayoutCx < ' tcx > ,
273- attrs : & mut ArgAttributes ,
274273 scalar : Scalar ,
275274 layout : TyAndLayout < ' tcx > ,
276275 offset : Size ,
277276 is_return : bool ,
278277 drop_target_pointee : Option < Ty < ' tcx > > ,
279- ) {
278+ ) -> ArgAttributes {
279+ let mut attrs = ArgAttributes :: new ( ) ;
280+
280281 // Booleans are always a noundef i1 that needs to be zero-extended.
281282 if scalar. is_bool ( ) {
282283 attrs. ext ( ArgExtension :: Zext ) ;
283284 attrs. set ( ArgAttribute :: NoUndef ) ;
284- return ;
285+ return attrs ;
285286 }
286287
287288 if !scalar. is_uninit_valid ( ) {
288289 attrs. set ( ArgAttribute :: NoUndef ) ;
289290 }
290291
291292 // Only pointer types handled below.
292- let Scalar :: Initialized { value : Pointer ( _) , valid_range } = scalar else { return } ;
293+ let Scalar :: Initialized { value : Pointer ( _) , valid_range } = scalar else { return attrs } ;
293294
294295 // Set `nonnull` if the validity range excludes zero, or for the argument to `drop_in_place`,
295296 // which must be nonnull per its documented safety requirements.
@@ -358,6 +359,8 @@ fn adjust_for_rust_scalar<'tcx>(
358359 }
359360 }
360361 }
362+
363+ attrs
361364}
362365
363366/// Ensure that the ABI makes basic sense.
@@ -471,9 +474,10 @@ fn fn_abi_new_uncached<'tcx>(
471474 let ( caller_location, determined_fn_def_id, is_virtual_call) = if let Some ( instance) = instance
472475 {
473476 let is_virtual_call = matches ! ( instance. def, ty:: InstanceKind :: Virtual ( ..) ) ;
477+ let is_tls_shim_call = matches ! ( instance. def, ty:: InstanceKind :: ThreadLocalShim ( _) ) ;
474478 (
475479 instance. def . requires_caller_location ( tcx) . then ( || tcx. caller_location_ty ( ) ) ,
476- if is_virtual_call { None } else { Some ( instance. def_id ( ) ) } ,
480+ if is_virtual_call || is_tls_shim_call { None } else { Some ( instance. def_id ( ) ) } ,
477481 is_virtual_call,
478482 )
479483 } else {
@@ -530,17 +534,7 @@ fn fn_abi_new_uncached<'tcx>(
530534 } ;
531535
532536 let mut arg = ArgAbi :: new ( cx, layout, |layout, scalar, offset| {
533- let mut attrs = ArgAttributes :: new ( ) ;
534- adjust_for_rust_scalar (
535- * cx,
536- & mut attrs,
537- scalar,
538- * layout,
539- offset,
540- is_return,
541- drop_target_pointee,
542- ) ;
543- attrs
537+ arg_attrs_for_rust_scalar ( * cx, scalar, * layout, offset, is_return, drop_target_pointee)
544538 } ) ;
545539
546540 if arg. layout . is_zst ( ) {
@@ -563,6 +557,7 @@ fn fn_abi_new_uncached<'tcx>(
563557 c_variadic : sig. c_variadic ,
564558 fixed_count : inputs. len ( ) as u32 ,
565559 conv,
560+ // FIXME return false for tls shim
566561 can_unwind : fn_can_unwind (
567562 tcx,
568563 // Since `#[rustc_nounwind]` can change unwinding, we cannot infer unwinding by `fn_def_id` for a virtual call.
@@ -575,8 +570,9 @@ fn fn_abi_new_uncached<'tcx>(
575570 & mut fn_abi,
576571 sig. abi ,
577572 // If this is a virtual call, we cannot pass the `fn_def_id`, as it might call other
578- // functions from vtable. Internally, `deduced_param_attrs` attempts to infer attributes by
579- // visit the function body.
573+ // functions from vtable. And for a tls shim, passing the `fn_def_id` would refer to
574+ // the underlying static. Internally, `deduced_param_attrs` attempts to infer attributes
575+ // by visit the function body.
580576 determined_fn_def_id,
581577 ) ;
582578 debug ! ( "fn_abi_new_uncached = {:?}" , fn_abi) ;
0 commit comments