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 MergingSucc::False
269 } else {
270 let llret = bx.call(
271 fn_ty,
272 caller_attrs,
273 Some(fn_abi),
274 fn_ptr,
275 llargs,
276 self.funclet(fx),
277 instance,
278 );
279 if fx.mir[self.bb].is_cleanup {
280 bx.apply_attrs_to_cleanup_callsite(llret);
281 }
282
283 if let Some((ret_dest, target)) = destination {
284 for &(tmp, size) in lifetime_ends_after_call {
285 bx.lifetime_end(tmp, size);
286 }
287 fx.store_return(bx, ret_dest, &fn_abi.ret, llret);
288 self.funclet_br(fx, bx, target, mergeable_succ)
289 } else {
290 bx.unreachable();
291 MergingSucc::False
292 }
293 }
294 }
295
296 fn do_inlineasm<Bx: BuilderMethods<'a, 'tcx>>(
298 &self,
299 fx: &mut FunctionCx<'a, 'tcx, Bx>,
300 bx: &mut Bx,
301 template: &[InlineAsmTemplatePiece],
302 operands: &[InlineAsmOperandRef<'tcx, Bx>],
303 options: InlineAsmOptions,
304 line_spans: &[Span],
305 destination: Option<mir::BasicBlock>,
306 unwind: mir::UnwindAction,
307 instance: Instance<'_>,
308 mergeable_succ: bool,
309 ) -> MergingSucc {
310 let unwind_target = match unwind {
311 mir::UnwindAction::Cleanup(cleanup) => Some(self.llbb_with_cleanup(fx, cleanup)),
312 mir::UnwindAction::Terminate(reason) => Some(fx.terminate_block(reason, None)),
313 mir::UnwindAction::Continue => None,
314 mir::UnwindAction::Unreachable => None,
315 };
316
317 if operands.iter().any(|x| #[allow(non_exhaustive_omitted_patterns)] match x {
InlineAsmOperandRef::Label { .. } => true,
_ => false,
}matches!(x, InlineAsmOperandRef::Label { .. })) {
318 if !unwind_target.is_none() {
::core::panicking::panic("assertion failed: unwind_target.is_none()")
};assert!(unwind_target.is_none());
319 let ret_llbb = if let Some(target) = destination {
320 self.llbb_with_cleanup(fx, target)
321 } else {
322 fx.unreachable_block()
323 };
324
325 bx.codegen_inline_asm(
326 template,
327 operands,
328 options,
329 line_spans,
330 instance,
331 Some(ret_llbb),
332 None,
333 );
334 MergingSucc::False
335 } else if let Some(cleanup) = unwind_target {
336 let ret_llbb = if let Some(target) = destination {
337 self.llbb_with_cleanup(fx, target)
338 } else {
339 fx.unreachable_block()
340 };
341
342 bx.codegen_inline_asm(
343 template,
344 operands,
345 options,
346 line_spans,
347 instance,
348 Some(ret_llbb),
349 Some((cleanup, self.funclet(fx))),
350 );
351 MergingSucc::False
352 } else {
353 bx.codegen_inline_asm(template, operands, options, line_spans, instance, None, None);
354
355 if let Some(target) = destination {
356 self.funclet_br(fx, bx, target, mergeable_succ)
357 } else {
358 bx.unreachable();
359 MergingSucc::False
360 }
361 }
362 }
363}
364
365impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
367 fn codegen_resume_terminator(&mut self, helper: TerminatorCodegenHelper<'tcx>, bx: &mut Bx) {
369 if let Some(funclet) = helper.funclet(self) {
370 bx.cleanup_ret(funclet, None);
371 } else {
372 let slot = self.get_personality_slot(bx);
373 let exn0 = slot.project_field(bx, 0);
374 let exn0 = bx.load_operand(exn0).immediate();
375 let exn1 = slot.project_field(bx, 1);
376 let exn1 = bx.load_operand(exn1).immediate();
377 slot.storage_dead(bx);
378
379 bx.resume(exn0, exn1);
380 }
381 }
382
383 fn codegen_switchint_terminator(
384 &mut self,
385 helper: TerminatorCodegenHelper<'tcx>,
386 bx: &mut Bx,
387 discr: &mir::Operand<'tcx>,
388 targets: &SwitchTargets,
389 ) {
390 let discr = self.codegen_operand(bx, discr);
391 let discr_value = discr.immediate();
392 let switch_ty = discr.layout.ty;
393 if let Some(const_discr) = bx.const_to_opt_u128(discr_value, false) {
395 let target = targets.target_for_value(const_discr);
396 bx.br(helper.llbb_with_cleanup(self, target));
397 return;
398 };
399
400 let mut target_iter = targets.iter();
401 if target_iter.len() == 1 {
402 let (test_value, target) = target_iter.next().unwrap();
405 let otherwise = targets.otherwise();
406 let lltarget = helper.llbb_with_cleanup(self, target);
407 let llotherwise = helper.llbb_with_cleanup(self, otherwise);
408 let target_cold = self.cold_blocks[target];
409 let otherwise_cold = self.cold_blocks[otherwise];
410 let expect = if target_cold == otherwise_cold { None } else { Some(otherwise_cold) };
414 if switch_ty == bx.tcx().types.bool {
415 match test_value {
417 0 => {
418 let expect = expect.map(|e| !e);
419 bx.cond_br_with_expect(discr_value, llotherwise, lltarget, expect);
420 }
421 1 => {
422 bx.cond_br_with_expect(discr_value, lltarget, llotherwise, expect);
423 }
424 _ => ::rustc_middle::util::bug::bug_fmt(format_args!("impossible case reached"))bug!(),
425 }
426 } else {
427 let switch_llty = bx.immediate_backend_type(bx.layout_of(switch_ty));
428 let llval = bx.const_uint_big(switch_llty, test_value);
429 let cmp = bx.icmp(IntPredicate::IntEQ, discr_value, llval);
430 bx.cond_br_with_expect(cmp, lltarget, llotherwise, expect);
431 }
432 } else if target_iter.len() == 2
433 && self.mir[targets.otherwise()].is_empty_unreachable()
434 && targets.all_values().contains(&Pu128(0))
435 && targets.all_values().contains(&Pu128(1))
436 {
437 let true_bb = targets.target_for_value(1);
441 let false_bb = targets.target_for_value(0);
442 let true_ll = helper.llbb_with_cleanup(self, true_bb);
443 let false_ll = helper.llbb_with_cleanup(self, false_bb);
444
445 let expected_cond_value = if self.cx.sess().opts.optimize == OptLevel::No {
446 None
447 } else {
448 match (self.cold_blocks[true_bb], self.cold_blocks[false_bb]) {
449 (true, true) | (false, false) => None,
451 (true, false) => Some(false),
453 (false, true) => Some(true),
454 }
455 };
456
457 let bool_ty = bx.tcx().types.bool;
458 let cond = if switch_ty == bool_ty {
459 discr_value
460 } else {
461 let bool_llty = bx.immediate_backend_type(bx.layout_of(bool_ty));
462 bx.unchecked_utrunc(discr_value, bool_llty)
463 };
464 bx.cond_br_with_expect(cond, true_ll, false_ll, expected_cond_value);
465 } else if self.cx.sess().opts.optimize == OptLevel::No
466 && target_iter.len() == 2
467 && self.mir[targets.otherwise()].is_empty_unreachable()
468 {
469 let (test_value1, target1) = target_iter.next().unwrap();
482 let (_test_value2, target2) = target_iter.next().unwrap();
483 let ll1 = helper.llbb_with_cleanup(self, target1);
484 let ll2 = helper.llbb_with_cleanup(self, target2);
485 let switch_llty = bx.immediate_backend_type(bx.layout_of(switch_ty));
486 let llval = bx.const_uint_big(switch_llty, test_value1);
487 let cmp = bx.icmp(IntPredicate::IntEQ, discr_value, llval);
488 bx.cond_br(cmp, ll1, ll2);
489 } else {
490 let otherwise = targets.otherwise();
491 let otherwise_cold = self.cold_blocks[otherwise];
492 let otherwise_unreachable = self.mir[otherwise].is_empty_unreachable();
493 let cold_count = targets.iter().filter(|(_, target)| self.cold_blocks[*target]).count();
494 let none_cold = cold_count == 0;
495 let all_cold = cold_count == targets.iter().len();
496 if (none_cold && (!otherwise_cold || otherwise_unreachable))
497 || (all_cold && (otherwise_cold || otherwise_unreachable))
498 {
499 bx.switch(
502 discr_value,
503 helper.llbb_with_cleanup(self, targets.otherwise()),
504 target_iter
505 .map(|(value, target)| (value, helper.llbb_with_cleanup(self, target))),
506 );
507 } else {
508 bx.switch_with_weights(
510 discr_value,
511 helper.llbb_with_cleanup(self, targets.otherwise()),
512 otherwise_cold,
513 target_iter.map(|(value, target)| {
514 (value, helper.llbb_with_cleanup(self, target), self.cold_blocks[target])
515 }),
516 );
517 }
518 }
519 }
520
521 fn codegen_return_terminator(&mut self, bx: &mut Bx) {
522 if self.fn_abi.c_variadic {
524 let va_list_arg_idx = self.fn_abi.args.len();
526 match self.locals[mir::Local::arg(va_list_arg_idx)] {
527 LocalRef::Place(va_list) => {
528 bx.va_end(va_list.val.llval);
529
530 bx.lifetime_end(va_list.val.llval, va_list.layout.size);
532 }
533 _ => ::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"),
534 }
535 }
536 if self.fn_abi.ret.layout.is_uninhabited() {
537 bx.abort();
542 bx.unreachable();
545 return;
546 }
547 let llval = match &self.fn_abi.ret.mode {
548 PassMode::Ignore | PassMode::Indirect { .. } => {
549 bx.ret_void();
550 return;
551 }
552
553 PassMode::Direct(_) | PassMode::Pair(..) => {
554 let op = self.codegen_consume(bx, mir::Place::return_place().as_ref());
555 if let Ref(place_val) = op.val {
556 bx.load_from_place(bx.backend_type(op.layout), place_val)
557 } else {
558 op.immediate_or_packed_pair(bx)
559 }
560 }
561
562 PassMode::Cast { cast: cast_ty, pad_i32: _ } => {
563 let op = match self.locals[mir::RETURN_PLACE] {
564 LocalRef::Operand(op) => op,
565 LocalRef::PendingOperand => ::rustc_middle::util::bug::bug_fmt(format_args!("use of return before def"))bug!("use of return before def"),
566 LocalRef::Place(cg_place) => OperandRef {
567 val: Ref(cg_place.val),
568 layout: cg_place.layout,
569 move_annotation: None,
570 },
571 LocalRef::UnsizedPlace(_) => ::rustc_middle::util::bug::bug_fmt(format_args!("return type must be sized"))bug!("return type must be sized"),
572 };
573 let llslot = match op.val {
574 Immediate(_) | Pair(..) => {
575 let scratch = PlaceRef::alloca(bx, self.fn_abi.ret.layout);
576 op.val.store(bx, scratch);
577 scratch.val.llval
578 }
579 Ref(place_val) => {
580 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!(
581 place_val.align, op.layout.align.abi,
582 "return place is unaligned!"
583 );
584 place_val.llval
585 }
586 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"),
587 };
588 load_cast(bx, cast_ty, llslot, self.fn_abi.ret.layout.align.abi)
589 }
590 };
591 bx.ret(llval);
592 }
593
594 #[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(594u32),
::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:643",
"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(643u32),
::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:644",
"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(644u32),
::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:645",
"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(645u32),
::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))]
595 fn codegen_drop_terminator(
596 &mut self,
597 helper: TerminatorCodegenHelper<'tcx>,
598 bx: &mut Bx,
599 source_info: &mir::SourceInfo,
600 location: mir::Place<'tcx>,
601 target: mir::BasicBlock,
602 unwind: mir::UnwindAction,
603 mergeable_succ: bool,
604 ) -> MergingSucc {
605 let ty = location.ty(self.mir, bx.tcx()).ty;
606 let ty = self.monomorphize(ty);
607 let drop_fn = Instance::resolve_drop_glue(bx.tcx(), ty);
608
609 if let ty::InstanceKind::DropGlue(_, None) = drop_fn.def {
610 return helper.funclet_br(self, bx, target, mergeable_succ);
612 }
613
614 let place = self.codegen_place(bx, location.as_ref());
615 let (args1, args2);
616 let mut args = if let Some(llextra) = place.val.llextra {
617 args2 = [place.val.llval, llextra];
618 &args2[..]
619 } else {
620 args1 = [place.val.llval];
621 &args1[..]
622 };
623 let (maybe_null, drop_fn, fn_abi, drop_instance) = match ty.kind() {
624 ty::Dynamic(_, _) => {
627 let virtual_drop = Instance {
640 def: ty::InstanceKind::Virtual(drop_fn.def_id(), 0), args: drop_fn.args,
642 };
643 debug!("ty = {:?}", ty);
644 debug!("drop_fn = {:?}", drop_fn);
645 debug!("args = {:?}", args);
646 let fn_abi = bx.fn_abi_of_instance(virtual_drop, ty::List::empty());
647 let vtable = args[1];
648 args = &args[..1];
650 (
651 true,
652 meth::VirtualIndex::from_index(ty::COMMON_VTABLE_ENTRIES_DROPINPLACE)
653 .get_optional_fn(bx, vtable, ty, fn_abi),
654 fn_abi,
655 virtual_drop,
656 )
657 }
658 _ => (
659 false,
660 bx.get_fn_addr(drop_fn),
661 bx.fn_abi_of_instance(drop_fn, ty::List::empty()),
662 drop_fn,
663 ),
664 };
665
666 if maybe_null {
669 let is_not_null = bx.append_sibling_block("is_not_null");
670 let llty = bx.fn_ptr_backend_type(fn_abi);
671 let null = bx.const_null(llty);
672 let non_null =
673 bx.icmp(base::bin_op_to_icmp_predicate(mir::BinOp::Ne, false), drop_fn, null);
674 bx.cond_br(non_null, is_not_null, helper.llbb_with_cleanup(self, target));
675 bx.switch_to_block(is_not_null);
676 self.set_debug_loc(bx, *source_info);
677 }
678
679 helper.do_call(
680 self,
681 bx,
682 fn_abi,
683 drop_fn,
684 args,
685 Some((ReturnDest::Nothing, target)),
686 unwind,
687 &[],
688 Some(drop_instance),
689 CallKind::Normal,
690 !maybe_null && mergeable_succ,
691 )
692 }
693
694 fn codegen_assert_terminator(
695 &mut self,
696 helper: TerminatorCodegenHelper<'tcx>,
697 bx: &mut Bx,
698 terminator: &mir::Terminator<'tcx>,
699 cond: &mir::Operand<'tcx>,
700 expected: bool,
701 msg: &mir::AssertMessage<'tcx>,
702 target: mir::BasicBlock,
703 unwind: mir::UnwindAction,
704 mergeable_succ: bool,
705 ) -> MergingSucc {
706 let span = terminator.source_info.span;
707 let cond = self.codegen_operand(bx, cond).immediate();
708 let mut const_cond = bx.const_to_opt_u128(cond, false).map(|c| c == 1);
709
710 if !bx.sess().overflow_checks() && msg.is_optional_overflow_check() {
715 const_cond = Some(expected);
716 }
717
718 if const_cond == Some(expected) {
720 return helper.funclet_br(self, bx, target, mergeable_succ);
721 }
722
723 let lltarget = helper.llbb_with_cleanup(self, target);
728 let panic_block = bx.append_sibling_block("panic");
729 if expected {
730 bx.cond_br(cond, lltarget, panic_block);
731 } else {
732 bx.cond_br(cond, panic_block, lltarget);
733 }
734
735 bx.switch_to_block(panic_block);
737 self.set_debug_loc(bx, terminator.source_info);
738
739 let location = self.get_caller_location(bx, terminator.source_info).immediate();
741
742 let (lang_item, args) = match msg {
744 AssertKind::BoundsCheck { len, index } => {
745 let len = self.codegen_operand(bx, len).immediate();
746 let index = self.codegen_operand(bx, index).immediate();
747 (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])
750 }
751 AssertKind::MisalignedPointerDereference { required, found } => {
752 let required = self.codegen_operand(bx, required).immediate();
753 let found = self.codegen_operand(bx, found).immediate();
754 (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])
757 }
758 AssertKind::NullPointerDereference => {
759 (LangItem::PanicNullPointerDereference, ::alloc::boxed::box_assume_init_into_vec_unsafe(::alloc::intrinsics::write_box_via_move(::alloc::boxed::Box::new_uninit(),
[location]))vec![location])
762 }
763 AssertKind::InvalidEnumConstruction(source) => {
764 let source = self.codegen_operand(bx, source).immediate();
765 (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])
768 }
769 _ => {
770 (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])
772 }
773 };
774
775 let (fn_abi, llfn, instance) = common::build_langcall(bx, span, lang_item);
776
777 let merging_succ = helper.do_call(
779 self,
780 bx,
781 fn_abi,
782 llfn,
783 &args,
784 None,
785 unwind,
786 &[],
787 Some(instance),
788 CallKind::Normal,
789 false,
790 );
791 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);
792 MergingSucc::False
793 }
794
795 fn codegen_terminate_terminator(
796 &mut self,
797 helper: TerminatorCodegenHelper<'tcx>,
798 bx: &mut Bx,
799 terminator: &mir::Terminator<'tcx>,
800 reason: UnwindTerminateReason,
801 ) {
802 let span = terminator.source_info.span;
803 self.set_debug_loc(bx, terminator.source_info);
804
805 let (fn_abi, llfn, instance) = common::build_langcall(bx, span, reason.lang_item());
807
808 let merging_succ = helper.do_call(
810 self,
811 bx,
812 fn_abi,
813 llfn,
814 &[],
815 None,
816 mir::UnwindAction::Unreachable,
817 &[],
818 Some(instance),
819 CallKind::Normal,
820 false,
821 );
822 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);
823 }
824
825 fn codegen_panic_intrinsic(
827 &mut self,
828 helper: &TerminatorCodegenHelper<'tcx>,
829 bx: &mut Bx,
830 intrinsic: ty::IntrinsicDef,
831 instance: Instance<'tcx>,
832 source_info: mir::SourceInfo,
833 target: Option<mir::BasicBlock>,
834 unwind: mir::UnwindAction,
835 mergeable_succ: bool,
836 ) -> Option<MergingSucc> {
837 let Some(requirement) = ValidityRequirement::from_intrinsic(intrinsic.name) else {
841 return None;
842 };
843
844 let ty = instance.args.type_at(0);
845
846 let is_valid = bx
847 .tcx()
848 .check_validity_requirement((requirement, bx.typing_env().as_query_input(ty)))
849 .expect("expect to have layout during codegen");
850
851 if is_valid {
852 let target = target.unwrap();
854 return Some(helper.funclet_br(self, bx, target, mergeable_succ));
855 }
856
857 let layout = bx.layout_of(ty);
858
859 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!({
860 with_no_trimmed_paths!({
861 if layout.is_uninhabited() {
862 format!("attempted to instantiate uninhabited type `{ty}`")
864 } else if requirement == ValidityRequirement::Zero {
865 format!("attempted to zero-initialize type `{ty}`, which is invalid")
866 } else {
867 format!("attempted to leave type `{ty}` uninitialized, which is invalid")
868 }
869 })
870 });
871 let msg = bx.const_str(&msg_str);
872
873 let (fn_abi, llfn, instance) =
875 common::build_langcall(bx, source_info.span, LangItem::PanicNounwind);
876
877 Some(helper.do_call(
879 self,
880 bx,
881 fn_abi,
882 llfn,
883 &[msg.0, msg.1],
884 target.as_ref().map(|bb| (ReturnDest::Nothing, *bb)),
885 unwind,
886 &[],
887 Some(instance),
888 CallKind::Normal,
889 mergeable_succ,
890 ))
891 }
892
893 fn codegen_call_terminator(
894 &mut self,
895 helper: TerminatorCodegenHelper<'tcx>,
896 bx: &mut Bx,
897 terminator: &mir::Terminator<'tcx>,
898 func: &mir::Operand<'tcx>,
899 args: &[Spanned<mir::Operand<'tcx>>],
900 destination: mir::Place<'tcx>,
901 target: Option<mir::BasicBlock>,
902 unwind: mir::UnwindAction,
903 fn_span: Span,
904 kind: CallKind,
905 mergeable_succ: bool,
906 ) -> MergingSucc {
907 let source_info = mir::SourceInfo { span: fn_span, ..terminator.source_info };
908
909 let callee = self.codegen_operand(bx, func);
911
912 let (instance, mut llfn) = match *callee.layout.ty.kind() {
913 ty::FnDef(def_id, generic_args) => {
914 let instance = ty::Instance::expect_resolve(
915 bx.tcx(),
916 bx.typing_env(),
917 def_id,
918 generic_args,
919 fn_span,
920 );
921
922 match instance.def {
923 ty::InstanceKind::DropGlue(_, None) => {
926 let target = target.unwrap();
928 return helper.funclet_br(self, bx, target, mergeable_succ);
929 }
930 ty::InstanceKind::Intrinsic(def_id) => {
931 let intrinsic = bx.tcx().intrinsic(def_id).unwrap();
932 if let Some(merging_succ) = self.codegen_panic_intrinsic(
933 &helper,
934 bx,
935 intrinsic,
936 instance,
937 source_info,
938 target,
939 unwind,
940 mergeable_succ,
941 ) {
942 return merging_succ;
943 }
944
945 let result_layout =
946 self.cx.layout_of(self.monomorphized_place_ty(destination.as_ref()));
947
948 let (result_place, store_in_local) =
949 if let Some(local) = destination.as_local() {
950 match self.locals[local] {
951 LocalRef::Place(dest) => (Some(dest.val), None),
952 LocalRef::UnsizedPlace(_) => ::rustc_middle::util::bug::bug_fmt(format_args!("return type must be sized"))bug!("return type must be sized"),
953 LocalRef::PendingOperand => (None, Some(local)),
954 LocalRef::Operand(_) => {
955 if result_layout.is_zst() {
956 let place = PlaceRef::new_sized(
957 bx.const_undef(bx.type_ptr()),
958 result_layout,
959 );
960 (Some(place.val), None)
961 } else {
962 ::rustc_middle::util::bug::bug_fmt(format_args!("place local already assigned to"));bug!("place local already assigned to");
963 }
964 }
965 }
966 } else {
967 (Some(self.codegen_place(bx, destination.as_ref()).val), None)
968 };
969
970 if let Some(place) = result_place
971 && place.align < result_layout.align.abi
972 {
973 ::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");
980 }
981
982 let args: Vec<_> =
983 args.iter().map(|arg| self.codegen_operand(bx, &arg.node)).collect();
984
985 let intrinsic_result = self.codegen_intrinsic_call(
986 bx,
987 instance,
988 &args,
989 result_layout,
990 result_place,
991 source_info,
992 );
993
994 if let IntrinsicResult::Operand(op_val) = intrinsic_result {
995 match (result_place, store_in_local) {
996 (None, Some(local)) => {
997 let op = OperandRef {
998 val: op_val,
999 layout: result_layout,
1000 move_annotation: None,
1001 };
1002 self.overwrite_local(local, LocalRef::Operand(op));
1003 self.debug_introduce_local(bx, local);
1004 }
1005 (Some(place_val), None) => {
1006 let dest = PlaceRef { val: place_val, layout: result_layout };
1007 op_val.store(bx, dest);
1008 }
1009 _ => ::rustc_middle::util::bug::bug_fmt(format_args!("impossible case reached"))bug!(),
1010 }
1011 }
1012
1013 match intrinsic_result {
1014 IntrinsicResult::Operand(_) | IntrinsicResult::WroteIntoPlace => {
1015 return if let Some(target) = target {
1016 helper.funclet_br(self, bx, target, mergeable_succ)
1017 } else {
1018 bx.unreachable();
1019 MergingSucc::False
1020 };
1021 }
1022 IntrinsicResult::Err(_) => {
1023 if let Some(local) = store_in_local {
1027 let op = OperandRef {
1028 val: OperandValue::poison(bx, result_layout),
1029 layout: result_layout,
1030 move_annotation: None,
1031 };
1032 self.overwrite_local(local, LocalRef::Operand(op));
1033 }
1034 bx.abort();
1037 return MergingSucc::False;
1038 }
1039 IntrinsicResult::Fallback(instance) => {
1040 if intrinsic.must_be_overridden {
1041 ::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!(
1042 fn_span,
1043 "intrinsic {} must be overridden by codegen backend, but isn't",
1044 intrinsic.name,
1045 );
1046 }
1047 (Some(instance), None)
1048 }
1049 }
1050 }
1051
1052 _ if kind == CallKind::Tail
1053 && instance.def.requires_caller_location(bx.tcx()) =>
1054 {
1055 if let Some(hir_id) =
1056 terminator.source_info.scope.lint_root(&self.mir.source_scopes)
1057 {
1058 bx.tcx().emit_node_lint(TAIL_CALL_TRACK_CALLER, hir_id, rustc_errors::DiagDecorator(|d| {
1059 _ = d.primary_message("tail calling a function marked with `#[track_caller]` has no special effect").span(fn_span)
1060 }));
1061 }
1062
1063 let instance = ty::Instance::resolve_for_fn_ptr(
1064 bx.tcx(),
1065 bx.typing_env(),
1066 def_id,
1067 generic_args,
1068 )
1069 .unwrap();
1070
1071 (None, Some(bx.get_fn_addr(instance)))
1072 }
1073 _ => (Some(instance), None),
1074 }
1075 }
1076 ty::FnPtr(..) => (None, Some(callee.immediate())),
1077 _ => ::rustc_middle::util::bug::bug_fmt(format_args!("{0} is not callable",
callee.layout.ty))bug!("{} is not callable", callee.layout.ty),
1078 };
1079
1080 if let Some(instance) = instance
1081 && let Some(name) = bx.tcx().codegen_fn_attrs(instance.def_id()).symbol_name
1082 && name.as_str().starts_with("llvm.")
1083 && name.as_str() != "llvm.wasm.throw"
1087 {
1088 if !!instance.args.has_infer() {
::core::panicking::panic("assertion failed: !instance.args.has_infer()")
};assert!(!instance.args.has_infer());
1089 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());
1090
1091 let result_layout =
1092 self.cx.layout_of(self.monomorphized_place_ty(destination.as_ref()));
1093
1094 let return_dest = if result_layout.is_zst() {
1095 ReturnDest::Nothing
1096 } else if let Some(index) = destination.as_local() {
1097 match self.locals[index] {
1098 LocalRef::Place(dest) => ReturnDest::Store(dest),
1099 LocalRef::UnsizedPlace(_) => ::rustc_middle::util::bug::bug_fmt(format_args!("return type must be sized"))bug!("return type must be sized"),
1100 LocalRef::PendingOperand => {
1101 ReturnDest::DirectOperand(index)
1104 }
1105 LocalRef::Operand(_) => ::rustc_middle::util::bug::bug_fmt(format_args!("place local already assigned to"))bug!("place local already assigned to"),
1106 }
1107 } else {
1108 ReturnDest::Store(self.codegen_place(bx, destination.as_ref()))
1109 };
1110
1111 let args =
1112 args.into_iter().map(|arg| self.codegen_operand(bx, &arg.node)).collect::<Vec<_>>();
1113
1114 self.set_debug_loc(bx, source_info);
1115
1116 let llret =
1117 bx.codegen_llvm_intrinsic_call(instance, &args, self.mir[helper.bb].is_cleanup);
1118
1119 if let Some(target) = target {
1120 self.store_return(
1121 bx,
1122 return_dest,
1123 &ArgAbi { layout: result_layout, mode: PassMode::Direct(ArgAttributes::new()) },
1124 llret,
1125 );
1126 return helper.funclet_br(self, bx, target, mergeable_succ);
1127 } else {
1128 bx.unreachable();
1129 return MergingSucc::False;
1130 }
1131 }
1132
1133 let sig = callee.layout.ty.fn_sig(bx.tcx());
1137
1138 let extra_args = &args[sig.inputs().skip_binder().len()..];
1139 let extra_args = bx.tcx().mk_type_list_from_iter(extra_args.iter().map(|op_arg| {
1140 let op_ty = op_arg.node.ty(self.mir, bx.tcx());
1141 self.monomorphize(op_ty)
1142 }));
1143
1144 let fn_abi = match instance {
1145 Some(instance) => bx.fn_abi_of_instance(instance, extra_args),
1146 None => bx.fn_abi_of_fn_ptr(sig, extra_args),
1147 };
1148
1149 let arg_count = fn_abi.args.len() + fn_abi.ret.is_indirect() as usize;
1151
1152 let mut llargs = Vec::with_capacity(arg_count);
1153
1154 let destination = match kind {
1158 CallKind::Normal => {
1159 let return_dest = self.make_return_dest(bx, destination, &fn_abi.ret, &mut llargs);
1160 target.map(|target| (return_dest, target))
1161 }
1162 CallKind::Tail => {
1163 if fn_abi.ret.is_indirect() {
1164 match self.make_return_dest(bx, destination, &fn_abi.ret, &mut llargs) {
1165 ReturnDest::Nothing => {}
1166 _ => ::rustc_middle::util::bug::bug_fmt(format_args!("tail calls to functions with indirect returns cannot store into a destination"))bug!(
1167 "tail calls to functions with indirect returns cannot store into a destination"
1168 ),
1169 }
1170 }
1171 None
1172 }
1173 };
1174
1175 let (first_args, untuple) = if sig.abi() == ExternAbi::RustCall
1177 && let Some((tup, args)) = args.split_last()
1178 {
1179 (args, Some(tup))
1180 } else {
1181 (args, None)
1182 };
1183
1184 let mut tail_call_temporaries = ::alloc::vec::Vec::new()vec![];
1207 if kind == CallKind::Tail {
1208 tail_call_temporaries = ::alloc::vec::from_elem(None, first_args.len())vec![None; first_args.len()];
1209 for (i, arg) in first_args.iter().enumerate() {
1212 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, .. }) {
1213 continue;
1214 }
1215
1216 let op = self.codegen_operand(bx, &arg.node);
1217 let tmp = PlaceRef::alloca(bx, op.layout);
1218 bx.lifetime_start(tmp.val.llval, tmp.layout.size);
1219 op.store_with_annotation(bx, tmp);
1220
1221 tail_call_temporaries[i] = Some(tmp);
1222 }
1223 }
1224
1225 let mut lifetime_ends_after_call: Vec<(Bx::Value, Size)> = Vec::new();
1229 'make_args: for (i, arg) in first_args.iter().enumerate() {
1230 let mut op = self.codegen_operand(bx, &arg.node);
1231
1232 if let (0, Some(ty::InstanceKind::Virtual(_, idx))) = (i, instance.map(|i| i.def)) {
1233 match op.val {
1234 Pair(data_ptr, meta) => {
1235 while !op.layout.ty.is_raw_ptr() && !op.layout.ty.is_ref() {
1245 let (idx, _) = op.layout.non_1zst_field(bx).expect(
1246 "not exactly one non-1-ZST field in a `DispatchFromDyn` type",
1247 );
1248 op = op.extract_field(self, bx, idx.as_usize());
1249 }
1250
1251 llfn = Some(meth::VirtualIndex::from_index(idx).get_fn(
1255 bx,
1256 meta,
1257 op.layout.ty,
1258 fn_abi,
1259 ));
1260 llargs.push(data_ptr);
1261 continue 'make_args;
1262 }
1263 Ref(PlaceValue { llval: data_ptr, llextra: Some(meta), .. }) => {
1264 llfn = Some(meth::VirtualIndex::from_index(idx).get_fn(
1266 bx,
1267 meta,
1268 op.layout.ty,
1269 fn_abi,
1270 ));
1271 llargs.push(data_ptr);
1272 continue;
1273 }
1274 _ => {
1275 ::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);
1276 }
1277 }
1278 }
1279
1280 let by_move = if let PassMode::Indirect { on_stack: false, .. } = fn_abi.args[i].mode
1281 && kind == CallKind::Tail
1282 {
1283 let Some(tmp) = tail_call_temporaries[i].take() else {
1296 ::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}")
1297 };
1298
1299 let local = self.mir.args_iter().nth(i).unwrap();
1300
1301 match &self.locals[local] {
1302 LocalRef::Place(arg) => {
1303 bx.typed_place_copy(arg.val, tmp.val, fn_abi.args[i].layout);
1304 op.val = Ref(arg.val);
1305 }
1306 LocalRef::Operand(arg) => {
1307 let Ref(place_value) = arg.val else {
1308 ::rustc_middle::util::bug::bug_fmt(format_args!("only `Ref` should use `PassMode::Indirect`"));bug!("only `Ref` should use `PassMode::Indirect`");
1309 };
1310 bx.typed_place_copy(place_value, tmp.val, fn_abi.args[i].layout);
1311 op.val = arg.val;
1312 }
1313 LocalRef::UnsizedPlace(_) => {
1314 ::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")
1315 }
1316 LocalRef::PendingOperand => {
1317 ::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")
1318 }
1319 };
1320
1321 bx.lifetime_end(tmp.val.llval, tmp.layout.size);
1322 true
1323 } else {
1324 #[allow(non_exhaustive_omitted_patterns)] match arg.node {
mir::Operand::Move(_) => true,
_ => false,
}matches!(arg.node, mir::Operand::Move(_))
1325 };
1326
1327 self.codegen_argument(
1328 bx,
1329 op,
1330 by_move,
1331 &mut llargs,
1332 &fn_abi.args[i],
1333 &mut lifetime_ends_after_call,
1334 );
1335 }
1336 let num_untupled = untuple.map(|tup| {
1337 self.codegen_arguments_untupled(
1338 bx,
1339 &tup.node,
1340 &mut llargs,
1341 &fn_abi.args[first_args.len()..],
1342 &mut lifetime_ends_after_call,
1343 )
1344 });
1345
1346 let needs_location =
1347 instance.is_some_and(|i| i.def.requires_caller_location(self.cx.tcx()));
1348 if needs_location {
1349 let mir_args = if let Some(num_untupled) = num_untupled {
1350 first_args.len() + num_untupled
1351 } else {
1352 args.len()
1353 };
1354 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!(
1355 fn_abi.args.len(),
1356 mir_args + 1,
1357 "#[track_caller] fn's must have 1 more argument in their ABI than in their MIR: {instance:?} {fn_span:?} {fn_abi:?}",
1358 );
1359 let location = self.get_caller_location(bx, source_info);
1360 {
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:1360",
"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(1360u32),
::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!(
1361 "codegen_call_terminator({:?}): location={:?} (fn_span {:?})",
1362 terminator, location, fn_span
1363 );
1364
1365 let last_arg = fn_abi.args.last().unwrap();
1366 self.codegen_argument(
1367 bx,
1368 location,
1369 false,
1370 &mut llargs,
1371 last_arg,
1372 &mut lifetime_ends_after_call,
1373 );
1374 }
1375
1376 let fn_ptr = match (instance, llfn) {
1377 (Some(instance), None) => bx.get_fn_addr(instance),
1378 (_, Some(llfn)) => llfn,
1379 _ => ::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"),
1380 };
1381 self.set_debug_loc(bx, source_info);
1382 helper.do_call(
1383 self,
1384 bx,
1385 fn_abi,
1386 fn_ptr,
1387 &llargs,
1388 destination,
1389 unwind,
1390 &lifetime_ends_after_call,
1391 instance,
1392 kind,
1393 mergeable_succ,
1394 )
1395 }
1396
1397 fn codegen_asm_terminator(
1398 &mut self,
1399 helper: TerminatorCodegenHelper<'tcx>,
1400 bx: &mut Bx,
1401 asm_macro: InlineAsmMacro,
1402 terminator: &mir::Terminator<'tcx>,
1403 template: &[ast::InlineAsmTemplatePiece],
1404 operands: &[mir::InlineAsmOperand<'tcx>],
1405 options: ast::InlineAsmOptions,
1406 line_spans: &[Span],
1407 targets: &[mir::BasicBlock],
1408 unwind: mir::UnwindAction,
1409 instance: Instance<'_>,
1410 mergeable_succ: bool,
1411 ) -> MergingSucc {
1412 let span = terminator.source_info.span;
1413
1414 let operands: Vec<_> = operands
1415 .iter()
1416 .map(|op| match *op {
1417 mir::InlineAsmOperand::In { reg, ref value } => {
1418 let value = self.codegen_operand(bx, value);
1419 InlineAsmOperandRef::In { reg, value }
1420 }
1421 mir::InlineAsmOperand::Out { reg, late, ref place } => {
1422 let place = place.map(|place| self.codegen_place(bx, place.as_ref()));
1423 InlineAsmOperandRef::Out { reg, late, place }
1424 }
1425 mir::InlineAsmOperand::InOut { reg, late, ref in_value, ref out_place } => {
1426 let in_value = self.codegen_operand(bx, in_value);
1427 let out_place =
1428 out_place.map(|out_place| self.codegen_place(bx, out_place.as_ref()));
1429 InlineAsmOperandRef::InOut { reg, late, in_value, out_place }
1430 }
1431 mir::InlineAsmOperand::Const { ref value } => {
1432 let const_value = self.eval_mir_constant(value);
1433 let string = common::asm_const_to_str(
1434 bx.tcx(),
1435 span,
1436 const_value,
1437 bx.layout_of(value.ty()),
1438 );
1439 InlineAsmOperandRef::Const { string }
1440 }
1441 mir::InlineAsmOperand::SymFn { ref value } => {
1442 let const_ = self.monomorphize(value.const_);
1443 if let ty::FnDef(def_id, args) = *const_.ty().kind() {
1444 let instance = ty::Instance::resolve_for_fn_ptr(
1445 bx.tcx(),
1446 bx.typing_env(),
1447 def_id,
1448 args,
1449 )
1450 .unwrap();
1451 InlineAsmOperandRef::SymFn { instance }
1452 } else {
1453 ::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)");
1454 }
1455 }
1456 mir::InlineAsmOperand::SymStatic { def_id } => {
1457 InlineAsmOperandRef::SymStatic { def_id }
1458 }
1459 mir::InlineAsmOperand::Label { target_index } => {
1460 InlineAsmOperandRef::Label { label: self.llbb(targets[target_index]) }
1461 }
1462 })
1463 .collect();
1464
1465 helper.do_inlineasm(
1466 self,
1467 bx,
1468 template,
1469 &operands,
1470 options,
1471 line_spans,
1472 if asm_macro.diverges(options) { None } else { targets.get(0).copied() },
1473 unwind,
1474 instance,
1475 mergeable_succ,
1476 )
1477 }
1478
1479 pub(crate) fn codegen_block(&mut self, mut bb: mir::BasicBlock) {
1480 let llbb = match self.try_llbb(bb) {
1481 Some(llbb) => llbb,
1482 None => return,
1483 };
1484 let bx = &mut Bx::build(self.cx, llbb);
1485 let mir = self.mir;
1486
1487 loop {
1491 let data = &mir[bb];
1492
1493 {
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:1493",
"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(1493u32),
::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);
1494
1495 for statement in &data.statements {
1496 self.codegen_statement(bx, statement);
1497 }
1498 self.codegen_stmt_debuginfos(bx, &data.after_last_stmt_debuginfos);
1499
1500 let merging_succ = self.codegen_terminator(bx, bb, data.terminator());
1501 if let MergingSucc::False = merging_succ {
1502 break;
1503 }
1504
1505 let mut successors = data.terminator().successors();
1513 let succ = successors.next().unwrap();
1514 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));
1515 self.cached_llbbs[succ] = CachedLlbb::Skip;
1516 bb = succ;
1517 }
1518 }
1519
1520 pub(crate) fn codegen_block_as_unreachable(&mut self, bb: mir::BasicBlock) {
1521 let llbb = match self.try_llbb(bb) {
1522 Some(llbb) => llbb,
1523 None => return,
1524 };
1525 let bx = &mut Bx::build(self.cx, llbb);
1526 {
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:1526",
"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(1526u32),
::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);
1527 bx.unreachable();
1528 }
1529
1530 fn codegen_terminator(
1531 &mut self,
1532 bx: &mut Bx,
1533 bb: mir::BasicBlock,
1534 terminator: &'tcx mir::Terminator<'tcx>,
1535 ) -> MergingSucc {
1536 {
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:1536",
"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(1536u32),
::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);
1537
1538 let helper = TerminatorCodegenHelper { bb, terminator };
1539
1540 let mergeable_succ = || {
1541 let mut successors = terminator.successors();
1544 if let Some(succ) = successors.next()
1545 && successors.next().is_none()
1546 && let &[succ_pred] = self.mir.basic_blocks.predecessors()[succ].as_slice()
1547 {
1548 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);
1551 true
1552 } else {
1553 false
1554 }
1555 };
1556
1557 self.set_debug_loc(bx, terminator.source_info);
1558 match terminator.kind {
1559 mir::TerminatorKind::UnwindResume => {
1560 self.codegen_resume_terminator(helper, bx);
1561 MergingSucc::False
1562 }
1563
1564 mir::TerminatorKind::UnwindTerminate(reason) => {
1565 self.codegen_terminate_terminator(helper, bx, terminator, reason);
1566 MergingSucc::False
1567 }
1568
1569 mir::TerminatorKind::Goto { target } => {
1570 helper.funclet_br(self, bx, target, mergeable_succ())
1571 }
1572
1573 mir::TerminatorKind::SwitchInt { ref discr, ref targets } => {
1574 self.codegen_switchint_terminator(helper, bx, discr, targets);
1575 MergingSucc::False
1576 }
1577
1578 mir::TerminatorKind::Return => {
1579 self.codegen_return_terminator(bx);
1580 MergingSucc::False
1581 }
1582
1583 mir::TerminatorKind::Unreachable => {
1584 bx.unreachable();
1585 MergingSucc::False
1586 }
1587
1588 mir::TerminatorKind::Drop { place, target, unwind, replace: _, drop, async_fut } => {
1589 if !(async_fut.is_none() && drop.is_none()) {
{
::core::panicking::panic_fmt(format_args!("Async Drop must be expanded or reset to sync before codegen"));
}
};assert!(
1590 async_fut.is_none() && drop.is_none(),
1591 "Async Drop must be expanded or reset to sync before codegen"
1592 );
1593 self.codegen_drop_terminator(
1594 helper,
1595 bx,
1596 &terminator.source_info,
1597 place,
1598 target,
1599 unwind,
1600 mergeable_succ(),
1601 )
1602 }
1603
1604 mir::TerminatorKind::Assert { ref cond, expected, ref msg, target, unwind } => self
1605 .codegen_assert_terminator(
1606 helper,
1607 bx,
1608 terminator,
1609 cond,
1610 expected,
1611 msg,
1612 target,
1613 unwind,
1614 mergeable_succ(),
1615 ),
1616
1617 mir::TerminatorKind::Call {
1618 ref func,
1619 ref args,
1620 destination,
1621 target,
1622 unwind,
1623 call_source: _,
1624 fn_span,
1625 } => self.codegen_call_terminator(
1626 helper,
1627 bx,
1628 terminator,
1629 func,
1630 args,
1631 destination,
1632 target,
1633 unwind,
1634 fn_span,
1635 CallKind::Normal,
1636 mergeable_succ(),
1637 ),
1638 mir::TerminatorKind::TailCall { ref func, ref args, fn_span } => self
1639 .codegen_call_terminator(
1640 helper,
1641 bx,
1642 terminator,
1643 func,
1644 args,
1645 mir::Place::from(mir::RETURN_PLACE),
1646 None,
1647 mir::UnwindAction::Unreachable,
1648 fn_span,
1649 CallKind::Tail,
1650 mergeable_succ(),
1651 ),
1652 mir::TerminatorKind::CoroutineDrop | mir::TerminatorKind::Yield { .. } => {
1653 ::rustc_middle::util::bug::bug_fmt(format_args!("coroutine ops in codegen"))bug!("coroutine ops in codegen")
1654 }
1655 mir::TerminatorKind::FalseEdge { .. } | mir::TerminatorKind::FalseUnwind { .. } => {
1656 ::rustc_middle::util::bug::bug_fmt(format_args!("borrowck false edges in codegen"))bug!("borrowck false edges in codegen")
1657 }
1658
1659 mir::TerminatorKind::InlineAsm {
1660 asm_macro,
1661 template,
1662 ref operands,
1663 options,
1664 line_spans,
1665 ref targets,
1666 unwind,
1667 } => self.codegen_asm_terminator(
1668 helper,
1669 bx,
1670 asm_macro,
1671 terminator,
1672 template,
1673 operands,
1674 options,
1675 line_spans,
1676 targets,
1677 unwind,
1678 self.instance,
1679 mergeable_succ(),
1680 ),
1681 }
1682 }
1683
1684 fn codegen_argument(
1685 &mut self,
1686 bx: &mut Bx,
1687 op: OperandRef<'tcx, Bx::Value>,
1688 by_move: bool,
1689 llargs: &mut Vec<Bx::Value>,
1690 arg: &ArgAbi<'tcx, Ty<'tcx>>,
1691 lifetime_ends_after_call: &mut Vec<(Bx::Value, Size)>,
1692 ) {
1693 match arg.mode {
1694 PassMode::Ignore => return,
1695 PassMode::Cast { pad_i32: true, .. } => {
1696 llargs.push(bx.const_undef(bx.reg_backend_type(&Reg::i32())));
1698 }
1699 PassMode::Pair(..) => match op.val {
1700 Pair(a, b) => {
1701 llargs.push(a);
1702 llargs.push(b);
1703 return;
1704 }
1705 _ => ::rustc_middle::util::bug::bug_fmt(format_args!("codegen_argument: {0:?} invalid for pair argument",
op))bug!("codegen_argument: {:?} invalid for pair argument", op),
1706 },
1707 PassMode::Indirect { attrs: _, meta_attrs: Some(_), on_stack: _ } => match op.val {
1708 Ref(PlaceValue { llval: a, llextra: Some(b), .. }) => {
1709 llargs.push(a);
1710 llargs.push(b);
1711 return;
1712 }
1713 _ => ::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),
1714 },
1715 _ => {}
1716 }
1717
1718 let (mut llval, align, by_ref) = match op.val {
1720 Immediate(_) | Pair(..) => match arg.mode {
1721 PassMode::Indirect { attrs, .. } => {
1722 let required_align = match attrs.pointee_align {
1726 Some(pointee_align) => cmp::max(pointee_align, arg.layout.align.abi),
1727 None => arg.layout.align.abi,
1728 };
1729 let scratch = PlaceValue::alloca(bx, arg.layout.size, required_align);
1730 bx.lifetime_start(scratch.llval, arg.layout.size);
1731 op.store_with_annotation(bx, scratch.with_type(arg.layout));
1732 lifetime_ends_after_call.push((scratch.llval, arg.layout.size));
1733 (scratch.llval, scratch.align, true)
1734 }
1735 PassMode::Cast { .. } => {
1736 let scratch = PlaceRef::alloca(bx, arg.layout);
1737 op.store_with_annotation(bx, scratch);
1738 (scratch.val.llval, scratch.val.align, true)
1739 }
1740 _ => (op.immediate_or_packed_pair(bx), arg.layout.align.abi, false),
1741 },
1742 Ref(op_place_val) => match arg.mode {
1743 PassMode::Indirect { attrs, on_stack, .. } => {
1744 let required_align = match attrs.pointee_align {
1748 Some(pointee_align) => cmp::max(pointee_align, arg.layout.align.abi),
1749 None => arg.layout.align.abi,
1750 };
1751 if op_place_val.align < required_align || (!on_stack && !by_move) {
1753 let scratch = PlaceValue::alloca(bx, arg.layout.size, required_align);
1754 bx.lifetime_start(scratch.llval, arg.layout.size);
1755 op.store_with_annotation(bx, scratch.with_type(arg.layout));
1756 lifetime_ends_after_call.push((scratch.llval, arg.layout.size));
1757 (scratch.llval, scratch.align, true)
1758 } else {
1759 (op_place_val.llval, op_place_val.align, true)
1760 }
1761 }
1762 _ => (op_place_val.llval, op_place_val.align, true),
1763 },
1764 ZeroSized => match arg.mode {
1765 PassMode::Indirect { on_stack, .. } => {
1766 if on_stack {
1767 ::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:?}");
1770 }
1771 let scratch = PlaceRef::alloca(bx, arg.layout);
1775 (scratch.val.llval, scratch.val.align, true)
1776 }
1777 _ => ::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:?}"),
1778 },
1779 };
1780
1781 if by_ref && !arg.is_indirect() {
1782 if let PassMode::Cast { cast, pad_i32: _ } = &arg.mode {
1784 let scratch_size = cast.size(bx);
1788 let scratch_align = cast.align(bx);
1789 let copy_bytes = cmp::min(cast.unaligned_size(bx).bytes(), arg.layout.size.bytes());
1796 let llscratch = bx.alloca(scratch_size, scratch_align);
1798 bx.lifetime_start(llscratch, scratch_size);
1799 bx.memcpy(
1801 llscratch,
1802 scratch_align,
1803 llval,
1804 align,
1805 bx.const_usize(copy_bytes),
1806 MemFlags::empty(),
1807 None,
1808 );
1809 llval = load_cast(bx, cast, llscratch, scratch_align);
1811 bx.lifetime_end(llscratch, scratch_size);
1812 } else {
1813 llval = bx.load(bx.backend_type(arg.layout), llval, align);
1819 if let BackendRepr::Scalar(scalar) = arg.layout.backend_repr {
1820 if scalar.is_bool() {
1821 bx.range_metadata(llval, WrappingRange { start: 0, end: 1 });
1822 }
1823 llval = bx.to_immediate_scalar(llval, scalar);
1825 }
1826 }
1827 }
1828
1829 llargs.push(llval);
1830 }
1831
1832 fn codegen_arguments_untupled(
1833 &mut self,
1834 bx: &mut Bx,
1835 operand: &mir::Operand<'tcx>,
1836 llargs: &mut Vec<Bx::Value>,
1837 args: &[ArgAbi<'tcx, Ty<'tcx>>],
1838 lifetime_ends_after_call: &mut Vec<(Bx::Value, Size)>,
1839 ) -> usize {
1840 let tuple = self.codegen_operand(bx, operand);
1841 let by_move = #[allow(non_exhaustive_omitted_patterns)] match operand {
mir::Operand::Move(_) => true,
_ => false,
}matches!(operand, mir::Operand::Move(_));
1842
1843 if let Ref(place_val) = tuple.val {
1845 if place_val.llextra.is_some() {
1846 ::rustc_middle::util::bug::bug_fmt(format_args!("closure arguments must be sized"));bug!("closure arguments must be sized");
1847 }
1848 let tuple_ptr = place_val.with_type(tuple.layout);
1849 for i in 0..tuple.layout.fields.count() {
1850 let field_ptr = tuple_ptr.project_field(bx, i);
1851 let field = bx.load_operand(field_ptr);
1852 self.codegen_argument(
1853 bx,
1854 field,
1855 by_move,
1856 llargs,
1857 &args[i],
1858 lifetime_ends_after_call,
1859 );
1860 }
1861 } else {
1862 for i in 0..tuple.layout.fields.count() {
1864 let op = tuple.extract_field(self, bx, i);
1865 self.codegen_argument(bx, op, by_move, llargs, &args[i], lifetime_ends_after_call);
1866 }
1867 }
1868 tuple.layout.fields.count()
1869 }
1870
1871 pub(super) fn get_caller_location(
1872 &mut self,
1873 bx: &mut Bx,
1874 source_info: mir::SourceInfo,
1875 ) -> OperandRef<'tcx, Bx::Value> {
1876 self.mir.caller_location_span(source_info, self.caller_location, bx.tcx(), |span: Span| {
1877 let const_loc = bx.tcx().span_as_caller_location(span);
1878 OperandRef::from_const(bx, const_loc, bx.tcx().caller_location_ty())
1879 })
1880 }
1881
1882 fn get_personality_slot(&mut self, bx: &mut Bx) -> PlaceRef<'tcx, Bx::Value> {
1883 let cx = bx.cx();
1884 if let Some(slot) = self.personality_slot {
1885 slot
1886 } else {
1887 let layout = cx.layout_of(Ty::new_tup(
1888 cx.tcx(),
1889 &[Ty::new_mut_ptr(cx.tcx(), cx.tcx().types.u8), cx.tcx().types.i32],
1890 ));
1891 let slot = PlaceRef::alloca(bx, layout);
1892 self.personality_slot = Some(slot);
1893 slot
1894 }
1895 }
1896
1897 fn landing_pad_for(&mut self, bb: mir::BasicBlock) -> Bx::BasicBlock {
1900 if let Some(landing_pad) = self.landing_pads[bb] {
1901 return landing_pad;
1902 }
1903
1904 let landing_pad = self.landing_pad_for_uncached(bb);
1905 self.landing_pads[bb] = Some(landing_pad);
1906 landing_pad
1907 }
1908
1909 fn landing_pad_for_uncached(&mut self, bb: mir::BasicBlock) -> Bx::BasicBlock {
1911 let llbb = self.llbb(bb);
1912 if base::wants_new_eh_instructions(self.cx.sess()) {
1913 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:?}"));
1914 let mut cleanup_bx = Bx::build(self.cx, cleanup_bb);
1915 let funclet = cleanup_bx.cleanup_pad(None, &[]);
1916 cleanup_bx.br(llbb);
1917 self.funclets[bb] = Some(funclet);
1918 cleanup_bb
1919 } else {
1920 let cleanup_llbb = Bx::append_block(self.cx, self.llfn, "cleanup");
1921 let mut cleanup_bx = Bx::build(self.cx, cleanup_llbb);
1922
1923 let llpersonality = self.cx.eh_personality();
1924 let (exn0, exn1) = cleanup_bx.cleanup_landing_pad(llpersonality);
1925
1926 let slot = self.get_personality_slot(&mut cleanup_bx);
1927 slot.storage_live(&mut cleanup_bx);
1928 Pair(exn0, exn1).store(&mut cleanup_bx, slot);
1929
1930 cleanup_bx.br(llbb);
1931 cleanup_llbb
1932 }
1933 }
1934
1935 fn unreachable_block(&mut self) -> Bx::BasicBlock {
1936 self.unreachable_block.unwrap_or_else(|| {
1937 let llbb = Bx::append_block(self.cx, self.llfn, "unreachable");
1938 let mut bx = Bx::build(self.cx, llbb);
1939 bx.unreachable();
1940 self.unreachable_block = Some(llbb);
1941 llbb
1942 })
1943 }
1944
1945 fn terminate_block(
1946 &mut self,
1947 reason: UnwindTerminateReason,
1948 outer_catchpad_bb: Option<mir::BasicBlock>,
1949 ) -> Bx::BasicBlock {
1950 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!(
1955 outer_catchpad_bb.is_some()
1956 == (base::wants_wasm_eh(self.cx.tcx().sess)
1957 && reason == UnwindTerminateReason::InCleanup)
1958 );
1959
1960 let mut cache_bb = mir::START_BLOCK;
1963 if let Some(outer_bb) = outer_catchpad_bb {
1966 let cleanup_kinds =
1967 self.cleanup_kinds.as_ref().expect("cleanup_kinds required for funclets");
1968 cache_bb = cleanup_kinds[outer_bb]
1969 .funclet_bb(outer_bb)
1970 .expect("funclet_bb should be in a funclet");
1971
1972 if self.funclets[cache_bb].is_none() {
1974 self.landing_pad_for(cache_bb);
1975 }
1976 }
1977 if let Some((cached_bb, cached_reason)) = self.terminate_blocks[cache_bb]
1978 && reason == cached_reason
1979 {
1980 return cached_bb;
1981 }
1982
1983 let funclet;
1984 let llbb;
1985 let mut bx;
1986 if base::wants_new_eh_instructions(self.cx.sess()) {
1987 llbb = Bx::append_block(self.cx, self.llfn, "cs_terminate");
2027
2028 let mut cs_bx = Bx::build(self.cx, llbb);
2029
2030 let mut outer_cleanuppad = None;
2034 if outer_catchpad_bb.is_some() {
2035 let outer_funclet = self.funclets[cache_bb]
2037 .as_ref()
2038 .expect("landing_pad_for didn't create funclet");
2039 outer_cleanuppad = Some(cs_bx.get_funclet_cleanuppad(outer_funclet));
2040 }
2041 let cp_llbb = Bx::append_block(self.cx, self.llfn, "cp_terminate");
2042 let cs = cs_bx.catch_switch(outer_cleanuppad, None, &[cp_llbb]);
2043 drop(cs_bx);
2044
2045 bx = Bx::build(self.cx, cp_llbb);
2046 let null =
2047 bx.const_null(bx.type_ptr_ext(bx.cx().data_layout().instruction_address_space));
2048
2049 let args = if base::wants_msvc_seh(self.cx.sess()) {
2053 let adjectives = bx.const_i32(0x40);
2060 &[null, adjectives, null] as &[_]
2061 } else {
2062 &[null] as &[_]
2068 };
2069
2070 funclet = Some(bx.catch_pad(cs, args));
2071 } else {
2077 llbb = Bx::append_block(self.cx, self.llfn, "terminate");
2078 bx = Bx::build(self.cx, llbb);
2079
2080 let llpersonality = self.cx.eh_personality();
2081 bx.filter_landing_pad(llpersonality);
2082
2083 funclet = None;
2084 }
2085
2086 self.set_debug_loc(&mut bx, mir::SourceInfo::outermost(self.mir.span));
2087
2088 let (fn_abi, fn_ptr, instance) =
2089 common::build_langcall(&bx, self.mir.span, reason.lang_item());
2090 if is_call_from_compiler_builtins_to_upstream_monomorphization(bx.tcx(), instance) {
2091 bx.abort();
2092 } else {
2093 let fn_ty = bx.fn_decl_backend_type(fn_abi);
2094
2095 let llret = bx.call(fn_ty, None, Some(fn_abi), fn_ptr, &[], funclet.as_ref(), None);
2096 bx.apply_attrs_to_cleanup_callsite(llret);
2097 }
2098
2099 bx.unreachable();
2100
2101 self.terminate_blocks[cache_bb] = Some((llbb, reason));
2102 llbb
2103 }
2104
2105 pub fn llbb(&mut self, bb: mir::BasicBlock) -> Bx::BasicBlock {
2110 self.try_llbb(bb).unwrap()
2111 }
2112
2113 pub(crate) fn try_llbb(&mut self, bb: mir::BasicBlock) -> Option<Bx::BasicBlock> {
2115 match self.cached_llbbs[bb] {
2116 CachedLlbb::None => {
2117 let llbb = Bx::append_block(self.cx, self.llfn, &::alloc::__export::must_use({
::alloc::fmt::format(format_args!("{0:?}", bb))
})format!("{bb:?}"));
2118 self.cached_llbbs[bb] = CachedLlbb::Some(llbb);
2119 Some(llbb)
2120 }
2121 CachedLlbb::Some(llbb) => Some(llbb),
2122 CachedLlbb::Skip => None,
2123 }
2124 }
2125
2126 fn make_return_dest(
2127 &mut self,
2128 bx: &mut Bx,
2129 dest: mir::Place<'tcx>,
2130 fn_ret: &ArgAbi<'tcx, Ty<'tcx>>,
2131 llargs: &mut Vec<Bx::Value>,
2132 ) -> ReturnDest<'tcx, Bx::Value> {
2133 if fn_ret.is_ignore() {
2135 return ReturnDest::Nothing;
2136 }
2137 let dest = if let Some(index) = dest.as_local() {
2138 match self.locals[index] {
2139 LocalRef::Place(dest) => dest,
2140 LocalRef::UnsizedPlace(_) => ::rustc_middle::util::bug::bug_fmt(format_args!("return type must be sized"))bug!("return type must be sized"),
2141 LocalRef::PendingOperand => {
2142 return if fn_ret.is_indirect() {
2145 let tmp = PlaceRef::alloca(bx, fn_ret.layout);
2148 tmp.storage_live(bx);
2149 llargs.push(tmp.val.llval);
2150 ReturnDest::IndirectOperand(tmp, index)
2151 } else {
2152 ReturnDest::DirectOperand(index)
2153 };
2154 }
2155 LocalRef::Operand(_) => {
2156 ::rustc_middle::util::bug::bug_fmt(format_args!("place local already assigned to"));bug!("place local already assigned to");
2157 }
2158 }
2159 } else {
2160 self.codegen_place(bx, dest.as_ref())
2161 };
2162 if fn_ret.is_indirect() {
2163 if dest.val.align < dest.layout.align.abi {
2164 ::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");
2171 }
2172 llargs.push(dest.val.llval);
2173 ReturnDest::Nothing
2174 } else {
2175 ReturnDest::Store(dest)
2176 }
2177 }
2178
2179 fn store_return(
2181 &mut self,
2182 bx: &mut Bx,
2183 dest: ReturnDest<'tcx, Bx::Value>,
2184 ret_abi: &ArgAbi<'tcx, Ty<'tcx>>,
2185 llval: Bx::Value,
2186 ) {
2187 use self::ReturnDest::*;
2188
2189 match dest {
2190 Nothing => (),
2191 Store(dst) => bx.store_arg(ret_abi, llval, dst),
2192 IndirectOperand(tmp, index) => {
2193 let op = bx.load_operand(tmp);
2194 tmp.storage_dead(bx);
2195 self.overwrite_local(index, LocalRef::Operand(op));
2196 self.debug_introduce_local(bx, index);
2197 }
2198 DirectOperand(index) => {
2199 let op = if let PassMode::Cast { .. } = ret_abi.mode {
2201 let tmp = PlaceRef::alloca(bx, ret_abi.layout);
2202 tmp.storage_live(bx);
2203 bx.store_arg(ret_abi, llval, tmp);
2204 let op = bx.load_operand(tmp);
2205 tmp.storage_dead(bx);
2206 op
2207 } else {
2208 OperandRef::from_immediate_or_packed_pair(bx, llval, ret_abi.layout)
2209 };
2210 self.overwrite_local(index, LocalRef::Operand(op));
2211 self.debug_introduce_local(bx, index);
2212 }
2213 }
2214 }
2215}
2216
2217enum ReturnDest<'tcx, V> {
2218 Nothing,
2220 Store(PlaceRef<'tcx, V>),
2222 IndirectOperand(PlaceRef<'tcx, V>, mir::Local),
2224 DirectOperand(mir::Local),
2226}
2227
2228fn load_cast<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
2229 bx: &mut Bx,
2230 cast: &CastTarget,
2231 ptr: Bx::Value,
2232 align: Align,
2233) -> Bx::Value {
2234 let cast_ty = bx.cast_backend_type(cast);
2235 if let Some(offset_from_start) = cast.rest_offset {
2236 if !cast.prefix[1..].iter().all(|p| p.is_none()) {
::core::panicking::panic("assertion failed: cast.prefix[1..].iter().all(|p| p.is_none())")
};assert!(cast.prefix[1..].iter().all(|p| p.is_none()));
2237 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);
2238 let first_ty = bx.reg_backend_type(&cast.prefix[0].unwrap());
2239 let second_ty = bx.reg_backend_type(&cast.rest.unit);
2240 let first = bx.load(first_ty, ptr, align);
2241 let second_ptr = bx.inbounds_ptradd(ptr, bx.const_usize(offset_from_start.bytes()));
2242 let second = bx.load(second_ty, second_ptr, align.restrict_for_offset(offset_from_start));
2243 let res = bx.cx().const_poison(cast_ty);
2244 let res = bx.insert_value(res, first, 0);
2245 bx.insert_value(res, second, 1)
2246 } else {
2247 bx.load(cast_ty, ptr, align)
2248 }
2249}
2250
2251pub fn store_cast<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
2252 bx: &mut Bx,
2253 cast: &CastTarget,
2254 value: Bx::Value,
2255 ptr: Bx::Value,
2256 align: Align,
2257) {
2258 if let Some(offset_from_start) = cast.rest_offset {
2259 if !cast.prefix[1..].iter().all(|p| p.is_none()) {
::core::panicking::panic("assertion failed: cast.prefix[1..].iter().all(|p| p.is_none())")
};assert!(cast.prefix[1..].iter().all(|p| p.is_none()));
2260 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);
2261 if !cast.prefix[0].is_some() {
::core::panicking::panic("assertion failed: cast.prefix[0].is_some()")
};assert!(cast.prefix[0].is_some());
2262 let first = bx.extract_value(value, 0);
2263 let second = bx.extract_value(value, 1);
2264 bx.store(first, ptr, align);
2265 let second_ptr = bx.inbounds_ptradd(ptr, bx.const_usize(offset_from_start.bytes()));
2266 bx.store(second, second_ptr, align.restrict_for_offset(offset_from_start));
2267 } else {
2268 bx.store(value, ptr, align);
2269 };
2270}