public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Martin Liska <marxin@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc r11-6038] gcov: fix line output for nested functions in JSON format
Date: Tue, 15 Dec 2020 08:41:32 +0000 (GMT)	[thread overview]
Message-ID: <20201215084132.B5790385800D@sourceware.org> (raw)

https://gcc.gnu.org/g:efd08ad579a1dea6409bd280cb5c263ed0849839

commit r11-6038-gefd08ad579a1dea6409bd280cb5c263ed0849839
Author: Martin Liska <mliska@suse.cz>
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<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 ();
+	}
     }
 }


                 reply	other threads:[~2020-12-15  8:41 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20201215084132.B5790385800D@sourceware.org \
    --to=marxin@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).