[gcc(refs/users/marxin/heads/PR97069-fix-gcov-with-zero-line)] gcov: fix streaming corruption

Martin Liska marxin@gcc.gnu.org
Mon Sep 21 14:26:49 GMT 2020


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

commit edb745cceb4baa5700852ce0012d4eac2020d243
Author: Martin Liska <mliska@suse.cz>
Date:   Mon Sep 21 16:26:10 2020 +0200

    gcov: fix streaming corruption
    
    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.

Diff:
---
 gcc/profile.c                       |  6 +++---
 gcc/testsuite/g++.dg/gcov/pr97069.C | 20 ++++++++++++++++++++
 2 files changed, 23 insertions(+), 3 deletions(-)

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 } }


More information about the Gcc-cvs mailing list