Skip to content

Commit efdcbf5

Browse files
ihnortontkelman
authored andcommitted
Fix inlinedAt debug locations
ref #922 and 35c5234 (cherry picked from commit 99ee2ff) ref #13431
1 parent 63de70a commit efdcbf5

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
@@ -4184,6 +4184,7 @@ static Function *emit_function(jl_lambda_info_t *lam)
41844184
}
41854185
}
41864186
ctx.lineno = lno;
4187+
int toplineno = lno;
41874188

41884189
DIBuilder dbuilder(*m);
41894190
ctx.dbuilder = &dbuilder;
@@ -4732,31 +4733,32 @@ static Function *emit_function(jl_lambda_info_t *lam)
47324733
MDNode *funcscope = (MDNode*)dbuilder.createLexicalBlockFile(SP, topfile);
47334734
MDNode *scope;
47344735
if ((dfil == topfile || dfil == NULL) &&
4735-
lno >= ctx.lineno) // if we are in the top-level file
4736-
// and the current lineno is less than
4737-
// the last, must be same-file inline
4738-
// TODO: improve this heuristic...
4736+
lno >= toplineno)
47394737
{
4740-
// set location to the current top-level line
4738+
// for sequentially-defined code,
4739+
// set location to line in top file.
4740+
// TODO: improve handling of nested inlines
47414741
loc = DebugLoc::get(lno, 1, SP, NULL);
47424742
} else {
4743-
// otherwise, we are compiling code from another file,
4744-
// so create a location for the top-level line, and
4745-
// set the DebugLoc "inlinedAt" parameter.
4743+
// otherwise, we are compiling inlined code,
4744+
// so set the DebugLoc "inlinedAt" parameter
4745+
// to the current line, then use source loc.
47464746
#ifdef LLVM37
47474747
scope = (MDNode*)dbuilder.createLexicalBlockFile(SP,dfil);
4748-
MDNode *inlineLocMd = DebugLoc::get(ctx.lineno, 1, funcscope, NULL).getAsMDNode();
4748+
MDNode *inlineLocMd = DebugLoc::get(toplineno, 1, funcscope, NULL).
4749+
getAsMDNode();
47494750
#else
47504751
scope = (MDNode*)dbuilder.createLexicalBlockFile(SP,DIFile(dfil));
4751-
MDNode *inlineLocMd = DebugLoc::get(ctx.lineno, 1, funcscope, NULL).getAsMDNode(jl_LLVMContext);
4752+
MDNode *inlineLocMd = DebugLoc::get(toplineno, 1, funcscope, NULL).
4753+
getAsMDNode(jl_LLVMContext);
47524754
#endif
47534755
loc = DebugLoc::get(lno, 1, scope, inlineLocMd);
47544756
}
47554757
builder.SetCurrentDebugLocation(loc);
47564758
}
47574759
if (do_coverage)
47584760
coverageVisitLine(filename, lno);
4759-
ctx.lineno = lno;
4761+
ctx.lineno = lno; // NOO TOUCHIE; NO TOUCH! See #922
47604762
}
47614763
if (jl_is_labelnode(stmt)) {
47624764
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)