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 match fn_abi.args[i].mode {
1260 PassMode::Indirect { on_stack: false, .. } => {
1261 let Some(tmp) = tail_call_temporaries[i].take() else {
1262 ::rustc_middle::util::bug::span_bug_fmt(fn_span,
format_args!("missing temporary for indirect tail call argument #{0}", i))span_bug!(
1263 fn_span,
1264 "missing temporary for indirect tail call argument #{i}"
1265 )
1266 };
1267
1268 let local = self.mir.args_iter().nth(i).unwrap();
1269
1270 match &self.locals[local] {
1271 LocalRef::Place(arg) => {
1272 bx.typed_place_copy(arg.val, tmp.val, fn_abi.args[i].layout);
1273 op.val = Ref(arg.val);
1274 }
1275 LocalRef::Operand(arg) => {
1276 let Ref(place_value) = arg.val else {
1277 ::rustc_middle::util::bug::bug_fmt(format_args!("only `Ref` should use `PassMode::Indirect`"));bug!("only `Ref` should use `PassMode::Indirect`");
1278 };
1279 bx.typed_place_copy(
1280 place_value,
1281 tmp.val,
1282 fn_abi.args[i].layout,
1283 );
1284 op.val = arg.val;
1285 }
1286 LocalRef::UnsizedPlace(_) => {
1287 ::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")
1288 }
1289 LocalRef::PendingOperand => {
1290 ::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")
1291 }
1292 };
1293
1294 bx.lifetime_end(tmp.val.llval, tmp.layout.size);
1295 }
1296 PassMode::Indirect { on_stack: true, .. } => {
1297 ::rustc_middle::util::bug::span_bug_fmt(fn_span,
format_args!("arguments using PassMode::Indirect {{ on_stack: true, .. }} are currently not supported for tail calls"))span_bug!(
1303 fn_span,
1304 "arguments using PassMode::Indirect {{ on_stack: true, .. }} are currently not supported for tail calls"
1305 )
1306 }
1307 _ => (),
1308 }
1309 }
1310 }
1311
1312 self.codegen_argument(
1313 bx,
1314 op,
1315 &mut llargs,
1316 &fn_abi.args[i],
1317 &mut lifetime_ends_after_call,
1318 );
1319 }
1320 let num_untupled = untuple.map(|tup| {
1321 self.codegen_arguments_untupled(
1322 bx,
1323 &tup.node,
1324 &mut llargs,
1325 &fn_abi.args[first_args.len()..],
1326 &mut lifetime_ends_after_call,
1327 )
1328 });
1329
1330 let needs_location =
1331 instance.is_some_and(|i| i.def.requires_caller_location(self.cx.tcx()));
1332 if needs_location {
1333 let mir_args = if let Some(num_untupled) = num_untupled {
1334 first_args.len() + num_untupled
1335 } else {
1336 args.len()
1337 };
1338 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!(
1339 fn_abi.args.len(),
1340 mir_args + 1,
1341 "#[track_caller] fn's must have 1 more argument in their ABI than in their MIR: {instance:?} {fn_span:?} {fn_abi:?}",
1342 );
1343 let location = self.get_caller_location(bx, source_info);
1344 {
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:1344",
"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(1344u32),
::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!(
1345 "codegen_call_terminator({:?}): location={:?} (fn_span {:?})",
1346 terminator, location, fn_span
1347 );
1348
1349 let last_arg = fn_abi.args.last().unwrap();
1350 self.codegen_argument(
1351 bx,
1352 location,
1353 &mut llargs,
1354 last_arg,
1355 &mut lifetime_ends_after_call,
1356 );
1357 }
1358
1359 let fn_ptr = match (instance, llfn) {
1360 (Some(instance), None) => bx.get_fn_addr(instance),
1361 (_, Some(llfn)) => llfn,
1362 _ => ::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"),
1363 };
1364 self.set_debug_loc(bx, source_info);
1365 helper.do_call(
1366 self,
1367 bx,
1368 fn_abi,
1369 fn_ptr,
1370 &llargs,
1371 destination,
1372 unwind,
1373 &lifetime_ends_after_call,
1374 instance,
1375 kind,
1376 mergeable_succ,
1377 )
1378 }
1379
1380 fn codegen_asm_terminator(
1381 &mut self,
1382 helper: TerminatorCodegenHelper<'tcx>,
1383 bx: &mut Bx,
1384 asm_macro: InlineAsmMacro,
1385 terminator: &mir::Terminator<'tcx>,
1386 template: &[ast::InlineAsmTemplatePiece],
1387 operands: &[mir::InlineAsmOperand<'tcx>],
1388 options: ast::InlineAsmOptions,
1389 line_spans: &[Span],
1390 targets: &[mir::BasicBlock],
1391 unwind: mir::UnwindAction,
1392 instance: Instance<'_>,
1393 mergeable_succ: bool,
1394 ) -> MergingSucc {
1395 let span = terminator.source_info.span;
1396
1397 let operands: Vec<_> = operands
1398 .iter()
1399 .map(|op| match *op {
1400 mir::InlineAsmOperand::In { reg, ref value } => {
1401 let value = self.codegen_operand(bx, value);
1402 InlineAsmOperandRef::In { reg, value }
1403 }
1404 mir::InlineAsmOperand::Out { reg, late, ref place } => {
1405 let place = place.map(|place| self.codegen_place(bx, place.as_ref()));
1406 InlineAsmOperandRef::Out { reg, late, place }
1407 }
1408 mir::InlineAsmOperand::InOut { reg, late, ref in_value, ref out_place } => {
1409 let in_value = self.codegen_operand(bx, in_value);
1410 let out_place =
1411 out_place.map(|out_place| self.codegen_place(bx, out_place.as_ref()));
1412 InlineAsmOperandRef::InOut { reg, late, in_value, out_place }
1413 }
1414 mir::InlineAsmOperand::Const { ref value } => {
1415 let const_value = self.eval_mir_constant(value);
1416 let string = common::asm_const_to_str(
1417 bx.tcx(),
1418 span,
1419 const_value,
1420 bx.layout_of(value.ty()),
1421 );
1422 InlineAsmOperandRef::Const { string }
1423 }
1424 mir::InlineAsmOperand::SymFn { ref value } => {
1425 let const_ = self.monomorphize(value.const_);
1426 if let ty::FnDef(def_id, args) = *const_.ty().kind() {
1427 let instance = ty::Instance::resolve_for_fn_ptr(
1428 bx.tcx(),
1429 bx.typing_env(),
1430 def_id,
1431 args,
1432 )
1433 .unwrap();
1434 InlineAsmOperandRef::SymFn { instance }
1435 } else {
1436 ::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)");
1437 }
1438 }
1439 mir::InlineAsmOperand::SymStatic { def_id } => {
1440 InlineAsmOperandRef::SymStatic { def_id }
1441 }
1442 mir::InlineAsmOperand::Label { target_index } => {
1443 InlineAsmOperandRef::Label { label: self.llbb(targets[target_index]) }
1444 }
1445 })
1446 .collect();
1447
1448 helper.do_inlineasm(
1449 self,
1450 bx,
1451 template,
1452 &operands,
1453 options,
1454 line_spans,
1455 if asm_macro.diverges(options) { None } else { targets.get(0).copied() },
1456 unwind,
1457 instance,
1458 mergeable_succ,
1459 )
1460 }
1461
1462 pub(crate) fn codegen_block(&mut self, mut bb: mir::BasicBlock) {
1463 let llbb = match self.try_llbb(bb) {
1464 Some(llbb) => llbb,
1465 None => return,
1466 };
1467 let bx = &mut Bx::build(self.cx, llbb);
1468 let mir = self.mir;
1469
1470 loop {
1474 let data = &mir[bb];
1475
1476 {
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:1476",
"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(1476u32),
::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);
1477
1478 for statement in &data.statements {
1479 self.codegen_statement(bx, statement);
1480 }
1481 self.codegen_stmt_debuginfos(bx, &data.after_last_stmt_debuginfos);
1482
1483 let merging_succ = self.codegen_terminator(bx, bb, data.terminator());
1484 if let MergingSucc::False = merging_succ {
1485 break;
1486 }
1487
1488 let mut successors = data.terminator().successors();
1496 let succ = successors.next().unwrap();
1497 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));
1498 self.cached_llbbs[succ] = CachedLlbb::Skip;
1499 bb = succ;
1500 }
1501 }
1502
1503 pub(crate) fn codegen_block_as_unreachable(&mut self, bb: mir::BasicBlock) {
1504 let llbb = match self.try_llbb(bb) {
1505 Some(llbb) => llbb,
1506 None => return,
1507 };
1508 let bx = &mut Bx::build(self.cx, llbb);
1509 {
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:1509",
"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(1509u32),
::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);
1510 bx.unreachable();
1511 }
1512
1513 fn codegen_terminator(
1514 &mut self,
1515 bx: &mut Bx,
1516 bb: mir::BasicBlock,
1517 terminator: &'tcx mir::Terminator<'tcx>,
1518 ) -> MergingSucc {
1519 {
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:1519",
"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(1519u32),
::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);
1520
1521 let helper = TerminatorCodegenHelper { bb, terminator };
1522
1523 let mergeable_succ = || {
1524 let mut successors = terminator.successors();
1527 if let Some(succ) = successors.next()
1528 && successors.next().is_none()
1529 && let &[succ_pred] = self.mir.basic_blocks.predecessors()[succ].as_slice()
1530 {
1531 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);
1534 true
1535 } else {
1536 false
1537 }
1538 };
1539
1540 self.set_debug_loc(bx, terminator.source_info);
1541 match terminator.kind {
1542 mir::TerminatorKind::UnwindResume => {
1543 self.codegen_resume_terminator(helper, bx);
1544 MergingSucc::False
1545 }
1546
1547 mir::TerminatorKind::UnwindTerminate(reason) => {
1548 self.codegen_terminate_terminator(helper, bx, terminator, reason);
1549 MergingSucc::False
1550 }
1551
1552 mir::TerminatorKind::Goto { target } => {
1553 helper.funclet_br(self, bx, target, mergeable_succ())
1554 }
1555
1556 mir::TerminatorKind::SwitchInt { ref discr, ref targets } => {
1557 self.codegen_switchint_terminator(helper, bx, discr, targets);
1558 MergingSucc::False
1559 }
1560
1561 mir::TerminatorKind::Return => {
1562 self.codegen_return_terminator(bx);
1563 MergingSucc::False
1564 }
1565
1566 mir::TerminatorKind::Unreachable => {
1567 bx.unreachable();
1568 MergingSucc::False
1569 }
1570
1571 mir::TerminatorKind::Drop { place, target, unwind, replace: _, drop, async_fut } => {
1572 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!(
1573 async_fut.is_none() && drop.is_none(),
1574 "Async Drop must be expanded or reset to sync before codegen"
1575 );
1576 self.codegen_drop_terminator(
1577 helper,
1578 bx,
1579 &terminator.source_info,
1580 place,
1581 target,
1582 unwind,
1583 mergeable_succ(),
1584 )
1585 }
1586
1587 mir::TerminatorKind::Assert { ref cond, expected, ref msg, target, unwind } => self
1588 .codegen_assert_terminator(
1589 helper,
1590 bx,
1591 terminator,
1592 cond,
1593 expected,
1594 msg,
1595 target,
1596 unwind,
1597 mergeable_succ(),
1598 ),
1599
1600 mir::TerminatorKind::Call {
1601 ref func,
1602 ref args,
1603 destination,
1604 target,
1605 unwind,
1606 call_source: _,
1607 fn_span,
1608 } => self.codegen_call_terminator(
1609 helper,
1610 bx,
1611 terminator,
1612 func,
1613 args,
1614 destination,
1615 target,
1616 unwind,
1617 fn_span,
1618 CallKind::Normal,
1619 mergeable_succ(),
1620 ),
1621 mir::TerminatorKind::TailCall { ref func, ref args, fn_span } => self
1622 .codegen_call_terminator(
1623 helper,
1624 bx,
1625 terminator,
1626 func,
1627 args,
1628 mir::Place::from(mir::RETURN_PLACE),
1629 None,
1630 mir::UnwindAction::Unreachable,
1631 fn_span,
1632 CallKind::Tail,
1633 mergeable_succ(),
1634 ),
1635 mir::TerminatorKind::CoroutineDrop | mir::TerminatorKind::Yield { .. } => {
1636 ::rustc_middle::util::bug::bug_fmt(format_args!("coroutine ops in codegen"))bug!("coroutine ops in codegen")
1637 }
1638 mir::TerminatorKind::FalseEdge { .. } | mir::TerminatorKind::FalseUnwind { .. } => {
1639 ::rustc_middle::util::bug::bug_fmt(format_args!("borrowck false edges in codegen"))bug!("borrowck false edges in codegen")
1640 }
1641
1642 mir::TerminatorKind::InlineAsm {
1643 asm_macro,
1644 template,
1645 ref operands,
1646 options,
1647 line_spans,
1648 ref targets,
1649 unwind,
1650 } => self.codegen_asm_terminator(
1651 helper,
1652 bx,
1653 asm_macro,
1654 terminator,
1655 template,
1656 operands,
1657 options,
1658 line_spans,
1659 targets,
1660 unwind,
1661 self.instance,
1662 mergeable_succ(),
1663 ),
1664 }
1665 }
1666
1667 fn codegen_argument(
1668 &mut self,
1669 bx: &mut Bx,
1670 op: OperandRef<'tcx, Bx::Value>,
1671 llargs: &mut Vec<Bx::Value>,
1672 arg: &ArgAbi<'tcx, Ty<'tcx>>,
1673 lifetime_ends_after_call: &mut Vec<(Bx::Value, Size)>,
1674 ) {
1675 match arg.mode {
1676 PassMode::Ignore => return,
1677 PassMode::Cast { pad_i32: true, .. } => {
1678 llargs.push(bx.const_undef(bx.reg_backend_type(&Reg::i32())));
1680 }
1681 PassMode::Pair(..) => match op.val {
1682 Pair(a, b) => {
1683 llargs.push(a);
1684 llargs.push(b);
1685 return;
1686 }
1687 _ => ::rustc_middle::util::bug::bug_fmt(format_args!("codegen_argument: {0:?} invalid for pair argument",
op))bug!("codegen_argument: {:?} invalid for pair argument", op),
1688 },
1689 PassMode::Indirect { attrs: _, meta_attrs: Some(_), on_stack: _ } => match op.val {
1690 Ref(PlaceValue { llval: a, llextra: Some(b), .. }) => {
1691 llargs.push(a);
1692 llargs.push(b);
1693 return;
1694 }
1695 _ => ::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),
1696 },
1697 _ => {}
1698 }
1699
1700 let (mut llval, align, by_ref) = match op.val {
1702 Immediate(_) | Pair(..) => match arg.mode {
1703 PassMode::Indirect { attrs, .. } => {
1704 let required_align = match attrs.pointee_align {
1708 Some(pointee_align) => cmp::max(pointee_align, arg.layout.align.abi),
1709 None => arg.layout.align.abi,
1710 };
1711 let scratch = PlaceValue::alloca(bx, arg.layout.size, required_align);
1712 bx.lifetime_start(scratch.llval, arg.layout.size);
1713 op.store_with_annotation(bx, scratch.with_type(arg.layout));
1714 lifetime_ends_after_call.push((scratch.llval, arg.layout.size));
1715 (scratch.llval, scratch.align, true)
1716 }
1717 PassMode::Cast { .. } => {
1718 let scratch = PlaceRef::alloca(bx, arg.layout);
1719 op.store_with_annotation(bx, scratch);
1720 (scratch.val.llval, scratch.val.align, true)
1721 }
1722 _ => (op.immediate_or_packed_pair(bx), arg.layout.align.abi, false),
1723 },
1724 Ref(op_place_val) => match arg.mode {
1725 PassMode::Indirect { attrs, .. } => {
1726 let required_align = match attrs.pointee_align {
1727 Some(pointee_align) => cmp::max(pointee_align, arg.layout.align.abi),
1728 None => arg.layout.align.abi,
1729 };
1730 if op_place_val.align < required_align {
1731 let scratch = PlaceValue::alloca(bx, arg.layout.size, required_align);
1735 bx.lifetime_start(scratch.llval, arg.layout.size);
1736 bx.typed_place_copy(scratch, op_place_val, op.layout);
1737 lifetime_ends_after_call.push((scratch.llval, arg.layout.size));
1738 (scratch.llval, scratch.align, true)
1739 } else {
1740 (op_place_val.llval, op_place_val.align, true)
1741 }
1742 }
1743 _ => (op_place_val.llval, op_place_val.align, true),
1744 },
1745 ZeroSized => match arg.mode {
1746 PassMode::Indirect { on_stack, .. } => {
1747 if on_stack {
1748 ::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:?}");
1751 }
1752 let scratch = PlaceRef::alloca(bx, arg.layout);
1756 (scratch.val.llval, scratch.val.align, true)
1757 }
1758 _ => ::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:?}"),
1759 },
1760 };
1761
1762 if by_ref && !arg.is_indirect() {
1763 if let PassMode::Cast { cast, pad_i32: _ } = &arg.mode {
1765 let scratch_size = cast.size(bx);
1769 let scratch_align = cast.align(bx);
1770 let copy_bytes = cmp::min(cast.unaligned_size(bx).bytes(), arg.layout.size.bytes());
1777 let llscratch = bx.alloca(scratch_size, scratch_align);
1779 bx.lifetime_start(llscratch, scratch_size);
1780 bx.memcpy(
1782 llscratch,
1783 scratch_align,
1784 llval,
1785 align,
1786 bx.const_usize(copy_bytes),
1787 MemFlags::empty(),
1788 None,
1789 );
1790 llval = load_cast(bx, cast, llscratch, scratch_align);
1792 bx.lifetime_end(llscratch, scratch_size);
1793 } else {
1794 llval = bx.load(bx.backend_type(arg.layout), llval, align);
1800 if let BackendRepr::Scalar(scalar) = arg.layout.backend_repr {
1801 if scalar.is_bool() {
1802 bx.range_metadata(llval, WrappingRange { start: 0, end: 1 });
1803 }
1804 llval = bx.to_immediate_scalar(llval, scalar);
1806 }
1807 }
1808 }
1809
1810 llargs.push(llval);
1811 }
1812
1813 fn codegen_arguments_untupled(
1814 &mut self,
1815 bx: &mut Bx,
1816 operand: &mir::Operand<'tcx>,
1817 llargs: &mut Vec<Bx::Value>,
1818 args: &[ArgAbi<'tcx, Ty<'tcx>>],
1819 lifetime_ends_after_call: &mut Vec<(Bx::Value, Size)>,
1820 ) -> usize {
1821 let tuple = self.codegen_operand(bx, operand);
1822
1823 if let Ref(place_val) = tuple.val {
1825 if place_val.llextra.is_some() {
1826 ::rustc_middle::util::bug::bug_fmt(format_args!("closure arguments must be sized"));bug!("closure arguments must be sized");
1827 }
1828 let tuple_ptr = place_val.with_type(tuple.layout);
1829 for i in 0..tuple.layout.fields.count() {
1830 let field_ptr = tuple_ptr.project_field(bx, i);
1831 let field = bx.load_operand(field_ptr);
1832 self.codegen_argument(bx, field, llargs, &args[i], lifetime_ends_after_call);
1833 }
1834 } else {
1835 for i in 0..tuple.layout.fields.count() {
1837 let op = tuple.extract_field(self, bx, i);
1838 self.codegen_argument(bx, op, llargs, &args[i], lifetime_ends_after_call);
1839 }
1840 }
1841 tuple.layout.fields.count()
1842 }
1843
1844 pub(super) fn get_caller_location(
1845 &mut self,
1846 bx: &mut Bx,
1847 source_info: mir::SourceInfo,
1848 ) -> OperandRef<'tcx, Bx::Value> {
1849 self.mir.caller_location_span(source_info, self.caller_location, bx.tcx(), |span: Span| {
1850 let const_loc = bx.tcx().span_as_caller_location(span);
1851 OperandRef::from_const(bx, const_loc, bx.tcx().caller_location_ty())
1852 })
1853 }
1854
1855 fn get_personality_slot(&mut self, bx: &mut Bx) -> PlaceRef<'tcx, Bx::Value> {
1856 let cx = bx.cx();
1857 if let Some(slot) = self.personality_slot {
1858 slot
1859 } else {
1860 let layout = cx.layout_of(Ty::new_tup(
1861 cx.tcx(),
1862 &[Ty::new_mut_ptr(cx.tcx(), cx.tcx().types.u8), cx.tcx().types.i32],
1863 ));
1864 let slot = PlaceRef::alloca(bx, layout);
1865 self.personality_slot = Some(slot);
1866 slot
1867 }
1868 }
1869
1870 fn landing_pad_for(&mut self, bb: mir::BasicBlock) -> Bx::BasicBlock {
1873 if let Some(landing_pad) = self.landing_pads[bb] {
1874 return landing_pad;
1875 }
1876
1877 let landing_pad = self.landing_pad_for_uncached(bb);
1878 self.landing_pads[bb] = Some(landing_pad);
1879 landing_pad
1880 }
1881
1882 fn landing_pad_for_uncached(&mut self, bb: mir::BasicBlock) -> Bx::BasicBlock {
1884 let llbb = self.llbb(bb);
1885 if base::wants_new_eh_instructions(self.cx.sess()) {
1886 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:?}"));
1887 let mut cleanup_bx = Bx::build(self.cx, cleanup_bb);
1888 let funclet = cleanup_bx.cleanup_pad(None, &[]);
1889 cleanup_bx.br(llbb);
1890 self.funclets[bb] = Some(funclet);
1891 cleanup_bb
1892 } else {
1893 let cleanup_llbb = Bx::append_block(self.cx, self.llfn, "cleanup");
1894 let mut cleanup_bx = Bx::build(self.cx, cleanup_llbb);
1895
1896 let llpersonality = self.cx.eh_personality();
1897 let (exn0, exn1) = cleanup_bx.cleanup_landing_pad(llpersonality);
1898
1899 let slot = self.get_personality_slot(&mut cleanup_bx);
1900 slot.storage_live(&mut cleanup_bx);
1901 Pair(exn0, exn1).store(&mut cleanup_bx, slot);
1902
1903 cleanup_bx.br(llbb);
1904 cleanup_llbb
1905 }
1906 }
1907
1908 fn unreachable_block(&mut self) -> Bx::BasicBlock {
1909 self.unreachable_block.unwrap_or_else(|| {
1910 let llbb = Bx::append_block(self.cx, self.llfn, "unreachable");
1911 let mut bx = Bx::build(self.cx, llbb);
1912 bx.unreachable();
1913 self.unreachable_block = Some(llbb);
1914 llbb
1915 })
1916 }
1917
1918 fn terminate_block(
1919 &mut self,
1920 reason: UnwindTerminateReason,
1921 outer_catchpad_bb: Option<mir::BasicBlock>,
1922 ) -> Bx::BasicBlock {
1923 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!(
1928 outer_catchpad_bb.is_some()
1929 == (base::wants_wasm_eh(self.cx.tcx().sess)
1930 && reason == UnwindTerminateReason::InCleanup)
1931 );
1932
1933 let mut cache_bb = mir::START_BLOCK;
1936 if let Some(outer_bb) = outer_catchpad_bb {
1939 let cleanup_kinds =
1940 self.cleanup_kinds.as_ref().expect("cleanup_kinds required for funclets");
1941 cache_bb = cleanup_kinds[outer_bb]
1942 .funclet_bb(outer_bb)
1943 .expect("funclet_bb should be in a funclet");
1944
1945 if self.funclets[cache_bb].is_none() {
1947 self.landing_pad_for(cache_bb);
1948 }
1949 }
1950 if let Some((cached_bb, cached_reason)) = self.terminate_blocks[cache_bb]
1951 && reason == cached_reason
1952 {
1953 return cached_bb;
1954 }
1955
1956 let funclet;
1957 let llbb;
1958 let mut bx;
1959 if base::wants_new_eh_instructions(self.cx.sess()) {
1960 llbb = Bx::append_block(self.cx, self.llfn, "cs_terminate");
2000
2001 let mut cs_bx = Bx::build(self.cx, llbb);
2002
2003 let mut outer_cleanuppad = None;
2007 if outer_catchpad_bb.is_some() {
2008 let outer_funclet = self.funclets[cache_bb]
2010 .as_ref()
2011 .expect("landing_pad_for didn't create funclet");
2012 outer_cleanuppad = Some(cs_bx.get_funclet_cleanuppad(outer_funclet));
2013 }
2014 let cp_llbb = Bx::append_block(self.cx, self.llfn, "cp_terminate");
2015 let cs = cs_bx.catch_switch(outer_cleanuppad, None, &[cp_llbb]);
2016 drop(cs_bx);
2017
2018 bx = Bx::build(self.cx, cp_llbb);
2019 let null =
2020 bx.const_null(bx.type_ptr_ext(bx.cx().data_layout().instruction_address_space));
2021
2022 let args = if base::wants_msvc_seh(self.cx.sess()) {
2026 let adjectives = bx.const_i32(0x40);
2033 &[null, adjectives, null] as &[_]
2034 } else {
2035 &[null] as &[_]
2041 };
2042
2043 funclet = Some(bx.catch_pad(cs, args));
2044 } else {
2050 llbb = Bx::append_block(self.cx, self.llfn, "terminate");
2051 bx = Bx::build(self.cx, llbb);
2052
2053 let llpersonality = self.cx.eh_personality();
2054 bx.filter_landing_pad(llpersonality);
2055
2056 funclet = None;
2057 }
2058
2059 self.set_debug_loc(&mut bx, mir::SourceInfo::outermost(self.mir.span));
2060
2061 let (fn_abi, fn_ptr, instance) =
2062 common::build_langcall(&bx, self.mir.span, reason.lang_item());
2063 if is_call_from_compiler_builtins_to_upstream_monomorphization(bx.tcx(), instance) {
2064 bx.abort();
2065 } else {
2066 let fn_ty = bx.fn_decl_backend_type(fn_abi);
2067
2068 let llret = bx.call(fn_ty, None, Some(fn_abi), fn_ptr, &[], funclet.as_ref(), None);
2069 bx.apply_attrs_to_cleanup_callsite(llret);
2070 }
2071
2072 bx.unreachable();
2073
2074 self.terminate_blocks[cache_bb] = Some((llbb, reason));
2075 llbb
2076 }
2077
2078 pub fn llbb(&mut self, bb: mir::BasicBlock) -> Bx::BasicBlock {
2083 self.try_llbb(bb).unwrap()
2084 }
2085
2086 pub(crate) fn try_llbb(&mut self, bb: mir::BasicBlock) -> Option<Bx::BasicBlock> {
2088 match self.cached_llbbs[bb] {
2089 CachedLlbb::None => {
2090 let llbb = Bx::append_block(self.cx, self.llfn, &::alloc::__export::must_use({
::alloc::fmt::format(format_args!("{0:?}", bb))
})format!("{bb:?}"));
2091 self.cached_llbbs[bb] = CachedLlbb::Some(llbb);
2092 Some(llbb)
2093 }
2094 CachedLlbb::Some(llbb) => Some(llbb),
2095 CachedLlbb::Skip => None,
2096 }
2097 }
2098
2099 fn make_return_dest(
2100 &mut self,
2101 bx: &mut Bx,
2102 dest: mir::Place<'tcx>,
2103 fn_ret: &ArgAbi<'tcx, Ty<'tcx>>,
2104 llargs: &mut Vec<Bx::Value>,
2105 ) -> ReturnDest<'tcx, Bx::Value> {
2106 if fn_ret.is_ignore() {
2108 return ReturnDest::Nothing;
2109 }
2110 let dest = if let Some(index) = dest.as_local() {
2111 match self.locals[index] {
2112 LocalRef::Place(dest) => dest,
2113 LocalRef::UnsizedPlace(_) => ::rustc_middle::util::bug::bug_fmt(format_args!("return type must be sized"))bug!("return type must be sized"),
2114 LocalRef::PendingOperand => {
2115 return if fn_ret.is_indirect() {
2118 let tmp = PlaceRef::alloca(bx, fn_ret.layout);
2121 tmp.storage_live(bx);
2122 llargs.push(tmp.val.llval);
2123 ReturnDest::IndirectOperand(tmp, index)
2124 } else {
2125 ReturnDest::DirectOperand(index)
2126 };
2127 }
2128 LocalRef::Operand(_) => {
2129 ::rustc_middle::util::bug::bug_fmt(format_args!("place local already assigned to"));bug!("place local already assigned to");
2130 }
2131 }
2132 } else {
2133 self.codegen_place(bx, dest.as_ref())
2134 };
2135 if fn_ret.is_indirect() {
2136 if dest.val.align < dest.layout.align.abi {
2137 ::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");
2144 }
2145 llargs.push(dest.val.llval);
2146 ReturnDest::Nothing
2147 } else {
2148 ReturnDest::Store(dest)
2149 }
2150 }
2151
2152 fn store_return(
2154 &mut self,
2155 bx: &mut Bx,
2156 dest: ReturnDest<'tcx, Bx::Value>,
2157 ret_abi: &ArgAbi<'tcx, Ty<'tcx>>,
2158 llval: Bx::Value,
2159 ) {
2160 use self::ReturnDest::*;
2161
2162 match dest {
2163 Nothing => (),
2164 Store(dst) => bx.store_arg(ret_abi, llval, dst),
2165 IndirectOperand(tmp, index) => {
2166 let op = bx.load_operand(tmp);
2167 tmp.storage_dead(bx);
2168 self.overwrite_local(index, LocalRef::Operand(op));
2169 self.debug_introduce_local(bx, index);
2170 }
2171 DirectOperand(index) => {
2172 let op = if let PassMode::Cast { .. } = ret_abi.mode {
2174 let tmp = PlaceRef::alloca(bx, ret_abi.layout);
2175 tmp.storage_live(bx);
2176 bx.store_arg(ret_abi, llval, tmp);
2177 let op = bx.load_operand(tmp);
2178 tmp.storage_dead(bx);
2179 op
2180 } else {
2181 OperandRef::from_immediate_or_packed_pair(bx, llval, ret_abi.layout)
2182 };
2183 self.overwrite_local(index, LocalRef::Operand(op));
2184 self.debug_introduce_local(bx, index);
2185 }
2186 }
2187 }
2188}
2189
2190enum ReturnDest<'tcx, V> {
2191 Nothing,
2193 Store(PlaceRef<'tcx, V>),
2195 IndirectOperand(PlaceRef<'tcx, V>, mir::Local),
2197 DirectOperand(mir::Local),
2199}
2200
2201fn load_cast<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
2202 bx: &mut Bx,
2203 cast: &CastTarget,
2204 ptr: Bx::Value,
2205 align: Align,
2206) -> Bx::Value {
2207 let cast_ty = bx.cast_backend_type(cast);
2208 if let Some(offset_from_start) = cast.rest_offset {
2209 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()));
2210 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);
2211 let first_ty = bx.reg_backend_type(&cast.prefix[0].unwrap());
2212 let second_ty = bx.reg_backend_type(&cast.rest.unit);
2213 let first = bx.load(first_ty, ptr, align);
2214 let second_ptr = bx.inbounds_ptradd(ptr, bx.const_usize(offset_from_start.bytes()));
2215 let second = bx.load(second_ty, second_ptr, align.restrict_for_offset(offset_from_start));
2216 let res = bx.cx().const_poison(cast_ty);
2217 let res = bx.insert_value(res, first, 0);
2218 bx.insert_value(res, second, 1)
2219 } else {
2220 bx.load(cast_ty, ptr, align)
2221 }
2222}
2223
2224pub fn store_cast<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
2225 bx: &mut Bx,
2226 cast: &CastTarget,
2227 value: Bx::Value,
2228 ptr: Bx::Value,
2229 align: Align,
2230) {
2231 if let Some(offset_from_start) = cast.rest_offset {
2232 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()));
2233 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);
2234 if !cast.prefix[0].is_some() {
::core::panicking::panic("assertion failed: cast.prefix[0].is_some()")
};assert!(cast.prefix[0].is_some());
2235 let first = bx.extract_value(value, 0);
2236 let second = bx.extract_value(value, 1);
2237 bx.store(first, ptr, align);
2238 let second_ptr = bx.inbounds_ptradd(ptr, bx.const_usize(offset_from_start.bytes()));
2239 bx.store(second, second_ptr, align.restrict_for_offset(offset_from_start));
2240 } else {
2241 bx.store(value, ptr, align);
2242 };
2243}