public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: "Martin Liška" <mliska@suse.cz>
To: gcc-patches@gcc.gnu.org
Subject: [PATCH] gcov: fix streaming corruption
Date: Tue, 22 Sep 2020 09:18:25 +0200	[thread overview]
Message-ID: <1a8e6630-b4c5-62b2-2eff-76251288701d@suse.cz> (raw)

As mentioned in the PR, line number equal to 0 is a bogus. Moreover, it messes
up GCNO file format where we use 0 as a separator. I'm thus suggesting to start
lines with at least 1.

Patch can bootstrap on x86_64-linux-gnu and survives regression tests.
I'll install the patch if there are no comments.

Thanks,
Martin

gcc/ChangeLog:

	PR gcov-profile/97069
	* profile.c (branch_prob): Line number must be at least 1.

gcc/testsuite/ChangeLog:

	PR gcov-profile/97069
	* g++.dg/gcov/pr97069.C: New test.
---
  gcc/profile.c                       |  6 +++---
  gcc/testsuite/g++.dg/gcov/pr97069.C | 20 ++++++++++++++++++++
  2 files changed, 23 insertions(+), 3 deletions(-)
  create mode 100644 gcc/testsuite/g++.dg/gcov/pr97069.C

diff --git a/gcc/profile.c b/gcc/profile.c
index fe8963cc9e9..45409591629 100644
--- a/gcc/profile.c
+++ b/gcc/profile.c
@@ -1375,7 +1375,7 @@ branch_prob (bool thunk)
  	      seen_locations.add (loc);
  	      expanded_location curr_location = expand_location (loc);
  	      output_location (&streamed_locations, curr_location.file,
-			       curr_location.line, &offset, bb);
+			       MAX (1, curr_location.line), &offset, bb);
  	    }
  
  	  for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi))
@@ -1386,7 +1386,7 @@ branch_prob (bool thunk)
  		{
  		  seen_locations.add (loc);
  		  output_location (&streamed_locations, gimple_filename (stmt),
-				   gimple_lineno (stmt), &offset, bb);
+				   MAX (1, gimple_lineno (stmt)), &offset, bb);
  		}
  	    }
  
@@ -1401,7 +1401,7 @@ branch_prob (bool thunk)
  	    {
  	      expanded_location curr_location = expand_location (loc);
  	      output_location (&streamed_locations, curr_location.file,
-			       curr_location.line, &offset, bb);
+			       MAX (1, curr_location.line), &offset, bb);
  	    }
  
  	  if (offset)
diff --git a/gcc/testsuite/g++.dg/gcov/pr97069.C b/gcc/testsuite/g++.dg/gcov/pr97069.C
new file mode 100644
index 00000000000..040e336662a
--- /dev/null
+++ b/gcc/testsuite/g++.dg/gcov/pr97069.C
@@ -0,0 +1,20 @@
+// PR gcov-profile/97069
+// { dg-options "--coverage" }
+// { dg-do run { target native } }
+
+# 0 "pr97069.C"
+# 0 "<built-in>"
+# 0 "<command-line>"
+# 1 "/usr/include/stdc-predef.h" 1 3 4
+# 0 "<command-line>" 2
+# 1 "pr97069.C"
+int main()
+{
+  return 0;
+}
+# 0 "pr97069.C"
+void zero_line_directive()
+{
+}
+
+// { dg-final { run-gcov pr97069.C } }
-- 
2.28.0


                 reply	other threads:[~2020-09-22  7:18 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=1a8e6630-b4c5-62b2-2eff-76251288701d@suse.cz \
    --to=mliska@suse.cz \
    --cc=gcc-patches@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).