OSDN Git Service

* config/i386/i386.h: Remove an unnecessary #undef.
[pf3gnuchains/gcc-fork.git] / gcc / coverage.c
index 4a00332..8b43d6a 100644 (file)
@@ -150,39 +150,35 @@ static void
 read_counts_file (void)
 {
   gcov_unsigned_t fn_ident = 0;
-  gcov_unsigned_t version, checksum = -1;
-  unsigned ix;
+  gcov_unsigned_t checksum = -1;
   counts_entry_t *summaried = NULL;
   unsigned seen_summary = 0;
   gcov_unsigned_t tag;
-  int error = 0;
+  int is_error = 0;
 
   if (!gcov_open (da_file_name, 1))
     return;
 
-  if (gcov_read_unsigned () != GCOV_DATA_MAGIC)
+  if (!gcov_magic (gcov_read_unsigned (), GCOV_DATA_MAGIC))
     {
       warning ("`%s' is not a gcov data file", da_file_name);
       gcov_close ();
       return;
     }
-  else if ((version = gcov_read_unsigned ()) != GCOV_VERSION)
+  else if ((tag = gcov_read_unsigned ()) != GCOV_VERSION)
     {
       char v[4], e[4];
-      gcov_unsigned_t required = GCOV_VERSION;
 
-      for (ix = 4; ix--; required >>= 8, version >>= 8)
-       {
-         v[ix] = version;
-         e[ix] = required;
-       }
+      GCOV_UNSIGNED2STRING (v, tag);
+      GCOV_UNSIGNED2STRING (e, GCOV_VERSION);
+
       warning ("`%s' is version `%.4s', expected version `%.4s'",
-              da_file_name, v, e);
+              da_file_name, v, e);
       gcov_close ();
       return;
     }
 
-  /* Read and discard the stamp. */
+  /* Read and discard the stamp.  */
   gcov_read_unsigned ();
   
   counts_hash = htab_create (10,
@@ -236,7 +232,7 @@ read_counts_file (void)
       else if (GCOV_TAG_IS_COUNTER (tag) && fn_ident)
        {
          counts_entry_t **slot, *entry, elt;
-         unsigned n_counts = length / 8;
+         unsigned n_counts = GCOV_TAG_COUNTER_NUM (length);
          unsigned ix;
 
          elt.ident = fn_ident;
@@ -254,17 +250,26 @@ read_counts_file (void)
              entry->summary.num = n_counts;
              entry->counts = xcalloc (n_counts, sizeof (gcov_type));
            }
-         else if (entry->checksum != checksum
-                  || entry->summary.num != n_counts)
+         else if (entry->checksum != checksum)
+           {
+             error ("coverage mismatch for function %u while reading execution counters.",
+                    fn_ident);
+             error ("checksum is %x instead of %x", entry->checksum, checksum);
+             htab_delete (counts_hash);
+             break;
+           }
+         else if (entry->summary.num != n_counts)
            {
-             warning ("coverage mismatch for function %u", fn_ident);
+             error ("coverage mismatch for function %u while reading execution counters.",
+                    fn_ident);
+             error ("number of counters is %d instead of %d", entry->summary.num, n_counts);
              htab_delete (counts_hash);
              break;
            }
          else if (elt.ctr >= GCOV_COUNTERS_SUMMABLE)
            {
-             warning ("cannot merge separate %s counters for function %u",
-                      ctr_names[elt.ctr], fn_ident);
+             error ("cannot merge separate %s counters for function %u",
+                    ctr_names[elt.ctr], fn_ident);
              goto skip_merge;
            }
 
@@ -282,14 +287,14 @@ read_counts_file (void)
        skip_merge:;
        }
       gcov_sync (offset, length);
-      if ((error = gcov_is_error ()))
+      if ((is_error = gcov_is_error ()))
        break;
     }
 
   if (!gcov_is_eof ())
     {
-      warning (error < 0 ? "`%s' has overflowed" : "`%s' is corrupted",
-              da_file_name);
+      error (is_error < 0 ? "`%s' has overflowed" : "`%s' is corrupted",
+            da_file_name);
       htab_delete (counts_hash);
     }
 
