@@ -14,6 +14,7 @@ use rustc_middle::ty::adjustment::CustomCoerceUnsized;
14
14
use rustc_middle:: ty:: Instance ;
15
15
use rustc_middle:: ty:: TyCtxt ;
16
16
use rustc_middle:: ty:: { self , Ty } ;
17
+ use rustc_span:: def_id:: DefId ;
17
18
use rustc_span:: def_id:: LOCAL_CRATE ;
18
19
use rustc_span:: ErrorGuaranteed ;
19
20
@@ -57,13 +58,24 @@ fn custom_coerce_unsize_info<'tcx>(
57
58
/// linkers will optimize such that dead calls to unresolved symbols are not an error, but this is
58
59
/// not guaranteed. So we used this function in codegen backends to ensure we do not generate any
59
60
/// unlinkable calls.
61
+ ///
62
+ /// Note that calls to LLVM intrinsics are uniquely okay because they won't make it to the linker.
60
63
pub fn is_call_from_compiler_builtins_to_upstream_monomorphization < ' tcx > (
61
64
tcx : TyCtxt < ' tcx > ,
62
65
instance : Instance < ' tcx > ,
63
66
) -> bool {
64
- !instance. def_id ( ) . is_local ( )
67
+ fn is_llvm_intrinsic ( tcx : TyCtxt < ' _ > , def_id : DefId ) -> bool {
68
+ if let Some ( name) = tcx. codegen_fn_attrs ( def_id) . link_name {
69
+ name. as_str ( ) . starts_with ( "llvm." )
70
+ } else {
71
+ false
72
+ }
73
+ }
74
+
75
+ let def_id = instance. def_id ( ) ;
76
+ !def_id. is_local ( )
65
77
&& tcx. is_compiler_builtins ( LOCAL_CRATE )
66
- && tcx . codegen_fn_attrs ( instance . def_id ( ) ) . link_name . is_none ( )
78
+ && ! is_llvm_intrinsic ( tcx , def_id)
67
79
&& !should_codegen_locally ( tcx, instance)
68
80
}
69
81
0 commit comments