]> git.ipfire.org Git - thirdparty/gcc.git/blobdiff - gcc/gcov-tool.c
Correct a function pre/postcondition [PR102403].
[thirdparty/gcc.git] / gcc / gcov-tool.c
index cadf09377ddb56997c92fca8c2efc818ed895e3a..71bdfdaa1f01da30fffccefa5c9c1f8863ac6124 100644 (file)
@@ -1,5 +1,5 @@
 /* Gcc offline profile processing tool support. */
-/* Copyright (C) 2014-2017 Free Software Foundation, Inc.
+/* Copyright (C) 2014-2021 Free Software Foundation, Inc.
    Contributed by Rong Xu <xur@google.com>.
 
 This file is part of GCC.
@@ -46,6 +46,7 @@ extern int gcov_profile_normalize (struct gcov_info*, gcov_type);
 extern int gcov_profile_scale (struct gcov_info*, float, int, int);
 extern struct gcov_info* gcov_read_profile_dir (const char*, int);
 extern void gcov_do_dump (struct gcov_info *, int);
+extern const char *gcov_get_filename (struct gcov_info *list);
 extern void gcov_set_verbose (void);
 
 /* Set to verbose output mode.  */
@@ -69,7 +70,7 @@ unlink_gcda_file (const char *name,
     ret = remove (name);
 
   if (ret)
-    fatal_error (input_location, "error in removing %s\n", name);
+    fatal_error (input_location, "error in removing %s", name);
 
   return ret;
 }
@@ -114,6 +115,14 @@ gcov_output_files (const char *out, struct gcov_info *profile)
   if (ret)
     fatal_error (input_location, "Cannot change directory to %s", out);
 
+  /* Verify that output file does not exist (either was removed by
+     unlink_profile_data or removed by user).  */
+  const char *filename = gcov_get_filename (profile);
+
+  if (access (filename, F_OK) != -1)
+    fatal_error (input_location, "output file %s already exists in folder %s",
+                filename, out);
+
   gcov_do_dump (profile, 0);
 
   ret = chdir (pwd);
@@ -164,8 +173,8 @@ print_merge_usage_message (int error_p)
   FILE *file = error_p ? stderr : stdout;
 
   fnotice (file, "  merge [options] <dir1> <dir2>         Merge coverage file contents\n");
-  fnotice (file, "    -v, --verbose                       Verbose mode\n");
   fnotice (file, "    -o, --output <dir>                  Output directory\n");
+  fnotice (file, "    -v, --verbose                       Verbose mode\n");
   fnotice (file, "    -w, --weight <w1,w2>                Set weights (float point values)\n");
 }
 
@@ -179,7 +188,7 @@ static const struct option merge_options[] =
 
 /* Print merge usage and exit.  */
 
-static void
+static void ATTRIBUTE_NORETURN
 merge_usage (void)
 {
   fnotice (stderr, "Merge subcomand usage:");
@@ -211,7 +220,7 @@ do_merge (int argc, char **argv)
         case 'w':
           sscanf (optarg, "%d,%d", &w1, &w2);
           if (w1 < 0 || w2 < 0)
-            fatal_error (input_location, "weights need to be non-negative\n");
+           fatal_error (input_location, "weights need to be non-negative");
           break;
         default:
           merge_usage ();
@@ -258,10 +267,10 @@ print_rewrite_usage_message (int error_p)
   FILE *file = error_p ? stderr : stdout;
 
   fnotice (file, "  rewrite [options] <dir>               Rewrite coverage file contents\n");
-  fnotice (file, "    -v, --verbose                       Verbose mode\n");
+  fnotice (file, "    -n, --normalize <int64_t>           Normalize the profile\n");
   fnotice (file, "    -o, --output <dir>                  Output directory\n");
   fnotice (file, "    -s, --scale <float or simple-frac>  Scale the profile counters\n");
-  fnotice (file, "    -n, --normalize <int64_t>           Normalize the profile\n");
+  fnotice (file, "    -v, --verbose                       Verbose mode\n");
 }
 
 static const struct option rewrite_options[] =
@@ -275,7 +284,7 @@ static const struct option rewrite_options[] =
 
 /* Print profile rewrite usage and exit.  */
 
-static void
+static void ATTRIBUTE_NORETURN
 rewrite_usage (void)
 {
   fnotice (stderr, "Rewrite subcommand usage:");
@@ -346,7 +355,7 @@ do_rewrite (int argc, char **argv)
             }
 
           if (scale < 0.0)
-            fatal_error (input_location, "scale needs to be non-negative\n");
+           fatal_error (input_location, "scale needs to be non-negative");
 
           if (normalize_val != 0)
             {
@@ -408,13 +417,12 @@ print_overlap_usage_message (int error_p)
   FILE *file = error_p ? stderr : stdout;
 
   fnotice (file, "  overlap [options] <dir1> <dir2>       Compute the overlap of two profiles\n");
-  fnotice (file, "    -v, --verbose                       Verbose mode\n");
-  fnotice (file, "    -h, --hotonly                       Only print info for hot objects/functions\n");
   fnotice (file, "    -f, --function                      Print function level info\n");
   fnotice (file, "    -F, --fullname                      Print full filename\n");
+  fnotice (file, "    -h, --hotonly                       Only print info for hot objects/functions\n");
   fnotice (file, "    -o, --object                        Print object level info\n");
   fnotice (file, "    -t <float>, --hot_threshold <float> Set the threshold for hotness\n");
-
+  fnotice (file, "    -v, --verbose                       Verbose mode\n");
 }
 
 static const struct option overlap_options[] =
@@ -430,7 +438,7 @@ static const struct option overlap_options[] =
 
 /* Print overlap usage and exit.  */
 
-static void
+static void ATTRIBUTE_NORETURN
 overlap_usage (void)
 {
   fnotice (stderr, "Overlap subcomand usage:");
@@ -517,12 +525,11 @@ static void
 print_version (void)
 {
   fnotice (stdout, "%s %s%s\n", progname, pkgversion_string, version_string);
-  fnotice (stdout, "Copyright %s 2014-2017 Free Software Foundation, Inc.\n",
+  fnotice (stdout, "Copyright %s 2021 Free Software Foundation, Inc.\n",
            _("(C)"));
   fnotice (stdout,
-           _("This is free software; see the source for copying conditions.\n"
-             "There is NO warranty; not even for MERCHANTABILITY or \n"
-             "FITNESS FOR A PARTICULAR PURPOSE.\n\n"));
+          _("This is free software; see the source for copying conditions.  There is NO\n\
+warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\n"));
   exit (SUCCESS_EXIT_CODE);
 }