Repository: rust-lang/rust
File: compiler/rustc_codegen_ssa/src/mir/block.rs (Rust)

Code before:
                                }
                                LocalRef::UnsizedPlace(_) => {
                                    span_bug!(fn_span, "unsized types are not supported")
                                }
                                LocalRef::PendingOperand => {
                                    span_bug!(fn_span, "argument local should not be pending")
                                }
                            };

                            bx.lifetime_end(tmp.val.llval, tmp.layout.size);
                        }
                        PassMode::Indirect { on_stack: true, .. } => {
                            // FIXME: some LLVM backends (notably x86) do not correctly pass byval
                            // arguments to tail calls (as of LLVM 21). See also:
                            //
                            // - https://github.com/rust-lang/rust/pull/144232#discussion_r2218543841
                            // - https://github.com/rust-lang/rust/issues/144855
                            span_bug!(
                                fn_span,
                                "arguments using PassMode::Indirect {{ on_stack: true, .. }} are currently not supported for tail calls"
                            )
                        }
                        _ => (),
                    }
                }
                CallKind::Normal => {
                    // The callee needs to own the argument memory if we pass it
                    // by-ref, so make a local copy of non-immediate constants.
                    match (&arg.node, op.val) {
                        (&mir::Operand::Copy(_), Ref(PlaceValue { llextra: None, .. }))
                        | (&mir::Operand::Constant(_), Ref(PlaceValue { llextra: None, .. })) => {
                            let tmp = PlaceRef::alloca(bx, op.layout);
                            bx.lifetime_start(tmp.val.llval, tmp.layout.size);
                            op.store_with_annotation(bx, tmp);
                            op.val = Ref(tmp.val);
                            lifetime_ends_after_call.push((tmp.val.llval, tmp.layout.size));
                        }
                        _ => {}
                    }
                }
            }

            self.codegen_argument(
                bx,
                op,
                &mut llargs,
                &fn_abi.args[i],
                &mut lifetime_ends_after_call,
            );
        }
        let num_untupled = untuple.map(|tup| {

Review comment (suggestion):
nitpick: I think I'd prefer to have this branch first (i.e. please swap the order of normal/tail calls around)

Code after:
                                )
                            };

                            let local = self.mir.args_iter().nth(i).unwrap();

                            match &self.locals[local] {
                                LocalRef::Place(arg) => {
                                    bx.typed_place_copy(arg.val, tmp.val, fn_abi.args[i].layout);
                                    op.val = Ref(arg.val);
                                }
                                LocalRef::Operand(arg) => {
                                    let Ref(place_value) = arg.val else {
                                        bug!("only `Ref` should use `PassMode::Indirect`");
                                    };
                                    bx.typed_place_copy(
                                        place_value,
                                        tmp.val,
                                        fn_abi.args[i].layout,
                                    );
                                    op.val = arg.val;
                                }
                                LocalRef::UnsizedPlace(_) => {
                                    span_bug!(fn_span, "unsized types are not supported")
                                }
                                LocalRef::PendingOperand => {
                                    span_bug!(fn_span, "argument local should not be pending")
                                }
                            };

                            bx.lifetime_end(tmp.val.llval, tmp.layout.size);
                        }
                        PassMode::Indirect { on_stack: true, .. } => {
                            // FIXME: some LLVM backends (notably x86) do not correctly pass byval
                            // arguments to tail calls (as of LLVM 21). See also:
                            //
                            // - https://github.com/rust-lang/rust/pull/144232#discussion_r2218543841
                            // - https://github.com/rust-lang/rust/issues/144855
                            span_bug!(
                                fn_span,
                                "arguments using PassMode::Indirect {{ on_stack: true, .. }} are currently not supported for tail calls"
                            )
                        }
                        _ => (),
                    }
                }
            }

            self.codegen_argument(
                bx,
                op,
                &mut llargs,