Skip to content

Commit

Permalink
coverage: ensure topline is recorded during inlining (JuliaLang#42170)
Browse files Browse the repository at this point in the history
  • Loading branch information
vtjnash authored and LilithHafner committed Mar 8, 2022
1 parent e1d0110 commit ed79cd2
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 11 deletions.
32 changes: 25 additions & 7 deletions base/compiler/ssair/inlining.jl
Original file line number Diff line number Diff line change
Expand Up @@ -304,29 +304,47 @@ function ir_inline_item!(compact::IncrementalCompact, idx::Int, argexprs::Vector
boundscheck::Symbol, todo_bbs::Vector{Tuple{Int, Int}})
# Ok, do the inlining here
spec = item.spec::ResolvedInliningSpec
sparam_vals = item.mi.sparam_vals
def = item.mi.def::Method
inline_cfg = spec.ir.cfg
stmt = compact.result[idx][:inst]
linetable_offset::Int32 = length(linetable)
# Append the linetable of the inlined function to our line table
inlined_at = Int(compact.result[idx][:line])
for entry in spec.ir.linetable
push!(linetable, LineInfoNode(entry.module, entry.method, entry.file, entry.line,
(entry.inlined_at > 0 ? entry.inlined_at + linetable_offset : inlined_at)))
topline::Int32 = linetable_offset + Int32(1)
coverage = coverage_enabled(def.module)
push!(linetable, LineInfoNode(def.module, def.name, def.file, Int(def.line), inlined_at))
oldlinetable = spec.ir.linetable
for oldline in 1:length(oldlinetable)
entry = oldlinetable[oldline]
newentry = LineInfoNode(entry.module, entry.method, entry.file, entry.line,
(entry.inlined_at > 0 ? entry.inlined_at + linetable_offset + (oldline == 1) : inlined_at))
if oldline == 1
# check for a duplicate on the first iteration (likely true)
if newentry === linetable[topline]
continue
else
linetable_offset += 1
end
end
push!(linetable, newentry)
end
if coverage && spec.ir.stmts[1][:line] + linetable_offset != topline
insert_node_here!(compact, NewInstruction(Expr(:code_coverage_effect), Nothing, topline))
end
(; def, sparam_vals) = item.mi
nargs_def = def.nargs::Int32
isva = nargs_def > 0 && def.isva
sig = def.sig
if isva
vararg = mk_tuplecall!(compact, argexprs[nargs_def:end], compact.result[idx][:line])
vararg = mk_tuplecall!(compact, argexprs[nargs_def:end], topline)
argexprs = Any[argexprs[1:(nargs_def - 1)]..., vararg]
end
is_opaque = isa(def, Method) && def.is_for_opaque_closure
is_opaque = def.is_for_opaque_closure
if is_opaque
# Replace the first argument by a load of the capture environment
argexprs[1] = insert_node_here!(compact,
NewInstruction(Expr(:call, GlobalRef(Core, :getfield), argexprs[1], QuoteNode(:captures)),
spec.ir.argtypes[1], compact.result[idx][:line]))
spec.ir.argtypes[1], topline))
end
flag = compact.result[idx][:flag]
boundscheck_idx = boundscheck
Expand Down
6 changes: 3 additions & 3 deletions test/testhelpers/coverage_file.info
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ DA:11,1
DA:12,1
DA:14,0
DA:17,1
DA:19,1
DA:19,2
DA:20,1
DA:22,1
LH:10
LF:13
LH:12
LF:14
end_of_record
2 changes: 1 addition & 1 deletion test/testhelpers/coverage_file.info.bad
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ DA:12,1
DA:14,0
DA:17,1
DA:18,0
DA:19,1
DA:19,2
DA:20,1
DA:22,1
DA:1234,0
Expand Down

0 comments on commit ed79cd2

Please sign in to comment.