Skip to content

Commit b9ffffd

Browse files
committed
Move caller_location handling into codegen_intrinsic_call
1 parent 55f4b04 commit b9ffffd

File tree

2 files changed

+20
-18
lines changed

2 files changed

+20
-18
lines changed

compiler/rustc_codegen_ssa/src/mir/block.rs

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ use rustc_middle::ty::print::{with_no_trimmed_paths, with_no_visible_paths};
1111
use rustc_middle::ty::{self, Instance, List, Ty};
1212
use rustc_middle::{bug, span_bug};
1313
use rustc_session::config::OptLevel;
14+
use rustc_span::Span;
1415
use rustc_span::source_map::Spanned;
15-
use rustc_span::{Span, sym};
1616
use rustc_target::callconv::{ArgAbi, FnAbi, PassMode};
1717
use tracing::{debug, info};
1818

@@ -965,20 +965,13 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
965965
let args: Vec<_> =
966966
args.iter().map(|arg| self.codegen_operand(bx, &arg.node)).collect();
967967

968-
if matches!(intrinsic, ty::IntrinsicDef { name: sym::caller_location, .. })
969-
{
970-
let location = self.get_caller_location(bx, source_info);
971-
972-
assert_eq!(llargs, []);
973-
if let ReturnDest::IndirectOperand(tmp, _) = ret_dest {
974-
location.val.store(bx, tmp);
975-
}
976-
self.store_return(bx, ret_dest, &fn_abi.ret, location.immediate());
977-
return helper.funclet_br(self, bx, target.unwrap(), mergeable_succ);
978-
}
979-
980-
match Self::codegen_intrinsic_call(
981-
bx, instance, fn_abi, &args, dest, fn_span,
968+
match self.codegen_intrinsic_call(
969+
bx,
970+
instance,
971+
fn_abi,
972+
&args,
973+
dest,
974+
source_info,
982975
) {
983976
Ok(()) => {
984977
if let ReturnDest::IndirectOperand(dst, _) = ret_dest {
@@ -1644,7 +1637,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
16441637
tuple.layout.fields.count()
16451638
}
16461639

1647-
fn get_caller_location(
1640+
pub(super) fn get_caller_location(
16481641
&mut self,
16491642
bx: &mut Bx,
16501643
source_info: mir::SourceInfo,

compiler/rustc_codegen_ssa/src/mir/intrinsic.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
use rustc_abi::WrappingRange;
2+
use rustc_middle::mir::SourceInfo;
23
use rustc_middle::ty::{self, Ty, TyCtxt};
34
use rustc_middle::{bug, span_bug};
45
use rustc_session::config::OptLevel;
5-
use rustc_span::{Span, sym};
6+
use rustc_span::sym;
67
use rustc_target::callconv::{FnAbi, PassMode};
78

89
use super::FunctionCx;
@@ -52,13 +53,15 @@ fn memset_intrinsic<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
5253
impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
5354
/// In the `Err` case, returns the instance that should be called instead.
5455
pub fn codegen_intrinsic_call(
56+
&mut self,
5557
bx: &mut Bx,
5658
instance: ty::Instance<'tcx>,
5759
fn_abi: &FnAbi<'tcx, Ty<'tcx>>,
5860
args: &[OperandRef<'tcx, Bx::Value>],
5961
llresult: Bx::Value,
60-
span: Span,
62+
source_info: SourceInfo,
6163
) -> Result<(), ty::Instance<'tcx>> {
64+
let span = source_info.span;
6265
let callee_ty = instance.ty(bx.tcx(), bx.typing_env());
6366

6467
let ty::FnDef(def_id, fn_args) = *callee_ty.kind() else {
@@ -105,6 +108,12 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
105108
return Ok(());
106109
}
107110

111+
sym::caller_location => {
112+
let location = self.get_caller_location(bx, source_info);
113+
location.val.store(bx, result);
114+
return Ok(());
115+
}
116+
108117
sym::va_start => bx.va_start(args[0].immediate()),
109118
sym::va_end => bx.va_end(args[0].immediate()),
110119
sym::size_of_val => {

0 commit comments

Comments
 (0)