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