OSDN Git Service

* config/arm/arm.c (arm_option_optimization): Set
[pf3gnuchains/gcc-fork.git] / gcc / opts.c
1 /* Command line option handling.
2    Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
3    Free Software Foundation, Inc.
4    Contributed by Neil Booth.
5
6 This file is part of GCC.
7
8 GCC is free software; you can redistribute it and/or modify it under
9 the terms of the GNU General Public License as published by the Free
10 Software Foundation; either version 3, or (at your option) any later
11 version.
12
13 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
16 for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING3.  If not see
20 <http://www.gnu.org/licenses/>.  */
21
22 #include "config.h"
23 #include "system.h"
24 #include "intl.h"
25 #include "coretypes.h"
26 #include "tm.h"
27 #include "tree.h"
28 #include "rtl.h"
29 #include "expr.h"
30 #include "ggc.h"
31 #include "output.h"
32 #include "langhooks.h"
33 #include "opts.h"
34 #include "options.h"
35 #include "flags.h"
36 #include "toplev.h"
37 #include "params.h"
38 #include "diagnostic.h"
39 #include "opts-diagnostic.h"
40 #include "insn-attr.h"          /* For INSN_SCHEDULING.  */
41 #include "target.h"
42 #include "tree-pass.h"
43 #include "dbgcnt.h"
44 #include "debug.h"
45 #include "plugin.h"
46 #include "except.h"
47 #include "lto-streamer.h"
48
49 /* True if we should exit after parsing options.  */
50 bool exit_after_options;
51
52 /* True to warn about any objects definitions whose size is larger
53    than N bytes.  Also want about function definitions whose returned
54    values are larger than N bytes, where N is `larger_than_size'.  */
55 bool warn_larger_than;
56 HOST_WIDE_INT larger_than_size;
57
58 /* True to warn about any function whose frame size is larger
59    than N bytes. */
60 bool warn_frame_larger_than;
61 HOST_WIDE_INT frame_larger_than_size;
62
63 /* Type(s) of debugging information we are producing (if any).  See
64    flags.h for the definitions of the different possible types of
65    debugging information.  */
66 enum debug_info_type write_symbols = NO_DEBUG;
67
68 /* Level of debugging information we are producing.  See flags.h for
69    the definitions of the different possible levels.  */
70 enum debug_info_level debug_info_level = DINFO_LEVEL_NONE;
71
72 /* A major contribution to object and executable size is debug
73    information size.  A major contribution to debug information size
74    is struct descriptions replicated in several object files. The
75    following flags attempt to reduce this information.  The basic
76    idea is to not emit struct debugging information in the current
77    compilation unit when that information will be generated by
78    another compilation unit.
79
80    Debug information for a struct defined in the current source
81    file should be generated in the object file.  Likewise the
82    debug information for a struct defined in a header should be
83    generated in the object file of the corresponding source file.
84    Both of these case are handled when the base name of the file of
85    the struct definition matches the base name of the source file
86    of the current compilation unit.  This matching emits minimal
87    struct debugging information.
88
89    The base file name matching rule above will fail to emit debug
90    information for structs defined in system headers.  So a second
91    category of files includes system headers in addition to files
92    with matching bases.
93
94    The remaining types of files are library headers and application
95    headers.  We cannot currently distinguish these two types.  */
96
97 enum debug_struct_file
98 {
99   DINFO_STRUCT_FILE_NONE,   /* Debug no structs. */
100   DINFO_STRUCT_FILE_BASE,   /* Debug structs defined in files with the
101                                same base name as the compilation unit. */
102   DINFO_STRUCT_FILE_SYS,    /* Also debug structs defined in system
103                                header files.  */
104   DINFO_STRUCT_FILE_ANY     /* Debug structs defined in all files. */
105 };
106
107 /* Generic structs (e.g. templates not explicitly specialized)
108    may not have a compilation unit associated with them, and so
109    may need to be treated differently from ordinary structs.
110
111    Structs only handled by reference (indirectly), will also usually
112    not need as much debugging information.  */
113
114 static enum debug_struct_file debug_struct_ordinary[DINFO_USAGE_NUM_ENUMS]
115   = { DINFO_STRUCT_FILE_ANY, DINFO_STRUCT_FILE_ANY, DINFO_STRUCT_FILE_ANY };
116 static enum debug_struct_file debug_struct_generic[DINFO_USAGE_NUM_ENUMS]
117   = { DINFO_STRUCT_FILE_ANY, DINFO_STRUCT_FILE_ANY, DINFO_STRUCT_FILE_ANY };
118
119 /* Run the second compilation of -fcompare-debug.  Not defined using
120    Var in common.opt because this is used in Ada code and so must be
121    an actual variable not a macro.  */
122 int flag_compare_debug;
123
124 /* Parse the -femit-struct-debug-detailed option value
125    and set the flag variables. */
126
127 #define MATCH( prefix, string ) \
128   ((strncmp (prefix, string, sizeof prefix - 1) == 0) \
129    ? ((string += sizeof prefix - 1), 1) : 0)
130
131 void
132 set_struct_debug_option (const char *spec)
133 {
134   /* various labels for comparison */
135   static char dfn_lbl[] = "dfn:", dir_lbl[] = "dir:", ind_lbl[] = "ind:";
136   static char ord_lbl[] = "ord:", gen_lbl[] = "gen:";
137   static char none_lbl[] = "none", any_lbl[] = "any";
138   static char base_lbl[] = "base", sys_lbl[] = "sys";
139
140   enum debug_struct_file files = DINFO_STRUCT_FILE_ANY;
141   /* Default is to apply to as much as possible. */
142   enum debug_info_usage usage = DINFO_USAGE_NUM_ENUMS;
143   int ord = 1, gen = 1;
144
145   /* What usage? */
146   if (MATCH (dfn_lbl, spec))
147     usage = DINFO_USAGE_DFN;
148   else if (MATCH (dir_lbl, spec))
149     usage = DINFO_USAGE_DIR_USE;
150   else if (MATCH (ind_lbl, spec))
151     usage = DINFO_USAGE_IND_USE;
152
153   /* Generics or not? */
154   if (MATCH (ord_lbl, spec))
155     gen = 0;
156   else if (MATCH (gen_lbl, spec))
157     ord = 0;
158
159   /* What allowable environment? */
160   if (MATCH (none_lbl, spec))
161     files = DINFO_STRUCT_FILE_NONE;
162   else if (MATCH (any_lbl, spec))
163     files = DINFO_STRUCT_FILE_ANY;
164   else if (MATCH (sys_lbl, spec))
165     files = DINFO_STRUCT_FILE_SYS;
166   else if (MATCH (base_lbl, spec))
167     files = DINFO_STRUCT_FILE_BASE;
168   else
169     error ("argument %qs to %<-femit-struct-debug-detailed%> not recognized",
170            spec);
171
172   /* Effect the specification. */
173   if (usage == DINFO_USAGE_NUM_ENUMS)
174     {
175       if (ord)
176         {
177           debug_struct_ordinary[DINFO_USAGE_DFN] = files;
178           debug_struct_ordinary[DINFO_USAGE_DIR_USE] = files;
179           debug_struct_ordinary[DINFO_USAGE_IND_USE] = files;
180         }
181       if (gen)
182         {
183           debug_struct_generic[DINFO_USAGE_DFN] = files;
184           debug_struct_generic[DINFO_USAGE_DIR_USE] = files;
185           debug_struct_generic[DINFO_USAGE_IND_USE] = files;
186         }
187     }
188   else
189     {
190       if (ord)
191         debug_struct_ordinary[usage] = files;
192       if (gen)
193         debug_struct_generic[usage] = files;
194     }
195
196   if (*spec == ',')
197     set_struct_debug_option (spec+1);
198   else
199     {
200       /* No more -femit-struct-debug-detailed specifications.
201          Do final checks. */
202       if (*spec != '\0')
203         error ("argument %qs to %<-femit-struct-debug-detailed%> unknown",
204                spec);
205       if (debug_struct_ordinary[DINFO_USAGE_DIR_USE]
206                 < debug_struct_ordinary[DINFO_USAGE_IND_USE]
207           || debug_struct_generic[DINFO_USAGE_DIR_USE]
208                 < debug_struct_generic[DINFO_USAGE_IND_USE])
209         error ("%<-femit-struct-debug-detailed=dir:...%> must allow at least"
210                " as much as %<-femit-struct-debug-detailed=ind:...%>");
211     }
212 }
213
214 /* Find the base name of a path, stripping off both directories and
215    a single final extension. */
216 static int
217 base_of_path (const char *path, const char **base_out)
218 {
219   const char *base = path;
220   const char *dot = 0;
221   const char *p = path;
222   char c = *p;
223   while (c)
224     {
225       if (IS_DIR_SEPARATOR(c))
226         {
227           base = p + 1;
228           dot = 0;
229         }
230       else if (c == '.')
231         dot = p;
232       c = *++p;
233     }
234   if (!dot)
235     dot = p;
236   *base_out = base;
237   return dot - base;
238 }
239
240 /* Match the base name of a file to the base name of a compilation unit. */
241
242 static const char *main_input_basename;
243 static int main_input_baselength;
244
245 static int
246 matches_main_base (const char *path)
247 {
248   /* Cache the last query. */
249   static const char *last_path = NULL;
250   static int last_match = 0;
251   if (path != last_path)
252     {
253       const char *base;
254       int length = base_of_path (path, &base);
255       last_path = path;
256       last_match = (length == main_input_baselength
257                     && memcmp (base, main_input_basename, length) == 0);
258     }
259   return last_match;
260 }
261
262 #ifdef DEBUG_DEBUG_STRUCT
263
264 static int
265 dump_struct_debug (tree type, enum debug_info_usage usage,
266                    enum debug_struct_file criterion, int generic,
267                    int matches, int result)
268 {
269   /* Find the type name. */
270   tree type_decl = TYPE_STUB_DECL (type);
271   tree t = type_decl;
272   const char *name = 0;
273   if (TREE_CODE (t) == TYPE_DECL)
274     t = DECL_NAME (t);
275   if (t)
276     name = IDENTIFIER_POINTER (t);
277
278   fprintf (stderr, "    struct %d %s %s %s %s %d %p %s\n",
279            criterion,
280            DECL_IN_SYSTEM_HEADER (type_decl) ? "sys" : "usr",
281            matches ? "bas" : "hdr",
282            generic ? "gen" : "ord",
283            usage == DINFO_USAGE_DFN ? ";" :
284              usage == DINFO_USAGE_DIR_USE ? "." : "*",
285            result,
286            (void*) type_decl, name);
287   return result;
288 }
289 #define DUMP_GSTRUCT(type, usage, criterion, generic, matches, result) \
290   dump_struct_debug (type, usage, criterion, generic, matches, result)
291
292 #else
293
294 #define DUMP_GSTRUCT(type, usage, criterion, generic, matches, result) \
295   (result)
296
297 #endif
298
299
300 bool
301 should_emit_struct_debug (tree type, enum debug_info_usage usage)
302 {
303   enum debug_struct_file criterion;
304   tree type_decl;
305   bool generic = lang_hooks.types.generic_p (type);
306
307   if (generic)
308     criterion = debug_struct_generic[usage];
309   else
310     criterion = debug_struct_ordinary[usage];
311
312   if (criterion == DINFO_STRUCT_FILE_NONE)
313     return DUMP_GSTRUCT (type, usage, criterion, generic, false, false);
314   if (criterion == DINFO_STRUCT_FILE_ANY)
315     return DUMP_GSTRUCT (type, usage, criterion, generic, false, true);
316
317   type_decl = TYPE_STUB_DECL (type);
318
319   if (criterion == DINFO_STRUCT_FILE_SYS && DECL_IN_SYSTEM_HEADER (type_decl))
320     return DUMP_GSTRUCT (type, usage, criterion, generic, false, true);
321
322   if (matches_main_base (DECL_SOURCE_FILE (type_decl)))
323     return DUMP_GSTRUCT (type, usage, criterion, generic, true, true);
324   return DUMP_GSTRUCT (type, usage, criterion, generic, false, false);
325 }
326
327 /* Nonzero means use GNU-only extensions in the generated symbolic
328    debugging information.  Currently, this only has an effect when
329    write_symbols is set to DBX_DEBUG, XCOFF_DEBUG, or DWARF_DEBUG.  */
330 bool use_gnu_debug_info_extensions;
331
332 /* The default visibility for all symbols (unless overridden) */
333 enum symbol_visibility default_visibility = VISIBILITY_DEFAULT;
334
335 /* Global visibility options.  */
336 struct visibility_flags visibility_options;
337
338 /* What to print when a switch has no documentation.  */
339 static const char undocumented_msg[] = N_("This switch lacks documentation");
340
341 /* Functions excluded from profiling.  */
342
343 typedef char *char_p; /* For DEF_VEC_P.  */
344 DEF_VEC_P(char_p);
345 DEF_VEC_ALLOC_P(char_p,heap);
346
347 static VEC(char_p,heap) *flag_instrument_functions_exclude_functions;
348 static VEC(char_p,heap) *flag_instrument_functions_exclude_files;
349
350 typedef const char *const_char_p; /* For DEF_VEC_P.  */
351 DEF_VEC_P(const_char_p);
352 DEF_VEC_ALLOC_P(const_char_p,heap);
353
354 static VEC(const_char_p,heap) *ignored_options;
355
356 /* Input file names.  */
357 const char **in_fnames;
358 unsigned num_in_fnames;
359
360 static bool common_handle_option (struct gcc_options *opts,
361                                   struct gcc_options *opts_set,
362                                   const struct cl_decoded_option *decoded,
363                                   unsigned int lang_mask, int kind,
364                                   const struct cl_option_handlers *handlers);
365 static void handle_param (struct gcc_options *opts,
366                           struct gcc_options *opts_set, const char *carg);
367 static char *write_langs (unsigned int lang_mask);
368 static void complain_wrong_lang (const struct cl_decoded_option *,
369                                  unsigned int lang_mask);
370 static void set_debug_level (enum debug_info_type type, int extended,
371                              const char *arg);
372
373 /* Return a malloced slash-separated list of languages in MASK.  */
374 static char *
375 write_langs (unsigned int mask)
376 {
377   unsigned int n = 0, len = 0;
378   const char *lang_name;
379   char *result;
380
381   for (n = 0; (lang_name = lang_names[n]) != 0; n++)
382     if (mask & (1U << n))
383       len += strlen (lang_name) + 1;
384
385   result = XNEWVEC (char, len);
386   len = 0;
387   for (n = 0; (lang_name = lang_names[n]) != 0; n++)
388     if (mask & (1U << n))
389       {
390         if (len)
391           result[len++] = '/';
392         strcpy (result + len, lang_name);
393         len += strlen (lang_name);
394       }
395
396   result[len] = 0;
397
398   return result;
399 }
400
401 /* Complain that switch DECODED does not apply to this front end (mask
402    LANG_MASK).  */
403 static void
404 complain_wrong_lang (const struct cl_decoded_option *decoded,
405                      unsigned int lang_mask)
406 {
407   const struct cl_option *option = &cl_options[decoded->opt_index];
408   const char *text = decoded->orig_option_with_args_text;
409   char *ok_langs = NULL, *bad_lang = NULL;
410   unsigned int opt_flags = option->flags;
411
412   if (!lang_hooks.complain_wrong_lang_p (option))
413     return;
414
415   opt_flags &= ((1U << cl_lang_count) - 1) | CL_DRIVER;
416   if (opt_flags != CL_DRIVER)
417     ok_langs = write_langs (opt_flags);
418   if (lang_mask != CL_DRIVER)
419     bad_lang = write_langs (lang_mask);
420
421   if (opt_flags == CL_DRIVER)
422     error ("command line option %qs is valid for the driver but not for %s",
423            text, bad_lang);
424   else if (lang_mask == CL_DRIVER)
425     gcc_unreachable ();
426   else
427     /* Eventually this should become a hard error IMO.  */
428     warning (0, "command line option %qs is valid for %s but not for %s",
429              text, ok_langs, bad_lang);
430
431   free (ok_langs);
432   free (bad_lang);
433 }
434
435 /* Buffer the unknown option described by the string OPT.  Currently,
436    we only complain about unknown -Wno-* options if they may have
437    prevented a diagnostic. Otherwise, we just ignore them.
438    Note that if we do complain, it is only as a warning, not an error;
439    passing the compiler an unrecognised -Wno-* option should never
440    change whether the compilation succeeds or fails.  */
441
442 static void postpone_unknown_option_warning(const char *opt)
443 {
444   VEC_safe_push (const_char_p, heap, ignored_options, opt);
445 }
446
447 /* Produce a warning for each option previously buffered.  */
448
449 void print_ignored_options (void)
450 {
451   location_t saved_loc = input_location;
452
453   input_location = 0;
454
455   while (!VEC_empty (const_char_p, ignored_options))
456     {
457       const char *opt;
458       opt = VEC_pop (const_char_p, ignored_options);
459       warning (0, "unrecognized command line option \"%s\"", opt);
460     }
461
462   input_location = saved_loc;
463 }
464
465 /* Handle an unknown option DECODED, returning true if an error should be
466    given.  */
467
468 static bool
469 unknown_option_callback (const struct cl_decoded_option *decoded)
470 {
471   const char *opt = decoded->arg;
472
473   if (opt[1] == 'W' && opt[2] == 'n' && opt[3] == 'o' && opt[4] == '-'
474       && !(decoded->errors & CL_ERR_NEGATIVE))
475     {
476       /* We don't generate warnings for unknown -Wno-* options unless
477          we issue diagnostics.  */
478       postpone_unknown_option_warning (opt);
479       return false;
480     }
481   else
482     return true;
483 }
484
485 /* Note that an option DECODED has been successfully handled with a
486    handler for mask MASK.  */
487
488 static void
489 post_handling_callback (const struct cl_decoded_option *decoded ATTRIBUTE_UNUSED,
490                         unsigned int mask ATTRIBUTE_UNUSED)
491 {
492 #ifdef ENABLE_LTO
493   lto_register_user_option (decoded->opt_index, decoded->arg,
494                             decoded->value, mask);
495 #endif
496 }
497
498 /* Handle a front-end option; arguments and return value as for
499    handle_option.  */
500
501 static bool
502 lang_handle_option (struct gcc_options *opts,
503                     struct gcc_options *opts_set,
504                     const struct cl_decoded_option *decoded,
505                     unsigned int lang_mask ATTRIBUTE_UNUSED, int kind,
506                     const struct cl_option_handlers *handlers)
507 {
508   gcc_assert (opts == &global_options);
509   gcc_assert (opts_set == &global_options_set);
510   gcc_assert (decoded->canonical_option_num_elements <= 2);
511   return lang_hooks.handle_option (decoded->opt_index, decoded->arg,
512                                    decoded->value, kind, handlers);
513 }
514
515 /* Handle a back-end option; arguments and return value as for
516    handle_option.  */
517
518 static bool
519 target_handle_option (struct gcc_options *opts,
520                       struct gcc_options *opts_set,
521                       const struct cl_decoded_option *decoded,
522                       unsigned int lang_mask ATTRIBUTE_UNUSED, int kind,
523                       const struct cl_option_handlers *handlers ATTRIBUTE_UNUSED)
524 {
525   gcc_assert (opts == &global_options);
526   gcc_assert (opts_set == &global_options_set);
527   gcc_assert (decoded->canonical_option_num_elements <= 2);
528   gcc_assert (kind == DK_UNSPECIFIED);
529   return targetm.handle_option (decoded->opt_index, decoded->arg,
530                                 decoded->value);
531 }
532
533 /* Handle FILENAME from the command line.  */
534 static void
535 add_input_filename (const char *filename)
536 {
537   num_in_fnames++;
538   in_fnames = XRESIZEVEC (const char *, in_fnames, num_in_fnames);
539   in_fnames[num_in_fnames - 1] = filename;
540 }
541
542 /* Add comma-separated strings to a char_p vector.  */
543
544 static void
545 add_comma_separated_to_vector (VEC(char_p,heap) **pvec, const char* arg)
546 {
547   char *tmp;
548   char *r;
549   char *w;
550   char *token_start;
551
552   /* We never free this string.  */
553   tmp = xstrdup (arg);
554
555   r = tmp;
556   w = tmp;
557   token_start = tmp;
558
559   while (*r != '\0')
560     {
561       if (*r == ',')
562         {
563           *w++ = '\0';
564           ++r;
565           VEC_safe_push (char_p, heap, *pvec, token_start);
566           token_start = w;
567         }
568       if (*r == '\\' && r[1] == ',')
569         {
570           *w++ = ',';
571           r += 2;
572         }
573       else
574         *w++ = *r++;
575     }
576   if (*token_start != '\0')
577     VEC_safe_push (char_p, heap, *pvec, token_start);
578 }
579
580 /* Return whether we should exclude FNDECL from instrumentation.  */
581
582 bool
583 flag_instrument_functions_exclude_p (tree fndecl)
584 {
585   if (VEC_length (char_p, flag_instrument_functions_exclude_functions) > 0)
586     {
587       const char *name;
588       int i;
589       char *s;
590
591       name = lang_hooks.decl_printable_name (fndecl, 0);
592       FOR_EACH_VEC_ELT (char_p, flag_instrument_functions_exclude_functions,
593                         i, s)
594         if (strstr (name, s) != NULL)
595           return true;
596     }
597
598   if (VEC_length (char_p, flag_instrument_functions_exclude_files) > 0)
599     {
600       const char *name;
601       int i;
602       char *s;
603
604       name = DECL_SOURCE_FILE (fndecl);
605       FOR_EACH_VEC_ELT (char_p, flag_instrument_functions_exclude_files, i, s)
606         if (strstr (name, s) != NULL)
607           return true;
608     }
609
610   return false;
611 }
612
613
614 /* Handle the vector of command line options, storing the results of
615    processing DECODED_OPTIONS and DECODED_OPTIONS_COUNT in OPTS and
616    OPTS_SET.  LANG_MASK contains has a single bit set representing the
617    current language.  HANDLERS describes what functions to call for
618    the options.  */
619 static void
620 read_cmdline_options (struct gcc_options *opts, struct gcc_options *opts_set,
621                       struct cl_decoded_option *decoded_options,
622                       unsigned int decoded_options_count,
623                       unsigned int lang_mask,
624                       const struct cl_option_handlers *handlers)
625 {
626   unsigned int i;
627
628   for (i = 1; i < decoded_options_count; i++)
629     {
630       if (decoded_options[i].opt_index == OPT_SPECIAL_input_file)
631         {
632           /* Input files should only ever appear on the main command
633              line.  */
634           gcc_assert (opts == &global_options);
635           gcc_assert (opts_set == &global_options_set);
636
637           if (main_input_filename == NULL)
638             {
639               main_input_filename = decoded_options[i].arg;
640               main_input_baselength
641                 = base_of_path (main_input_filename, &main_input_basename);
642             }
643           add_input_filename (decoded_options[i].arg);
644           continue;
645         }
646
647       read_cmdline_option (opts, opts_set,
648                            decoded_options + i, lang_mask, handlers,
649                            global_dc);
650     }
651 }
652
653 /* Language mask determined at initialization.  */
654 static unsigned int initial_lang_mask;
655
656 /* Initialize global options-related settings at start-up.  */
657
658 void
659 init_options_once (void)
660 {
661   /* Perform language-specific options initialization.  */
662   initial_lang_mask = lang_hooks.option_lang_mask ();
663
664   lang_hooks.initialize_diagnostics (global_dc);
665 }
666
667 /* Initialize OPTS and OPTS_SET before using them in parsing options.  */
668
669 void
670 init_options_struct (struct gcc_options *opts, struct gcc_options *opts_set)
671 {
672   size_t num_params = get_num_compiler_params ();
673
674   *opts = global_options_init;
675   memset (opts_set, 0, sizeof (*opts_set));
676
677   opts->x_param_values = XNEWVEC (int, num_params);
678   opts_set->x_param_values = XCNEWVEC (int, num_params);
679   init_param_values (opts->x_param_values);
680
681   /* Use priority coloring if cover classes is not defined for the
682      target.  */
683   if (targetm.ira_cover_classes == NULL)
684     opts->x_flag_ira_algorithm = IRA_ALGORITHM_PRIORITY;
685
686   /* Initialize whether `char' is signed.  */
687   opts->x_flag_signed_char = DEFAULT_SIGNED_CHAR;
688   /* Set this to a special "uninitialized" value.  The actual default
689      is set after target options have been processed.  */
690   opts->x_flag_short_enums = 2;
691
692   /* Initialize target_flags before targetm.target_option.optimization
693      so the latter can modify it.  */
694   opts->x_target_flags = targetm.default_target_flags;
695
696   /* Some targets have ABI-specified unwind tables.  */
697   opts->x_flag_unwind_tables = targetm.unwind_tables_default;
698
699   /* Some targets have other target-specific initialization.  */
700   targetm.target_option.init_struct (opts);
701 }
702
703 /* Decode command-line options to an array, like
704    decode_cmdline_options_to_array and with the same arguments but
705    using the default lang_mask.  */
706
707 void
708 decode_cmdline_options_to_array_default_mask (unsigned int argc,
709                                               const char **argv, 
710                                               struct cl_decoded_option **decoded_options,
711                                               unsigned int *decoded_options_count)
712 {
713   decode_cmdline_options_to_array (argc, argv,
714                                    initial_lang_mask | CL_COMMON | CL_TARGET,
715                                    decoded_options, decoded_options_count);
716 }
717
718 /* Default the options in OPTS and OPTS_SET based on the optimization
719    settings in DECODED_OPTIONS and DECODED_OPTIONS_COUNT.  */
720 static void
721 default_options_optimization (struct gcc_options *opts,
722                               struct gcc_options *opts_set,
723                               struct cl_decoded_option *decoded_options,
724                               unsigned int decoded_options_count)
725 {
726   unsigned int i;
727   int opt1;
728   int opt2;
729   int opt3;
730   int opt1_max;
731   int ofast = 0;
732
733   gcc_assert (opts == &global_options);
734   gcc_assert (opts_set = &global_options_set);
735
736   /* Scan to see what optimization level has been specified.  That will
737      determine the default value of many flags.  */
738   for (i = 1; i < decoded_options_count; i++)
739     {
740       struct cl_decoded_option *opt = &decoded_options[i];
741       switch (opt->opt_index)
742         {
743         case OPT_O:
744           if (*opt->arg == '\0')
745             {
746               optimize = 1;
747               optimize_size = 0;
748               ofast = 0;
749             }
750           else
751             {
752               const int optimize_val = integral_argument (opt->arg);
753               if (optimize_val == -1)
754                 error ("argument to %qs should be a non-negative integer",
755                        "-O");
756               else
757                 {
758                   optimize = optimize_val;
759                   if ((unsigned int) optimize > 255)
760                     optimize = 255;
761                   optimize_size = 0;
762                   ofast = 0;
763                 }
764             }
765           break;
766
767         case OPT_Os:
768           optimize_size = 1;
769
770           /* Optimizing for size forces optimize to be 2.  */
771           optimize = 2;
772           ofast = 0;
773           break;
774
775         case OPT_Ofast:
776           /* -Ofast only adds flags to -O3.  */
777           optimize_size = 0;
778           optimize = 3;
779           ofast = 1;
780           break;
781
782         default:
783           /* Ignore other options in this prescan.  */
784           break;
785         }
786     }
787
788   /* -O1 optimizations.  */
789   opt1 = (optimize >= 1);
790   flag_defer_pop = opt1;
791 #ifdef DELAY_SLOTS
792   flag_delayed_branch = opt1;
793 #endif
794 #ifdef CAN_DEBUG_WITHOUT_FP
795   flag_omit_frame_pointer = opt1;
796 #endif
797   flag_guess_branch_prob = opt1;
798   flag_cprop_registers = opt1;
799   flag_forward_propagate = opt1;
800   flag_if_conversion = opt1;
801   flag_if_conversion2 = opt1;
802   flag_ipa_pure_const = opt1;
803   flag_ipa_reference = opt1;
804   flag_ipa_profile = opt1;
805   flag_merge_constants = opt1;
806   flag_split_wide_types = opt1;
807   flag_tree_ccp = opt1;
808   flag_tree_bit_ccp = opt1;
809   flag_tree_dce = opt1;
810   flag_tree_dom = opt1;
811   flag_tree_dse = opt1;
812   flag_tree_ter = opt1;
813   flag_tree_sra = opt1;
814   flag_tree_copyrename = opt1;
815   flag_tree_fre = opt1;
816   flag_tree_copy_prop = opt1;
817   flag_tree_sink = opt1;
818   flag_tree_ch = opt1;
819   flag_combine_stack_adjustments = opt1;
820
821   /* -O2 optimizations.  */
822   opt2 = (optimize >= 2);
823   flag_inline_small_functions = opt2;
824   flag_indirect_inlining = opt2;
825   flag_partial_inlining = opt2;
826   flag_thread_jumps = opt2;
827   flag_crossjumping = opt2;
828   flag_optimize_sibling_calls = opt2;
829   flag_cse_follow_jumps = opt2;
830   flag_gcse = opt2;
831   flag_expensive_optimizations = opt2;
832   flag_rerun_cse_after_loop = opt2;
833   flag_caller_saves = opt2;
834   flag_peephole2 = opt2;
835 #ifdef INSN_SCHEDULING
836   /* Only run the pre-regalloc scheduling pass if optimizing for speed.  */
837   flag_schedule_insns = opt2 && ! optimize_size;
838   flag_schedule_insns_after_reload = opt2;
839 #endif
840   flag_regmove = opt2;
841   flag_strict_aliasing = opt2;
842   flag_strict_overflow = opt2;
843   flag_reorder_blocks = opt2;
844   flag_reorder_functions = opt2;
845   flag_tree_vrp = opt2;
846   flag_tree_builtin_call_dce = opt2;
847   flag_tree_pre = opt2;
848   flag_tree_switch_conversion = opt2;
849   flag_ipa_cp = opt2;
850   flag_ipa_sra = opt2;
851
852   /* Track fields in field-sensitive alias analysis.  */
853   maybe_set_param_value
854     (PARAM_MAX_FIELDS_FOR_FIELD_SENSITIVE,
855      opt2 ? 100 : default_param_value (PARAM_MAX_FIELDS_FOR_FIELD_SENSITIVE),
856      opts->x_param_values, opts_set->x_param_values);
857
858   /* For -O1 only do loop invariant motion for very small loops.  */
859   maybe_set_param_value
860     (PARAM_LOOP_INVARIANT_MAX_BBS_IN_LOOP,
861      opt2 ? default_param_value (PARAM_LOOP_INVARIANT_MAX_BBS_IN_LOOP) : 1000,
862      opts->x_param_values, opts_set->x_param_values);
863
864   /* -O3 optimizations.  */
865   opt3 = (optimize >= 3);
866   flag_tree_loop_distribute_patterns = opt3;
867   flag_predictive_commoning = opt3;
868   flag_inline_functions = opt3;
869   flag_unswitch_loops = opt3;
870   flag_gcse_after_reload = opt3;
871   flag_tree_vectorize = opt3;
872   flag_ipa_cp_clone = opt3;
873   if (flag_ipa_cp_clone)
874     flag_ipa_cp = 1;
875
876   /* Just -O1/-O0 optimizations.  */
877   opt1_max = (optimize <= 1);
878   align_loops = opt1_max;
879   align_jumps = opt1_max;
880   align_labels = opt1_max;
881   align_functions = opt1_max;
882
883   if (optimize_size)
884     {
885       /* Inlining of functions reducing size is a good idea regardless of them
886          being declared inline.  */
887       flag_inline_functions = 1;
888
889       /* Basic optimization options.  */
890       optimize_size = 1;
891       if (optimize > 2)
892         optimize = 2;
893
894       /* We want to crossjump as much as possible.  */
895       maybe_set_param_value (PARAM_MIN_CROSSJUMP_INSNS, 1,
896                              opts->x_param_values, opts_set->x_param_values);
897     }
898   else
899     maybe_set_param_value (PARAM_MIN_CROSSJUMP_INSNS,
900                            default_param_value (PARAM_MIN_CROSSJUMP_INSNS),
901                            opts->x_param_values, opts_set->x_param_values);
902
903   /* -Ofast adds optimizations to -O3.  */
904   if (ofast)
905     {
906       /* Which is -ffast-math for now.  */
907       set_fast_math_flags (1);
908       /* Allow targets to enable extra options with -Ofast
909          before general options processing so disabling them
910          again afterwards works.  */
911       targetm.handle_ofast ();
912     }
913
914   /* Allow default optimizations to be specified on a per-machine basis.  */
915   targetm.target_option.optimization (optimize, optimize_size);
916 }
917
918 static void finish_options (struct gcc_options *, struct gcc_options *);
919
920 /* Parse command line options and set default flag values.  Do minimal
921    options processing.  The decoded options are in *DECODED_OPTIONS
922    and *DECODED_OPTIONS_COUNT.  */
923 void
924 decode_options (struct gcc_options *opts, struct gcc_options *opts_set,
925                 struct cl_decoded_option *decoded_options,
926                 unsigned int decoded_options_count)
927 {
928   struct cl_option_handlers handlers;
929
930   unsigned int lang_mask;
931
932   lang_mask = initial_lang_mask;
933
934   handlers.unknown_option_callback = unknown_option_callback;
935   handlers.wrong_lang_callback = complain_wrong_lang;
936   handlers.post_handling_callback = post_handling_callback;
937   handlers.num_handlers = 3;
938   handlers.handlers[0].handler = lang_handle_option;
939   handlers.handlers[0].mask = lang_mask;
940   handlers.handlers[1].handler = common_handle_option;
941   handlers.handlers[1].mask = CL_COMMON;
942   handlers.handlers[2].handler = target_handle_option;
943   handlers.handlers[2].mask = CL_TARGET;
944
945   /* Enable -Werror=coverage-mismatch by default */
946   enable_warning_as_error ("coverage-mismatch", 1, lang_mask, &handlers,
947                            global_dc);
948
949   default_options_optimization (opts, opts_set,
950                                 decoded_options, decoded_options_count);
951
952 #ifdef ENABLE_LTO
953   /* Clear any options currently held for LTO.  */
954   lto_clear_user_options ();
955 #endif
956
957   read_cmdline_options (opts, opts_set,
958                         decoded_options, decoded_options_count, lang_mask,
959                         &handlers);
960
961   finish_options (opts, opts_set);
962 }
963
964 /* After all options have been read into OPTS and OPTS_SET, finalize
965    settings of those options and diagnose incompatible
966    combinations.  */
967 static void
968 finish_options (struct gcc_options *opts, struct gcc_options *opts_set)
969 {
970   static bool first_time_p = true;
971   enum unwind_info_type ui_except;
972
973   gcc_assert (opts == &global_options);
974   gcc_assert (opts_set = &global_options_set);
975
976   if (dump_base_name && ! IS_ABSOLUTE_PATH (dump_base_name))
977     {
978       /* First try to make DUMP_BASE_NAME relative to the DUMP_DIR_NAME
979          directory.  Then try to make DUMP_BASE_NAME relative to the
980          AUX_BASE_NAME directory, typically the directory to contain
981          the object file.  */
982       if (dump_dir_name)
983         dump_base_name = concat (dump_dir_name, dump_base_name, NULL);
984       else if (aux_base_name)
985         {
986           const char *aux_base;
987
988           base_of_path (aux_base_name, &aux_base);
989           if (aux_base_name != aux_base)
990             {
991               int dir_len = aux_base - aux_base_name;
992               char *new_dump_base_name =
993                 XNEWVEC (char, strlen(dump_base_name) + dir_len + 1);
994
995               /* Copy directory component from AUX_BASE_NAME.  */
996               memcpy (new_dump_base_name, aux_base_name, dir_len);
997               /* Append existing DUMP_BASE_NAME.  */
998               strcpy (new_dump_base_name + dir_len, dump_base_name);
999               dump_base_name = new_dump_base_name;
1000             }
1001         }
1002     }
1003
1004   /* Handle related options for unit-at-a-time, toplevel-reorder, and
1005      section-anchors.  */
1006   if (!flag_unit_at_a_time)
1007     {
1008       if (flag_section_anchors && opts_set->x_flag_section_anchors)
1009         error ("Section anchors must be disabled when unit-at-a-time "
1010                "is disabled.");
1011       flag_section_anchors = 0;
1012       if (flag_toplevel_reorder == 1)
1013         error ("Toplevel reorder must be disabled when unit-at-a-time "
1014                "is disabled.");
1015       flag_toplevel_reorder = 0;
1016     }
1017
1018   /* -Wmissing-noreturn is alias for -Wsuggest-attribute=noreturn.  */
1019   if (warn_missing_noreturn)
1020     warn_suggest_attribute_noreturn = true;
1021     
1022   /* Unless the user has asked for section anchors, we disable toplevel
1023      reordering at -O0 to disable transformations that might be surprising
1024      to end users and to get -fno-toplevel-reorder tested.  */
1025   if (!optimize
1026       && flag_toplevel_reorder == 2
1027       && !(flag_section_anchors && opts_set->x_flag_section_anchors))
1028     {
1029       flag_toplevel_reorder = 0;
1030       flag_section_anchors = 0;
1031     }
1032   if (!flag_toplevel_reorder)
1033     {
1034       if (flag_section_anchors && opts_set->x_flag_section_anchors)
1035         error ("section anchors must be disabled when toplevel reorder"
1036                " is disabled");
1037       flag_section_anchors = 0;
1038     }
1039
1040   if (first_time_p)
1041     {
1042       if (flag_pie)
1043         flag_pic = flag_pie;
1044       if (flag_pic && !flag_pie)
1045         flag_shlib = 1;
1046       first_time_p = false;
1047     }
1048
1049   if (optimize == 0)
1050     {
1051       /* Inlining does not work if not optimizing,
1052          so force it not to be done.  */
1053       warn_inline = 0;
1054       flag_no_inline = 1;
1055     }
1056
1057   /* The optimization to partition hot and cold basic blocks into separate
1058      sections of the .o and executable files does not work (currently)
1059      with exception handling.  This is because there is no support for
1060      generating unwind info.  If flag_exceptions is turned on we need to
1061      turn off the partitioning optimization.  */
1062
1063   ui_except = targetm.except_unwind_info ();
1064
1065   if (flag_exceptions
1066       && flag_reorder_blocks_and_partition
1067       && (ui_except == UI_SJLJ || ui_except == UI_TARGET))
1068     {
1069       inform (input_location,
1070               "-freorder-blocks-and-partition does not work "
1071               "with exceptions on this architecture");
1072       flag_reorder_blocks_and_partition = 0;
1073       flag_reorder_blocks = 1;
1074     }
1075
1076   /* If user requested unwind info, then turn off the partitioning
1077      optimization.  */
1078
1079   if (flag_unwind_tables
1080       && !targetm.unwind_tables_default
1081       && flag_reorder_blocks_and_partition
1082       && (ui_except == UI_SJLJ || ui_except == UI_TARGET))
1083     {
1084       inform (input_location,
1085               "-freorder-blocks-and-partition does not support "
1086               "unwind info on this architecture");
1087       flag_reorder_blocks_and_partition = 0;
1088       flag_reorder_blocks = 1;
1089     }
1090
1091   /* If the target requested unwind info, then turn off the partitioning
1092      optimization with a different message.  Likewise, if the target does not
1093      support named sections.  */
1094
1095   if (flag_reorder_blocks_and_partition
1096       && (!targetm.have_named_sections
1097           || (flag_unwind_tables
1098               && targetm.unwind_tables_default
1099               && (ui_except == UI_SJLJ || ui_except == UI_TARGET))))
1100     {
1101       inform (input_location,
1102               "-freorder-blocks-and-partition does not work "
1103               "on this architecture");
1104       flag_reorder_blocks_and_partition = 0;
1105       flag_reorder_blocks = 1;
1106     }
1107
1108   /* Pipelining of outer loops is only possible when general pipelining
1109      capabilities are requested.  */
1110   if (!flag_sel_sched_pipelining)
1111     flag_sel_sched_pipelining_outer_loops = 0;
1112
1113   if (!targetm.ira_cover_classes
1114       && flag_ira_algorithm == IRA_ALGORITHM_CB)
1115     {
1116       inform (input_location,
1117               "-fira-algorithm=CB does not work on this architecture");
1118       flag_ira_algorithm = IRA_ALGORITHM_PRIORITY;
1119     }
1120
1121   if (flag_conserve_stack)
1122     {
1123       maybe_set_param_value (PARAM_LARGE_STACK_FRAME, 100,
1124                              opts->x_param_values, opts_set->x_param_values);
1125       maybe_set_param_value (PARAM_STACK_FRAME_GROWTH, 40,
1126                              opts->x_param_values, opts_set->x_param_values);
1127     }
1128   if (flag_wpa || flag_ltrans)
1129     {
1130       /* These passes are not WHOPR compatible yet.  */
1131       flag_ipa_pta = 0;
1132       flag_ipa_struct_reorg = 0;
1133     }
1134
1135   if (flag_lto || flag_whopr)
1136     {
1137 #ifdef ENABLE_LTO
1138       flag_generate_lto = 1;
1139
1140       /* When generating IL, do not operate in whole-program mode.
1141          Otherwise, symbols will be privatized too early, causing link
1142          errors later.  */
1143       flag_whole_program = 0;
1144 #else
1145       error ("LTO support has not been enabled in this configuration");
1146 #endif
1147     }
1148   if (flag_lto_partition_balanced || flag_lto_partition_1to1)
1149     {
1150       if (flag_lto_partition_balanced && flag_lto_partition_1to1)
1151         error ("Only one -flto-partitoin value can be specified");
1152       if (!flag_whopr)
1153         error ("-flto-partitoin has effect only with -fwhopr");
1154     }
1155
1156   /* Reconcile -flto and -fwhopr.  Set additional flags as appropriate and
1157      check option consistency.  */
1158   if (flag_lto && flag_whopr)
1159     error ("-flto and -fwhopr are mutually exclusive");
1160
1161   /* We initialize flag_split_stack to -1 so that targets can set a
1162      default value if they choose based on other options.  */
1163   if (flag_split_stack == -1)
1164     flag_split_stack = 0;
1165   else if (flag_split_stack)
1166     {
1167       if (!targetm.supports_split_stack (true))
1168         {
1169           error ("%<-fsplit-stack%> is not supported by "
1170                  "this compiler configuration");
1171           flag_split_stack = 0;
1172         }
1173     }
1174 }
1175
1176 #define LEFT_COLUMN     27
1177
1178 /* Output ITEM, of length ITEM_WIDTH, in the left column,
1179    followed by word-wrapped HELP in a second column.  */
1180 static void
1181 wrap_help (const char *help,
1182            const char *item,
1183            unsigned int item_width,
1184            unsigned int columns)
1185 {
1186   unsigned int col_width = LEFT_COLUMN;
1187   unsigned int remaining, room, len;
1188
1189   remaining = strlen (help);
1190
1191   do
1192     {
1193       room = columns - 3 - MAX (col_width, item_width);
1194       if (room > columns)
1195         room = 0;
1196       len = remaining;
1197
1198       if (room < len)
1199         {
1200           unsigned int i;
1201
1202           for (i = 0; help[i]; i++)
1203             {
1204               if (i >= room && len != remaining)
1205                 break;
1206               if (help[i] == ' ')
1207                 len = i;
1208               else if ((help[i] == '-' || help[i] == '/')
1209                        && help[i + 1] != ' '
1210                        && i > 0 && ISALPHA (help[i - 1]))
1211                 len = i + 1;
1212             }
1213         }
1214
1215       printf( "  %-*.*s %.*s\n", col_width, item_width, item, len, help);
1216       item_width = 0;
1217       while (help[len] == ' ')
1218         len++;
1219       help += len;
1220       remaining -= len;
1221     }
1222   while (remaining);
1223 }
1224
1225 /* Print help for a specific front-end, etc.  */
1226 static void
1227 print_filtered_help (unsigned int include_flags,
1228                      unsigned int exclude_flags,
1229                      unsigned int any_flags,
1230                      unsigned int columns)
1231 {
1232   unsigned int i;
1233   const char *help;
1234   static char *printed = NULL;
1235   bool found = false;
1236   bool displayed = false;
1237
1238   if (include_flags == CL_PARAMS)
1239     {
1240       for (i = 0; i < LAST_PARAM; i++)
1241         {
1242           const char *param = compiler_params[i].option;
1243
1244           help = compiler_params[i].help;
1245           if (help == NULL || *help == '\0')
1246             {
1247               if (exclude_flags & CL_UNDOCUMENTED)
1248                 continue;
1249               help = undocumented_msg;
1250             }
1251
1252           /* Get the translation.  */
1253           help = _(help);
1254
1255           wrap_help (help, param, strlen (param), columns);
1256         }
1257       putchar ('\n');
1258       return;
1259     }
1260
1261   if (!printed)
1262     printed = XCNEWVAR (char, cl_options_count);
1263
1264   for (i = 0; i < cl_options_count; i++)
1265     {
1266       static char new_help[128];
1267       const struct cl_option *option = cl_options + i;
1268       unsigned int len;
1269       const char *opt;
1270       const char *tab;
1271
1272       if (include_flags == 0
1273           || ((option->flags & include_flags) != include_flags))
1274         {
1275           if ((option->flags & any_flags) == 0)
1276             continue;
1277         }
1278
1279       /* Skip unwanted switches.  */
1280       if ((option->flags & exclude_flags) != 0)
1281         continue;
1282
1283       /* The driver currently prints its own help text.  */
1284       if ((option->flags & CL_DRIVER) != 0
1285           && (option->flags & (((1U << cl_lang_count) - 1)
1286                                | CL_COMMON | CL_TARGET)) == 0)
1287         continue;
1288
1289       found = true;
1290       /* Skip switches that have already been printed.  */
1291       if (printed[i])
1292         continue;
1293
1294       printed[i] = true;
1295
1296       help = option->help;
1297       if (help == NULL)
1298         {
1299           if (exclude_flags & CL_UNDOCUMENTED)
1300             continue;
1301           help = undocumented_msg;
1302         }
1303
1304       /* Get the translation.  */
1305       help = _(help);
1306
1307       /* Find the gap between the name of the
1308          option and its descriptive text.  */
1309       tab = strchr (help, '\t');
1310       if (tab)
1311         {
1312           len = tab - help;
1313           opt = help;
1314           help = tab + 1;
1315         }
1316       else
1317         {
1318           opt = option->opt_text;
1319           len = strlen (opt);
1320         }
1321
1322       /* With the -Q option enabled we change the descriptive text associated
1323          with an option to be an indication of its current setting.  */
1324       if (!quiet_flag)
1325         {
1326           void *flag_var = option_flag_var (i, &global_options);
1327
1328           if (len < (LEFT_COLUMN + 2))
1329             strcpy (new_help, "\t\t");
1330           else
1331             strcpy (new_help, "\t");
1332
1333           if (flag_var != NULL)
1334             {
1335               if (option->flags & CL_JOINED)
1336                 {
1337                   if (option->var_type == CLVC_STRING)
1338                     {
1339                       if (* (const char **) flag_var != NULL)
1340                         snprintf (new_help + strlen (new_help),
1341                                   sizeof (new_help) - strlen (new_help),
1342                                   * (const char **) flag_var);
1343                     }
1344                   else
1345                     sprintf (new_help + strlen (new_help),
1346                              "%#x", * (int *) flag_var);
1347                 }
1348               else
1349                 strcat (new_help, option_enabled (i, &global_options)
1350                         ? _("[enabled]") : _("[disabled]"));
1351             }
1352
1353           help = new_help;
1354         }
1355
1356       wrap_help (help, opt, len, columns);
1357       displayed = true;
1358     }
1359
1360   if (! found)
1361     {
1362       unsigned int langs = include_flags & CL_LANG_ALL;
1363
1364       if (langs == 0)
1365         printf (_(" No options with the desired characteristics were found\n"));
1366       else
1367         {
1368           unsigned int i;
1369
1370           /* PR 31349: Tell the user how to see all of the
1371              options supported by a specific front end.  */
1372           for (i = 0; (1U << i) < CL_LANG_ALL; i ++)
1373             if ((1U << i) & langs)
1374               printf (_(" None found.  Use --help=%s to show *all* the options supported by the %s front-end\n"),
1375                       lang_names[i], lang_names[i]);
1376         }
1377
1378     }
1379   else if (! displayed)
1380     printf (_(" All options with the desired characteristics have already been displayed\n"));
1381
1382   putchar ('\n');
1383 }
1384
1385 /* Display help for a specified type of option.
1386    The options must have ALL of the INCLUDE_FLAGS set
1387    ANY of the flags in the ANY_FLAGS set
1388    and NONE of the EXCLUDE_FLAGS set.  */
1389 static void
1390 print_specific_help (unsigned int include_flags,
1391                      unsigned int exclude_flags,
1392                      unsigned int any_flags)
1393 {
1394   unsigned int all_langs_mask = (1U << cl_lang_count) - 1;
1395   const char * description = NULL;
1396   const char * descrip_extra = "";
1397   size_t i;
1398   unsigned int flag;
1399   static unsigned int columns = 0;
1400
1401   /* Sanity check: Make sure that we do not have more
1402      languages than we have bits available to enumerate them.  */
1403   gcc_assert ((1U << cl_lang_count) < CL_MIN_OPTION_CLASS);
1404
1405   /* If we have not done so already, obtain
1406      the desired maximum width of the output.  */
1407   if (columns == 0)
1408     {
1409       const char *p;
1410
1411       GET_ENVIRONMENT (p, "COLUMNS");
1412       if (p != NULL)
1413         {
1414           int value = atoi (p);
1415
1416           if (value > 0)
1417             columns = value;
1418         }
1419
1420       if (columns == 0)
1421         /* Use a reasonable default.  */
1422         columns = 80;
1423     }
1424
1425   /* Decide upon the title for the options that we are going to display.  */
1426   for (i = 0, flag = 1; flag <= CL_MAX_OPTION_CLASS; flag <<= 1, i ++)
1427     {
1428       switch (flag & include_flags)
1429         {
1430         case 0:
1431         case CL_DRIVER:
1432           break;
1433
1434         case CL_TARGET:
1435           description = _("The following options are target specific");
1436           break;
1437         case CL_WARNING:
1438           description = _("The following options control compiler warning messages");
1439           break;
1440         case CL_OPTIMIZATION:
1441           description = _("The following options control optimizations");
1442           break;
1443         case CL_COMMON:
1444           description = _("The following options are language-independent");
1445           break;
1446         case CL_PARAMS:
1447           description = _("The --param option recognizes the following as parameters");
1448           break;
1449         default:
1450           if (i >= cl_lang_count)
1451             break;
1452           if (exclude_flags & all_langs_mask)
1453             description = _("The following options are specific to just the language ");
1454           else
1455             description = _("The following options are supported by the language ");
1456           descrip_extra = lang_names [i];
1457           break;
1458         }
1459     }
1460
1461   if (description == NULL)
1462     {
1463       if (any_flags == 0)
1464         {
1465           if (include_flags & CL_UNDOCUMENTED)
1466             description = _("The following options are not documented");
1467           else if (include_flags & CL_SEPARATE)
1468             description = _("The following options take separate arguments");
1469           else if (include_flags & CL_JOINED)
1470             description = _("The following options take joined arguments");
1471           else
1472             {
1473               internal_error ("unrecognized include_flags 0x%x passed to print_specific_help",
1474                               include_flags);
1475               return;
1476             }
1477         }
1478       else
1479         {
1480           if (any_flags & all_langs_mask)
1481             description = _("The following options are language-related");
1482           else
1483             description = _("The following options are language-independent");
1484         }
1485     }
1486
1487   printf ("%s%s:\n", description, descrip_extra);
1488   print_filtered_help (include_flags, exclude_flags, any_flags, columns);
1489 }
1490
1491 /* Handle target- and language-independent options.  Return zero to
1492    generate an "unknown option" message.  Only options that need
1493    extra handling need to be listed here; if you simply want
1494    DECODED->value assigned to a variable, it happens automatically.  */
1495
1496 static bool
1497 common_handle_option (struct gcc_options *opts,
1498                       struct gcc_options *opts_set,
1499                       const struct cl_decoded_option *decoded,
1500                       unsigned int lang_mask, int kind ATTRIBUTE_UNUSED,
1501                       const struct cl_option_handlers *handlers)
1502 {
1503   size_t scode = decoded->opt_index;
1504   const char *arg = decoded->arg;
1505   int value = decoded->value;
1506   static bool verbose = false;
1507   enum opt_code code = (enum opt_code) scode;
1508
1509   gcc_assert (opts == &global_options);
1510   gcc_assert (opts_set == &global_options_set);
1511   gcc_assert (decoded->canonical_option_num_elements <= 2);
1512
1513   switch (code)
1514     {
1515     case OPT__param:
1516       handle_param (opts, opts_set, arg);
1517       break;
1518
1519     case OPT_v:
1520       verbose = true;
1521       break;
1522
1523     case OPT__help:
1524       {
1525         unsigned int all_langs_mask = (1U << cl_lang_count) - 1;
1526         unsigned int undoc_mask;
1527         unsigned int i;
1528
1529         undoc_mask = (verbose | extra_warnings) ? 0 : CL_UNDOCUMENTED;
1530         /* First display any single language specific options.  */
1531         for (i = 0; i < cl_lang_count; i++)
1532           print_specific_help
1533             (1U << i, (all_langs_mask & (~ (1U << i))) | undoc_mask, 0);
1534         /* Next display any multi language specific options.  */
1535         print_specific_help (0, undoc_mask, all_langs_mask);
1536         /* Then display any remaining, non-language options.  */
1537         for (i = CL_MIN_OPTION_CLASS; i <= CL_MAX_OPTION_CLASS; i <<= 1)
1538           if (i != CL_DRIVER)
1539             print_specific_help (i, undoc_mask, 0);
1540         exit_after_options = true;
1541         break;
1542       }
1543
1544     case OPT__target_help:
1545       print_specific_help (CL_TARGET, CL_UNDOCUMENTED, 0);
1546       exit_after_options = true;
1547
1548       /* Allow the target a chance to give the user some additional information.  */
1549       if (targetm.help)
1550         targetm.help ();
1551       break;
1552
1553     case OPT__help_:
1554       {
1555         const char * a = arg;
1556         unsigned int include_flags = 0;
1557         /* Note - by default we include undocumented options when listing
1558            specific classes.  If you only want to see documented options
1559            then add ",^undocumented" to the --help= option.  E.g.:
1560
1561            --help=target,^undocumented  */
1562         unsigned int exclude_flags = 0;
1563
1564         /* Walk along the argument string, parsing each word in turn.
1565            The format is:
1566            arg = [^]{word}[,{arg}]
1567            word = {optimizers|target|warnings|undocumented|
1568                    params|common|<language>}  */
1569         while (* a != 0)
1570           {
1571             static struct
1572             {
1573               const char * string;
1574               unsigned int flag;
1575             }
1576             specifics[] =
1577             {
1578               { "optimizers", CL_OPTIMIZATION },
1579               { "target", CL_TARGET },
1580               { "warnings", CL_WARNING },
1581               { "undocumented", CL_UNDOCUMENTED },
1582               { "params", CL_PARAMS },
1583               { "joined", CL_JOINED },
1584               { "separate", CL_SEPARATE },
1585               { "common", CL_COMMON },
1586               { NULL, 0 }
1587             };
1588             unsigned int * pflags;
1589             const char * comma;
1590             unsigned int lang_flag, specific_flag;
1591             unsigned int len;
1592             unsigned int i;
1593
1594             if (* a == '^')
1595               {
1596                 ++ a;
1597                 pflags = & exclude_flags;
1598               }
1599             else
1600               pflags = & include_flags;
1601
1602             comma = strchr (a, ',');
1603             if (comma == NULL)
1604               len = strlen (a);
1605             else
1606               len = comma - a;
1607             if (len == 0)
1608               {
1609                 a = comma + 1;
1610                 continue;
1611               }
1612
1613             /* Check to see if the string matches an option class name.  */
1614             for (i = 0, specific_flag = 0; specifics[i].string != NULL; i++)
1615               if (strncasecmp (a, specifics[i].string, len) == 0)
1616                 {
1617                   specific_flag = specifics[i].flag;
1618                   break;
1619                 }
1620
1621             /* Check to see if the string matches a language name.
1622                Note - we rely upon the alpha-sorted nature of the entries in
1623                the lang_names array, specifically that shorter names appear
1624                before their longer variants.  (i.e. C before C++).  That way
1625                when we are attempting to match --help=c for example we will
1626                match with C first and not C++.  */
1627             for (i = 0, lang_flag = 0; i < cl_lang_count; i++)
1628               if (strncasecmp (a, lang_names[i], len) == 0)
1629                 {
1630                   lang_flag = 1U << i;
1631                   break;
1632                 }
1633
1634             if (specific_flag != 0)
1635               {
1636                 if (lang_flag == 0)
1637                   * pflags |= specific_flag;
1638                 else
1639                   {
1640                     /* The option's argument matches both the start of a
1641                        language name and the start of an option class name.
1642                        We have a special case for when the user has
1643                        specified "--help=c", but otherwise we have to issue
1644                        a warning.  */
1645                     if (strncasecmp (a, "c", len) == 0)
1646                       * pflags |= lang_flag;
1647                     else
1648                       fnotice (stderr,
1649                                "warning: --help argument %.*s is ambiguous, please be more specific\n",
1650                                len, a);
1651                   }
1652               }
1653             else if (lang_flag != 0)
1654               * pflags |= lang_flag;
1655             else
1656               fnotice (stderr,
1657                        "warning: unrecognized argument to --help= option: %.*s\n",
1658                        len, a);
1659
1660             if (comma == NULL)
1661               break;
1662             a = comma + 1;
1663           }
1664
1665         if (include_flags)
1666           print_specific_help (include_flags, exclude_flags, 0);
1667         exit_after_options = true;
1668         break;
1669       }
1670
1671     case OPT__version:
1672       exit_after_options = true;
1673       break;
1674
1675     case OPT_O:
1676     case OPT_Os:
1677     case OPT_Ofast:
1678       /* Currently handled in a prescan.  */
1679       break;
1680
1681     case OPT_Werror_:
1682       enable_warning_as_error (arg, value, lang_mask, handlers, global_dc);
1683       break;
1684
1685     case OPT_Wlarger_than_:
1686       larger_than_size = value;
1687       warn_larger_than = value != -1;
1688       break;
1689
1690     case OPT_Wfatal_errors:
1691       global_dc->fatal_errors = value;
1692       break;
1693
1694     case OPT_Wframe_larger_than_:
1695       frame_larger_than_size = value;
1696       warn_frame_larger_than = value != -1;
1697       break;
1698
1699     case OPT_Wstrict_aliasing:
1700       set_Wstrict_aliasing (value);
1701       break;
1702
1703     case OPT_Wstrict_aliasing_:
1704       warn_strict_aliasing = value;
1705       break;
1706
1707     case OPT_Wstrict_overflow:
1708       warn_strict_overflow = (value
1709                               ? (int) WARN_STRICT_OVERFLOW_CONDITIONAL
1710                               : 0);
1711       break;
1712
1713     case OPT_Wstrict_overflow_:
1714       warn_strict_overflow = value;
1715       break;
1716
1717     case OPT_Wsystem_headers:
1718       global_dc->dc_warn_system_headers = value;
1719       break;
1720
1721     case OPT_Wunused:
1722       warn_unused = value;
1723       break;
1724
1725     case OPT_aux_info:
1726       aux_info_file_name = arg;
1727       flag_gen_aux_info = 1;
1728       break;
1729
1730     case OPT_auxbase:
1731       aux_base_name = arg;
1732       break;
1733
1734     case OPT_auxbase_strip:
1735       {
1736         char *tmp = xstrdup (arg);
1737         strip_off_ending (tmp, strlen (tmp));
1738         if (tmp[0])
1739           aux_base_name = tmp;
1740       }
1741       break;
1742
1743     case OPT_d:
1744       decode_d_option (arg);
1745       break;
1746
1747     case OPT_dumpbase:
1748       dump_base_name = arg;
1749       break;
1750
1751     case OPT_dumpdir:
1752       dump_dir_name = arg;
1753       break;
1754
1755     case OPT_falign_functions_:
1756       align_functions = value;
1757       break;
1758
1759     case OPT_falign_jumps_:
1760       align_jumps = value;
1761       break;
1762
1763     case OPT_falign_labels_:
1764       align_labels = value;
1765       break;
1766
1767     case OPT_falign_loops_:
1768       align_loops = value;
1769       break;
1770
1771     case OPT_fcall_used_:
1772       fix_register (arg, 0, 1);
1773       break;
1774
1775     case OPT_fcall_saved_:
1776       fix_register (arg, 0, 0);
1777       break;
1778
1779     case OPT_fcompare_debug_second:
1780       flag_compare_debug = value;
1781       break;
1782
1783     case OPT_fdbg_cnt_:
1784       dbg_cnt_process_opt (arg);
1785       break;
1786
1787     case OPT_fdbg_cnt_list:
1788       dbg_cnt_list_all_counters ();
1789       break;
1790
1791     case OPT_fdebug_prefix_map_:
1792       add_debug_prefix_map (arg);
1793       break;
1794
1795     case OPT_fdiagnostics_show_location_:
1796       if (!strcmp (arg, "once"))
1797         diagnostic_prefixing_rule (global_dc) = DIAGNOSTICS_SHOW_PREFIX_ONCE;
1798       else if (!strcmp (arg, "every-line"))
1799         diagnostic_prefixing_rule (global_dc)
1800           = DIAGNOSTICS_SHOW_PREFIX_EVERY_LINE;
1801       else
1802         return false;
1803       break;
1804
1805     case OPT_fdiagnostics_show_option:
1806       global_dc->show_option_requested = value;
1807       break;
1808
1809     case OPT_fdump_:
1810       if (!dump_switch_p (arg))
1811         return false;
1812       break;
1813
1814     case OPT_fexcess_precision_:
1815       if (!strcmp (arg, "fast"))
1816         flag_excess_precision_cmdline = EXCESS_PRECISION_FAST;
1817       else if (!strcmp (arg, "standard"))
1818         flag_excess_precision_cmdline = EXCESS_PRECISION_STANDARD;
1819       else
1820         error ("unknown excess precision style \"%s\"", arg);
1821       break;
1822
1823     case OPT_ffast_math:
1824       set_fast_math_flags (value);
1825       break;
1826
1827     case OPT_funsafe_math_optimizations:
1828       set_unsafe_math_optimizations_flags (value);
1829       break;
1830
1831     case OPT_ffixed_:
1832       fix_register (arg, 1, 1);
1833       break;
1834
1835     case OPT_finline_limit_:
1836       set_param_value ("max-inline-insns-single", value / 2,
1837                        opts->x_param_values, opts_set->x_param_values);
1838       set_param_value ("max-inline-insns-auto", value / 2,
1839                        opts->x_param_values, opts_set->x_param_values);
1840       break;
1841
1842     case OPT_finstrument_functions_exclude_function_list_:
1843       add_comma_separated_to_vector
1844         (&flag_instrument_functions_exclude_functions, arg);
1845       break;
1846
1847     case OPT_finstrument_functions_exclude_file_list_:
1848       add_comma_separated_to_vector
1849         (&flag_instrument_functions_exclude_files, arg);
1850       break;
1851
1852     case OPT_fmessage_length_:
1853       pp_set_line_maximum_length (global_dc->printer, value);
1854       break;
1855
1856     case OPT_fpack_struct_:
1857       if (value <= 0 || (value & (value - 1)) || value > 16)
1858         error ("structure alignment must be a small power of two, not %d", value);
1859       else
1860         {
1861           initial_max_fld_align = value;
1862           maximum_field_alignment = value * BITS_PER_UNIT;
1863         }
1864       break;
1865
1866     case OPT_fplugin_:
1867 #ifdef ENABLE_PLUGIN
1868       add_new_plugin (arg);
1869 #else
1870       error ("Plugin support is disabled.  Configure with --enable-plugin.");
1871 #endif
1872       break;
1873
1874     case OPT_fplugin_arg_:
1875 #ifdef ENABLE_PLUGIN
1876       parse_plugin_arg_opt (arg);
1877 #else
1878       error ("Plugin support is disabled.  Configure with --enable-plugin.");
1879 #endif
1880       break;
1881
1882     case OPT_fprofile_dir_:
1883       profile_data_prefix = xstrdup (arg);
1884       break;
1885
1886     case OPT_fprofile_use_:
1887       profile_data_prefix = xstrdup (arg);
1888       flag_profile_use = true;
1889       value = true;
1890       /* No break here - do -fprofile-use processing. */
1891     case OPT_fprofile_use:
1892       if (!opts_set->x_flag_branch_probabilities)
1893         flag_branch_probabilities = value;
1894       if (!opts_set->x_flag_profile_values)
1895         flag_profile_values = value;
1896       if (!opts_set->x_flag_unroll_loops)
1897         flag_unroll_loops = value;
1898       if (!opts_set->x_flag_peel_loops)
1899         flag_peel_loops = value;
1900       if (!opts_set->x_flag_tracer)
1901         flag_tracer = value;
1902       if (!opts_set->x_flag_value_profile_transformations)
1903         flag_value_profile_transformations = value;
1904       if (!opts_set->x_flag_inline_functions)
1905         flag_inline_functions = value;
1906       if (!opts_set->x_flag_ipa_cp)
1907         flag_ipa_cp = value;
1908       if (!opts_set->x_flag_ipa_cp_clone
1909           && value && flag_ipa_cp)
1910         flag_ipa_cp_clone = value;
1911       if (!opts_set->x_flag_predictive_commoning)
1912         flag_predictive_commoning = value;
1913       if (!opts_set->x_flag_unswitch_loops)
1914         flag_unswitch_loops = value;
1915       if (!opts_set->x_flag_gcse_after_reload)
1916         flag_gcse_after_reload = value;
1917       break;
1918
1919     case OPT_fprofile_generate_:
1920       profile_data_prefix = xstrdup (arg);
1921       value = true;
1922       /* No break here - do -fprofile-generate processing. */
1923     case OPT_fprofile_generate:
1924       if (!opts_set->x_profile_arc_flag)
1925         profile_arc_flag = value;
1926       if (!opts_set->x_flag_profile_values)
1927         flag_profile_values = value;
1928       if (!opts_set->x_flag_value_profile_transformations)
1929         flag_value_profile_transformations = value;
1930       if (!opts_set->x_flag_inline_functions)
1931         flag_inline_functions = value;
1932       break;
1933
1934     case OPT_fshow_column:
1935       global_dc->show_column = value;
1936       break;
1937
1938     case OPT_fvisibility_:
1939       {
1940         if (!strcmp(arg, "default"))
1941           default_visibility = VISIBILITY_DEFAULT;
1942         else if (!strcmp(arg, "internal"))
1943           default_visibility = VISIBILITY_INTERNAL;
1944         else if (!strcmp(arg, "hidden"))
1945           default_visibility = VISIBILITY_HIDDEN;
1946         else if (!strcmp(arg, "protected"))
1947           default_visibility = VISIBILITY_PROTECTED;
1948         else
1949           error ("unrecognized visibility value \"%s\"", arg);
1950       }
1951       break;
1952
1953     case OPT_frandom_seed:
1954       /* The real switch is -fno-random-seed.  */
1955       if (value)
1956         return false;
1957       set_random_seed (NULL);
1958       break;
1959
1960     case OPT_frandom_seed_:
1961       set_random_seed (arg);
1962       break;
1963
1964     case OPT_fsched_verbose_:
1965 #ifdef INSN_SCHEDULING
1966       fix_sched_param ("verbose", arg);
1967       break;
1968 #else
1969       return false;
1970 #endif
1971
1972     case OPT_fsched_stalled_insns_:
1973       flag_sched_stalled_insns = value;
1974       if (flag_sched_stalled_insns == 0)
1975         flag_sched_stalled_insns = -1;
1976       break;
1977
1978     case OPT_fsched_stalled_insns_dep_:
1979       flag_sched_stalled_insns_dep = value;
1980       break;
1981
1982     case OPT_fstack_check_:
1983       if (!strcmp (arg, "no"))
1984         flag_stack_check = NO_STACK_CHECK;
1985       else if (!strcmp (arg, "generic"))
1986         /* This is the old stack checking method.  */
1987         flag_stack_check = STACK_CHECK_BUILTIN
1988                            ? FULL_BUILTIN_STACK_CHECK
1989                            : GENERIC_STACK_CHECK;
1990       else if (!strcmp (arg, "specific"))
1991         /* This is the new stack checking method.  */
1992         flag_stack_check = STACK_CHECK_BUILTIN
1993                            ? FULL_BUILTIN_STACK_CHECK
1994                            : STACK_CHECK_STATIC_BUILTIN
1995                              ? STATIC_BUILTIN_STACK_CHECK
1996                              : GENERIC_STACK_CHECK;
1997       else
1998         warning (0, "unknown stack check parameter \"%s\"", arg);
1999       break;
2000
2001     case OPT_fstack_limit:
2002       /* The real switch is -fno-stack-limit.  */
2003       if (value)
2004         return false;
2005       stack_limit_rtx = NULL_RTX;
2006       break;
2007
2008     case OPT_fstack_limit_register_:
2009       {
2010         int reg = decode_reg_name (arg);
2011         if (reg < 0)
2012           error ("unrecognized register name \"%s\"", arg);
2013         else
2014           stack_limit_rtx = gen_rtx_REG (Pmode, reg);
2015       }
2016       break;
2017
2018     case OPT_fstack_limit_symbol_:
2019       stack_limit_rtx = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (arg));
2020       break;
2021
2022     case OPT_ftree_vectorizer_verbose_:
2023       vect_set_verbosity_level (arg);
2024       break;
2025
2026     case OPT_ftls_model_:
2027       if (!strcmp (arg, "global-dynamic"))
2028         flag_tls_default = TLS_MODEL_GLOBAL_DYNAMIC;
2029       else if (!strcmp (arg, "local-dynamic"))
2030         flag_tls_default = TLS_MODEL_LOCAL_DYNAMIC;
2031       else if (!strcmp (arg, "initial-exec"))
2032         flag_tls_default = TLS_MODEL_INITIAL_EXEC;
2033       else if (!strcmp (arg, "local-exec"))
2034         flag_tls_default = TLS_MODEL_LOCAL_EXEC;
2035       else
2036         warning (0, "unknown tls-model \"%s\"", arg);
2037       break;
2038
2039     case OPT_fira_algorithm_:
2040       if (!strcmp (arg, "CB"))
2041         flag_ira_algorithm = IRA_ALGORITHM_CB;
2042       else if (!strcmp (arg, "priority"))
2043         flag_ira_algorithm = IRA_ALGORITHM_PRIORITY;
2044       else
2045         warning (0, "unknown ira algorithm \"%s\"", arg);
2046       break;
2047
2048     case OPT_fira_region_:
2049       if (!strcmp (arg, "one"))
2050         flag_ira_region = IRA_REGION_ONE;
2051       else if (!strcmp (arg, "all"))
2052         flag_ira_region = IRA_REGION_ALL;
2053       else if (!strcmp (arg, "mixed"))
2054         flag_ira_region = IRA_REGION_MIXED;
2055       else
2056         warning (0, "unknown ira region \"%s\"", arg);
2057       break;
2058
2059     case OPT_fira_verbose_:
2060       flag_ira_verbose = value;
2061       break;
2062
2063     case OPT_g:
2064       set_debug_level (NO_DEBUG, DEFAULT_GDB_EXTENSIONS, arg);
2065       break;
2066
2067     case OPT_gcoff:
2068       set_debug_level (SDB_DEBUG, false, arg);
2069       break;
2070
2071     case OPT_gdwarf_:
2072       if (value < 2 || value > 4)
2073         error ("dwarf version %d is not supported", value);
2074       else
2075         dwarf_version = value;
2076       set_debug_level (DWARF2_DEBUG, false, "");
2077       break;
2078
2079     case OPT_ggdb:
2080       set_debug_level (NO_DEBUG, 2, arg);
2081       break;
2082
2083     case OPT_gstabs:
2084     case OPT_gstabs_:
2085       set_debug_level (DBX_DEBUG, code == OPT_gstabs_, arg);
2086       break;
2087
2088     case OPT_gvms:
2089       set_debug_level (VMS_DEBUG, false, arg);
2090       break;
2091
2092     case OPT_gxcoff:
2093     case OPT_gxcoff_:
2094       set_debug_level (XCOFF_DEBUG, code == OPT_gxcoff_, arg);
2095       break;
2096
2097     case OPT_o:
2098       asm_file_name = arg;
2099       break;
2100
2101     case OPT_pedantic_errors:
2102       flag_pedantic_errors = pedantic = 1;
2103       global_dc->pedantic_errors = 1;
2104       break;
2105
2106     case OPT_fwhopr_:
2107       flag_whopr = arg;
2108       break;
2109
2110     case OPT_fwhopr:
2111       flag_whopr = "";
2112       break;
2113
2114     case OPT_w:
2115       global_dc->dc_inhibit_warnings = true;
2116       break;
2117
2118     case OPT_fuse_linker_plugin:
2119       /* No-op. Used by the driver and passed to us because it starts with f.*/
2120       break;
2121
2122     default:
2123       /* If the flag was handled in a standard way, assume the lack of
2124          processing here is intentional.  */
2125       gcc_assert (option_flag_var (scode, opts));
2126       break;
2127     }
2128
2129   return true;
2130 }
2131
2132 /* Handle --param NAME=VALUE.  */
2133 static void
2134 handle_param (struct gcc_options *opts, struct gcc_options *opts_set,
2135               const char *carg)
2136 {
2137   char *equal, *arg;
2138   int value;
2139
2140   arg = xstrdup (carg);
2141   equal = strchr (arg, '=');
2142   if (!equal)
2143     error ("%s: --param arguments should be of the form NAME=VALUE", arg);
2144   else
2145     {
2146       value = integral_argument (equal + 1);
2147       if (value == -1)
2148         error ("invalid --param value %qs", equal + 1);
2149       else
2150         {
2151           *equal = '\0';
2152           set_param_value (arg, value,
2153                            opts->x_param_values, opts_set->x_param_values);
2154         }
2155     }
2156
2157   free (arg);
2158 }
2159
2160 /* Used to set the level of strict aliasing warnings,
2161    when no level is specified (i.e., when -Wstrict-aliasing, and not
2162    -Wstrict-aliasing=level was given).
2163    ONOFF is assumed to take value 1 when -Wstrict-aliasing is specified,
2164    and 0 otherwise.  After calling this function, wstrict_aliasing will be
2165    set to the default value of -Wstrict_aliasing=level, currently 3.  */
2166 void
2167 set_Wstrict_aliasing (int onoff)
2168 {
2169   gcc_assert (onoff == 0 || onoff == 1);
2170   if (onoff != 0)
2171     warn_strict_aliasing = 3;
2172   else
2173     warn_strict_aliasing = 0;
2174 }
2175
2176 /* The following routines are useful in setting all the flags that
2177    -ffast-math and -fno-fast-math imply.  */
2178 void
2179 set_fast_math_flags (int set)
2180 {
2181   flag_unsafe_math_optimizations = set;
2182   set_unsafe_math_optimizations_flags (set);
2183   flag_finite_math_only = set;
2184   flag_errno_math = !set;
2185   if (set)
2186     {
2187       flag_signaling_nans = 0;
2188       flag_rounding_math = 0;
2189       flag_cx_limited_range = 1;
2190     }
2191 }
2192
2193 /* When -funsafe-math-optimizations is set the following
2194    flags are set as well.  */
2195 void
2196 set_unsafe_math_optimizations_flags (int set)
2197 {
2198   flag_trapping_math = !set;
2199   flag_signed_zeros = !set;
2200   flag_associative_math = set;
2201   flag_reciprocal_math = set;
2202 }
2203
2204 /* Return true iff flags are set as if -ffast-math.  */
2205 bool
2206 fast_math_flags_set_p (void)
2207 {
2208   return (!flag_trapping_math
2209           && flag_unsafe_math_optimizations
2210           && flag_finite_math_only
2211           && !flag_signed_zeros
2212           && !flag_errno_math);
2213 }
2214
2215 /* Return true iff flags are set as if -ffast-math but using the flags stored
2216    in the struct cl_optimization structure.  */
2217 bool
2218 fast_math_flags_struct_set_p (struct cl_optimization *opt)
2219 {
2220   return (!opt->x_flag_trapping_math
2221           && opt->x_flag_unsafe_math_optimizations
2222           && opt->x_flag_finite_math_only
2223           && !opt->x_flag_signed_zeros
2224           && !opt->x_flag_errno_math);
2225 }
2226
2227 /* Handle a debug output -g switch.  EXTENDED is true or false to support
2228    extended output (2 is special and means "-ggdb" was given).  */
2229 static void
2230 set_debug_level (enum debug_info_type type, int extended, const char *arg)
2231 {
2232   static bool type_explicit;
2233
2234   use_gnu_debug_info_extensions = extended;
2235
2236   if (type == NO_DEBUG)
2237     {
2238       if (write_symbols == NO_DEBUG)
2239         {
2240           write_symbols = PREFERRED_DEBUGGING_TYPE;
2241
2242           if (extended == 2)
2243             {
2244 #ifdef DWARF2_DEBUGGING_INFO
2245               write_symbols = DWARF2_DEBUG;
2246 #elif defined DBX_DEBUGGING_INFO
2247               write_symbols = DBX_DEBUG;
2248 #endif
2249             }
2250
2251           if (write_symbols == NO_DEBUG)
2252             warning (0, "target system does not support debug output");
2253         }
2254     }
2255   else
2256     {
2257       /* Does it conflict with an already selected type?  */
2258       if (type_explicit && write_symbols != NO_DEBUG && type != write_symbols)
2259         error ("debug format \"%s\" conflicts with prior selection",
2260                debug_type_names[type]);
2261       write_symbols = type;
2262       type_explicit = true;
2263     }
2264
2265   /* A debug flag without a level defaults to level 2.  */
2266   if (*arg == '\0')
2267     {
2268       if (!debug_info_level)
2269         debug_info_level = DINFO_LEVEL_NORMAL;
2270     }
2271   else
2272     {
2273       int argval = integral_argument (arg);
2274       if (argval == -1)
2275         error ("unrecognised debug output level \"%s\"", arg);
2276       else if (argval > 3)
2277         error ("debug output level %s is too high", arg);
2278       else
2279         debug_info_level = (enum debug_info_level) argval;
2280     }
2281 }
2282
2283 /* Return 1 if option OPT_IDX is enabled in OPTS, 0 if it is disabled,
2284    or -1 if it isn't a simple on-off switch.  */
2285
2286 int
2287 option_enabled (int opt_idx, void *opts)
2288 {
2289   const struct cl_option *option = &(cl_options[opt_idx]);
2290   struct gcc_options *optsg = (struct gcc_options *) opts;
2291   void *flag_var = option_flag_var (opt_idx, optsg);
2292
2293   if (flag_var)
2294     switch (option->var_type)
2295       {
2296       case CLVC_BOOLEAN:
2297         return *(int *) flag_var != 0;
2298
2299       case CLVC_EQUAL:
2300         return *(int *) flag_var == option->var_value;
2301
2302       case CLVC_BIT_CLEAR:
2303         return (*(int *) flag_var & option->var_value) == 0;
2304
2305       case CLVC_BIT_SET:
2306         return (*(int *) flag_var & option->var_value) != 0;
2307
2308       case CLVC_STRING:
2309         break;
2310       }
2311   return -1;
2312 }
2313
2314 /* Fill STATE with the current state of option OPTION in OPTS.  Return
2315    true if there is some state to store.  */
2316
2317 bool
2318 get_option_state (struct gcc_options *opts, int option,
2319                   struct cl_option_state *state)
2320 {
2321   void *flag_var = option_flag_var (option, opts);
2322
2323   if (flag_var == 0)
2324     return false;
2325
2326   switch (cl_options[option].var_type)
2327     {
2328     case CLVC_BOOLEAN:
2329     case CLVC_EQUAL:
2330       state->data = flag_var;
2331       state->size = sizeof (int);
2332       break;
2333
2334     case CLVC_BIT_CLEAR:
2335     case CLVC_BIT_SET:
2336       state->ch = option_enabled (option, opts);
2337       state->data = &state->ch;
2338       state->size = 1;
2339       break;
2340
2341     case CLVC_STRING:
2342       state->data = *(const char **) flag_var;
2343       if (state->data == 0)
2344         state->data = "";
2345       state->size = strlen ((const char *) state->data) + 1;
2346       break;
2347     }
2348   return true;
2349 }
2350
2351 /* Callback function, called when -Werror= enables a warning.  */
2352
2353 static void (*warning_as_error_callback) (int) = NULL;
2354
2355 /* Register a callback for enable_warning_as_error calls.  */
2356
2357 void
2358 register_warning_as_error_callback (void (*callback) (int))
2359 {
2360   gcc_assert (warning_as_error_callback == NULL || callback == NULL);
2361   warning_as_error_callback = callback;
2362 }
2363
2364 /* Enable (or disable if VALUE is 0) a warning option ARG (language
2365    mask LANG_MASK, option handlers HANDLERS) as an error for
2366    diagnostic context DC (possibly NULL).  This is used by
2367    -Werror=.  */
2368
2369 void
2370 enable_warning_as_error (const char *arg, int value, unsigned int lang_mask,
2371                          const struct cl_option_handlers *handlers,
2372                          diagnostic_context *dc)
2373 {
2374   char *new_option;
2375   int option_index;
2376
2377   new_option = XNEWVEC (char, strlen (arg) + 2);
2378   new_option[0] = 'W';
2379   strcpy (new_option + 1, arg);
2380   option_index = find_opt (new_option, lang_mask);
2381   if (option_index == OPT_SPECIAL_unknown)
2382     {
2383       error ("-Werror=%s: No option -%s", arg, new_option);
2384     }
2385   else
2386     {
2387       const struct cl_option *option = &cl_options[option_index];
2388       const diagnostic_t kind = value ? DK_ERROR : DK_WARNING;
2389
2390       if (option->alias_target != N_OPTS)
2391         option_index = option->alias_target;
2392       if (option_index == OPT_SPECIAL_ignore)
2393         return;
2394       if (dc)
2395         diagnostic_classify_diagnostic (dc, option_index, kind,
2396                                         UNKNOWN_LOCATION);
2397       if (kind == DK_ERROR)
2398         {
2399           const struct cl_option * const option = cl_options + option_index;
2400
2401           /* -Werror=foo implies -Wfoo.  */
2402           if (option->var_type == CLVC_BOOLEAN)
2403             handle_generated_option (&global_options, &global_options_set,
2404                                      option_index, NULL, value, lang_mask,
2405                                      (int)kind, handlers,
2406                                      dc);
2407
2408           if (warning_as_error_callback)
2409             warning_as_error_callback (option_index);
2410         }
2411     }
2412   free (new_option);
2413 }
2414
2415 /* Return malloced memory for the name of the option OPTION_INDEX
2416    which enabled a diagnostic (context CONTEXT), originally of type
2417    ORIG_DIAG_KIND but possibly converted to DIAG_KIND by options such
2418    as -Werror.  */
2419
2420 char *
2421 option_name (diagnostic_context *context, int option_index,
2422              diagnostic_t orig_diag_kind, diagnostic_t diag_kind)
2423 {
2424   if (option_index)
2425     {
2426       /* A warning classified as an error.  */
2427       if ((orig_diag_kind == DK_WARNING || orig_diag_kind == DK_PEDWARN)
2428           && diag_kind == DK_ERROR)
2429         return concat (cl_options[OPT_Werror_].opt_text,
2430                        /* Skip over "-W".  */
2431                        cl_options[option_index].opt_text + 2,
2432                        NULL);
2433       /* A warning with option.  */
2434       else
2435         return xstrdup (cl_options[option_index].opt_text);
2436     }
2437   /* A warning without option classified as an error.  */
2438   else if (orig_diag_kind == DK_WARNING || orig_diag_kind == DK_PEDWARN
2439            || diag_kind == DK_WARNING)
2440     {
2441       if (context->warning_as_error_requested)
2442         return xstrdup (cl_options[OPT_Werror].opt_text);
2443       else
2444         return xstrdup (_("enabled by default"));
2445     }
2446   else
2447     return NULL;
2448 }