@@ -303,6 +308,7 @@ get_coverage_counts (unsigned counter, unsigned expected,
                     const struct gcov_ctr_summary **summary)
 {
   counts_entry_t *entry, elt;
+  gcov_unsigned_t checksum = -1;
 
   /* No hash table, no counts.  */
   if (!counts_hash)
@@ -310,8 +316,8 @@ get_coverage_counts (unsigned counter, unsigned expected,
       static int warned = 0;
 
       if (!warned++)
-       warning ("file %s not found, execution counts assumed to be zero",
-                da_file_name);
+       inform ("file %s not found, execution counts assumed to be zero",
+               da_file_name);
       return NULL;
     }
 
@@ -325,12 +331,22 @@ get_coverage_counts (unsigned counter, unsigned expected,
       return 0;
     }
 
-  if (expected != entry->summary.num
-      || compute_checksum () != entry->checksum)
+  checksum = compute_checksum ();
+  if (entry->checksum != checksum)
     {
-      warning ("coverage mismatch for `%s'", IDENTIFIER_POINTER
-              (DECL_ASSEMBLER_NAME (current_function_decl)));
-      return NULL;
+      error ("coverage mismatch for function '%s' while reading counter '%s'.",
+            IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (current_function_decl)),
+            ctr_names[counter]);
+      error ("checksum is %x instead of %x", entry->checksum, checksum);
+      return 0;
+    }
+  else if (entry->summary.num != expected)
+    {
+      error ("coverage mismatch for function '%s' while reading counter '%s'.",
+            IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (current_function_decl)),
+            ctr_names[counter]);
+      error ("number of counters is %d instead of %d", entry->summary.num, expected);
+      return 0;
     }
 
   if (summary)
@@ -446,7 +462,7 @@ coverage_begin_output (void)
            error ("cannot open %s", bbg_file_name);
          else
            {
-             gcov_write_unsigned (GCOV_GRAPH_MAGIC);
+             gcov_write_unsigned (GCOV_NOTE_MAGIC);
              gcov_write_unsigned (GCOV_VERSION);
              gcov_write_unsigned (local_tick);
            }
@@ -641,7 +657,7 @@ build_ctr_info_value (unsigned int counter, tree type)
       array_type = build_array_type (TREE_TYPE (TREE_TYPE (fields)),
                                     array_type);
 
-      array = build (VAR_DECL, array_type, NULL_TREE, NULL_TREE);
+      array = build_decl (VAR_DECL, NULL_TREE, array_type);
       TREE_STATIC (array) = 1;
       DECL_NAME (array) = get_identifier (XSTR (ctr_labels[counter], 0));
       assemble_variable (array, 0, 0, 0);
@@ -828,8 +844,7 @@ create_coverage (void)
 
   gcov_info_value = build_gcov_info ();
 
-  gcov_info = build (VAR_DECL, TREE_TYPE (gcov_info_value),
-                    NULL_TREE, NULL_TREE);
+  gcov_info = build_decl (VAR_DECL, NULL_TREE, TREE_TYPE (gcov_info_value));
   DECL_INITIAL (gcov_info) = gcov_info_value;
 
   TREE_STATIC (gcov_info) = 1;
@@ -858,19 +873,18 @@ create_coverage (void)
   rest_of_decl_compilation (ctor, 0, 1, 0);
   announce_function (ctor);
   current_function_decl = ctor;
-  DECL_INITIAL (ctor) = error_mark_node;
   make_decl_rtl (ctor, NULL);
   init_function_start (ctor);
-  (*lang_hooks.decls.pushlevel) (0);
   expand_function_start (ctor, 0);
-
   /* Actually generate the code to call __gcov_init.  */
   gcov_info_address = force_reg (Pmode, XEXP (DECL_RTL (gcov_info), 0));
   emit_library_call (gcov_init_libfunc, LCT_NORMAL, VOIDmode, 1,
                     gcov_info_address, Pmode);
 
   expand_function_end ();
-  (*lang_hooks.decls.poplevel) (1, 0, 1);
+  /* Create a dummy BLOCK.  */
+  DECL_INITIAL (ctor) = make_node (BLOCK);
+  TREE_USED (DECL_INITIAL (ctor)) = 1;
 
   rest_of_compilation (ctor);
 
@@ -892,14 +906,14 @@ coverage_init (const char *filename)
   int len = strlen (filename);
 
   /* Name of da file.  */
-  da_file_name = (char *) xmalloc (len + strlen (GCOV_DATA_SUFFIX) + 1);
+  da_file_name = xmalloc (len + strlen (GCOV_DATA_SUFFIX) + 1);
   strcpy (da_file_name, filename);
   strcat (da_file_name, GCOV_DATA_SUFFIX);
 
   /* Name of bbg file.  */
-  bbg_file_name = (char *) xmalloc (len + strlen (GCOV_GRAPH_SUFFIX) + 1);
+  bbg_file_name = xmalloc (len + strlen (GCOV_NOTE_SUFFIX) + 1);
   strcpy (bbg_file_name, filename);
-  strcat (bbg_file_name, GCOV_GRAPH_SUFFIX);
+  strcat (bbg_file_name, GCOV_NOTE_SUFFIX);
 
   read_counts_file ();
 }