Skip to content

Commit 98258e3

Browse files
committed
Never create allocas for indirect function arguments
The assertion that argument debuginfo always has to be assigned to allocas only exists in rustc, not in LLVM. The reason for that assertion might have been that we used to created bad debuginfo for closures which did indeed lead to errors when we skipped the alloca, but this was fixed in commit 218eccf "Fix de-deduplication for closure debuginfo". So now we can always skip the alloca for indirect arguments, even when generating debuginfo.
1 parent 58b0aa5 commit 98258e3

File tree

2 files changed

+21
-15
lines changed

2 files changed

+21
-15
lines changed

src/librustc_trans/trans/base.rs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ use middle::pat_util::simple_identifier;
4343
use middle::subst::Substs;
4444
use middle::ty::{self, Ty, HasTypeFlags};
4545
use rustc::ast_map;
46-
use session::config::{self, NoDebugInfo, FullDebugInfo};
46+
use session::config::{self, NoDebugInfo};
4747
use session::Session;
4848
use trans::_match;
4949
use trans::adt;
@@ -1370,12 +1370,11 @@ pub fn create_datums_for_fn_args<'a, 'tcx>(mut bcx: Block<'a, 'tcx>,
13701370
// the event it's not truly needed.
13711371
let mut idx = fcx.arg_offset() as c_uint;
13721372
for (i, &arg_ty) in arg_tys.iter().enumerate() {
1373+
let mut indirect_arg = type_of::arg_is_indirect(bcx.ccx(), arg_ty);
13731374
let arg_datum = if !has_tupled_arg || i < arg_tys.len() - 1 {
1374-
if type_of::arg_is_indirect(bcx.ccx(), arg_ty)
1375-
&& bcx.sess().opts.debuginfo != FullDebugInfo {
1375+
if indirect_arg {
13761376
// Don't copy an indirect argument to an alloca, the caller
1377-
// already put it in a temporary alloca and gave it up, unless
1378-
// we emit extra-debug-info, which requires local allocas :(.
1377+
// already put it in a temporary alloca and gave it up
13791378
let llarg = get_param(fcx.llfn, idx);
13801379
idx += 1;
13811380
bcx.fcx.schedule_lifetime_end(arg_scope_id, llarg);
@@ -1450,11 +1449,13 @@ pub fn create_datums_for_fn_args<'a, 'tcx>(mut bcx: Block<'a, 'tcx>,
14501449
bcx.fcx.lllocals.borrow_mut().insert(pat.id, arg_datum);
14511450
bcx
14521451
} else {
1453-
// General path. Copy out the values that are used in the
1454-
// pattern.
1452+
// General path. Copy out the values that are used in the pattern.
1453+
// Since we're copying the values out, the argument is not indirect
1454+
// as far as debug info is concerned
1455+
indirect_arg = false;
14551456
_match::bind_irrefutable_pat(bcx, pat, arg_datum.match_input(), arg_scope_id)
14561457
};
1457-
debuginfo::create_argument_metadata(bcx, &args[i]);
1458+
debuginfo::create_argument_metadata(bcx, &args[i], indirect_arg);
14581459
}
14591460

14601461
bcx

src/librustc_trans/trans/debuginfo/metadata.rs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2078,7 +2078,7 @@ pub fn create_match_binding_metadata<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
20782078
/// This function assumes that there's a datum for each pattern component of the
20792079
/// argument in `bcx.fcx.lllocals`.
20802080
/// Adds the created metadata nodes directly to the crate's IR.
2081-
pub fn create_argument_metadata(bcx: Block, arg: &ast::Arg) {
2081+
pub fn create_argument_metadata(bcx: Block, arg: &ast::Arg, indirect: bool) {
20822082
if bcx.unreachable.get() ||
20832083
fn_should_be_ignored(bcx.fcx) ||
20842084
bcx.sess().opts.debuginfo != FullDebugInfo {
@@ -2103,11 +2103,6 @@ pub fn create_argument_metadata(bcx: Block, arg: &ast::Arg) {
21032103
}
21042104
};
21052105

2106-
if unsafe { llvm::LLVMIsAAllocaInst(datum.val) } == ptr::null_mut() {
2107-
bcx.sess().span_bug(span, "debuginfo::create_argument_metadata() - \
2108-
Referenced variable location is not an alloca!");
2109-
}
2110-
21112106
let argument_index = {
21122107
let counter = &bcx
21132108
.fcx
@@ -2119,11 +2114,21 @@ pub fn create_argument_metadata(bcx: Block, arg: &ast::Arg) {
21192114
argument_index
21202115
};
21212116

2117+
let deref = unsafe { [llvm::LLVMDIBuilderCreateOpDeref()] };
2118+
let access = if indirect {
2119+
VariableAccess::IndirectVariable {
2120+
alloca: datum.val,
2121+
address_operations: &deref,
2122+
}
2123+
} else {
2124+
VariableAccess::DirectVariable { alloca: datum.val }
2125+
};
2126+
21222127
declare_local(bcx,
21232128
var_ident.node.name,
21242129
datum.ty,
21252130
scope_metadata,
2126-
VariableAccess::DirectVariable { alloca: datum.val },
2131+
access,
21272132
VariableKind::ArgumentVariable(argument_index),
21282133
span);
21292134
})

0 commit comments

Comments
 (0)