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;
16use rustc_span::source_map::Spanned;
17use rustc_target::callconv::{ArgAbi, ArgAttributes, CastTarget, FnAbi, PassMode};
18use tracing::{debug, info};
19
20use super::operand::OperandRef;
21use super::operand::OperandValue::{Immediate, Pair, Ref, ZeroSized};
22use super::place::{PlaceRef, PlaceValue};
23use super::{CachedLlbb, FunctionCx, LocalRef};
24use crate::base::{self, is_call_from_compiler_builtins_to_upstream_monomorphization};
25use crate::common::{self, IntPredicate};
26use crate::errors::CompilerBuiltinsCannotCall;
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::from_usize(1 + 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_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: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_in_place(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, store_in_local) = if result_layout.is_zst() {
949 (
950 PlaceRef::new_sized(bx.const_undef(bx.type_ptr()), result_layout),
951 None,
952 )
953 } else if let Some(local) = destination.as_local() {
954 match self.locals[local] {
955 LocalRef::Place(dest) => (dest, None),
956 LocalRef::UnsizedPlace(_) => ::rustc_middle::util::bug::bug_fmt(format_args!("return type must be sized"))bug!("return type must be sized"),
957 LocalRef::PendingOperand => {
958 let tmp = PlaceRef::alloca(bx, result_layout);
962 tmp.storage_live(bx);
963 (tmp, Some(local))
964 }
965 LocalRef::Operand(_) => {
966 ::rustc_middle::util::bug::bug_fmt(format_args!("place local already assigned to"));bug!("place local already assigned to");
967 }
968 }
969 } else {
970 (self.codegen_place(bx, destination.as_ref()), None)
971 };
972
973 if result.val.align < result.layout.align.abi {
974 ::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");
981 }
982
983 let args: Vec<_> =
984 args.iter().map(|arg| self.codegen_operand(bx, &arg.node)).collect();
985
986 match self.codegen_intrinsic_call(bx, instance, &args, result, source_info)
987 {
988 Ok(()) => {
989 if let Some(local) = store_in_local {
990 let op = bx.load_operand(result);
991 result.storage_dead(bx);
992 self.overwrite_local(local, LocalRef::Operand(op));
993 self.debug_introduce_local(bx, local);
994 }
995
996 return if let Some(target) = target {
997 helper.funclet_br(self, bx, target, mergeable_succ)
998 } else {
999 bx.unreachable();
1000 MergingSucc::False
1001 };
1002 }
1003 Err(instance) => {
1004 if intrinsic.must_be_overridden {
1005 ::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!(
1006 fn_span,
1007 "intrinsic {} must be overridden by codegen backend, but isn't",
1008 intrinsic.name,
1009 );
1010 }
1011 (Some(instance), None)
1012 }
1013 }
1014 }
1015
1016 _ if kind == CallKind::Tail
1017 && instance.def.requires_caller_location(bx.tcx()) =>
1018 {
1019 if let Some(hir_id) =
1020 terminator.source_info.scope.lint_root(&self.mir.source_scopes)
1021 {
1022 let msg = "tail calling a function marked with `#[track_caller]` has no special effect";
1023 bx.tcx().node_lint(TAIL_CALL_TRACK_CALLER, hir_id, |d| {
1024 _ = d.primary_message(msg).span(fn_span)
1025 });
1026 }
1027
1028 let instance = ty::Instance::resolve_for_fn_ptr(
1029 bx.tcx(),
1030 bx.typing_env(),
1031 def_id,
1032 generic_args,
1033 )
1034 .unwrap();
1035
1036 (None, Some(bx.get_fn_addr(instance)))
1037 }
1038 _ => (Some(instance), None),
1039 }
1040 }
1041 ty::FnPtr(..) => (None, Some(callee.immediate())),
1042 _ => ::rustc_middle::util::bug::bug_fmt(format_args!("{0} is not callable",
callee.layout.ty))bug!("{} is not callable", callee.layout.ty),
1043 };
1044
1045 if let Some(instance) = instance
1046 && let Some(name) = bx.tcx().codegen_fn_attrs(instance.def_id()).symbol_name
1047 && name.as_str().starts_with("llvm.")
1048 && name.as_str() != "llvm.wasm.throw"
1052 {
1053 if !!instance.args.has_infer() {
::core::panicking::panic("assertion failed: !instance.args.has_infer()")
};assert!(!instance.args.has_infer());
1054 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());
1055
1056 let result_layout =
1057 self.cx.layout_of(self.monomorphized_place_ty(destination.as_ref()));
1058
1059 let return_dest = if result_layout.is_zst() {
1060 ReturnDest::Nothing
1061 } else if let Some(index) = destination.as_local() {
1062 match self.locals[index] {
1063 LocalRef::Place(dest) => ReturnDest::Store(dest),
1064 LocalRef::UnsizedPlace(_) => ::rustc_middle::util::bug::bug_fmt(format_args!("return type must be sized"))bug!("return type must be sized"),
1065 LocalRef::PendingOperand => {
1066 ReturnDest::DirectOperand(index)
1069 }
1070 LocalRef::Operand(_) => ::rustc_middle::util::bug::bug_fmt(format_args!("place local already assigned to"))bug!("place local already assigned to"),
1071 }
1072 } else {
1073 ReturnDest::Store(self.codegen_place(bx, destination.as_ref()))
1074 };
1075
1076 let args =
1077 args.into_iter().map(|arg| self.codegen_operand(bx, &arg.node)).collect::<Vec<_>>();
1078
1079 self.set_debug_loc(bx, source_info);
1080
1081 let llret =
1082 bx.codegen_llvm_intrinsic_call(instance, &args, self.mir[helper.bb].is_cleanup);
1083
1084 if let Some(target) = target {
1085 self.store_return(
1086 bx,
1087 return_dest,
1088 &ArgAbi { layout: result_layout, mode: PassMode::Direct(ArgAttributes::new()) },
1089 llret,
1090 );
1091 return helper.funclet_br(self, bx, target, mergeable_succ);
1092 } else {
1093 bx.unreachable();
1094 return MergingSucc::False;
1095 }
1096 }
1097
1098 let sig = callee.layout.ty.fn_sig(bx.tcx());
1102
1103 let extra_args = &args[sig.inputs().skip_binder().len()..];
1104 let extra_args = bx.tcx().mk_type_list_from_iter(extra_args.iter().map(|op_arg| {
1105 let op_ty = op_arg.node.ty(self.mir, bx.tcx());
1106 self.monomorphize(op_ty)
1107 }));
1108
1109 let fn_abi = match instance {
1110 Some(instance) => bx.fn_abi_of_instance(instance, extra_args),
1111 None => bx.fn_abi_of_fn_ptr(sig, extra_args),
1112 };
1113
1114 let arg_count = fn_abi.args.len() + fn_abi.ret.is_indirect() as usize;
1116
1117 let mut llargs = Vec::with_capacity(arg_count);
1118
1119 let destination = match kind {
1123 CallKind::Normal => {
1124 let return_dest = self.make_return_dest(bx, destination, &fn_abi.ret, &mut llargs);
1125 target.map(|target| (return_dest, target))
1126 }
1127 CallKind::Tail => {
1128 if fn_abi.ret.is_indirect() {
1129 match self.make_return_dest(bx, destination, &fn_abi.ret, &mut llargs) {
1130 ReturnDest::Nothing => {}
1131 _ => ::rustc_middle::util::bug::bug_fmt(format_args!("tail calls to functions with indirect returns cannot store into a destination"))bug!(
1132 "tail calls to functions with indirect returns cannot store into a destination"
1133 ),
1134 }
1135 }
1136 None
1137 }
1138 };
1139
1140 let (first_args, untuple) = if sig.abi() == ExternAbi::RustCall
1142 && let Some((tup, args)) = args.split_last()
1143 {
1144 (args, Some(tup))
1145 } else {
1146 (args, None)
1147 };
1148
1149 let mut tail_call_temporaries = ::alloc::vec::Vec::new()vec![];
1171 if kind == CallKind::Tail {
1172 tail_call_temporaries = ::alloc::vec::from_elem(None, first_args.len())vec![None; first_args.len()];
1173 for (i, arg) in first_args.iter().enumerate() {
1176 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, .. }) {
1177 continue;
1178 }
1179
1180 let op = self.codegen_operand(bx, &arg.node);
1181 let tmp = PlaceRef::alloca(bx, op.layout);
1182 bx.lifetime_start(tmp.val.llval, tmp.layout.size);
1183 op.store_with_annotation(bx, tmp);
1184
1185 tail_call_temporaries[i] = Some(tmp);
1186 }
1187 }
1188
1189 let mut lifetime_ends_after_call: Vec<(Bx::Value, Size)> = Vec::new();
1193 'make_args: for (i, arg) in first_args.iter().enumerate() {
1194 let mut op = self.codegen_operand(bx, &arg.node);
1195
1196 if let (0, Some(ty::InstanceKind::Virtual(_, idx))) = (i, instance.map(|i| i.def)) {
1197 match op.val {
1198 Pair(data_ptr, meta) => {
1199 while !op.layout.ty.is_raw_ptr() && !op.layout.ty.is_ref() {
1209 let (idx, _) = op.layout.non_1zst_field(bx).expect(
1210 "not exactly one non-1-ZST field in a `DispatchFromDyn` type",
1211 );
1212 op = op.extract_field(self, bx, idx.as_usize());
1213 }
1214
1215 llfn = Some(meth::VirtualIndex::from_index(idx).get_fn(
1219 bx,
1220 meta,
1221 op.layout.ty,
1222 fn_abi,
1223 ));
1224 llargs.push(data_ptr);
1225 continue 'make_args;
1226 }
1227 Ref(PlaceValue { llval: data_ptr, llextra: Some(meta), .. }) => {
1228 llfn = Some(meth::VirtualIndex::from_index(idx).get_fn(
1230 bx,
1231 meta,
1232 op.layout.ty,
1233 fn_abi,
1234 ));
1235 llargs.push(data_ptr);
1236 continue;
1237 }
1238 _ => {
1239 ::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);
1240 }
1241 }
1242 }
1243
1244 match kind {
1245 CallKind::Normal => {
1246 if let &mir::Operand::Copy(_) | &mir::Operand::Constant(_) = &arg.node
1249 && let Ref(PlaceValue { llextra: None, .. }) = op.val
1250 {
1251 let tmp = PlaceRef::alloca(bx, op.layout);
1252 bx.lifetime_start(tmp.val.llval, tmp.layout.size);
1253 op.store_with_annotation(bx, tmp);
1254 op.val = Ref(tmp.val);
1255 lifetime_ends_after_call.push((tmp.val.llval, tmp.layout.size));
1256 }
1257 }
1258 CallKind::Tail => {
1259 if let PassMode::Indirect { on_stack: false, .. } = fn_abi.args[i].mode {
1260 let Some(tmp) = tail_call_temporaries[i].take() else {
1261 ::rustc_middle::util::bug::span_bug_fmt(fn_span,
format_args!("missing temporary for indirect tail call argument #{0}", i))span_bug!(
1262 fn_span,
1263 "missing temporary for indirect tail call argument #{i}"
1264 )
1265 };
1266
1267 let local = self.mir.args_iter().nth(i).unwrap();
1268
1269 match &self.locals[local] {
1270 LocalRef::Place(arg) => {
1271 bx.typed_place_copy(arg.val, tmp.val, fn_abi.args[i].layout);
1272 op.val = Ref(arg.val);
1273 }
1274 LocalRef::Operand(arg) => {
1275 let Ref(place_value) = arg.val else {
1276 ::rustc_middle::util::bug::bug_fmt(format_args!("only `Ref` should use `PassMode::Indirect`"));bug!("only `Ref` should use `PassMode::Indirect`");
1277 };
1278 bx.typed_place_copy(place_value, tmp.val, fn_abi.args[i].layout);
1279 op.val = arg.val;
1280 }
1281 LocalRef::UnsizedPlace(_) => {
1282 ::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")
1283 }
1284 LocalRef::PendingOperand => {
1285 ::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")
1286 }
1287 };
1288
1289 bx.lifetime_end(tmp.val.llval, tmp.layout.size);
1290 }
1291 }
1292 }
1293
1294 self.codegen_argument(
1295 bx,
1296 op,
1297 &mut llargs,
1298 &fn_abi.args[i],
1299 &mut lifetime_ends_after_call,
1300 );
1301 }
1302 let num_untupled = untuple.map(|tup| {
1303 self.codegen_arguments_untupled(
1304 bx,
1305 &tup.node,
1306 &mut llargs,
1307 &fn_abi.args[first_args.len()..],
1308 &mut lifetime_ends_after_call,
1309 )
1310 });
1311
1312 let needs_location =
1313 instance.is_some_and(|i| i.def.requires_caller_location(self.cx.tcx()));
1314 if needs_location {
1315 let mir_args = if let Some(num_untupled) = num_untupled {
1316 first_args.len() + num_untupled
1317 } else {
1318 args.len()
1319 };
1320 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!(
1321 fn_abi.args.len(),
1322 mir_args + 1,
1323 "#[track_caller] fn's must have 1 more argument in their ABI than in their MIR: {instance:?} {fn_span:?} {fn_abi:?}",
1324 );
1325 let location = self.get_caller_location(bx, source_info);
1326 {
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:1326",
"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(1326u32),
::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!(
1327 "codegen_call_terminator({:?}): location={:?} (fn_span {:?})",
1328 terminator, location, fn_span
1329 );
1330
1331 let last_arg = fn_abi.args.last().unwrap();
1332 self.codegen_argument(
1333 bx,
1334 location,
1335 &mut llargs,
1336 last_arg,
1337 &mut lifetime_ends_after_call,
1338 );
1339 }
1340
1341 let fn_ptr = match (instance, llfn) {
1342 (Some(instance), None) => bx.get_fn_addr(instance),
1343 (_, Some(llfn)) => llfn,
1344 _ => ::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"),
1345 };
1346 self.set_debug_loc(bx, source_info);
1347 helper.do_call(
1348 self,
1349 bx,
1350 fn_abi,
1351 fn_ptr,
1352 &llargs,
1353 destination,
1354 unwind,
1355 &lifetime_ends_after_call,
1356 instance,
1357 kind,
1358 mergeable_succ,
1359 )
1360 }
1361
1362 fn codegen_asm_terminator(
1363 &mut self,
1364 helper: TerminatorCodegenHelper<'tcx>,
1365 bx: &mut Bx,
1366 asm_macro: InlineAsmMacro,
1367 terminator: &mir::Terminator<'tcx>,
1368 template: &[ast::InlineAsmTemplatePiece],
1369 operands: &[mir::InlineAsmOperand<'tcx>],
1370 options: ast::InlineAsmOptions,
1371 line_spans: &[Span],
1372 targets: &[mir::BasicBlock],
1373 unwind: mir::UnwindAction,
1374 instance: Instance<'_>,
1375 mergeable_succ: bool,
1376 ) -> MergingSucc {
1377 let span = terminator.source_info.span;
1378
1379 let operands: Vec<_> = operands
1380 .iter()
1381 .map(|op| match *op {
1382 mir::InlineAsmOperand::In { reg, ref value } => {
1383 let value = self.codegen_operand(bx, value);
1384 InlineAsmOperandRef::In { reg, value }
1385 }
1386 mir::InlineAsmOperand::Out { reg, late, ref place } => {
1387 let place = place.map(|place| self.codegen_place(bx, place.as_ref()));
1388 InlineAsmOperandRef::Out { reg, late, place }
1389 }
1390 mir::InlineAsmOperand::InOut { reg, late, ref in_value, ref out_place } => {
1391 let in_value = self.codegen_operand(bx, in_value);
1392 let out_place =
1393 out_place.map(|out_place| self.codegen_place(bx, out_place.as_ref()));
1394 InlineAsmOperandRef::InOut { reg, late, in_value, out_place }
1395 }
1396 mir::InlineAsmOperand::Const { ref value } => {
1397 let const_value = self.eval_mir_constant(value);
1398 let string = common::asm_const_to_str(
1399 bx.tcx(),
1400 span,
1401 const_value,
1402 bx.layout_of(value.ty()),
1403 );
1404 InlineAsmOperandRef::Const { string }
1405 }
1406 mir::InlineAsmOperand::SymFn { ref value } => {
1407 let const_ = self.monomorphize(value.const_);
1408 if let ty::FnDef(def_id, args) = *const_.ty().kind() {
1409 let instance = ty::Instance::resolve_for_fn_ptr(
1410 bx.tcx(),
1411 bx.typing_env(),
1412 def_id,
1413 args,
1414 )
1415 .unwrap();
1416 InlineAsmOperandRef::SymFn { instance }
1417 } else {
1418 ::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)");
1419 }
1420 }
1421 mir::InlineAsmOperand::SymStatic { def_id } => {
1422 InlineAsmOperandRef::SymStatic { def_id }
1423 }
1424 mir::InlineAsmOperand::Label { target_index } => {
1425 InlineAsmOperandRef::Label { label: self.llbb(targets[target_index]) }
1426 }
1427 })
1428 .collect();
1429
1430 helper.do_inlineasm(
1431 self,
1432 bx,
1433 template,
1434 &operands,
1435 options,
1436 line_spans,
1437 if asm_macro.diverges(options) { None } else { targets.get(0).copied() },
1438 unwind,
1439 instance,
1440 mergeable_succ,
1441 )
1442 }
1443
1444 pub(crate) fn codegen_block(&mut self, mut bb: mir::BasicBlock) {
1445 let llbb = match self.try_llbb(bb) {
1446 Some(llbb) => llbb,
1447 None => return,
1448 };
1449 let bx = &mut Bx::build(self.cx, llbb);
1450 let mir = self.mir;
1451
1452 loop {
1456 let data = &mir[bb];
1457
1458 {
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:1458",
"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(1458u32),
::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);
1459
1460 for statement in &data.statements {
1461 self.codegen_statement(bx, statement);
1462 }
1463 self.codegen_stmt_debuginfos(bx, &data.after_last_stmt_debuginfos);
1464
1465 let merging_succ = self.codegen_terminator(bx, bb, data.terminator());
1466 if let MergingSucc::False = merging_succ {
1467 break;
1468 }
1469
1470 let mut successors = data.terminator().successors();
1478 let succ = successors.next().unwrap();
1479 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));
1480 self.cached_llbbs[succ] = CachedLlbb::Skip;
1481 bb = succ;
1482 }
1483 }
1484
1485 pub(crate) fn codegen_block_as_unreachable(&mut self, bb: mir::BasicBlock) {
1486 let llbb = match self.try_llbb(bb) {
1487 Some(llbb) => llbb,
1488 None => return,
1489 };
1490 let bx = &mut Bx::build(self.cx, llbb);
1491 {
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:1491",
"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(1491u32),
::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);
1492 bx.unreachable();
1493 }
1494
1495 fn codegen_terminator(
1496 &mut self,
1497 bx: &mut Bx,
1498 bb: mir::BasicBlock,
1499 terminator: &'tcx mir::Terminator<'tcx>,
1500 ) -> MergingSucc {
1501 {
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:1501",
"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(1501u32),
::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);
1502
1503 let helper = TerminatorCodegenHelper { bb, terminator };
1504
1505 let mergeable_succ = || {
1506 let mut successors = terminator.successors();
1509 if let Some(succ) = successors.next()
1510 && successors.next().is_none()
1511 && let &[succ_pred] = self.mir.basic_blocks.predecessors()[succ].as_slice()
1512 {
1513 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);
1516 true
1517 } else {
1518 false
1519 }
1520 };
1521
1522 self.set_debug_loc(bx, terminator.source_info);
1523 match terminator.kind {
1524 mir::TerminatorKind::UnwindResume => {
1525 self.codegen_resume_terminator(helper, bx);
1526 MergingSucc::False
1527 }
1528
1529 mir::TerminatorKind::UnwindTerminate(reason) => {
1530 self.codegen_terminate_terminator(helper, bx, terminator, reason);
1531 MergingSucc::False
1532 }
1533
1534 mir::TerminatorKind::Goto { target } => {
1535 helper.funclet_br(self, bx, target, mergeable_succ())
1536 }
1537
1538 mir::TerminatorKind::SwitchInt { ref discr, ref targets } => {
1539 self.codegen_switchint_terminator(helper, bx, discr, targets);
1540 MergingSucc::False
1541 }
1542
1543 mir::TerminatorKind::Return => {
1544 self.codegen_return_terminator(bx);
1545 MergingSucc::False
1546 }
1547
1548 mir::TerminatorKind::Unreachable => {
1549 bx.unreachable();
1550 MergingSucc::False
1551 }
1552
1553 mir::TerminatorKind::Drop { place, target, unwind, replace: _, drop, async_fut } => {
1554 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!(
1555 async_fut.is_none() && drop.is_none(),
1556 "Async Drop must be expanded or reset to sync before codegen"
1557 );
1558 self.codegen_drop_terminator(
1559 helper,
1560 bx,
1561 &terminator.source_info,
1562 place,
1563 target,
1564 unwind,
1565 mergeable_succ(),
1566 )
1567 }
1568
1569 mir::TerminatorKind::Assert { ref cond, expected, ref msg, target, unwind } => self
1570 .codegen_assert_terminator(
1571 helper,
1572 bx,
1573 terminator,
1574 cond,
1575 expected,
1576 msg,
1577 target,
1578 unwind,
1579 mergeable_succ(),
1580 ),
1581
1582 mir::TerminatorKind::Call {
1583 ref func,
1584 ref args,
1585 destination,
1586 target,
1587 unwind,
1588 call_source: _,
1589 fn_span,
1590 } => self.codegen_call_terminator(
1591 helper,
1592 bx,
1593 terminator,
1594 func,
1595 args,
1596 destination,
1597 target,
1598 unwind,
1599 fn_span,
1600 CallKind::Normal,
1601 mergeable_succ(),
1602 ),
1603 mir::TerminatorKind::TailCall { ref func, ref args, fn_span } => self
1604 .codegen_call_terminator(
1605 helper,
1606 bx,
1607 terminator,
1608 func,
1609 args,
1610 mir::Place::from(mir::RETURN_PLACE),
1611 None,
1612 mir::UnwindAction::Unreachable,
1613 fn_span,
1614 CallKind::Tail,
1615 mergeable_succ(),
1616 ),
1617 mir::TerminatorKind::CoroutineDrop | mir::TerminatorKind::Yield { .. } => {
1618 ::rustc_middle::util::bug::bug_fmt(format_args!("coroutine ops in codegen"))bug!("coroutine ops in codegen")
1619 }
1620 mir::TerminatorKind::FalseEdge { .. } | mir::TerminatorKind::FalseUnwind { .. } => {
1621 ::rustc_middle::util::bug::bug_fmt(format_args!("borrowck false edges in codegen"))bug!("borrowck false edges in codegen")
1622 }
1623
1624 mir::TerminatorKind::InlineAsm {
1625 asm_macro,
1626 template,
1627 ref operands,
1628 options,
1629 line_spans,
1630 ref targets,
1631 unwind,
1632 } => self.codegen_asm_terminator(
1633 helper,
1634 bx,
1635 asm_macro,
1636 terminator,
1637 template,
1638 operands,
1639 options,
1640 line_spans,
1641 targets,
1642 unwind,
1643 self.instance,
1644 mergeable_succ(),
1645 ),
1646 }
1647 }
1648
1649 fn codegen_argument(
1650 &mut self,
1651 bx: &mut Bx,
1652 op: OperandRef<'tcx, Bx::Value>,
1653 llargs: &mut Vec<Bx::Value>,
1654 arg: &ArgAbi<'tcx, Ty<'tcx>>,
1655 lifetime_ends_after_call: &mut Vec<(Bx::Value, Size)>,
1656 ) {
1657 match arg.mode {
1658 PassMode::Ignore => return,
1659 PassMode::Cast { pad_i32: true, .. } => {
1660 llargs.push(bx.const_undef(bx.reg_backend_type(&Reg::i32())));
1662 }
1663 PassMode::Pair(..) => match op.val {
1664 Pair(a, b) => {
1665 llargs.push(a);
1666 llargs.push(b);
1667 return;
1668 }
1669 _ => ::rustc_middle::util::bug::bug_fmt(format_args!("codegen_argument: {0:?} invalid for pair argument",
op))bug!("codegen_argument: {:?} invalid for pair argument", op),
1670 },
1671 PassMode::Indirect { attrs: _, meta_attrs: Some(_), on_stack: _ } => match op.val {
1672 Ref(PlaceValue { llval: a, llextra: Some(b), .. }) => {
1673 llargs.push(a);
1674 llargs.push(b);
1675 return;
1676 }
1677 _ => ::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),
1678 },
1679 _ => {}
1680 }
1681
1682 let (mut llval, align, by_ref) = match op.val {
1684 Immediate(_) | Pair(..) => match arg.mode {
1685 PassMode::Indirect { attrs, .. } => {
1686 let required_align = match attrs.pointee_align {
1690 Some(pointee_align) => cmp::max(pointee_align, arg.layout.align.abi),
1691 None => arg.layout.align.abi,
1692 };
1693 let scratch = PlaceValue::alloca(bx, arg.layout.size, required_align);
1694 bx.lifetime_start(scratch.llval, arg.layout.size);
1695 op.store_with_annotation(bx, scratch.with_type(arg.layout));
1696 lifetime_ends_after_call.push((scratch.llval, arg.layout.size));
1697 (scratch.llval, scratch.align, true)
1698 }
1699 PassMode::Cast { .. } => {
1700 let scratch = PlaceRef::alloca(bx, arg.layout);
1701 op.store_with_annotation(bx, scratch);
1702 (scratch.val.llval, scratch.val.align, true)
1703 }
1704 _ => (op.immediate_or_packed_pair(bx), arg.layout.align.abi, false),
1705 },
1706 Ref(op_place_val) => match arg.mode {
1707 PassMode::Indirect { attrs, .. } => {
1708 let required_align = match attrs.pointee_align {
1709 Some(pointee_align) => cmp::max(pointee_align, arg.layout.align.abi),
1710 None => arg.layout.align.abi,
1711 };
1712 if op_place_val.align < required_align {
1713 let scratch = PlaceValue::alloca(bx, arg.layout.size, required_align);
1717 bx.lifetime_start(scratch.llval, arg.layout.size);
1718 bx.typed_place_copy(scratch, op_place_val, op.layout);
1719 lifetime_ends_after_call.push((scratch.llval, arg.layout.size));
1720 (scratch.llval, scratch.align, true)
1721 } else {
1722 (op_place_val.llval, op_place_val.align, true)
1723 }
1724 }
1725 _ => (op_place_val.llval, op_place_val.align, true),
1726 },
1727 ZeroSized => match arg.mode {
1728 PassMode::Indirect { on_stack, .. } => {
1729 if on_stack {
1730 ::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:?}");
1733 }
1734 let scratch = PlaceRef::alloca(bx, arg.layout);
1738 (scratch.val.llval, scratch.val.align, true)
1739 }
1740 _ => ::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:?}"),
1741 },
1742 };
1743
1744 if by_ref && !arg.is_indirect() {
1745 if let PassMode::Cast { cast, pad_i32: _ } = &arg.mode {
1747 let scratch_size = cast.size(bx);
1751 let scratch_align = cast.align(bx);
1752 let copy_bytes = cmp::min(cast.unaligned_size(bx).bytes(), arg.layout.size.bytes());
1759 let llscratch = bx.alloca(scratch_size, scratch_align);
1761 bx.lifetime_start(llscratch, scratch_size);
1762 bx.memcpy(
1764 llscratch,
1765 scratch_align,
1766 llval,
1767 align,
1768 bx.const_usize(copy_bytes),
1769 MemFlags::empty(),
1770 None,
1771 );
1772 llval = load_cast(bx, cast, llscratch, scratch_align);
1774 bx.lifetime_end(llscratch, scratch_size);
1775 } else {
1776 llval = bx.load(bx.backend_type(arg.layout), llval, align);
1782 if let BackendRepr::Scalar(scalar) = arg.layout.backend_repr {
1783 if scalar.is_bool() {
1784 bx.range_metadata(llval, WrappingRange { start: 0, end: 1 });
1785 }
1786 llval = bx.to_immediate_scalar(llval, scalar);
1788 }
1789 }
1790 }
1791
1792 llargs.push(llval);
1793 }
1794
1795 fn codegen_arguments_untupled(
1796 &mut self,
1797 bx: &mut Bx,
1798 operand: &mir::Operand<'tcx>,
1799 llargs: &mut Vec<Bx::Value>,
1800 args: &[ArgAbi<'tcx, Ty<'tcx>>],
1801 lifetime_ends_after_call: &mut Vec<(Bx::Value, Size)>,
1802 ) -> usize {
1803 let tuple = self.codegen_operand(bx, operand);
1804
1805 if let Ref(place_val) = tuple.val {
1807 if place_val.llextra.is_some() {
1808 ::rustc_middle::util::bug::bug_fmt(format_args!("closure arguments must be sized"));bug!("closure arguments must be sized");
1809 }
1810 let tuple_ptr = place_val.with_type(tuple.layout);
1811 for i in 0..tuple.layout.fields.count() {
1812 let field_ptr = tuple_ptr.project_field(bx, i);
1813 let field = bx.load_operand(field_ptr);
1814 self.codegen_argument(bx, field, llargs, &args[i], lifetime_ends_after_call);
1815 }
1816 } else {
1817 for i in 0..tuple.layout.fields.count() {
1819 let op = tuple.extract_field(self, bx, i);
1820 self.codegen_argument(bx, op, llargs, &args[i], lifetime_ends_after_call);
1821 }
1822 }
1823 tuple.layout.fields.count()
1824 }
1825
1826 pub(super) fn get_caller_location(
1827 &mut self,
1828 bx: &mut Bx,
1829 source_info: mir::SourceInfo,
1830 ) -> OperandRef<'tcx, Bx::Value> {
1831 self.mir.caller_location_span(source_info, self.caller_location, bx.tcx(), |span: Span| {
1832 let const_loc = bx.tcx().span_as_caller_location(span);
1833 OperandRef::from_const(bx, const_loc, bx.tcx().caller_location_ty())
1834 })
1835 }
1836
1837 fn get_personality_slot(&mut self, bx: &mut Bx) -> PlaceRef<'tcx, Bx::Value> {
1838 let cx = bx.cx();
1839 if let Some(slot) = self.personality_slot {
1840 slot
1841 } else {
1842 let layout = cx.layout_of(Ty::new_tup(
1843 cx.tcx(),
1844 &[Ty::new_mut_ptr(cx.tcx(), cx.tcx().types.u8), cx.tcx().types.i32],
1845 ));
1846 let slot = PlaceRef::alloca(bx, layout);
1847 self.personality_slot = Some(slot);
1848 slot
1849 }
1850 }
1851
1852 fn landing_pad_for(&mut self, bb: mir::BasicBlock) -> Bx::BasicBlock {
1855 if let Some(landing_pad) = self.landing_pads[bb] {
1856 return landing_pad;
1857 }
1858
1859 let landing_pad = self.landing_pad_for_uncached(bb);
1860 self.landing_pads[bb] = Some(landing_pad);
1861 landing_pad
1862 }
1863
1864 fn landing_pad_for_uncached(&mut self, bb: mir::BasicBlock) -> Bx::BasicBlock {
1866 let llbb = self.llbb(bb);
1867 if base::wants_new_eh_instructions(self.cx.sess()) {
1868 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:?}"));
1869 let mut cleanup_bx = Bx::build(self.cx, cleanup_bb);
1870 let funclet = cleanup_bx.cleanup_pad(None, &[]);
1871 cleanup_bx.br(llbb);
1872 self.funclets[bb] = Some(funclet);
1873 cleanup_bb
1874 } else {
1875 let cleanup_llbb = Bx::append_block(self.cx, self.llfn, "cleanup");
1876 let mut cleanup_bx = Bx::build(self.cx, cleanup_llbb);
1877
1878 let llpersonality = self.cx.eh_personality();
1879 let (exn0, exn1) = cleanup_bx.cleanup_landing_pad(llpersonality);
1880
1881 let slot = self.get_personality_slot(&mut cleanup_bx);
1882 slot.storage_live(&mut cleanup_bx);
1883 Pair(exn0, exn1).store(&mut cleanup_bx, slot);
1884
1885 cleanup_bx.br(llbb);
1886 cleanup_llbb
1887 }
1888 }
1889
1890 fn unreachable_block(&mut self) -> Bx::BasicBlock {
1891 self.unreachable_block.unwrap_or_else(|| {
1892 let llbb = Bx::append_block(self.cx, self.llfn, "unreachable");
1893 let mut bx = Bx::build(self.cx, llbb);
1894 bx.unreachable();
1895 self.unreachable_block = Some(llbb);
1896 llbb
1897 })
1898 }
1899
1900 fn terminate_block(
1901 &mut self,
1902 reason: UnwindTerminateReason,
1903 outer_catchpad_bb: Option<mir::BasicBlock>,
1904 ) -> Bx::BasicBlock {
1905 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!(
1910 outer_catchpad_bb.is_some()
1911 == (base::wants_wasm_eh(self.cx.tcx().sess)
1912 && reason == UnwindTerminateReason::InCleanup)
1913 );
1914
1915 let mut cache_bb = mir::START_BLOCK;
1918 if let Some(outer_bb) = outer_catchpad_bb {
1921 let cleanup_kinds =
1922 self.cleanup_kinds.as_ref().expect("cleanup_kinds required for funclets");
1923 cache_bb = cleanup_kinds[outer_bb]
1924 .funclet_bb(outer_bb)
1925 .expect("funclet_bb should be in a funclet");
1926
1927 if self.funclets[cache_bb].is_none() {
1929 self.landing_pad_for(cache_bb);
1930 }
1931 }
1932 if let Some((cached_bb, cached_reason)) = self.terminate_blocks[cache_bb]
1933 && reason == cached_reason
1934 {
1935 return cached_bb;
1936 }
1937
1938 let funclet;
1939 let llbb;
1940 let mut bx;
1941 if base::wants_new_eh_instructions(self.cx.sess()) {
1942 llbb = Bx::append_block(self.cx, self.llfn, "cs_terminate");
1982
1983 let mut cs_bx = Bx::build(self.cx, llbb);
1984
1985 let mut outer_cleanuppad = None;
1989 if outer_catchpad_bb.is_some() {
1990 let outer_funclet = self.funclets[cache_bb]
1992 .as_ref()
1993 .expect("landing_pad_for didn't create funclet");
1994 outer_cleanuppad = Some(cs_bx.get_funclet_cleanuppad(outer_funclet));
1995 }
1996 let cp_llbb = Bx::append_block(self.cx, self.llfn, "cp_terminate");
1997 let cs = cs_bx.catch_switch(outer_cleanuppad, None, &[cp_llbb]);
1998 drop(cs_bx);
1999
2000 bx = Bx::build(self.cx, cp_llbb);
2001 let null =
2002 bx.const_null(bx.type_ptr_ext(bx.cx().data_layout().instruction_address_space));
2003
2004 let args = if base::wants_msvc_seh(self.cx.sess()) {
2008 let adjectives = bx.const_i32(0x40);
2015 &[null, adjectives, null] as &[_]
2016 } else {
2017 &[null] as &[_]
2023 };
2024
2025 funclet = Some(bx.catch_pad(cs, args));
2026 } else {
2032 llbb = Bx::append_block(self.cx, self.llfn, "terminate");
2033 bx = Bx::build(self.cx, llbb);
2034
2035 let llpersonality = self.cx.eh_personality();
2036 bx.filter_landing_pad(llpersonality);
2037
2038 funclet = None;
2039 }
2040
2041 self.set_debug_loc(&mut bx, mir::SourceInfo::outermost(self.mir.span));
2042
2043 let (fn_abi, fn_ptr, instance) =
2044 common::build_langcall(&bx, self.mir.span, reason.lang_item());
2045 if is_call_from_compiler_builtins_to_upstream_monomorphization(bx.tcx(), instance) {
2046 bx.abort();
2047 } else {
2048 let fn_ty = bx.fn_decl_backend_type(fn_abi);
2049
2050 let llret = bx.call(fn_ty, None, Some(fn_abi), fn_ptr, &[], funclet.as_ref(), None);
2051 bx.apply_attrs_to_cleanup_callsite(llret);
2052 }
2053
2054 bx.unreachable();
2055
2056 self.terminate_blocks[cache_bb] = Some((llbb, reason));
2057 llbb
2058 }
2059
2060 pub fn llbb(&mut self, bb: mir::BasicBlock) -> Bx::BasicBlock {
2065 self.try_llbb(bb).unwrap()
2066 }
2067
2068 pub(crate) fn try_llbb(&mut self, bb: mir::BasicBlock) -> Option<Bx::BasicBlock> {
2070 match self.cached_llbbs[bb] {
2071 CachedLlbb::None => {
2072 let llbb = Bx::append_block(self.cx, self.llfn, &::alloc::__export::must_use({
::alloc::fmt::format(format_args!("{0:?}", bb))
})format!("{bb:?}"));
2073 self.cached_llbbs[bb] = CachedLlbb::Some(llbb);
2074 Some(llbb)
2075 }
2076 CachedLlbb::Some(llbb) => Some(llbb),
2077 CachedLlbb::Skip => None,
2078 }
2079 }
2080
2081 fn make_return_dest(
2082 &mut self,
2083 bx: &mut Bx,
2084 dest: mir::Place<'tcx>,
2085 fn_ret: &ArgAbi<'tcx, Ty<'tcx>>,
2086 llargs: &mut Vec<Bx::Value>,
2087 ) -> ReturnDest<'tcx, Bx::Value> {
2088 if fn_ret.is_ignore() {
2090 return ReturnDest::Nothing;
2091 }
2092 let dest = if let Some(index) = dest.as_local() {
2093 match self.locals[index] {
2094 LocalRef::Place(dest) => dest,
2095 LocalRef::UnsizedPlace(_) => ::rustc_middle::util::bug::bug_fmt(format_args!("return type must be sized"))bug!("return type must be sized"),
2096 LocalRef::PendingOperand => {
2097 return if fn_ret.is_indirect() {
2100 let tmp = PlaceRef::alloca(bx, fn_ret.layout);
2103 tmp.storage_live(bx);
2104 llargs.push(tmp.val.llval);
2105 ReturnDest::IndirectOperand(tmp, index)
2106 } else {
2107 ReturnDest::DirectOperand(index)
2108 };
2109 }
2110 LocalRef::Operand(_) => {
2111 ::rustc_middle::util::bug::bug_fmt(format_args!("place local already assigned to"));bug!("place local already assigned to");
2112 }
2113 }
2114 } else {
2115 self.codegen_place(bx, dest.as_ref())
2116 };
2117 if fn_ret.is_indirect() {
2118 if dest.val.align < dest.layout.align.abi {
2119 ::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");
2126 }
2127 llargs.push(dest.val.llval);
2128 ReturnDest::Nothing
2129 } else {
2130 ReturnDest::Store(dest)
2131 }
2132 }
2133
2134 fn store_return(
2136 &mut self,
2137 bx: &mut Bx,
2138 dest: ReturnDest<'tcx, Bx::Value>,
2139 ret_abi: &ArgAbi<'tcx, Ty<'tcx>>,
2140 llval: Bx::Value,
2141 ) {
2142 use self::ReturnDest::*;
2143
2144 match dest {
2145 Nothing => (),
2146 Store(dst) => bx.store_arg(ret_abi, llval, dst),
2147 IndirectOperand(tmp, index) => {
2148 let op = bx.load_operand(tmp);
2149 tmp.storage_dead(bx);
2150 self.overwrite_local(index, LocalRef::Operand(op));
2151 self.debug_introduce_local(bx, index);
2152 }
2153 DirectOperand(index) => {
2154 let op = if let PassMode::Cast { .. } = ret_abi.mode {
2156 let tmp = PlaceRef::alloca(bx, ret_abi.layout);
2157 tmp.storage_live(bx);
2158 bx.store_arg(ret_abi, llval, tmp);
2159 let op = bx.load_operand(tmp);
2160 tmp.storage_dead(bx);
2161 op
2162 } else {
2163 OperandRef::from_immediate_or_packed_pair(bx, llval, ret_abi.layout)
2164 };
2165 self.overwrite_local(index, LocalRef::Operand(op));
2166 self.debug_introduce_local(bx, index);
2167 }
2168 }
2169 }
2170}
2171
2172enum ReturnDest<'tcx, V> {
2173 Nothing,
2175 Store(PlaceRef<'tcx, V>),
2177 IndirectOperand(PlaceRef<'tcx, V>, mir::Local),
2179 DirectOperand(mir::Local),
2181}
2182
2183fn load_cast<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
2184 bx: &mut Bx,
2185 cast: &CastTarget,
2186 ptr: Bx::Value,
2187 align: Align,
2188) -> Bx::Value {
2189 let cast_ty = bx.cast_backend_type(cast);
2190 if let Some(offset_from_start) = cast.rest_offset {
2191 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()));
2192 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);
2193 let first_ty = bx.reg_backend_type(&cast.prefix[0].unwrap());
2194 let second_ty = bx.reg_backend_type(&cast.rest.unit);
2195 let first = bx.load(first_ty, ptr, align);
2196 let second_ptr = bx.inbounds_ptradd(ptr, bx.const_usize(offset_from_start.bytes()));
2197 let second = bx.load(second_ty, second_ptr, align.restrict_for_offset(offset_from_start));
2198 let res = bx.cx().const_poison(cast_ty);
2199 let res = bx.insert_value(res, first, 0);
2200 bx.insert_value(res, second, 1)
2201 } else {
2202 bx.load(cast_ty, ptr, align)
2203 }
2204}
2205
2206pub fn store_cast<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
2207 bx: &mut Bx,
2208 cast: &CastTarget,
2209 value: Bx::Value,
2210 ptr: Bx::Value,
2211 align: Align,
2212) {
2213 if let Some(offset_from_start) = cast.rest_offset {
2214 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()));
2215 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);
2216 if !cast.prefix[0].is_some() {
::core::panicking::panic("assertion failed: cast.prefix[0].is_some()")
};assert!(cast.prefix[0].is_some());
2217 let first = bx.extract_value(value, 0);
2218 let second = bx.extract_value(value, 1);
2219 bx.store(first, ptr, align);
2220 let second_ptr = bx.inbounds_ptradd(ptr, bx.const_usize(offset_from_start.bytes()));
2221 bx.store(second, second_ptr, align.restrict_for_offset(offset_from_start));
2222 } else {
2223 bx.store(value, ptr, align);
2224 };
2225}