summaryrefslogtreecommitdiffstats
path: root/compiler/rustc_monomorphize/src/collector.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-19 09:26:03 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-19 09:26:03 +0000
commit9918693037dce8aa4bb6f08741b6812923486c18 (patch)
tree21d2b40bec7e6a7ea664acee056eb3d08e15a1cf /compiler/rustc_monomorphize/src/collector.rs
parentReleasing progress-linux version 1.75.0+dfsg1-5~progress7.99u1. (diff)
downloadrustc-9918693037dce8aa4bb6f08741b6812923486c18.tar.xz
rustc-9918693037dce8aa4bb6f08741b6812923486c18.zip
Merging upstream version 1.76.0+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'compiler/rustc_monomorphize/src/collector.rs')
-rw-r--r--compiler/rustc_monomorphize/src/collector.rs51
1 files changed, 35 insertions, 16 deletions
diff --git a/compiler/rustc_monomorphize/src/collector.rs b/compiler/rustc_monomorphize/src/collector.rs
index 65bdcf107..a68bfcd06 100644
--- a/compiler/rustc_monomorphize/src/collector.rs
+++ b/compiler/rustc_monomorphize/src/collector.rs
@@ -176,6 +176,7 @@ use rustc_middle::mir::visit::Visitor as MirVisitor;
use rustc_middle::mir::{self, Location};
use rustc_middle::query::TyCtxtAt;
use rustc_middle::ty::adjustment::{CustomCoerceUnsized, PointerCoercion};
+use rustc_middle::ty::layout::ValidityRequirement;
use rustc_middle::ty::print::with_no_trimmed_paths;
use rustc_middle::ty::{
self, AssocKind, GenericParamDefKind, Instance, InstanceDef, Ty, TyCtxt, TypeFoldable,
@@ -370,7 +371,7 @@ fn collect_items_rec<'tcx>(
// current step of mono items collection.
//
// FIXME: don't rely on global state, instead bubble up errors. Note: this is very hard to do.
- let error_count = tcx.sess.diagnostic().err_count();
+ let error_count = tcx.sess.dcx().err_count();
match starting_item.node {
MonoItem::Static(def_id) => {
@@ -385,8 +386,8 @@ fn collect_items_rec<'tcx>(
recursion_depth_reset = None;
if let Ok(alloc) = tcx.eval_static_initializer(def_id) {
- for &id in alloc.inner().provenance().ptrs().values() {
- collect_alloc(tcx, id, &mut used_items);
+ for &prov in alloc.inner().provenance().ptrs().values() {
+ collect_alloc(tcx, prov.alloc_id(), &mut used_items);
}
}
@@ -458,7 +459,7 @@ fn collect_items_rec<'tcx>(
// Check for PMEs and emit a diagnostic if one happened. To try to show relevant edges of the
// mono item graph.
- if tcx.sess.diagnostic().err_count() > error_count
+ if tcx.sess.dcx().err_count() > error_count
&& starting_item.node.is_generic_fn(tcx)
&& starting_item.node.is_user_defined()
{
@@ -740,7 +741,7 @@ impl<'a, 'tcx> MirVisitor<'tcx> for MirUsedCollector<'a, 'tcx> {
) => {
let fn_ty = operand.ty(self.body, self.tcx);
let fn_ty = self.monomorphize(fn_ty);
- visit_fn_use(self.tcx, fn_ty, false, span, &mut self.output);
+ visit_fn_use(self.tcx, fn_ty, false, span, self.output);
}
mir::Rvalue::Cast(
mir::CastKind::PointerCoercion(PointerCoercion::ClosureFnPointer(_)),
@@ -816,7 +817,7 @@ impl<'a, 'tcx> MirVisitor<'tcx> for MirUsedCollector<'a, 'tcx> {
let callee_ty = func.ty(self.body, tcx);
let callee_ty = self.monomorphize(callee_ty);
self.check_fn_args_move_size(callee_ty, args, location);
- visit_fn_use(self.tcx, callee_ty, true, source, &mut self.output)
+ visit_fn_use(self.tcx, callee_ty, true, source, self.output)
}
mir::TerminatorKind::Drop { ref place, .. } => {
let ty = place.ty(self.body, self.tcx).ty;
@@ -828,7 +829,7 @@ impl<'a, 'tcx> MirVisitor<'tcx> for MirUsedCollector<'a, 'tcx> {
match *op {
mir::InlineAsmOperand::SymFn { ref value } => {
let fn_ty = self.monomorphize(value.const_.ty());
- visit_fn_use(self.tcx, fn_ty, false, source, &mut self.output);
+ visit_fn_use(self.tcx, fn_ty, false, source, self.output);
}
mir::InlineAsmOperand::SymStatic { def_id } => {
let instance = Instance::mono(self.tcx, def_id);
@@ -844,6 +845,9 @@ impl<'a, 'tcx> MirVisitor<'tcx> for MirUsedCollector<'a, 'tcx> {
mir::TerminatorKind::Assert { ref msg, .. } => {
let lang_item = match &**msg {
mir::AssertKind::BoundsCheck { .. } => LangItem::PanicBoundsCheck,
+ mir::AssertKind::MisalignedPointerDereference { .. } => {
+ LangItem::PanicMisalignedPointerDereference
+ }
_ => LangItem::Panic,
};
push_mono_lang_item(self, lang_item);
@@ -920,6 +924,21 @@ fn visit_instance_use<'tcx>(
return;
}
+ // 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
+ // codegen a call to that function without generating code for the function itself.
+ if let ty::InstanceDef::Intrinsic(def_id) = instance.def {
+ let name = tcx.item_name(def_id);
+ if let Some(_requirement) = ValidityRequirement::from_intrinsic(name) {
+ let def_id = tcx.lang_items().get(LangItem::PanicNounwind).unwrap();
+ let panic_instance = Instance::mono(tcx, def_id);
+ if should_codegen_locally(tcx, &panic_instance) {
+ output.push(create_fn_mono_item(tcx, panic_instance, source));
+ }
+ }
+ }
+
match instance.def {
ty::InstanceDef::Virtual(..) | ty::InstanceDef::Intrinsic(_) => {
if !is_direct_call {
@@ -1118,7 +1137,7 @@ fn create_mono_items_for_vtable_methods<'tcx>(
) {
assert!(!trait_ty.has_escaping_bound_vars() && !impl_ty.has_escaping_bound_vars());
- if let ty::Dynamic(ref trait_ty, ..) = trait_ty.kind() {
+ if let ty::Dynamic(trait_ty, ..) = trait_ty.kind() {
if let Some(principal) = trait_ty.principal() {
let poly_trait_ref = principal.with_self_ty(tcx, impl_ty);
assert!(!poly_trait_ref.has_escaping_bound_vars());
@@ -1191,7 +1210,7 @@ impl<'v> RootCollector<'_, 'v> {
// but even just declaring them must collect the items they refer to
if let Ok(val) = self.tcx.const_eval_poly(id.owner_id.to_def_id()) {
- collect_const_value(self.tcx, val, &mut self.output);
+ collect_const_value(self.tcx, val, self.output);
}
}
DefKind::Impl { .. } => {
@@ -1363,9 +1382,9 @@ fn collect_alloc<'tcx>(tcx: TyCtxt<'tcx>, alloc_id: AllocId, output: &mut MonoIt
}
GlobalAlloc::Memory(alloc) => {
trace!("collecting {:?} with {:#?}", alloc_id, alloc);
- for &inner in alloc.inner().provenance().ptrs().values() {
+ for &prov in alloc.inner().provenance().ptrs().values() {
rustc_data_structures::stack::ensure_sufficient_stack(|| {
- collect_alloc(tcx, inner, output);
+ collect_alloc(tcx, prov.alloc_id(), output);
});
}
}
@@ -1422,14 +1441,14 @@ fn collect_used_items<'tcx>(
// and abort compilation if any of them errors.
MirUsedCollector {
tcx,
- body: &body,
+ body: body,
output,
instance,
move_size_spans: vec![],
visiting_call_terminator: false,
skip_move_check_fns: None,
}
- .visit_body(&body);
+ .visit_body(body);
}
#[instrument(skip(tcx, output), level = "debug")]
@@ -1440,12 +1459,12 @@ fn collect_const_value<'tcx>(
) {
match value {
mir::ConstValue::Scalar(Scalar::Ptr(ptr, _size)) => {
- collect_alloc(tcx, ptr.provenance, output)
+ collect_alloc(tcx, ptr.provenance.alloc_id(), output)
}
mir::ConstValue::Indirect { alloc_id, .. } => collect_alloc(tcx, alloc_id, output),
mir::ConstValue::Slice { data, meta: _ } => {
- for &id in data.inner().provenance().ptrs().values() {
- collect_alloc(tcx, id, output);
+ for &prov in data.inner().provenance().ptrs().values() {
+ collect_alloc(tcx, prov.alloc_id(), output);
}
}
_ => {}