OSDN Git Service

* opts.c (in_fnames, num_in_fnames): Moved here from c-opts.
[pf3gnuchains/gcc-fork.git] / gcc / opts.c
1 /* Command line option handling.
2    Copyright (C) 2002, 2003 Free Software Foundation, Inc.
3    Contributed by Neil Booth.
4
5 This file is part of GCC.
6
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 2, or (at your option) any later
10 version.
11
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
15 for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING.  If not, write to the Free
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
20 02111-1307, USA.  */
21
22 #include "config.h"
23 #include "system.h"
24 #include "intl.h"
25 #include "coretypes.h"
26 #include "tm.h"
27 #include "tree.h"
28 #include "rtl.h"
29 #include "ggc.h"
30 #include "output.h"
31 #include "langhooks.h"
32 #include "opts.h"
33 #include "options.h"
34 #include "flags.h"
35 #include "toplev.h"
36 #include "params.h"
37 #include "diagnostic.h"
38 #include "tm_p.h"               /* For OPTIMIZATION_OPTIONS.  */
39 #include "insn-attr.h"          /* For INSN_SCHEDULING.  */
40
41 /* Value of the -G xx switch, and whether it was passed or not.  */
42 unsigned HOST_WIDE_INT g_switch_value;
43 bool g_switch_set;
44
45 /* True if we should exit after parsing options.  */
46 bool exit_after_options;
47
48 /* If -version.  */
49 bool version_flag;
50
51 /* Print various extra warnings.  -W/-Wextra.  */
52 bool extra_warnings;
53
54 /* Don't print warning messages.  -w.  */
55 bool inhibit_warnings;
56
57 /* Treat warnings as errors.  -Werror.  */
58 bool warnings_are_errors;
59
60 /* Warn if a function returns an aggregate, since there are often
61    incompatible calling conventions for doing this.  */
62 bool warn_aggregate_return;
63
64 /* Nonzero means warn about pointer casts that increase the required
65    alignment of the target type (and might therefore lead to a crash
66    due to a misaligned access).  */
67 bool warn_cast_align;
68
69 /* Nonzero means warn about uses of __attribute__((deprecated))
70    declarations.  */
71 bool warn_deprecated_decl = true;
72
73 /* Warn when an optimization pass is disabled.  */
74 bool warn_disabled_optimization;
75
76 /* Nonzero means warn if inline function is too large.  */
77 bool warn_inline;
78
79 /* True to warn about any objects definitions whose size is larger
80    than N bytes.  Also want about function definitions whose returned
81    values are larger than N bytes, where N is `larger_than_size'.  */
82 bool warn_larger_than;
83 HOST_WIDE_INT larger_than_size;
84
85 /* Warn about functions which might be candidates for attribute noreturn.  */
86 bool warn_missing_noreturn;
87
88 /* True to warn about code which is never reached.  */
89 bool warn_notreached;
90
91 /* Warn if packed attribute on struct is unnecessary and inefficient.  */
92 bool warn_packed;
93
94 /* Warn when gcc pads a structure to an alignment boundary.  */
95 bool warn_padded;
96
97 /* True means warn about all declarations which shadow others.  */
98 bool warn_shadow;
99
100 /* Nonzero means warn about constructs which might not be
101    strict-aliasing safe.  */
102 bool warn_strict_aliasing;
103
104 /* True to warn if a switch on an enum, that does not have a default
105    case, fails to have a case for every enum value.  */
106 bool warn_switch;
107
108 /* Warn if a switch does not have a default case.  */
109 bool warn_switch_default;
110
111 /* Warn if a switch on an enum fails to have a case for every enum
112    value (regardless of the presence or otherwise of a default case).  */
113 bool warn_switch_enum;
114
115 /* Don't suppress warnings from system headers.  -Wsystem-headers.  */
116 bool warn_system_headers;
117
118 /* True to warn about variables used before they are initialized.  */
119 int warn_uninitialized;
120
121 /* True to warn about unused variables, functions et.al.  */
122 bool warn_unused_function;
123 bool warn_unused_label;
124 bool warn_unused_parameter;
125 bool warn_unused_variable;
126 bool warn_unused_value;
127
128 /* Hack for cooperation between set_Wunused and set_Wextra.  */
129 static bool maybe_warn_unused_parameter;
130
131 /* Columns of --help display.  */
132 static unsigned int columns = 80;
133
134 /* What to print when a switch has no documentation.  */
135 static const char undocumented_msg[] = N_("This switch lacks documentation");
136
137 /* Input file names. */
138 const char **in_fnames;
139 unsigned num_in_fnames;
140
141 static size_t find_opt (const char *, int);
142 static int common_handle_option (size_t scode, const char *arg, int value);
143 static void handle_param (const char *);
144 static void set_Wextra (int);
145 static unsigned int handle_option (const char **argv, unsigned int lang_mask);
146 static char *write_langs (unsigned int lang_mask);
147 static void complain_wrong_lang (const char *, const struct cl_option *,
148                                  unsigned int lang_mask);
149 static void handle_options (unsigned int, const char **, unsigned int);
150 static void wrap_help (const char *help, const char *item, unsigned int);
151 static void print_help (void);
152 static void print_param_help (void);
153 static void print_filtered_help (unsigned int flag);
154 static unsigned int print_switch (const char *text, unsigned int indent);
155
156 /* Perform a binary search to find which option the command-line INPUT
157    matches.  Returns its index in the option array, and N_OPTS
158    (cl_options_count) on failure.
159
160    This routine is quite subtle.  A normal binary search is not good
161    enough because some options can be suffixed with an argument, and
162    multiple sub-matches can occur, e.g. input of "-pedantic" matching
163    the initial substring of "-pedantic-errors".
164
165    A more complicated example is -gstabs.  It should match "-g" with
166    an argument of "stabs".  Suppose, however, that the number and list
167    of switches are such that the binary search tests "-gen-decls"
168    before having tested "-g".  This doesn't match, and as "-gen-decls"
169    is less than "-gstabs", it will become the lower bound of the
170    binary search range, and "-g" will never be seen.  To resolve this
171    issue, opts.sh makes "-gen-decls" point, via the back_chain member,
172    to "-g" so that failed searches that end between "-gen-decls" and
173    the lexicographically subsequent switch know to go back and see if
174    "-g" causes a match (which it does in this example).
175
176    This search is done in such a way that the longest match for the
177    front end in question wins.  If there is no match for the current
178    front end, the longest match for a different front end is returned
179    (or N_OPTS if none) and the caller emits an error message.  */
180 static size_t
181 find_opt (const char *input, int lang_mask)
182 {
183   size_t mn, mx, md, opt_len;
184   size_t match_wrong_lang;
185   int comp;
186
187   mn = 0;
188   mx = cl_options_count;
189
190   /* Find mn such this lexicographical inequality holds:
191      cl_options[mn] <= input < cl_options[mn + 1].  */
192   while (mx - mn > 1)
193     {
194       md = (mn + mx) / 2;
195       opt_len = cl_options[md].opt_len;
196       comp = strncmp (input, cl_options[md].opt_text + 1, opt_len);
197
198       if (comp < 0)
199         mx = md;
200       else
201         mn = md;
202     }
203
204   /* This is the switch that is the best match but for a different
205      front end, or cl_options_count if there is no match at all.  */
206   match_wrong_lang = cl_options_count;
207
208   /* Backtrace the chain of possible matches, returning the longest
209      one, if any, that fits best.  With current GCC switches, this
210      loop executes at most twice.  */
211   do
212     {
213       const struct cl_option *opt = &cl_options[mn];
214
215       /* Is this switch a prefix of the input?  */
216       if (!strncmp (input, opt->opt_text + 1, opt->opt_len))
217         {
218           /* If language is OK, and the match is exact or the switch
219              takes a joined argument, return it.  */
220           if ((opt->flags & lang_mask)
221               && (input[opt->opt_len] == '\0' || (opt->flags & CL_JOINED)))
222             return mn;
223
224           /* If we haven't remembered a prior match, remember this
225              one.  Any prior match is necessarily better.  */
226           if (match_wrong_lang == cl_options_count)
227             match_wrong_lang = mn;
228         }
229
230       /* Try the next possibility.  This is cl_options_count if there
231          are no more.  */
232       mn = opt->back_chain;
233     }
234   while (mn != cl_options_count);
235
236   /* Return the best wrong match, or cl_options_count if none.  */
237   return match_wrong_lang;
238 }
239
240 /* If ARG is a non-negative integer made up solely of digits, return its
241    value, otherwise return -1.  */
242 static int
243 integral_argument (const char *arg)
244 {
245   const char *p = arg;
246
247   while (*p && ISDIGIT (*p))
248     p++;
249
250   if (*p == '\0')
251     return atoi (arg);
252
253   return -1;
254 }
255
256 /* Return a malloced slash-separated list of languages in MASK.  */
257 static char *
258 write_langs (unsigned int mask)
259 {
260   unsigned int n = 0, len = 0;
261   const char *lang_name;
262   char *result;
263
264   for (n = 0; (lang_name = lang_names[n]) != 0; n++)
265     if (mask & (1U << n))
266       len += strlen (lang_name) + 1;
267
268   result = xmalloc (len);
269   len = 0;
270   for (n = 0; (lang_name = lang_names[n]) != 0; n++)
271     if (mask & (1U << n))
272       {
273         if (len)
274           result[len++] = '/';
275         strcpy (result + len, lang_name);
276         len += strlen (lang_name);
277       }
278
279   result[len] = 0;
280
281   return result;
282 }
283
284 /* Complain that switch OPT_INDEX does not apply to this front end.  */
285 static void
286 complain_wrong_lang (const char *text, const struct cl_option *option,
287                      unsigned int lang_mask)
288 {
289   char *ok_langs, *bad_lang;
290
291   ok_langs = write_langs (option->flags);
292   bad_lang = write_langs (lang_mask);
293
294   /* Eventually this should become a hard error IMO.  */
295   warning ("command line option \"%s\" is valid for %s but not for %s",
296            text, ok_langs, bad_lang);
297
298   free (ok_langs);
299   free (bad_lang);
300 }
301
302 /* Handle the switch beginning at ARGV for the language indicated by
303    LANG_MASK.  Returns the number of switches consumed.  */
304 static unsigned int
305 handle_option (const char **argv, unsigned int lang_mask)
306 {
307   size_t opt_index;
308   const char *opt, *arg = 0;
309   char *dup = 0;
310   int value = 1;
311   unsigned int result = 0;
312   const struct cl_option *option;
313
314   opt = argv[0];
315
316   /* Drop the "no-" from negative switches.  */
317   if ((opt[1] == 'W' || opt[1] == 'f')
318       && opt[2] == 'n' && opt[3] == 'o' && opt[4] == '-')
319     {
320       size_t len = strlen (opt) - 3;
321
322       dup = xmalloc (len + 1);
323       dup[0] = '-';
324       dup[1] = opt[1];
325       memcpy (dup + 2, opt + 5, len - 2 + 1);
326       opt = dup;
327       value = 0;
328     }
329
330   opt_index = find_opt (opt + 1, lang_mask | CL_COMMON);
331   if (opt_index == cl_options_count)
332     goto done;
333
334   option = &cl_options[opt_index];
335
336   /* Reject negative form of switches that don't take negatives as
337      unrecognized.  */
338   if (!value && (option->flags & CL_REJECT_NEGATIVE))
339     goto done;
340
341   /* We've recognized this switch.  */
342   result = 1;
343
344   /* Sort out any argument the switch takes.  */
345   if (option->flags & CL_JOINED)
346     {
347       /* Have arg point to the original switch.  This is because
348          some code, such as disable_builtin_function, expects its
349          argument to be persistent until the program exits.  */
350       arg = argv[0] + cl_options[opt_index].opt_len + 1;
351       if (!value)
352         arg += strlen ("no-");
353
354       if (*arg == '\0' && !(option->flags & CL_MISSING_OK))
355         {
356           if (option->flags & CL_SEPARATE)
357             {
358               arg = argv[1];
359               result = 2;
360             }
361           else
362             /* Missing argument.  */
363             arg = NULL;
364         }
365     }
366   else if (option->flags & CL_SEPARATE)
367     {
368       arg = argv[1];
369       result = 2;
370     }
371
372   /* Now we've swallowed any potential argument, complain if this
373      is a switch for a different front end.  */
374   if (!(option->flags & (lang_mask | CL_COMMON)))
375     {
376       complain_wrong_lang (argv[0], option, lang_mask);
377       goto done;
378     }
379
380   if (arg == NULL && (option->flags & (CL_JOINED | CL_SEPARATE)))
381     {
382       if (!(*lang_hooks.missing_argument) (opt, opt_index))
383         error ("missing argument to \"%s\"", opt);
384       goto done;
385     }
386
387   /* If the switch takes an integer, convert it.  */
388   if (arg && (option->flags & CL_UINTEGER))
389     {
390       value = integral_argument (arg);
391       if (value == -1)
392         {
393           error ("argument to \"%s\" should be a non-negative integer",
394                  option->opt_text);
395           goto done;
396         }
397     }
398
399   if (option->flags & lang_mask)
400     if ((*lang_hooks.handle_option) (opt_index, arg, value) == 0)
401       result = 0;
402
403   if (result && (option->flags & CL_COMMON))
404     if (common_handle_option (opt_index, arg, value) == 0)
405       result = 0;
406
407  done:
408   if (dup)
409     free (dup);
410   return result;
411 }
412
413 /* Decode and handle the vector of command line options.  LANG_MASK
414    contains has a single bit set representing the current
415    language.  */
416 static void
417 handle_options (unsigned int argc, const char **argv, unsigned int lang_mask)
418 {
419   unsigned int n, i;
420
421   for (i = 1; i < argc; i += n)
422     {
423       const char *opt = argv[i];
424
425       /* Interpret "-" or a non-switch as a file name.  */
426       if (opt[0] != '-' || opt[1] == '\0')
427         {
428           main_input_filename = opt;
429           add_input_filename (opt);
430           n = 1;
431           continue;
432         }
433
434       n = handle_option (argv + i, lang_mask);
435
436       if (!n)
437         {
438           n = 1;
439           error ("unrecognized command line option \"%s\"", opt);
440         }
441     }
442 }
443
444 /* Handle FILENAME from the command line.  */
445 void
446 add_input_filename (const char *filename)
447 {
448   num_in_fnames++;
449   in_fnames = xrealloc (in_fnames, num_in_fnames * sizeof (in_fnames[0]));
450   in_fnames[num_in_fnames - 1] = filename;
451 }
452
453 /* Parse command line options and set default flag values.  Do minimal
454    options processing.  */
455 void
456 decode_options (unsigned int argc, const char **argv)
457 {
458   unsigned int i, lang_mask;
459
460   /* Perform language-specific options initialization.  */
461   lang_mask = (*lang_hooks.init_options) (argc, argv);
462
463   /* Scan to see what optimization level has been specified.  That will
464      determine the default value of many flags.  */
465   for (i = 1; i < argc; i++)
466     {
467       if (!strcmp (argv[i], "-O"))
468         {
469           optimize = 1;
470           optimize_size = 0;
471         }
472       else if (argv[i][0] == '-' && argv[i][1] == 'O')
473         {
474           /* Handle -Os, -O2, -O3, -O69, ...  */
475           const char *p = &argv[i][2];
476
477           if ((p[0] == 's') && (p[1] == 0))
478             {
479               optimize_size = 1;
480
481               /* Optimizing for size forces optimize to be 2.  */
482               optimize = 2;
483             }
484           else
485             {
486               const int optimize_val = read_integral_parameter (p, p - 2, -1);
487               if (optimize_val != -1)
488                 {
489                   optimize = optimize_val;
490                   optimize_size = 0;
491                 }
492             }
493         }
494     }
495
496   if (!optimize)
497     {
498       flag_merge_constants = 0;
499     }
500
501   if (optimize >= 1)
502     {
503       flag_defer_pop = 1;
504       flag_thread_jumps = 1;
505 #ifdef DELAY_SLOTS
506       flag_delayed_branch = 1;
507 #endif
508 #ifdef CAN_DEBUG_WITHOUT_FP
509       flag_omit_frame_pointer = 1;
510 #endif
511       flag_guess_branch_prob = 1;
512       flag_cprop_registers = 1;
513       flag_loop_optimize = 1;
514       flag_crossjumping = 1;
515       flag_if_conversion = 1;
516       flag_if_conversion2 = 1;
517     }
518
519   if (optimize >= 2)
520     {
521       flag_optimize_sibling_calls = 1;
522       flag_cse_follow_jumps = 1;
523       flag_cse_skip_blocks = 1;
524       flag_gcse = 1;
525       flag_expensive_optimizations = 1;
526       flag_strength_reduce = 1;
527       flag_rerun_cse_after_loop = 1;
528       flag_rerun_loop_opt = 1;
529       flag_caller_saves = 1;
530       flag_force_mem = 1;
531       flag_peephole2 = 1;
532 #ifdef INSN_SCHEDULING
533       flag_schedule_insns = 1;
534       flag_schedule_insns_after_reload = 1;
535 #endif
536       flag_regmove = 1;
537       flag_strict_aliasing = 1;
538       flag_delete_null_pointer_checks = 1;
539       flag_reorder_blocks = 1;
540       flag_reorder_functions = 1;
541     }
542
543   if (optimize >= 3)
544     {
545       flag_inline_functions = 1;
546       flag_rename_registers = 1;
547       flag_unswitch_loops = 1;
548       flag_unit_at_a_time = 1;
549     }
550
551   if (optimize < 2 || optimize_size)
552     {
553       align_loops = 1;
554       align_jumps = 1;
555       align_labels = 1;
556       align_functions = 1;
557
558       /* Don't reorder blocks when optimizing for size because extra
559          jump insns may be created; also barrier may create extra padding.
560
561          More correctly we should have a block reordering mode that tried
562          to minimize the combined size of all the jumps.  This would more
563          or less automatically remove extra jumps, but would also try to
564          use more short jumps instead of long jumps.  */
565       flag_reorder_blocks = 0;
566     }
567
568   /* Initialize whether `char' is signed.  */
569   flag_signed_char = DEFAULT_SIGNED_CHAR;
570 #ifdef DEFAULT_SHORT_ENUMS
571   /* Initialize how much space enums occupy, by default.  */
572   flag_short_enums = DEFAULT_SHORT_ENUMS;
573 #endif
574
575   /* Initialize target_flags before OPTIMIZATION_OPTIONS so the latter can
576      modify it.  */
577   target_flags = 0;
578   set_target_switch ("");
579
580   /* Unwind tables are always present in an ABI-conformant IA-64
581      object file, so the default should be ON.  */
582 #ifdef IA64_UNWIND_INFO
583   flag_unwind_tables = IA64_UNWIND_INFO;
584 #endif
585
586 #ifdef OPTIMIZATION_OPTIONS
587   /* Allow default optimizations to be specified on a per-machine basis.  */
588   OPTIMIZATION_OPTIONS (optimize, optimize_size);
589 #endif
590
591   handle_options (argc, argv, lang_mask);
592
593   if (flag_pie)
594     flag_pic = flag_pie;
595   if (flag_pic && !flag_pie)
596     flag_shlib = 1;
597
598   if (flag_no_inline == 2)
599     flag_no_inline = 0;
600   else
601     flag_really_no_inline = flag_no_inline;
602
603   /* Set flag_no_inline before the post_options () hook.  The C front
604      ends use it to determine tree inlining defaults.  FIXME: such
605      code should be lang-independent when all front ends use tree
606      inlining, in which case it, and this condition, should be moved
607      to the top of process_options() instead.  */
608   if (optimize == 0)
609     {
610       /* Inlining does not work if not optimizing,
611          so force it not to be done.  */
612       flag_no_inline = 1;
613       warn_inline = 0;
614
615       /* The c_decode_option function and decode_option hook set
616          this to `2' if -Wall is used, so we can avoid giving out
617          lots of errors for people who don't realize what -Wall does.  */
618       if (warn_uninitialized == 1)
619         warning ("-Wuninitialized is not supported without -O");
620     }
621
622   if (flag_really_no_inline == 2)
623     flag_really_no_inline = flag_no_inline;
624 }
625
626 /* Handle target- and language-independent options.  Return zero to
627    generate an "unknown option" message.  */
628 static int
629 common_handle_option (size_t scode, const char *arg,
630                       int value ATTRIBUTE_UNUSED)
631 {
632   enum opt_code code = (enum opt_code) scode;
633
634   switch (code)
635     {
636     default:
637       abort ();
638
639     case OPT__help:
640       print_help ();
641       exit_after_options = true;
642       break;
643
644     case OPT__param:
645       handle_param (arg);
646       break;
647
648     case OPT__target_help:
649       display_target_options ();
650       exit_after_options = true;
651       break;
652
653     case OPT__version:
654       print_version (stderr, "");
655       exit_after_options = true;
656       break;
657
658     case OPT_G:
659       g_switch_value = value;
660       g_switch_set = true;
661       break;
662
663     case OPT_O:
664     case OPT_Os:
665       /* Currently handled in a prescan.  */
666       break;
667
668     case OPT_W:
669       /* For backward compatibility, -W is the same as -Wextra.  */
670       set_Wextra (value);
671       break;
672
673     case OPT_Waggregate_return:
674       warn_aggregate_return = value;
675       break;
676
677     case OPT_Wcast_align:
678       warn_cast_align = value;
679       break;
680
681     case OPT_Wdeprecated_declarations:
682       warn_deprecated_decl = value;
683       break;
684
685     case OPT_Wdisabled_optimization:
686       warn_disabled_optimization = value;
687       break;
688
689     case OPT_Werror:
690       warnings_are_errors = value;
691       break;
692
693     case OPT_Wextra:
694       set_Wextra (value);
695       break;
696
697     case OPT_Winline:
698       warn_inline = value;
699       break;
700
701     case OPT_Wlarger_than_:
702       larger_than_size = value;
703       warn_larger_than = value != -1;
704       break;
705
706     case OPT_Wmissing_noreturn:
707       warn_missing_noreturn = value;
708       break;
709
710     case OPT_Wpacked:
711       warn_packed = value;
712       break;
713
714     case OPT_Wpadded:
715       warn_padded = value;
716       break;
717
718     case OPT_Wshadow:
719       warn_shadow = value;
720       break;
721
722     case OPT_Wstrict_aliasing:
723       warn_strict_aliasing = value;
724       break;
725
726     case OPT_Wswitch:
727       warn_switch = value;
728       break;
729
730     case OPT_Wswitch_default:
731       warn_switch_default = value;
732       break;
733
734     case OPT_Wswitch_enum:
735       warn_switch_enum = value;
736       break;
737
738     case OPT_Wsystem_headers:
739       warn_system_headers = value;
740       break;
741
742     case OPT_Wuninitialized:
743       warn_uninitialized = value;
744       break;
745
746     case OPT_Wunreachable_code:
747       warn_notreached = value;
748       break;
749
750     case OPT_Wunused:
751       set_Wunused (value);
752       break;
753
754     case OPT_Wunused_function:
755       warn_unused_function = value;
756       break;
757
758     case OPT_Wunused_label:
759       warn_unused_label = value;
760       break;
761
762     case OPT_Wunused_parameter:
763       warn_unused_parameter = value;
764       break;
765
766     case OPT_Wunused_value:
767       warn_unused_value = value;
768       break;
769
770     case OPT_Wunused_variable:
771       warn_unused_variable = value;
772       break;
773
774     case OPT_aux_info:
775     case OPT_aux_info_:
776       aux_info_file_name = arg;
777       flag_gen_aux_info = 1;
778       break;
779
780     case OPT_auxbase:
781       aux_base_name = arg;
782       break;
783
784     case OPT_auxbase_strip:
785       {
786         char *tmp = xstrdup (arg);
787         strip_off_ending (tmp, strlen (tmp));
788         if (tmp[0])
789           aux_base_name = tmp;
790       }
791       break;
792
793     case OPT_d:
794       decode_d_option (arg);
795       break;
796
797     case OPT_dumpbase:
798       dump_base_name = arg;
799       break;
800
801     case OPT_fPIC:
802       flag_pic = value + value;
803       break;
804
805     case OPT_fPIE:
806       flag_pie = value + value;
807       break;
808
809     case OPT_falign_functions:
810       align_functions = !value;
811       break;
812
813     case OPT_falign_functions_:
814       align_functions = value;
815       break;
816
817     case OPT_falign_jumps:
818       align_jumps = !value;
819       break;
820
821     case OPT_falign_jumps_:
822       align_jumps = value;
823       break;
824
825     case OPT_falign_labels:
826       align_labels = !value;
827       break;
828
829     case OPT_falign_labels_:
830       align_labels = value;
831       break;
832
833     case OPT_falign_loops:
834       align_loops = !value;
835       break;
836
837     case OPT_falign_loops_:
838       align_loops = value;
839       break;
840
841     case OPT_fargument_alias:
842       flag_argument_noalias = !value;
843       break;
844
845     case OPT_fargument_noalias:
846       flag_argument_noalias = value;
847       break;
848
849     case OPT_fargument_noalias_global:
850       flag_argument_noalias = value + value;
851       break;
852
853     case OPT_fasynchronous_unwind_tables:
854       flag_asynchronous_unwind_tables = value;
855       break;
856
857     case OPT_fbounds_check:
858       flag_bounds_check = value;
859       break;
860
861     case OPT_fbranch_count_reg:
862       flag_branch_on_count_reg = value;
863       break;
864
865     case OPT_fbranch_probabilities:
866       flag_branch_probabilities = value;
867       break;
868
869     case OPT_fbranch_target_load_optimize:
870       flag_branch_target_load_optimize = value;
871       break;
872
873     case OPT_fbranch_target_load_optimize2:
874       flag_branch_target_load_optimize2 = value;
875       break;
876
877     case OPT_fcall_used_:
878       fix_register (arg, 0, 1);
879       break;
880
881     case OPT_fcall_saved_:
882       fix_register (arg, 0, 0);
883       break;
884
885     case OPT_fcaller_saves:
886       flag_caller_saves = value;
887       break;
888
889     case OPT_fcommon:
890       flag_no_common = !value;
891       break;
892
893     case OPT_fcprop_registers:
894       flag_cprop_registers = value;
895       break;
896
897     case OPT_fcrossjumping:
898       flag_crossjumping = value;
899       break;
900
901     case OPT_fcse_follow_jumps:
902       flag_cse_follow_jumps = value;
903       break;
904
905     case OPT_fcse_skip_blocks:
906       flag_cse_skip_blocks = value;
907       break;
908
909     case OPT_fdata_sections:
910       flag_data_sections = value;
911       break;
912
913     case OPT_fdefer_pop:
914       flag_defer_pop = value;
915       break;
916
917     case OPT_fdelayed_branch:
918       flag_delayed_branch = value;
919       break;
920
921     case OPT_fdelete_null_pointer_checks:
922       flag_delete_null_pointer_checks = value;
923       break;
924
925     case OPT_fdiagnostics_show_location_:
926       if (!strcmp (arg, "once"))
927         diagnostic_prefixing_rule (global_dc) = DIAGNOSTICS_SHOW_PREFIX_ONCE;
928       else if (!strcmp (arg, "every-line"))
929         diagnostic_prefixing_rule (global_dc)
930           = DIAGNOSTICS_SHOW_PREFIX_EVERY_LINE;
931       else
932         return 0;
933       break;
934
935     case OPT_fdump_unnumbered:
936       flag_dump_unnumbered = value;
937       break;
938
939     case OPT_feliminate_dwarf2_dups:
940       flag_eliminate_dwarf2_dups = value;
941       break;
942
943     case OPT_feliminate_unused_debug_types:
944       flag_eliminate_unused_debug_types = value;
945       break;
946
947     case OPT_feliminate_unused_debug_symbols:
948       flag_debug_only_used_symbols = value;
949       break;
950
951     case OPT_fexceptions:
952       flag_exceptions = value;
953       break;
954
955     case OPT_fexpensive_optimizations:
956       flag_expensive_optimizations = value;
957       break;
958
959     case OPT_ffast_math:
960       set_fast_math_flags (value);
961       break;
962
963     case OPT_ffinite_math_only:
964       flag_finite_math_only = value;
965       break;
966
967     case OPT_ffixed_:
968       fix_register (arg, 1, 1);
969       break;
970
971     case OPT_ffunction_cse:
972       flag_no_function_cse = !value;
973       break;
974
975     case OPT_ffloat_store:
976       flag_float_store = value;
977       break;
978
979     case OPT_fforce_addr:
980       flag_force_addr = value;
981       break;
982
983     case OPT_fforce_mem:
984       flag_force_mem = value;
985       break;
986
987     case OPT_ffunction_sections:
988       flag_function_sections = value;
989       break;
990
991     case OPT_fgcse:
992       flag_gcse = value;
993       break;
994
995     case OPT_fgcse_lm:
996       flag_gcse_lm = value;
997       break;
998
999     case OPT_fgcse_sm:
1000       flag_gcse_sm = value;
1001       break;
1002
1003     case OPT_fgnu_linker:
1004       flag_gnu_linker = value;
1005       break;
1006
1007     case OPT_fguess_branch_probability:
1008       flag_guess_branch_prob = value;
1009       break;
1010
1011     case OPT_fident:
1012       flag_no_ident = !value;
1013       break;
1014
1015     case OPT_fif_conversion:
1016       flag_if_conversion = value;
1017       break;
1018
1019     case OPT_fif_conversion2:
1020       flag_if_conversion2 = value;
1021       break;
1022
1023     case OPT_finhibit_size_directive:
1024       flag_inhibit_size_directive = value;
1025       break;
1026
1027     case OPT_finline:
1028       flag_no_inline = !value;
1029       break;
1030
1031     case OPT_finline_functions:
1032       flag_inline_functions = value;
1033       break;
1034
1035     case OPT_finline_limit_:
1036     case OPT_finline_limit_eq:
1037       set_param_value ("max-inline-insns", value);
1038       set_param_value ("max-inline-insns-single", value / 2);
1039       set_param_value ("max-inline-insns-auto", value / 2);
1040       set_param_value ("max-inline-insns-rtl", value);
1041       if (value / 4 < MIN_INLINE_INSNS)
1042         {
1043           if (value / 4 > 10)
1044             set_param_value ("min-inline-insns", value / 4);
1045           else
1046             set_param_value ("min-inline-insns", 10);
1047         }
1048       break;
1049
1050     case OPT_finstrument_functions:
1051       flag_instrument_function_entry_exit = value;
1052       break;
1053
1054     case OPT_fkeep_inline_functions:
1055       flag_keep_inline_functions =value;
1056       break;
1057
1058     case OPT_fkeep_static_consts:
1059       flag_keep_static_consts = value;
1060       break;
1061
1062     case OPT_fleading_underscore:
1063       flag_leading_underscore = value;
1064       break;
1065
1066     case OPT_floop_optimize:
1067       flag_loop_optimize = value;
1068       break;
1069
1070     case OPT_fmath_errno:
1071       flag_errno_math = value;
1072       break;
1073
1074     case OPT_fmem_report:
1075       mem_report = value;
1076       break;
1077
1078     case OPT_fmerge_all_constants:
1079       flag_merge_constants = value + value;
1080       break;
1081
1082     case OPT_fmerge_constants:
1083       flag_merge_constants = value;
1084       break;
1085
1086     case OPT_fmessage_length_:
1087       pp_set_line_maximum_length (global_dc->printer, value);
1088       break;
1089
1090     case OPT_fmove_all_movables:
1091       flag_move_all_movables = value;
1092       break;
1093
1094     case OPT_fnew_ra:
1095       flag_new_regalloc = value;
1096       break;
1097
1098     case OPT_fnon_call_exceptions:
1099       flag_non_call_exceptions = value;
1100       break;
1101
1102     case OPT_fold_unroll_all_loops:
1103       flag_old_unroll_all_loops = value;
1104       break;
1105
1106     case OPT_fold_unroll_loops:
1107       flag_old_unroll_loops = value;
1108       break;
1109
1110     case OPT_fomit_frame_pointer:
1111       flag_omit_frame_pointer = value;
1112       break;
1113
1114     case OPT_foptimize_register_move:
1115       flag_regmove = value;
1116       break;
1117
1118     case OPT_foptimize_sibling_calls:
1119       flag_optimize_sibling_calls = value;
1120       break;
1121
1122     case OPT_fpack_struct:
1123       flag_pack_struct = value;
1124       break;
1125
1126     case OPT_fpeel_loops:
1127       flag_peel_loops = value;
1128       break;
1129
1130     case OPT_fpcc_struct_return:
1131       flag_pcc_struct_return = value;
1132       break;
1133
1134     case OPT_fpeephole:
1135       flag_no_peephole = !value;
1136       break;
1137
1138     case OPT_fpeephole2:
1139       flag_peephole2 = value;
1140       break;
1141
1142     case OPT_fpic:
1143       flag_pic = value;
1144       break;
1145
1146     case OPT_fpie:
1147       flag_pie = value;
1148       break;
1149
1150     case OPT_fprefetch_loop_arrays:
1151       flag_prefetch_loop_arrays = value;
1152       break;
1153
1154     case OPT_fprofile:
1155       profile_flag = value;
1156       break;
1157
1158     case OPT_fprofile_arcs:
1159       profile_arc_flag = value;
1160       break;
1161
1162     case OPT_frandom_seed:
1163       /* The real switch is -fno-random-seed.  */
1164       if (value)
1165         return 0;
1166       flag_random_seed = NULL;
1167       break;
1168
1169     case OPT_frandom_seed_:
1170       flag_random_seed = arg;
1171       break;
1172
1173     case OPT_freduce_all_givs:
1174       flag_reduce_all_givs = value;
1175       break;
1176
1177     case OPT_freg_struct_return:
1178       flag_pcc_struct_return = !value;
1179       break;
1180
1181     case OPT_fregmove:
1182       flag_regmove = value;
1183       break;
1184
1185     case OPT_frename_registers:
1186       flag_rename_registers = value;
1187       break;
1188
1189     case OPT_freorder_blocks:
1190       flag_reorder_blocks = value;
1191       break;
1192
1193     case OPT_freorder_functions:
1194       flag_reorder_functions = value;
1195       break;
1196
1197     case OPT_frerun_cse_after_loop:
1198       flag_rerun_cse_after_loop = value;
1199       break;
1200
1201     case OPT_frerun_loop_opt:
1202       flag_rerun_loop_opt = value;
1203       break;
1204
1205     case OPT_fsched_interblock:
1206       flag_schedule_interblock= value;
1207       break;
1208
1209     case OPT_fsched_spec:
1210       flag_schedule_speculative = value;
1211       break;
1212
1213     case OPT_fsched_spec_load:
1214       flag_schedule_speculative_load = value;
1215       break;
1216
1217     case OPT_fsched_spec_load_dangerous:
1218       flag_schedule_speculative_load_dangerous = value;
1219       break;
1220
1221     case OPT_fsched_verbose_:
1222 #ifdef INSN_SCHEDULING
1223       fix_sched_param ("verbose", arg);
1224       break;
1225 #else
1226       return 0;
1227 #endif
1228
1229     case OPT_fsched2_use_superblocks:
1230       flag_sched2_use_superblocks = value;
1231       break;
1232
1233     case OPT_fsched2_use_traces:
1234       flag_sched2_use_traces = value;
1235       break;
1236
1237     case OPT_fschedule_insns:
1238       flag_schedule_insns = value;
1239       break;
1240
1241     case OPT_fschedule_insns2:
1242       flag_schedule_insns_after_reload = value;
1243       break;
1244
1245     case OPT_fshared_data:
1246       flag_shared_data = value;
1247       break;
1248
1249     case OPT_fsignaling_nans:
1250       flag_signaling_nans = value;
1251       break;
1252
1253     case OPT_fsingle_precision_constant:
1254       flag_single_precision_constant = value;
1255       break;
1256
1257     case OPT_fssa:
1258       flag_ssa = value;
1259       break;
1260
1261     case OPT_fssa_ccp:
1262       flag_ssa_ccp = value;
1263       break;
1264
1265     case OPT_fssa_dce:
1266       flag_ssa_dce = value;
1267       break;
1268
1269     case OPT_fstack_check:
1270       flag_stack_check = value;
1271       break;
1272
1273     case OPT_fstack_limit:
1274       /* The real switch is -fno-stack-limit.  */
1275       if (value)
1276         return 0;
1277       stack_limit_rtx = NULL_RTX;
1278       break;
1279
1280     case OPT_fstack_limit_register_:
1281       {
1282         int reg = decode_reg_name (arg);
1283         if (reg < 0)
1284           error ("unrecognized register name \"%s\"", arg);
1285         else
1286           stack_limit_rtx = gen_rtx_REG (Pmode, reg);
1287       }
1288       break;
1289
1290     case OPT_fstack_limit_symbol_:
1291       stack_limit_rtx = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (arg));
1292       break;
1293
1294     case OPT_fstrength_reduce:
1295       flag_strength_reduce = value;
1296       break;
1297
1298     case OPT_fstrict_aliasing:
1299       flag_strict_aliasing = value;
1300       break;
1301
1302     case OPT_fsyntax_only:
1303       flag_syntax_only = value;
1304       break;
1305
1306     case OPT_ftest_coverage:
1307       flag_test_coverage = value;
1308       break;
1309
1310     case OPT_fthread_jumps:
1311       flag_thread_jumps = value;
1312       break;
1313
1314     case OPT_ftime_report:
1315       time_report = value;
1316       break;
1317
1318     case OPT_ftls_model_:
1319       if (!strcmp (arg, "global-dynamic"))
1320         flag_tls_default = TLS_MODEL_GLOBAL_DYNAMIC;
1321       else if (!strcmp (arg, "local-dynamic"))
1322         flag_tls_default = TLS_MODEL_LOCAL_DYNAMIC;
1323       else if (!strcmp (arg, "initial-exec"))
1324         flag_tls_default = TLS_MODEL_INITIAL_EXEC;
1325       else if (!strcmp (arg, "local-exec"))
1326         flag_tls_default = TLS_MODEL_LOCAL_EXEC;
1327       else
1328         warning ("unknown tls-model \"%s\"", arg);
1329       break;
1330
1331     case OPT_ftracer:
1332       flag_tracer = value;
1333       break;
1334
1335     case OPT_ftrapping_math:
1336       flag_trapping_math = value;
1337       break;
1338
1339     case OPT_ftrapv:
1340       flag_trapv = value;
1341       break;
1342
1343     case OPT_funit_at_a_time:
1344       flag_unit_at_a_time = value;
1345       break;
1346
1347     case OPT_funroll_all_loops:
1348       flag_unroll_all_loops = value;
1349       break;
1350
1351     case OPT_funroll_loops:
1352       flag_unroll_loops = value;
1353       break;
1354
1355     case OPT_funsafe_math_optimizations:
1356       flag_unsafe_math_optimizations = value;
1357       break;
1358
1359     case OPT_funswitch_loops:
1360       flag_unswitch_loops = value;
1361       break;
1362
1363     case OPT_funwind_tables:
1364       flag_unwind_tables = value;
1365       break;
1366
1367     case OPT_fverbose_asm:
1368       flag_verbose_asm = value;
1369       break;
1370       
1371     case OPT_fwrapv:
1372       flag_wrapv = value;
1373       break;
1374
1375     case OPT_fwritable_strings:
1376       flag_writable_strings = value;
1377       break;
1378
1379     case OPT_fzero_initialized_in_bss:
1380       flag_zero_initialized_in_bss = value;
1381       break;
1382
1383     case OPT_g:
1384       decode_g_option (arg);
1385       break;
1386
1387     case OPT_m:
1388       set_target_switch (arg);
1389       break;
1390
1391     case OPT_o:
1392       asm_file_name = arg;
1393       break;
1394
1395     case OPT_p:
1396       profile_flag = 1;
1397       break;
1398
1399     case OPT_pedantic:
1400       pedantic = 1;
1401       break;
1402
1403     case OPT_pedantic_errors:
1404       flag_pedantic_errors = pedantic = 1;
1405       break;
1406
1407     case OPT_quiet:
1408       quiet_flag = 1;
1409       break;
1410
1411     case OPT_version:
1412       version_flag = 1;
1413       break;
1414
1415     case OPT_w:
1416       inhibit_warnings = true;
1417       break;      
1418     }
1419
1420   return 1;
1421 }
1422
1423 /* Handle --param NAME=VALUE.  */
1424 static void
1425 handle_param (const char *carg)
1426 {
1427   char *equal, *arg;
1428   int value;
1429
1430   arg = xstrdup (carg);
1431   equal = strchr (arg, '=');
1432   if (!equal)
1433     error ("%s: --param arguments should be of the form NAME=VALUE", arg);
1434   else
1435     {
1436       value = integral_argument (equal + 1);
1437       if (value == -1)
1438         error ("invalid --param value `%s'", equal + 1);
1439       else
1440         {
1441           *equal = '\0';
1442           set_param_value (arg, value);
1443         }
1444     }
1445
1446   free (arg);
1447 }
1448
1449 /* Handle -W and -Wextra.  */
1450 static void
1451 set_Wextra (int setting)
1452 {
1453   extra_warnings = setting;
1454   warn_unused_value = setting;
1455   warn_unused_parameter = (setting && maybe_warn_unused_parameter);
1456
1457   /* We save the value of warn_uninitialized, since if they put
1458      -Wuninitialized on the command line, we need to generate a
1459      warning about not using it without also specifying -O.  */
1460   if (setting == 0)
1461     warn_uninitialized = 0;
1462   else if (warn_uninitialized != 1)
1463     warn_uninitialized = 2;
1464 }
1465
1466 /* Initialize unused warning flags.  */
1467 void
1468 set_Wunused (int setting)
1469 {
1470   warn_unused_function = setting;
1471   warn_unused_label = setting;
1472   /* Unused function parameter warnings are reported when either
1473      ``-Wextra -Wunused'' or ``-Wunused-parameter'' is specified.
1474      Thus, if -Wextra has already been seen, set warn_unused_parameter;
1475      otherwise set maybe_warn_extra_parameter, which will be picked up
1476      by set_Wextra.  */
1477   maybe_warn_unused_parameter = setting;
1478   warn_unused_parameter = (setting && extra_warnings);
1479   warn_unused_variable = setting;
1480   warn_unused_value = setting;
1481 }
1482
1483 /* The following routines are useful in setting all the flags that
1484    -ffast-math and -fno-fast-math imply.  */
1485 void
1486 set_fast_math_flags (int set)
1487 {
1488   flag_trapping_math = !set;
1489   flag_unsafe_math_optimizations = set;
1490   flag_finite_math_only = set;
1491   flag_errno_math = !set;
1492   if (set)
1493     flag_signaling_nans = 0;
1494 }
1495
1496 /* Return true iff flags are set as if -ffast-math.  */
1497 bool
1498 fast_math_flags_set_p (void)
1499 {
1500   return (!flag_trapping_math
1501           && flag_unsafe_math_optimizations
1502           && flag_finite_math_only
1503           && !flag_errno_math);
1504 }
1505
1506 /* Output --help text.  */
1507 static void
1508 print_help (void)
1509 {
1510   size_t i;
1511   const char *p;
1512
1513   GET_ENVIRONMENT (p, "COLUMNS");
1514   if (p)
1515     {
1516       int value = atoi (p);
1517       if (value > 0)
1518         columns = value;
1519     }
1520
1521   puts (_("The following options are language-independent:\n"));
1522
1523   print_filtered_help (CL_COMMON);
1524   print_param_help ();
1525
1526   for (i = 0; lang_names[i]; i++)
1527     {
1528       printf (_("The %s front end recognizes the following options:\n\n"),
1529               lang_names[i]);
1530       print_filtered_help (1U << i);
1531     }
1532
1533   display_help ();
1534 }
1535
1536 /* Print the help for --param.  */
1537 static void
1538 print_param_help (void)
1539 {
1540   size_t i;
1541
1542   puts (_("The --param option recognizes the following as parameters:\n"));
1543
1544   for (i = 0; i < LAST_PARAM; i++)
1545     {
1546       const char *help = compiler_params[i].help;
1547       const char *param = compiler_params[i].option;
1548
1549       if (help == NULL || *help == '\0')
1550         help = undocumented_msg;
1551
1552       /* Get the translation.  */
1553       help = _(help);
1554
1555       wrap_help (help, param, strlen (param));
1556     }
1557
1558   putchar ('\n');
1559 }
1560
1561 /* Print help for a specific front-end, etc.  */
1562 static void
1563 print_filtered_help (unsigned int flag)
1564 {
1565   unsigned int i, len, filter, indent = 0;
1566   bool duplicates = false;
1567   const char *help, *opt, *tab;
1568   static char *printed;
1569
1570   if (flag == CL_COMMON)
1571     {
1572       filter = flag;
1573       if (!printed)
1574         printed = xmalloc (cl_options_count);
1575       memset (printed, 0, cl_options_count);
1576     }
1577   else
1578     {
1579       /* Don't print COMMON options twice.  */
1580       filter = flag | CL_COMMON;
1581
1582       for (i = 0; i < cl_options_count; i++)
1583         {
1584           if ((cl_options[i].flags & filter) != flag)
1585             continue;
1586
1587           /* Skip help for internal switches.  */
1588           if (cl_options[i].flags & CL_UNDOCUMENTED)
1589             continue;
1590
1591           /* Skip switches that have already been printed, mark them to be
1592              listed later.  */
1593           if (printed[i])
1594             {
1595               duplicates = true;
1596               indent = print_switch (cl_options[i].opt_text, indent);
1597             }
1598         }
1599
1600       if (duplicates)
1601         {
1602           putchar ('\n');
1603           putchar ('\n');
1604         }
1605     }
1606
1607   for (i = 0; i < cl_options_count; i++)
1608     {
1609       if ((cl_options[i].flags & filter) != flag)
1610         continue;
1611
1612       /* Skip help for internal switches.  */
1613       if (cl_options[i].flags & CL_UNDOCUMENTED)
1614         continue;
1615
1616       /* Skip switches that have already been printed.  */
1617       if (printed[i])
1618         continue;
1619
1620       printed[i] = true;
1621
1622       help = cl_options[i].help;
1623       if (!help)
1624         help = undocumented_msg;
1625
1626       /* Get the translation.  */
1627       help = _(help);
1628
1629       tab = strchr (help, '\t');
1630       if (tab)
1631         {
1632           len = tab - help;
1633           opt = help;
1634           help = tab + 1;
1635         }
1636       else
1637         {
1638           opt = cl_options[i].opt_text;
1639           len = strlen (opt);
1640         }
1641
1642       wrap_help (help, opt, len);
1643     }
1644
1645   putchar ('\n');
1646 }
1647
1648 /* Output ITEM, of length ITEM_WIDTH, in the left column, followed by
1649    word-wrapped HELP in a second column.  */
1650 static unsigned int
1651 print_switch (const char *text, unsigned int indent)
1652 {
1653   unsigned int len = strlen (text) + 1; /* trailing comma */
1654
1655   if (indent)
1656     {
1657       putchar (',');
1658       if (indent + len > columns)
1659         {
1660           putchar ('\n');
1661           putchar (' ');
1662           indent = 1;
1663         }
1664     }
1665   else
1666     putchar (' ');
1667
1668   putchar (' ');
1669   fputs (text, stdout);
1670
1671   return indent + len + 1;
1672 }
1673
1674 /* Output ITEM, of length ITEM_WIDTH, in the left column, followed by
1675    word-wrapped HELP in a second column.  */
1676 static void
1677 wrap_help (const char *help, const char *item, unsigned int item_width)
1678 {
1679   unsigned int col_width = 27;
1680   unsigned int remaining, room, len;
1681
1682   remaining = strlen (help);
1683
1684   do
1685     {
1686       room = columns - 3 - MAX (col_width, item_width);
1687       if (room > columns)
1688         room = 0;
1689       len = remaining;
1690
1691       if (room < len)
1692         {
1693           unsigned int i;
1694
1695           for (i = 0; help[i]; i++)
1696             {
1697               if (i >= room && len != remaining)
1698                 break;
1699               if (help[i] == ' ')
1700                 len = i;
1701               else if ((help[i] == '-' || help[i] == '/')
1702                        && help[i + 1] != ' '
1703                        && ISALPHA (help[i - 1]))
1704                 len = i + 1;
1705             }
1706         }
1707
1708       printf( "  %-*.*s %.*s\n", col_width, item_width, item, len, help);
1709       item_width = 0;
1710       while (help[len] == ' ')
1711         len++;
1712       help += len;
1713       remaining -= len;
1714     }
1715   while (remaining);
1716 }