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