Skip to content

debuginfo: Some refactoring and fix for #8670 #8684

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
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
26 changes: 21 additions & 5 deletions src/librustc/middle/trans/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,13 @@ fn fcx_has_nonzero_span(fcx: &FunctionContext) -> bool {
}
}

fn span_is_empty(opt_span: &Option<span>) -> bool {
match *opt_span {
None => true,
Some(span) => *span.lo == 0 && *span.hi == 0
}
}

struct StatRecorder<'self> {
ccx: @mut CrateContext,
name: &'self str,
Expand Down Expand Up @@ -1623,6 +1630,13 @@ pub fn new_fn_ctxt_w_id(ccx: @mut CrateContext,
}
};
let uses_outptr = type_of::return_uses_outptr(ccx.tcx, substd_output_type);

let debug_context = if id != -1 && ccx.sess.opts.debuginfo && !span_is_empty(&sp) {
Some(debuginfo::create_function_debug_context(ccx, id, param_substs, llfndecl))
} else {
None
};

let fcx = @mut FunctionContext {
llfn: llfndecl,
llenv: unsafe {
Expand All @@ -1643,7 +1657,7 @@ pub fn new_fn_ctxt_w_id(ccx: @mut CrateContext,
span: sp,
path: path,
ccx: ccx,
debug_context: None,
debug_context: debug_context,
};
fcx.llenv = unsafe {
llvm::LLVMGetParam(llfndecl, fcx.env_arg_pos() as c_uint)
Expand Down Expand Up @@ -1872,6 +1886,7 @@ pub fn trans_closure(ccx: @mut CrateContext,
param_substs,
body.info(),
Some(body.span));

let raw_llargs = create_llargs_for_fn_args(fcx, self_arg, decl.inputs);

// Set the fixed stack segment flag if necessary.
Expand All @@ -1880,10 +1895,6 @@ pub fn trans_closure(ccx: @mut CrateContext,
set_fixed_stack_segment(fcx.llfn);
}

if ccx.sess.opts.debuginfo && fcx_has_nonzero_span(fcx) {
debuginfo::create_function_metadata(fcx);
}

// Create the first basic block in the function and keep a handle on it to
// pass to finish_fn later.
let bcx_top = fcx.entry_bcx.unwrap();
Expand All @@ -1895,6 +1906,11 @@ pub fn trans_closure(ccx: @mut CrateContext,

maybe_load_env(fcx);

// Up until here, IR instructions for this function have explicitly not been annotated with
// source code location, so we don't step into call setup code. From here on, source location
// emitting should be enabled.
debuginfo::start_emitting_source_locations(fcx);

// This call to trans_block is the place where we bridge between
// translation calls that don't have a return value (trans_crate,
// trans_mod, trans_item, et cetera) and those that do
Expand Down
Loading