aboutsummaryrefslogtreecommitdiff
path: root/gcc/gcov.c
diff options
context:
space:
mode:
authorMartin Liska <mliska@suse.cz>2020-12-14 14:00:08 +0100
committerMartin Liska <mliska@suse.cz>2020-12-15 09:41:21 +0100
commitefd08ad579a1dea6409bd280cb5c263ed0849839 (patch)
tree6cff7d4e2e6921e815733fb2c2ac5f18fe6042aa /gcc/gcov.c
parent23900be4d316be2d049378c094798982b7f0df9e (diff)
downloadgcc-efd08ad579a1dea6409bd280cb5c263ed0849839.zip
gcc-efd08ad579a1dea6409bd280cb5c263ed0849839.tar.gz
gcc-efd08ad579a1dea6409bd280cb5c263ed0849839.tar.bz2
gcov: fix line output for nested functions in JSON format
gcc/ChangeLog: PR gcov-profile/98273 * gcov.c (output_json_intermediate_file): Use stack of nested functions for lines in a source file. Pop when a function ends.
Diffstat (limited to 'gcc/gcov.c')
-rw-r--r--gcc/gcov.c18
1 files changed, 13 insertions, 5 deletions
diff --git a/gcc/gcov.c b/gcc/gcov.c
index daa1266..8dcec94 100644
--- a/gcc/gcov.c
+++ b/gcc/gcov.c
@@ -1165,7 +1165,7 @@ output_json_intermediate_file (json::array *json_files, source_info *src)
json::array *lineso = new json::array ();
root->set ("lines", lineso);
- function_info *last_non_group_fn = NULL;
+ vector<function_info *> last_non_group_fns;
for (unsigned line_num = 1; line_num <= src->lines.size (); line_num++)
{
@@ -1177,7 +1177,7 @@ output_json_intermediate_file (json::array *json_files, source_info *src)
it2 != fns->end (); it2++)
{
if (!(*it2)->is_group)
- last_non_group_fn = *it2;
+ last_non_group_fns.push_back (*it2);
vector<line_info> &lines = (*it2)->lines;
/* The LINES array is allocated only for group functions. */
@@ -1191,9 +1191,17 @@ output_json_intermediate_file (json::array *json_files, source_info *src)
/* Follow with lines associated with the source file. */
if (line_num < src->lines.size ())
- output_intermediate_json_line (lineso, &src->lines[line_num], line_num,
- (last_non_group_fn != NULL
- ? last_non_group_fn->m_name : NULL));
+ {
+ unsigned size = last_non_group_fns.size ();
+ function_info *last_fn = size > 0 ? last_non_group_fns[size - 1] : NULL;
+ const char *fname = last_fn ? last_fn->m_name : NULL;
+ output_intermediate_json_line (lineso, &src->lines[line_num], line_num,
+ fname);
+
+ /* Pop ending function from stack. */
+ if (last_fn != NULL && last_fn->end_line == line_num)
+ last_non_group_fns.pop_back ();
+ }
}
}