Skip to content

Commit

Permalink
Fix inlinedAt debug locations
Browse files Browse the repository at this point in the history
  • Loading branch information
ihnorton committed Oct 3, 2015
1 parent 19563a3 commit 99ee2ff
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
24 changes: 13 additions & 11 deletions src/codegen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4414,6 +4414,7 @@ static Function *emit_function(jl_lambda_info_t *lam)
}
}
ctx.lineno = lno;
int toplineno = lno;

DIBuilder dbuilder(*m);
ctx.dbuilder = &dbuilder;
Expand Down Expand Up @@ -4994,31 +4995,32 @@ static Function *emit_function(jl_lambda_info_t *lam)
MDNode *funcscope = (MDNode*)dbuilder.createLexicalBlockFile(SP, topfile);
MDNode *scope;
if ((dfil == topfile || dfil == NULL) &&
lno >= ctx.lineno) // if we are in the top-level file
// and the current lineno is less than
// the last, must be same-file inline
// TODO: improve this heuristic...
lno >= toplineno)
{
// set location to the current top-level line
// for sequentially-defined code,
// set location to line in top file.
// TODO: improve handling of nested inlines
loc = DebugLoc::get(lno, 1, SP, NULL);
} else {
// otherwise, we are compiling code from another file,
// so create a location for the top-level line, and
// set the DebugLoc "inlinedAt" parameter.
// otherwise, we are compiling inlined code,
// so set the DebugLoc "inlinedAt" parameter
// to the current line, then use source loc.
#ifdef LLVM37
scope = (MDNode*)dbuilder.createLexicalBlockFile(SP,dfil);
MDNode *inlineLocMd = DebugLoc::get(ctx.lineno, 1, funcscope, NULL).getAsMDNode();
MDNode *inlineLocMd = DebugLoc::get(toplineno, 1, funcscope, NULL).
getAsMDNode();
#else
scope = (MDNode*)dbuilder.createLexicalBlockFile(SP,DIFile(dfil));
MDNode *inlineLocMd = DebugLoc::get(ctx.lineno, 1, funcscope, NULL).getAsMDNode(jl_LLVMContext);
MDNode *inlineLocMd = DebugLoc::get(toplineno, 1, funcscope, NULL).
getAsMDNode(jl_LLVMContext);
#endif
loc = DebugLoc::get(lno, 1, scope, inlineLocMd);
}
builder.SetCurrentDebugLocation(loc);
}
if (do_coverage)
coverageVisitLine(filename, lno);
ctx.lineno = lno;
ctx.lineno = lno; // NOO TOUCHIE; NO TOUCH! See #922
}
if (jl_is_labelnode(stmt)) {
if (prevlabel) continue;
Expand Down
2 changes: 2 additions & 0 deletions test/backtrace.jl
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ eval(Expr(:function, Expr(:call, :test_inline_1),
# different-file inline
eval(Expr(:function, Expr(:call, :test_inline_2),
Expr(:block, LineNumberNode(symbol("backtrace.jl"), 99),
LineNumberNode(symbol("foobar.jl"), 666),
LineNumberNode(symbol("/foo/bar/baz.jl"), 111),
Expr(:call, :throw, "foo"))))

Expand Down Expand Up @@ -74,6 +75,7 @@ loc = functionloc(f12977)
@test endswith(loc[1], "backtrace.jl")
@test loc[2] == linenum

# issue #922: SimplifyCFG pass merges throws
code_loc(p, skipC=true) = ccall(:jl_lookup_code_address, Any, (Ptr{Void},Cint), p, skipC)

@noinline function test_throw_commoning(x)
Expand Down

0 comments on commit 99ee2ff

Please sign in to comment.