From efdcbf5661b531ee5dd0da89e0d88a16ca87f22e Mon Sep 17 00:00:00 2001 From: Isaiah Norton Date: Fri, 2 Oct 2015 23:40:26 -0400 Subject: [PATCH] Fix inlinedAt debug locations ref #922 and 35c5234a (cherry picked from commit 99ee2ffe229842f8713b5b6436eecf1d360c362b) ref #13431 --- src/codegen.cpp | 24 +++++++++++++----------- test/backtrace.jl | 2 ++ 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/src/codegen.cpp b/src/codegen.cpp index ac20bf6a93869..d3f4a4bfbb929 100644 --- a/src/codegen.cpp +++ b/src/codegen.cpp @@ -4184,6 +4184,7 @@ static Function *emit_function(jl_lambda_info_t *lam) } } ctx.lineno = lno; + int toplineno = lno; DIBuilder dbuilder(*m); ctx.dbuilder = &dbuilder; @@ -4732,23 +4733,24 @@ 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); } @@ -4756,7 +4758,7 @@ static Function *emit_function(jl_lambda_info_t *lam) } 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; diff --git a/test/backtrace.jl b/test/backtrace.jl index 19c0f4f17eeeb..16bfec0f626d1 100644 --- a/test/backtrace.jl +++ b/test/backtrace.jl @@ -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")))) @@ -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)