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