1use std::cmp;
2use std::ops::Range;
3
4use rustc_abi::{
5 Align, ArmCall, BackendRepr, CanonAbi, ExternAbi, HasDataLayout, Reg, Size, WrappingRange,
6};
7use rustc_ast as ast;
8use rustc_ast::{InlineAsmOptions, InlineAsmTemplatePiece};
9use rustc_data_structures::packed::Pu128;
10use rustc_hir::attrs::AttributeKind;
11use rustc_hir::lang_items::LangItem;
12use rustc_lint_defs::builtin::TAIL_CALL_TRACK_CALLER;
13use rustc_middle::mir::{self, AssertKind, InlineAsmMacro, SwitchTargets, UnwindTerminateReason};
14use rustc_middle::ty::layout::{HasTyCtxt, LayoutOf, ValidityRequirement};
15use rustc_middle::ty::print::{with_no_trimmed_paths, with_no_visible_paths};
16use rustc_middle::ty::{self, Instance, Ty, TypeVisitableExt};
17use rustc_middle::{bug, span_bug};
18use rustc_session::config::OptLevel;
19use rustc_span::{Span, Spanned};
20use rustc_target::callconv::{ArgAbi, ArgAttributes, CastTarget, FnAbi, PassMode};
21use tracing::{debug, info};
22
23use super::operand::OperandRef;
24use super::operand::OperandValue::{self, Immediate, Pair, Ref, ZeroSized};
25use super::place::{PlaceRef, PlaceValue};
26use super::{CachedLlbb, FunctionCx, LocalRef};
27use crate::base::{self, is_call_from_compiler_builtins_to_upstream_monomorphization};
28use crate::common::{self, IntPredicate};
29use crate::errors::CompilerBuiltinsCannotCall;
30use crate::mir::IntrinsicResult;
31use crate::traits::*;
32use crate::{MemFlags, meth};
33
34#[derive(#[automatically_derived]
impl ::core::fmt::Debug for MergingSucc {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::write_str(f,
match self {
MergingSucc::False => "False",
MergingSucc::True => "True",
})
}
}Debug, #[automatically_derived]
impl ::core::cmp::PartialEq for MergingSucc {
#[inline]
fn eq(&self, other: &MergingSucc) -> bool {
let __self_discr = ::core::intrinsics::discriminant_value(self);
let __arg1_discr = ::core::intrinsics::discriminant_value(other);
__self_discr == __arg1_discr
}
}PartialEq)]
38enum MergingSucc {
39 False,
40 True,
41}
42
43#[derive(#[automatically_derived]
impl ::core::fmt::Debug for CallKind {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::write_str(f,
match self {
CallKind::Normal => "Normal",
CallKind::Tail => "Tail",
})
}
}Debug, #[automatically_derived]
impl ::core::cmp::PartialEq for CallKind {
#[inline]
fn eq(&self, other: &CallKind) -> bool {
let __self_discr = ::core::intrinsics::discriminant_value(self);
let __arg1_discr = ::core::intrinsics::discriminant_value(other);
__self_discr == __arg1_discr
}
}PartialEq)]
46enum CallKind {
47 Normal,
48 Tail,
49}
50
51struct TerminatorCodegenHelper<'tcx> {
54 bb: mir::BasicBlock,
55 terminator: &'tcx mir::Terminator<'tcx>,
56}
57
58impl<'a, 'tcx> TerminatorCodegenHelper<'tcx> {
59 fn funclet<'b, Bx: BuilderMethods<'a, 'tcx>>(
62 &self,
63 fx: &'b mut FunctionCx<'a, 'tcx, Bx>,
64 ) -> Option<&'b Bx::Funclet> {
65 let cleanup_kinds = fx.cleanup_kinds.as_ref()?;
66 let funclet_bb = cleanup_kinds[self.bb].funclet_bb(self.bb)?;
67 if fx.funclets[funclet_bb].is_none() {
76 fx.landing_pad_for(funclet_bb);
77 }
78 Some(
79 fx.funclets[funclet_bb]
80 .as_ref()
81 .expect("landing_pad_for didn't also create funclets entry"),
82 )
83 }
84
85 fn llbb_with_cleanup<Bx: BuilderMethods<'a, 'tcx>>(
88 &self,
89 fx: &mut FunctionCx<'a, 'tcx, Bx>,
90 target: mir::BasicBlock,
91 ) -> Bx::BasicBlock {
92 let (needs_landing_pad, is_cleanupret) = self.llbb_characteristics(fx, target);
93 let mut lltarget = fx.llbb(target);
94 if needs_landing_pad {
95 lltarget = fx.landing_pad_for(target);
96 }
97 if is_cleanupret {
98 if !base::wants_new_eh_instructions(fx.cx.tcx().sess) {
::core::panicking::panic("assertion failed: base::wants_new_eh_instructions(fx.cx.tcx().sess)")
};assert!(base::wants_new_eh_instructions(fx.cx.tcx().sess));
100 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_codegen_ssa/src/mir/block.rs:100",
"rustc_codegen_ssa::mir::block", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_codegen_ssa/src/mir/block.rs"),
::tracing_core::__macro_support::Option::Some(100u32),
::tracing_core::__macro_support::Option::Some("rustc_codegen_ssa::mir::block"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&format_args!("llbb_with_cleanup: creating cleanup trampoline for {0:?}",
target) as &dyn Value))])
});
} else { ; }
};debug!("llbb_with_cleanup: creating cleanup trampoline for {:?}", target);
101 let name = &::alloc::__export::must_use({
::alloc::fmt::format(format_args!("{0:?}_cleanup_trampoline_{1:?}",
self.bb, target))
})format!("{:?}_cleanup_trampoline_{:?}", self.bb, target);
102 let trampoline_llbb = Bx::append_block(fx.cx, fx.llfn, name);
103 let mut trampoline_bx = Bx::build(fx.cx, trampoline_llbb);
104 trampoline_bx.cleanup_ret(self.funclet(fx).unwrap(), Some(lltarget));
105 trampoline_llbb
106 } else {
107 lltarget
108 }
109 }
110
111 fn llbb_characteristics<Bx: BuilderMethods<'a, 'tcx>>(
112 &self,
113 fx: &mut FunctionCx<'a, 'tcx, Bx>,
114 target: mir::BasicBlock,
115 ) -> (bool, bool) {
116 if let Some(ref cleanup_kinds) = fx.cleanup_kinds {
117 let funclet_bb = cleanup_kinds[self.bb].funclet_bb(self.bb);
118 let target_funclet = cleanup_kinds[target].funclet_bb(target);
119 let (needs_landing_pad, is_cleanupret) = match (funclet_bb, target_funclet) {
120 (None, None) => (false, false),
121 (None, Some(_)) => (true, false),
122 (Some(f), Some(t_f)) => (f != t_f, f != t_f),
123 (Some(_), None) => {
124 let span = self.terminator.source_info.span;
125 ::rustc_middle::util::bug::span_bug_fmt(span,
format_args!("{0:?} - jump out of cleanup?", self.terminator));span_bug!(span, "{:?} - jump out of cleanup?", self.terminator);
126 }
127 };
128 (needs_landing_pad, is_cleanupret)
129 } else {
130 let needs_landing_pad = !fx.mir[self.bb].is_cleanup && fx.mir[target].is_cleanup;
131 let is_cleanupret = false;
132 (needs_landing_pad, is_cleanupret)
133 }
134 }
135
136 fn funclet_br<Bx: BuilderMethods<'a, 'tcx>>(
137 &self,
138 fx: &mut FunctionCx<'a, 'tcx, Bx>,
139 bx: &mut Bx,
140 target: mir::BasicBlock,
141 mergeable_succ: bool,
142 attributes: &[AttributeKind],
143 ) -> MergingSucc {
144 let (needs_landing_pad, is_cleanupret) = self.llbb_characteristics(fx, target);
145 if mergeable_succ && !needs_landing_pad && !is_cleanupret {
146 MergingSucc::True
148 } else {
149 let mut lltarget = fx.llbb(target);
150 if needs_landing_pad {
151 lltarget = fx.landing_pad_for(target);
152 }
153 if is_cleanupret {
154 bx.cleanup_ret(self.funclet(fx).unwrap(), Some(lltarget));
157 } else {
158 bx.br_with_attrs(lltarget, attributes);
159 }
160 MergingSucc::False
161 }
162 }
163
164 fn do_call<Bx: BuilderMethods<'a, 'tcx>>(
167 &self,
168 fx: &mut FunctionCx<'a, 'tcx, Bx>,
169 bx: &mut Bx,
170 fn_abi: &'tcx FnAbi<'tcx, Ty<'tcx>>,
171 fn_ptr: Bx::Value,
172 llargs: &[Bx::Value],
173 destination: Option<(ReturnDest<'tcx, Bx::Value>, mir::BasicBlock)>,
174 mut unwind: mir::UnwindAction,
175 lifetime_ends_after_call: &[(Bx::Value, Size)],
176 instance: Option<Instance<'tcx>>,
177 kind: CallKind,
178 mergeable_succ: bool,
179 ) -> MergingSucc {
180 let tcx = bx.tcx();
181 if let Some(instance) = instance
182 && is_call_from_compiler_builtins_to_upstream_monomorphization(tcx, instance)
183 {
184 if destination.is_some() {
185 let caller_def = fx.instance.def_id();
186 let e = CompilerBuiltinsCannotCall {
187 span: tcx.def_span(caller_def),
188 caller: { let _guard = NoTrimmedGuard::new(); tcx.def_path_str(caller_def) }with_no_trimmed_paths!(tcx.def_path_str(caller_def)),
189 callee: { let _guard = NoTrimmedGuard::new(); tcx.def_path_str(instance.def_id()) }with_no_trimmed_paths!(tcx.def_path_str(instance.def_id())),
190 };
191 tcx.dcx().emit_err(e);
192 } else {
193 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_codegen_ssa/src/mir/block.rs:193",
"rustc_codegen_ssa::mir::block", ::tracing::Level::INFO,
::tracing_core::__macro_support::Option::Some("compiler/rustc_codegen_ssa/src/mir/block.rs"),
::tracing_core::__macro_support::Option::Some(193u32),
::tracing_core::__macro_support::Option::Some("rustc_codegen_ssa::mir::block"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::INFO <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::INFO <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&format_args!("compiler_builtins call to diverging function {0:?} replaced with abort",
instance.def_id()) as &dyn Value))])
});
} else { ; }
};info!(
194 "compiler_builtins call to diverging function {:?} replaced with abort",
195 instance.def_id()
196 );
197 bx.abort();
198 bx.unreachable();
199 return MergingSucc::False;
200 }
201 }
202
203 let fn_ty = bx.fn_decl_backend_type(fn_abi);
206
207 let caller_attrs = if bx.tcx().def_kind(fx.instance.def_id()).has_codegen_attrs() {
208 Some(bx.tcx().codegen_instance_attrs(fx.instance.def))
209 } else {
210 None
211 };
212 let caller_attrs = caller_attrs.as_deref();
213
214 if !fn_abi.can_unwind {
215 unwind = mir::UnwindAction::Unreachable;
216 }
217
218 let unwind_block = match unwind {
219 mir::UnwindAction::Cleanup(cleanup) => Some(self.llbb_with_cleanup(fx, cleanup)),
220 mir::UnwindAction::Continue => None,
221 mir::UnwindAction::Unreachable => None,
222 mir::UnwindAction::Terminate(reason) => {
223 if fx.mir[self.bb].is_cleanup && base::wants_wasm_eh(fx.cx.tcx().sess) {
224 Some(fx.terminate_block(reason, Some(self.bb)))
227 } else if fx.mir[self.bb].is_cleanup
228 && base::wants_new_eh_instructions(fx.cx.tcx().sess)
229 {
230 None
233 } else {
234 Some(fx.terminate_block(reason, None))
235 }
236 }
237 };
238
239 if kind == CallKind::Tail {
240 bx.tail_call(fn_ty, caller_attrs, fn_abi, fn_ptr, llargs, self.funclet(fx), instance);
241 return MergingSucc::False;
242 }
243
244 if let Some(unwind_block) = unwind_block {
245 let ret_llbb = if let Some((_, target)) = destination {
246 self.llbb_with_cleanup(fx, target)
247 } else {
248 fx.unreachable_block()
249 };
250 let invokeret = bx.invoke(
251 fn_ty,
252 caller_attrs,
253 Some(fn_abi),
254 fn_ptr,
255 llargs,
256 ret_llbb,
257 unwind_block,
258 self.funclet(fx),
259 instance,
260 );
261 if fx.mir[self.bb].is_cleanup {
262 bx.apply_attrs_to_cleanup_callsite(invokeret);
263 }
264
265 if let Some((ret_dest, target)) = destination {
266 bx.switch_to_block(fx.llbb(target));
267 fx.set_debug_loc(bx, self.terminator.source_info);
268 for &(tmp, size) in lifetime_ends_after_call {
269 bx.lifetime_end(tmp, size);
270 }
271 fx.store_return(bx, ret_dest, &fn_abi.ret, invokeret);
272
273 fx.cached_llbbs[target] = CachedLlbb::Some(bx.llbb());
278 }
279 MergingSucc::False
280 } else {
281 let llret = bx.call(
282 fn_ty,
283 caller_attrs,
284 Some(fn_abi),
285 fn_ptr,
286 llargs,
287 self.funclet(fx),
288 instance,
289 );
290 if fx.mir[self.bb].is_cleanup {
291 bx.apply_attrs_to_cleanup_callsite(llret);
292 }
293
294 if let Some((ret_dest, target)) = destination {
295 for &(tmp, size) in lifetime_ends_after_call {
296 bx.lifetime_end(tmp, size);
297 }
298 fx.store_return(bx, ret_dest, &fn_abi.ret, llret);
299 self.funclet_br(fx, bx, target, mergeable_succ, &[])
300 } else {
301 bx.unreachable();
302 MergingSucc::False
303 }
304 }
305 }
306
307 fn do_inlineasm<Bx: BuilderMethods<'a, 'tcx>>(
309 &self,
310 fx: &mut FunctionCx<'a, 'tcx, Bx>,
311 bx: &mut Bx,
312 template: &[InlineAsmTemplatePiece],
313 operands: &[InlineAsmOperandRef<'tcx, Bx>],
314 options: InlineAsmOptions,
315 line_spans: &[Span],
316 destination: Option<mir::BasicBlock>,
317 unwind: mir::UnwindAction,
318 instance: Instance<'_>,
319 mergeable_succ: bool,
320 ) -> MergingSucc {
321 let unwind_target = match unwind {
322 mir::UnwindAction::Cleanup(cleanup) => Some(self.llbb_with_cleanup(fx, cleanup)),
323 mir::UnwindAction::Terminate(reason) => Some(fx.terminate_block(reason, None)),
324 mir::UnwindAction::Continue => None,
325 mir::UnwindAction::Unreachable => None,
326 };
327
328 if operands.iter().any(|x| #[allow(non_exhaustive_omitted_patterns)] match x {
InlineAsmOperandRef::Label { .. } => true,
_ => false,
}matches!(x, InlineAsmOperandRef::Label { .. })) {
329 if !unwind_target.is_none() {
::core::panicking::panic("assertion failed: unwind_target.is_none()")
};assert!(unwind_target.is_none());
330 let ret_llbb = if let Some(target) = destination {
331 self.llbb_with_cleanup(fx, target)
332 } else {
333 fx.unreachable_block()
334 };
335
336 bx.codegen_inline_asm(
337 template,
338 operands,
339 options,
340 line_spans,
341 instance,
342 Some(ret_llbb),
343 None,
344 );
345 MergingSucc::False
346 } else if let Some(cleanup) = unwind_target {
347 let ret_llbb = if let Some(target) = destination {
348 self.llbb_with_cleanup(fx, target)
349 } else {
350 fx.unreachable_block()
351 };
352
353 bx.codegen_inline_asm(
354 template,
355 operands,
356 options,
357 line_spans,
358 instance,
359 Some(ret_llbb),
360 Some((cleanup, self.funclet(fx))),
361 );
362 MergingSucc::False
363 } else {
364 bx.codegen_inline_asm(template, operands, options, line_spans, instance, None, None);
365
366 if let Some(target) = destination {
367 self.funclet_br(fx, bx, target, mergeable_succ, &[])
368 } else {
369 bx.unreachable();
370 MergingSucc::False
371 }
372 }
373 }
374}
375
376impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
378 fn codegen_resume_terminator(&mut self, helper: TerminatorCodegenHelper<'tcx>, bx: &mut Bx) {
380 if let Some(funclet) = helper.funclet(self) {
381 bx.cleanup_ret(funclet, None);
382 } else {
383 let slot = self.get_personality_slot(bx);
384 let exn0 = slot.project_field(bx, 0);
385 let exn0 = bx.load_operand(exn0).immediate();
386 let exn1 = slot.project_field(bx, 1);
387 let exn1 = bx.load_operand(exn1).immediate();
388 slot.storage_dead(bx);
389
390 bx.resume(exn0, exn1);
391 }
392 }
393
394 fn codegen_switchint_terminator(
395 &mut self,
396 helper: TerminatorCodegenHelper<'tcx>,
397 bx: &mut Bx,
398 discr: &mir::Operand<'tcx>,
399 targets: &SwitchTargets,
400 ) {
401 let discr = self.codegen_operand(bx, discr);
402 let discr_value = discr.immediate();
403 let switch_ty = discr.layout.ty;
404 if let Some(const_discr) = bx.const_to_opt_u128(discr_value, false) {
406 let target = targets.target_for_value(const_discr);
407 bx.br(helper.llbb_with_cleanup(self, target));
408 return;
409 };
410
411 let mut target_iter = targets.iter();
412 if target_iter.len() == 1 {
413 let (test_value, target) = target_iter.next().unwrap();
416 let otherwise = targets.otherwise();
417 let lltarget = helper.llbb_with_cleanup(self, target);
418 let llotherwise = helper.llbb_with_cleanup(self, otherwise);
419 let target_cold = self.cold_blocks[target];
420 let otherwise_cold = self.cold_blocks[otherwise];
421 let expect = if target_cold == otherwise_cold { None } else { Some(otherwise_cold) };
425 if switch_ty == bx.tcx().types.bool {
426 match test_value {
428 0 => {
429 let expect = expect.map(|e| !e);
430 bx.cond_br_with_expect(discr_value, llotherwise, lltarget, expect);
431 }
432 1 => {
433 bx.cond_br_with_expect(discr_value, lltarget, llotherwise, expect);
434 }
435 _ => ::rustc_middle::util::bug::bug_fmt(format_args!("impossible case reached"))bug!(),
436 }
437 } else {
438 let switch_llty = bx.immediate_backend_type(bx.layout_of(switch_ty));
439 let llval = bx.const_uint_big(switch_llty, test_value);
440 let cmp = bx.icmp(IntPredicate::IntEQ, discr_value, llval);
441 bx.cond_br_with_expect(cmp, lltarget, llotherwise, expect);
442 }
443 } else if target_iter.len() == 2
444 && self.mir[targets.otherwise()].is_empty_unreachable()
445 && targets.all_values().contains(&Pu128(0))
446 && targets.all_values().contains(&Pu128(1))
447 {
448 let true_bb = targets.target_for_value(1);
452 let false_bb = targets.target_for_value(0);
453 let true_ll = helper.llbb_with_cleanup(self, true_bb);
454 let false_ll = helper.llbb_with_cleanup(self, false_bb);
455
456 let expected_cond_value = if self.cx.sess().opts.optimize == OptLevel::No {
457 None
458 } else {
459 match (self.cold_blocks[true_bb], self.cold_blocks[false_bb]) {
460 (true, true) | (false, false) => None,
462 (true, false) => Some(false),
464 (false, true) => Some(true),
465 }
466 };
467
468 let bool_ty = bx.tcx().types.bool;
469 let cond = if switch_ty == bool_ty {
470 discr_value
471 } else {
472 let bool_llty = bx.immediate_backend_type(bx.layout_of(bool_ty));
473 bx.unchecked_utrunc(discr_value, bool_llty)
474 };
475 bx.cond_br_with_expect(cond, true_ll, false_ll, expected_cond_value);
476 } else if self.cx.sess().opts.optimize == OptLevel::No
477 && target_iter.len() == 2
478 && self.mir[targets.otherwise()].is_empty_unreachable()
479 {
480 let (test_value1, target1) = target_iter.next().unwrap();
493 let (_test_value2, target2) = target_iter.next().unwrap();
494 let ll1 = helper.llbb_with_cleanup(self, target1);
495 let ll2 = helper.llbb_with_cleanup(self, target2);
496 let switch_llty = bx.immediate_backend_type(bx.layout_of(switch_ty));
497 let llval = bx.const_uint_big(switch_llty, test_value1);
498 let cmp = bx.icmp(IntPredicate::IntEQ, discr_value, llval);
499 bx.cond_br(cmp, ll1, ll2);
500 } else {
501 let otherwise = targets.otherwise();
502 let otherwise_cold = self.cold_blocks[otherwise];
503 let otherwise_unreachable = self.mir[otherwise].is_empty_unreachable();
504 let cold_count = targets.iter().filter(|(_, target)| self.cold_blocks[*target]).count();
505 let none_cold = cold_count == 0;
506 let all_cold = cold_count == targets.iter().len();
507 if (none_cold && (!otherwise_cold || otherwise_unreachable))
508 || (all_cold && (otherwise_cold || otherwise_unreachable))
509 {
510 bx.switch(
513 discr_value,
514 helper.llbb_with_cleanup(self, targets.otherwise()),
515 target_iter
516 .map(|(value, target)| (value, helper.llbb_with_cleanup(self, target))),
517 );
518 } else {
519 bx.switch_with_weights(
521 discr_value,
522 helper.llbb_with_cleanup(self, targets.otherwise()),
523 otherwise_cold,
524 target_iter.map(|(value, target)| {
525 (value, helper.llbb_with_cleanup(self, target), self.cold_blocks[target])
526 }),
527 );
528 }
529 }
530 }
531
532 fn codegen_return_terminator(&mut self, bx: &mut Bx) {
533 if self.fn_abi.c_variadic {
537 let va_list_arg_idx = self.fn_abi.args.len();
539 match self.locals[mir::Local::arg(va_list_arg_idx)] {
540 LocalRef::Place(va_list) => {
541 bx.lifetime_end(va_list.val.llval, va_list.layout.size);
547 }
548 _ => ::rustc_middle::util::bug::bug_fmt(format_args!("C-variadic function must have a `VaList` place"))bug!("C-variadic function must have a `VaList` place"),
549 }
550 }
551 if self.fn_abi.ret.layout.is_uninhabited() {
552 bx.abort();
557 bx.unreachable();
560 return;
561 }
562 let llval = match &self.fn_abi.ret.mode {
563 PassMode::Ignore | PassMode::Indirect { .. } => {
564 bx.ret_void();
565 return;
566 }
567
568 PassMode::Direct(_) | PassMode::Pair(..) => {
569 let op = self.codegen_consume(bx, mir::Place::return_place().as_ref());
570 if let Ref(place_val) = op.val {
571 bx.load_from_place(bx.backend_type(op.layout), place_val)
572 } else {
573 op.immediate_or_packed_pair(bx)
574 }
575 }
576
577 PassMode::Cast { cast: cast_ty, pad_i32: _ } => {
578 let op = match self.locals[mir::RETURN_PLACE] {
579 LocalRef::Operand(op) => op,
580 LocalRef::PendingOperand => ::rustc_middle::util::bug::bug_fmt(format_args!("use of return before def"))bug!("use of return before def"),
581 LocalRef::Place(cg_place) => OperandRef {
582 val: Ref(cg_place.val),
583 layout: cg_place.layout,
584 move_annotation: None,
585 },
586 LocalRef::UnsizedPlace(_) => ::rustc_middle::util::bug::bug_fmt(format_args!("return type must be sized"))bug!("return type must be sized"),
587 };
588 let llslot = match op.val {
589 Immediate(_) | Pair(..) => {
590 let scratch = PlaceRef::alloca(bx, self.fn_abi.ret.layout);
591 op.val.store(bx, scratch);
592 scratch.val.llval
593 }
594 Ref(place_val) => {
595 {
match (&place_val.align, &op.layout.align.abi) {
(left_val, right_val) => {
if !(*left_val == *right_val) {
let kind = ::core::panicking::AssertKind::Eq;
::core::panicking::assert_failed(kind, &*left_val,
&*right_val,
::core::option::Option::Some(format_args!("return place is unaligned!")));
}
}
}
};assert_eq!(
596 place_val.align, op.layout.align.abi,
597 "return place is unaligned!"
598 );
599 place_val.llval
600 }
601 ZeroSized => ::rustc_middle::util::bug::bug_fmt(format_args!("ZST return value shouldn\'t be in PassMode::Cast"))bug!("ZST return value shouldn't be in PassMode::Cast"),
602 };
603
604 if self.fn_abi.conv == CanonAbi::Arm(ArmCall::CCmseNonSecureEntry) {
605 let ret_layout = self.fn_abi.ret.layout;
613 let uninit_ranges = ret_layout.padding_ranges(bx.cx());
614 self.zero_byte_ranges(bx, llslot, ret_layout.size, &uninit_ranges);
615 }
616
617 load_cast(bx, cast_ty, llslot, self.fn_abi.ret.layout.align.abi)
618 }
619 };
620 bx.ret(llval);
621 }
622
623 #[allow(clippy :: suspicious_else_formatting)]
{
let __tracing_attr_span;
let __tracing_attr_guard;
if ::tracing::Level::TRACE <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::TRACE <=
::tracing::level_filters::LevelFilter::current() ||
{ false } {
__tracing_attr_span =
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("codegen_drop_terminator",
"rustc_codegen_ssa::mir::block", ::tracing::Level::TRACE,
::tracing_core::__macro_support::Option::Some("compiler/rustc_codegen_ssa/src/mir/block.rs"),
::tracing_core::__macro_support::Option::Some(623u32),
::tracing_core::__macro_support::Option::Some("rustc_codegen_ssa::mir::block"),
::tracing_core::field::FieldSet::new(&["source_info",
"location", "target", "unwind", "mergeable_succ"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::TRACE <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::TRACE <=
::tracing::level_filters::LevelFilter::current() &&
{ interest = __CALLSITE.interest(); !interest.is_never() }
&&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest) {
let meta = __CALLSITE.metadata();
::tracing::Span::new(meta,
&{
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
let mut iter = meta.fields().iter();
meta.fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&source_info)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&location)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&target)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&unwind)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&mergeable_succ as
&dyn Value))])
})
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[warn(clippy :: suspicious_else_formatting)]
{
#[allow(unknown_lints, unreachable_code, clippy ::
diverging_sub_expression, clippy :: empty_loop, clippy ::
let_unit_value, clippy :: let_with_type_underscore, clippy ::
needless_return, clippy :: unreachable)]
if false {
let __tracing_attr_fake_return: MergingSucc = loop {};
return __tracing_attr_fake_return;
}
{
let ty = location.ty(self.mir, bx.tcx()).ty;
let ty = self.monomorphize(ty);
let drop_fn = Instance::resolve_drop_glue(bx.tcx(), ty);
if let ty::InstanceKind::Shim(ty::ShimKind::DropGlue(_, None)) =
drop_fn.def {
return helper.funclet_br(self, bx, target, mergeable_succ,
&[]);
}
let place = self.codegen_place(bx, location.as_ref());
let (args1, args2);
let mut args =
if let Some(llextra) = place.val.llextra {
args2 = [place.val.llval, llextra];
&args2[..]
} else { args1 = [place.val.llval]; &args1[..] };
let (maybe_null, drop_fn, fn_abi, drop_instance) =
match ty.kind() {
ty::Dynamic(_, _) => {
let virtual_drop =
Instance {
def: ty::InstanceKind::Virtual(drop_fn.def_id(), 0),
args: drop_fn.args,
};
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_codegen_ssa/src/mir/block.rs:672",
"rustc_codegen_ssa::mir::block", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_codegen_ssa/src/mir/block.rs"),
::tracing_core::__macro_support::Option::Some(672u32),
::tracing_core::__macro_support::Option::Some("rustc_codegen_ssa::mir::block"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&format_args!("ty = {0:?}",
ty) as &dyn Value))])
});
} else { ; }
};
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_codegen_ssa/src/mir/block.rs:673",
"rustc_codegen_ssa::mir::block", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_codegen_ssa/src/mir/block.rs"),
::tracing_core::__macro_support::Option::Some(673u32),
::tracing_core::__macro_support::Option::Some("rustc_codegen_ssa::mir::block"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&format_args!("drop_fn = {0:?}",
drop_fn) as &dyn Value))])
});
} else { ; }
};
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_codegen_ssa/src/mir/block.rs:674",
"rustc_codegen_ssa::mir::block", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_codegen_ssa/src/mir/block.rs"),
::tracing_core::__macro_support::Option::Some(674u32),
::tracing_core::__macro_support::Option::Some("rustc_codegen_ssa::mir::block"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&format_args!("args = {0:?}",
args) as &dyn Value))])
});
} else { ; }
};
let fn_abi =
bx.fn_abi_of_instance(virtual_drop, ty::List::empty());
let vtable = args[1];
args = &args[..1];
(true,
meth::VirtualIndex::from_index(ty::COMMON_VTABLE_ENTRIES_DROPINPLACE).get_optional_fn(bx,
vtable, ty, fn_abi), fn_abi, virtual_drop)
}
_ =>
(false, bx.get_fn_addr(drop_fn),
bx.fn_abi_of_instance(drop_fn, ty::List::empty()), drop_fn),
};
if maybe_null {
let is_not_null = bx.append_sibling_block("is_not_null");
let llty = bx.fn_ptr_backend_type(fn_abi);
let null = bx.const_null(llty);
let non_null =
bx.icmp(base::bin_op_to_icmp_predicate(mir::BinOp::Ne,
false), drop_fn, null);
bx.cond_br(non_null, is_not_null,
helper.llbb_with_cleanup(self, target));
bx.switch_to_block(is_not_null);
self.set_debug_loc(bx, *source_info);
}
helper.do_call(self, bx, fn_abi, drop_fn, args,
Some((ReturnDest::Nothing, target)), unwind, &[],
Some(drop_instance), CallKind::Normal,
!maybe_null && mergeable_succ)
}
}
}#[tracing::instrument(level = "trace", skip(self, helper, bx))]
624 fn codegen_drop_terminator(
625 &mut self,
626 helper: TerminatorCodegenHelper<'tcx>,
627 bx: &mut Bx,
628 source_info: &mir::SourceInfo,
629 location: mir::Place<'tcx>,
630 target: mir::BasicBlock,
631 unwind: mir::UnwindAction,
632 mergeable_succ: bool,
633 ) -> MergingSucc {
634 let ty = location.ty(self.mir, bx.tcx()).ty;
635 let ty = self.monomorphize(ty);
636 let drop_fn = Instance::resolve_drop_glue(bx.tcx(), ty);
637
638 if let ty::InstanceKind::Shim(ty::ShimKind::DropGlue(_, None)) = drop_fn.def {
639 return helper.funclet_br(self, bx, target, mergeable_succ, &[]);
641 }
642
643 let place = self.codegen_place(bx, location.as_ref());
644 let (args1, args2);
645 let mut args = if let Some(llextra) = place.val.llextra {
646 args2 = [place.val.llval, llextra];
647 &args2[..]
648 } else {
649 args1 = [place.val.llval];
650 &args1[..]
651 };
652 let (maybe_null, drop_fn, fn_abi, drop_instance) = match ty.kind() {
653 ty::Dynamic(_, _) => {
656 let virtual_drop = Instance {
669 def: ty::InstanceKind::Virtual(drop_fn.def_id(), 0), args: drop_fn.args,
671 };
672 debug!("ty = {:?}", ty);
673 debug!("drop_fn = {:?}", drop_fn);
674 debug!("args = {:?}", args);
675 let fn_abi = bx.fn_abi_of_instance(virtual_drop, ty::List::empty());
676 let vtable = args[1];
677 args = &args[..1];
679 (
680 true,
681 meth::VirtualIndex::from_index(ty::COMMON_VTABLE_ENTRIES_DROPINPLACE)
682 .get_optional_fn(bx, vtable, ty, fn_abi),
683 fn_abi,
684 virtual_drop,
685 )
686 }
687 _ => (
688 false,
689 bx.get_fn_addr(drop_fn),
690 bx.fn_abi_of_instance(drop_fn, ty::List::empty()),
691 drop_fn,
692 ),
693 };
694
695 if maybe_null {
698 let is_not_null = bx.append_sibling_block("is_not_null");
699 let llty = bx.fn_ptr_backend_type(fn_abi);
700 let null = bx.const_null(llty);
701 let non_null =
702 bx.icmp(base::bin_op_to_icmp_predicate(mir::BinOp::Ne, false), drop_fn, null);
703 bx.cond_br(non_null, is_not_null, helper.llbb_with_cleanup(self, target));
704 bx.switch_to_block(is_not_null);
705 self.set_debug_loc(bx, *source_info);
706 }
707
708 helper.do_call(
709 self,
710 bx,
711 fn_abi,
712 drop_fn,
713 args,
714 Some((ReturnDest::Nothing, target)),
715 unwind,
716 &[],
717 Some(drop_instance),
718 CallKind::Normal,
719 !maybe_null && mergeable_succ,
720 )
721 }
722
723 fn codegen_assert_terminator(
724 &mut self,
725 helper: TerminatorCodegenHelper<'tcx>,
726 bx: &mut Bx,
727 terminator: &mir::Terminator<'tcx>,
728 cond: &mir::Operand<'tcx>,
729 expected: bool,
730 msg: &mir::AssertMessage<'tcx>,
731 target: mir::BasicBlock,
732 unwind: mir::UnwindAction,
733 mergeable_succ: bool,
734 ) -> MergingSucc {
735 let span = terminator.source_info.span;
736 let cond = self.codegen_operand(bx, cond).immediate();
737 let mut const_cond = bx.const_to_opt_u128(cond, false).map(|c| c == 1);
738
739 if !bx.sess().overflow_checks() && msg.is_optional_overflow_check() {
744 const_cond = Some(expected);
745 }
746
747 if const_cond == Some(expected) {
749 return helper.funclet_br(self, bx, target, mergeable_succ, &[]);
750 }
751
752 let lltarget = helper.llbb_with_cleanup(self, target);
757 let panic_block = bx.append_sibling_block("panic");
758 if expected {
759 bx.cond_br(cond, lltarget, panic_block);
760 } else {
761 bx.cond_br(cond, panic_block, lltarget);
762 }
763
764 bx.switch_to_block(panic_block);
766 self.set_debug_loc(bx, terminator.source_info);
767
768 let location = self.get_caller_location(bx, terminator.source_info).immediate();
770
771 let (lang_item, args) = match msg {
773 AssertKind::BoundsCheck { len, index } => {
774 let len = self.codegen_operand(bx, len).immediate();
775 let index = self.codegen_operand(bx, index).immediate();
776 (LangItem::PanicBoundsCheck, ::alloc::boxed::box_assume_init_into_vec_unsafe(::alloc::intrinsics::write_box_via_move(::alloc::boxed::Box::new_uninit(),
[index, len, location]))vec![index, len, location])
779 }
780 AssertKind::MisalignedPointerDereference { required, found } => {
781 let required = self.codegen_operand(bx, required).immediate();
782 let found = self.codegen_operand(bx, found).immediate();
783 (LangItem::PanicMisalignedPointerDereference, ::alloc::boxed::box_assume_init_into_vec_unsafe(::alloc::intrinsics::write_box_via_move(::alloc::boxed::Box::new_uninit(),
[required, found, location]))vec![required, found, location])
786 }
787 AssertKind::NullPointerDereference => {
788 (LangItem::PanicNullPointerDereference, ::alloc::boxed::box_assume_init_into_vec_unsafe(::alloc::intrinsics::write_box_via_move(::alloc::boxed::Box::new_uninit(),
[location]))vec![location])
791 }
792 AssertKind::InvalidEnumConstruction(source) => {
793 let source = self.codegen_operand(bx, source).immediate();
794 (LangItem::PanicInvalidEnumConstruction, ::alloc::boxed::box_assume_init_into_vec_unsafe(::alloc::intrinsics::write_box_via_move(::alloc::boxed::Box::new_uninit(),
[source, location]))vec![source, location])
797 }
798 _ => {
799 (msg.panic_function(), ::alloc::boxed::box_assume_init_into_vec_unsafe(::alloc::intrinsics::write_box_via_move(::alloc::boxed::Box::new_uninit(),
[location]))vec![location])
801 }
802 };
803
804 let (fn_abi, llfn, instance) = common::build_langcall(bx, span, lang_item);
805
806 let merging_succ = helper.do_call(
808 self,
809 bx,
810 fn_abi,
811 llfn,
812 &args,
813 None,
814 unwind,
815 &[],
816 Some(instance),
817 CallKind::Normal,
818 false,
819 );
820 {
match (&merging_succ, &MergingSucc::False) {
(left_val, right_val) => {
if !(*left_val == *right_val) {
let kind = ::core::panicking::AssertKind::Eq;
::core::panicking::assert_failed(kind, &*left_val,
&*right_val, ::core::option::Option::None);
}
}
}
};assert_eq!(merging_succ, MergingSucc::False);
821 MergingSucc::False
822 }
823
824 fn codegen_terminate_terminator(
825 &mut self,
826 helper: TerminatorCodegenHelper<'tcx>,
827 bx: &mut Bx,
828 terminator: &mir::Terminator<'tcx>,
829 reason: UnwindTerminateReason,
830 ) {
831 let span = terminator.source_info.span;
832 self.set_debug_loc(bx, terminator.source_info);
833
834 let (fn_abi, llfn, instance) = common::build_langcall(bx, span, reason.lang_item());
836
837 let merging_succ = helper.do_call(
839 self,
840 bx,
841 fn_abi,
842 llfn,
843 &[],
844 None,
845 mir::UnwindAction::Unreachable,
846 &[],
847 Some(instance),
848 CallKind::Normal,
849 false,
850 );
851 {
match (&merging_succ, &MergingSucc::False) {
(left_val, right_val) => {
if !(*left_val == *right_val) {
let kind = ::core::panicking::AssertKind::Eq;
::core::panicking::assert_failed(kind, &*left_val,
&*right_val, ::core::option::Option::None);
}
}
}
};assert_eq!(merging_succ, MergingSucc::False);
852 }
853
854 fn codegen_panic_intrinsic(
856 &mut self,
857 helper: &TerminatorCodegenHelper<'tcx>,
858 bx: &mut Bx,
859 intrinsic: ty::IntrinsicDef,
860 instance: Instance<'tcx>,
861 source_info: mir::SourceInfo,
862 target: Option<mir::BasicBlock>,
863 unwind: mir::UnwindAction,
864 mergeable_succ: bool,
865 ) -> Option<MergingSucc> {
866 let Some(requirement) = ValidityRequirement::from_intrinsic(intrinsic.name) else {
870 return None;
871 };
872
873 let ty = instance.args.type_at(0);
874
875 let is_valid = bx
876 .tcx()
877 .check_validity_requirement((requirement, bx.typing_env().as_query_input(ty)))
878 .expect("expect to have layout during codegen");
879
880 if is_valid {
881 let target = target.unwrap();
883 return Some(helper.funclet_br(self, bx, target, mergeable_succ, &[]));
884 }
885
886 let layout = bx.layout_of(ty);
887
888 let msg_str = {
let _guard = NoVisibleGuard::new();
{
{
let _guard = NoTrimmedGuard::new();
{
if layout.is_uninhabited() {
::alloc::__export::must_use({
::alloc::fmt::format(format_args!("attempted to instantiate uninhabited type `{0}`",
ty))
})
} else if requirement == ValidityRequirement::Zero {
::alloc::__export::must_use({
::alloc::fmt::format(format_args!("attempted to zero-initialize type `{0}`, which is invalid",
ty))
})
} else {
::alloc::__export::must_use({
::alloc::fmt::format(format_args!("attempted to leave type `{0}` uninitialized, which is invalid",
ty))
})
}
}
}
}
}with_no_visible_paths!({
889 with_no_trimmed_paths!({
890 if layout.is_uninhabited() {
891 format!("attempted to instantiate uninhabited type `{ty}`")
893 } else if requirement == ValidityRequirement::Zero {
894 format!("attempted to zero-initialize type `{ty}`, which is invalid")
895 } else {
896 format!("attempted to leave type `{ty}` uninitialized, which is invalid")
897 }
898 })
899 });
900 let msg = bx.const_str(&msg_str);
901
902 let (fn_abi, llfn, instance) =
904 common::build_langcall(bx, source_info.span, LangItem::PanicNounwind);
905
906 Some(helper.do_call(
908 self,
909 bx,
910 fn_abi,
911 llfn,
912 &[msg.0, msg.1],
913 target.as_ref().map(|bb| (ReturnDest::Nothing, *bb)),
914 unwind,
915 &[],
916 Some(instance),
917 CallKind::Normal,
918 mergeable_succ,
919 ))
920 }
921
922 fn codegen_call_terminator(
923 &mut self,
924 helper: TerminatorCodegenHelper<'tcx>,
925 bx: &mut Bx,
926 terminator: &mir::Terminator<'tcx>,
927 func: &mir::Operand<'tcx>,
928 args: &[Spanned<mir::Operand<'tcx>>],
929 destination: mir::Place<'tcx>,
930 target: Option<mir::BasicBlock>,
931 unwind: mir::UnwindAction,
932 fn_span: Span,
933 kind: CallKind,
934 mergeable_succ: bool,
935 ) -> MergingSucc {
936 let source_info = mir::SourceInfo { span: fn_span, ..terminator.source_info };
937
938 let callee = self.codegen_operand(bx, func);
940
941 let (instance, mut llfn) = match *callee.layout.ty.kind() {
942 ty::FnDef(def_id, generic_args) => {
943 let instance = ty::Instance::expect_resolve(
944 bx.tcx(),
945 bx.typing_env(),
946 def_id,
947 generic_args,
948 fn_span,
949 );
950
951 match instance.def {
952 ty::InstanceKind::Shim(ty::ShimKind::DropGlue(_, None)) => {
955 let target = target.unwrap();
957 return helper.funclet_br(self, bx, target, mergeable_succ, &[]);
958 }
959 ty::InstanceKind::Intrinsic(def_id) => {
960 let intrinsic = bx.tcx().intrinsic(def_id).unwrap();
961 if let Some(merging_succ) = self.codegen_panic_intrinsic(
962 &helper,
963 bx,
964 intrinsic,
965 instance,
966 source_info,
967 target,
968 unwind,
969 mergeable_succ,
970 ) {
971 return merging_succ;
972 }
973
974 let result_layout =
975 self.cx.layout_of(self.monomorphized_place_ty(destination.as_ref()));
976
977 let (result_place, store_in_local) =
978 if let Some(local) = destination.as_local() {
979 match self.locals[local] {
980 LocalRef::Place(dest) => (Some(dest.val), None),
981 LocalRef::UnsizedPlace(_) => ::rustc_middle::util::bug::bug_fmt(format_args!("return type must be sized"))bug!("return type must be sized"),
982 LocalRef::PendingOperand => (None, Some(local)),
983 LocalRef::Operand(_) => {
984 if result_layout.is_zst() {
985 let place = PlaceRef::new_sized(
986 bx.const_undef(bx.type_ptr()),
987 result_layout,
988 );
989 (Some(place.val), None)
990 } else {
991 ::rustc_middle::util::bug::bug_fmt(format_args!("place local already assigned to"));bug!("place local already assigned to");
992 }
993 }
994 }
995 } else {
996 (Some(self.codegen_place(bx, destination.as_ref()).val), None)
997 };
998
999 if let Some(place) = result_place
1000 && place.align < result_layout.align.abi
1001 {
1002 ::rustc_middle::util::bug::span_bug_fmt(self.mir.span,
format_args!("can\'t directly store to unaligned value"));span_bug!(self.mir.span, "can't directly store to unaligned value");
1009 }
1010
1011 let args: Vec<_> =
1012 args.iter().map(|arg| self.codegen_operand(bx, &arg.node)).collect();
1013
1014 let intrinsic_result = self.codegen_intrinsic_call(
1015 bx,
1016 instance,
1017 &args,
1018 result_layout,
1019 result_place,
1020 source_info,
1021 );
1022
1023 if let IntrinsicResult::Operand(op_val) = intrinsic_result {
1024 match (result_place, store_in_local) {
1025 (None, Some(local)) => {
1026 let op = OperandRef {
1027 val: op_val,
1028 layout: result_layout,
1029 move_annotation: None,
1030 };
1031 self.overwrite_local(local, LocalRef::Operand(op));
1032 self.debug_introduce_local(bx, local);
1033 }
1034 (Some(place_val), None) => {
1035 let dest = PlaceRef { val: place_val, layout: result_layout };
1036 op_val.store(bx, dest);
1037 }
1038 _ => ::rustc_middle::util::bug::bug_fmt(format_args!("impossible case reached"))bug!(),
1039 }
1040 }
1041
1042 match intrinsic_result {
1043 IntrinsicResult::Operand(_) | IntrinsicResult::WroteIntoPlace => {
1044 return if let Some(target) = target {
1045 helper.funclet_br(self, bx, target, mergeable_succ, &[])
1046 } else {
1047 bx.unreachable();
1048 MergingSucc::False
1049 };
1050 }
1051 IntrinsicResult::Err(_) => {
1052 if let Some(local) = store_in_local {
1056 let op = OperandRef {
1057 val: OperandValue::poison(bx, result_layout),
1058 layout: result_layout,
1059 move_annotation: None,
1060 };
1061 self.overwrite_local(local, LocalRef::Operand(op));
1062 }
1063 bx.abort();
1066 return MergingSucc::False;
1067 }
1068 IntrinsicResult::Fallback(instance) => {
1069 if intrinsic.must_be_overridden {
1070 ::rustc_middle::util::bug::span_bug_fmt(fn_span,
format_args!("intrinsic {0} must be overridden by codegen backend, but isn\'t",
intrinsic.name));span_bug!(
1071 fn_span,
1072 "intrinsic {} must be overridden by codegen backend, but isn't",
1073 intrinsic.name,
1074 );
1075 }
1076 (Some(instance), None)
1077 }
1078 }
1079 }
1080
1081 _ if kind == CallKind::Tail
1082 && instance.def.requires_caller_location(bx.tcx()) =>
1083 {
1084 if let Some(hir_id) =
1085 terminator.source_info.scope.lint_root(&self.mir.source_scopes)
1086 {
1087 bx.tcx().emit_node_lint(TAIL_CALL_TRACK_CALLER, hir_id, rustc_errors::DiagDecorator(|d| {
1088 _ = d.primary_message("tail calling a function marked with `#[track_caller]` has no special effect").span(fn_span)
1089 }));
1090 }
1091
1092 let instance = ty::Instance::resolve_for_fn_ptr(
1093 bx.tcx(),
1094 bx.typing_env(),
1095 def_id,
1096 generic_args,
1097 )
1098 .unwrap();
1099
1100 (None, Some(bx.get_fn_addr(instance)))
1101 }
1102 _ => (Some(instance), None),
1103 }
1104 }
1105 ty::FnPtr(..) => (None, Some(callee.immediate())),
1106 _ => ::rustc_middle::util::bug::bug_fmt(format_args!("{0} is not callable",
callee.layout.ty))bug!("{} is not callable", callee.layout.ty),
1107 };
1108
1109 if let Some(instance) = instance
1110 && let Some(name) = bx.tcx().codegen_fn_attrs(instance.def_id()).symbol_name
1111 && name.as_str().starts_with("llvm.")
1112 && name.as_str() != "llvm.wasm.throw"
1116 {
1117 if !!instance.args.has_infer() {
::core::panicking::panic("assertion failed: !instance.args.has_infer()")
};assert!(!instance.args.has_infer());
1118 if !!instance.args.has_escaping_bound_vars() {
::core::panicking::panic("assertion failed: !instance.args.has_escaping_bound_vars()")
};assert!(!instance.args.has_escaping_bound_vars());
1119
1120 let result_layout =
1121 self.cx.layout_of(self.monomorphized_place_ty(destination.as_ref()));
1122
1123 let return_dest = if result_layout.is_zst() {
1124 ReturnDest::Nothing
1125 } else if let Some(index) = destination.as_local() {
1126 match self.locals[index] {
1127 LocalRef::Place(dest) => ReturnDest::Store(dest),
1128 LocalRef::UnsizedPlace(_) => ::rustc_middle::util::bug::bug_fmt(format_args!("return type must be sized"))bug!("return type must be sized"),
1129 LocalRef::PendingOperand => {
1130 ReturnDest::DirectOperand(index)
1133 }
1134 LocalRef::Operand(_) => ::rustc_middle::util::bug::bug_fmt(format_args!("place local already assigned to"))bug!("place local already assigned to"),
1135 }
1136 } else {
1137 ReturnDest::Store(self.codegen_place(bx, destination.as_ref()))
1138 };
1139
1140 let args =
1141 args.into_iter().map(|arg| self.codegen_operand(bx, &arg.node)).collect::<Vec<_>>();
1142
1143 self.set_debug_loc(bx, source_info);
1144
1145 let llret =
1146 bx.codegen_llvm_intrinsic_call(instance, &args, self.mir[helper.bb].is_cleanup);
1147
1148 if let Some(target) = target {
1149 self.store_return(
1150 bx,
1151 return_dest,
1152 &ArgAbi { layout: result_layout, mode: PassMode::Direct(ArgAttributes::new()) },
1153 llret,
1154 );
1155 return helper.funclet_br(self, bx, target, mergeable_succ, &[]);
1156 } else {
1157 bx.unreachable();
1158 return MergingSucc::False;
1159 }
1160 }
1161
1162 let sig = callee.layout.ty.fn_sig(bx.tcx());
1166
1167 let extra_args = &args[sig.inputs().skip_binder().len()..];
1168 let extra_args = bx.tcx().mk_type_list_from_iter(extra_args.iter().map(|op_arg| {
1169 let op_ty = op_arg.node.ty(self.mir, bx.tcx());
1170 self.monomorphize(op_ty)
1171 }));
1172
1173 let fn_abi = match instance {
1174 Some(instance) => bx.fn_abi_of_instance(instance, extra_args),
1175 None => bx.fn_abi_of_fn_ptr(sig, extra_args),
1176 };
1177
1178 let arg_count = fn_abi.args.len() + fn_abi.ret.is_indirect() as usize;
1180
1181 let mut llargs = Vec::with_capacity(arg_count);
1182
1183 let destination = match kind {
1187 CallKind::Normal => {
1188 let return_dest = self.make_return_dest(bx, destination, &fn_abi.ret, &mut llargs);
1189 target.map(|target| (return_dest, target))
1190 }
1191 CallKind::Tail => {
1192 if fn_abi.ret.is_indirect() {
1193 match self.make_return_dest(bx, destination, &fn_abi.ret, &mut llargs) {
1194 ReturnDest::Nothing => {}
1195 _ => ::rustc_middle::util::bug::bug_fmt(format_args!("tail calls to functions with indirect returns cannot store into a destination"))bug!(
1196 "tail calls to functions with indirect returns cannot store into a destination"
1197 ),
1198 }
1199 }
1200 None
1201 }
1202 };
1203
1204 let (first_args, untuple) = if sig.abi() == ExternAbi::RustCall
1206 && let Some((tup, args)) = args.split_last()
1207 {
1208 (args, Some(tup))
1209 } else {
1210 (args, None)
1211 };
1212
1213 let mut tail_call_temporaries = ::alloc::vec::Vec::new()vec![];
1236 if kind == CallKind::Tail {
1237 tail_call_temporaries = ::alloc::vec::from_elem(None, first_args.len())vec![None; first_args.len()];
1238 for (i, arg) in first_args.iter().enumerate() {
1241 if !#[allow(non_exhaustive_omitted_patterns)] match fn_abi.args[i].mode {
PassMode::Indirect { on_stack: false, .. } => true,
_ => false,
}matches!(fn_abi.args[i].mode, PassMode::Indirect { on_stack: false, .. }) {
1242 continue;
1243 }
1244
1245 let op = self.codegen_operand(bx, &arg.node);
1246 let tmp = PlaceRef::alloca(bx, op.layout);
1247 bx.lifetime_start(tmp.val.llval, tmp.layout.size);
1248 op.store_with_annotation(bx, tmp);
1249
1250 tail_call_temporaries[i] = Some(tmp);
1251 }
1252 }
1253
1254 let mut lifetime_ends_after_call: Vec<(Bx::Value, Size)> = Vec::new();
1258 'make_args: for (i, arg) in first_args.iter().enumerate() {
1259 let mut op = self.codegen_operand(bx, &arg.node);
1260
1261 if let (0, Some(ty::InstanceKind::Virtual(_, idx))) = (i, instance.map(|i| i.def)) {
1262 match op.val {
1263 Pair(data_ptr, meta) => {
1264 while !op.layout.ty.is_raw_ptr() && !op.layout.ty.is_ref() {
1274 let (idx, _) = op.layout.non_1zst_field(bx).expect(
1275 "not exactly one non-1-ZST field in a `DispatchFromDyn` type",
1276 );
1277 op = op.extract_field(self, bx, idx.as_usize());
1278 }
1279
1280 llfn = Some(meth::VirtualIndex::from_index(idx).get_fn(
1284 bx,
1285 meta,
1286 op.layout.ty,
1287 fn_abi,
1288 ));
1289 llargs.push(data_ptr);
1290 continue 'make_args;
1291 }
1292 Ref(PlaceValue { llval: data_ptr, llextra: Some(meta), .. }) => {
1293 llfn = Some(meth::VirtualIndex::from_index(idx).get_fn(
1295 bx,
1296 meta,
1297 op.layout.ty,
1298 fn_abi,
1299 ));
1300 llargs.push(data_ptr);
1301 continue;
1302 }
1303 _ => {
1304 ::rustc_middle::util::bug::span_bug_fmt(fn_span,
format_args!("can\'t codegen a virtual call on {0:#?}", op));span_bug!(fn_span, "can't codegen a virtual call on {:#?}", op);
1305 }
1306 }
1307 }
1308
1309 let by_move = if let PassMode::Indirect { on_stack: false, .. } = fn_abi.args[i].mode
1310 && kind == CallKind::Tail
1311 {
1312 let Some(tmp) = tail_call_temporaries[i].take() else {
1325 ::rustc_middle::util::bug::span_bug_fmt(fn_span,
format_args!("missing temporary for indirect tail call argument #{0}", i))span_bug!(fn_span, "missing temporary for indirect tail call argument #{i}")
1326 };
1327
1328 let local = self.mir.args_iter().nth(i).unwrap();
1329
1330 match &self.locals[local] {
1331 LocalRef::Place(arg) => {
1332 bx.typed_place_copy(arg.val, tmp.val, fn_abi.args[i].layout);
1333 op.val = Ref(arg.val);
1334 }
1335 LocalRef::Operand(arg) => {
1336 let Ref(place_value) = arg.val else {
1337 ::rustc_middle::util::bug::bug_fmt(format_args!("only `Ref` should use `PassMode::Indirect`, but got {0:?}",
arg.val));bug!(
1338 "only `Ref` should use `PassMode::Indirect`, but got {:?}",
1339 arg.val
1340 );
1341 };
1342 bx.typed_place_copy(place_value, tmp.val, fn_abi.args[i].layout);
1343 op.val = arg.val;
1344 }
1345 LocalRef::UnsizedPlace(_) => {
1346 ::rustc_middle::util::bug::span_bug_fmt(fn_span,
format_args!("unsized types are not supported"))span_bug!(fn_span, "unsized types are not supported")
1347 }
1348 LocalRef::PendingOperand => {
1349 ::rustc_middle::util::bug::span_bug_fmt(fn_span,
format_args!("argument local should not be pending"))span_bug!(fn_span, "argument local should not be pending")
1350 }
1351 };
1352
1353 bx.lifetime_end(tmp.val.llval, tmp.layout.size);
1354 true
1355 } else {
1356 #[allow(non_exhaustive_omitted_patterns)] match arg.node {
mir::Operand::Move(_) => true,
_ => false,
}matches!(arg.node, mir::Operand::Move(_))
1357 };
1358
1359 self.codegen_argument(
1360 bx,
1361 fn_abi.conv,
1362 op,
1363 by_move,
1364 &mut llargs,
1365 &fn_abi.args[i],
1366 &mut lifetime_ends_after_call,
1367 );
1368 }
1369 let num_untupled = untuple.map(|tup| {
1370 self.codegen_arguments_untupled(
1371 bx,
1372 fn_abi.conv,
1373 &tup.node,
1374 &mut llargs,
1375 &fn_abi.args[first_args.len()..],
1376 &mut lifetime_ends_after_call,
1377 )
1378 });
1379
1380 let needs_location =
1381 instance.is_some_and(|i| i.def.requires_caller_location(self.cx.tcx()));
1382 if needs_location {
1383 let mir_args = if let Some(num_untupled) = num_untupled {
1384 first_args.len() + num_untupled
1385 } else {
1386 args.len()
1387 };
1388 {
match (&fn_abi.args.len(), &(mir_args + 1)) {
(left_val, right_val) => {
if !(*left_val == *right_val) {
let kind = ::core::panicking::AssertKind::Eq;
::core::panicking::assert_failed(kind, &*left_val,
&*right_val,
::core::option::Option::Some(format_args!("#[track_caller] fn\'s must have 1 more argument in their ABI than in their MIR: {0:?} {1:?} {2:?}",
instance, fn_span, fn_abi)));
}
}
}
};assert_eq!(
1389 fn_abi.args.len(),
1390 mir_args + 1,
1391 "#[track_caller] fn's must have 1 more argument in their ABI than in their MIR: {instance:?} {fn_span:?} {fn_abi:?}",
1392 );
1393 let location = self.get_caller_location(bx, source_info);
1394 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_codegen_ssa/src/mir/block.rs:1394",
"rustc_codegen_ssa::mir::block", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_codegen_ssa/src/mir/block.rs"),
::tracing_core::__macro_support::Option::Some(1394u32),
::tracing_core::__macro_support::Option::Some("rustc_codegen_ssa::mir::block"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&format_args!("codegen_call_terminator({0:?}): location={1:?} (fn_span {2:?})",
terminator, location, fn_span) as &dyn Value))])
});
} else { ; }
};debug!(
1395 "codegen_call_terminator({:?}): location={:?} (fn_span {:?})",
1396 terminator, location, fn_span
1397 );
1398
1399 let last_arg = fn_abi.args.last().unwrap();
1400 self.codegen_argument(
1401 bx,
1402 fn_abi.conv,
1403 location,
1404 false,
1405 &mut llargs,
1406 last_arg,
1407 &mut lifetime_ends_after_call,
1408 );
1409 }
1410
1411 let fn_ptr = match (instance, llfn) {
1412 (Some(instance), None) => bx.get_fn_addr(instance),
1413 (_, Some(llfn)) => llfn,
1414 _ => ::rustc_middle::util::bug::span_bug_fmt(fn_span,
format_args!("no instance or llfn for call"))span_bug!(fn_span, "no instance or llfn for call"),
1415 };
1416 self.set_debug_loc(bx, source_info);
1417 helper.do_call(
1418 self,
1419 bx,
1420 fn_abi,
1421 fn_ptr,
1422 &llargs,
1423 destination,
1424 unwind,
1425 &lifetime_ends_after_call,
1426 instance,
1427 kind,
1428 mergeable_succ,
1429 )
1430 }
1431
1432 fn codegen_asm_terminator(
1433 &mut self,
1434 helper: TerminatorCodegenHelper<'tcx>,
1435 bx: &mut Bx,
1436 asm_macro: InlineAsmMacro,
1437 terminator: &mir::Terminator<'tcx>,
1438 template: &[ast::InlineAsmTemplatePiece],
1439 operands: &[mir::InlineAsmOperand<'tcx>],
1440 options: ast::InlineAsmOptions,
1441 line_spans: &[Span],
1442 targets: &[mir::BasicBlock],
1443 unwind: mir::UnwindAction,
1444 instance: Instance<'_>,
1445 mergeable_succ: bool,
1446 ) -> MergingSucc {
1447 let span = terminator.source_info.span;
1448
1449 let operands: Vec<_> = operands
1450 .iter()
1451 .map(|op| match *op {
1452 mir::InlineAsmOperand::In { reg, ref value } => {
1453 let value = self.codegen_operand(bx, value);
1454 InlineAsmOperandRef::In { reg, value }
1455 }
1456 mir::InlineAsmOperand::Out { reg, late, ref place } => {
1457 let place = place.map(|place| self.codegen_place(bx, place.as_ref()));
1458 InlineAsmOperandRef::Out { reg, late, place }
1459 }
1460 mir::InlineAsmOperand::InOut { reg, late, ref in_value, ref out_place } => {
1461 let in_value = self.codegen_operand(bx, in_value);
1462 let out_place =
1463 out_place.map(|out_place| self.codegen_place(bx, out_place.as_ref()));
1464 InlineAsmOperandRef::InOut { reg, late, in_value, out_place }
1465 }
1466 mir::InlineAsmOperand::Const { ref value } => {
1467 let const_value = self.eval_mir_constant(value);
1468 let string = common::asm_const_to_str(
1469 bx.tcx(),
1470 span,
1471 const_value,
1472 bx.layout_of(value.ty()),
1473 );
1474 InlineAsmOperandRef::Const { string }
1475 }
1476 mir::InlineAsmOperand::SymFn { ref value } => {
1477 let const_ = self.monomorphize(value.const_);
1478 if let ty::FnDef(def_id, args) = *const_.ty().kind() {
1479 let instance = ty::Instance::resolve_for_fn_ptr(
1480 bx.tcx(),
1481 bx.typing_env(),
1482 def_id,
1483 args,
1484 )
1485 .unwrap();
1486 InlineAsmOperandRef::SymFn { instance }
1487 } else {
1488 ::rustc_middle::util::bug::span_bug_fmt(span,
format_args!("invalid type for asm sym (fn)"));span_bug!(span, "invalid type for asm sym (fn)");
1489 }
1490 }
1491 mir::InlineAsmOperand::SymStatic { def_id } => {
1492 InlineAsmOperandRef::SymStatic { def_id }
1493 }
1494 mir::InlineAsmOperand::Label { target_index } => {
1495 InlineAsmOperandRef::Label { label: self.llbb(targets[target_index]) }
1496 }
1497 })
1498 .collect();
1499
1500 helper.do_inlineasm(
1501 self,
1502 bx,
1503 template,
1504 &operands,
1505 options,
1506 line_spans,
1507 if asm_macro.diverges(options) { None } else { targets.get(0).copied() },
1508 unwind,
1509 instance,
1510 mergeable_succ,
1511 )
1512 }
1513
1514 pub(crate) fn codegen_block(&mut self, mut bb: mir::BasicBlock) {
1515 let llbb = match self.try_llbb(bb) {
1516 Some(llbb) => llbb,
1517 None => return,
1518 };
1519 let bx = &mut Bx::build(self.cx, llbb);
1520 let mir = self.mir;
1521
1522 loop {
1526 let data = &mir[bb];
1527
1528 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_codegen_ssa/src/mir/block.rs:1528",
"rustc_codegen_ssa::mir::block", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_codegen_ssa/src/mir/block.rs"),
::tracing_core::__macro_support::Option::Some(1528u32),
::tracing_core::__macro_support::Option::Some("rustc_codegen_ssa::mir::block"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&format_args!("codegen_block({0:?}={1:?})",
bb, data) as &dyn Value))])
});
} else { ; }
};debug!("codegen_block({:?}={:?})", bb, data);
1529
1530 for statement in &data.statements {
1531 self.codegen_statement(bx, statement);
1532 }
1533 self.codegen_stmt_debuginfos(bx, &data.after_last_stmt_debuginfos);
1534
1535 let merging_succ = self.codegen_terminator(bx, bb, data.terminator());
1536 if let MergingSucc::False = merging_succ {
1537 break;
1538 }
1539
1540 let mut successors = data.terminator().successors();
1548 let succ = successors.next().unwrap();
1549 if !#[allow(non_exhaustive_omitted_patterns)] match self.cached_llbbs[succ] {
CachedLlbb::None => true,
_ => false,
} {
::core::panicking::panic("assertion failed: matches!(self.cached_llbbs[succ], CachedLlbb::None)")
};assert!(matches!(self.cached_llbbs[succ], CachedLlbb::None));
1550 self.cached_llbbs[succ] = CachedLlbb::Skip;
1551 bb = succ;
1552 }
1553 }
1554
1555 pub(crate) fn codegen_block_as_unreachable(&mut self, bb: mir::BasicBlock) {
1556 let llbb = match self.try_llbb(bb) {
1557 Some(llbb) => llbb,
1558 None => return,
1559 };
1560 let bx = &mut Bx::build(self.cx, llbb);
1561 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_codegen_ssa/src/mir/block.rs:1561",
"rustc_codegen_ssa::mir::block", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_codegen_ssa/src/mir/block.rs"),
::tracing_core::__macro_support::Option::Some(1561u32),
::tracing_core::__macro_support::Option::Some("rustc_codegen_ssa::mir::block"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&format_args!("codegen_block_as_unreachable({0:?})",
bb) as &dyn Value))])
});
} else { ; }
};debug!("codegen_block_as_unreachable({:?})", bb);
1562 bx.unreachable();
1563 }
1564
1565 fn codegen_terminator(
1566 &mut self,
1567 bx: &mut Bx,
1568 bb: mir::BasicBlock,
1569 terminator: &'tcx mir::Terminator<'tcx>,
1570 ) -> MergingSucc {
1571 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_codegen_ssa/src/mir/block.rs:1571",
"rustc_codegen_ssa::mir::block", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_codegen_ssa/src/mir/block.rs"),
::tracing_core::__macro_support::Option::Some(1571u32),
::tracing_core::__macro_support::Option::Some("rustc_codegen_ssa::mir::block"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&format_args!("codegen_terminator: {0:?}",
terminator) as &dyn Value))])
});
} else { ; }
};debug!("codegen_terminator: {:?}", terminator);
1572
1573 let helper = TerminatorCodegenHelper { bb, terminator };
1574
1575 let mergeable_succ = || {
1576 let mut successors = terminator.successors();
1579 if let Some(succ) = successors.next()
1580 && successors.next().is_none()
1581 && let &[succ_pred] = self.mir.basic_blocks.predecessors()[succ].as_slice()
1582 {
1583 {
match (&succ_pred, &bb) {
(left_val, right_val) => {
if !(*left_val == *right_val) {
let kind = ::core::panicking::AssertKind::Eq;
::core::panicking::assert_failed(kind, &*left_val,
&*right_val, ::core::option::Option::None);
}
}
}
};assert_eq!(succ_pred, bb);
1586 true
1587 } else {
1588 false
1589 }
1590 };
1591
1592 self.set_debug_loc(bx, terminator.source_info);
1593 match terminator.kind {
1594 mir::TerminatorKind::UnwindResume => {
1595 self.codegen_resume_terminator(helper, bx);
1596 MergingSucc::False
1597 }
1598
1599 mir::TerminatorKind::UnwindTerminate(reason) => {
1600 self.codegen_terminate_terminator(helper, bx, terminator, reason);
1601 MergingSucc::False
1602 }
1603
1604 mir::TerminatorKind::Goto { target } => {
1605 helper.funclet_br(self, bx, target, mergeable_succ(), &terminator.attributes)
1606 }
1607
1608 mir::TerminatorKind::SwitchInt { ref discr, ref targets } => {
1609 self.codegen_switchint_terminator(helper, bx, discr, targets);
1610 MergingSucc::False
1611 }
1612
1613 mir::TerminatorKind::Return => {
1614 self.codegen_return_terminator(bx);
1615 MergingSucc::False
1616 }
1617
1618 mir::TerminatorKind::Unreachable => {
1619 bx.unreachable();
1620 MergingSucc::False
1621 }
1622
1623 mir::TerminatorKind::Drop { place, target, unwind, replace: _, drop } => {
1624 if !drop.is_none() {
{
::core::panicking::panic_fmt(format_args!("Async Drop must be expanded or reset to sync before codegen"));
}
};assert!(
1625 drop.is_none(),
1626 "Async Drop must be expanded or reset to sync before codegen"
1627 );
1628 self.codegen_drop_terminator(
1629 helper,
1630 bx,
1631 &terminator.source_info,
1632 place,
1633 target,
1634 unwind,
1635 mergeable_succ(),
1636 )
1637 }
1638
1639 mir::TerminatorKind::Assert { ref cond, expected, ref msg, target, unwind } => self
1640 .codegen_assert_terminator(
1641 helper,
1642 bx,
1643 terminator,
1644 cond,
1645 expected,
1646 msg,
1647 target,
1648 unwind,
1649 mergeable_succ(),
1650 ),
1651
1652 mir::TerminatorKind::Call {
1653 ref func,
1654 ref args,
1655 destination,
1656 target,
1657 unwind,
1658 call_source: _,
1659 fn_span,
1660 } => self.codegen_call_terminator(
1661 helper,
1662 bx,
1663 terminator,
1664 func,
1665 args,
1666 destination,
1667 target,
1668 unwind,
1669 fn_span,
1670 CallKind::Normal,
1671 mergeable_succ(),
1672 ),
1673 mir::TerminatorKind::TailCall { ref func, ref args, fn_span } => self
1674 .codegen_call_terminator(
1675 helper,
1676 bx,
1677 terminator,
1678 func,
1679 args,
1680 mir::Place::from(mir::RETURN_PLACE),
1681 None,
1682 mir::UnwindAction::Unreachable,
1683 fn_span,
1684 CallKind::Tail,
1685 mergeable_succ(),
1686 ),
1687 mir::TerminatorKind::CoroutineDrop | mir::TerminatorKind::Yield { .. } => {
1688 ::rustc_middle::util::bug::bug_fmt(format_args!("coroutine ops in codegen"))bug!("coroutine ops in codegen")
1689 }
1690 mir::TerminatorKind::FalseEdge { .. } | mir::TerminatorKind::FalseUnwind { .. } => {
1691 ::rustc_middle::util::bug::bug_fmt(format_args!("borrowck false edges in codegen"))bug!("borrowck false edges in codegen")
1692 }
1693
1694 mir::TerminatorKind::InlineAsm {
1695 asm_macro,
1696 template,
1697 ref operands,
1698 options,
1699 line_spans,
1700 ref targets,
1701 unwind,
1702 } => self.codegen_asm_terminator(
1703 helper,
1704 bx,
1705 asm_macro,
1706 terminator,
1707 template,
1708 operands,
1709 options,
1710 line_spans,
1711 targets,
1712 unwind,
1713 self.instance,
1714 mergeable_succ(),
1715 ),
1716 }
1717 }
1718
1719 fn zero_byte_ranges(
1720 &mut self,
1721 bx: &mut Bx,
1722 ptr: Bx::Value,
1723 limit: Size,
1724 ranges: &[Range<Size>],
1725 ) {
1726 let zero = bx.const_u8(0);
1727
1728 for range in ranges {
1729 let end = cmp::min(range.end, limit);
1730 if range.start >= end {
1731 continue;
1732 }
1733 let offset = bx.const_usize(range.start.bytes());
1734 let len = bx.const_usize((end - range.start).bytes());
1735 let ptr = bx.inbounds_ptradd(ptr, offset);
1736 bx.memset(ptr, zero, len, Align::ONE, MemFlags::empty());
1737 }
1738 }
1739
1740 fn codegen_argument(
1741 &mut self,
1742 bx: &mut Bx,
1743 conv: CanonAbi,
1744 op: OperandRef<'tcx, Bx::Value>,
1745 by_move: bool,
1746 llargs: &mut Vec<Bx::Value>,
1747 arg: &ArgAbi<'tcx, Ty<'tcx>>,
1748 lifetime_ends_after_call: &mut Vec<(Bx::Value, Size)>,
1749 ) {
1750 match arg.mode {
1751 PassMode::Ignore => return,
1752 PassMode::Cast { pad_i32: true, .. } => {
1753 llargs.push(bx.const_undef(bx.reg_backend_type(&Reg::i32())));
1755 }
1756 PassMode::Pair(..) => match op.val {
1757 Pair(a, b) => {
1758 llargs.push(a);
1759 llargs.push(b);
1760 return;
1761 }
1762 _ => ::rustc_middle::util::bug::bug_fmt(format_args!("codegen_argument: {0:?} invalid for pair argument",
op))bug!("codegen_argument: {:?} invalid for pair argument", op),
1763 },
1764 PassMode::Indirect { attrs: _, meta_attrs: Some(_), on_stack: _ } => match op.val {
1765 Ref(PlaceValue { llval: a, llextra: Some(b), .. }) => {
1766 llargs.push(a);
1767 llargs.push(b);
1768 return;
1769 }
1770 _ => ::rustc_middle::util::bug::bug_fmt(format_args!("codegen_argument: {0:?} invalid for unsized indirect argument",
op))bug!("codegen_argument: {:?} invalid for unsized indirect argument", op),
1771 },
1772 _ => {}
1773 }
1774
1775 let (mut llval, align, by_ref) = match op.val {
1777 Immediate(_) | Pair(..) => match arg.mode {
1778 PassMode::Indirect { attrs, .. } => {
1779 let required_align = match attrs.pointee_align {
1783 Some(pointee_align) => cmp::max(pointee_align, arg.layout.align.abi),
1784 None => arg.layout.align.abi,
1785 };
1786 let scratch = PlaceValue::alloca(bx, arg.layout.size, required_align);
1787 bx.lifetime_start(scratch.llval, arg.layout.size);
1788 op.store_with_annotation(bx, scratch.with_type(arg.layout));
1789 lifetime_ends_after_call.push((scratch.llval, arg.layout.size));
1790 (scratch.llval, scratch.align, true)
1791 }
1792 PassMode::Cast { .. } => {
1793 let scratch = PlaceRef::alloca(bx, arg.layout);
1794 op.store_with_annotation(bx, scratch);
1795 (scratch.val.llval, scratch.val.align, true)
1796 }
1797 PassMode::Direct(_) => (op.immediate(), arg.layout.align.abi, false),
1798 PassMode::Ignore | PassMode::Pair(..) => {
::core::panicking::panic_fmt(format_args!("internal error: entered unreachable code: {0}",
format_args!("handled above")));
}unreachable!("handled above"),
1799 },
1800 Ref(op_place_val) => match arg.mode {
1801 PassMode::Indirect { attrs, on_stack, .. } => {
1802 let required_align = match attrs.pointee_align {
1806 Some(pointee_align) => cmp::max(pointee_align, arg.layout.align.abi),
1807 None => arg.layout.align.abi,
1808 };
1809 if op_place_val.align < required_align || (!on_stack && !by_move) {
1811 let scratch = PlaceValue::alloca(bx, arg.layout.size, required_align);
1812 bx.lifetime_start(scratch.llval, arg.layout.size);
1813 op.store_with_annotation(bx, scratch.with_type(arg.layout));
1814 lifetime_ends_after_call.push((scratch.llval, arg.layout.size));
1815 (scratch.llval, scratch.align, true)
1816 } else {
1817 (op_place_val.llval, op_place_val.align, true)
1818 }
1819 }
1820 _ => (op_place_val.llval, op_place_val.align, true),
1821 },
1822 ZeroSized => match arg.mode {
1823 PassMode::Indirect { on_stack, .. } => {
1824 if on_stack {
1825 ::rustc_middle::util::bug::bug_fmt(format_args!("ZST {0:?} passed on stack with abi {1:?}",
op, arg));bug!("ZST {op:?} passed on stack with abi {arg:?}");
1828 }
1829 let scratch = PlaceRef::alloca(bx, arg.layout);
1833 (scratch.val.llval, scratch.val.align, true)
1834 }
1835 _ => ::rustc_middle::util::bug::bug_fmt(format_args!("ZST {0:?} wasn\'t ignored, but was passed with abi {1:?}",
op, arg))bug!("ZST {op:?} wasn't ignored, but was passed with abi {arg:?}"),
1836 },
1837 };
1838
1839 if by_ref && !arg.is_indirect() {
1840 if let PassMode::Cast { cast, pad_i32: _ } = &arg.mode {
1842 let scratch_size = cast.size(bx);
1846 let scratch_align = cast.align(bx);
1847 let copy_bytes = cmp::min(cast.unaligned_size(bx).bytes(), arg.layout.size.bytes());
1854 let llscratch = bx.alloca(scratch_size, scratch_align);
1856 bx.lifetime_start(llscratch, scratch_size);
1857 bx.memcpy(
1859 llscratch,
1860 scratch_align,
1861 llval,
1862 align,
1863 bx.const_usize(copy_bytes),
1864 MemFlags::empty(),
1865 None,
1866 );
1867
1868 if conv == CanonAbi::Arm(ArmCall::CCmseNonSecureCall) {
1876 self.zero_byte_ranges(
1877 bx,
1878 llscratch,
1879 Size::from_bytes(copy_bytes),
1880 &arg.layout.padding_ranges(bx.cx()),
1881 );
1882 }
1883
1884 llval = load_cast(bx, cast, llscratch, scratch_align);
1886 bx.lifetime_end(llscratch, scratch_size);
1887 } else {
1888 llval = bx.load(bx.backend_type(arg.layout), llval, align);
1894 if let BackendRepr::Scalar(scalar) = arg.layout.backend_repr {
1895 if scalar.is_bool() {
1896 bx.range_metadata(llval, WrappingRange { start: 0, end: 1 });
1897 }
1898 llval = bx.to_immediate_scalar(llval, scalar);
1900 }
1901 }
1902 }
1903
1904 llargs.push(llval);
1905 }
1906
1907 fn codegen_arguments_untupled(
1908 &mut self,
1909 bx: &mut Bx,
1910 conv: CanonAbi,
1911 operand: &mir::Operand<'tcx>,
1912 llargs: &mut Vec<Bx::Value>,
1913 args: &[ArgAbi<'tcx, Ty<'tcx>>],
1914 lifetime_ends_after_call: &mut Vec<(Bx::Value, Size)>,
1915 ) -> usize {
1916 let tuple = self.codegen_operand(bx, operand);
1917 let by_move = #[allow(non_exhaustive_omitted_patterns)] match operand {
mir::Operand::Move(_) => true,
_ => false,
}matches!(operand, mir::Operand::Move(_));
1918
1919 if let Ref(place_val) = tuple.val {
1921 if place_val.llextra.is_some() {
1922 ::rustc_middle::util::bug::bug_fmt(format_args!("closure arguments must be sized"));bug!("closure arguments must be sized");
1923 }
1924 let tuple_ptr = place_val.with_type(tuple.layout);
1925 for i in 0..tuple.layout.fields.count() {
1926 let field_ptr = tuple_ptr.project_field(bx, i);
1927 let field = bx.load_operand(field_ptr);
1928 self.codegen_argument(
1929 bx,
1930 conv,
1931 field,
1932 by_move,
1933 llargs,
1934 &args[i],
1935 lifetime_ends_after_call,
1936 );
1937 }
1938 } else {
1939 for i in 0..tuple.layout.fields.count() {
1941 let op = tuple.extract_field(self, bx, i);
1942 self.codegen_argument(
1943 bx,
1944 conv,
1945 op,
1946 by_move,
1947 llargs,
1948 &args[i],
1949 lifetime_ends_after_call,
1950 );
1951 }
1952 }
1953 tuple.layout.fields.count()
1954 }
1955
1956 pub(super) fn get_caller_location(
1957 &mut self,
1958 bx: &mut Bx,
1959 source_info: mir::SourceInfo,
1960 ) -> OperandRef<'tcx, Bx::Value> {
1961 self.mir.caller_location_span(source_info, self.caller_location, bx.tcx(), |span: Span| {
1962 let const_loc = bx.tcx().span_as_caller_location(span);
1963 OperandRef::from_const(bx, const_loc, bx.tcx().caller_location_ty())
1964 })
1965 }
1966
1967 fn get_personality_slot(&mut self, bx: &mut Bx) -> PlaceRef<'tcx, Bx::Value> {
1968 let cx = bx.cx();
1969 if let Some(slot) = self.personality_slot {
1970 slot
1971 } else {
1972 let layout = cx.layout_of(Ty::new_tup(
1973 cx.tcx(),
1974 &[Ty::new_mut_ptr(cx.tcx(), cx.tcx().types.u8), cx.tcx().types.i32],
1975 ));
1976 let slot = PlaceRef::alloca(bx, layout);
1977 self.personality_slot = Some(slot);
1978 slot
1979 }
1980 }
1981
1982 fn landing_pad_for(&mut self, bb: mir::BasicBlock) -> Bx::BasicBlock {
1985 if let Some(landing_pad) = self.landing_pads[bb] {
1986 return landing_pad;
1987 }
1988
1989 let landing_pad = self.landing_pad_for_uncached(bb);
1990 self.landing_pads[bb] = Some(landing_pad);
1991 landing_pad
1992 }
1993
1994 fn landing_pad_for_uncached(&mut self, bb: mir::BasicBlock) -> Bx::BasicBlock {
1996 let llbb = self.llbb(bb);
1997 if base::wants_new_eh_instructions(self.cx.sess()) {
1998 let cleanup_bb = Bx::append_block(self.cx, self.llfn, &::alloc::__export::must_use({
::alloc::fmt::format(format_args!("funclet_{0:?}", bb))
})format!("funclet_{bb:?}"));
1999 let mut cleanup_bx = Bx::build(self.cx, cleanup_bb);
2000 let funclet = cleanup_bx.cleanup_pad(None, &[]);
2001 cleanup_bx.br(llbb);
2002 self.funclets[bb] = Some(funclet);
2003 cleanup_bb
2004 } else {
2005 let cleanup_llbb = Bx::append_block(self.cx, self.llfn, "cleanup");
2006 let mut cleanup_bx = Bx::build(self.cx, cleanup_llbb);
2007
2008 let llpersonality = self.cx.eh_personality();
2009 let (exn0, exn1) = cleanup_bx.cleanup_landing_pad(llpersonality);
2010
2011 let slot = self.get_personality_slot(&mut cleanup_bx);
2012 slot.storage_live(&mut cleanup_bx);
2013 Pair(exn0, exn1).store(&mut cleanup_bx, slot);
2014
2015 cleanup_bx.br(llbb);
2016 cleanup_llbb
2017 }
2018 }
2019
2020 fn unreachable_block(&mut self) -> Bx::BasicBlock {
2021 self.unreachable_block.unwrap_or_else(|| {
2022 let llbb = Bx::append_block(self.cx, self.llfn, "unreachable");
2023 let mut bx = Bx::build(self.cx, llbb);
2024 bx.unreachable();
2025 self.unreachable_block = Some(llbb);
2026 llbb
2027 })
2028 }
2029
2030 fn terminate_block(
2031 &mut self,
2032 reason: UnwindTerminateReason,
2033 outer_catchpad_bb: Option<mir::BasicBlock>,
2034 ) -> Bx::BasicBlock {
2035 if true {
if !(outer_catchpad_bb.is_some() ==
(base::wants_wasm_eh(self.cx.tcx().sess) &&
reason == UnwindTerminateReason::InCleanup)) {
::core::panicking::panic("assertion failed: outer_catchpad_bb.is_some() ==\n (base::wants_wasm_eh(self.cx.tcx().sess) &&\n reason == UnwindTerminateReason::InCleanup)")
};
};debug_assert!(
2040 outer_catchpad_bb.is_some()
2041 == (base::wants_wasm_eh(self.cx.tcx().sess)
2042 && reason == UnwindTerminateReason::InCleanup)
2043 );
2044
2045 let mut cache_bb = mir::START_BLOCK;
2048 if let Some(outer_bb) = outer_catchpad_bb {
2051 let cleanup_kinds =
2052 self.cleanup_kinds.as_ref().expect("cleanup_kinds required for funclets");
2053 cache_bb = cleanup_kinds[outer_bb]
2054 .funclet_bb(outer_bb)
2055 .expect("funclet_bb should be in a funclet");
2056
2057 if self.funclets[cache_bb].is_none() {
2059 self.landing_pad_for(cache_bb);
2060 }
2061 }
2062 if let Some((cached_bb, cached_reason)) = self.terminate_blocks[cache_bb]
2063 && reason == cached_reason
2064 {
2065 return cached_bb;
2066 }
2067
2068 let funclet;
2069 let llbb;
2070 let mut bx;
2071 if base::wants_new_eh_instructions(self.cx.sess()) {
2072 llbb = Bx::append_block(self.cx, self.llfn, "cs_terminate");
2112
2113 let mut cs_bx = Bx::build(self.cx, llbb);
2114
2115 let mut outer_cleanuppad = None;
2119 if outer_catchpad_bb.is_some() {
2120 let outer_funclet = self.funclets[cache_bb]
2122 .as_ref()
2123 .expect("landing_pad_for didn't create funclet");
2124 outer_cleanuppad = Some(cs_bx.get_funclet_cleanuppad(outer_funclet));
2125 }
2126 let cp_llbb = Bx::append_block(self.cx, self.llfn, "cp_terminate");
2127 let cs = cs_bx.catch_switch(outer_cleanuppad, None, &[cp_llbb]);
2128 drop(cs_bx);
2129
2130 bx = Bx::build(self.cx, cp_llbb);
2131 let null =
2132 bx.const_null(bx.type_ptr_ext(bx.cx().data_layout().instruction_address_space));
2133
2134 let args = if base::wants_msvc_seh(self.cx.sess()) {
2138 let adjectives = bx.const_i32(0x40);
2145 &[null, adjectives, null] as &[_]
2146 } else {
2147 &[null] as &[_]
2153 };
2154
2155 funclet = Some(bx.catch_pad(cs, args));
2156 } else {
2162 llbb = Bx::append_block(self.cx, self.llfn, "terminate");
2163 bx = Bx::build(self.cx, llbb);
2164
2165 let llpersonality = self.cx.eh_personality();
2166 bx.filter_landing_pad(llpersonality);
2167
2168 funclet = None;
2169 }
2170
2171 self.set_debug_loc(&mut bx, mir::SourceInfo::outermost(self.mir.span));
2172
2173 let (fn_abi, fn_ptr, instance) =
2174 common::build_langcall(&bx, self.mir.span, reason.lang_item());
2175 if is_call_from_compiler_builtins_to_upstream_monomorphization(bx.tcx(), instance) {
2176 bx.abort();
2177 } else {
2178 let fn_ty = bx.fn_decl_backend_type(fn_abi);
2179
2180 let llret = bx.call(fn_ty, None, Some(fn_abi), fn_ptr, &[], funclet.as_ref(), None);
2181 bx.apply_attrs_to_cleanup_callsite(llret);
2182 }
2183
2184 bx.unreachable();
2185
2186 self.terminate_blocks[cache_bb] = Some((llbb, reason));
2187 llbb
2188 }
2189
2190 pub fn llbb(&mut self, bb: mir::BasicBlock) -> Bx::BasicBlock {
2195 self.try_llbb(bb).unwrap()
2196 }
2197
2198 pub(crate) fn try_llbb(&mut self, bb: mir::BasicBlock) -> Option<Bx::BasicBlock> {
2200 match self.cached_llbbs[bb] {
2201 CachedLlbb::None => {
2202 let llbb = Bx::append_block(self.cx, self.llfn, &::alloc::__export::must_use({
::alloc::fmt::format(format_args!("{0:?}", bb))
})format!("{bb:?}"));
2203 self.cached_llbbs[bb] = CachedLlbb::Some(llbb);
2204 Some(llbb)
2205 }
2206 CachedLlbb::Some(llbb) => Some(llbb),
2207 CachedLlbb::Skip => None,
2208 }
2209 }
2210
2211 fn make_return_dest(
2212 &mut self,
2213 bx: &mut Bx,
2214 dest: mir::Place<'tcx>,
2215 fn_ret: &ArgAbi<'tcx, Ty<'tcx>>,
2216 llargs: &mut Vec<Bx::Value>,
2217 ) -> ReturnDest<'tcx, Bx::Value> {
2218 if fn_ret.is_ignore() {
2220 return ReturnDest::Nothing;
2221 }
2222 let dest = if let Some(index) = dest.as_local() {
2223 match self.locals[index] {
2224 LocalRef::Place(dest) => dest,
2225 LocalRef::UnsizedPlace(_) => ::rustc_middle::util::bug::bug_fmt(format_args!("return type must be sized"))bug!("return type must be sized"),
2226 LocalRef::PendingOperand => {
2227 return if fn_ret.is_indirect() {
2230 let tmp = PlaceRef::alloca(bx, fn_ret.layout);
2233 tmp.storage_live(bx);
2234 llargs.push(tmp.val.llval);
2235 ReturnDest::IndirectOperand(tmp, index)
2236 } else {
2237 ReturnDest::DirectOperand(index)
2238 };
2239 }
2240 LocalRef::Operand(_) => {
2241 ::rustc_middle::util::bug::bug_fmt(format_args!("place local already assigned to"));bug!("place local already assigned to");
2242 }
2243 }
2244 } else {
2245 self.codegen_place(bx, dest.as_ref())
2246 };
2247 if fn_ret.is_indirect() {
2248 if dest.val.align < dest.layout.align.abi {
2249 ::rustc_middle::util::bug::span_bug_fmt(self.mir.span,
format_args!("can\'t directly store to unaligned value"));span_bug!(self.mir.span, "can't directly store to unaligned value");
2256 }
2257 llargs.push(dest.val.llval);
2258 ReturnDest::Nothing
2259 } else {
2260 ReturnDest::Store(dest)
2261 }
2262 }
2263
2264 fn store_return(
2266 &mut self,
2267 bx: &mut Bx,
2268 dest: ReturnDest<'tcx, Bx::Value>,
2269 ret_abi: &ArgAbi<'tcx, Ty<'tcx>>,
2270 llval: Bx::Value,
2271 ) {
2272 use self::ReturnDest::*;
2273 let retags_enabled = bx.tcx().sess.opts.unstable_opts.codegen_emit_retag.is_some();
2274 match dest {
2275 Nothing => (),
2276 Store(dst) => {
2277 bx.store_arg(ret_abi, llval, dst);
2278 if retags_enabled {
2279 self.codegen_retag_place(bx, dst, false);
2280 }
2281 }
2282 IndirectOperand(tmp, index) => {
2283 let mut op = bx.load_operand(tmp);
2284 tmp.storage_dead(bx);
2285 if retags_enabled {
2286 op = self.codegen_retag_operand(bx, op, false);
2287 }
2288 self.overwrite_local(index, LocalRef::Operand(op));
2289 self.debug_introduce_local(bx, index);
2290 }
2291 DirectOperand(index) => {
2292 let mut op = if let PassMode::Cast { .. } = ret_abi.mode {
2294 let tmp = PlaceRef::alloca(bx, ret_abi.layout);
2295 tmp.storage_live(bx);
2296 bx.store_arg(ret_abi, llval, tmp);
2297 let op = bx.load_operand(tmp);
2298 tmp.storage_dead(bx);
2299 op
2300 } else {
2301 OperandRef::from_immediate_or_packed_pair(bx, llval, ret_abi.layout)
2302 };
2303 if retags_enabled {
2304 op = self.codegen_retag_operand(bx, op, false);
2305 }
2306 self.overwrite_local(index, LocalRef::Operand(op));
2307 self.debug_introduce_local(bx, index);
2308 }
2309 }
2310 }
2311}
2312
2313enum ReturnDest<'tcx, V> {
2314 Nothing,
2316 Store(PlaceRef<'tcx, V>),
2318 IndirectOperand(PlaceRef<'tcx, V>, mir::Local),
2320 DirectOperand(mir::Local),
2322}
2323
2324fn load_cast<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
2325 bx: &mut Bx,
2326 cast: &CastTarget,
2327 ptr: Bx::Value,
2328 align: Align,
2329) -> Bx::Value {
2330 let cast_ty = bx.cast_backend_type(cast);
2331 if let Some(offset_from_start) = cast.rest_offset {
2332 {
match (&cast.prefix.len(), &1) {
(left_val, right_val) => {
if !(*left_val == *right_val) {
let kind = ::core::panicking::AssertKind::Eq;
::core::panicking::assert_failed(kind, &*left_val,
&*right_val, ::core::option::Option::None);
}
}
}
};assert_eq!(cast.prefix.len(), 1);
2333 {
match (&cast.rest.unit.size, &cast.rest.total) {
(left_val, right_val) => {
if !(*left_val == *right_val) {
let kind = ::core::panicking::AssertKind::Eq;
::core::panicking::assert_failed(kind, &*left_val,
&*right_val, ::core::option::Option::None);
}
}
}
};assert_eq!(cast.rest.unit.size, cast.rest.total);
2334 let first_ty = bx.reg_backend_type(&cast.prefix[0]);
2335 let second_ty = bx.reg_backend_type(&cast.rest.unit);
2336 let first = bx.load(first_ty, ptr, align);
2337 let second_ptr = bx.inbounds_ptradd(ptr, bx.const_usize(offset_from_start.bytes()));
2338 let second = bx.load(second_ty, second_ptr, align.restrict_for_offset(offset_from_start));
2339 let res = bx.cx().const_poison(cast_ty);
2340 let res = bx.insert_value(res, first, 0);
2341 bx.insert_value(res, second, 1)
2342 } else {
2343 bx.load(cast_ty, ptr, align)
2344 }
2345}
2346
2347pub fn store_cast<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
2348 bx: &mut Bx,
2349 cast: &CastTarget,
2350 value: Bx::Value,
2351 ptr: Bx::Value,
2352 align: Align,
2353) {
2354 if let Some(offset_from_start) = cast.rest_offset {
2355 {
match (&cast.prefix.len(), &1) {
(left_val, right_val) => {
if !(*left_val == *right_val) {
let kind = ::core::panicking::AssertKind::Eq;
::core::panicking::assert_failed(kind, &*left_val,
&*right_val, ::core::option::Option::None);
}
}
}
};assert_eq!(cast.prefix.len(), 1);
2356 {
match (&cast.rest.unit.size, &cast.rest.total) {
(left_val, right_val) => {
if !(*left_val == *right_val) {
let kind = ::core::panicking::AssertKind::Eq;
::core::panicking::assert_failed(kind, &*left_val,
&*right_val, ::core::option::Option::None);
}
}
}
};assert_eq!(cast.rest.unit.size, cast.rest.total);
2357 let first = bx.extract_value(value, 0);
2358 let second = bx.extract_value(value, 1);
2359 bx.store(first, ptr, align);
2360 let second_ptr = bx.inbounds_ptradd(ptr, bx.const_usize(offset_from_start.bytes()));
2361 bx.store(second, second_ptr, align.restrict_for_offset(offset_from_start));
2362 } else {
2363 bx.store(value, ptr, align);
2364 };
2365}