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_new_eh_instructions(fx.cx.tcx().sess) {
219 None
229 } else {
230 Some(fx.terminate_block(reason))
231 }
232 }
233 };
234
235 if kind == CallKind::Tail {
236 bx.tail_call(fn_ty, caller_attrs, fn_abi, fn_ptr, llargs, self.funclet(fx), instance);
237 return MergingSucc::False;
238 }
239
240 if let Some(unwind_block) = unwind_block {
241 let ret_llbb = if let Some((_, target)) = destination {
242 fx.llbb(target)
243 } else {
244 fx.unreachable_block()
245 };
246 let invokeret = bx.invoke(
247 fn_ty,
248 caller_attrs,
249 Some(fn_abi),
250 fn_ptr,
251 llargs,
252 ret_llbb,
253 unwind_block,
254 self.funclet(fx),
255 instance,
256 );
257 if fx.mir[self.bb].is_cleanup {
258 bx.apply_attrs_to_cleanup_callsite(invokeret);
259 }
260
261 if let Some((ret_dest, target)) = destination {
262 bx.switch_to_block(fx.llbb(target));
263 fx.set_debug_loc(bx, self.terminator.source_info);
264 for &(tmp, size) in lifetime_ends_after_call {
265 bx.lifetime_end(tmp, size);
266 }
267 fx.store_return(bx, ret_dest, &fn_abi.ret, invokeret);
268 }
269 MergingSucc::False
270 } else {
271 let llret = bx.call(
272 fn_ty,
273 caller_attrs,
274 Some(fn_abi),
275 fn_ptr,
276 llargs,
277 self.funclet(fx),
278 instance,
279 );
280 if fx.mir[self.bb].is_cleanup {
281 bx.apply_attrs_to_cleanup_callsite(llret);
282 }
283
284 if let Some((ret_dest, target)) = destination {
285 for &(tmp, size) in lifetime_ends_after_call {
286 bx.lifetime_end(tmp, size);
287 }
288 fx.store_return(bx, ret_dest, &fn_abi.ret, llret);
289 self.funclet_br(fx, bx, target, mergeable_succ)
290 } else {
291 bx.unreachable();
292 MergingSucc::False
293 }
294 }
295 }
296
297 fn do_inlineasm<Bx: BuilderMethods<'a, 'tcx>>(
299 &self,
300 fx: &mut FunctionCx<'a, 'tcx, Bx>,
301 bx: &mut Bx,
302 template: &[InlineAsmTemplatePiece],
303 operands: &[InlineAsmOperandRef<'tcx, Bx>],
304 options: InlineAsmOptions,
305 line_spans: &[Span],
306 destination: Option<mir::BasicBlock>,
307 unwind: mir::UnwindAction,
308 instance: Instance<'_>,
309 mergeable_succ: bool,
310 ) -> MergingSucc {
311 let unwind_target = match unwind {
312 mir::UnwindAction::Cleanup(cleanup) => Some(self.llbb_with_cleanup(fx, cleanup)),
313 mir::UnwindAction::Terminate(reason) => Some(fx.terminate_block(reason)),
314 mir::UnwindAction::Continue => None,
315 mir::UnwindAction::Unreachable => None,
316 };
317
318 if operands.iter().any(|x| #[allow(non_exhaustive_omitted_patterns)] match x {
InlineAsmOperandRef::Label { .. } => true,
_ => false,
}matches!(x, InlineAsmOperandRef::Label { .. })) {
319 if !unwind_target.is_none() {
::core::panicking::panic("assertion failed: unwind_target.is_none()")
};assert!(unwind_target.is_none());
320 let ret_llbb = if let Some(target) = destination {
321 fx.llbb(target)
322 } else {
323 fx.unreachable_block()
324 };
325
326 bx.codegen_inline_asm(
327 template,
328 operands,
329 options,
330 line_spans,
331 instance,
332 Some(ret_llbb),
333 None,
334 );
335 MergingSucc::False
336 } else if let Some(cleanup) = unwind_target {
337 let ret_llbb = if let Some(target) = destination {
338 fx.llbb(target)
339 } else {
340 fx.unreachable_block()
341 };
342
343 bx.codegen_inline_asm(
344 template,
345 operands,
346 options,
347 line_spans,
348 instance,
349 Some(ret_llbb),
350 Some((cleanup, self.funclet(fx))),
351 );
352 MergingSucc::False
353 } else {
354 bx.codegen_inline_asm(template, operands, options, line_spans, instance, None, None);
355
356 if let Some(target) = destination {
357 self.funclet_br(fx, bx, target, mergeable_succ)
358 } else {
359 bx.unreachable();
360 MergingSucc::False
361 }
362 }
363 }
364}
365
366impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
368 fn codegen_resume_terminator(&mut self, helper: TerminatorCodegenHelper<'tcx>, bx: &mut Bx) {
370 if let Some(funclet) = helper.funclet(self) {
371 bx.cleanup_ret(funclet, None);
372 } else {
373 let slot = self.get_personality_slot(bx);
374 let exn0 = slot.project_field(bx, 0);
375 let exn0 = bx.load_operand(exn0).immediate();
376 let exn1 = slot.project_field(bx, 1);
377 let exn1 = bx.load_operand(exn1).immediate();
378 slot.storage_dead(bx);
379
380 bx.resume(exn0, exn1);
381 }
382 }
383
384 fn codegen_switchint_terminator(
385 &mut self,
386 helper: TerminatorCodegenHelper<'tcx>,
387 bx: &mut Bx,
388 discr: &mir::Operand<'tcx>,
389 targets: &SwitchTargets,
390 ) {
391 let discr = self.codegen_operand(bx, discr);
392 let discr_value = discr.immediate();
393 let switch_ty = discr.layout.ty;
394 if let Some(const_discr) = bx.const_to_opt_u128(discr_value, false) {
396 let target = targets.target_for_value(const_discr);
397 bx.br(helper.llbb_with_cleanup(self, target));
398 return;
399 };
400
401 let mut target_iter = targets.iter();
402 if target_iter.len() == 1 {
403 let (test_value, target) = target_iter.next().unwrap();
406 let otherwise = targets.otherwise();
407 let lltarget = helper.llbb_with_cleanup(self, target);
408 let llotherwise = helper.llbb_with_cleanup(self, otherwise);
409 let target_cold = self.cold_blocks[target];
410 let otherwise_cold = self.cold_blocks[otherwise];
411 let expect = if target_cold == otherwise_cold { None } else { Some(otherwise_cold) };
415 if switch_ty == bx.tcx().types.bool {
416 match test_value {
418 0 => {
419 let expect = expect.map(|e| !e);
420 bx.cond_br_with_expect(discr_value, llotherwise, lltarget, expect);
421 }
422 1 => {
423 bx.cond_br_with_expect(discr_value, lltarget, llotherwise, expect);
424 }
425 _ => ::rustc_middle::util::bug::bug_fmt(format_args!("impossible case reached"))bug!(),
426 }
427 } else {
428 let switch_llty = bx.immediate_backend_type(bx.layout_of(switch_ty));
429 let llval = bx.const_uint_big(switch_llty, test_value);
430 let cmp = bx.icmp(IntPredicate::IntEQ, discr_value, llval);
431 bx.cond_br_with_expect(cmp, lltarget, llotherwise, expect);
432 }
433 } else if target_iter.len() == 2
434 && self.mir[targets.otherwise()].is_empty_unreachable()
435 && targets.all_values().contains(&Pu128(0))
436 && targets.all_values().contains(&Pu128(1))
437 {
438 let true_bb = targets.target_for_value(1);
442 let false_bb = targets.target_for_value(0);
443 let true_ll = helper.llbb_with_cleanup(self, true_bb);
444 let false_ll = helper.llbb_with_cleanup(self, false_bb);
445
446 let expected_cond_value = if self.cx.sess().opts.optimize == OptLevel::No {
447 None
448 } else {
449 match (self.cold_blocks[true_bb], self.cold_blocks[false_bb]) {
450 (true, true) | (false, false) => None,
452 (true, false) => Some(false),
454 (false, true) => Some(true),
455 }
456 };
457
458 let bool_ty = bx.tcx().types.bool;
459 let cond = if switch_ty == bool_ty {
460 discr_value
461 } else {
462 let bool_llty = bx.immediate_backend_type(bx.layout_of(bool_ty));
463 bx.unchecked_utrunc(discr_value, bool_llty)
464 };
465 bx.cond_br_with_expect(cond, true_ll, false_ll, expected_cond_value);
466 } else if self.cx.sess().opts.optimize == OptLevel::No
467 && target_iter.len() == 2
468 && self.mir[targets.otherwise()].is_empty_unreachable()
469 {
470 let (test_value1, target1) = target_iter.next().unwrap();
483 let (_test_value2, target2) = target_iter.next().unwrap();
484 let ll1 = helper.llbb_with_cleanup(self, target1);
485 let ll2 = helper.llbb_with_cleanup(self, target2);
486 let switch_llty = bx.immediate_backend_type(bx.layout_of(switch_ty));
487 let llval = bx.const_uint_big(switch_llty, test_value1);
488 let cmp = bx.icmp(IntPredicate::IntEQ, discr_value, llval);
489 bx.cond_br(cmp, ll1, ll2);
490 } else {
491 let otherwise = targets.otherwise();
492 let otherwise_cold = self.cold_blocks[otherwise];
493 let otherwise_unreachable = self.mir[otherwise].is_empty_unreachable();
494 let cold_count = targets.iter().filter(|(_, target)| self.cold_blocks[*target]).count();
495 let none_cold = cold_count == 0;
496 let all_cold = cold_count == targets.iter().len();
497 if (none_cold && (!otherwise_cold || otherwise_unreachable))
498 || (all_cold && (otherwise_cold || otherwise_unreachable))
499 {
500 bx.switch(
503 discr_value,
504 helper.llbb_with_cleanup(self, targets.otherwise()),
505 target_iter
506 .map(|(value, target)| (value, helper.llbb_with_cleanup(self, target))),
507 );
508 } else {
509 bx.switch_with_weights(
511 discr_value,
512 helper.llbb_with_cleanup(self, targets.otherwise()),
513 otherwise_cold,
514 target_iter.map(|(value, target)| {
515 (value, helper.llbb_with_cleanup(self, target), self.cold_blocks[target])
516 }),
517 );
518 }
519 }
520 }
521
522 fn codegen_return_terminator(&mut self, bx: &mut Bx) {
523 if self.fn_abi.c_variadic {
525 let va_list_arg_idx = self.fn_abi.args.len();
527 match self.locals[mir::Local::from_usize(1 + va_list_arg_idx)] {
528 LocalRef::Place(va_list) => {
529 bx.va_end(va_list.val.llval);
530
531 bx.lifetime_end(va_list.val.llval, va_list.layout.size);
533 }
534 _ => ::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"),
535 }
536 }
537 if self.fn_abi.ret.layout.is_uninhabited() {
538 bx.abort();
543 bx.unreachable();
546 return;
547 }
548 let llval = match &self.fn_abi.ret.mode {
549 PassMode::Ignore | PassMode::Indirect { .. } => {
550 bx.ret_void();
551 return;
552 }
553
554 PassMode::Direct(_) | PassMode::Pair(..) => {
555 let op = self.codegen_consume(bx, mir::Place::return_place().as_ref());
556 if let Ref(place_val) = op.val {
557 bx.load_from_place(bx.backend_type(op.layout), place_val)
558 } else {
559 op.immediate_or_packed_pair(bx)
560 }
561 }
562
563 PassMode::Cast { cast: cast_ty, pad_i32: _ } => {
564 let op = match self.locals[mir::RETURN_PLACE] {
565 LocalRef::Operand(op) => op,
566 LocalRef::PendingOperand => ::rustc_middle::util::bug::bug_fmt(format_args!("use of return before def"))bug!("use of return before def"),
567 LocalRef::Place(cg_place) => OperandRef {
568 val: Ref(cg_place.val),
569 layout: cg_place.layout,
570 move_annotation: None,
571 },
572 LocalRef::UnsizedPlace(_) => ::rustc_middle::util::bug::bug_fmt(format_args!("return type must be sized"))bug!("return type must be sized"),
573 };
574 let llslot = match op.val {
575 Immediate(_) | Pair(..) => {
576 let scratch = PlaceRef::alloca(bx, self.fn_abi.ret.layout);
577 op.val.store(bx, scratch);
578 scratch.val.llval
579 }
580 Ref(place_val) => {
581 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!(
582 place_val.align, op.layout.align.abi,
583 "return place is unaligned!"
584 );
585 place_val.llval
586 }
587 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"),
588 };
589 load_cast(bx, cast_ty, llslot, self.fn_abi.ret.layout.align.abi)
590 }
591 };
592 bx.ret(llval);
593 }
594
595 #[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(595u32),
::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: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!("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: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!("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:646",
"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(646u32),
::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))]
596 fn codegen_drop_terminator(
597 &mut self,
598 helper: TerminatorCodegenHelper<'tcx>,
599 bx: &mut Bx,
600 source_info: &mir::SourceInfo,
601 location: mir::Place<'tcx>,
602 target: mir::BasicBlock,
603 unwind: mir::UnwindAction,
604 mergeable_succ: bool,
605 ) -> MergingSucc {
606 let ty = location.ty(self.mir, bx.tcx()).ty;
607 let ty = self.monomorphize(ty);
608 let drop_fn = Instance::resolve_drop_in_place(bx.tcx(), ty);
609
610 if let ty::InstanceKind::DropGlue(_, None) = drop_fn.def {
611 return helper.funclet_br(self, bx, target, mergeable_succ);
613 }
614
615 let place = self.codegen_place(bx, location.as_ref());
616 let (args1, args2);
617 let mut args = if let Some(llextra) = place.val.llextra {
618 args2 = [place.val.llval, llextra];
619 &args2[..]
620 } else {
621 args1 = [place.val.llval];
622 &args1[..]
623 };
624 let (maybe_null, drop_fn, fn_abi, drop_instance) = match ty.kind() {
625 ty::Dynamic(_, _) => {
628 let virtual_drop = Instance {
641 def: ty::InstanceKind::Virtual(drop_fn.def_id(), 0), args: drop_fn.args,
643 };
644 debug!("ty = {:?}", ty);
645 debug!("drop_fn = {:?}", drop_fn);
646 debug!("args = {:?}", args);
647 let fn_abi = bx.fn_abi_of_instance(virtual_drop, ty::List::empty());
648 let vtable = args[1];
649 args = &args[..1];
651 (
652 true,
653 meth::VirtualIndex::from_index(ty::COMMON_VTABLE_ENTRIES_DROPINPLACE)
654 .get_optional_fn(bx, vtable, ty, fn_abi),
655 fn_abi,
656 virtual_drop,
657 )
658 }
659 _ => (
660 false,
661 bx.get_fn_addr(drop_fn),
662 bx.fn_abi_of_instance(drop_fn, ty::List::empty()),
663 drop_fn,
664 ),
665 };
666
667 if maybe_null {
670 let is_not_null = bx.append_sibling_block("is_not_null");
671 let llty = bx.fn_ptr_backend_type(fn_abi);
672 let null = bx.const_null(llty);
673 let non_null =
674 bx.icmp(base::bin_op_to_icmp_predicate(mir::BinOp::Ne, false), drop_fn, null);
675 bx.cond_br(non_null, is_not_null, helper.llbb_with_cleanup(self, target));
676 bx.switch_to_block(is_not_null);
677 self.set_debug_loc(bx, *source_info);
678 }
679
680 helper.do_call(
681 self,
682 bx,
683 fn_abi,
684 drop_fn,
685 args,
686 Some((ReturnDest::Nothing, target)),
687 unwind,
688 &[],
689 Some(drop_instance),
690 CallKind::Normal,
691 !maybe_null && mergeable_succ,
692 )
693 }
694
695 fn codegen_assert_terminator(
696 &mut self,
697 helper: TerminatorCodegenHelper<'tcx>,
698 bx: &mut Bx,
699 terminator: &mir::Terminator<'tcx>,
700 cond: &mir::Operand<'tcx>,
701 expected: bool,
702 msg: &mir::AssertMessage<'tcx>,
703 target: mir::BasicBlock,
704 unwind: mir::UnwindAction,
705 mergeable_succ: bool,
706 ) -> MergingSucc {
707 let span = terminator.source_info.span;
708 let cond = self.codegen_operand(bx, cond).immediate();
709 let mut const_cond = bx.const_to_opt_u128(cond, false).map(|c| c == 1);
710
711 if !bx.sess().overflow_checks() && msg.is_optional_overflow_check() {
716 const_cond = Some(expected);
717 }
718
719 if const_cond == Some(expected) {
721 return helper.funclet_br(self, bx, target, mergeable_succ);
722 }
723
724 let lltarget = helper.llbb_with_cleanup(self, target);
729 let panic_block = bx.append_sibling_block("panic");
730 if expected {
731 bx.cond_br(cond, lltarget, panic_block);
732 } else {
733 bx.cond_br(cond, panic_block, lltarget);
734 }
735
736 bx.switch_to_block(panic_block);
738 self.set_debug_loc(bx, terminator.source_info);
739
740 let location = self.get_caller_location(bx, terminator.source_info).immediate();
742
743 let (lang_item, args) = match msg {
745 AssertKind::BoundsCheck { len, index } => {
746 let len = self.codegen_operand(bx, len).immediate();
747 let index = self.codegen_operand(bx, index).immediate();
748 (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])
751 }
752 AssertKind::MisalignedPointerDereference { required, found } => {
753 let required = self.codegen_operand(bx, required).immediate();
754 let found = self.codegen_operand(bx, found).immediate();
755 (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])
758 }
759 AssertKind::NullPointerDereference => {
760 (LangItem::PanicNullPointerDereference, ::alloc::boxed::box_assume_init_into_vec_unsafe(::alloc::intrinsics::write_box_via_move(::alloc::boxed::Box::new_uninit(),
[location]))vec![location])
763 }
764 AssertKind::InvalidEnumConstruction(source) => {
765 let source = self.codegen_operand(bx, source).immediate();
766 (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])
769 }
770 _ => {
771 (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])
773 }
774 };
775
776 let (fn_abi, llfn, instance) = common::build_langcall(bx, span, lang_item);
777
778 let merging_succ = helper.do_call(
780 self,
781 bx,
782 fn_abi,
783 llfn,
784 &args,
785 None,
786 unwind,
787 &[],
788 Some(instance),
789 CallKind::Normal,
790 false,
791 );
792 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);
793 MergingSucc::False
794 }
795
796 fn codegen_terminate_terminator(
797 &mut self,
798 helper: TerminatorCodegenHelper<'tcx>,
799 bx: &mut Bx,
800 terminator: &mir::Terminator<'tcx>,
801 reason: UnwindTerminateReason,
802 ) {
803 let span = terminator.source_info.span;
804 self.set_debug_loc(bx, terminator.source_info);
805
806 let (fn_abi, llfn, instance) = common::build_langcall(bx, span, reason.lang_item());
808
809 let merging_succ = helper.do_call(
811 self,
812 bx,
813 fn_abi,
814 llfn,
815 &[],
816 None,
817 mir::UnwindAction::Unreachable,
818 &[],
819 Some(instance),
820 CallKind::Normal,
821 false,
822 );
823 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);
824 }
825
826 fn codegen_panic_intrinsic(
828 &mut self,
829 helper: &TerminatorCodegenHelper<'tcx>,
830 bx: &mut Bx,
831 intrinsic: ty::IntrinsicDef,
832 instance: Instance<'tcx>,
833 source_info: mir::SourceInfo,
834 target: Option<mir::BasicBlock>,
835 unwind: mir::UnwindAction,
836 mergeable_succ: bool,
837 ) -> Option<MergingSucc> {
838 let Some(requirement) = ValidityRequirement::from_intrinsic(intrinsic.name) else {
842 return None;
843 };
844
845 let ty = instance.args.type_at(0);
846
847 let is_valid = bx
848 .tcx()
849 .check_validity_requirement((requirement, bx.typing_env().as_query_input(ty)))
850 .expect("expect to have layout during codegen");
851
852 if is_valid {
853 let target = target.unwrap();
855 return Some(helper.funclet_br(self, bx, target, mergeable_succ));
856 }
857
858 let layout = bx.layout_of(ty);
859
860 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!({
861 with_no_trimmed_paths!({
862 if layout.is_uninhabited() {
863 format!("attempted to instantiate uninhabited type `{ty}`")
865 } else if requirement == ValidityRequirement::Zero {
866 format!("attempted to zero-initialize type `{ty}`, which is invalid")
867 } else {
868 format!("attempted to leave type `{ty}` uninitialized, which is invalid")
869 }
870 })
871 });
872 let msg = bx.const_str(&msg_str);
873
874 let (fn_abi, llfn, instance) =
876 common::build_langcall(bx, source_info.span, LangItem::PanicNounwind);
877
878 Some(helper.do_call(
880 self,
881 bx,
882 fn_abi,
883 llfn,
884 &[msg.0, msg.1],
885 target.as_ref().map(|bb| (ReturnDest::Nothing, *bb)),
886 unwind,
887 &[],
888 Some(instance),
889 CallKind::Normal,
890 mergeable_succ,
891 ))
892 }
893
894 fn codegen_call_terminator(
895 &mut self,
896 helper: TerminatorCodegenHelper<'tcx>,
897 bx: &mut Bx,
898 terminator: &mir::Terminator<'tcx>,
899 func: &mir::Operand<'tcx>,
900 args: &[Spanned<mir::Operand<'tcx>>],
901 destination: mir::Place<'tcx>,
902 target: Option<mir::BasicBlock>,
903 unwind: mir::UnwindAction,
904 fn_span: Span,
905 kind: CallKind,
906 mergeable_succ: bool,
907 ) -> MergingSucc {
908 let source_info = mir::SourceInfo { span: fn_span, ..terminator.source_info };
909
910 let callee = self.codegen_operand(bx, func);
912
913 let (instance, mut llfn) = match *callee.layout.ty.kind() {
914 ty::FnDef(def_id, generic_args) => {
915 let instance = ty::Instance::expect_resolve(
916 bx.tcx(),
917 bx.typing_env(),
918 def_id,
919 generic_args,
920 fn_span,
921 );
922
923 match instance.def {
924 ty::InstanceKind::DropGlue(_, None) => {
927 let target = target.unwrap();
929 return helper.funclet_br(self, bx, target, mergeable_succ);
930 }
931 ty::InstanceKind::Intrinsic(def_id) => {
932 let intrinsic = bx.tcx().intrinsic(def_id).unwrap();
933 if let Some(merging_succ) = self.codegen_panic_intrinsic(
934 &helper,
935 bx,
936 intrinsic,
937 instance,
938 source_info,
939 target,
940 unwind,
941 mergeable_succ,
942 ) {
943 return merging_succ;
944 }
945
946 let result_layout =
947 self.cx.layout_of(self.monomorphized_place_ty(destination.as_ref()));
948
949 let (result, store_in_local) = if result_layout.is_zst() {
950 (
951 PlaceRef::new_sized(bx.const_undef(bx.type_ptr()), result_layout),
952 None,
953 )
954 } else if let Some(local) = destination.as_local() {
955 match self.locals[local] {
956 LocalRef::Place(dest) => (dest, None),
957 LocalRef::UnsizedPlace(_) => ::rustc_middle::util::bug::bug_fmt(format_args!("return type must be sized"))bug!("return type must be sized"),
958 LocalRef::PendingOperand => {
959 let tmp = PlaceRef::alloca(bx, result_layout);
963 tmp.storage_live(bx);
964 (tmp, Some(local))
965 }
966 LocalRef::Operand(_) => {
967 ::rustc_middle::util::bug::bug_fmt(format_args!("place local already assigned to"));bug!("place local already assigned to");
968 }
969 }
970 } else {
971 (self.codegen_place(bx, destination.as_ref()), None)
972 };
973
974 if result.val.align < result.layout.align.abi {
975 ::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");
982 }
983
984 let args: Vec<_> =
985 args.iter().map(|arg| self.codegen_operand(bx, &arg.node)).collect();
986
987 match self.codegen_intrinsic_call(bx, instance, &args, result, source_info)
988 {
989 Ok(()) => {
990 if let Some(local) = store_in_local {
991 let op = bx.load_operand(result);
992 result.storage_dead(bx);
993 self.overwrite_local(local, LocalRef::Operand(op));
994 self.debug_introduce_local(bx, local);
995 }
996
997 return if let Some(target) = target {
998 helper.funclet_br(self, bx, target, mergeable_succ)
999 } else {
1000 bx.unreachable();
1001 MergingSucc::False
1002 };
1003 }
1004 Err(instance) => {
1005 if intrinsic.must_be_overridden {
1006 ::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!(
1007 fn_span,
1008 "intrinsic {} must be overridden by codegen backend, but isn't",
1009 intrinsic.name,
1010 );
1011 }
1012 (Some(instance), None)
1013 }
1014 }
1015 }
1016
1017 _ if kind == CallKind::Tail
1018 && instance.def.requires_caller_location(bx.tcx()) =>
1019 {
1020 if let Some(hir_id) =
1021 terminator.source_info.scope.lint_root(&self.mir.source_scopes)
1022 {
1023 let msg = "tail calling a function marked with `#[track_caller]` has no special effect";
1024 bx.tcx().node_lint(TAIL_CALL_TRACK_CALLER, hir_id, |d| {
1025 _ = d.primary_message(msg).span(fn_span)
1026 });
1027 }
1028
1029 let instance = ty::Instance::resolve_for_fn_ptr(
1030 bx.tcx(),
1031 bx.typing_env(),
1032 def_id,
1033 generic_args,
1034 )
1035 .unwrap();
1036
1037 (None, Some(bx.get_fn_addr(instance)))
1038 }
1039 _ => (Some(instance), None),
1040 }
1041 }
1042 ty::FnPtr(..) => (None, Some(callee.immediate())),
1043 _ => ::rustc_middle::util::bug::bug_fmt(format_args!("{0} is not callable",
callee.layout.ty))bug!("{} is not callable", callee.layout.ty),
1044 };
1045
1046 if let Some(instance) = instance
1047 && let Some(name) = bx.tcx().codegen_fn_attrs(instance.def_id()).symbol_name
1048 && name.as_str().starts_with("llvm.")
1049 && name.as_str() != "llvm.wasm.throw"
1053 {
1054 if !!instance.args.has_infer() {
::core::panicking::panic("assertion failed: !instance.args.has_infer()")
};assert!(!instance.args.has_infer());
1055 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());
1056
1057 let result_layout =
1058 self.cx.layout_of(self.monomorphized_place_ty(destination.as_ref()));
1059
1060 let return_dest = if result_layout.is_zst() {
1061 ReturnDest::Nothing
1062 } else if let Some(index) = destination.as_local() {
1063 match self.locals[index] {
1064 LocalRef::Place(dest) => ReturnDest::Store(dest),
1065 LocalRef::UnsizedPlace(_) => ::rustc_middle::util::bug::bug_fmt(format_args!("return type must be sized"))bug!("return type must be sized"),
1066 LocalRef::PendingOperand => {
1067 ReturnDest::DirectOperand(index)
1070 }
1071 LocalRef::Operand(_) => ::rustc_middle::util::bug::bug_fmt(format_args!("place local already assigned to"))bug!("place local already assigned to"),
1072 }
1073 } else {
1074 ReturnDest::Store(self.codegen_place(bx, destination.as_ref()))
1075 };
1076
1077 let args =
1078 args.into_iter().map(|arg| self.codegen_operand(bx, &arg.node)).collect::<Vec<_>>();
1079
1080 self.set_debug_loc(bx, source_info);
1081
1082 let llret =
1083 bx.codegen_llvm_intrinsic_call(instance, &args, self.mir[helper.bb].is_cleanup);
1084
1085 if let Some(target) = target {
1086 self.store_return(
1087 bx,
1088 return_dest,
1089 &ArgAbi { layout: result_layout, mode: PassMode::Direct(ArgAttributes::new()) },
1090 llret,
1091 );
1092 return helper.funclet_br(self, bx, target, mergeable_succ);
1093 } else {
1094 bx.unreachable();
1095 return MergingSucc::False;
1096 }
1097 }
1098
1099 let sig = callee.layout.ty.fn_sig(bx.tcx());
1103
1104 let extra_args = &args[sig.inputs().skip_binder().len()..];
1105 let extra_args = bx.tcx().mk_type_list_from_iter(extra_args.iter().map(|op_arg| {
1106 let op_ty = op_arg.node.ty(self.mir, bx.tcx());
1107 self.monomorphize(op_ty)
1108 }));
1109
1110 let fn_abi = match instance {
1111 Some(instance) => bx.fn_abi_of_instance(instance, extra_args),
1112 None => bx.fn_abi_of_fn_ptr(sig, extra_args),
1113 };
1114
1115 let arg_count = fn_abi.args.len() + fn_abi.ret.is_indirect() as usize;
1117
1118 let mut llargs = Vec::with_capacity(arg_count);
1119
1120 let destination = match kind {
1124 CallKind::Normal => {
1125 let return_dest = self.make_return_dest(bx, destination, &fn_abi.ret, &mut llargs);
1126 target.map(|target| (return_dest, target))
1127 }
1128 CallKind::Tail => {
1129 if fn_abi.ret.is_indirect() {
1130 match self.make_return_dest(bx, destination, &fn_abi.ret, &mut llargs) {
1131 ReturnDest::Nothing => {}
1132 _ => ::rustc_middle::util::bug::bug_fmt(format_args!("tail calls to functions with indirect returns cannot store into a destination"))bug!(
1133 "tail calls to functions with indirect returns cannot store into a destination"
1134 ),
1135 }
1136 }
1137 None
1138 }
1139 };
1140
1141 let (first_args, untuple) = if sig.abi() == ExternAbi::RustCall
1143 && let Some((tup, args)) = args.split_last()
1144 {
1145 (args, Some(tup))
1146 } else {
1147 (args, None)
1148 };
1149
1150 let mut tail_call_temporaries = ::alloc::vec::Vec::new()vec![];
1172 if kind == CallKind::Tail {
1173 tail_call_temporaries = ::alloc::vec::from_elem(None, first_args.len())vec![None; first_args.len()];
1174 for (i, arg) in first_args.iter().enumerate() {
1177 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, .. }) {
1178 continue;
1179 }
1180
1181 let op = self.codegen_operand(bx, &arg.node);
1182 let tmp = PlaceRef::alloca(bx, op.layout);
1183 bx.lifetime_start(tmp.val.llval, tmp.layout.size);
1184 op.store_with_annotation(bx, tmp);
1185
1186 tail_call_temporaries[i] = Some(tmp);
1187 }
1188 }
1189
1190 let mut lifetime_ends_after_call: Vec<(Bx::Value, Size)> = Vec::new();
1194 'make_args: for (i, arg) in first_args.iter().enumerate() {
1195 let mut op = self.codegen_operand(bx, &arg.node);
1196
1197 if let (0, Some(ty::InstanceKind::Virtual(_, idx))) = (i, instance.map(|i| i.def)) {
1198 match op.val {
1199 Pair(data_ptr, meta) => {
1200 while !op.layout.ty.is_raw_ptr() && !op.layout.ty.is_ref() {
1210 let (idx, _) = op.layout.non_1zst_field(bx).expect(
1211 "not exactly one non-1-ZST field in a `DispatchFromDyn` type",
1212 );
1213 op = op.extract_field(self, bx, idx.as_usize());
1214 }
1215
1216 llfn = Some(meth::VirtualIndex::from_index(idx).get_fn(
1220 bx,
1221 meta,
1222 op.layout.ty,
1223 fn_abi,
1224 ));
1225 llargs.push(data_ptr);
1226 continue 'make_args;
1227 }
1228 Ref(PlaceValue { llval: data_ptr, llextra: Some(meta), .. }) => {
1229 llfn = Some(meth::VirtualIndex::from_index(idx).get_fn(
1231 bx,
1232 meta,
1233 op.layout.ty,
1234 fn_abi,
1235 ));
1236 llargs.push(data_ptr);
1237 continue;
1238 }
1239 _ => {
1240 ::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);
1241 }
1242 }
1243 }
1244
1245 match kind {
1246 CallKind::Normal => {
1247 if let &mir::Operand::Copy(_) | &mir::Operand::Constant(_) = &arg.node
1250 && let Ref(PlaceValue { llextra: None, .. }) = op.val
1251 {
1252 let tmp = PlaceRef::alloca(bx, op.layout);
1253 bx.lifetime_start(tmp.val.llval, tmp.layout.size);
1254 op.store_with_annotation(bx, tmp);
1255 op.val = Ref(tmp.val);
1256 lifetime_ends_after_call.push((tmp.val.llval, tmp.layout.size));
1257 }
1258 }
1259 CallKind::Tail => {
1260 match fn_abi.args[i].mode {
1261 PassMode::Indirect { on_stack: false, .. } => {
1262 let Some(tmp) = tail_call_temporaries[i].take() else {
1263 ::rustc_middle::util::bug::span_bug_fmt(fn_span,
format_args!("missing temporary for indirect tail call argument #{0}", i))span_bug!(
1264 fn_span,
1265 "missing temporary for indirect tail call argument #{i}"
1266 )
1267 };
1268
1269 let local = self.mir.args_iter().nth(i).unwrap();
1270
1271 match &self.locals[local] {
1272 LocalRef::Place(arg) => {
1273 bx.typed_place_copy(arg.val, tmp.val, fn_abi.args[i].layout);
1274 op.val = Ref(arg.val);
1275 }
1276 LocalRef::Operand(arg) => {
1277 let Ref(place_value) = arg.val else {
1278 ::rustc_middle::util::bug::bug_fmt(format_args!("only `Ref` should use `PassMode::Indirect`"));bug!("only `Ref` should use `PassMode::Indirect`");
1279 };
1280 bx.typed_place_copy(
1281 place_value,
1282 tmp.val,
1283 fn_abi.args[i].layout,
1284 );
1285 op.val = arg.val;
1286 }
1287 LocalRef::UnsizedPlace(_) => {
1288 ::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")
1289 }
1290 LocalRef::PendingOperand => {
1291 ::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")
1292 }
1293 };
1294
1295 bx.lifetime_end(tmp.val.llval, tmp.layout.size);
1296 }
1297 PassMode::Indirect { on_stack: true, .. } => {
1298 ::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!(
1304 fn_span,
1305 "arguments using PassMode::Indirect {{ on_stack: true, .. }} are currently not supported for tail calls"
1306 )
1307 }
1308 _ => (),
1309 }
1310 }
1311 }
1312
1313 self.codegen_argument(
1314 bx,
1315 op,
1316 &mut llargs,
1317 &fn_abi.args[i],
1318 &mut lifetime_ends_after_call,
1319 );
1320 }
1321 let num_untupled = untuple.map(|tup| {
1322 self.codegen_arguments_untupled(
1323 bx,
1324 &tup.node,
1325 &mut llargs,
1326 &fn_abi.args[first_args.len()..],
1327 &mut lifetime_ends_after_call,
1328 )
1329 });
1330
1331 let needs_location =
1332 instance.is_some_and(|i| i.def.requires_caller_location(self.cx.tcx()));
1333 if needs_location {
1334 let mir_args = if let Some(num_untupled) = num_untupled {
1335 first_args.len() + num_untupled
1336 } else {
1337 args.len()
1338 };
1339 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!(
1340 fn_abi.args.len(),
1341 mir_args + 1,
1342 "#[track_caller] fn's must have 1 more argument in their ABI than in their MIR: {instance:?} {fn_span:?} {fn_abi:?}",
1343 );
1344 let location = self.get_caller_location(bx, source_info);
1345 {
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:1345",
"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(1345u32),
::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!(
1346 "codegen_call_terminator({:?}): location={:?} (fn_span {:?})",
1347 terminator, location, fn_span
1348 );
1349
1350 let last_arg = fn_abi.args.last().unwrap();
1351 self.codegen_argument(
1352 bx,
1353 location,
1354 &mut llargs,
1355 last_arg,
1356 &mut lifetime_ends_after_call,
1357 );
1358 }
1359
1360 let fn_ptr = match (instance, llfn) {
1361 (Some(instance), None) => bx.get_fn_addr(instance),
1362 (_, Some(llfn)) => llfn,
1363 _ => ::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"),
1364 };
1365 self.set_debug_loc(bx, source_info);
1366 helper.do_call(
1367 self,
1368 bx,
1369 fn_abi,
1370 fn_ptr,
1371 &llargs,
1372 destination,
1373 unwind,
1374 &lifetime_ends_after_call,
1375 instance,
1376 kind,
1377 mergeable_succ,
1378 )
1379 }
1380
1381 fn codegen_asm_terminator(
1382 &mut self,
1383 helper: TerminatorCodegenHelper<'tcx>,
1384 bx: &mut Bx,
1385 asm_macro: InlineAsmMacro,
1386 terminator: &mir::Terminator<'tcx>,
1387 template: &[ast::InlineAsmTemplatePiece],
1388 operands: &[mir::InlineAsmOperand<'tcx>],
1389 options: ast::InlineAsmOptions,
1390 line_spans: &[Span],
1391 targets: &[mir::BasicBlock],
1392 unwind: mir::UnwindAction,
1393 instance: Instance<'_>,
1394 mergeable_succ: bool,
1395 ) -> MergingSucc {
1396 let span = terminator.source_info.span;
1397
1398 let operands: Vec<_> = operands
1399 .iter()
1400 .map(|op| match *op {
1401 mir::InlineAsmOperand::In { reg, ref value } => {
1402 let value = self.codegen_operand(bx, value);
1403 InlineAsmOperandRef::In { reg, value }
1404 }
1405 mir::InlineAsmOperand::Out { reg, late, ref place } => {
1406 let place = place.map(|place| self.codegen_place(bx, place.as_ref()));
1407 InlineAsmOperandRef::Out { reg, late, place }
1408 }
1409 mir::InlineAsmOperand::InOut { reg, late, ref in_value, ref out_place } => {
1410 let in_value = self.codegen_operand(bx, in_value);
1411 let out_place =
1412 out_place.map(|out_place| self.codegen_place(bx, out_place.as_ref()));
1413 InlineAsmOperandRef::InOut { reg, late, in_value, out_place }
1414 }
1415 mir::InlineAsmOperand::Const { ref value } => {
1416 let const_value = self.eval_mir_constant(value);
1417 let string = common::asm_const_to_str(
1418 bx.tcx(),
1419 span,
1420 const_value,
1421 bx.layout_of(value.ty()),
1422 );
1423 InlineAsmOperandRef::Const { string }
1424 }
1425 mir::InlineAsmOperand::SymFn { ref value } => {
1426 let const_ = self.monomorphize(value.const_);
1427 if let ty::FnDef(def_id, args) = *const_.ty().kind() {
1428 let instance = ty::Instance::resolve_for_fn_ptr(
1429 bx.tcx(),
1430 bx.typing_env(),
1431 def_id,
1432 args,
1433 )
1434 .unwrap();
1435 InlineAsmOperandRef::SymFn { instance }
1436 } else {
1437 ::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)");
1438 }
1439 }
1440 mir::InlineAsmOperand::SymStatic { def_id } => {
1441 InlineAsmOperandRef::SymStatic { def_id }
1442 }
1443 mir::InlineAsmOperand::Label { target_index } => {
1444 InlineAsmOperandRef::Label { label: self.llbb(targets[target_index]) }
1445 }
1446 })
1447 .collect();
1448
1449 helper.do_inlineasm(
1450 self,
1451 bx,
1452 template,
1453 &operands,
1454 options,
1455 line_spans,
1456 if asm_macro.diverges(options) { None } else { targets.get(0).copied() },
1457 unwind,
1458 instance,
1459 mergeable_succ,
1460 )
1461 }
1462
1463 pub(crate) fn codegen_block(&mut self, mut bb: mir::BasicBlock) {
1464 let llbb = match self.try_llbb(bb) {
1465 Some(llbb) => llbb,
1466 None => return,
1467 };
1468 let bx = &mut Bx::build(self.cx, llbb);
1469 let mir = self.mir;
1470
1471 loop {
1475 let data = &mir[bb];
1476
1477 {
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:1477",
"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(1477u32),
::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);
1478
1479 for statement in &data.statements {
1480 self.codegen_statement(bx, statement);
1481 }
1482 self.codegen_stmt_debuginfos(bx, &data.after_last_stmt_debuginfos);
1483
1484 let merging_succ = self.codegen_terminator(bx, bb, data.terminator());
1485 if let MergingSucc::False = merging_succ {
1486 break;
1487 }
1488
1489 let mut successors = data.terminator().successors();
1497 let succ = successors.next().unwrap();
1498 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));
1499 self.cached_llbbs[succ] = CachedLlbb::Skip;
1500 bb = succ;
1501 }
1502 }
1503
1504 pub(crate) fn codegen_block_as_unreachable(&mut self, bb: mir::BasicBlock) {
1505 let llbb = match self.try_llbb(bb) {
1506 Some(llbb) => llbb,
1507 None => return,
1508 };
1509 let bx = &mut Bx::build(self.cx, llbb);
1510 {
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:1510",
"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(1510u32),
::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);
1511 bx.unreachable();
1512 }
1513
1514 fn codegen_terminator(
1515 &mut self,
1516 bx: &mut Bx,
1517 bb: mir::BasicBlock,
1518 terminator: &'tcx mir::Terminator<'tcx>,
1519 ) -> MergingSucc {
1520 {
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:1520",
"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(1520u32),
::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);
1521
1522 let helper = TerminatorCodegenHelper { bb, terminator };
1523
1524 let mergeable_succ = || {
1525 let mut successors = terminator.successors();
1528 if let Some(succ) = successors.next()
1529 && successors.next().is_none()
1530 && let &[succ_pred] = self.mir.basic_blocks.predecessors()[succ].as_slice()
1531 {
1532 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);
1535 true
1536 } else {
1537 false
1538 }
1539 };
1540
1541 self.set_debug_loc(bx, terminator.source_info);
1542 match terminator.kind {
1543 mir::TerminatorKind::UnwindResume => {
1544 self.codegen_resume_terminator(helper, bx);
1545 MergingSucc::False
1546 }
1547
1548 mir::TerminatorKind::UnwindTerminate(reason) => {
1549 self.codegen_terminate_terminator(helper, bx, terminator, reason);
1550 MergingSucc::False
1551 }
1552
1553 mir::TerminatorKind::Goto { target } => {
1554 helper.funclet_br(self, bx, target, mergeable_succ())
1555 }
1556
1557 mir::TerminatorKind::SwitchInt { ref discr, ref targets } => {
1558 self.codegen_switchint_terminator(helper, bx, discr, targets);
1559 MergingSucc::False
1560 }
1561
1562 mir::TerminatorKind::Return => {
1563 self.codegen_return_terminator(bx);
1564 MergingSucc::False
1565 }
1566
1567 mir::TerminatorKind::Unreachable => {
1568 bx.unreachable();
1569 MergingSucc::False
1570 }
1571
1572 mir::TerminatorKind::Drop { place, target, unwind, replace: _, drop, async_fut } => {
1573 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!(
1574 async_fut.is_none() && drop.is_none(),
1575 "Async Drop must be expanded or reset to sync before codegen"
1576 );
1577 self.codegen_drop_terminator(
1578 helper,
1579 bx,
1580 &terminator.source_info,
1581 place,
1582 target,
1583 unwind,
1584 mergeable_succ(),
1585 )
1586 }
1587
1588 mir::TerminatorKind::Assert { ref cond, expected, ref msg, target, unwind } => self
1589 .codegen_assert_terminator(
1590 helper,
1591 bx,
1592 terminator,
1593 cond,
1594 expected,
1595 msg,
1596 target,
1597 unwind,
1598 mergeable_succ(),
1599 ),
1600
1601 mir::TerminatorKind::Call {
1602 ref func,
1603 ref args,
1604 destination,
1605 target,
1606 unwind,
1607 call_source: _,
1608 fn_span,
1609 } => self.codegen_call_terminator(
1610 helper,
1611 bx,
1612 terminator,
1613 func,
1614 args,
1615 destination,
1616 target,
1617 unwind,
1618 fn_span,
1619 CallKind::Normal,
1620 mergeable_succ(),
1621 ),
1622 mir::TerminatorKind::TailCall { ref func, ref args, fn_span } => self
1623 .codegen_call_terminator(
1624 helper,
1625 bx,
1626 terminator,
1627 func,
1628 args,
1629 mir::Place::from(mir::RETURN_PLACE),
1630 None,
1631 mir::UnwindAction::Unreachable,
1632 fn_span,
1633 CallKind::Tail,
1634 mergeable_succ(),
1635 ),
1636 mir::TerminatorKind::CoroutineDrop | mir::TerminatorKind::Yield { .. } => {
1637 ::rustc_middle::util::bug::bug_fmt(format_args!("coroutine ops in codegen"))bug!("coroutine ops in codegen")
1638 }
1639 mir::TerminatorKind::FalseEdge { .. } | mir::TerminatorKind::FalseUnwind { .. } => {
1640 ::rustc_middle::util::bug::bug_fmt(format_args!("borrowck false edges in codegen"))bug!("borrowck false edges in codegen")
1641 }
1642
1643 mir::TerminatorKind::InlineAsm {
1644 asm_macro,
1645 template,
1646 ref operands,
1647 options,
1648 line_spans,
1649 ref targets,
1650 unwind,
1651 } => self.codegen_asm_terminator(
1652 helper,
1653 bx,
1654 asm_macro,
1655 terminator,
1656 template,
1657 operands,
1658 options,
1659 line_spans,
1660 targets,
1661 unwind,
1662 self.instance,
1663 mergeable_succ(),
1664 ),
1665 }
1666 }
1667
1668 fn codegen_argument(
1669 &mut self,
1670 bx: &mut Bx,
1671 op: OperandRef<'tcx, Bx::Value>,
1672 llargs: &mut Vec<Bx::Value>,
1673 arg: &ArgAbi<'tcx, Ty<'tcx>>,
1674 lifetime_ends_after_call: &mut Vec<(Bx::Value, Size)>,
1675 ) {
1676 match arg.mode {
1677 PassMode::Ignore => return,
1678 PassMode::Cast { pad_i32: true, .. } => {
1679 llargs.push(bx.const_undef(bx.reg_backend_type(&Reg::i32())));
1681 }
1682 PassMode::Pair(..) => match op.val {
1683 Pair(a, b) => {
1684 llargs.push(a);
1685 llargs.push(b);
1686 return;
1687 }
1688 _ => ::rustc_middle::util::bug::bug_fmt(format_args!("codegen_argument: {0:?} invalid for pair argument",
op))bug!("codegen_argument: {:?} invalid for pair argument", op),
1689 },
1690 PassMode::Indirect { attrs: _, meta_attrs: Some(_), on_stack: _ } => match op.val {
1691 Ref(PlaceValue { llval: a, llextra: Some(b), .. }) => {
1692 llargs.push(a);
1693 llargs.push(b);
1694 return;
1695 }
1696 _ => ::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),
1697 },
1698 _ => {}
1699 }
1700
1701 let (mut llval, align, by_ref) = match op.val {
1703 Immediate(_) | Pair(..) => match arg.mode {
1704 PassMode::Indirect { attrs, .. } => {
1705 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 let scratch = PlaceValue::alloca(bx, arg.layout.size, required_align);
1713 bx.lifetime_start(scratch.llval, arg.layout.size);
1714 op.store_with_annotation(bx, scratch.with_type(arg.layout));
1715 lifetime_ends_after_call.push((scratch.llval, arg.layout.size));
1716 (scratch.llval, scratch.align, true)
1717 }
1718 PassMode::Cast { .. } => {
1719 let scratch = PlaceRef::alloca(bx, arg.layout);
1720 op.store_with_annotation(bx, scratch);
1721 (scratch.val.llval, scratch.val.align, true)
1722 }
1723 _ => (op.immediate_or_packed_pair(bx), arg.layout.align.abi, false),
1724 },
1725 Ref(op_place_val) => match arg.mode {
1726 PassMode::Indirect { attrs, .. } => {
1727 let required_align = match attrs.pointee_align {
1728 Some(pointee_align) => cmp::max(pointee_align, arg.layout.align.abi),
1729 None => arg.layout.align.abi,
1730 };
1731 if op_place_val.align < required_align {
1732 let scratch = PlaceValue::alloca(bx, arg.layout.size, required_align);
1736 bx.lifetime_start(scratch.llval, arg.layout.size);
1737 bx.typed_place_copy(scratch, op_place_val, op.layout);
1738 lifetime_ends_after_call.push((scratch.llval, arg.layout.size));
1739 (scratch.llval, scratch.align, true)
1740 } else {
1741 (op_place_val.llval, op_place_val.align, true)
1742 }
1743 }
1744 _ => (op_place_val.llval, op_place_val.align, true),
1745 },
1746 ZeroSized => match arg.mode {
1747 PassMode::Indirect { on_stack, .. } => {
1748 if on_stack {
1749 ::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:?}");
1752 }
1753 let scratch = PlaceRef::alloca(bx, arg.layout);
1757 (scratch.val.llval, scratch.val.align, true)
1758 }
1759 _ => ::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:?}"),
1760 },
1761 };
1762
1763 if by_ref && !arg.is_indirect() {
1764 if let PassMode::Cast { cast, pad_i32: _ } = &arg.mode {
1766 let scratch_size = cast.size(bx);
1770 let scratch_align = cast.align(bx);
1771 let copy_bytes = cmp::min(cast.unaligned_size(bx).bytes(), arg.layout.size.bytes());
1778 let llscratch = bx.alloca(scratch_size, scratch_align);
1780 bx.lifetime_start(llscratch, scratch_size);
1781 bx.memcpy(
1783 llscratch,
1784 scratch_align,
1785 llval,
1786 align,
1787 bx.const_usize(copy_bytes),
1788 MemFlags::empty(),
1789 None,
1790 );
1791 llval = load_cast(bx, cast, llscratch, scratch_align);
1793 bx.lifetime_end(llscratch, scratch_size);
1794 } else {
1795 llval = bx.load(bx.backend_type(arg.layout), llval, align);
1801 if let BackendRepr::Scalar(scalar) = arg.layout.backend_repr {
1802 if scalar.is_bool() {
1803 bx.range_metadata(llval, WrappingRange { start: 0, end: 1 });
1804 }
1805 llval = bx.to_immediate_scalar(llval, scalar);
1807 }
1808 }
1809 }
1810
1811 llargs.push(llval);
1812 }
1813
1814 fn codegen_arguments_untupled(
1815 &mut self,
1816 bx: &mut Bx,
1817 operand: &mir::Operand<'tcx>,
1818 llargs: &mut Vec<Bx::Value>,
1819 args: &[ArgAbi<'tcx, Ty<'tcx>>],
1820 lifetime_ends_after_call: &mut Vec<(Bx::Value, Size)>,
1821 ) -> usize {
1822 let tuple = self.codegen_operand(bx, operand);
1823
1824 if let Ref(place_val) = tuple.val {
1826 if place_val.llextra.is_some() {
1827 ::rustc_middle::util::bug::bug_fmt(format_args!("closure arguments must be sized"));bug!("closure arguments must be sized");
1828 }
1829 let tuple_ptr = place_val.with_type(tuple.layout);
1830 for i in 0..tuple.layout.fields.count() {
1831 let field_ptr = tuple_ptr.project_field(bx, i);
1832 let field = bx.load_operand(field_ptr);
1833 self.codegen_argument(bx, field, llargs, &args[i], lifetime_ends_after_call);
1834 }
1835 } else {
1836 for i in 0..tuple.layout.fields.count() {
1838 let op = tuple.extract_field(self, bx, i);
1839 self.codegen_argument(bx, op, llargs, &args[i], lifetime_ends_after_call);
1840 }
1841 }
1842 tuple.layout.fields.count()
1843 }
1844
1845 pub(super) fn get_caller_location(
1846 &mut self,
1847 bx: &mut Bx,
1848 source_info: mir::SourceInfo,
1849 ) -> OperandRef<'tcx, Bx::Value> {
1850 self.mir.caller_location_span(source_info, self.caller_location, bx.tcx(), |span: Span| {
1851 let const_loc = bx.tcx().span_as_caller_location(span);
1852 OperandRef::from_const(bx, const_loc, bx.tcx().caller_location_ty())
1853 })
1854 }
1855
1856 fn get_personality_slot(&mut self, bx: &mut Bx) -> PlaceRef<'tcx, Bx::Value> {
1857 let cx = bx.cx();
1858 if let Some(slot) = self.personality_slot {
1859 slot
1860 } else {
1861 let layout = cx.layout_of(Ty::new_tup(
1862 cx.tcx(),
1863 &[Ty::new_mut_ptr(cx.tcx(), cx.tcx().types.u8), cx.tcx().types.i32],
1864 ));
1865 let slot = PlaceRef::alloca(bx, layout);
1866 self.personality_slot = Some(slot);
1867 slot
1868 }
1869 }
1870
1871 fn landing_pad_for(&mut self, bb: mir::BasicBlock) -> Bx::BasicBlock {
1874 if let Some(landing_pad) = self.landing_pads[bb] {
1875 return landing_pad;
1876 }
1877
1878 let landing_pad = self.landing_pad_for_uncached(bb);
1879 self.landing_pads[bb] = Some(landing_pad);
1880 landing_pad
1881 }
1882
1883 fn landing_pad_for_uncached(&mut self, bb: mir::BasicBlock) -> Bx::BasicBlock {
1885 let llbb = self.llbb(bb);
1886 if base::wants_new_eh_instructions(self.cx.sess()) {
1887 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:?}"));
1888 let mut cleanup_bx = Bx::build(self.cx, cleanup_bb);
1889 let funclet = cleanup_bx.cleanup_pad(None, &[]);
1890 cleanup_bx.br(llbb);
1891 self.funclets[bb] = Some(funclet);
1892 cleanup_bb
1893 } else {
1894 let cleanup_llbb = Bx::append_block(self.cx, self.llfn, "cleanup");
1895 let mut cleanup_bx = Bx::build(self.cx, cleanup_llbb);
1896
1897 let llpersonality = self.cx.eh_personality();
1898 let (exn0, exn1) = cleanup_bx.cleanup_landing_pad(llpersonality);
1899
1900 let slot = self.get_personality_slot(&mut cleanup_bx);
1901 slot.storage_live(&mut cleanup_bx);
1902 Pair(exn0, exn1).store(&mut cleanup_bx, slot);
1903
1904 cleanup_bx.br(llbb);
1905 cleanup_llbb
1906 }
1907 }
1908
1909 fn unreachable_block(&mut self) -> Bx::BasicBlock {
1910 self.unreachable_block.unwrap_or_else(|| {
1911 let llbb = Bx::append_block(self.cx, self.llfn, "unreachable");
1912 let mut bx = Bx::build(self.cx, llbb);
1913 bx.unreachable();
1914 self.unreachable_block = Some(llbb);
1915 llbb
1916 })
1917 }
1918
1919 fn terminate_block(&mut self, reason: UnwindTerminateReason) -> Bx::BasicBlock {
1920 if let Some((cached_bb, cached_reason)) = self.terminate_block
1921 && reason == cached_reason
1922 {
1923 return cached_bb;
1924 }
1925
1926 let funclet;
1927 let llbb;
1928 let mut bx;
1929 if base::wants_new_eh_instructions(self.cx.sess()) {
1930 llbb = Bx::append_block(self.cx, self.llfn, "cs_terminate");
1960 let cp_llbb = Bx::append_block(self.cx, self.llfn, "cp_terminate");
1961
1962 let mut cs_bx = Bx::build(self.cx, llbb);
1963 let cs = cs_bx.catch_switch(None, None, &[cp_llbb]);
1964
1965 bx = Bx::build(self.cx, cp_llbb);
1966 let null =
1967 bx.const_null(bx.type_ptr_ext(bx.cx().data_layout().instruction_address_space));
1968
1969 let args = if base::wants_msvc_seh(self.cx.sess()) {
1973 let adjectives = bx.const_i32(0x40);
1980 &[null, adjectives, null] as &[_]
1981 } else {
1982 &[null] as &[_]
1988 };
1989
1990 funclet = Some(bx.catch_pad(cs, args));
1991 } else {
1992 llbb = Bx::append_block(self.cx, self.llfn, "terminate");
1993 bx = Bx::build(self.cx, llbb);
1994
1995 let llpersonality = self.cx.eh_personality();
1996 bx.filter_landing_pad(llpersonality);
1997
1998 funclet = None;
1999 }
2000
2001 self.set_debug_loc(&mut bx, mir::SourceInfo::outermost(self.mir.span));
2002
2003 let (fn_abi, fn_ptr, instance) =
2004 common::build_langcall(&bx, self.mir.span, reason.lang_item());
2005 if is_call_from_compiler_builtins_to_upstream_monomorphization(bx.tcx(), instance) {
2006 bx.abort();
2007 } else {
2008 let fn_ty = bx.fn_decl_backend_type(fn_abi);
2009
2010 let llret = bx.call(fn_ty, None, Some(fn_abi), fn_ptr, &[], funclet.as_ref(), None);
2011 bx.apply_attrs_to_cleanup_callsite(llret);
2012 }
2013
2014 bx.unreachable();
2015
2016 self.terminate_block = Some((llbb, reason));
2017 llbb
2018 }
2019
2020 pub fn llbb(&mut self, bb: mir::BasicBlock) -> Bx::BasicBlock {
2025 self.try_llbb(bb).unwrap()
2026 }
2027
2028 pub(crate) fn try_llbb(&mut self, bb: mir::BasicBlock) -> Option<Bx::BasicBlock> {
2030 match self.cached_llbbs[bb] {
2031 CachedLlbb::None => {
2032 let llbb = Bx::append_block(self.cx, self.llfn, &::alloc::__export::must_use({
::alloc::fmt::format(format_args!("{0:?}", bb))
})format!("{bb:?}"));
2033 self.cached_llbbs[bb] = CachedLlbb::Some(llbb);
2034 Some(llbb)
2035 }
2036 CachedLlbb::Some(llbb) => Some(llbb),
2037 CachedLlbb::Skip => None,
2038 }
2039 }
2040
2041 fn make_return_dest(
2042 &mut self,
2043 bx: &mut Bx,
2044 dest: mir::Place<'tcx>,
2045 fn_ret: &ArgAbi<'tcx, Ty<'tcx>>,
2046 llargs: &mut Vec<Bx::Value>,
2047 ) -> ReturnDest<'tcx, Bx::Value> {
2048 if fn_ret.is_ignore() {
2050 return ReturnDest::Nothing;
2051 }
2052 let dest = if let Some(index) = dest.as_local() {
2053 match self.locals[index] {
2054 LocalRef::Place(dest) => dest,
2055 LocalRef::UnsizedPlace(_) => ::rustc_middle::util::bug::bug_fmt(format_args!("return type must be sized"))bug!("return type must be sized"),
2056 LocalRef::PendingOperand => {
2057 return if fn_ret.is_indirect() {
2060 let tmp = PlaceRef::alloca(bx, fn_ret.layout);
2063 tmp.storage_live(bx);
2064 llargs.push(tmp.val.llval);
2065 ReturnDest::IndirectOperand(tmp, index)
2066 } else {
2067 ReturnDest::DirectOperand(index)
2068 };
2069 }
2070 LocalRef::Operand(_) => {
2071 ::rustc_middle::util::bug::bug_fmt(format_args!("place local already assigned to"));bug!("place local already assigned to");
2072 }
2073 }
2074 } else {
2075 self.codegen_place(bx, dest.as_ref())
2076 };
2077 if fn_ret.is_indirect() {
2078 if dest.val.align < dest.layout.align.abi {
2079 ::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");
2086 }
2087 llargs.push(dest.val.llval);
2088 ReturnDest::Nothing
2089 } else {
2090 ReturnDest::Store(dest)
2091 }
2092 }
2093
2094 fn store_return(
2096 &mut self,
2097 bx: &mut Bx,
2098 dest: ReturnDest<'tcx, Bx::Value>,
2099 ret_abi: &ArgAbi<'tcx, Ty<'tcx>>,
2100 llval: Bx::Value,
2101 ) {
2102 use self::ReturnDest::*;
2103
2104 match dest {
2105 Nothing => (),
2106 Store(dst) => bx.store_arg(ret_abi, llval, dst),
2107 IndirectOperand(tmp, index) => {
2108 let op = bx.load_operand(tmp);
2109 tmp.storage_dead(bx);
2110 self.overwrite_local(index, LocalRef::Operand(op));
2111 self.debug_introduce_local(bx, index);
2112 }
2113 DirectOperand(index) => {
2114 let op = if let PassMode::Cast { .. } = ret_abi.mode {
2116 let tmp = PlaceRef::alloca(bx, ret_abi.layout);
2117 tmp.storage_live(bx);
2118 bx.store_arg(ret_abi, llval, tmp);
2119 let op = bx.load_operand(tmp);
2120 tmp.storage_dead(bx);
2121 op
2122 } else {
2123 OperandRef::from_immediate_or_packed_pair(bx, llval, ret_abi.layout)
2124 };
2125 self.overwrite_local(index, LocalRef::Operand(op));
2126 self.debug_introduce_local(bx, index);
2127 }
2128 }
2129 }
2130}
2131
2132enum ReturnDest<'tcx, V> {
2133 Nothing,
2135 Store(PlaceRef<'tcx, V>),
2137 IndirectOperand(PlaceRef<'tcx, V>, mir::Local),
2139 DirectOperand(mir::Local),
2141}
2142
2143fn load_cast<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
2144 bx: &mut Bx,
2145 cast: &CastTarget,
2146 ptr: Bx::Value,
2147 align: Align,
2148) -> Bx::Value {
2149 let cast_ty = bx.cast_backend_type(cast);
2150 if let Some(offset_from_start) = cast.rest_offset {
2151 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()));
2152 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);
2153 let first_ty = bx.reg_backend_type(&cast.prefix[0].unwrap());
2154 let second_ty = bx.reg_backend_type(&cast.rest.unit);
2155 let first = bx.load(first_ty, ptr, align);
2156 let second_ptr = bx.inbounds_ptradd(ptr, bx.const_usize(offset_from_start.bytes()));
2157 let second = bx.load(second_ty, second_ptr, align.restrict_for_offset(offset_from_start));
2158 let res = bx.cx().const_poison(cast_ty);
2159 let res = bx.insert_value(res, first, 0);
2160 bx.insert_value(res, second, 1)
2161 } else {
2162 bx.load(cast_ty, ptr, align)
2163 }
2164}
2165
2166pub fn store_cast<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
2167 bx: &mut Bx,
2168 cast: &CastTarget,
2169 value: Bx::Value,
2170 ptr: Bx::Value,
2171 align: Align,
2172) {
2173 if let Some(offset_from_start) = cast.rest_offset {
2174 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()));
2175 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);
2176 if !cast.prefix[0].is_some() {
::core::panicking::panic("assertion failed: cast.prefix[0].is_some()")
};assert!(cast.prefix[0].is_some());
2177 let first = bx.extract_value(value, 0);
2178 let second = bx.extract_value(value, 1);
2179 bx.store(first, ptr, align);
2180 let second_ptr = bx.inbounds_ptradd(ptr, bx.const_usize(offset_from_start.bytes()));
2181 bx.store(second, second_ptr, align.restrict_for_offset(offset_from_start));
2182 } else {
2183 bx.store(value, ptr, align);
2184 };
2185}