Skip to content

Commit 36cc064

Browse files
committed
Consistent handling of invalid line numbers.
Signed-off-by: Henry Cox <[email protected]>
1 parent 3eb59e3 commit 36cc064

File tree

5 files changed

+77
-25
lines changed

5 files changed

+77
-25
lines changed

bin/genhtml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2745,6 +2745,9 @@ sub _categorizeLineCov
27452745
# LLVM seems to like to generate inconsistent data.
27462746
my $branchCurrent = $current_data->sumbr();
27472747
foreach my $line ($branchCurrent->keylist()) {
2748+
# just ignore bogus data - we already warned when we read the data
2749+
next if ($line <= 0);
2750+
27482751
my $type = $diffMap->type($filename, $diffMap->NEW, $line);
27492752
# LCOV_EXCL_START
27502753
if ($type eq 'delete') {
@@ -2762,6 +2765,8 @@ sub _categorizeLineCov
27622765
# (This observation is also true for branch and function
27632766
# coverages.)
27642767
foreach my $line ($lineCovCurrent->keylist()) {
2768+
# just ignore bogus data - we already warned when we read the data
2769+
next if ($line <= 0);
27652770
my $type = $diffMap->type($filename, $diffMap->NEW, $line);
27662771
if ($type eq 'delete') {
27672772
# can happen in some inconsistent case, when there are certain
@@ -2788,6 +2793,8 @@ sub _categorizeLineCov
27882793
return unless (defined($lineCovBase));
27892794

27902795
foreach my $bline ($lineCovBase->keylist()) {
2796+
# just ignore bogus data - we already warned when we read the data
2797+
next if ($bline <= 0);
27912798
my $linedata = $self->_findLineData($diffMap, $filename, $bline);
27922799
my $val = $lineCovBase->value($bline);
27932800
$linedata->base_count($val);
@@ -2888,6 +2895,7 @@ sub _categorizeBranchCov
28882895
# Or because we did something bad and no longer reach what had been
28892896
# a high probability event?
28902897
foreach my $line ($branchCurrent->keylist()) {
2898+
next if ($line <= 0); # ignore bogus
28912899
unless (exists($lineDataMap->{$line})) {
28922900
# unless ignored, should have been caught or fixed during
28932901
# TraceInfo::_checkConsistency
@@ -2931,6 +2939,7 @@ sub _categorizeBranchCov
29312939

29322940
# go through all the branch data for each line, and categorize everything
29332941
foreach my $line (keys(%branchCovLines)) {
2942+
next if ($line <= 0); # ignore bogus
29342943
my $data = $self->lineMap()->{$line};
29352944
my $type = $data->type();
29362945
my $curr = $data->current_branch();
@@ -3058,6 +3067,7 @@ sub _categorizeMcdcCov
30583067
# Or because we did something bad and no longer reach what had been
30593068
# a high probability event?
30603069
foreach my $line ($mcdcCurrent->keylist()) {
3070+
next if ($line <= 0); # ignore bogus
30613071
unless (exists($lineDataMap->{$line})) {
30623072
# unless ignored, should have been caught or fixed during
30633073
# TraceInfo::_checkConsistency
@@ -3086,6 +3096,7 @@ sub _categorizeMcdcCov
30863096
# now look through the baseline to find matching data
30873097

30883098
foreach my $base_line ($mcdcBaseline->keylist()) {
3099+
next if ($base_line <= 0); # ignore bogus
30893100
my $data = $self->_findLineData($diffMap, $filename, $base_line);
30903101
my $curr_line = $data->lineNo('current');
30913102
my $type = $data->type();
@@ -3203,6 +3214,7 @@ sub _categorizeFunctionCov
32033214
foreach my $key ($funcCurrent->keylist()) {
32043215
my $func = $funcCurrent->findKey($key);
32053216
my $line = $func->line();
3217+
next if ($line <= 0); # ignore bogus
32063218
my $type = $diffMap->type($filename, $diffMap->NEW, $line);
32073219
$funcCovLines{$line} = 1;
32083220
lcovutil::ignorable_error($lcovutil::ERROR_INTERNAL,
@@ -3241,6 +3253,7 @@ sub _categorizeFunctionCov
32413253
foreach my $key ($funcBase->keylist()) {
32423254
my $func = $funcBase->findKey($key);
32433255
my $line = $func->line();
3256+
next if ($line <= 0); # ignore bogus
32443257
my $data = $self->_findLineData($diffMap, $filename, $line);
32453258

32463259
my $type = $data->type();

bin/geninfo

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1726,7 +1726,6 @@ sub process_dafile($$$$)
17261726
}
17271727

17281728
my $traceFile = TraceFile->new();
1729-
my $warnedUnexecuted;
17301729
# Traverse the list of generated .gcov files and combine them into a
17311730
# single .info file
17321731
foreach $gcov_file (@gcov_list) {
@@ -1894,12 +1893,16 @@ sub process_dafile($$$$)
18941893
);
18951894
if ($lcovutil::opt_adjust_unexecuted_blocks) {
18961895
$hit = 0;
1897-
} else {
1896+
} elsif (
1897+
lcovutil::warn_once(
1898+
"unexecuted block",
1899+
$ERROR_INCONSISTENT_DATA
1900+
)
1901+
) {
18981902
lcovutil::ignorable_warning(
18991903
$ERROR_INCONSISTENT_DATA,
19001904
"$source_filename:$line_number: unexecuted block on non-branch line with non-zero hit count. Use \"geninfo --rc geninfo_unexecuted_blocks=1 to set count to zero."
1901-
) unless $warnedUnexecuted;
1902-
$warnedUnexecuted = 1;
1905+
);
19031906
}
19041907
}
19051908
}
@@ -2536,7 +2539,6 @@ sub intermediate_json_to_info($)
25362539
my $traceFile = TraceFile->new();
25372540
lcovutil::debug(1,
25382541
"called intermediate_json_to_info " . join(' ', keys(%$data)) . "\n");
2539-
my $warnedUnexecuted; # once only
25402542
while (my ($filename, $file_data) = each(%$data)) {
25412543
# note that we already substituted the source file name and handled
25422544
# include/exclude directives - so no need to check here
@@ -2582,24 +2584,19 @@ sub intermediate_json_to_info($)
25822584
next
25832585
if (!defined($line) || !defined($count));
25842586

2585-
if ($line <= 0) {
2586-
lcovutil::ignorable_error($lcovutil::ERROR_FORMAT,
2587-
'"' . $fileData->filename() .
2588-
"\":: unexpected line number '$line' in gcov record"
2589-
);
2590-
next; # don't store inconsistent data if message is ignored
2591-
}
25922587
if (0 == scalar(@$branches) && $unexec && $count != 0) {
25932588
lcovutil::debug(
25942589
"$filename:$line: unexecuted block on non-branch line with count=$count\n"
25952590
);
25962591
if ($lcovutil::opt_adjust_unexecuted_blocks) {
25972592
$count = 0;
2598-
} else {
2593+
} elsif (
2594+
lcovutil::warn_once("unexecuted block",
2595+
$ERROR_INCONSISTENT_DATA)
2596+
) {
25992597
lcovutil::ignorable_warning($ERROR_INCONSISTENT_DATA,
26002598
"$filename:$line: unexecuted block on non-branch line with non-zero hit count. Use \"geninfo --rc geninfo_unexecuted_blocks=1 to set count to zero."
2601-
) unless $warnedUnexecuted;
2602-
$warnedUnexecuted = 1;
2599+
);
26032600
}
26042601
}
26052602

lib/lcovutil.pm

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5330,7 +5330,6 @@ sub append_mcdc
53305330
sub new_mcdc
53315331
{
53325332
my ($self, $fileData, $line) = @_;
5333-
die("undexpected line $line <= 0") if ($line <= 0);
53345333

53355334
return $self->[BranchMap::DATA]->{$line}
53365335
if exists($self->[BranchMap::DATA]->{$line});
@@ -8505,7 +8504,8 @@ sub _read_info
85058504
lcovutil::ignorable_error($lcovutil::ERROR_FORMAT,
85068505
"\"$tracefile\":$.: unexpected line number '$line' in .info file record '$_'"
85078506
);
8508-
last;
8507+
# just keep invalid number - if error ignored
8508+
# last;
85098509
}
85108510
if ($readSourceCallback->notEmpty()) {
85118511
# does the source checksum match the recorded checksum?
@@ -8645,7 +8645,8 @@ sub _read_info
86458645
lcovutil::ignorable_error($lcovutil::ERROR_FORMAT,
86468646
"\"$tracefile\":$.: unexpected line number '$line' in .info file record '$_'"
86478647
);
8648-
last;
8648+
# just keep invalid line number if error ignored
8649+
# last;
86498650
}
86508651

86518652
last if $is_exception && $lcovutil::exclude_exception_branch;
@@ -8701,7 +8702,8 @@ sub _read_info
87018702
lcovutil::ignorable_error($lcovutil::ERROR_FORMAT,
87028703
"\"$tracefile\":$.: unexpected line number '$line' in condition data record '$_'."
87038704
);
8704-
last;
8705+
# keep invalid line number
8706+
#last;
87058707
}
87068708

87078709
if (!defined($current_mcdc) ||
@@ -8927,7 +8929,8 @@ sub write_info($$$)
89278929
lcovutil::ignorable_error($lcovutil::ERROR_FORMAT,
89288930
"\"$source_file\": unexpected line number '$line' in branch data record."
89298931
);
8930-
last;
8932+
# keep bogus data if error ignored
8933+
# last;
89318934
}
89328935
my $brdata = $testbrcount->value($line);
89338936
# want the block_id to be treated as 32-bit unsigned integer
@@ -8965,8 +8968,11 @@ sub write_info($$$)
89658968
my $mcdc_found = 0;
89668969
my $mcdc_hit = 0;
89678970
foreach my $line (sort({ $a <=> $b } $mcdc->keylist())) {
8968-
8969-
die("unexpected MCDC line $line") if ($line <= 0);
8971+
if ($line <= 0) {
8972+
lcovutil::ignorable_error($lcovutil::ERROR_FORMAT,
8973+
"\"$source_file\": unexpected line number '$line' in MC/DC data record."
8974+
);
8975+
}
89708976
my $m = $mcdc->value($line);
89718977
my $groups = $m->groups();
89728978
foreach my $groupSize (sort keys %$groups) {
@@ -8995,6 +9001,11 @@ sub write_info($$$)
89959001
my $found = 0;
89969002
my $hit = 0;
89979003
foreach my $line (sort({ $a <=> $b } $testcount->keylist())) {
9004+
if ($line <= 0) {
9005+
lcovutil::ignorable_error($lcovutil::ERROR_FORMAT,
9006+
"\"$source_file\": unexpected line number '$line' in 'line' data record."
9007+
);
9008+
}
89989009
my $l_hit = $testcount->value($line);
89999010
my $chk = '';
90009011
if ($verify_checksum) {

tests/gendiffcov/errs/msgtest.sh

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,26 @@ if [ 0 != $? ] ; then
231231
fi
232232
fi
233233
234+
# invalid syntax test:
235+
cp initial.info badRecord.info
236+
echo "MDCD:0,1,t,1,1,abc" >> badRecord.info
237+
echo lcov $LCOV_OPTS --summary badRecord.info --msg-log badRecord.log
238+
$COVER $LCOV_TOOL $LCOV_OPTS --summary badRecord.info --msg-log badRecord.log
239+
if [ 0 == $? ] ; then
240+
echo "ERROR: missing format message"
241+
if [ 0 == $KEEP_GOING ] ; then
242+
exit 1
243+
fi
244+
fi
245+
grep 'unexpected .info file record' badRecord.log
246+
if [ 0 != $? ] ; then
247+
echo "ERROR: failed to find format message"
248+
if [ 0 == $KEEP_GOING ] ; then
249+
exit 1
250+
fi
251+
fi
252+
253+
234254
echo lcov $LCOV_OPTS --summary initial.info --prune
235255
$COVER $LCOV_TOOL $LCOV_OPTS --summary initial.info --prune 2>&1 | tee prune_err.log
236256
if [ 0 == ${PIPESTATUS[0]} ] ; then
@@ -769,7 +789,7 @@ if [ "$ENABLE_MCDC" != 1 ] ; then
769789
770790
fi
771791
772-
$COVER $LCOV_TOOL --summary mcdc_errs.dat --mcdc-coverage $LCOV_OPTS --msg-log mcdc_expr.log --ignore format,inconsistent,source
792+
$COVER $LCOV_TOOL -o err.info -a mcdc_errs.dat --mcdc-coverage $LCOV_OPTS --msg-log mcdc_expr.log --ignore format,inconsistent,source
773793
if [ 0 != $? ] ; then
774794
echo "ERROR: didn't ignore MC/DC errors"
775795
if [ 0 == $KEEP_GOING ] ; then

tests/lcov/errs/errs.sh

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ if [ "${VER[0]}" -lt 5 ] ; then
9898
FILTER='--filter branch'
9999
fi
100100
101-
rm -f *.log *.json dumper*
101+
rm -f *.log *.json dumper* *.out
102102
rm -rf emptyDir
103103
104104
if [ "x$COVER" != 'x' ] && [ 0 != $LOCAL_COVERAGE ] ; then
@@ -135,7 +135,7 @@ for f in badFncLine badFncEndLine fncMismatch badBranchLine badLine ; do
135135
fi
136136
fi
137137
138-
echo lcov $LCOV_OPTS --summary $f.info --ignore inconsistent
138+
echo lcov $LCOV_OPTS --summary $f.info --ignore inconsistent,format
139139
$COVER $LCOV_TOOL $LCOV_OPTS --summary $f.info --ignore format,inconsistent 2>&1 | tee ${f}2.log
140140
if [ 0 != ${PIPESTATUS[0]} ] ; then
141141
echo "failed to ignore message ${f}2.log"
@@ -144,6 +144,17 @@ for f in badFncLine badFncEndLine fncMismatch badBranchLine badLine ; do
144144
exit $status
145145
fi
146146
fi
147+
# and print the data out again..
148+
echo lcov $LCOV_OPTS -o $f.out -a $f.info --ignore format,inconsistent
149+
$COVER $LCOV_TOOL $LCOV_OPTS -o $f.out -a $f.info --ignore format,inconsistent --msg-log $f{3}.log
150+
if [ 0 != $? ] ; then
151+
echo "failed to ignore message ${f}3.log"
152+
status=1
153+
if [ 0 == $KEEP_GOING ] ; then
154+
exit $status
155+
fi
156+
fi
157+
147158
done
148159
149160
for f in noFunc ; do

0 commit comments

Comments
 (0)