OSDN Git Service

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