@@ -39,7 +39,7 @@ fn fn_sig_for_fn_abi<'tcx>(
39
39
tcx. thread_local_ptr_ty ( instance. def_id ( ) ) ,
40
40
false ,
41
41
hir:: Safety :: Safe ,
42
- rustc_abi:: ExternAbi :: Unadjusted ,
42
+ rustc_abi:: ExternAbi :: Rust ,
43
43
) ;
44
44
}
45
45
@@ -268,28 +268,29 @@ fn fn_abi_of_instance<'tcx>(
268
268
}
269
269
270
270
// Handle safe Rust thin and wide pointers.
271
- fn adjust_for_rust_scalar < ' tcx > (
271
+ fn arg_attrs_for_rust_scalar < ' tcx > (
272
272
cx : LayoutCx < ' tcx > ,
273
- attrs : & mut ArgAttributes ,
274
273
scalar : Scalar ,
275
274
layout : TyAndLayout < ' tcx > ,
276
275
offset : Size ,
277
276
is_return : bool ,
278
277
drop_target_pointee : Option < Ty < ' tcx > > ,
279
- ) {
278
+ ) -> ArgAttributes {
279
+ let mut attrs = ArgAttributes :: new ( ) ;
280
+
280
281
// Booleans are always a noundef i1 that needs to be zero-extended.
281
282
if scalar. is_bool ( ) {
282
283
attrs. ext ( ArgExtension :: Zext ) ;
283
284
attrs. set ( ArgAttribute :: NoUndef ) ;
284
- return ;
285
+ return attrs ;
285
286
}
286
287
287
288
if !scalar. is_uninit_valid ( ) {
288
289
attrs. set ( ArgAttribute :: NoUndef ) ;
289
290
}
290
291
291
292
// 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 } ;
293
294
294
295
// Set `nonnull` if the validity range excludes zero, or for the argument to `drop_in_place`,
295
296
// which must be nonnull per its documented safety requirements.
@@ -358,6 +359,8 @@ fn adjust_for_rust_scalar<'tcx>(
358
359
}
359
360
}
360
361
}
362
+
363
+ attrs
361
364
}
362
365
363
366
/// Ensure that the ABI makes basic sense.
@@ -471,9 +474,10 @@ fn fn_abi_new_uncached<'tcx>(
471
474
let ( caller_location, determined_fn_def_id, is_virtual_call) = if let Some ( instance) = instance
472
475
{
473
476
let is_virtual_call = matches ! ( instance. def, ty:: InstanceKind :: Virtual ( ..) ) ;
477
+ let is_tls_shim_call = matches ! ( instance. def, ty:: InstanceKind :: ThreadLocalShim ( _) ) ;
474
478
(
475
479
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 ( ) ) } ,
477
481
is_virtual_call,
478
482
)
479
483
} else {
@@ -530,17 +534,7 @@ fn fn_abi_new_uncached<'tcx>(
530
534
} ;
531
535
532
536
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)
544
538
} ) ;
545
539
546
540
if arg. layout . is_zst ( ) {
@@ -563,6 +557,7 @@ fn fn_abi_new_uncached<'tcx>(
563
557
c_variadic : sig. c_variadic ,
564
558
fixed_count : inputs. len ( ) as u32 ,
565
559
conv,
560
+ // FIXME return false for tls shim
566
561
can_unwind : fn_can_unwind (
567
562
tcx,
568
563
// 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>(
575
570
& mut fn_abi,
576
571
sig. abi ,
577
572
// 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.
580
576
determined_fn_def_id,
581
577
) ;
582
578
debug ! ( "fn_abi_new_uncached = {:?}" , fn_abi) ;
0 commit comments