From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1851) id B5790385800D; Tue, 15 Dec 2020 08:41:32 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B5790385800D MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Martin Liska To: gcc-cvs@gcc.gnu.org Subject: [gcc r11-6038] gcov: fix line output for nested functions in JSON format X-Act-Checkin: gcc X-Git-Author: Martin Liska X-Git-Refname: refs/heads/master X-Git-Oldrev: 23900be4d316be2d049378c094798982b7f0df9e X-Git-Newrev: efd08ad579a1dea6409bd280cb5c263ed0849839 Message-Id: <20201215084132.B5790385800D@sourceware.org> Date: Tue, 15 Dec 2020 08:41:32 +0000 (GMT) X-BeenThere: gcc-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 15 Dec 2020 08:41:32 -0000 https://gcc.gnu.org/g:efd08ad579a1dea6409bd280cb5c263ed0849839 commit r11-6038-gefd08ad579a1dea6409bd280cb5c263ed0849839 Author: Martin Liska Date: Mon Dec 14 14:00:08 2020 +0100 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. Diff: --- gcc/gcov.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/gcc/gcov.c b/gcc/gcov.c index daa1266db86..8dcec9432a6 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 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 &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 (); + } } }