OSDN Git Service

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