OSDN Git Service

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