Skip to content

Commit f1f5cfd

Browse files
committed
Fix various issues which occur with older gcc versions which don't
natively support function end line reporting. Tested with gcc 4.8.5, 5.2.0, 6.2.0, 10.2.0 Signed-off-by: Henry Cox <[email protected]>
1 parent 16e4892 commit f1f5cfd

File tree

5 files changed

+167
-110
lines changed

5 files changed

+167
-110
lines changed

bin/geninfo

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1461,15 +1461,14 @@ sub process_dafile($$$$)
14611461
my $fn_data = $graph->{$source_filename};
14621462

14631463
while (my ($fn, $ln_data) = each(%$fn_data)) {
1464+
next if ($fn eq "");
14641465
my $line = $ln_data->[0];
14651466

1466-
if ($fn eq "") {
1467-
next;
1468-
}
1469-
1470-
# Normalize function name - no need to demangle again
1471-
# because we already did it in 'read_gcov_file'
1472-
$fn = filter_fn_name($fn, 0);
1467+
# Normalize function name - need to demangle here because
1468+
# the graph data came from reading the gcno file and isn't
1469+
# demangled already
1470+
$fn = filter_fn_name($fn,
1471+
defined($lcovutil::demangle_cpp_cmd));
14731472
$functionData{$fn} =
14741473
$functionMap->define_function($fn, $source_filename,
14751474
$line);
@@ -1480,6 +1479,8 @@ sub process_dafile($$$$)
14801479
my $count = shift(@gcov_functions);
14811480
my $fn = shift(@gcov_functions);
14821481

1482+
# don't need to demangle here because this came from reading
1483+
# the gcov result - and we demangled that.
14831484
$fn = filter_fn_name($fn, 0);
14841485
next unless exists($functionData{$fn});
14851486
$functionData{$fn}->addAlias($fn, $count);

lib/lcovutil.pm

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1472,7 +1472,7 @@ sub summarize_cov_filters
14721472
if ($patternCount) {
14731473
my $omitCount = 0;
14741474
foreach my $p (@omit_line_patterns) {
1475-
$omitCount += $p->[1];
1475+
$omitCount += $p->[-1];
14761476
}
14771477
info(-1,
14781478
"Omitted %d total line%s matching %d '--omit-lines' pattern%s\n",
@@ -4139,13 +4139,24 @@ sub applyFilters
41394139
# sort functions by start line number
41404140
my @functions = sort { $a->line() <=> $b->line() }
41414141
$traceInfo->func()->valuelist();
4142+
die("unexpectedly empty list of lines for $name")
4143+
unless (@lines);
41424144
my $currentLine = shift(@lines);
41434145
my $funcData = $traceInfo->testfnc();
4144-
while (@functions) {
4146+
FUNC: while (@functions) {
41454147
my $func = shift(@functions);
41464148
my $first = $func->line();
41474149
while ($first < $currentLine) {
4148-
$currentLine = shift @lines;
4150+
if (@lines) {
4151+
$currentLine = shift @lines;
4152+
} else {
4153+
lcovutil::ignorable_error(
4154+
$lcovutil::ERROR_INCONSISTENT_DATA,
4155+
"\"$name\":$first: function " . $func->name() .
4156+
" found on line but no corresponding 'line' coverage data point. Cannot derive function end line."
4157+
);
4158+
next FUNC;
4159+
}
41494160
}
41504161
if (!defined($func->end_line())) {
41514162
# where is the next function? Find the last 'line' coverpoint
@@ -4163,7 +4174,17 @@ sub applyFilters
41634174
} else {
41644175
# last line in the file must be the last line
41654176
# of this function
4166-
$currentLine = $lines[-1];
4177+
if (@lines) {
4178+
$currentLine = $lines[-1];
4179+
} else {
4180+
lcovutil::ignorable_error(
4181+
$lcovutil::ERROR_INCONSISTENT_DATA,
4182+
"\"$name\":$first: function " .
4183+
$func->name() .
4184+
": last line in file is not last line of function"
4185+
);
4186+
next FUNC;
4187+
}
41674188
}
41684189
} elsif ($currentLine < $first) {
41694190
# we ran out of lines in the data...check for inconsistency
@@ -4173,8 +4194,8 @@ sub applyFilters
41734194
" found on line but no corresponding 'line' coverage data point. Cannot derive function end line."
41744195
);
41754196

4176-
# last; # quit looking here - all the other functions after this one will have same issue
4177-
next; # warn about them all
4197+
# last FUNC; # quit looking here - all the other functions after this one will have same issue
4198+
next FUNC; # warn about them all
41784199
}
41794200
lcovutil::info(1,
41804201
"\"$name\":$currentLine: assign end_line " .

tests/gendiffcov/insensitive/insensitive.sh

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,14 @@ ${CXX} --coverage TEST.cpp
137137
echo `which gcov`
138138
echo `which lcov`
139139

140-
echo lcov $LCOV_OPTS --capture --directory . --output-file baseline.info
141-
$COVER $LCOV_HOME/bin/lcov $LCOV_OPTS --capture --directory . --output-file baseline.info --no-external
140+
# old gcc version generates inconsistent line/function data
141+
IFS='.' read -r -a VER <<< `gcc -dumpversion`
142+
if [ "${VER[0]}" -lt 5 ] ; then
143+
IGNORE="--ignore inconsistent"
144+
fi
145+
146+
echo lcov $LCOV_OPTS --capture --directory . --output-file baseline.info $IGNORE
147+
$COVER $LCOV_HOME/bin/lcov $LCOV_OPTS --capture --directory . --output-file baseline.info --no-external $IGNORE
142148
if [ 0 != $? ] ; then
143149
echo "ERROR: lcov --capture failed"
144150
if [ 0 == $KEEP_GOING ] ; then
@@ -200,8 +206,8 @@ rm -f TEST.cpp *.gcno *.gcda a.out
200206
ln -s ../simple/simple2.cpp TeSt.cpp
201207
${CXX} --coverage -DADD_CODE -DREMOVE_CODE TeSt.cpp
202208
./a.out
203-
echo lcov $LCOV_OPTS --capture --directory . --output-file current.info
204-
$COVER $LCOV_HOME/bin/lcov $LCOV_OPTS --capture --directory . --output-file current.info
209+
echo lcov $LCOV_OPTS --capture --directory . --output-file current.info $IGNORE
210+
$COVER $LCOV_HOME/bin/lcov $LCOV_OPTS --capture --directory . --output-file current.info $IGNORE
205211
if [ 0 != $? ] ; then
206212
echo "ERROR: lcov --capture TeSt failed"
207213
if [ 0 == $KEEP_GOING ] ; then
@@ -217,8 +223,8 @@ fi
217223
ln -s ../simple/simple2.cpp.annotated TEst.cpp.annotated
218224
219225
# check that this works with test names
220-
echo ${LCOV_HOME}/bin/genhtml $DIFFCOV_OPTS --baseline-file ./baseline.info --diff-file diff.txt --annotate-script `pwd`/annotate.sh --show-owners all --show-noncode -o differential ./current.info --rc case_insensitive=1 --ignore-annotate,source
221-
$COVER ${LCOV_HOME}/bin/genhtml $DIFFCOV_OPTS --baseline-file ./baseline.info --diff-file diff.txt --annotate-script `pwd`/annotate.sh --show-owners all --show-noncode -o differential ./current.info --rc case_insensitive=1 $GENHTML_PORT --ignore annotate,source
226+
echo ${LCOV_HOME}/bin/genhtml $DIFFCOV_OPTS --baseline-file ./baseline.info --diff-file diff.txt --annotate-script `pwd`/annotate.sh --show-owners all --show-noncode -o differential ./current.info --rc case_insensitive=1 --ignore-annotate,source $IGNORE
227+
$COVER ${LCOV_HOME}/bin/genhtml $DIFFCOV_OPTS --baseline-file ./baseline.info --diff-file diff.txt --annotate-script `pwd`/annotate.sh --show-owners all --show-noncode -o differential ./current.info --rc case_insensitive=1 $GENHTML_PORT --ignore annotate,source $IGNORE
222228
if [ 0 != $? ] ; then
223229
echo "ERROR: genhtml differential failed"
224230
if [ 0 == $KEEP_GOING ] ; then
@@ -227,8 +233,8 @@ if [ 0 != $? ] ; then
227233
fi
228234
229235
# check warning
230-
echo lcov $LCOV_OPTS --capture --directory . --output-file current.info --substitute 's/test/TEST/g'
231-
$COVER $LCOV_HOME/bin/lcov $LCOV_OPTS --capture --directory . --output-file current.info --substitute 's/test\b/TEST/' --rc case_insensitive=1 --ignore unused,source 2>&1 | tee warn.log
236+
echo lcov $LCOV_OPTS --capture --directory . --output-file current.info --substitute 's/test/TEST/g' $IGNORE
237+
$COVER $LCOV_HOME/bin/lcov $LCOV_OPTS --capture --directory . --output-file current.info --substitute 's/test\b/TEST/' --rc case_insensitive=1 --ignore unused,source $IGNORE 2>&1 | tee warn.log
232238
if [ 0 != $? ] ; then
233239
echo "ERROR: lcov --capture TeSt failed"
234240
if [ 0 == $KEEP_GOING ] ; then
@@ -245,10 +251,10 @@ fi
245251
246252
rm -f TeSt.cpp
247253
248-
# check annotateion failure message...
254+
# check annotation failure message...
249255
# check that this works with test names
250-
echo ${LCOV_HOME}/bin/genhtml $DIFFCOV_OPTS --baseline-file ./baseline.info --diff-file diff.txt --annotate-script $ANNOTATATE --show-owners all --show-noncode -o differential ./current.info --ignore-source
251-
$COVER ${LCOV_HOME}/bin/genhtml $DIFFCOV_OPTS --baseline-file ./baseline.info --diff-file diff.txt --annotate-script $ANNOTATE --show-owners all --show-noncode -o differential ./current.info $GENHTML_PORT --ignore source 2>&1 | tee fail.log
256+
echo ${LCOV_HOME}/bin/genhtml $DIFFCOV_OPTS --baseline-file ./baseline.info --diff-file diff.txt --annotate-script $ANNOTATATE --show-owners all --show-noncode -o differential ./current.info --ignore source $IGNORE
257+
$COVER ${LCOV_HOME}/bin/genhtml $DIFFCOV_OPTS --baseline-file ./baseline.info --diff-file diff.txt --annotate-script $ANNOTATE --show-owners all --show-noncode -o differential ./current.info $GENHTML_PORT --ignore source $IGNORE 2>&1 | tee fail.log
252258
if [ 0 == ${PIPESTATUS[0]} ] ; then
253259
echo "ERROR: expected annotation error but didn't find"
254260
if [ 0 == $KEEP_GOING ] ; then
@@ -261,8 +267,8 @@ if [ 0 != $? ] ; then
261267
exit 1
262268
fi
263269
264-
echo ${LCOV_HOME}/bin/genhtml $DIFFCOV_OPTS --baseline-file ./baseline.info --diff-file diff.txt --annotate-script $ANNOTATATE --show-owners all --show-noncode -o differential ./current.info --ignore-source,annotate
265-
$COVER ${LCOV_HOME}/bin/genhtml $DIFFCOV_OPTS --baseline-file ./baseline.info --diff-file diff.txt --annotate-script $ANNOTATE --show-owners all --show-noncode -o differential ./current.info $GENHTML_PORT --ignore source,annotate 2>&1 | tee fail2.log
270+
echo ${LCOV_HOME}/bin/genhtml $DIFFCOV_OPTS --baseline-file ./baseline.info --diff-file diff.txt --annotate-script $ANNOTATATE --show-owners all --show-noncode -o differential ./current.info --ignore-source,annotate $IGNORE
271+
$COVER ${LCOV_HOME}/bin/genhtml $DIFFCOV_OPTS --baseline-file ./baseline.info --diff-file diff.txt --annotate-script $ANNOTATE --show-owners all --show-noncode -o differential ./current.info $GENHTML_PORT --ignore source,annotate $IGNORE 2>&1 | tee fail2.log
266272
if [ 0 == ${PIPESTATUS[0]} ] ; then
267273
echo "ERROR: expected synthesize error but didn't find"
268274
if [ 0 == $KEEP_GOING ] ; then
@@ -280,8 +286,8 @@ if [ 0 != $? ] ; then
280286
exit 1
281287
fi
282288
283-
echo ${LCOV_HOME}/bin/genhtml $DIFFCOV_OPTS --baseline-file ./baseline.info --diff-file diff.txt --annotate-script $ANNOTATATE --show-owners all --show-noncode -o differential ./current.info --ignore-source,annotate --synthesize
284-
$COVER ${LCOV_HOME}/bin/genhtml $DIFFCOV_OPTS --baseline-file ./baseline.info --diff-file diff.txt --annotate-script $ANNOTATE --show-owners all --show-noncode -o differential ./current.info $GENHTML_PORT --ignore source,annotate --synthesize 2>&1 | tee fail3.log
289+
echo ${LCOV_HOME}/bin/genhtml $DIFFCOV_OPTS --baseline-file ./baseline.info --diff-file diff.txt --annotate-script $ANNOTATATE --show-owners all --show-noncode -o differential ./current.info --ignore-source,annotate --synthesize $IGNORE
290+
$COVER ${LCOV_HOME}/bin/genhtml $DIFFCOV_OPTS --baseline-file ./baseline.info --diff-file diff.txt --annotate-script $ANNOTATE --show-owners all --show-noncode -o differential ./current.info $GENHTML_PORT --ignore source,annotate --synthesize $IGNORE 2>&1 | tee fail3.log
285291
if [ 0 != ${PIPESTATUS[0]} ] ; then
286292
echo "ERROR: unexpected synthesize error"
287293
if [ 0 == $KEEP_GOING ] ; then

0 commit comments

Comments
 (0)