Skip to content

Commit 1a912b2

Browse files
vtjnashKristofferC
authored andcommitted
coverage: ensure topline is recorded during inlining (#42170)
Fixes JuliaCI/CoverageTools.jl#48 (cherry picked from commit 664c06e)
1 parent 3fa2d26 commit 1a912b2

File tree

3 files changed

+29
-12
lines changed

3 files changed

+29
-12
lines changed

base/compiler/ssair/inlining.jl

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -304,30 +304,47 @@ function ir_inline_item!(compact::IncrementalCompact, idx::Int, argexprs::Vector
304304
boundscheck::Symbol, todo_bbs::Vector{Tuple{Int, Int}})
305305
# Ok, do the inlining here
306306
spec = item.spec::ResolvedInliningSpec
307+
sparam_vals = item.mi.sparam_vals
308+
def = item.mi.def::Method
307309
inline_cfg = spec.ir.cfg
308310
stmt = compact.result[idx][:inst]
309311
linetable_offset::Int32 = length(linetable)
310312
# Append the linetable of the inlined function to our line table
311313
inlined_at = Int(compact.result[idx][:line])
312-
for entry in spec.ir.linetable
313-
push!(linetable, LineInfoNode(entry.module, entry.method, entry.file, entry.line,
314-
(entry.inlined_at > 0 ? entry.inlined_at + linetable_offset : inlined_at)))
314+
topline::Int32 = linetable_offset + Int32(1)
315+
coverage = coverage_enabled(def.module)
316+
push!(linetable, LineInfoNode(def.module, def.name, def.file, Int(def.line), inlined_at))
317+
oldlinetable = spec.ir.linetable
318+
for oldline in 1:length(oldlinetable)
319+
entry = oldlinetable[oldline]
320+
newentry = LineInfoNode(entry.module, entry.method, entry.file, entry.line,
321+
(entry.inlined_at > 0 ? entry.inlined_at + linetable_offset + (oldline == 1) : inlined_at))
322+
if oldline == 1
323+
# check for a duplicate on the first iteration (likely true)
324+
if newentry === linetable[topline]
325+
continue
326+
else
327+
linetable_offset += 1
328+
end
329+
end
330+
push!(linetable, newentry)
331+
end
332+
if coverage && spec.ir.stmts[1][:line] + linetable_offset != topline
333+
insert_node_here!(compact, NewInstruction(Expr(:code_coverage_effect), Nothing, topline))
315334
end
316-
(; def, sparam_vals) = item.mi
317335
nargs_def = def.nargs::Int32
318336
isva = nargs_def > 0 && def.isva
319337
sig = def.sig
320338
if isva
321-
vararg = mk_tuplecall!(compact, argexprs[nargs_def:end], compact.result[idx][:line])
339+
vararg = mk_tuplecall!(compact, argexprs[nargs_def:end], topline)
322340
argexprs = Any[argexprs[1:(nargs_def - 1)]..., vararg]
323341
end
324-
mi = item.mi
325-
is_opaque = isa(mi.def, Method) && mi.def.is_for_opaque_closure
342+
is_opaque = def.is_for_opaque_closure
326343
if is_opaque
327344
# Replace the first argument by a load of the capture environment
328345
argexprs[1] = insert_node_here!(compact,
329346
NewInstruction(Expr(:call, GlobalRef(Core, :getfield), argexprs[1], QuoteNode(:captures)),
330-
spec.ir.argtypes[1], compact.result[idx][:line]))
347+
spec.ir.argtypes[1], topline))
331348
end
332349
flag = compact.result[idx][:flag]
333350
boundscheck_idx = boundscheck

test/testhelpers/coverage_file.info

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ DA:11,1
99
DA:12,1
1010
DA:14,0
1111
DA:17,1
12-
DA:19,1
12+
DA:19,2
1313
DA:20,1
1414
DA:22,1
15-
LH:10
16-
LF:13
15+
LH:12
16+
LF:14
1717
end_of_record

test/testhelpers/coverage_file.info.bad

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ DA:12,1
1010
DA:14,0
1111
DA:17,1
1212
DA:18,0
13-
DA:19,1
13+
DA:19,2
1414
DA:20,1
1515
DA:22,1
1616
DA:1234,0

0 commit comments

Comments
 (0)