Skip to content

Commit 3723acf

Browse files
committed
Check signature of intrinsics with fallback bodies
1 parent 487e9af commit 3723acf

File tree

2 files changed

+30
-7
lines changed

2 files changed

+30
-7
lines changed

compiler/rustc_hir_analysis/src/check/check.rs

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,18 @@ pub(crate) fn check_item_type(tcx: TyCtxt<'_>, def_id: LocalDefId) {
472472
DefKind::Enum => {
473473
check_enum(tcx, def_id);
474474
}
475-
DefKind::Fn => {} // entirely within check_item_body
475+
DefKind::Fn => {
476+
if let Some(name) = tcx.intrinsic(def_id) {
477+
intrinsic::check_intrinsic_type(
478+
tcx,
479+
def_id,
480+
tcx.def_ident_span(def_id).unwrap(),
481+
name,
482+
Abi::Rust,
483+
)
484+
}
485+
// Everything else is checked entirely within check_item_body
486+
}
476487
DefKind::Impl { of_trait } => {
477488
if of_trait && let Some(impl_trait_ref) = tcx.impl_trait_ref(def_id) {
478489
check_impl_items_against_trait(tcx, def_id, impl_trait_ref.instantiate_identity());
@@ -533,7 +544,13 @@ pub(crate) fn check_item_type(tcx: TyCtxt<'_>, def_id: LocalDefId) {
533544
match abi {
534545
Abi::RustIntrinsic => {
535546
for item in items {
536-
intrinsic::check_intrinsic_type(tcx, item.id.owner_id.def_id, item.span);
547+
intrinsic::check_intrinsic_type(
548+
tcx,
549+
item.id.owner_id.def_id,
550+
item.span,
551+
item.ident.name,
552+
abi,
553+
);
537554
}
538555
}
539556

compiler/rustc_hir_analysis/src/check/intrinsic.rs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ fn equate_intrinsic_type<'tcx>(
2626
sig: ty::PolyFnSig<'tcx>,
2727
) {
2828
let (own_counts, span) = match tcx.hir_node_by_def_id(def_id) {
29-
hir::Node::ForeignItem(hir::ForeignItem {
29+
hir::Node::Item(hir::Item { kind: hir::ItemKind::Fn(_, generics, _), .. })
30+
| hir::Node::ForeignItem(hir::ForeignItem {
3031
kind: hir::ForeignItemKind::Fn(.., generics),
3132
..
3233
}) => {
@@ -135,9 +136,14 @@ pub fn intrinsic_operation_unsafety(tcx: TyCtxt<'_>, intrinsic_id: LocalDefId) -
135136

136137
/// Remember to add all intrinsics here, in `compiler/rustc_codegen_llvm/src/intrinsic.rs`,
137138
/// and in `library/core/src/intrinsics.rs`.
138-
pub fn check_intrinsic_type(tcx: TyCtxt<'_>, intrinsic_id: LocalDefId, span: Span) {
139+
pub fn check_intrinsic_type(
140+
tcx: TyCtxt<'_>,
141+
intrinsic_id: LocalDefId,
142+
span: Span,
143+
intrinsic_name: Symbol,
144+
abi: Abi,
145+
) {
139146
let param = |n| Ty::new_param(tcx, n, Symbol::intern(&format!("P{n}")));
140-
let intrinsic_name = tcx.item_name(intrinsic_id.into());
141147
let name_str = intrinsic_name.as_str();
142148

143149
let bound_vars = tcx.mk_bound_variable_kinds(&[
@@ -468,7 +474,7 @@ pub fn check_intrinsic_type(tcx: TyCtxt<'_>, intrinsic_id: LocalDefId, span: Spa
468474

469475
sym::black_box => (1, 0, vec![param(0)], param(0)),
470476

471-
sym::is_val_statically_known => (1, 0, vec![param(0)], tcx.types.bool),
477+
sym::is_val_statically_known => (1, 1, vec![param(0)], tcx.types.bool),
472478

473479
sym::const_eval_select => (4, 0, vec![param(0), param(1), param(2)], param(3)),
474480

@@ -483,7 +489,7 @@ pub fn check_intrinsic_type(tcx: TyCtxt<'_>, intrinsic_id: LocalDefId, span: Spa
483489
};
484490
(n_tps, 0, n_cts, inputs, output, unsafety)
485491
};
486-
let sig = tcx.mk_fn_sig(inputs, output, false, unsafety, Abi::RustIntrinsic);
492+
let sig = tcx.mk_fn_sig(inputs, output, false, unsafety, abi);
487493
let sig = ty::Binder::bind_with_vars(sig, bound_vars);
488494
equate_intrinsic_type(tcx, span, intrinsic_id, n_tps, n_lts, n_cts, sig)
489495
}

0 commit comments

Comments
 (0)