Skip to content

Commit

Permalink
Fix debug info tracking with non-linear codegen.
Browse files Browse the repository at this point in the history
  • Loading branch information
yuyichao committed Sep 7, 2016
1 parent d5521eb commit ba68017
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions src/codegen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4668,22 +4668,29 @@ static std::unique_ptr<Module> emit_function(jl_lambda_info_t *lam, jl_llvm_func
// step 12. Do codegen in control flow order
std::vector<std::pair<int,BasicBlock*>> workstack;
int cursor = 0;
// Whether we are doing codegen in statement order.
// We need to update debug location if this is false even if
// `loc_changed` is false.
bool linear_codegen = false;
auto find_next_stmt = [&] (int seq_next) {
// `seq_next` is the next statement we want to emit
// i.e. if it exists, it's the next one following control flow and
// should be emitted into the current insert point.
if (seq_next >= 0 && (unsigned)seq_next < stmtslen) {
linear_codegen = (seq_next - cursor) == 1;
cursor = seq_next;
return;
}
if (!builder.GetInsertBlock()->getTerminator())
builder.CreateUnreachable();
if (workstack.empty()) {
cursor = -1;
linear_codegen = false;
return;
}
auto &item = workstack.back();
builder.SetInsertPoint(item.second);
linear_codegen = (item.first - cursor) == 1;
cursor = item.first;
workstack.pop_back();
};
Expand Down Expand Up @@ -4755,16 +4762,14 @@ static std::unique_ptr<Module> emit_function(jl_lambda_info_t *lam, jl_llvm_func
builder.SetCurrentDebugLocation(topdebugloc);
coverageVisitLine(filename, toplineno);
}
stmtprops[0].loc_changed = true;
while (cursor != -1) {
auto &props = stmtprops[cursor];
if (props.loc_changed) {
if (ctx.debug_enabled)
builder.SetCurrentDebugLocation(props.loc);
// Disable coverage for pop_loc, it doesn't start a new expression
if (do_coverage(props.in_user_code) && !props.is_poploc) {
coverageVisitLine(props.file, props.line);
}
if ((props.loc_changed || !linear_codegen) && ctx.debug_enabled)
builder.SetCurrentDebugLocation(props.loc);
// Disable coverage for pop_loc, it doesn't start a new expression
if (props.loc_changed && do_coverage(props.in_user_code) &&
!props.is_poploc) {
coverageVisitLine(props.file, props.line);
}
ctx.is_inbounds = props.is_inbounds;
jl_value_t *stmt = jl_array_ptr_ref(stmts, cursor);
Expand Down

0 comments on commit ba68017

Please sign in to comment.