Skip to content

Commit 549be5f

Browse files
committed
Emit proper function argument attributes for closure environments
1 parent 8a69110 commit 549be5f

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

src/librustc_trans/trans/base.rs

+11-7
Original file line numberDiff line numberDiff line change
@@ -2430,21 +2430,19 @@ pub fn get_fn_llvm_attributes<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, fn_ty: Ty<
24302430
use middle::ty::{BrAnon, ReLateBound};
24312431

24322432
let function_type;
2433-
let (fn_sig, abi, has_env) = match fn_ty.sty {
2434-
ty::ty_bare_fn(_, ref f) => (&f.sig, f.abi, false),
2433+
let (fn_sig, abi, env_ty) = match fn_ty.sty {
2434+
ty::ty_bare_fn(_, ref f) => (&f.sig, f.abi, None),
24352435
ty::ty_closure(closure_did, _, substs) => {
24362436
let typer = common::NormalizingClosureTyper::new(ccx.tcx());
24372437
function_type = typer.closure_type(closure_did, substs);
2438-
(&function_type.sig, RustCall, true)
2438+
let self_type = self_type_for_closure(ccx, closure_did, fn_ty);
2439+
(&function_type.sig, RustCall, Some(self_type))
24392440
}
24402441
_ => ccx.sess().bug("expected closure or function.")
24412442
};
24422443

24432444
let fn_sig = ty::erase_late_bound_regions(ccx.tcx(), fn_sig);
24442445

2445-
// Since index 0 is the return value of the llvm func, we start
2446-
// at either 1 or 2 depending on whether there's an env slot or not
2447-
let mut first_arg_offset = if has_env { 2 } else { 1 };
24482446
let mut attrs = llvm::AttrBuilder::new();
24492447
let ret_ty = fn_sig.output;
24502448

@@ -2455,7 +2453,11 @@ pub fn get_fn_llvm_attributes<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, fn_ty: Ty<
24552453
assert!(abi == RustCall);
24562454

24572455
match fn_sig.inputs[0].sty {
2458-
ty::ty_tup(ref inputs) => inputs.clone(),
2456+
ty::ty_tup(ref inputs) => {
2457+
let mut full_inputs = vec![env_ty.expect("Missing closure environment")];
2458+
full_inputs.push_all(inputs);
2459+
full_inputs
2460+
}
24592461
_ => ccx.sess().bug("expected tuple'd inputs")
24602462
}
24612463
},
@@ -2473,6 +2475,8 @@ pub fn get_fn_llvm_attributes<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, fn_ty: Ty<
24732475
_ => fn_sig.inputs.clone()
24742476
};
24752477

2478+
// Index 0 is the return value of the llvm func, so we start at 1
2479+
let mut first_arg_offset = 1;
24762480
if let ty::FnConverging(ret_ty) = ret_ty {
24772481
// A function pointer is called without the declaration
24782482
// available, so we have to apply any attributes with ABI

0 commit comments

Comments
 (0)