Skip to content

Commit 950771e

Browse files
committed
Ignore coverpoints on line numbers <= 0; remove from DB if error message
is ignored. There clearly are no such lines in any file. These happen for certain branches generated by Coverage.py. Signed-off-by: Henry Cox <[email protected]>
1 parent c2fd3ab commit 950771e

File tree

2 files changed

+61
-10
lines changed

2 files changed

+61
-10
lines changed

bin/genhtml

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2494,22 +2494,25 @@ sub _categorizeBranchCov
24942494
# a high probability event?
24952495
foreach my $line ($branchCurrent->keylist()) {
24962496
my $type = $linemap->type($filename, $linemap->NEW, $line);
2497-
lcovutil::ignorable_error($lcovutil::ERROR_INCONSISTENT_DATA,
2498-
"'current' line $filename:$line should not be marked 'delete'")
2499-
if $type eq 'delete';
2500-
#next if $type eq 'delete';
2501-
2502-
$branchCovLines{$line} = 1;
2497+
if ($type eq 'delete') {
2498+
lcovutil::ignorable_error($lcovutil::ERROR_INCONSISTENT_DATA,
2499+
"'current' line $filename:$line should not be marked 'delete'");
2500+
delete($branchCurrent->{$line});
2501+
next;
2502+
}
25032503
my $data;
25042504
if (!exists($lineDataMap->{$line})) {
2505-
$data = LineData->new($type);
2506-
$lineDataMap->{$line} = $data;
25072505
# we expect the associated line to also have line coverage data
25082506
lcovutil::ignorable_error($lcovutil::ERROR_UNKNOWN_CATEGORY,
25092507
"line $line of $filename has branchcov but no linecov data");
2508+
# maybe should skip this branch if no line data - rather
2509+
# than building fake data.
2510+
$data = LineData->new($type);
2511+
$lineDataMap->{$line} = $data;
25102512
} else {
25112513
$data = $lineDataMap->{$line};
25122514
}
2515+
$branchCovLines{$line} = 1;
25132516
# we expect that the line number matches...
25142517
$data->lineNo("current", $line);
25152518
# append this branch data for the line

lib/lcovutil.pm

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6513,6 +6513,13 @@ sub _read_info
65136513

65146514
/^DA:(\d+),([^,]+)(,([^,\s]+))?/ && do {
65156515
my ($line, $count, $checksum) = ($1, $2, $4);
6516+
if ($line <= 0) {
6517+
lcovutil::ignorable_error(
6518+
$lcovutil::ERROR_INCONSISTENT_DATA,
6519+
"\"$tracefile\":$.: unexpected line number '$line' in .info file record '$_'"
6520+
);
6521+
last;
6522+
}
65166523
if ($readSourceCallback->notEmpty()) {
65176524
# does the source checksum match the recorded checksum?
65186525
if ($verify_checksum) {
@@ -6567,6 +6574,13 @@ sub _read_info
65676574
my $lineNo = $1;
65686575
my $fnName = $4;
65696576
my $end_line = $3;
6577+
if ($lineNo <= 0) {
6578+
lcovutil::ignorable_error(
6579+
$lcovutil::ERROR_INCONSISTENT_DATA,
6580+
"\"$tracefile\":$.: unexpected line number '$lineNo' in .info file record '$_'"
6581+
);
6582+
last;
6583+
}
65706584
# the function may already be defined by another testcase
65716585
# (for the same file)
65726586
$functionMap->define_function($fnName, $filename, $lineNo,
@@ -6597,6 +6611,24 @@ sub _read_info
65976611
my ($line, $is_exception, $block, $d) =
65986612
($1, defined($2) && 'e' eq $2, $3, $4);
65996613

6614+
if ($line <= 0) {
6615+
# Python coverage.py emits line number 0 (zero) for branches
6616+
# - which is bogus, as there is no line number zero,
6617+
# and the corresponding branch expression is not there in
6618+
# any case.
6619+
# Meantime: this confuses the lcov DB - so we simply skip
6620+
# such data.
6621+
# Note that we only need to check while reading .info files.
6622+
# - if we wrote one from geninfo, then we will not have
6623+
# produced bogus data - so no need to check.
6624+
# - only some (broken) external tool could have the issue
6625+
lcovutil::ignorable_error(
6626+
$lcovutil::ERROR_INCONSISTENT_DATA,
6627+
"\"$tracefile\":$.: unexpected line number '$line' in .info file record '$_'"
6628+
);
6629+
last;
6630+
}
6631+
66006632
last if $is_exception && $lcovutil::exclude_exception_branch;
66016633
my $comma = rindex($d, ',');
66026634
my $taken = substr($d, $comma + 1);
@@ -6866,15 +6898,24 @@ sub write_info($$$)
68666898
defined($data->end_line()) ?
68676899
',' . $data->end_line() :
68686900
'';
6901+
if ($line <= 0) {
6902+
my $alias = (sort keys %$aliases)[0];
6903+
lcovutil::ignorable_error(
6904+
$lcovutil::ERROR_INCONSISTENT_DATA,
6905+
"\"$source_file\": unexpected line number '$line' for function $alias"
6906+
);
6907+
next;
6908+
}
68696909
foreach my $alias (sort keys %$aliases) {
68706910
print(INFO_HANDLE "FN:$line$endLine,$alias\n");
68716911
}
68726912
}
68736913
my $f_found = 0;
68746914
my $f_hit = 0;
68756915
foreach my $key (@functionOrder) {
6876-
my $data = $functionMap->findKey($key);
6877-
my $line = $data->line();
6916+
my $data = $functionMap->findKey($key);
6917+
my $line = $data->line();
6918+
next unless $line > 0;
68786919
my $aliases = $data->aliases();
68796920
foreach my $alias (sort keys %$aliases) {
68806921
my $hit = $aliases->{$alias};
@@ -6895,6 +6936,13 @@ sub write_info($$$)
68956936

68966937
foreach my $line (sort({ $a <=> $b } $testbrcount->keylist())) {
68976938

6939+
if ($line <= 0) {
6940+
lcovutil::ignorable_error(
6941+
$lcovutil::ERROR_INCONSISTENT_DATA,
6942+
"\"$source_file\": unexpected line number '$line' in branch data record record '$_'"
6943+
);
6944+
last;
6945+
}
68986946
my $brdata = $testbrcount->value($line);
68996947
# want the block_id to be treated as 32-bit unsigned integer
69006948
# (need masking to match regression tests)

0 commit comments

Comments
 (0)