GCOV: simplify usage of function_info::artificial.
authorMartin Liska <mliska@suse.cz>
Mon, 13 Nov 2017 09:05:38 +0000 (10:05 +0100)
committerMartin Liska <marxin@gcc.gnu.org>
Mon, 13 Nov 2017 09:05:38 +0000 (09:05 +0000)
2017-11-13  Martin Liska  <mliska@suse.cz>

* gcov.c (function_info::is_artificial): New function.
(process_file): Erase all artificial early.
(generate_results): Skip as all artificial are already
removed.

From-SVN: r254673

gcc/ChangeLog
gcc/gcov.c

index 0261faffc6765010932699a88c6054843eba47ef..993477049f774d6409a7b958582f03157a853ecb 100644 (file)
@@ -1,3 +1,10 @@
+2017-11-13  Martin Liska  <mliska@suse.cz>
+
+       * gcov.c (function_info::is_artificial): New function.
+       (process_file): Erase all artificial early.
+       (generate_results): Skip as all artificial are already
+       removed.
+
 2017-11-13  Martin Liska  <mliska@suse.cz>
 
        * gcov.c (read_graph_file): Store to global vector of functions.
index 71239cf0cbd1bced40122361457a008d64ddd913..01901ed7493b1a32440e256a8a912ba01ddc9060 100644 (file)
@@ -232,6 +232,14 @@ typedef struct function_info
      The line must be defined in body of the function, can't be inlined.  */
   bool group_line_p (unsigned n, unsigned src_idx);
 
+  /* Function filter based on function_info::artificial variable.  */
+
+  static inline bool
+  is_artificial (function_info *fn)
+  {
+    return fn->artificial;
+  }
+
   /* Name of function.  */
   char *name;
   char *demangled_name;
@@ -1152,33 +1160,40 @@ process_file (const char *file_name)
          fn_map.put (needle, *it);
       }
 
+  /* Remove all artificial function.  */
+  functions.erase (remove_if (functions.begin (), functions.end (),
+                             function_info::is_artificial), functions.end ());
+
   for (vector<function_t *>::iterator it = functions.begin ();
        it != functions.end (); it++)
     {
       function_t *fn = *it;
+      unsigned src = fn->src;
 
       if (fn->counts || no_data_file)
        {
-         unsigned src = fn->src;
-         unsigned block_no;
+         source_info *s = &sources[src];
+         s->functions.push_back (fn);
 
-         /* Process only non-artificial functions.  */
-         if (!fn->artificial)
+         /* Mark last line in files touched by function.  */
+         for (unsigned block_no = 0; block_no != fn->blocks.size ();
+              block_no++)
            {
-             source_info *s = &sources[src];
-             s->functions.push_back (fn);
-
-             /* Mark last line in files touched by function.  */
-             for (block_no = 0; block_no != fn->blocks.size (); block_no++)
+             block_t *block = &fn->blocks[block_no];
+             for (unsigned i = 0; i < block->locations.size (); i++)
                {
-                 block_t *block = &fn->blocks[block_no];
-                 for (unsigned i = 0; i < block->locations.size (); i++)
+                 /* Sort lines of locations.  */
+                 sort (block->locations[i].lines.begin (),
+                       block->locations[i].lines.end ());
+
+                 if (!block->locations[i].lines.empty ())
                    {
-                     /* Sort lines of locations.  */
-                     sort (block->locations[i].lines.begin (),
-                           block->locations[i].lines.end ());
+                     s = &sources[block->locations[i].source_file_idx];
+                     unsigned last_line
+                       = block->locations[i].lines.back ();
 
-                     if (!block->locations[i].lines.empty ())
+                     /* Record new lines for the function.  */
+                     if (last_line >= s->lines.size ())
                        {
                          s = &sources[block->locations[i].source_file_idx];
                          unsigned last_line
@@ -1192,17 +1207,18 @@ process_file (const char *file_name)
                            }
                        }
                    }
-
-                 /* Allocate lines for group function, following start_line
-                    and end_line information of the function.  */
-                 if (fn->is_group)
-                   fn->lines.resize (fn->end_line - fn->start_line + 1);
                }
-
-             solve_flow_graph (fn);
-             if (fn->has_catch)
-               find_exception_blocks (fn);
            }
+
+         /* Allocate lines for group function, following start_line
+            and end_line information of the function.  */
+         if (fn->is_group)
+           fn->lines.resize (fn->end_line - fn->start_line + 1);
+
+
+         solve_flow_graph (fn);
+         if (fn->has_catch)
+           find_exception_blocks (fn);
        }
       else
        {
@@ -1251,8 +1267,6 @@ generate_results (const char *file_name)
     {
       function_t *fn = *it;
       coverage_t coverage;
-      if (fn->artificial)
-       continue;
 
       memset (&coverage, 0, sizeof (coverage));
       coverage.name = flag_demangled_names ? fn->demangled_name : fn->name;