Skip to content

Commit 664c06e

Browse files
authored
coverage: ensure topline is recorded during inlining (#42170)
Fixes JuliaCI/CoverageTools.jl#48
1 parent 70cc57c commit 664c06e

File tree

3 files changed

+29
-11
lines changed

3 files changed

+29
-11
lines changed

base/compiler/ssair/inlining.jl

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -304,29 +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-
is_opaque = isa(def, Method) && def.is_for_opaque_closure
342+
is_opaque = def.is_for_opaque_closure
325343
if is_opaque
326344
# Replace the first argument by a load of the capture environment
327345
argexprs[1] = insert_node_here!(compact,
328346
NewInstruction(Expr(:call, GlobalRef(Core, :getfield), argexprs[1], QuoteNode(:captures)),
329-
spec.ir.argtypes[1], compact.result[idx][:line]))
347+
spec.ir.argtypes[1], topline))
330348
end
331349
flag = compact.result[idx][:flag]
332350
boundscheck_idx = boundscheck

test/testhelpers/coverage_file.info

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

test/testhelpers/coverage_file.info.bad

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

0 commit comments

Comments
 (0)