OSDN Git Service

2008-06-04 Xinliang David Li <davidxl@google.com>
[pf3gnuchains/gcc-fork.git] / gcc / opts.c
index 16ca6bf..d86c2b3 100644 (file)
@@ -58,6 +58,11 @@ bool extra_warnings;
 bool warn_larger_than;
 HOST_WIDE_INT larger_than_size;
 
+/* True to warn about any function whose frame size is larger
+ * than N bytes. */
+bool warn_frame_larger_than;
+HOST_WIDE_INT frame_larger_than_size;
+
 /* Hack for cooperation between set_Wunused and set_Wextra.  */
 static bool maybe_warn_unused_parameter;
 
@@ -337,7 +342,11 @@ bool no_unit_at_a_time_default;
 struct visibility_flags visibility_options;
 
 /* What to print when a switch has no documentation.  */
+#ifdef ENABLE_CHECKING
 static const char undocumented_msg[] = N_("This switch lacks documentation");
+#else
+static const char undocumented_msg[] = "";
+#endif
 
 /* Used for bookkeeping on whether user set these flags so
    -fprofile-use/-fprofile-generate does not use them.  */
@@ -356,6 +365,12 @@ DEF_VEC_ALLOC_P(char_p,heap);
 static VEC(char_p,heap) *flag_instrument_functions_exclude_functions;
 static VEC(char_p,heap) *flag_instrument_functions_exclude_files;
 
+typedef const char *const_char_p; /* For DEF_VEC_P.  */
+DEF_VEC_P(const_char_p);
+DEF_VEC_ALLOC_P(const_char_p,heap);
+
+static VEC(const_char_p,heap) *ignored_options;
+
 /* Input file names.  */
 const char **in_fnames;
 unsigned num_in_fnames;
@@ -434,6 +449,33 @@ complain_wrong_lang (const char *text, const struct cl_option *option,
   free (bad_lang);
 }
 
+/* Buffer the unknown option described by the string OPT.  Currently,
+   we only complain about unknown -Wno-* options if they may have
+   prevented a diagnostic. Otherwise, we just ignore them.  */
+
+static void postpone_unknown_option_error(const char *opt)
+{
+  VEC_safe_push (const_char_p, heap, ignored_options, opt);
+}
+
+/* Produce an error for each option previously buffered.  */
+
+void print_ignored_options (void)
+{
+  location_t saved_loc = input_location;
+
+  input_location = 0;
+
+  while (!VEC_empty (const_char_p, ignored_options))
+    {
+      const char *opt;
+      opt = VEC_pop (const_char_p, ignored_options);
+      error ("unrecognized command line option \"%s\"", opt);
+    }
+
+  input_location = saved_loc;
+}
+
 /* Handle the switch beginning at ARGV for the language indicated by
    LANG_MASK.  Returns the number of switches consumed.  */
 static unsigned int
@@ -463,6 +505,14 @@ handle_option (const char **argv, unsigned int lang_mask)
       opt = dup;
       value = 0;
       opt_index = find_opt (opt + 1, lang_mask | CL_COMMON | CL_TARGET);
+      if (opt_index == cl_options_count && opt[1] == 'W')
+       {
+         /* We don't generate errors for unknown -Wno-* options
+             unless we issue diagnostics.  */
+         postpone_unknown_option_error (argv[0]);
+         result = 1;
+         goto done;
+       }
     }
 
   if (opt_index == cl_options_count)
