OSDN Git Service

Daily bump.
[pf3gnuchains/gcc-fork.git] / gcc / coverage.c
index 656db92..ce8b175 100644 (file)
@@ -1,6 +1,6 @@
 /* Read and write coverage files, and associated functionality.
    Copyright (C) 1990, 1991, 1992, 1993, 1994, 1996, 1997, 1998, 1999,
-   2000, 2001, 2003, 2004, 2005, 2007, 2008, 2009, 2010, 2011
+   2000, 2001, 2003, 2004, 2005, 2007, 2008, 2009, 2010, 2011, 2012
    Free Software Foundation, Inc.
    Contributed by James E. Wilson, UC Berkeley/Cygnus Support;
    based on some ideas from Dain Samples of UC Berkeley.
@@ -50,6 +50,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "diagnostic-core.h"
 #include "intl.h"
 #include "filenames.h"
+#include "target.h"
 
 #include "gcov-io.h"
 #include "gcov-io.c"
@@ -604,20 +605,33 @@ coverage_end_function (unsigned lineno_checksum, unsigned cfg_checksum)
       bbg_file_name = NULL;
     }
 
-  /* If the function is extern (i.e. extern inline), then we won't be
-     outputting it, so don't chain it onto the function list.  */
-  if (fn_ctr_mask && !DECL_EXTERNAL (current_function_decl))
+  if (fn_ctr_mask)
     {
-      struct coverage_data *item = ggc_alloc_coverage_data ();
+      struct coverage_data *item = 0;
+
+      /* If the function is extern (i.e. extern inline), then we won't
+        be outputting it, so don't chain it onto the function
+        list.  */
+      if (!DECL_EXTERNAL (current_function_decl))
+       {
+         item = ggc_alloc_coverage_data ();
+         
+         item->ident = current_function_funcdef_no + 1;
+         item->lineno_checksum = lineno_checksum;
+         item->cfg_checksum = cfg_checksum;
+
+         item->fn_decl = current_function_decl;
+         item->next = 0;
+         *functions_tail = item;
+         functions_tail = &item->next;
+       }
 
-      item->ident = current_function_funcdef_no + 1;
-      item->lineno_checksum = lineno_checksum;
-      item->cfg_checksum = cfg_checksum;
       for (i = 0; i != GCOV_COUNTERS; i++)
        {
          tree var = fn_v_ctrs[i];
-         
-         item->ctr_vars[i] = var;
+
+         if (item)
+           item->ctr_vars[i] = var;
          if (var)
            {
              tree array_type = build_index_type (size_int (fn_n_ctrs[i] - 1));
@@ -627,17 +641,7 @@ coverage_end_function (unsigned lineno_checksum, unsigned cfg_checksum)
              DECL_SIZE_UNIT (var) = TYPE_SIZE_UNIT (array_type);
              varpool_finalize_decl (var);
            }
-       }
-      item->fn_decl = current_function_decl;
-      item->next = 0;
-      *functions_tail = item;
-      functions_tail = &item->next;
-    }
-  
-  if (fn_ctr_mask)
-    {
-      for (i = 0; i != GCOV_COUNTERS; i++)
-       {
+         
          fn_b_ctrs[i] = fn_n_ctrs[i] = 0;
          fn_v_ctrs[i] = NULL_TREE;
        }
@@ -653,13 +657,25 @@ static tree
 build_var (tree fn_decl, tree type, int counter)
 {
   tree var = build_decl (BUILTINS_LOCATION, VAR_DECL, NULL_TREE, type);
-  tree fn_name = DECL_ASSEMBLER_NAME (fn_decl);
-  char *buf = (char *)alloca (IDENTIFIER_LENGTH (fn_name) + 10);
+  const char *fn_name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (fn_decl));
+  char *buf;
+  size_t fn_name_len, len;
+
+  fn_name = targetm.strip_name_encoding (fn_name);
+  fn_name_len = strlen (fn_name);
+  buf = XALLOCAVEC (char, fn_name_len + 8 + sizeof (int) * 3);
 
   if (counter < 0)
-    sprintf (buf, "__gcov__%s", IDENTIFIER_POINTER (fn_name));
+    strcpy (buf, "__gcov__");
   else
-    sprintf (buf, "__gcov%u_%s", counter, IDENTIFIER_POINTER (fn_name));
+    sprintf (buf, "__gcov%u_", counter);
+  len = strlen (buf);
+#ifndef NO_DOT_IN_LABEL
+  buf[len - 1] = '.';
+#elif !defined NO_DOLLAR_IN_LABEL
+  buf[len - 1] = '$';
+#endif
+  memcpy (buf + len, fn_name, fn_name_len + 1);
   DECL_NAME (var) = get_identifier (buf);
   TREE_STATIC (var) = 1;
   TREE_ADDRESSABLE (var) = 1;
@@ -1116,7 +1132,7 @@ coverage_finish (void)
   if (bbg_file_name && gcov_close ())
     unlink (bbg_file_name);
   
-  if (!local_tick)
+  if (!local_tick || local_tick == (unsigned)-1)
     /* Only remove the da file, if we cannot stamp it.  If we can
        stamp it, libgcov will DTRT.  */
     unlink (da_file_name);