Skip to content

Commit dc685d0

Browse files
committed
Remove unused/unreachable code.
Add corresponding error message tests. Signed-off-by: Henry Cox <[email protected]>
1 parent d1e601b commit dc685d0

14 files changed

+635
-118
lines changed

bin/genhtml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3389,12 +3389,6 @@ sub show_map
33893389
return $self;
33903390
}
33913391

3392-
sub strip_directories
3393-
{
3394-
my $path = shift;
3395-
return $path;
3396-
}
3397-
33983392
sub _read_udiff
33993393
{
34003394
my $self = shift;

lib/lcovutil.pm

Lines changed: 15 additions & 111 deletions
Original file line numberDiff line numberDiff line change
@@ -3454,21 +3454,12 @@ sub merge
34543454
{
34553455
# return 1 if something changed, 0 if nothing new covered or discovered
34563456
my ($self, $that, $filename, $line) = @_;
3457-
if ($self->exprString() ne $that->exprString()) {
3458-
my $loc = defined($filename) ? "\"$filename\":$line: " : '';
3459-
lcovutil::ignorable_error($lcovutil::ERROR_MISMATCH,
3460-
"${loc}mismatched expressions for id " .
3461-
$self->id() . ", " . $that->id() .
3462-
": '" . $self->exprString() .
3463-
"' -> '" . $that->exprString() . "'");
3464-
# else - ignore the issue and merge data even though the expressions
3465-
# look different
3466-
# To enable a consistent result, keep the one which is alphabetically
3467-
# first
3468-
if ($that->exprString() le $self->exprString()) {
3469-
$self->[EXPR] = $that->[EXPR];
3470-
}
3471-
}
3457+
# should have called 'iscompatible' first
3458+
die('attempt to merge incompatible expressions for id' .
3459+
$self->id() . ', ' . $that->id() .
3460+
": '" . $self->exprString() . "' -> '" . $that->exprString() . "'")
3461+
if ($self->exprString() ne $that->exprString());
3462+
34723463
if ($self->is_exception() != $that->is_exception()) {
34733464
my $loc = defined($filename) ? "\"$filename\":$line: " : '';
34743465
lcovutil::ignorable_error($lcovutil::ERROR_MISMATCH,
@@ -4042,57 +4033,6 @@ sub difference
40424033
return $changed;
40434034
}
40444035

4045-
sub cloneWithRename
4046-
{
4047-
my ($self, $conv) = @_;
4048-
4049-
my $newData = FunctionMap->new();
4050-
foreach my $key ($self->keylist()) {
4051-
my $data = $self->findKey($key);
4052-
my $aliases = $data->aliases();
4053-
foreach my $alias (keys %$aliases) {
4054-
my $cn = $conv->{$alias};
4055-
my $hit = $aliases->{$alias};
4056-
4057-
# Abort if two functions on different lines map to the
4058-
# same demangled name.
4059-
die("Demangled function name $cn maps to different lines (" .
4060-
$newData->findName($cn)->line() .
4061-
" vs " . $data->line() . ") in " . $newData->file())
4062-
if (defined($newData->findName($cn)) &&
4063-
$newData->findName($cn)->line() != $data->line());
4064-
$newData->define_function($cn, $data->file(), $data->line(),
4065-
$data->end_line());
4066-
$newData->add_count($cn, $hit);
4067-
}
4068-
}
4069-
return $newData;
4070-
}
4071-
4072-
sub insert
4073-
{
4074-
my ($self, $entry) = @_;
4075-
die("expected FunctionEntry - " . ref($entry))
4076-
unless 'FunctionEntry' eq ref($entry);
4077-
my ($locationMap, $nameMap) = @$self;
4078-
my $key = $entry->file() . ":" . $entry->line();
4079-
#die("duplicate entry \@$key")
4080-
# if exists($locationMap->{$key});
4081-
if (exists($locationMap->{$key})) {
4082-
my $current = $locationMap->{$key};
4083-
print("DUP: " . $current->name() . " -> " . $entry->name() .
4084-
"\n" . $current->file() . ":" . $current->line() .
4085-
" -> " . $entry->file() . $entry->line() . "\n");
4086-
die("duplicate entry \@$key");
4087-
}
4088-
$locationMap->{$key} = $entry;
4089-
foreach my $alias (keys %{$entry->aliases()}) {
4090-
die("duplicate alias '$alias'")
4091-
if (exists($nameMap->{$alias}));
4092-
$nameMap->{$alias} = $entry;
4093-
}
4094-
}
4095-
40964036
sub remove
40974037
{
40984038
my ($self, $entry) = @_;
@@ -4805,31 +4745,6 @@ sub get_info($)
48054745
$br_hit);
48064746
}
48074747

4808-
#
4809-
# rename_functions(info, conv)
4810-
#
4811-
# Rename all function names in TraceInfo according to CONV: OLD_NAME -> NEW_NAME.
4812-
# In case two functions demangle to the same name, assume that they are
4813-
# different object code implementations for the same source function.
4814-
#
4815-
4816-
sub rename_functions($$)
4817-
{
4818-
my ($self, $conv, $filename) = @_;
4819-
4820-
my $newData = $self->func()->cloneWithRename($conv);
4821-
$self->[FUNCTION_DATA]->[0] = $newData;
4822-
4823-
# testfncdata: test name -> testfnccount
4824-
# testfnccount: function name -> execution count
4825-
my $testfncdata = $self->testfnc();
4826-
foreach my $tn ($testfncdata->keylist()) {
4827-
my $testfnccount = $testfncdata->value($tn);
4828-
my $newtestfnccount = $testfnccount->cloneWithRename($conv);
4829-
$testfncdata->replace($tn, $newtestfnccount);
4830-
}
4831-
}
4832-
48334748
sub _merge_checksums
48344749
{
48354750
my $self = shift;
@@ -6825,11 +6740,17 @@ sub _read_info
68256740
my $lineNo = $1;
68266741
my $fnName = $4;
68276742
my $end_line = $3;
6828-
if ($lineNo <= 0) {
6743+
if ($lineNo <= 0 ||
6744+
(defined($end_line) && $end_line <= 0)) {
68296745
lcovutil::ignorable_error(
68306746
$lcovutil::ERROR_INCONSISTENT_DATA,
6831-
"\"$tracefile\":$.: unexpected line number '$lineNo' in .info file record '$_'"
6832-
);
6747+
"\"$tracefile\":$.: unexpected function line '$lineNo' in .info file record '$_'"
6748+
) if $lineNo <= 0;
6749+
lcovutil::ignorable_error(
6750+
$lcovutil::ERROR_INCONSISTENT_DATA,
6751+
"\"$tracefile\":$.: unexpected function end line '$end_line' in .info file record '$_'"
6752+
) if defined($end_line) && $end_line <= 0;
6753+
68336754
last;
68346755
}
68356756
# the function may already be defined by another testcase
@@ -7193,23 +7114,6 @@ sub write_info($$$)
71937114
}
71947115
}
71957116

7196-
#
7197-
# rename_functions(info, conv)
7198-
#
7199-
# Rename all function names in TraceFile according to CONV: OLD_NAME -> NEW_NAME.
7200-
# In case two functions demangle to the same name, assume that they are
7201-
# different object code implementations for the same source function.
7202-
#
7203-
7204-
sub rename_functions($$)
7205-
{
7206-
my ($self, $conv) = @_;
7207-
7208-
foreach my $filename ($self->files()) {
7209-
my $data = $self->data($filename)->rename_functions($conv, $filename);
7210-
}
7211-
}
7212-
72137117
package AggregateTraces;
72147118
# parse sna merge TraceFiles - possibly in parallel
72157119
# - common utility, used by lcov 'add_trace' and genhtml multi-file read

tests/lcov/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
include ../common.mak
22

3-
TESTS := add/ diff/ misc/ summary/ extract/ demangle/ exception/ gcov-tool/ branch/ merge/ format
3+
TESTS := add/ diff/ misc/ summary/ extract/ demangle/ exception/ gcov-tool/ branch/ merge/ format errs

tests/lcov/errs/Makefile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
include ../../common.mak
2+
3+
TESTS := errs.sh
4+
5+
clean:
6+
$(shell ./errs.sh --clean)

tests/lcov/errs/badBranchLine.info

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
TN:
2+
SF:test.cpp
3+
VER:#1
4+
FN:1,45,main
5+
FNDA:1,main
6+
DA:0,0
7+
FNF:1
8+
FNH:1
9+
BRDA:15,e0,0,1
10+
BRDA:15,e0,1,0
11+
BRDA:42,0,0,-
12+
BRDA:42,0,1,-
13+
BRDA:0,0,0,-
14+
BRDA:0,0,1,-
15+
BRF:6
16+
BRH:2
17+
DA:12,1
18+
DA:14,1
19+
DA:15,1
20+
DA:17,1
21+
DA:22,1
22+
DA:23,1
23+
DA:25,1
24+
DA:30,0
25+
DA:31,0
26+
DA:36,0
27+
DA:38,0
28+
DA:40,1
29+
DA:41,1
30+
DA:42,0
31+
DA:43,0
32+
DA:44,1
33+
LF:16
34+
LH:10
35+
end_of_record
36+
TN:
37+
SF:/mtkoss/gcc/10.2.0-rhel7/x86_64/include/c++/10.2.0/iostream
38+
VER:2020-10-05T04:38:04-04:00
39+
FNF:0
40+
FNH:0
41+
LF:0
42+
LH:0
43+
end_of_record

tests/lcov/errs/badFncEndLine.info

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
TN: name with space
2+
SF:test.cpp
3+
VER:#1
4+
VER:#1
5+
FN:1,0,main
6+
#FNDA:1,main <- FNDA record mismatches because FN record is skipped
7+
DA:0,0
8+
FNF:1
9+
FNH:1
10+
BRDA:15,e0,0,1
11+
BRDA:15,e0,1,0
12+
BRDA:42,0,0,-
13+
BRDA:42,0,1,-
14+
BRDA:44,0,0,-
15+
BRDA:44,0,1,-
16+
BRF:6
17+
BRH:2
18+
DA:12,1
19+
DA:14,1
20+
DA:15,1
21+
DA:17,1
22+
DA:22,1
23+
DA:23,1
24+
DA:25,1
25+
DA:30,0
26+
DA:31,0
27+
DA:36,0
28+
DA:38,0
29+
DA:40,1
30+
DA:41,1
31+
DA:42,0
32+
DA:43,0
33+
DA:44,1
34+
LF:16
35+
LH:10
36+
end_of_record
37+
TN:
38+
SF:/mtkoss/gcc/10.2.0-rhel7/x86_64/include/c++/10.2.0/iostream
39+
VER:2020-10-05T04:38:04-04:00
40+
FNF:0
41+
FNH:0
42+
LF:0
43+
LH:0
44+
end_of_record

tests/lcov/errs/badFncLine.info

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
TN:
2+
SF:test.cpp
3+
VER:#1
4+
FN:0,45,main
5+
#FNDA:1,main <- FNDA record mismatches because FN record is skipped
6+
DA:0,0
7+
FNF:1
8+
FNH:1
9+
BRDA:15,e0,0,1
10+
BRDA:15,e0,1,0
11+
BRDA:42,0,0,-
12+
BRDA:42,0,1,-
13+
BRDA:44,0,0,-
14+
BRDA:44,0,1,-
15+
BRF:6
16+
BRH:2
17+
DA:12,1
18+
DA:14,1
19+
DA:15,1
20+
DA:17,1
21+
DA:22,1
22+
DA:23,1
23+
DA:25,1
24+
DA:30,0
25+
DA:31,0
26+
DA:36,0
27+
DA:38,0
28+
DA:40,1
29+
DA:41,1
30+
DA:42,0
31+
DA:43,0
32+
DA:44,1
33+
LF:16
34+
LH:10
35+
end_of_record
36+
TN:
37+
SF:/mtkoss/gcc/10.2.0-rhel7/x86_64/include/c++/10.2.0/iostream
38+
VER:2020-10-05T04:38:04-04:00
39+
FNF:0
40+
FNH:0
41+
LF:0
42+
LH:0
43+
end_of_record

tests/lcov/errs/badLine.info

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
TN:
2+
SF:test.cpp
3+
VER:#1
4+
FN:1,45,main
5+
FNDA:1,main
6+
DA:0,0
7+
FNF:1
8+
FNH:1
9+
BRDA:15,e0,0,1
10+
BRDA:15,e0,1,0
11+
BRDA:42,0,0,-
12+
BRDA:42,0,1,-
13+
BRDA:44,0,0,-
14+
BRDA:44,0,1,-
15+
BRF:6
16+
BRH:2
17+
DA:0,1
18+
DA:14,1
19+
DA:15,1
20+
DA:17,1
21+
DA:22,1
22+
DA:23,1
23+
DA:25,1
24+
DA:30,0
25+
DA:31,0
26+
DA:36,0
27+
DA:38,0
28+
DA:40,1
29+
DA:41,1
30+
DA:42,0
31+
DA:43,0
32+
DA:44,1
33+
LF:16
34+
LH:10
35+
end_of_record
36+
TN:
37+
SF:/mtkoss/gcc/10.2.0-rhel7/x86_64/include/c++/10.2.0/iostream
38+
VER:2020-10-05T04:38:04-04:00
39+
FNF:0
40+
FNH:0
41+
LF:0
42+
LH:0
43+
end_of_record

0 commit comments

Comments
 (0)