@@ -703,7 +753,7 @@ handle_options (unsigned int argc, const char **argv, unsigned int lang_mask)
        {
          if (main_input_filename == NULL)
            {
-           main_input_filename = opt;
+             main_input_filename = opt;
              main_input_baselength
                = base_of_path (main_input_filename, &main_input_basename);
            }
@@ -798,7 +848,6 @@ decode_options (unsigned int argc, const char **argv)
       flag_tree_fre = 1;
       flag_tree_copy_prop = 1;
       flag_tree_sink = 1;
-      flag_tree_salias = 1;
       if (!no_unit_at_a_time_default)
         flag_unit_at_a_time = 1;
 
@@ -840,6 +889,8 @@ decode_options (unsigned int argc, const char **argv)
 
       if (!optimize_size)
        {
+          /* Conditional DCE generates bigger code.  */
+          flag_tree_builtin_call_dce = 1;
           /* PRE tends to generate bigger code.  */
           flag_tree_pre = 1;
        }
@@ -1169,7 +1220,24 @@ print_filtered_help (unsigned int include_flags,
     }
 
   if (! found)
-    printf (_(" No options with the desired characteristics were found\n"));
+    {
+      unsigned int langs = include_flags & CL_LANG_ALL;
+
+      if (langs == 0)
+       printf (_(" No options with the desired characteristics were found\n"));
+      else
+       {
+         unsigned int i;
+
+         /* PR 31349: Tell the user how to see all of the
+            options supported by a specific front end.  */
+         for (i = 0; (1U << i) < CL_LANG_ALL; i ++)
+           if ((1U << i) & langs)
+             printf (_(" None found.  Use --help=%s to show *all* the options supported by the %s front-end\n"),
+                     lang_names[i], lang_names[i]);
+       }
+       
+    }
   else if (! displayed)
     printf (_(" All options with the desired characteristics have already been displayed\n"));
 
@@ -1243,13 +1311,10 @@ print_specific_help (unsigned int include_flags,
          if (i >= cl_lang_count)
            break;
          if ((exclude_flags & ((1U << cl_lang_count) - 1)) != 0)
-           {
-             description = _("The following options are specific to the language ");
-             descrip_extra = lang_names [i];
-           }
+           description = _("The following options are specific to just the language ");
          else
            description = _("The following options are supported by the language ");
-           descrip_extra = lang_names [i];
+         descrip_extra = lang_names [i];
          break;
        }
     }
