Skip to content

set sret attribute as needed on call instructions #9158

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/librustc/middle/trans/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -655,9 +655,9 @@ pub fn FastCall(cx: @mut Block, Fn: ValueRef, Args: &[ValueRef]) -> ValueRef {
}

pub fn CallWithConv(cx: @mut Block, Fn: ValueRef, Args: &[ValueRef],
Conv: CallConv) -> ValueRef {
Conv: CallConv, sret: bool) -> ValueRef {
if cx.unreachable { return _UndefReturn(cx, Fn); }
B(cx).call_with_conv(Fn, Args, Conv)
B(cx).call_with_conv(Fn, Args, Conv, sret)
}

pub fn AtomicFence(cx: @mut Block, order: AtomicOrdering) {
Expand Down
14 changes: 7 additions & 7 deletions src/librustc/middle/trans/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use lib::llvm::llvm;
use lib::llvm::{CallConv, AtomicBinOp, AtomicOrdering, AsmDialect};
use lib::llvm::{Opcode, IntPredicate, RealPredicate, False};
use lib::llvm::{ValueRef, BasicBlockRef, BuilderRef, ModuleRef};
use lib::llvm::{StructRetAttribute};
use middle::trans::base;
use middle::trans::common::*;
use middle::trans::machine::llalign_of_min;
Expand Down Expand Up @@ -778,14 +779,9 @@ impl Builder {

pub fn call(&self, llfn: ValueRef, args: &[ValueRef]) -> ValueRef {
self.count_insn("call");

debug!("Call(llfn=%s, args=%?)",
self.ccx.tn.val_to_str(llfn),
args.map(|arg| self.ccx.tn.val_to_str(*arg)));

do args.as_imm_buf |ptr, len| {
unsafe {
llvm::LLVMBuildCall(self.llbuilder, llfn, ptr, len as c_uint, noname())
llvm::LLVMBuildCall(self.llbuilder, llfn, ptr, len as c_uint, noname())
}
}
}
Expand All @@ -801,12 +797,16 @@ impl Builder {
}

pub fn call_with_conv(&self, llfn: ValueRef, args: &[ValueRef],
conv: CallConv) -> ValueRef {
conv: CallConv, sret: bool) -> ValueRef {
self.count_insn("callwithconv");
unsafe {
let v = llvm::LLVMBuildCall(self.llbuilder, llfn, vec::raw::to_ptr(args),
args.len() as c_uint, noname());
lib::llvm::SetInstructionCallConv(v, conv);
if sret {
let return_slot = 1;
llvm::LLVMAddInstrAttribute(v, return_slot, StructRetAttribute as c_uint);
}
v
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/trans/foreign.rs
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ pub fn trans_native_call(bcx: @mut Block,
}
};

let llforeign_retval = CallWithConv(bcx, llfn, llargs_foreign, cc);
let llforeign_retval = CallWithConv(bcx, llfn, llargs_foreign, cc, fn_type.sret);

// If the function we just called does not use an outpointer,
// store the result into the rust outpointer. Cast the outpointer
Expand Down