Skip to content

Commit 748dba2

Browse files
committed
Only allow upstream calls to LLVM intrinsics, not any link_name function
1 parent 395f780 commit 748dba2

File tree

1 file changed

+14
-2
lines changed
  • compiler/rustc_monomorphize/src

1 file changed

+14
-2
lines changed

compiler/rustc_monomorphize/src/lib.rs

+14-2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use rustc_middle::ty::adjustment::CustomCoerceUnsized;
1414
use rustc_middle::ty::Instance;
1515
use rustc_middle::ty::TyCtxt;
1616
use rustc_middle::ty::{self, Ty};
17+
use rustc_span::def_id::DefId;
1718
use rustc_span::def_id::LOCAL_CRATE;
1819
use rustc_span::ErrorGuaranteed;
1920

@@ -57,13 +58,24 @@ fn custom_coerce_unsize_info<'tcx>(
5758
/// linkers will optimize such that dead calls to unresolved symbols are not an error, but this is
5859
/// not guaranteed. So we used this function in codegen backends to ensure we do not generate any
5960
/// unlinkable calls.
61+
///
62+
/// Note that calls to LLVM intrinsics are uniquely okay because they won't make it to the linker.
6063
pub fn is_call_from_compiler_builtins_to_upstream_monomorphization<'tcx>(
6164
tcx: TyCtxt<'tcx>,
6265
instance: Instance<'tcx>,
6366
) -> 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()
6577
&& 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)
6779
&& !should_codegen_locally(tcx, instance)
6880
}
6981

0 commit comments

Comments
 (0)