* [PATCH] gcov: fix streaming corruption
@ 2020-09-22 7:18 Martin Liška
0 siblings, 0 replies; only message in thread
From: Martin Liška @ 2020-09-22 7:18 UTC (permalink / raw)
To: gcc-patches
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
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2020-09-22 7:18 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-22 7:18 [PATCH] gcov: fix streaming corruption Martin Liška
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).