This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Make groups more generic (PR gcov-profile/84548).


Hi.

Considering following C++ code snippet:

struct A { static int foo () { return 1; }; static int bar () {
  int x;
  return 2; } };

we should consider functions foo and bar as 2 within a single group. Even though
these functions are not 'clones',  they still overlap and it's proper to group them.

Doing that we'll have:

        2:    1:struct A { static int foo () { return 1; }; static int bar () {
        -:    2:  int x;
        1:    3:  return 2; } };
------------------
_ZN1A3fooEv:
        1:    1:struct A { static int foo () { return 1; }; static int bar () {
------------------
_ZN1A3barEv:
        1:    1:struct A { static int foo () { return 1; }; static int bar () {
        -:    2:  int x;
        1:    3:  return 2; } };
------------------

which is proper fix in my opinion.

Patch can bootstrap on ppc64le-redhat-linux and survives regression tests.

Ready to be installed?
Martin

Martin

gcc/ChangeLog:

2018-02-26  Martin Liska  <mliska@suse.cz>

	PR gcov-profile/84548
	* gcov.c (process_file): Allow partial overlap and consider it
	also as group functions.
	(output_lines): Properly calculate range of lines for a group.

gcc/testsuite/ChangeLog:

2018-02-26  Martin Liska  <mliska@suse.cz>

	PR gcov-profile/84548
	* g++.dg/gcov/pr84548.C: New test.
---
 gcc/gcov.c                          |  9 +++++++--
 gcc/testsuite/g++.dg/gcov/pr84548.C | 19 +++++++++++++++++++
 2 files changed, 26 insertions(+), 2 deletions(-)
 create mode 100644 gcc/testsuite/g++.dg/gcov/pr84548.C


diff --git a/gcc/gcov.c b/gcc/gcov.c
index 37f431c0e91..3d802a10870 100644
--- a/gcc/gcov.c
+++ b/gcc/gcov.c
@@ -1151,7 +1151,6 @@ process_file (const char *file_name)
 	function_info **slot = fn_map.get (needle);
 	if (slot)
 	  {
-	    gcc_assert ((*slot)->end_line == (*it)->end_line);
 	    (*slot)->is_group = 1;
 	    (*it)->is_group = 1;
 	  }
@@ -2957,7 +2956,13 @@ output_lines (FILE *gcov_file, const source_info *src)
 	{
 	  fns = src->get_functions_at_location (line_num);
 	  if (fns.size () > 1)
-	    line_start_group = fns[0]->end_line;
+	    {
+	      /* It's possible to have function that partially overlap,
+		 thus take the maximum end_line of got functions.  */
+	      for (unsigned i = 0; i < fns.size (); i++)
+		if (fns[i]->end_line > line_start_group)
+		  line_start_group = fns[i]->end_line;
+	    }
 	  else if (fns.size () == 1)
 	    {
 	      function_info *fn = fns[0];
diff --git a/gcc/testsuite/g++.dg/gcov/pr84548.C b/gcc/testsuite/g++.dg/gcov/pr84548.C
new file mode 100644
index 00000000000..6c22c1902f2
--- /dev/null
+++ b/gcc/testsuite/g++.dg/gcov/pr84548.C
@@ -0,0 +1,19 @@
+// PR gcov-profile/84548
+// { dg-options "-fprofile-arcs -ftest-coverage" }
+// { dg-do run { target native } }
+// TODO: add support for groups to gcov.exp script
+
+struct A { static int foo () { return 1; }; static int bar () {
+  int x;
+  return 2; } };
+
+int main()
+{
+  int a = A::foo () + A::bar ();
+  if (a != 3)
+    return 1;
+
+  return 0;
+}
+
+// { dg-final { run-gcov remove-gcda pr84548.C } }


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]