Skip to content

Commit e41c82a

Browse files
committed
Fix on-stack handling for indirect calls
1 parent d252dd6 commit e41c82a

1 file changed

Lines changed: 10 additions & 7 deletions

File tree

src/builder.rs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ use rustc_span::def_id::DefId;
3232
use rustc_target::callconv::FnAbi;
3333
use rustc_target::spec::{HasTargetSpec, HasX86AbiOpt, Target, X86Abi};
3434

35+
use crate::abi::FnAbiGccExt;
3536
use crate::common::{SignType, TypeReflection, type_is_pointer};
3637
use crate::context::CodegenCx;
3738
use crate::errors;
@@ -212,6 +213,7 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> {
212213
_typ: &str,
213214
func_ptr: RValue<'gcc>,
214215
args: &'b [RValue<'gcc>],
216+
on_stack_param_indices: &FxHashSet<usize>,
215217
) -> Cow<'b, [RValue<'gcc>]> {
216218
let mut all_args_match = true;
217219
let mut param_types = vec![];
@@ -224,11 +226,6 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> {
224226
param_types.push(param);
225227
}
226228

227-
let mut on_stack_param_indices = FxHashSet::default();
228-
if let Some(indices) = self.on_stack_params.borrow().get(&gcc_func) {
229-
on_stack_param_indices.clone_from(indices);
230-
}
231-
232229
if all_args_match {
233230
return Cow::Borrowed(args);
234231
}
@@ -350,6 +347,7 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> {
350347
fn function_ptr_call(
351348
&mut self,
352349
typ: Type<'gcc>,
350+
fn_abi: Option<&FnAbi<'tcx, Ty<'tcx>>>,
353351
mut func_ptr: RValue<'gcc>,
354352
args: &[RValue<'gcc>],
355353
_funclet: Option<&Funclet>,
@@ -364,6 +362,11 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> {
364362
}
365363
};
366364
let gcc_func = func_ptr_type.dyncast_function_ptr_type().expect("function ptr");
365+
let on_stack_param_indices = if let Some(fn_abi) = fn_abi {
366+
fn_abi.gcc_type(self.cx).on_stack_param_indices
367+
} else {
368+
self.on_stack_params.borrow().get(&gcc_func).cloned().unwrap_or_default()
369+
};
367370
let func_name = format!("{:?}", func_ptr);
368371
let previous_arg_count = args.len();
369372
let orig_args = args;
@@ -372,7 +375,7 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> {
372375
llvm::adjust_intrinsic_arguments(self, gcc_func, args.into(), &func_name)
373376
};
374377
let args_adjusted = args.len() != previous_arg_count;
375-
let args = self.check_ptr_call("call", func_ptr, &args);
378+
let args = self.check_ptr_call("call", func_ptr, &args, &on_stack_param_indices);
376379

377380
// gccjit requires to use the result of functions, even when it's not used.
378381
// That's why we assign the result to a local or call add_eval().
@@ -1777,7 +1780,7 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> {
17771780
self.function_call(func, args, funclet)
17781781
} else {
17791782
// If it's a not function that was defined, it's a function pointer.
1780-
self.function_ptr_call(typ, func, args, funclet)
1783+
self.function_ptr_call(typ, fn_abi, func, args, funclet)
17811784
};
17821785
if let Some(_fn_abi) = fn_abi {
17831786
// FIXME(bjorn3): Apply function attributes

0 commit comments

Comments
 (0)