Skip to content

Commit 0433563

Browse files
committed
geninfo: Fix "Can't use an undefined value" error
When run on data for source code that causes gcc 8 to generate artificial functions, geninfo emits warnings and eventually aborts processing: geninfo: Use of uninitialized value in hash element at /usr/local/bin/geninfo line 3001. geninfo: Can't use an undefined value as an ARRAY reference at /usr/local/bin/geninfo line 2889. This problem was introduced by commit 9aa0d14 ("geninfo: Ignore artificial functions during --initial"). It is the result of an incomplete removal of artificial functions from internal data. Fix this by explicitcly removing known artificial functions after parsing of graph files completes. Signed-off-by: Peter Oberparleiter <[email protected]> Reported-by: Steven Peters <[email protected]>
1 parent 9aa0d14 commit 0433563

File tree

1 file changed

+27
-17
lines changed

1 file changed

+27
-17
lines changed

bin/geninfo

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ sub read_bbg($);
197197
sub read_gcno_word(*;$$);
198198
sub read_gcno_value(*$;$$);
199199
sub read_gcno_string(*$);
200-
sub read_gcno_lines_record(*$$$$$$$);
200+
sub read_gcno_lines_record(*$$$$$$);
201201
sub determine_gcno_split_crc($$$$);
202202
sub read_gcno_function_record(*$$$$$);
203203
sub read_gcno($);
@@ -3421,16 +3421,16 @@ sub read_gcno_string(*$)
34213421

34223422
#
34233423
# read_gcno_lines_record(handle, gcno_filename, bb, fileorder, filename,
3424-
# function, big_endian, artificial)
3424+
# function, big_endian)
34253425
#
34263426
# Read a gcno format lines record from handle and add the relevant data to
34273427
# bb and fileorder. Return filename on success, undef on error.
34283428
#
34293429

3430-
sub read_gcno_lines_record(*$$$$$$$)
3430+
sub read_gcno_lines_record(*$$$$$$)
34313431
{
34323432
my ($handle, $gcno_filename, $bb, $fileorder, $filename, $function,
3433-
$big_endian, $artificial) = @_;
3433+
$big_endian) = @_;
34343434
my $string;
34353435
my $lineno;
34363436

@@ -3462,12 +3462,9 @@ sub read_gcno_lines_record(*$$$$$$$)
34623462
"$gcno_filename\n");
34633463
next;
34643464
}
3465-
3466-
if (!$artificial) {
3467-
# Add to list
3468-
push(@{$bb->{$function}->{$filename}}, $lineno);
3469-
graph_add_order($fileorder, $function, $filename);
3470-
}
3465+
# Add to list
3466+
push(@{$bb->{$function}->{$filename}}, $lineno);
3467+
graph_add_order($fileorder, $function, $filename);
34713468
}
34723469
}
34733470

@@ -3565,11 +3562,9 @@ sub read_gcno_function_record(*$$$$$)
35653562
graph_skip($handle, 4, "column number") or return undef;
35663563
graph_skip($handle, 4, "ending line number") or return undef;
35673564
}
3568-
if (!$artificial) {
3569-
# Add to list
3570-
push(@{$bb->{$function}->{$filename}}, $lineno);
3571-
graph_add_order($fileorder, $function, $filename);
3572-
}
3565+
# Add to list
3566+
push(@{$bb->{$function}->{$filename}}, $lineno);
3567+
graph_add_order($fileorder, $function, $filename);
35733568

35743569
return ($filename, $function, $artificial);
35753570
}
@@ -3601,6 +3596,15 @@ sub map_gcno_version($)
36013596
return $major << 16 | $minor << 8;
36023597
}
36033598

3599+
sub remove_fn_from_hash($$)
3600+
{
3601+
my ($hash, $fns) = @_;
3602+
3603+
foreach my $fn (@$fns) {
3604+
delete($hash->{$fn});
3605+
}
3606+
}
3607+
36043608
#
36053609
# read_gcno(filename)
36063610
#
@@ -3633,6 +3637,7 @@ sub read_gcno($)
36333637
my $filelength;
36343638
my $version;
36353639
my $artificial;
3640+
my @artificial_fns;
36363641
local *HANDLE;
36373642

36383643
open(HANDLE, "<", $gcno_filename) or goto open_error;
@@ -3691,12 +3696,12 @@ sub read_gcno($)
36913696
*HANDLE, $bb, $fileorder, $big_endian,
36923697
$length, $version);
36933698
goto incomplete if (!defined($function));
3699+
push(@artificial_fns, $function) if ($artificial);
36943700
} elsif ($tag == $tag_lines) {
36953701
# Read lines record
36963702
$filename = read_gcno_lines_record(*HANDLE,
36973703
$gcno_filename, $bb, $fileorder,
3698-
$filename, $function,
3699-
$big_endian, $artificial);
3704+
$filename, $function, $big_endian);
37003705
goto incomplete if (!defined($filename));
37013706
} else {
37023707
# Skip record contents
@@ -3713,6 +3718,11 @@ sub read_gcno($)
37133718
or goto incomplete;
37143719
}
37153720
close(HANDLE);
3721+
3722+
# Remove artificial functions from result data
3723+
remove_fn_from_hash($bb, \@artificial_fns);
3724+
remove_fn_from_hash($fileorder, \@artificial_fns);
3725+
37163726
($instr, $graph) = graph_from_bb($bb, $fileorder, $gcno_filename);
37173727
graph_cleanup($graph);
37183728

0 commit comments

Comments
 (0)