]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
gcov: fix streaming corruption
authorMartin Liska <mliska@suse.cz>
Mon, 21 Sep 2020 14:26:10 +0000 (16:26 +0200)
committerMartin Liska <mliska@suse.cz>
Thu, 1 Oct 2020 19:19:14 +0000 (21:19 +0200)
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.

(cherry picked from commit 6b4e8bf88f1172ce8561f57b12fb81063b21a78f)

gcc/profile.c
gcc/testsuite/g++.dg/gcov/pr97069.C [new file with mode: 0644]

index cd754c4c66a1f2ff4bcd7a8dd8ef2d9d70c04ff0..2e5ab0d34156f46d98c69217f337621fdfd36198 100644 (file)
@@ -1367,7 +1367,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))
@@ -1378,7 +1378,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);
                }
            }
 
@@ -1393,7 +1393,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 (file)
index 0000000..040e336
--- /dev/null
@@ -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 } }