Skip to content

Commit 99ee2ff

Browse files
committed
Fix inlinedAt debug locations
ref #922 and 35c5234
1 parent 19563a3 commit 99ee2ff

File tree

2 files changed

+15
-11
lines changed

2 files changed

+15
-11
lines changed

src/codegen.cpp

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4414,6 +4414,7 @@ static Function *emit_function(jl_lambda_info_t *lam)
44144414
}
44154415
}
44164416
ctx.lineno = lno;
4417+
int toplineno = lno;
44174418

44184419
DIBuilder dbuilder(*m);
44194420
ctx.dbuilder = &dbuilder;
@@ -4994,31 +4995,32 @@ static Function *emit_function(jl_lambda_info_t *lam)
49944995
MDNode *funcscope = (MDNode*)dbuilder.createLexicalBlockFile(SP, topfile);
49954996
MDNode *scope;
49964997
if ((dfil == topfile || dfil == NULL) &&
4997-
lno >= ctx.lineno) // if we are in the top-level file
4998-
// and the current lineno is less than
4999-
// the last, must be same-file inline
5000-
// TODO: improve this heuristic...
4998+
lno >= toplineno)
50014999
{
5002-
// set location to the current top-level line
5000+
// for sequentially-defined code,
5001+
// set location to line in top file.
5002+
// TODO: improve handling of nested inlines
50035003
loc = DebugLoc::get(lno, 1, SP, NULL);
50045004
} else {
5005-
// otherwise, we are compiling code from another file,
5006-
// so create a location for the top-level line, and
5007-
// set the DebugLoc "inlinedAt" parameter.
5005+
// otherwise, we are compiling inlined code,
5006+
// so set the DebugLoc "inlinedAt" parameter
5007+
// to the current line, then use source loc.
50085008
#ifdef LLVM37
50095009
scope = (MDNode*)dbuilder.createLexicalBlockFile(SP,dfil);
5010-
MDNode *inlineLocMd = DebugLoc::get(ctx.lineno, 1, funcscope, NULL).getAsMDNode();
5010+
MDNode *inlineLocMd = DebugLoc::get(toplineno, 1, funcscope, NULL).
5011+
getAsMDNode();
50115012
#else
50125013
scope = (MDNode*)dbuilder.createLexicalBlockFile(SP,DIFile(dfil));
5013-
MDNode *inlineLocMd = DebugLoc::get(ctx.lineno, 1, funcscope, NULL).getAsMDNode(jl_LLVMContext);
5014+
MDNode *inlineLocMd = DebugLoc::get(toplineno, 1, funcscope, NULL).
5015+
getAsMDNode(jl_LLVMContext);
50145016
#endif
50155017
loc = DebugLoc::get(lno, 1, scope, inlineLocMd);
50165018
}
50175019
builder.SetCurrentDebugLocation(loc);
50185020
}
50195021
if (do_coverage)
50205022
coverageVisitLine(filename, lno);
5021-
ctx.lineno = lno;
5023+
ctx.lineno = lno; // NOO TOUCHIE; NO TOUCH! See #922
50225024
}
50235025
if (jl_is_labelnode(stmt)) {
50245026
if (prevlabel) continue;

test/backtrace.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ eval(Expr(:function, Expr(:call, :test_inline_1),
3434
# different-file inline
3535
eval(Expr(:function, Expr(:call, :test_inline_2),
3636
Expr(:block, LineNumberNode(symbol("backtrace.jl"), 99),
37+
LineNumberNode(symbol("foobar.jl"), 666),
3738
LineNumberNode(symbol("/foo/bar/baz.jl"), 111),
3839
Expr(:call, :throw, "foo"))))
3940

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

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

7981
@noinline function test_throw_commoning(x)

0 commit comments

Comments
 (0)