@@ -1289,6 +1354,7 @@ static int
 common_handle_option (size_t scode, const char *arg, int value,
                      unsigned int lang_mask)
 {
+  static bool verbose = false;
   enum opt_code code = (enum opt_code) scode;
 
   switch (code)
@@ -1297,6 +1363,10 @@ common_handle_option (size_t scode, const char *arg, int value,
       handle_param (arg);
       break;
 
+    case OPT_v:
+      verbose = true;
+      break;
+
     case OPT_fhelp:
     case OPT__help:
       {
@@ -1304,7 +1374,7 @@ common_handle_option (size_t scode, const char *arg, int value,
        unsigned int undoc_mask;
        unsigned int i;
 
-       undoc_mask = extra_warnings ? 0 : CL_UNDOCUMENTED;
+       undoc_mask = (verbose | extra_warnings) ? 0 : CL_UNDOCUMENTED;
        /* First display any single language specific options.  */
        for (i = 0; i < cl_lang_count; i++)
          print_specific_help
@@ -1366,6 +1436,7 @@ common_handle_option (size_t scode, const char *arg, int value,
            };
            unsigned int * pflags;
            char * comma;
+           unsigned int lang_flag, specific_flag;
            unsigned int len;
            unsigned int i;
 
@@ -1383,28 +1454,52 @@ common_handle_option (size_t scode, const char *arg, int value,
            else
              len = comma - a;
 
-           for (i = 0; specifics[i].string != NULL; i++)
+           /* Check to see if the string matches an option class name.  */
+           for (i = 0, specific_flag = 0; specifics[i].string != NULL; i++)
              if (strncasecmp (a, specifics[i].string, len) == 0)
                {
-                 * pflags |= specifics[i].flag;
+                 specific_flag = specifics[i].flag;
+                 break;
+               }
+           
+           /* Check to see if the string matches a language name.
+              Note - we rely upon the alpha-sorted nature of the entries in
+              the lang_names array, specifically that shorter names appear
+              before their longer variants.  (ie C before C++).  That way
+              when we are attempting to match --help=c for example we will
+              match with C first and not C++.  */
+           for (i = 0, lang_flag = 0; i < cl_lang_count; i++)
+             if (strncasecmp (a, lang_names[i], len) == 0)
+               {
+                 lang_flag = 1U << i;
                  break;
                }
 
-           if (specifics[i].string == NULL)
+           if (specific_flag != 0)
              {
-               /* Check to see if the string matches a language name.  */
-               for (i = 0; i < cl_lang_count; i++)
-                 if (strncasecmp (a, lang_names[i], len) == 0)
-                   {
-                     * pflags |= 1U << i;
-                     break;
-                   }
-
-               if (i == cl_lang_count)
-                 fnotice (stderr,
-                          "warning: unrecognized argument to --help= switch: %.*s\n",
-                          len, a);
+               if (lang_flag == 0)
+                 * pflags |= specific_flag;
+               else
+                 {
+                   /* The option's argument matches both the start of a
+                      language name and the start of an option class name.
+                      We have a special case for when the user has
+                      specified "--help=c", but otherwise we have to issue
+                      a warning.  */
+                   if (strncasecmp (a, "c", len) == 0)
+                     * pflags |= lang_flag;
+                   else
+                     fnotice (stderr,
+                              "warning: --help argument %.*s is ambiguous, please be more specific\n",
+                              len, a);
+                 }
              }
+           else if (lang_flag != 0)
+             * pflags |= lang_flag;
+           else
+             fnotice (stderr,
+                      "warning: unrecognized argument to --help= option: %.*s\n",
+                      len, a);
 
            if (comma == NULL)
              break;
@@ -1446,10 +1541,20 @@ common_handle_option (size_t scode, const char *arg, int value,
       break;
 
     case OPT_Wlarger_than_:
+      /* This form corresponds to -Wlarger-than-.  
+        Kept for backward compatibility. 
+        Don't use it as the first argument of warning().  */
+
+    case OPT_Wlarger_than_eq:
       larger_than_size = value;
       warn_larger_than = value != -1;
       break;
 
+    case OPT_Wframe_larger_than_:
+      frame_larger_than_size = value;
+      warn_frame_larger_than = value != -1;
+      break;
+
     case OPT_Wstrict_aliasing:
       set_Wstrict_aliasing (value);
       break;
@@ -1612,6 +1717,15 @@ common_handle_option (size_t scode, const char *arg, int value,
       flag_inline_functions_set = true;
       break;
 
+    case OPT_fprofile_dir_:
+      profile_data_prefix = xstrdup (arg);
+      break;
+
+    case OPT_fprofile_use_:
+      profile_data_prefix = xstrdup (arg);
+      flag_profile_use = true;
+      value = true;
+      /* No break here - do -fprofile-use processing. */
     case OPT_fprofile_use:
       if (!flag_branch_probabilities_set)
         flag_branch_probabilities = value;
@@ -1629,6 +1743,10 @@ common_handle_option (size_t scode, const char *arg, int value,
         flag_inline_functions = value;
       break;
 
+    case OPT_fprofile_generate_:
+      profile_data_prefix = xstrdup (arg);
+      value = true;
+      /* No break here - do -fprofile-generate processing. */
     case OPT_fprofile_generate:
       if (!profile_arc_flag_set)
         profile_arc_flag = value;
@@ -1781,6 +1899,7 @@ common_handle_option (size_t scode, const char *arg, int value,
     case OPT_fstrength_reduce:
     case OPT_ftree_store_copy_prop:
     case OPT_fforce_addr:
+    case OPT_ftree_salias:
       /* These are no-ops, preserved for backward compatibility.  */
       break;
 
@@ -1865,6 +1984,8 @@ set_Wstrict_aliasing (int onoff)
   gcc_assert (onoff == 0 || onoff == 1);
   if (onoff != 0)
     warn_strict_aliasing = 3;
+  else
+    warn_strict_aliasing = 0;
 }
 
 /* The following routines are useful in setting all the flags that