Skip to content

Never create allocas for indirect function arguments #27687

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
17 changes: 9 additions & 8 deletions src/librustc_trans/trans/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ use middle::pat_util::simple_identifier;
use middle::subst::Substs;
use middle::ty::{self, Ty, HasTypeFlags};
use rustc::ast_map;
use session::config::{self, NoDebugInfo, FullDebugInfo};
use session::config::{self, NoDebugInfo};
use session::Session;
use trans::_match;
use trans::adt;
Expand Down Expand Up @@ -1370,12 +1370,11 @@ pub fn create_datums_for_fn_args<'a, 'tcx>(mut bcx: Block<'a, 'tcx>,
// the event it's not truly needed.
let mut idx = fcx.arg_offset() as c_uint;
for (i, &arg_ty) in arg_tys.iter().enumerate() {
let mut indirect_arg = type_of::arg_is_indirect(bcx.ccx(), arg_ty);
let arg_datum = if !has_tupled_arg || i < arg_tys.len() - 1 {
if type_of::arg_is_indirect(bcx.ccx(), arg_ty)
&& bcx.sess().opts.debuginfo != FullDebugInfo {
if indirect_arg {
// Don't copy an indirect argument to an alloca, the caller
// already put it in a temporary alloca and gave it up, unless
// we emit extra-debug-info, which requires local allocas :(.
// already put it in a temporary alloca and gave it up
let llarg = get_param(fcx.llfn, idx);
idx += 1;
bcx.fcx.schedule_lifetime_end(arg_scope_id, llarg);
Expand Down Expand Up @@ -1450,11 +1449,13 @@ pub fn create_datums_for_fn_args<'a, 'tcx>(mut bcx: Block<'a, 'tcx>,
bcx.fcx.lllocals.borrow_mut().insert(pat.id, arg_datum);
bcx
} else {
// General path. Copy out the values that are used in the
// pattern.
// General path. Copy out the values that are used in the pattern.
// Since we're copying the values out, the argument is not indirect
// as far as debug info is concerned
indirect_arg = false;
_match::bind_irrefutable_pat(bcx, pat, arg_datum.match_input(), arg_scope_id)
};
debuginfo::create_argument_metadata(bcx, &args[i]);
debuginfo::create_argument_metadata(bcx, &args[i], indirect_arg);
}

bcx
Expand Down
19 changes: 12 additions & 7 deletions src/librustc_trans/trans/debuginfo/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2078,7 +2078,7 @@ pub fn create_match_binding_metadata<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
/// This function assumes that there's a datum for each pattern component of the
/// argument in `bcx.fcx.lllocals`.
/// Adds the created metadata nodes directly to the crate's IR.
pub fn create_argument_metadata(bcx: Block, arg: &ast::Arg) {
pub fn create_argument_metadata(bcx: Block, arg: &ast::Arg, indirect: bool) {
if bcx.unreachable.get() ||
fn_should_be_ignored(bcx.fcx) ||
bcx.sess().opts.debuginfo != FullDebugInfo {
Expand All @@ -2103,11 +2103,6 @@ pub fn create_argument_metadata(bcx: Block, arg: &ast::Arg) {
}
};

if unsafe { llvm::LLVMIsAAllocaInst(datum.val) } == ptr::null_mut() {
bcx.sess().span_bug(span, "debuginfo::create_argument_metadata() - \
Referenced variable location is not an alloca!");
}

let argument_index = {
let counter = &bcx
.fcx
Expand All @@ -2119,11 +2114,21 @@ pub fn create_argument_metadata(bcx: Block, arg: &ast::Arg) {
argument_index
};

let deref = unsafe { [llvm::LLVMDIBuilderCreateOpDeref()] };
let access = if indirect {
VariableAccess::IndirectVariable {
alloca: datum.val,
address_operations: &deref,
}
} else {
VariableAccess::DirectVariable { alloca: datum.val }
};

declare_local(bcx,
var_ident.node.name,
datum.ty,
scope_metadata,
VariableAccess::DirectVariable { alloca: datum.val },
access,
VariableKind::ArgumentVariable(argument_index),
span);
})
Expand Down