rustc_intrinsic: support functions without body; they are implicitly marked as must-be-overridden
This commit is contained in:
parent
be65012aa3
commit
3cd3649c6c
19 changed files with 118 additions and 68 deletions
|
@ -232,7 +232,7 @@ use rustc_middle::{bug, span_bug};
|
|||
use rustc_session::Limit;
|
||||
use rustc_session::config::EntryFnType;
|
||||
use rustc_span::source_map::{Spanned, dummy_spanned, respan};
|
||||
use rustc_span::{DUMMY_SP, Span, sym};
|
||||
use rustc_span::{DUMMY_SP, Span};
|
||||
use tracing::{debug, instrument, trace};
|
||||
|
||||
use crate::errors::{self, EncounteredErrorWhileInstantiating, NoOptimizedMir, RecursionLimit};
|
||||
|
@ -894,9 +894,8 @@ fn visit_instance_use<'tcx>(
|
|||
if !tcx.should_codegen_locally(instance) {
|
||||
return;
|
||||
}
|
||||
if let ty::InstanceKind::Intrinsic(def_id) = instance.def {
|
||||
let name = tcx.item_name(def_id);
|
||||
if let Some(_requirement) = ValidityRequirement::from_intrinsic(name) {
|
||||
if let Some(intrinsic) = tcx.intrinsic(instance.def_id()) {
|
||||
if let Some(_requirement) = ValidityRequirement::from_intrinsic(intrinsic.name) {
|
||||
// The intrinsics assert_inhabited, assert_zero_valid, and assert_mem_uninitialized_valid will
|
||||
// be lowered in codegen to nothing or a call to panic_nounwind. So if we encounter any
|
||||
// of those intrinsics, we need to include a mono item for panic_nounwind, else we may try to
|
||||
|
@ -906,11 +905,12 @@ fn visit_instance_use<'tcx>(
|
|||
if tcx.should_codegen_locally(panic_instance) {
|
||||
output.push(create_fn_mono_item(tcx, panic_instance, source));
|
||||
}
|
||||
} else if tcx.has_attr(def_id, sym::rustc_intrinsic)
|
||||
&& !tcx.has_attr(def_id, sym::rustc_intrinsic_must_be_overridden)
|
||||
{
|
||||
// Codegen the fallback body of intrinsics with fallback bodies
|
||||
let instance = ty::Instance::new(def_id, instance.args);
|
||||
} else if !intrinsic.must_be_overridden {
|
||||
// Codegen the fallback body of intrinsics with fallback bodies.
|
||||
// We explicitly skip this otherwise to ensure we get a linker error
|
||||
// if anyone tries to call this intrinsic and the codegen backend did not
|
||||
// override the implementation.
|
||||
let instance = ty::Instance::new(instance.def_id(), instance.args);
|
||||
if tcx.should_codegen_locally(instance) {
|
||||
output.push(create_fn_mono_item(tcx, instance, source));
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue