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