1use std::cmp;
2
3use rustc_abi::{Align, BackendRepr, ExternAbi, HasDataLayout, Reg, Size, WrappingRange};
4use rustc_ast as ast;
5use rustc_ast::{InlineAsmOptions, InlineAsmTemplatePiece};
6use rustc_data_structures::packed::Pu128;
7use rustc_hir::lang_items::LangItem;
8use rustc_lint_defs::builtin::TAIL_CALL_TRACK_CALLER;
9use rustc_middle::mir::{self, AssertKind, InlineAsmMacro, SwitchTargets, UnwindTerminateReason};
10use rustc_middle::ty::layout::{HasTyCtxt, LayoutOf, ValidityRequirement};
11use rustc_middle::ty::print::{with_no_trimmed_paths, with_no_visible_paths};
12use rustc_middle::ty::{self, Instance, Ty, TypeVisitableExt};
13use rustc_middle::{bug, span_bug};
14use rustc_session::config::OptLevel;
15use rustc_span::{Span, Spanned};
16use rustc_target::callconv::{ArgAbi, ArgAttributes, CastTarget, FnAbi, PassMode};
17use tracing::{debug, info};
18
19use super::operand::OperandRef;
20use super::operand::OperandValue::{self, Immediate, Pair, Ref, ZeroSized};
21use super::place::{PlaceRef, PlaceValue};
22use super::{CachedLlbb, FunctionCx, LocalRef};
23use crate::base::{self, is_call_from_compiler_builtins_to_upstream_monomorphization};
24use crate::common::{self, IntPredicate};
25use crate::errors::CompilerBuiltinsCannotCall;
26use crate::mir::IntrinsicResult;
27use crate::traits::*;
28use crate::{MemFlags, meth};
29
30#[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)]
34enum MergingSucc {
35 False,
36 True,
37}
38
39#[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)]
42enum CallKind {
43 Normal,
44 Tail,
45}
46
47struct TerminatorCodegenHelper<'tcx> {
50 bb: mir::BasicBlock,
51 terminator: &'tcx mir::Terminator<'tcx>,
52}
53
54impl<'a, 'tcx> TerminatorCodegenHelper<'tcx> {
55 fn funclet<'b, Bx: BuilderMethods<'a, 'tcx>>(
58 &self,
59 fx: &'b mut FunctionCx<'a, 'tcx, Bx>,
60 ) -> Option<&'b Bx::Funclet> {
61 let cleanup_kinds = fx.cleanup_kinds.as_ref()?;
62 let funclet_bb = cleanup_kinds[self.bb].funclet_bb(self.bb)?;
63 if fx.funclets[funclet_bb].is_none() {
72 fx.landing_pad_for(funclet_bb);
73 }
74 Some(
75 fx.funclets[funclet_bb]
76 .as_ref()
77 .expect("landing_pad_for didn't also create funclets entry"),
78 )
79 }
80
81 fn llbb_with_cleanup<Bx: BuilderMethods<'a, 'tcx>>(
84 &self,
85 fx: &mut FunctionCx<'a, 'tcx, Bx>,
86 target: mir::BasicBlock,
87 ) -> Bx::BasicBlock {
88 let (needs_landing_pad, is_cleanupret) = self.llbb_characteristics(fx, target);
89 let mut lltarget = fx.llbb(target);
90 if needs_landing_pad {
91 lltarget = fx.landing_pad_for(target);
92 }
93 if is_cleanupret {
94 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));
96 {
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:96",
"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(96u32),
::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);
97 let name = &::alloc::__export::must_use({
::alloc::fmt::format(format_args!("{0:?}_cleanup_trampoline_{1:?}",
self.bb, target))
})format!("{:?}_cleanup_trampoline_{:?}", self.bb, target);
98 let trampoline_llbb = Bx::append_block(fx.cx, fx.llfn, name);
99 let mut trampoline_bx = Bx::build(fx.cx, trampoline_llbb);
100 trampoline_bx.cleanup_ret(self.funclet(fx).unwrap(), Some(lltarget));
101 trampoline_llbb
102 } else {
103 lltarget
104 }
105 }
106
107 fn llbb_characteristics<Bx: BuilderMethods<'a, 'tcx>>(
108 &self,
109 fx: &mut FunctionCx<'a, 'tcx, Bx>,
110 target: mir::BasicBlock,
111 ) -> (bool, bool) {
112 if let Some(ref cleanup_kinds) = fx.cleanup_kinds {
113 let funclet_bb = cleanup_kinds[self.bb].funclet_bb(self.bb);
114 let target_funclet = cleanup_kinds[target].funclet_bb(target);
115 let (needs_landing_pad, is_cleanupret) = match (funclet_bb, target_funclet) {
116 (None, None) => (false, false),
117 (None, Some(_)) => (true, false),
118 (Some(f), Some(t_f)) => (f != t_f, f != t_f),
119 (Some(_), None) => {
120 let span = self.terminator.source_info.span;
121 ::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);
122 }
123 };
124 (needs_landing_pad, is_cleanupret)
125 } else {
126 let needs_landing_pad = !fx.mir[self.bb].is_cleanup && fx.mir[target].is_cleanup;
127 let is_cleanupret = false;
128 (needs_landing_pad, is_cleanupret)
129 }
130 }
131
132 fn funclet_br<Bx: BuilderMethods<'a, 'tcx>>(
133 &self,
134 fx: &mut FunctionCx<'a, 'tcx, Bx>,
135 bx: &mut Bx,
136 target: mir::BasicBlock,
137 mergeable_succ: bool,
138 ) -> MergingSucc {
139 let (needs_landing_pad, is_cleanupret) = self.llbb_characteristics(fx, target);
140 if mergeable_succ && !needs_landing_pad && !is_cleanupret {
141 MergingSucc::True
143 } else {
144 let mut lltarget = fx.llbb(target);
145 if needs_landing_pad {
146 lltarget = fx.landing_pad_for(target);
147 }
148 if is_cleanupret {
149 bx.cleanup_ret(self.funclet(fx).unwrap(), Some(lltarget));
152 } else {
153 bx.br(lltarget);
154 }
155 MergingSucc::False
156 }
157 }
158
159 fn do_call<Bx: BuilderMethods<'a, 'tcx>>(
162 &self,
163 fx: &mut FunctionCx<'a, 'tcx, Bx>,
164 bx: &mut Bx,
165 fn_abi: &'tcx FnAbi<'tcx, Ty<'tcx>>,
166 fn_ptr: Bx::Value,
167 llargs: &[Bx::Value],
168 destination: Option<(ReturnDest<'tcx, Bx::Value>, mir::BasicBlock)>,
169 mut unwind: mir::UnwindAction,
170 lifetime_ends_after_call: &[(Bx::Value, Size)],
171 instance: Option<Instance<'tcx>>,
172 kind: CallKind,
173 mergeable_succ: bool,
174 ) -> MergingSucc {
175 let tcx = bx.tcx();
176 if let Some(instance) = instance
177 && is_call_from_compiler_builtins_to_upstream_monomorphization(tcx, instance)
178 {
179 if destination.is_some() {
180 let caller_def = fx.instance.def_id();
181 let e = CompilerBuiltinsCannotCall {
182 span: tcx.def_span(caller_def),
183 caller: { let _guard = NoTrimmedGuard::new(); tcx.def_path_str(caller_def) }with_no_trimmed_paths!(tcx.def_path_str(caller_def)),
184 callee: { let _guard = NoTrimmedGuard::new(); tcx.def_path_str(instance.def_id()) }with_no_trimmed_paths!(tcx.def_path_str(instance.def_id())),
185 };
186 tcx.dcx().emit_err(e);
187 } else {
188 {
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:188",
"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(188u32),
::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!(
189 "compiler_builtins call to diverging function {:?} replaced with abort",
190 instance.def_id()
191 );
192 bx.abort();
193 bx.unreachable();
194 return MergingSucc::False;
195 }
196 }
197
198 let fn_ty = bx.fn_decl_backend_type(fn_abi);
201
202 let caller_attrs = if bx.tcx().def_kind(fx.instance.def_id()).has_codegen_attrs() {
203 Some(bx.tcx().codegen_instance_attrs(fx.instance.def))
204 } else {
205 None
206 };
207 let caller_attrs = caller_attrs.as_deref();
208
209 if !fn_abi.can_unwind {
210 unwind = mir::UnwindAction::Unreachable;
211 }
212
213 let unwind_block = match unwind {
214 mir::UnwindAction::Cleanup(cleanup) => Some(self.llbb_with_cleanup(fx, cleanup)),
215 mir::UnwindAction::Continue => None,
216 mir::UnwindAction::Unreachable => None,
217 mir::UnwindAction::Terminate(reason) => {
218 if fx.mir[self.bb].is_cleanup && base::wants_wasm_eh(fx.cx.tcx().sess) {
219 Some(fx.terminate_block(reason, Some(self.bb)))
222 } else if fx.mir[self.bb].is_cleanup
223 && base::wants_new_eh_instructions(fx.cx.tcx().sess)
224 {
225 None
228 } else {
229 Some(fx.terminate_block(reason, None))
230 }
231 }
232 };
233
234 if kind == CallKind::Tail {
235 bx.tail_call(fn_ty, caller_attrs, fn_abi, fn_ptr, llargs, self.funclet(fx), instance);
236 return MergingSucc::False;
237 }
238
239 if let Some(unwind_block) = unwind_block {
240 let ret_llbb = if let Some((_, target)) = destination {
241 self.llbb_with_cleanup(fx, target)
242 } else {
243 fx.unreachable_block()
244 };
245 let invokeret = bx.invoke(
246 fn_ty,
247 caller_attrs,
248 Some(fn_abi),
249 fn_ptr,
250 llargs,
251 ret_llbb,
252 unwind_block,
253 self.funclet(fx),
254 instance,
255 );
256 if fx.mir[self.bb].is_cleanup {
257 bx.apply_attrs_to_cleanup_callsite(invokeret);
258 }
259
260 if let Some((ret_dest, target)) = destination {
261 bx.switch_to_block(fx.llbb(target));
262 fx.set_debug_loc(bx, self.terminator.source_info);
263 for &(tmp, size) in lifetime_ends_after_call {
264 bx.lifetime_end(tmp, size);
265 }
266 fx.store_return(bx, ret_dest, &fn_abi.ret, invokeret);
267
268 fx.cached_llbbs[target] = CachedLlbb::Some(bx.llbb());
273 }
274 MergingSucc::False
275 } else {
276 let llret = bx.call(
277 fn_ty,
278 caller_attrs,
279 Some(fn_abi),
280 fn_ptr,
281 llargs,
282 self.funclet(fx),
283 instance,
284 );
285 if fx.mir[self.bb].is_cleanup {
286 bx.apply_attrs_to_cleanup_callsite(llret);
287 }
288
289 if let Some((ret_dest, target)) = destination {
290 for &(tmp, size) in lifetime_ends_after_call {
291 bx.lifetime_end(tmp, size);
292 }
293 fx.store_return(bx, ret_dest, &fn_abi.ret, llret);
294 self.funclet_br(fx, bx, target, mergeable_succ)
295 } else {
296 bx.unreachable();
297 MergingSucc::False
298 }
299 }
300 }
301
302 fn do_inlineasm<Bx: BuilderMethods<'a, 'tcx>>(
304 &self,
305 fx: &mut FunctionCx<'a, 'tcx, Bx>,
306 bx: &mut Bx,
307 template: &[InlineAsmTemplatePiece],
308 operands: &[InlineAsmOperandRef<'tcx, Bx>],
309 options: InlineAsmOptions,
310 line_spans: &[Span],
311 destination: Option<mir::BasicBlock>,
312 unwind: mir::UnwindAction,
313 instance: Instance<'_>,
314 mergeable_succ: bool,
315 ) -> MergingSucc {
316 let unwind_target = match unwind {
317 mir::UnwindAction::Cleanup(cleanup) => Some(self.llbb_with_cleanup(fx, cleanup)),
318 mir::UnwindAction::Terminate(reason) => Some(fx.terminate_block(reason, None)),
319 mir::UnwindAction::Continue => None,
320 mir::UnwindAction::Unreachable => None,
321 };
322
323 if operands.iter().any(|x| #[allow(non_exhaustive_omitted_patterns)] match x {
InlineAsmOperandRef::Label { .. } => true,
_ => false,
}matches!(x, InlineAsmOperandRef::Label { .. })) {
324 if !unwind_target.is_none() {
::core::panicking::panic("assertion failed: unwind_target.is_none()")
};assert!(unwind_target.is_none());
325 let ret_llbb = if let Some(target) = destination {
326 self.llbb_with_cleanup(fx, target)
327 } else {
328 fx.unreachable_block()
329 };
330
331 bx.codegen_inline_asm(
332 template,
333 operands,
334 options,
335 line_spans,
336 instance,
337 Some(ret_llbb),
338 None,
339 );
340 MergingSucc::False
341 } else if let Some(cleanup) = unwind_target {
342 let ret_llbb = if let Some(target) = destination {
343 self.llbb_with_cleanup(fx, target)
344 } else {
345 fx.unreachable_block()
346 };
347
348 bx.codegen_inline_asm(
349 template,
350 operands,
351 options,
352 line_spans,
353 instance,
354 Some(ret_llbb),
355 Some((cleanup, self.funclet(fx))),
356 );
357 MergingSucc::False
358 } else {
359 bx.codegen_inline_asm(template, operands, options, line_spans, instance, None, None);
360
361 if let Some(target) = destination {
362 self.funclet_br(fx, bx, target, mergeable_succ)
363 } else {
364 bx.unreachable();
365 MergingSucc::False
366 }
367 }
368 }
369}
370
371impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
373 fn codegen_resume_terminator(&mut self, helper: TerminatorCodegenHelper<'tcx>, bx: &mut Bx) {
375 if let Some(funclet) = helper.funclet(self) {
376 bx.cleanup_ret(funclet, None);
377 } else {
378 let slot = self.get_personality_slot(bx);
379 let exn0 = slot.project_field(bx, 0);
380 let exn0 = bx.load_operand(exn0).immediate();
381 let exn1 = slot.project_field(bx, 1);
382 let exn1 = bx.load_operand(exn1).immediate();
383 slot.storage_dead(bx);
384
385 bx.resume(exn0, exn1);
386 }
387 }
388
389 fn codegen_switchint_terminator(
390 &mut self,
391 helper: TerminatorCodegenHelper<'tcx>,
392 bx: &mut Bx,
393 discr: &mir::Operand<'tcx>,
394 targets: &SwitchTargets,
395 ) {
396 let discr = self.codegen_operand(bx, discr);
397 let discr_value = discr.immediate();
398 let switch_ty = discr.layout.ty;
399 if let Some(const_discr) = bx.const_to_opt_u128(discr_value, false) {
401 let target = targets.target_for_value(const_discr);
402 bx.br(helper.llbb_with_cleanup(self, target));
403 return;
404 };
405
406 let mut target_iter = targets.iter();
407 if target_iter.len() == 1 {
408 let (test_value, target) = target_iter.next().unwrap();
411 let otherwise = targets.otherwise();
412 let lltarget = helper.llbb_with_cleanup(self, target);
413 let llotherwise = helper.llbb_with_cleanup(self, otherwise);
414 let target_cold = self.cold_blocks[target];
415 let otherwise_cold = self.cold_blocks[otherwise];
416 let expect = if target_cold == otherwise_cold { None } else { Some(otherwise_cold) };
420 if switch_ty == bx.tcx().types.bool {
421 match test_value {
423 0 => {
424 let expect = expect.map(|e| !e);
425 bx.cond_br_with_expect(discr_value, llotherwise, lltarget, expect);
426 }
427 1 => {
428 bx.cond_br_with_expect(discr_value, lltarget, llotherwise, expect);
429 }
430 _ => ::rustc_middle::util::bug::bug_fmt(format_args!("impossible case reached"))bug!(),
431 }
432 } else {
433 let switch_llty = bx.immediate_backend_type(bx.layout_of(switch_ty));
434 let llval = bx.const_uint_big(switch_llty, test_value);
435 let cmp = bx.icmp(IntPredicate::IntEQ, discr_value, llval);
436 bx.cond_br_with_expect(cmp, lltarget, llotherwise, expect);
437 }
438 } else if target_iter.len() == 2
439 && self.mir[targets.otherwise()].is_empty_unreachable()
440 && targets.all_values().contains(&Pu128(0))
441 && targets.all_values().contains(&Pu128(1))
442 {
443 let true_bb = targets.target_for_value(1);
447 let false_bb = targets.target_for_value(0);
448 let true_ll = helper.llbb_with_cleanup(self, true_bb);
449 let false_ll = helper.llbb_with_cleanup(self, false_bb);
450
451 let expected_cond_value = if self.cx.sess().opts.optimize == OptLevel::No {
452 None
453 } else {
454 match (self.cold_blocks[true_bb], self.cold_blocks[false_bb]) {
455 (true, true) | (false, false) => None,
457 (true, false) => Some(false),
459 (false, true) => Some(true),
460 }
461 };
462
463 let bool_ty = bx.tcx().types.bool;
464 let cond = if switch_ty == bool_ty {
465 discr_value
466 } else {
467 let bool_llty = bx.immediate_backend_type(bx.layout_of(bool_ty));
468 bx.unchecked_utrunc(discr_value, bool_llty)
469 };
470 bx.cond_br_with_expect(cond, true_ll, false_ll, expected_cond_value);
471 } else if self.cx.sess().opts.optimize == OptLevel::No
472 && target_iter.len() == 2
473 && self.mir[targets.otherwise()].is_empty_unreachable()
474 {
475 let (test_value1, target1) = target_iter.next().unwrap();
488 let (_test_value2, target2) = target_iter.next().unwrap();
489 let ll1 = helper.llbb_with_cleanup(self, target1);
490 let ll2 = helper.llbb_with_cleanup(self, target2);
491 let switch_llty = bx.immediate_backend_type(bx.layout_of(switch_ty));
492 let llval = bx.const_uint_big(switch_llty, test_value1);
493 let cmp = bx.icmp(IntPredicate::IntEQ, discr_value, llval);
494 bx.cond_br(cmp, ll1, ll2);
495 } else {
496 let otherwise = targets.otherwise();
497 let otherwise_cold = self.cold_blocks[otherwise];
498 let otherwise_unreachable = self.mir[otherwise].is_empty_unreachable();
499 let cold_count = targets.iter().filter(|(_, target)| self.cold_blocks[*target]).count();
500 let none_cold = cold_count == 0;
501 let all_cold = cold_count == targets.iter().len();
502 if (none_cold && (!otherwise_cold || otherwise_unreachable))
503 || (all_cold && (otherwise_cold || otherwise_unreachable))
504 {
505 bx.switch(
508 discr_value,
509 helper.llbb_with_cleanup(self, targets.otherwise()),
510 target_iter
511 .map(|(value, target)| (value, helper.llbb_with_cleanup(self, target))),
512 );
513 } else {
514 bx.switch_with_weights(
516 discr_value,
517 helper.llbb_with_cleanup(self, targets.otherwise()),
518 otherwise_cold,
519 target_iter.map(|(value, target)| {
520 (value, helper.llbb_with_cleanup(self, target), self.cold_blocks[target])
521 }),
522 );
523 }
524 }
525 }
526
527 fn codegen_return_terminator(&mut self, bx: &mut Bx) {
528 if self.fn_abi.c_variadic {
530 let va_list_arg_idx = self.fn_abi.args.len();
532 match self.locals[mir::Local::arg(va_list_arg_idx)] {
533 LocalRef::Place(va_list) => {
534 bx.va_end(va_list.val.llval);
535
536 bx.lifetime_end(va_list.val.llval, va_list.layout.size);
538 }
539 _ => ::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"),
540 }
541 }
542 if self.fn_abi.ret.layout.is_uninhabited() {
543 bx.abort();
548 bx.unreachable();
551 return;
552 }
553 let llval = match &self.fn_abi.ret.mode {
554 PassMode::Ignore | PassMode::Indirect { .. } => {
555 bx.ret_void();
556 return;
557 }
558
559 PassMode::Direct(_) | PassMode::Pair(..) => {
560 let op = self.codegen_consume(bx, mir::Place::return_place().as_ref());
561 if let Ref(place_val) = op.val {
562 bx.load_from_place(bx.backend_type(op.layout), place_val)
563 } else {
564 op.immediate_or_packed_pair(bx)
565 }
566 }
567
568 PassMode::Cast { cast: cast_ty, pad_i32: _ } => {
569 let op = match self.locals[mir::RETURN_PLACE] {
570 LocalRef::Operand(op) => op,
571 LocalRef::PendingOperand => ::rustc_middle::util::bug::bug_fmt(format_args!("use of return before def"))bug!("use of return before def"),
572 LocalRef::Place(cg_place) => OperandRef {
573 val: Ref(cg_place.val),
574 layout: cg_place.layout,
575 move_annotation: None,
576 },
577 LocalRef::UnsizedPlace(_) => ::rustc_middle::util::bug::bug_fmt(format_args!("return type must be sized"))bug!("return type must be sized"),
578 };
579 let llslot = match op.val {
580 Immediate(_) | Pair(..) => {
581 let scratch = PlaceRef::alloca(bx, self.fn_abi.ret.layout);
582 op.val.store(bx, scratch);
583 scratch.val.llval
584 }
585 Ref(place_val) => {
586 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!(
587 place_val.align, op.layout.align.abi,
588 "return place is unaligned!"
589 );
590 place_val.llval
591 }
592 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"),
593 };
594 load_cast(bx, cast_ty, llslot, self.fn_abi.ret.layout.align.abi)
595 }
596 };
597 bx.ret(llval);
598 }
599
600 #[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(600u32),
::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::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:649",
"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(649u32),
::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:650",
"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(650u32),
::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:651",
"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(651u32),
::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))]
601 fn codegen_drop_terminator(
602 &mut self,
603 helper: TerminatorCodegenHelper<'tcx>,
604 bx: &mut Bx,
605 source_info: &mir::SourceInfo,
606 location: mir::Place<'tcx>,
607 target: mir::BasicBlock,
608 unwind: mir::UnwindAction,
609 mergeable_succ: bool,
610 ) -> MergingSucc {
611 let ty = location.ty(self.mir, bx.tcx()).ty;
612 let ty = self.monomorphize(ty);
613 let drop_fn = Instance::resolve_drop_glue(bx.tcx(), ty);
614
615 if let ty::InstanceKind::DropGlue(_, None) = drop_fn.def {
616 return helper.funclet_br(self, bx, target, mergeable_succ);
618 }
619
620 let place = self.codegen_place(bx, location.as_ref());
621 let (args1, args2);
622 let mut args = if let Some(llextra) = place.val.llextra {
623 args2 = [place.val.llval, llextra];
624 &args2[..]
625 } else {
626 args1 = [place.val.llval];
627 &args1[..]
628 };
629 let (maybe_null, drop_fn, fn_abi, drop_instance) = match ty.kind() {
630 ty::Dynamic(_, _) => {
633 let virtual_drop = Instance {
646 def: ty::InstanceKind::Virtual(drop_fn.def_id(), 0), args: drop_fn.args,
648 };
649 debug!("ty = {:?}", ty);
650 debug!("drop_fn = {:?}", drop_fn);
651 debug!("args = {:?}", args);
652 let fn_abi = bx.fn_abi_of_instance(virtual_drop, ty::List::empty());
653 let vtable = args[1];
654 args = &args[..1];
656 (
657 true,
658 meth::VirtualIndex::from_index(ty::COMMON_VTABLE_ENTRIES_DROPINPLACE)
659 .get_optional_fn(bx, vtable, ty, fn_abi),
660 fn_abi,
661 virtual_drop,
662 )
663 }
664 _ => (
665 false,
666 bx.get_fn_addr(drop_fn),
667 bx.fn_abi_of_instance(drop_fn, ty::List::empty()),
668 drop_fn,
669 ),
670 };
671
672 if maybe_null {
675 let is_not_null = bx.append_sibling_block("is_not_null");
676 let llty = bx.fn_ptr_backend_type(fn_abi);
677 let null = bx.const_null(llty);
678 let non_null =
679 bx.icmp(base::bin_op_to_icmp_predicate(mir::BinOp::Ne, false), drop_fn, null);
680 bx.cond_br(non_null, is_not_null, helper.llbb_with_cleanup(self, target));
681 bx.switch_to_block(is_not_null);
682 self.set_debug_loc(bx, *source_info);
683 }
684
685 helper.do_call(
686 self,
687 bx,
688 fn_abi,
689 drop_fn,
690 args,
691 Some((ReturnDest::Nothing, target)),
692 unwind,
693 &[],
694 Some(drop_instance),
695 CallKind::Normal,
696 !maybe_null && mergeable_succ,
697 )
698 }
699
700 fn codegen_assert_terminator(
701 &mut self,
702 helper: TerminatorCodegenHelper<'tcx>,
703 bx: &mut Bx,
704 terminator: &mir::Terminator<'tcx>,
705 cond: &mir::Operand<'tcx>,
706 expected: bool,
707 msg: &mir::AssertMessage<'tcx>,
708 target: mir::BasicBlock,
709 unwind: mir::UnwindAction,
710 mergeable_succ: bool,
711 ) -> MergingSucc {
712 let span = terminator.source_info.span;
713 let cond = self.codegen_operand(bx, cond).immediate();
714 let mut const_cond = bx.const_to_opt_u128(cond, false).map(|c| c == 1);
715
716 if !bx.sess().overflow_checks() && msg.is_optional_overflow_check() {
721 const_cond = Some(expected);
722 }
723
724 if const_cond == Some(expected) {
726 return helper.funclet_br(self, bx, target, mergeable_succ);
727 }
728
729 let lltarget = helper.llbb_with_cleanup(self, target);
734 let panic_block = bx.append_sibling_block("panic");
735 if expected {
736 bx.cond_br(cond, lltarget, panic_block);
737 } else {
738 bx.cond_br(cond, panic_block, lltarget);
739 }
740
741 bx.switch_to_block(panic_block);
743 self.set_debug_loc(bx, terminator.source_info);
744
745 let location = self.get_caller_location(bx, terminator.source_info).immediate();
747
748 let (lang_item, args) = match msg {
750 AssertKind::BoundsCheck { len, index } => {
751 let len = self.codegen_operand(bx, len).immediate();
752 let index = self.codegen_operand(bx, index).immediate();
753 (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])
756 }
757 AssertKind::MisalignedPointerDereference { required, found } => {
758 let required = self.codegen_operand(bx, required).immediate();
759 let found = self.codegen_operand(bx, found).immediate();
760 (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])
763 }
764 AssertKind::NullPointerDereference => {
765 (LangItem::PanicNullPointerDereference, ::alloc::boxed::box_assume_init_into_vec_unsafe(::alloc::intrinsics::write_box_via_move(::alloc::boxed::Box::new_uninit(),
[location]))vec![location])
768 }
769 AssertKind::InvalidEnumConstruction(source) => {
770 let source = self.codegen_operand(bx, source).immediate();
771 (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])
774 }
775 _ => {
776 (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])
778 }
779 };
780
781 let (fn_abi, llfn, instance) = common::build_langcall(bx, span, lang_item);
782
783 let merging_succ = helper.do_call(
785 self,
786 bx,
787 fn_abi,
788 llfn,
789 &args,
790 None,
791 unwind,
792 &[],
793 Some(instance),
794 CallKind::Normal,
795 false,
796 );
797 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);
798 MergingSucc::False
799 }
800
801 fn codegen_terminate_terminator(
802 &mut self,
803 helper: TerminatorCodegenHelper<'tcx>,
804 bx: &mut Bx,
805 terminator: &mir::Terminator<'tcx>,
806 reason: UnwindTerminateReason,
807 ) {
808 let span = terminator.source_info.span;
809 self.set_debug_loc(bx, terminator.source_info);
810
811 let (fn_abi, llfn, instance) = common::build_langcall(bx, span, reason.lang_item());
813
814 let merging_succ = helper.do_call(
816 self,
817 bx,
818 fn_abi,
819 llfn,
820 &[],
821 None,
822 mir::UnwindAction::Unreachable,
823 &[],
824 Some(instance),
825 CallKind::Normal,
826 false,
827 );
828 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);
829 }
830
831 fn codegen_panic_intrinsic(
833 &mut self,
834 helper: &TerminatorCodegenHelper<'tcx>,
835 bx: &mut Bx,
836 intrinsic: ty::IntrinsicDef,
837 instance: Instance<'tcx>,
838 source_info: mir::SourceInfo,
839 target: Option<mir::BasicBlock>,
840 unwind: mir::UnwindAction,
841 mergeable_succ: bool,
842 ) -> Option<MergingSucc> {
843 let Some(requirement) = ValidityRequirement::from_intrinsic(intrinsic.name) else {
847 return None;
848 };
849
850 let ty = instance.args.type_at(0);
851
852 let is_valid = bx
853 .tcx()
854 .check_validity_requirement((requirement, bx.typing_env().as_query_input(ty)))
855 .expect("expect to have layout during codegen");
856
857 if is_valid {
858 let target = target.unwrap();
860 return Some(helper.funclet_br(self, bx, target, mergeable_succ));
861 }
862
863 let layout = bx.layout_of(ty);
864
865 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!({
866 with_no_trimmed_paths!({
867 if layout.is_uninhabited() {
868 format!("attempted to instantiate uninhabited type `{ty}`")
870 } else if requirement == ValidityRequirement::Zero {
871 format!("attempted to zero-initialize type `{ty}`, which is invalid")
872 } else {
873 format!("attempted to leave type `{ty}` uninitialized, which is invalid")
874 }
875 })
876 });
877 let msg = bx.const_str(&msg_str);
878
879 let (fn_abi, llfn, instance) =
881 common::build_langcall(bx, source_info.span, LangItem::PanicNounwind);
882
883 Some(helper.do_call(
885 self,
886 bx,
887 fn_abi,
888 llfn,
889 &[msg.0, msg.1],
890 target.as_ref().map(|bb| (ReturnDest::Nothing, *bb)),
891 unwind,
892 &[],
893 Some(instance),
894 CallKind::Normal,
895 mergeable_succ,
896 ))
897 }
898
899 fn codegen_call_terminator(
900 &mut self,
901 helper: TerminatorCodegenHelper<'tcx>,
902 bx: &mut Bx,
903 terminator: &mir::Terminator<'tcx>,
904 func: &mir::Operand<'tcx>,
905 args: &[Spanned<mir::Operand<'tcx>>],
906 destination: mir::Place<'tcx>,
907 target: Option<mir::BasicBlock>,
908 unwind: mir::UnwindAction,
909 fn_span: Span,
910 kind: CallKind,
911 mergeable_succ: bool,
912 ) -> MergingSucc {
913 let source_info = mir::SourceInfo { span: fn_span, ..terminator.source_info };
914
915 let callee = self.codegen_operand(bx, func);
917
918 let (instance, mut llfn) = match *callee.layout.ty.kind() {
919 ty::FnDef(def_id, generic_args) => {
920 let instance = ty::Instance::expect_resolve(
921 bx.tcx(),
922 bx.typing_env(),
923 def_id,
924 generic_args,
925 fn_span,
926 );
927
928 match instance.def {
929 ty::InstanceKind::DropGlue(_, None) => {
932 let target = target.unwrap();
934 return helper.funclet_br(self, bx, target, mergeable_succ);
935 }
936 ty::InstanceKind::Intrinsic(def_id) => {
937 let intrinsic = bx.tcx().intrinsic(def_id).unwrap();
938 if let Some(merging_succ) = self.codegen_panic_intrinsic(
939 &helper,
940 bx,
941 intrinsic,
942 instance,
943 source_info,
944 target,
945 unwind,
946 mergeable_succ,
947 ) {
948 return merging_succ;
949 }
950
951 let result_layout =
952 self.cx.layout_of(self.monomorphized_place_ty(destination.as_ref()));
953
954 let (result_place, store_in_local) =
955 if let Some(local) = destination.as_local() {
956 match self.locals[local] {
957 LocalRef::Place(dest) => (Some(dest.val), None),
958 LocalRef::UnsizedPlace(_) => ::rustc_middle::util::bug::bug_fmt(format_args!("return type must be sized"))bug!("return type must be sized"),
959 LocalRef::PendingOperand => (None, Some(local)),
960 LocalRef::Operand(_) => {
961 if result_layout.is_zst() {
962 let place = PlaceRef::new_sized(
963 bx.const_undef(bx.type_ptr()),
964 result_layout,
965 );
966 (Some(place.val), None)
967 } else {
968 ::rustc_middle::util::bug::bug_fmt(format_args!("place local already assigned to"));bug!("place local already assigned to");
969 }
970 }
971 }
972 } else {
973 (Some(self.codegen_place(bx, destination.as_ref()).val), None)
974 };
975
976 if let Some(place) = result_place
977 && place.align < result_layout.align.abi
978 {
979 ::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");
986 }
987
988 let args: Vec<_> =
989 args.iter().map(|arg| self.codegen_operand(bx, &arg.node)).collect();
990
991 let intrinsic_result = self.codegen_intrinsic_call(
992 bx,
993 instance,
994 &args,
995 result_layout,
996 result_place,
997 source_info,
998 );
999
1000 if let IntrinsicResult::Operand(op_val) = intrinsic_result {
1001 match (result_place, store_in_local) {
1002 (None, Some(local)) => {
1003 let op = OperandRef {
1004 val: op_val,
1005 layout: result_layout,
1006 move_annotation: None,
1007 };
1008 self.overwrite_local(local, LocalRef::Operand(op));
1009 self.debug_introduce_local(bx, local);
1010 }
1011 (Some(place_val), None) => {
1012 let dest = PlaceRef { val: place_val, layout: result_layout };
1013 op_val.store(bx, dest);
1014 }
1015 _ => ::rustc_middle::util::bug::bug_fmt(format_args!("impossible case reached"))bug!(),
1016 }
1017 }
1018
1019 match intrinsic_result {
1020 IntrinsicResult::Operand(_) | IntrinsicResult::WroteIntoPlace => {
1021 return if let Some(target) = target {
1022 helper.funclet_br(self, bx, target, mergeable_succ)
1023 } else {
1024 bx.unreachable();
1025 MergingSucc::False
1026 };
1027 }
1028 IntrinsicResult::Err(_) => {
1029 if let Some(local) = store_in_local {
1033 let op = OperandRef {
1034 val: OperandValue::poison(bx, result_layout),
1035 layout: result_layout,
1036 move_annotation: None,
1037 };
1038 self.overwrite_local(local, LocalRef::Operand(op));
1039 }
1040 bx.abort();
1043 return MergingSucc::False;
1044 }
1045 IntrinsicResult::Fallback(instance) => {
1046 if intrinsic.must_be_overridden {
1047 ::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!(
1048 fn_span,
1049 "intrinsic {} must be overridden by codegen backend, but isn't",
1050 intrinsic.name,
1051 );
1052 }
1053 (Some(instance), None)
1054 }
1055 }
1056 }
1057
1058 _ if kind == CallKind::Tail
1059 && instance.def.requires_caller_location(bx.tcx()) =>
1060 {
1061 if let Some(hir_id) =
1062 terminator.source_info.scope.lint_root(&self.mir.source_scopes)
1063 {
1064 bx.tcx().emit_node_lint(TAIL_CALL_TRACK_CALLER, hir_id, rustc_errors::DiagDecorator(|d| {
1065 _ = d.primary_message("tail calling a function marked with `#[track_caller]` has no special effect").span(fn_span)
1066 }));
1067 }
1068
1069 let instance = ty::Instance::resolve_for_fn_ptr(
1070 bx.tcx(),
1071 bx.typing_env(),
1072 def_id,
1073 generic_args,
1074 )
1075 .unwrap();
1076
1077 (None, Some(bx.get_fn_addr(instance)))
1078 }
1079 _ => (Some(instance), None),
1080 }
1081 }
1082 ty::FnPtr(..) => (None, Some(callee.immediate())),
1083 _ => ::rustc_middle::util::bug::bug_fmt(format_args!("{0} is not callable",
callee.layout.ty))bug!("{} is not callable", callee.layout.ty),
1084 };
1085
1086 if let Some(instance) = instance
1087 && let Some(name) = bx.tcx().codegen_fn_attrs(instance.def_id()).symbol_name
1088 && name.as_str().starts_with("llvm.")
1089 && name.as_str() != "llvm.wasm.throw"
1093 {
1094 if !!instance.args.has_infer() {
::core::panicking::panic("assertion failed: !instance.args.has_infer()")
};assert!(!instance.args.has_infer());
1095 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());
1096
1097 let result_layout =
1098 self.cx.layout_of(self.monomorphized_place_ty(destination.as_ref()));
1099
1100 let return_dest = if result_layout.is_zst() {
1101 ReturnDest::Nothing
1102 } else if let Some(index) = destination.as_local() {
1103 match self.locals[index] {
1104 LocalRef::Place(dest) => ReturnDest::Store(dest),
1105 LocalRef::UnsizedPlace(_) => ::rustc_middle::util::bug::bug_fmt(format_args!("return type must be sized"))bug!("return type must be sized"),
1106 LocalRef::PendingOperand => {
1107 ReturnDest::DirectOperand(index)
1110 }
1111 LocalRef::Operand(_) => ::rustc_middle::util::bug::bug_fmt(format_args!("place local already assigned to"))bug!("place local already assigned to"),
1112 }
1113 } else {
1114 ReturnDest::Store(self.codegen_place(bx, destination.as_ref()))
1115 };
1116
1117 let args =
1118 args.into_iter().map(|arg| self.codegen_operand(bx, &arg.node)).collect::<Vec<_>>();
1119
1120 self.set_debug_loc(bx, source_info);
1121
1122 let llret =
1123 bx.codegen_llvm_intrinsic_call(instance, &args, self.mir[helper.bb].is_cleanup);
1124
1125 if let Some(target) = target {
1126 self.store_return(
1127 bx,
1128 return_dest,
1129 &ArgAbi { layout: result_layout, mode: PassMode::Direct(ArgAttributes::new()) },
1130 llret,
1131 );
1132 return helper.funclet_br(self, bx, target, mergeable_succ);
1133 } else {
1134 bx.unreachable();
1135 return MergingSucc::False;
1136 }
1137 }
1138
1139 let sig = callee.layout.ty.fn_sig(bx.tcx());
1143
1144 let extra_args = &args[sig.inputs().skip_binder().len()..];
1145 let extra_args = bx.tcx().mk_type_list_from_iter(extra_args.iter().map(|op_arg| {
1146 let op_ty = op_arg.node.ty(self.mir, bx.tcx());
1147 self.monomorphize(op_ty)
1148 }));
1149
1150 let fn_abi = match instance {
1151 Some(instance) => bx.fn_abi_of_instance(instance, extra_args),
1152 None => bx.fn_abi_of_fn_ptr(sig, extra_args),
1153 };
1154
1155 let arg_count = fn_abi.args.len() + fn_abi.ret.is_indirect() as usize;
1157
1158 let mut llargs = Vec::with_capacity(arg_count);
1159
1160 let destination = match kind {
1164 CallKind::Normal => {
1165 let return_dest = self.make_return_dest(bx, destination, &fn_abi.ret, &mut llargs);
1166 target.map(|target| (return_dest, target))
1167 }
1168 CallKind::Tail => {
1169 if fn_abi.ret.is_indirect() {
1170 match self.make_return_dest(bx, destination, &fn_abi.ret, &mut llargs) {
1171 ReturnDest::Nothing => {}
1172 _ => ::rustc_middle::util::bug::bug_fmt(format_args!("tail calls to functions with indirect returns cannot store into a destination"))bug!(
1173 "tail calls to functions with indirect returns cannot store into a destination"
1174 ),
1175 }
1176 }
1177 None
1178 }
1179 };
1180
1181 let (first_args, untuple) = if sig.abi() == ExternAbi::RustCall
1183 && let Some((tup, args)) = args.split_last()
1184 {
1185 (args, Some(tup))
1186 } else {
1187 (args, None)
1188 };
1189
1190 let mut tail_call_temporaries = ::alloc::vec::Vec::new()vec![];
1213 if kind == CallKind::Tail {
1214 tail_call_temporaries = ::alloc::vec::from_elem(None, first_args.len())vec![None; first_args.len()];
1215 for (i, arg) in first_args.iter().enumerate() {
1218 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, .. }) {
1219 continue;
1220 }
1221
1222 let op = self.codegen_operand(bx, &arg.node);
1223 let tmp = PlaceRef::alloca(bx, op.layout);
1224 bx.lifetime_start(tmp.val.llval, tmp.layout.size);
1225 op.store_with_annotation(bx, tmp);
1226
1227 tail_call_temporaries[i] = Some(tmp);
1228 }
1229 }
1230
1231 let mut lifetime_ends_after_call: Vec<(Bx::Value, Size)> = Vec::new();
1235 'make_args: for (i, arg) in first_args.iter().enumerate() {
1236 let mut op = self.codegen_operand(bx, &arg.node);
1237
1238 if let (0, Some(ty::InstanceKind::Virtual(_, idx))) = (i, instance.map(|i| i.def)) {
1239 match op.val {
1240 Pair(data_ptr, meta) => {
1241 while !op.layout.ty.is_raw_ptr() && !op.layout.ty.is_ref() {
1251 let (idx, _) = op.layout.non_1zst_field(bx).expect(
1252 "not exactly one non-1-ZST field in a `DispatchFromDyn` type",
1253 );
1254 op = op.extract_field(self, bx, idx.as_usize());
1255 }
1256
1257 llfn = Some(meth::VirtualIndex::from_index(idx).get_fn(
1261 bx,
1262 meta,
1263 op.layout.ty,
1264 fn_abi,
1265 ));
1266 llargs.push(data_ptr);
1267 continue 'make_args;
1268 }
1269 Ref(PlaceValue { llval: data_ptr, llextra: Some(meta), .. }) => {
1270 llfn = Some(meth::VirtualIndex::from_index(idx).get_fn(
1272 bx,
1273 meta,
1274 op.layout.ty,
1275 fn_abi,
1276 ));
1277 llargs.push(data_ptr);
1278 continue;
1279 }
1280 _ => {
1281 ::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);
1282 }
1283 }
1284 }
1285
1286 let by_move = if let PassMode::Indirect { on_stack: false, .. } = fn_abi.args[i].mode
1287 && kind == CallKind::Tail
1288 {
1289 let Some(tmp) = tail_call_temporaries[i].take() else {
1302 ::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}")
1303 };
1304
1305 let local = self.mir.args_iter().nth(i).unwrap();
1306
1307 match &self.locals[local] {
1308 LocalRef::Place(arg) => {
1309 bx.typed_place_copy(arg.val, tmp.val, fn_abi.args[i].layout);
1310 op.val = Ref(arg.val);
1311 }
1312 LocalRef::Operand(arg) => {
1313 let Ref(place_value) = arg.val else {
1314 ::rustc_middle::util::bug::bug_fmt(format_args!("only `Ref` should use `PassMode::Indirect`"));bug!("only `Ref` should use `PassMode::Indirect`");
1315 };
1316 bx.typed_place_copy(place_value, tmp.val, fn_abi.args[i].layout);
1317 op.val = arg.val;
1318 }
1319 LocalRef::UnsizedPlace(_) => {
1320 ::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")
1321 }
1322 LocalRef::PendingOperand => {
1323 ::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")
1324 }
1325 };
1326
1327 bx.lifetime_end(tmp.val.llval, tmp.layout.size);
1328 true
1329 } else {
1330 #[allow(non_exhaustive_omitted_patterns)] match arg.node {
mir::Operand::Move(_) => true,
_ => false,
}matches!(arg.node, mir::Operand::Move(_))
1331 };
1332
1333 self.codegen_argument(
1334 bx,
1335 op,
1336 by_move,
1337 &mut llargs,
1338 &fn_abi.args[i],
1339 &mut lifetime_ends_after_call,
1340 );
1341 }
1342 let num_untupled = untuple.map(|tup| {
1343 self.codegen_arguments_untupled(
1344 bx,
1345 &tup.node,
1346 &mut llargs,
1347 &fn_abi.args[first_args.len()..],
1348 &mut lifetime_ends_after_call,
1349 )
1350 });
1351
1352 let needs_location =
1353 instance.is_some_and(|i| i.def.requires_caller_location(self.cx.tcx()));
1354 if needs_location {
1355 let mir_args = if let Some(num_untupled) = num_untupled {
1356 first_args.len() + num_untupled
1357 } else {
1358 args.len()
1359 };
1360 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!(
1361 fn_abi.args.len(),
1362 mir_args + 1,
1363 "#[track_caller] fn's must have 1 more argument in their ABI than in their MIR: {instance:?} {fn_span:?} {fn_abi:?}",
1364 );
1365 let location = self.get_caller_location(bx, source_info);
1366 {
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:1366",
"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(1366u32),
::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!(
1367 "codegen_call_terminator({:?}): location={:?} (fn_span {:?})",
1368 terminator, location, fn_span
1369 );
1370
1371 let last_arg = fn_abi.args.last().unwrap();
1372 self.codegen_argument(
1373 bx,
1374 location,
1375 false,
1376 &mut llargs,
1377 last_arg,
1378 &mut lifetime_ends_after_call,
1379 );
1380 }
1381
1382 let fn_ptr = match (instance, llfn) {
1383 (Some(instance), None) => bx.get_fn_addr(instance),
1384 (_, Some(llfn)) => llfn,
1385 _ => ::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"),
1386 };
1387 self.set_debug_loc(bx, source_info);
1388 helper.do_call(
1389 self,
1390 bx,
1391 fn_abi,
1392 fn_ptr,
1393 &llargs,
1394 destination,
1395 unwind,
1396 &lifetime_ends_after_call,
1397 instance,
1398 kind,
1399 mergeable_succ,
1400 )
1401 }
1402
1403 fn codegen_asm_terminator(
1404 &mut self,
1405 helper: TerminatorCodegenHelper<'tcx>,
1406 bx: &mut Bx,
1407 asm_macro: InlineAsmMacro,
1408 terminator: &mir::Terminator<'tcx>,
1409 template: &[ast::InlineAsmTemplatePiece],
1410 operands: &[mir::InlineAsmOperand<'tcx>],
1411 options: ast::InlineAsmOptions,
1412 line_spans: &[Span],
1413 targets: &[mir::BasicBlock],
1414 unwind: mir::UnwindAction,
1415 instance: Instance<'_>,
1416 mergeable_succ: bool,
1417 ) -> MergingSucc {
1418 let span = terminator.source_info.span;
1419
1420 let operands: Vec<_> = operands
1421 .iter()
1422 .map(|op| match *op {
1423 mir::InlineAsmOperand::In { reg, ref value } => {
1424 let value = self.codegen_operand(bx, value);
1425 InlineAsmOperandRef::In { reg, value }
1426 }
1427 mir::InlineAsmOperand::Out { reg, late, ref place } => {
1428 let place = place.map(|place| self.codegen_place(bx, place.as_ref()));
1429 InlineAsmOperandRef::Out { reg, late, place }
1430 }
1431 mir::InlineAsmOperand::InOut { reg, late, ref in_value, ref out_place } => {
1432 let in_value = self.codegen_operand(bx, in_value);
1433 let out_place =
1434 out_place.map(|out_place| self.codegen_place(bx, out_place.as_ref()));
1435 InlineAsmOperandRef::InOut { reg, late, in_value, out_place }
1436 }
1437 mir::InlineAsmOperand::Const { ref value } => {
1438 let const_value = self.eval_mir_constant(value);
1439 let string = common::asm_const_to_str(
1440 bx.tcx(),
1441 span,
1442 const_value,
1443 bx.layout_of(value.ty()),
1444 );
1445 InlineAsmOperandRef::Const { string }
1446 }
1447 mir::InlineAsmOperand::SymFn { ref value } => {
1448 let const_ = self.monomorphize(value.const_);
1449 if let ty::FnDef(def_id, args) = *const_.ty().kind() {
1450 let instance = ty::Instance::resolve_for_fn_ptr(
1451 bx.tcx(),
1452 bx.typing_env(),
1453 def_id,
1454 args,
1455 )
1456 .unwrap();
1457 InlineAsmOperandRef::SymFn { instance }
1458 } else {
1459 ::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)");
1460 }
1461 }
1462 mir::InlineAsmOperand::SymStatic { def_id } => {
1463 InlineAsmOperandRef::SymStatic { def_id }
1464 }
1465 mir::InlineAsmOperand::Label { target_index } => {
1466 InlineAsmOperandRef::Label { label: self.llbb(targets[target_index]) }
1467 }
1468 })
1469 .collect();
1470
1471 helper.do_inlineasm(
1472 self,
1473 bx,
1474 template,
1475 &operands,
1476 options,
1477 line_spans,
1478 if asm_macro.diverges(options) { None } else { targets.get(0).copied() },
1479 unwind,
1480 instance,
1481 mergeable_succ,
1482 )
1483 }
1484
1485 pub(crate) fn codegen_block(&mut self, mut bb: mir::BasicBlock) {
1486 let llbb = match self.try_llbb(bb) {
1487 Some(llbb) => llbb,
1488 None => return,
1489 };
1490 let bx = &mut Bx::build(self.cx, llbb);
1491 let mir = self.mir;
1492
1493 loop {
1497 let data = &mir[bb];
1498
1499 {
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:1499",
"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(1499u32),
::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);
1500
1501 for statement in &data.statements {
1502 self.codegen_statement(bx, statement);
1503 }
1504 self.codegen_stmt_debuginfos(bx, &data.after_last_stmt_debuginfos);
1505
1506 let merging_succ = self.codegen_terminator(bx, bb, data.terminator());
1507 if let MergingSucc::False = merging_succ {
1508 break;
1509 }
1510
1511 let mut successors = data.terminator().successors();
1519 let succ = successors.next().unwrap();
1520 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));
1521 self.cached_llbbs[succ] = CachedLlbb::Skip;
1522 bb = succ;
1523 }
1524 }
1525
1526 pub(crate) fn codegen_block_as_unreachable(&mut self, bb: mir::BasicBlock) {
1527 let llbb = match self.try_llbb(bb) {
1528 Some(llbb) => llbb,
1529 None => return,
1530 };
1531 let bx = &mut Bx::build(self.cx, llbb);
1532 {
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:1532",
"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(1532u32),
::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);
1533 bx.unreachable();
1534 }
1535
1536 fn codegen_terminator(
1537 &mut self,
1538 bx: &mut Bx,
1539 bb: mir::BasicBlock,
1540 terminator: &'tcx mir::Terminator<'tcx>,
1541 ) -> MergingSucc {
1542 {
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:1542",
"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(1542u32),
::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);
1543
1544 let helper = TerminatorCodegenHelper { bb, terminator };
1545
1546 let mergeable_succ = || {
1547 let mut successors = terminator.successors();
1550 if let Some(succ) = successors.next()
1551 && successors.next().is_none()
1552 && let &[succ_pred] = self.mir.basic_blocks.predecessors()[succ].as_slice()
1553 {
1554 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);
1557 true
1558 } else {
1559 false
1560 }
1561 };
1562
1563 self.set_debug_loc(bx, terminator.source_info);
1564 match terminator.kind {
1565 mir::TerminatorKind::UnwindResume => {
1566 self.codegen_resume_terminator(helper, bx);
1567 MergingSucc::False
1568 }
1569
1570 mir::TerminatorKind::UnwindTerminate(reason) => {
1571 self.codegen_terminate_terminator(helper, bx, terminator, reason);
1572 MergingSucc::False
1573 }
1574
1575 mir::TerminatorKind::Goto { target } => {
1576 helper.funclet_br(self, bx, target, mergeable_succ())
1577 }
1578
1579 mir::TerminatorKind::SwitchInt { ref discr, ref targets } => {
1580 self.codegen_switchint_terminator(helper, bx, discr, targets);
1581 MergingSucc::False
1582 }
1583
1584 mir::TerminatorKind::Return => {
1585 self.codegen_return_terminator(bx);
1586 MergingSucc::False
1587 }
1588
1589 mir::TerminatorKind::Unreachable => {
1590 bx.unreachable();
1591 MergingSucc::False
1592 }
1593
1594 mir::TerminatorKind::Drop { place, target, unwind, replace: _, drop } => {
1595 if !drop.is_none() {
{
::core::panicking::panic_fmt(format_args!("Async Drop must be expanded or reset to sync before codegen"));
}
};assert!(
1596 drop.is_none(),
1597 "Async Drop must be expanded or reset to sync before codegen"
1598 );
1599 self.codegen_drop_terminator(
1600 helper,
1601 bx,
1602 &terminator.source_info,
1603 place,
1604 target,
1605 unwind,
1606 mergeable_succ(),
1607 )
1608 }
1609
1610 mir::TerminatorKind::Assert { ref cond, expected, ref msg, target, unwind } => self
1611 .codegen_assert_terminator(
1612 helper,
1613 bx,
1614 terminator,
1615 cond,
1616 expected,
1617 msg,
1618 target,
1619 unwind,
1620 mergeable_succ(),
1621 ),
1622
1623 mir::TerminatorKind::Call {
1624 ref func,
1625 ref args,
1626 destination,
1627 target,
1628 unwind,
1629 call_source: _,
1630 fn_span,
1631 } => self.codegen_call_terminator(
1632 helper,
1633 bx,
1634 terminator,
1635 func,
1636 args,
1637 destination,
1638 target,
1639 unwind,
1640 fn_span,
1641 CallKind::Normal,
1642 mergeable_succ(),
1643 ),
1644 mir::TerminatorKind::TailCall { ref func, ref args, fn_span } => self
1645 .codegen_call_terminator(
1646 helper,
1647 bx,
1648 terminator,
1649 func,
1650 args,
1651 mir::Place::from(mir::RETURN_PLACE),
1652 None,
1653 mir::UnwindAction::Unreachable,
1654 fn_span,
1655 CallKind::Tail,
1656 mergeable_succ(),
1657 ),
1658 mir::TerminatorKind::CoroutineDrop | mir::TerminatorKind::Yield { .. } => {
1659 ::rustc_middle::util::bug::bug_fmt(format_args!("coroutine ops in codegen"))bug!("coroutine ops in codegen")
1660 }
1661 mir::TerminatorKind::FalseEdge { .. } | mir::TerminatorKind::FalseUnwind { .. } => {
1662 ::rustc_middle::util::bug::bug_fmt(format_args!("borrowck false edges in codegen"))bug!("borrowck false edges in codegen")
1663 }
1664
1665 mir::TerminatorKind::InlineAsm {
1666 asm_macro,
1667 template,
1668 ref operands,
1669 options,
1670 line_spans,
1671 ref targets,
1672 unwind,
1673 } => self.codegen_asm_terminator(
1674 helper,
1675 bx,
1676 asm_macro,
1677 terminator,
1678 template,
1679 operands,
1680 options,
1681 line_spans,
1682 targets,
1683 unwind,
1684 self.instance,
1685 mergeable_succ(),
1686 ),
1687 }
1688 }
1689
1690 fn codegen_argument(
1691 &mut self,
1692 bx: &mut Bx,
1693 op: OperandRef<'tcx, Bx::Value>,
1694 by_move: bool,
1695 llargs: &mut Vec<Bx::Value>,
1696 arg: &ArgAbi<'tcx, Ty<'tcx>>,
1697 lifetime_ends_after_call: &mut Vec<(Bx::Value, Size)>,
1698 ) {
1699 match arg.mode {
1700 PassMode::Ignore => return,
1701 PassMode::Cast { pad_i32: true, .. } => {
1702 llargs.push(bx.const_undef(bx.reg_backend_type(&Reg::i32())));
1704 }
1705 PassMode::Pair(..) => match op.val {
1706 Pair(a, b) => {
1707 llargs.push(a);
1708 llargs.push(b);
1709 return;
1710 }
1711 _ => ::rustc_middle::util::bug::bug_fmt(format_args!("codegen_argument: {0:?} invalid for pair argument",
op))bug!("codegen_argument: {:?} invalid for pair argument", op),
1712 },
1713 PassMode::Indirect { attrs: _, meta_attrs: Some(_), on_stack: _ } => match op.val {
1714 Ref(PlaceValue { llval: a, llextra: Some(b), .. }) => {
1715 llargs.push(a);
1716 llargs.push(b);
1717 return;
1718 }
1719 _ => ::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),
1720 },
1721 _ => {}
1722 }
1723
1724 let (mut llval, align, by_ref) = match op.val {
1726 Immediate(_) | Pair(..) => match arg.mode {
1727 PassMode::Indirect { attrs, .. } => {
1728 let required_align = match attrs.pointee_align {
1732 Some(pointee_align) => cmp::max(pointee_align, arg.layout.align.abi),
1733 None => arg.layout.align.abi,
1734 };
1735 let scratch = PlaceValue::alloca(bx, arg.layout.size, required_align);
1736 bx.lifetime_start(scratch.llval, arg.layout.size);
1737 op.store_with_annotation(bx, scratch.with_type(arg.layout));
1738 lifetime_ends_after_call.push((scratch.llval, arg.layout.size));
1739 (scratch.llval, scratch.align, true)
1740 }
1741 PassMode::Cast { .. } => {
1742 let scratch = PlaceRef::alloca(bx, arg.layout);
1743 op.store_with_annotation(bx, scratch);
1744 (scratch.val.llval, scratch.val.align, true)
1745 }
1746 PassMode::Direct(_) => (op.immediate(), arg.layout.align.abi, false),
1747 PassMode::Ignore | PassMode::Pair(..) => {
::core::panicking::panic_fmt(format_args!("internal error: entered unreachable code: {0}",
format_args!("handled above")));
}unreachable!("handled above"),
1748 },
1749 Ref(op_place_val) => match arg.mode {
1750 PassMode::Indirect { attrs, on_stack, .. } => {
1751 let required_align = match attrs.pointee_align {
1755 Some(pointee_align) => cmp::max(pointee_align, arg.layout.align.abi),
1756 None => arg.layout.align.abi,
1757 };
1758 if op_place_val.align < required_align || (!on_stack && !by_move) {
1760 let scratch = PlaceValue::alloca(bx, arg.layout.size, required_align);
1761 bx.lifetime_start(scratch.llval, arg.layout.size);
1762 op.store_with_annotation(bx, scratch.with_type(arg.layout));
1763 lifetime_ends_after_call.push((scratch.llval, arg.layout.size));
1764 (scratch.llval, scratch.align, true)
1765 } else {
1766 (op_place_val.llval, op_place_val.align, true)
1767 }
1768 }
1769 _ => (op_place_val.llval, op_place_val.align, true),
1770 },
1771 ZeroSized => match arg.mode {
1772 PassMode::Indirect { on_stack, .. } => {
1773 if on_stack {
1774 ::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:?}");
1777 }
1778 let scratch = PlaceRef::alloca(bx, arg.layout);
1782 (scratch.val.llval, scratch.val.align, true)
1783 }
1784 _ => ::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:?}"),
1785 },
1786 };
1787
1788 if by_ref && !arg.is_indirect() {
1789 if let PassMode::Cast { cast, pad_i32: _ } = &arg.mode {
1791 let scratch_size = cast.size(bx);
1795 let scratch_align = cast.align(bx);
1796 let copy_bytes = cmp::min(cast.unaligned_size(bx).bytes(), arg.layout.size.bytes());
1803 let llscratch = bx.alloca(scratch_size, scratch_align);
1805 bx.lifetime_start(llscratch, scratch_size);
1806 bx.memcpy(
1808 llscratch,
1809 scratch_align,
1810 llval,
1811 align,
1812 bx.const_usize(copy_bytes),
1813 MemFlags::empty(),
1814 None,
1815 );
1816 llval = load_cast(bx, cast, llscratch, scratch_align);
1818 bx.lifetime_end(llscratch, scratch_size);
1819 } else {
1820 llval = bx.load(bx.backend_type(arg.layout), llval, align);
1826 if let BackendRepr::Scalar(scalar) = arg.layout.backend_repr {
1827 if scalar.is_bool() {
1828 bx.range_metadata(llval, WrappingRange { start: 0, end: 1 });
1829 }
1830 llval = bx.to_immediate_scalar(llval, scalar);
1832 }
1833 }
1834 }
1835
1836 llargs.push(llval);
1837 }
1838
1839 fn codegen_arguments_untupled(
1840 &mut self,
1841 bx: &mut Bx,
1842 operand: &mir::Operand<'tcx>,
1843 llargs: &mut Vec<Bx::Value>,
1844 args: &[ArgAbi<'tcx, Ty<'tcx>>],
1845 lifetime_ends_after_call: &mut Vec<(Bx::Value, Size)>,
1846 ) -> usize {
1847 let tuple = self.codegen_operand(bx, operand);
1848 let by_move = #[allow(non_exhaustive_omitted_patterns)] match operand {
mir::Operand::Move(_) => true,
_ => false,
}matches!(operand, mir::Operand::Move(_));
1849
1850 if let Ref(place_val) = tuple.val {
1852 if place_val.llextra.is_some() {
1853 ::rustc_middle::util::bug::bug_fmt(format_args!("closure arguments must be sized"));bug!("closure arguments must be sized");
1854 }
1855 let tuple_ptr = place_val.with_type(tuple.layout);
1856 for i in 0..tuple.layout.fields.count() {
1857 let field_ptr = tuple_ptr.project_field(bx, i);
1858 let field = bx.load_operand(field_ptr);
1859 self.codegen_argument(
1860 bx,
1861 field,
1862 by_move,
1863 llargs,
1864 &args[i],
1865 lifetime_ends_after_call,
1866 );
1867 }
1868 } else {
1869 for i in 0..tuple.layout.fields.count() {
1871 let op = tuple.extract_field(self, bx, i);
1872 self.codegen_argument(bx, op, by_move, llargs, &args[i], lifetime_ends_after_call);
1873 }
1874 }
1875 tuple.layout.fields.count()
1876 }
1877
1878 pub(super) fn get_caller_location(
1879 &mut self,
1880 bx: &mut Bx,
1881 source_info: mir::SourceInfo,
1882 ) -> OperandRef<'tcx, Bx::Value> {
1883 self.mir.caller_location_span(source_info, self.caller_location, bx.tcx(), |span: Span| {
1884 let const_loc = bx.tcx().span_as_caller_location(span);
1885 OperandRef::from_const(bx, const_loc, bx.tcx().caller_location_ty())
1886 })
1887 }
1888
1889 fn get_personality_slot(&mut self, bx: &mut Bx) -> PlaceRef<'tcx, Bx::Value> {
1890 let cx = bx.cx();
1891 if let Some(slot) = self.personality_slot {
1892 slot
1893 } else {
1894 let layout = cx.layout_of(Ty::new_tup(
1895 cx.tcx(),
1896 &[Ty::new_mut_ptr(cx.tcx(), cx.tcx().types.u8), cx.tcx().types.i32],
1897 ));
1898 let slot = PlaceRef::alloca(bx, layout);
1899 self.personality_slot = Some(slot);
1900 slot
1901 }
1902 }
1903
1904 fn landing_pad_for(&mut self, bb: mir::BasicBlock) -> Bx::BasicBlock {
1907 if let Some(landing_pad) = self.landing_pads[bb] {
1908 return landing_pad;
1909 }
1910
1911 let landing_pad = self.landing_pad_for_uncached(bb);
1912 self.landing_pads[bb] = Some(landing_pad);
1913 landing_pad
1914 }
1915
1916 fn landing_pad_for_uncached(&mut self, bb: mir::BasicBlock) -> Bx::BasicBlock {
1918 let llbb = self.llbb(bb);
1919 if base::wants_new_eh_instructions(self.cx.sess()) {
1920 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:?}"));
1921 let mut cleanup_bx = Bx::build(self.cx, cleanup_bb);
1922 let funclet = cleanup_bx.cleanup_pad(None, &[]);
1923 cleanup_bx.br(llbb);
1924 self.funclets[bb] = Some(funclet);
1925 cleanup_bb
1926 } else {
1927 let cleanup_llbb = Bx::append_block(self.cx, self.llfn, "cleanup");
1928 let mut cleanup_bx = Bx::build(self.cx, cleanup_llbb);
1929
1930 let llpersonality = self.cx.eh_personality();
1931 let (exn0, exn1) = cleanup_bx.cleanup_landing_pad(llpersonality);
1932
1933 let slot = self.get_personality_slot(&mut cleanup_bx);
1934 slot.storage_live(&mut cleanup_bx);
1935 Pair(exn0, exn1).store(&mut cleanup_bx, slot);
1936
1937 cleanup_bx.br(llbb);
1938 cleanup_llbb
1939 }
1940 }
1941
1942 fn unreachable_block(&mut self) -> Bx::BasicBlock {
1943 self.unreachable_block.unwrap_or_else(|| {
1944 let llbb = Bx::append_block(self.cx, self.llfn, "unreachable");
1945 let mut bx = Bx::build(self.cx, llbb);
1946 bx.unreachable();
1947 self.unreachable_block = Some(llbb);
1948 llbb
1949 })
1950 }
1951
1952 fn terminate_block(
1953 &mut self,
1954 reason: UnwindTerminateReason,
1955 outer_catchpad_bb: Option<mir::BasicBlock>,
1956 ) -> Bx::BasicBlock {
1957 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!(
1962 outer_catchpad_bb.is_some()
1963 == (base::wants_wasm_eh(self.cx.tcx().sess)
1964 && reason == UnwindTerminateReason::InCleanup)
1965 );
1966
1967 let mut cache_bb = mir::START_BLOCK;
1970 if let Some(outer_bb) = outer_catchpad_bb {
1973 let cleanup_kinds =
1974 self.cleanup_kinds.as_ref().expect("cleanup_kinds required for funclets");
1975 cache_bb = cleanup_kinds[outer_bb]
1976 .funclet_bb(outer_bb)
1977 .expect("funclet_bb should be in a funclet");
1978
1979 if self.funclets[cache_bb].is_none() {
1981 self.landing_pad_for(cache_bb);
1982 }
1983 }
1984 if let Some((cached_bb, cached_reason)) = self.terminate_blocks[cache_bb]
1985 && reason == cached_reason
1986 {
1987 return cached_bb;
1988 }
1989
1990 let funclet;
1991 let llbb;
1992 let mut bx;
1993 if base::wants_new_eh_instructions(self.cx.sess()) {
1994 llbb = Bx::append_block(self.cx, self.llfn, "cs_terminate");
2034
2035 let mut cs_bx = Bx::build(self.cx, llbb);
2036
2037 let mut outer_cleanuppad = None;
2041 if outer_catchpad_bb.is_some() {
2042 let outer_funclet = self.funclets[cache_bb]
2044 .as_ref()
2045 .expect("landing_pad_for didn't create funclet");
2046 outer_cleanuppad = Some(cs_bx.get_funclet_cleanuppad(outer_funclet));
2047 }
2048 let cp_llbb = Bx::append_block(self.cx, self.llfn, "cp_terminate");
2049 let cs = cs_bx.catch_switch(outer_cleanuppad, None, &[cp_llbb]);
2050 drop(cs_bx);
2051
2052 bx = Bx::build(self.cx, cp_llbb);
2053 let null =
2054 bx.const_null(bx.type_ptr_ext(bx.cx().data_layout().instruction_address_space));
2055
2056 let args = if base::wants_msvc_seh(self.cx.sess()) {
2060 let adjectives = bx.const_i32(0x40);
2067 &[null, adjectives, null] as &[_]
2068 } else {
2069 &[null] as &[_]
2075 };
2076
2077 funclet = Some(bx.catch_pad(cs, args));
2078 } else {
2084 llbb = Bx::append_block(self.cx, self.llfn, "terminate");
2085 bx = Bx::build(self.cx, llbb);
2086
2087 let llpersonality = self.cx.eh_personality();
2088 bx.filter_landing_pad(llpersonality);
2089
2090 funclet = None;
2091 }
2092
2093 self.set_debug_loc(&mut bx, mir::SourceInfo::outermost(self.mir.span));
2094
2095 let (fn_abi, fn_ptr, instance) =
2096 common::build_langcall(&bx, self.mir.span, reason.lang_item());
2097 if is_call_from_compiler_builtins_to_upstream_monomorphization(bx.tcx(), instance) {
2098 bx.abort();
2099 } else {
2100 let fn_ty = bx.fn_decl_backend_type(fn_abi);
2101
2102 let llret = bx.call(fn_ty, None, Some(fn_abi), fn_ptr, &[], funclet.as_ref(), None);
2103 bx.apply_attrs_to_cleanup_callsite(llret);
2104 }
2105
2106 bx.unreachable();
2107
2108 self.terminate_blocks[cache_bb] = Some((llbb, reason));
2109 llbb
2110 }
2111
2112 pub fn llbb(&mut self, bb: mir::BasicBlock) -> Bx::BasicBlock {
2117 self.try_llbb(bb).unwrap()
2118 }
2119
2120 pub(crate) fn try_llbb(&mut self, bb: mir::BasicBlock) -> Option<Bx::BasicBlock> {
2122 match self.cached_llbbs[bb] {
2123 CachedLlbb::None => {
2124 let llbb = Bx::append_block(self.cx, self.llfn, &::alloc::__export::must_use({
::alloc::fmt::format(format_args!("{0:?}", bb))
})format!("{bb:?}"));
2125 self.cached_llbbs[bb] = CachedLlbb::Some(llbb);
2126 Some(llbb)
2127 }
2128 CachedLlbb::Some(llbb) => Some(llbb),
2129 CachedLlbb::Skip => None,
2130 }
2131 }
2132
2133 fn make_return_dest(
2134 &mut self,
2135 bx: &mut Bx,
2136 dest: mir::Place<'tcx>,
2137 fn_ret: &ArgAbi<'tcx, Ty<'tcx>>,
2138 llargs: &mut Vec<Bx::Value>,
2139 ) -> ReturnDest<'tcx, Bx::Value> {
2140 if fn_ret.is_ignore() {
2142 return ReturnDest::Nothing;
2143 }
2144 let dest = if let Some(index) = dest.as_local() {
2145 match self.locals[index] {
2146 LocalRef::Place(dest) => dest,
2147 LocalRef::UnsizedPlace(_) => ::rustc_middle::util::bug::bug_fmt(format_args!("return type must be sized"))bug!("return type must be sized"),
2148 LocalRef::PendingOperand => {
2149 return if fn_ret.is_indirect() {
2152 let tmp = PlaceRef::alloca(bx, fn_ret.layout);
2155 tmp.storage_live(bx);
2156 llargs.push(tmp.val.llval);
2157 ReturnDest::IndirectOperand(tmp, index)
2158 } else {
2159 ReturnDest::DirectOperand(index)
2160 };
2161 }
2162 LocalRef::Operand(_) => {
2163 ::rustc_middle::util::bug::bug_fmt(format_args!("place local already assigned to"));bug!("place local already assigned to");
2164 }
2165 }
2166 } else {
2167 self.codegen_place(bx, dest.as_ref())
2168 };
2169 if fn_ret.is_indirect() {
2170 if dest.val.align < dest.layout.align.abi {
2171 ::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");
2178 }
2179 llargs.push(dest.val.llval);
2180 ReturnDest::Nothing
2181 } else {
2182 ReturnDest::Store(dest)
2183 }
2184 }
2185
2186 fn store_return(
2188 &mut self,
2189 bx: &mut Bx,
2190 dest: ReturnDest<'tcx, Bx::Value>,
2191 ret_abi: &ArgAbi<'tcx, Ty<'tcx>>,
2192 llval: Bx::Value,
2193 ) {
2194 use self::ReturnDest::*;
2195 let retags_enabled = bx.tcx().sess.opts.unstable_opts.codegen_emit_retag.is_some();
2196 match dest {
2197 Nothing => (),
2198 Store(dst) => {
2199 bx.store_arg(ret_abi, llval, dst);
2200 if retags_enabled {
2201 self.codegen_retag_place(bx, dst, false);
2202 }
2203 }
2204 IndirectOperand(tmp, index) => {
2205 let mut op = bx.load_operand(tmp);
2206 tmp.storage_dead(bx);
2207 if retags_enabled {
2208 op = self.codegen_retag_operand(bx, op, false);
2209 }
2210 self.overwrite_local(index, LocalRef::Operand(op));
2211 self.debug_introduce_local(bx, index);
2212 }
2213 DirectOperand(index) => {
2214 let mut op = if let PassMode::Cast { .. } = ret_abi.mode {
2216 let tmp = PlaceRef::alloca(bx, ret_abi.layout);
2217 tmp.storage_live(bx);
2218 bx.store_arg(ret_abi, llval, tmp);
2219 let op = bx.load_operand(tmp);
2220 tmp.storage_dead(bx);
2221 op
2222 } else {
2223 OperandRef::from_immediate_or_packed_pair(bx, llval, ret_abi.layout)
2224 };
2225 if retags_enabled {
2226 op = self.codegen_retag_operand(bx, op, false);
2227 }
2228 self.overwrite_local(index, LocalRef::Operand(op));
2229 self.debug_introduce_local(bx, index);
2230 }
2231 }
2232 }
2233}
2234
2235enum ReturnDest<'tcx, V> {
2236 Nothing,
2238 Store(PlaceRef<'tcx, V>),
2240 IndirectOperand(PlaceRef<'tcx, V>, mir::Local),
2242 DirectOperand(mir::Local),
2244}
2245
2246fn load_cast<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
2247 bx: &mut Bx,
2248 cast: &CastTarget,
2249 ptr: Bx::Value,
2250 align: Align,
2251) -> Bx::Value {
2252 let cast_ty = bx.cast_backend_type(cast);
2253 if let Some(offset_from_start) = cast.rest_offset {
2254 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);
2255 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);
2256 let first_ty = bx.reg_backend_type(&cast.prefix[0]);
2257 let second_ty = bx.reg_backend_type(&cast.rest.unit);
2258 let first = bx.load(first_ty, ptr, align);
2259 let second_ptr = bx.inbounds_ptradd(ptr, bx.const_usize(offset_from_start.bytes()));
2260 let second = bx.load(second_ty, second_ptr, align.restrict_for_offset(offset_from_start));
2261 let res = bx.cx().const_poison(cast_ty);
2262 let res = bx.insert_value(res, first, 0);
2263 bx.insert_value(res, second, 1)
2264 } else {
2265 bx.load(cast_ty, ptr, align)
2266 }
2267}
2268
2269pub fn store_cast<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
2270 bx: &mut Bx,
2271 cast: &CastTarget,
2272 value: Bx::Value,
2273 ptr: Bx::Value,
2274 align: Align,
2275) {
2276 if let Some(offset_from_start) = cast.rest_offset {
2277 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);
2278 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);
2279 let first = bx.extract_value(value, 0);
2280 let second = bx.extract_value(value, 1);
2281 bx.store(first, ptr, align);
2282 let second_ptr = bx.inbounds_ptradd(ptr, bx.const_usize(offset_from_start.bytes()));
2283 bx.store(second, second_ptr, align.restrict_for_offset(offset_from_start));
2284 } else {
2285 bx.store(value, ptr, align);
2286 };
2287}