OSDN Git Service

* c-opts.c (missing_arg): Make non-static.
[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 "coretypes.h"
25 #include "tm.h"
26 #include "tree.h"
27 #include "rtl.h"
28 #include "ggc.h"
29 #include "output.h"
30 #include "langhooks.h"
31 #include "opts.h"
32 #include "options.h"
33 #include "flags.h"
34 #include "toplev.h"
35 #include "params.h"
36 #include "diagnostic.h"
37
38 /* Value of the -G xx switch, and whether it was passed or not.  */
39 unsigned HOST_WIDE_INT g_switch_value;
40 bool g_switch_set;
41
42 /* True if we should exit after parsing options.  */
43 bool exit_after_options;
44
45 /* If -version.  */
46 bool version_flag;
47
48 /* Print various extra warnings.  -W/-Wextra.  */
49 bool extra_warnings;
50
51 /* Don't print warning messages.  -w.  */
52 bool inhibit_warnings;
53
54 /* Treat warnings as errors.  -Werror.  */
55 bool warnings_are_errors;
56
57 /* Warn if a function returns an aggregate, since there are often
58    incompatible calling conventions for doing this.  */
59 bool warn_aggregate_return;
60
61 /* Nonzero means warn about pointer casts that increase the required
62    alignment of the target type (and might therefore lead to a crash
63    due to a misaligned access).  */
64 bool warn_cast_align;
65
66 /* Nonzero means warn about uses of __attribute__((deprecated))
67    declarations.  */
68 bool warn_deprecated_decl = true;
69
70 /* Warn when an optimization pass is disabled.  */
71 bool warn_disabled_optimization;
72
73 /* Nonzero means warn if inline function is too large.  */
74 bool warn_inline;
75
76 /* True to warn about any objects definitions whose size is larger
77    than N bytes.  Also want about function definitions whose returned
78    values are larger than N bytes, where N is `larger_than_size'.  */
79 bool warn_larger_than;
80 HOST_WIDE_INT larger_than_size;
81
82 /* Warn about functions which might be candidates for attribute noreturn.  */
83 bool warn_missing_noreturn;
84
85 /* True to warn about code which is never reached.  */
86 bool warn_notreached;
87
88 /* Warn if packed attribute on struct is unnecessary and inefficient.  */
89 bool warn_packed;
90
91 /* Warn when gcc pads a structure to an alignment boundary.  */
92 bool warn_padded;
93
94 /* True means warn about all declarations which shadow others.  */
95 bool warn_shadow;
96
97 /* Nonzero means warn about constructs which might not be
98    strict-aliasing safe.  */
99 bool warn_strict_aliasing;
100
101 /* True to warn if a switch on an enum, that does not have a default
102    case, fails to have a case for every enum value.  */
103 bool warn_switch;
104
105 /* Warn if a switch does not have a default case.  */
106 bool warn_switch_default;
107
108 /* Warn if a switch on an enum fails to have a case for every enum
109    value (regardless of the presence or otherwise of a default case).  */
110 bool warn_switch_enum;
111
112 /* Don't suppress warnings from system headers.  -Wsystem-headers.  */
113 bool warn_system_headers;
114
115 /* True to warn about variables used before they are initialized.  */
116 int warn_uninitialized;
117
118 /* True to warn about unused variables, functions et.al.  */
119 bool warn_unused_function;
120 bool warn_unused_label;
121 bool warn_unused_parameter;
122 bool warn_unused_variable;
123 bool warn_unused_value;
124
125 /* Hack for cooperation between set_Wunused and set_Wextra.  */
126 static bool maybe_warn_unused_parameter;
127
128 static size_t find_opt (const char *, int);
129 static int common_handle_option (size_t scode, const char *arg, int value);
130 static void handle_param (const char *);
131 static void set_Wextra (int);
132 static unsigned int handle_option (char **argv, unsigned int lang_mask);
133 static char *write_langs (unsigned int lang_mask);
134 static void complain_wrong_lang (const char *, const struct cl_option *,
135                                  unsigned int lang_mask);
136
137 /* Perform a binary search to find which option the command-line INPUT
138    matches.  Returns its index in the option array, and N_OPTS
139    (cl_options_count) on failure.
140
141    This routine is quite subtle.  A normal binary search is not good
142    enough because some options can be suffixed with an argument, and
143    multiple sub-matches can occur, e.g. input of "-pedantic" matching
144    the initial substring of "-pedantic-errors".
145
146    A more complicated example is -gstabs.  It should match "-g" with
147    an argument of "stabs".  Suppose, however, that the number and list
148    of switches are such that the binary search tests "-gen-decls"
149    before having tested "-g".  This doesn't match, and as "-gen-decls"
150    is less than "-gstabs", it will become the lower bound of the
151    binary search range, and "-g" will never be seen.  To resolve this
152    issue, opts.sh makes "-gen-decls" point, via the back_chain member,
153    to "-g" so that failed searches that end between "-gen-decls" and
154    the lexicographically subsequent switch know to go back and see if
155    "-g" causes a match (which it does in this example).
156
157    This search is done in such a way that the longest match for the
158    front end in question wins.  If there is no match for the current
159    front end, the longest match for a different front end is returned
160    (or N_OPTS if none) and the caller emits an error message.  */
161 static size_t
162 find_opt (const char *input, int lang_mask)
163 {
164   size_t mn, mx, md, opt_len;
165   size_t match_wrong_lang;
166   int comp;
167
168   mn = 0;
169   mx = cl_options_count;
170
171   /* Find mn such this lexicographical inequality holds:
172      cl_options[mn] <= input < cl_options[mn + 1].  */
173   while (mx - mn > 1)
174     {
175       md = (mn + mx) / 2;
176       opt_len = cl_options[md].opt_len;
177       comp = strncmp (input, cl_options[md].opt_text, opt_len);
178
179       if (comp < 0)
180         mx = md;
181       else
182         mn = md;
183     }
184
185   /* This is the switch that is the best match but for a different
186      front end, or cl_options_count if there is no match at all.  */
187   match_wrong_lang = cl_options_count;
188
189   /* Backtrace the chain of possible matches, returning the longest
190      one, if any, that fits best.  With current GCC switches, this
191      loop executes at most twice.  */
192   do
193     {
194       const struct cl_option *opt = &cl_options[mn];
195
196       /* Is this switch a prefix of the input?  */
197       if (!strncmp (input, opt->opt_text, opt->opt_len))
198         {
199           /* If language is OK, and the match is exact or the switch
200              takes a joined argument, return it.  */
201           if ((opt->flags & lang_mask)
202               && (input[opt->opt_len] == '\0' || (opt->flags & CL_JOINED)))
203             return mn;
204
205           /* If we haven't remembered a prior match, remember this
206              one.  Any prior match is necessarily better.  */
207           if (match_wrong_lang == cl_options_count)
208             match_wrong_lang = mn;
209         }
210
211       /* Try the next possibility.  This is cl_options_count if there
212          are no more.  */
213       mn = opt->back_chain;
214     }
215   while (mn != cl_options_count);
216
217   /* Return the best wrong match, or cl_options_count if none.  */
218   return match_wrong_lang;
219 }
220
221 /* If ARG is a non-negative integer made up solely of digits, return its
222    value, otherwise return -1.  */
223 static int
224 integral_argument (const char *arg)
225 {
226   const char *p = arg;
227
228   while (*p && ISDIGIT (*p))
229     p++;
230
231   if (*p == '\0')
232     return atoi (arg);
233
234   return -1;
235 }
236
237 /* Return a malloced slash-separated list of languages in MASK.  */
238 static char *
239 write_langs (unsigned int mask)
240 {
241   unsigned int n = 0, len = 0;
242   const char *lang_name;
243   char *result;
244
245   for (n = 0; (lang_name = lang_names[n]) != 0; n++)
246     if (mask & (1U << n))
247       len += strlen (lang_name) + 1;
248
249   result = xmalloc (len);
250   len = 0;
251   for (n = 0; (lang_name = lang_names[n]) != 0; n++)
252     if (mask & (1U << n))
253       {
254         if (len)
255           result[len++] = '/';
256         strcpy (result + len, lang_name);
257         len += strlen (lang_name);
258       }
259
260   result[len] = 0;
261
262   return result;
263 }
264
265 /* Complain that switch OPT_INDEX does not apply to this front end.  */
266 static void
267 complain_wrong_lang (const char *text, const struct cl_option *option,
268                      unsigned int lang_mask)
269 {
270   char *ok_langs, *bad_lang;
271
272   ok_langs = write_langs (option->flags);
273   bad_lang = write_langs (lang_mask);
274
275   /* Eventually this should become a hard error IMO.  */
276   warning ("command line option \"%s\" is valid for %s but not for %s",
277            text, ok_langs, bad_lang);
278
279   free (ok_langs);
280   free (bad_lang);
281 }
282
283 /* Handle the switch beginning at ARGV for the language indicated by
284    LANG_MASK.  Returns the number of switches consumed.  */
285 static unsigned int
286 handle_option (char **argv, unsigned int lang_mask)
287 {
288   size_t opt_index;
289   const char *opt, *arg = 0;
290   char *dup = 0;
291   int value = 1;
292   unsigned int result = 0;
293   const struct cl_option *option;
294
295   opt = argv[0];
296
297   /* Interpret "-" or a non-switch as a file name.  */
298   if (opt[0] != '-' || opt[1] == '\0')
299     {
300       opt_index = cl_options_count;
301       arg = opt;
302       main_input_filename = opt;
303       result = (*lang_hooks.handle_option) (opt_index, arg, value);
304     }
305   else
306     {
307       /* Drop the "no-" from negative switches.  */
308       if ((opt[1] == 'W' || opt[1] == 'f')
309           && opt[2] == 'n' && opt[3] == 'o' && opt[4] == '-')
310         {
311           size_t len = strlen (opt) - 3;
312
313           dup = xmalloc (len + 1);
314           dup[0] = '-';
315           dup[1] = opt[1];
316           memcpy (dup + 2, opt + 5, len - 2 + 1);
317           opt = dup;
318           value = 0;
319         }
320
321       opt_index = find_opt (opt + 1, lang_mask | CL_COMMON);
322       if (opt_index == cl_options_count)
323         goto done;
324
325       option = &cl_options[opt_index];
326
327       /* Reject negative form of switches that don't take negatives as
328          unrecognized.  */
329       if (!value && (option->flags & CL_REJECT_NEGATIVE))
330         goto done;
331
332       /* We've recognized this switch.  */
333       result = 1;
334
335       /* Sort out any argument the switch takes.  */
336       if (option->flags & CL_JOINED)
337         {
338           /* Have arg point to the original switch.  This is because
339              some code, such as disable_builtin_function, expects its
340              argument to be persistent until the program exits.  */
341           arg = argv[0] + cl_options[opt_index].opt_len + 1;
342           if (!value)
343             arg += strlen ("no-");
344
345           if (*arg == '\0' && !(option->flags & CL_MISSING_OK))
346             {
347               if (option->flags & CL_SEPARATE)
348                 {
349                   arg = argv[1];
350                   result = 2;
351                 }
352               else
353                 /* Missing argument.  */
354                 arg = NULL;
355             }
356         }
357       else if (option->flags & CL_SEPARATE)
358         {
359           arg = argv[1];
360           result = 2;
361         }
362
363       /* Now we've swallowed any potential argument, complain if this
364          is a switch for a different front end.  */
365       if (!(option->flags & (lang_mask | CL_COMMON)))
366         {
367           complain_wrong_lang (argv[0], option, lang_mask);
368           goto done;
369         }
370
371       if (arg == NULL && (option->flags & (CL_JOINED | CL_SEPARATE)))
372         {
373           error ("missing argument to \"-%s\"", argv[0]);
374           goto done;
375         }
376
377       /* If the switch takes an integer, convert it.  */
378       if (arg && (option->flags & CL_UINTEGER))
379         {
380           value = integral_argument (arg);
381           if (value == -1)
382             {
383               error ("argument to \"-%s\" should be a non-negative integer",
384                      option->opt_text);
385               goto done;
386             }
387         }
388
389       if (option->flags & lang_mask)
390         if ((*lang_hooks.handle_option) (opt_index, arg, value) == 0)
391           result = 0;
392
393       if (result && (option->flags & CL_COMMON))
394         if (common_handle_option (opt_index, arg, value) == 0)
395           result = 0;
396     }
397
398  done:
399   if (dup)
400     free (dup);
401   return result;
402 }
403
404 /* Decode and handle the vector of command line options.  LANG_MASK
405    contains has a single bit set representing the current
406    language.  */
407 void
408 handle_options (unsigned int argc, char **argv, unsigned int lang_mask)
409 {
410   unsigned int n, i;
411
412   for (i = 1; i < argc; i += n)
413     {
414       n = handle_option (argv + i, lang_mask);
415
416       if (!n)
417         {
418           n = 1;
419           error ("unrecognized command line option \"%s\"", argv[i]);
420         }
421     }
422 }
423
424 /* Handle target- and language-independent options.  Return zero to
425    generate an "unknown option" message.  */
426 static int
427 common_handle_option (size_t scode, const char *arg,
428                       int value ATTRIBUTE_UNUSED)
429 {
430   const struct cl_option *option = &cl_options[scode];
431   enum opt_code code = (enum opt_code) scode;
432
433   if (arg == NULL && (option->flags & (CL_JOINED | CL_SEPARATE)))
434     {
435       error ("missing argument to \"-%s\"", option->opt_text);
436       return 1;
437     }
438
439   switch (code)
440     {
441     default:
442       abort ();
443
444     case OPT__help:
445       display_help ();
446       exit_after_options = true;
447       break;
448
449     case OPT__param:
450       handle_param (arg);
451       break;
452
453     case OPT__target_help:
454       display_target_options ();
455       exit_after_options = true;
456       break;
457
458     case OPT__version:
459       print_version (stderr, "");
460       exit_after_options = true;
461       break;
462
463     case OPT_G:
464       g_switch_value = value;
465       g_switch_set = true;
466       break;
467
468     case OPT_O:
469     case OPT_Os:
470       /* Currently handled in a prescan.  */
471       break;
472
473     case OPT_W:
474       /* For backward compatibility, -W is the same as -Wextra.  */
475       set_Wextra (value);
476       break;
477
478     case OPT_Waggregate_return:
479       warn_aggregate_return = value;
480       break;
481
482     case OPT_Wcast_align:
483       warn_cast_align = value;
484       break;
485
486     case OPT_Wdeprecated_declarations:
487       warn_deprecated_decl = value;
488       break;
489
490     case OPT_Wdisabled_optimization:
491       warn_disabled_optimization = value;
492       break;
493
494     case OPT_Werror:
495       warnings_are_errors = value;
496       break;
497
498     case OPT_Wextra:
499       set_Wextra (value);
500       break;
501
502     case OPT_Winline:
503       warn_inline = value;
504       break;
505
506     case OPT_Wlarger_than_:
507       larger_than_size = value;
508       warn_larger_than = value != -1;
509       break;
510
511     case OPT_Wmissing_noreturn:
512       warn_missing_noreturn = value;
513       break;
514
515     case OPT_Wpacked:
516       warn_packed = value;
517       break;
518
519     case OPT_Wpadded:
520       warn_padded = value;
521       break;
522
523     case OPT_Wshadow:
524       warn_shadow = value;
525       break;
526
527     case OPT_Wstrict_aliasing:
528       warn_strict_aliasing = value;
529       break;
530
531     case OPT_Wswitch:
532       warn_switch = value;
533       break;
534
535     case OPT_Wswitch_default:
536       warn_switch_default = value;
537       break;
538
539     case OPT_Wswitch_enum:
540       warn_switch_enum = value;
541       break;
542
543     case OPT_Wsystem_headers:
544       warn_system_headers = value;
545       break;
546
547     case OPT_Wuninitialized:
548       warn_uninitialized = value;
549       break;
550
551     case OPT_Wunreachable_code:
552       warn_notreached = value;
553       break;
554
555     case OPT_Wunused:
556       set_Wunused (value);
557       break;
558
559     case OPT_Wunused_function:
560       warn_unused_function = value;
561       break;
562
563     case OPT_Wunused_label:
564       warn_unused_label = value;
565       break;
566
567     case OPT_Wunused_parameter:
568       warn_unused_parameter = value;
569       break;
570
571     case OPT_Wunused_value:
572       warn_unused_value = value;
573       break;
574
575     case OPT_Wunused_variable:
576       warn_unused_variable = value;
577       break;
578
579     case OPT_aux_info:
580     case OPT_aux_info_:
581       aux_info_file_name = arg;
582       flag_gen_aux_info = 1;
583       break;
584
585     case OPT_auxbase:
586       aux_base_name = arg;
587       break;
588
589     case OPT_auxbase_strip:
590       {
591         char *tmp = xstrdup (arg);
592         strip_off_ending (tmp, strlen (tmp));
593         if (tmp[0])
594           aux_base_name = tmp;
595       }
596       break;
597
598     case OPT_d:
599       decode_d_option (arg);
600       break;
601
602     case OPT_dumpbase:
603       dump_base_name = arg;
604       break;
605
606     case OPT_fPIC:
607       flag_pic = value + value;
608       break;
609
610     case OPT_fPIE:
611       flag_pie = value + value;
612       break;
613
614     case OPT_falign_functions:
615     case OPT_falign_functions_:
616       align_functions = value;
617       break;
618
619     case OPT_falign_jumps:
620     case OPT_falign_jumps_:
621       align_jumps = value;
622       break;
623
624     case OPT_falign_labels:
625     case OPT_falign_labels_:
626       align_labels = value;
627       break;
628
629     case OPT_falign_loops:
630     case OPT_falign_loops_:
631       align_loops = value;
632       break;
633
634     case OPT_fargument_alias:
635       flag_argument_noalias = !value;
636       break;
637
638     case OPT_fargument_noalias:
639       flag_argument_noalias = value;
640       break;
641
642     case OPT_fargument_noalias_global:
643       flag_argument_noalias = value + value;
644       break;
645
646     case OPT_fasynchronous_unwind_tables:
647       flag_asynchronous_unwind_tables = value;
648       break;
649
650     case OPT_fbounds_check:
651       flag_bounds_check = value;
652       break;
653
654     case OPT_fbranch_count_reg:
655       flag_branch_on_count_reg = value;
656       break;
657
658     case OPT_fbranch_probabilities:
659       flag_branch_probabilities = value;
660       break;
661
662     case OPT_fbranch_target_load_optimize:
663       flag_branch_target_load_optimize = value;
664       break;
665
666     case OPT_fbranch_target_load_optimize2:
667       flag_branch_target_load_optimize2 = value;
668       break;
669
670     case OPT_fcall_used_:
671       fix_register (arg, 0, 1);
672       break;
673
674     case OPT_fcall_saved_:
675       fix_register (arg, 0, 0);
676       break;
677
678     case OPT_fcaller_saves:
679       flag_caller_saves = value;
680       break;
681
682     case OPT_fcommon:
683       flag_no_common = !value;
684       break;
685
686     case OPT_fcprop_registers:
687       flag_cprop_registers = value;
688       break;
689
690     case OPT_fcrossjumping:
691       flag_crossjumping = value;
692       break;
693
694     case OPT_fcse_follow_jumps:
695       flag_cse_follow_jumps = value;
696       break;
697
698     case OPT_fcse_skip_blocks:
699       flag_cse_skip_blocks = value;
700       break;
701
702     case OPT_fdata_sections:
703       flag_data_sections = value;
704       break;
705
706     case OPT_fdefer_pop:
707       flag_defer_pop = value;
708       break;
709
710     case OPT_fdelayed_branch:
711       flag_delayed_branch = value;
712       break;
713
714     case OPT_fdelete_null_pointer_checks:
715       flag_delete_null_pointer_checks = value;
716       break;
717
718     case OPT_fdiagnostics_show_location_:
719       if (!strcmp (arg, "once"))
720         diagnostic_prefixing_rule (global_dc) = DIAGNOSTICS_SHOW_PREFIX_ONCE;
721       else if (!strcmp (arg, "every-line"))
722         diagnostic_prefixing_rule (global_dc)
723           = DIAGNOSTICS_SHOW_PREFIX_EVERY_LINE;
724       else
725         return 0;
726       break;
727
728     case OPT_fdump_unnumbered:
729       flag_dump_unnumbered = value;
730       break;
731
732     case OPT_feliminate_dwarf2_dups:
733       flag_eliminate_dwarf2_dups = value;
734       break;
735
736     case OPT_feliminate_unused_debug_types:
737       flag_eliminate_unused_debug_types = value;
738       break;
739
740     case OPT_fexceptions:
741       flag_exceptions = value;
742       break;
743
744     case OPT_fexpensive_optimizations:
745       flag_expensive_optimizations = value;
746       break;
747
748     case OPT_ffast_math:
749       set_fast_math_flags (value);
750       break;
751
752     case OPT_ffinite_math_only:
753       flag_finite_math_only = value;
754       break;
755
756     case OPT_ffixed_:
757       fix_register (arg, 1, 1);
758       break;
759
760     case OPT_ffunction_cse:
761       flag_no_function_cse = !value;
762       break;
763
764     case OPT_ffloat_store:
765       flag_float_store = value;
766       break;
767
768     case OPT_fforce_addr:
769       flag_force_addr = value;
770       break;
771
772     case OPT_fforce_mem:
773       flag_force_mem = value;
774       break;
775
776     case OPT_ffunction_sections:
777       flag_function_sections = value;
778       break;
779
780     case OPT_fgcse:
781       flag_gcse = value;
782       break;
783
784     case OPT_fgcse_lm:
785       flag_gcse_lm = value;
786       break;
787
788     case OPT_fgcse_sm:
789       flag_gcse_sm = value;
790       break;
791
792     case OPT_fgnu_linker:
793       flag_gnu_linker = value;
794       break;
795
796     case OPT_fguess_branch_probability:
797       flag_guess_branch_prob = value;
798       break;
799
800     case OPT_fident:
801       flag_no_ident = !value;
802       break;
803
804     case OPT_fif_conversion:
805       flag_if_conversion = value;
806       break;
807
808     case OPT_fif_conversion2:
809       flag_if_conversion2 = value;
810       break;
811
812     case OPT_finhibit_size_directive:
813       flag_inhibit_size_directive = value;
814       break;
815
816     case OPT_finline:
817       flag_no_inline = !value;
818       break;
819
820     case OPT_finline_functions:
821       flag_inline_functions = value;
822       break;
823
824     case OPT_finline_limit_:
825     case OPT_finline_limit_eq:
826       set_param_value ("max-inline-insns", value);
827       set_param_value ("max-inline-insns-single", value / 2);
828       set_param_value ("max-inline-insns-auto", value / 2);
829       set_param_value ("max-inline-insns-rtl", value);
830       if (value / 4 < MIN_INLINE_INSNS)
831         {
832           if (value / 4 > 10)
833             set_param_value ("min-inline-insns", value / 4);
834           else
835             set_param_value ("min-inline-insns", 10);
836         }
837       break;
838
839     case OPT_finstrument_functions:
840       flag_instrument_function_entry_exit = value;
841       break;
842
843     case OPT_fkeep_inline_functions:
844       flag_keep_inline_functions =value;
845       break;
846
847     case OPT_fkeep_static_consts:
848       flag_keep_static_consts = value;
849       break;
850
851     case OPT_fleading_underscore:
852       flag_leading_underscore = value;
853       break;
854
855     case OPT_floop_optimize:
856       flag_loop_optimize = value;
857       break;
858
859     case OPT_fmath_errno:
860       flag_errno_math = value;
861       break;
862
863     case OPT_fmem_report:
864       mem_report = value;
865       break;
866
867     case OPT_fmerge_all_constants:
868       flag_merge_constants = value + value;
869       break;
870
871     case OPT_fmerge_constants:
872       flag_merge_constants = value;
873       break;
874
875     case OPT_fmessage_length_:
876       output_set_maximum_length (&global_dc->buffer, value);
877       break;
878
879     case OPT_fmove_all_movables:
880       flag_move_all_movables = value;
881       break;
882
883     case OPT_fnew_ra:
884       flag_new_regalloc = value;
885       break;
886
887     case OPT_fnon_call_exceptions:
888       flag_non_call_exceptions = value;
889       break;
890
891     case OPT_fold_unroll_all_loops:
892       flag_old_unroll_all_loops = value;
893       break;
894
895     case OPT_fold_unroll_loops:
896       flag_old_unroll_loops = value;
897       break;
898
899     case OPT_fomit_frame_pointer:
900       flag_omit_frame_pointer = value;
901       break;
902
903     case OPT_foptimize_register_move:
904       flag_regmove = value;
905       break;
906
907     case OPT_foptimize_sibling_calls:
908       flag_optimize_sibling_calls = value;
909       break;
910
911     case OPT_fpack_struct:
912       flag_pack_struct = value;
913       break;
914
915     case OPT_fpeel_loops:
916       flag_peel_loops = value;
917       break;
918
919     case OPT_fpcc_struct_return:
920       flag_pcc_struct_return = value;
921       break;
922
923     case OPT_fpeephole:
924       flag_no_peephole = !value;
925       break;
926
927     case OPT_fpeephole2:
928       flag_peephole2 = value;
929       break;
930
931     case OPT_fpic:
932       flag_pic = value;
933       break;
934
935     case OPT_fpie:
936       flag_pie = value;
937       break;
938
939     case OPT_fprefetch_loop_arrays:
940       flag_prefetch_loop_arrays = value;
941       break;
942
943     case OPT_fprofile:
944       profile_flag = value;
945       break;
946
947     case OPT_fprofile_arcs:
948       profile_arc_flag = value;
949       break;
950
951     case OPT_frandom_seed:
952       /* The real switch is -fno-random-seed.  */
953       if (value)
954         return 0;
955       flag_random_seed = NULL;
956       break;
957
958     case OPT_frandom_seed_:
959       flag_random_seed = arg;
960       break;
961
962     case OPT_freduce_all_givs:
963       flag_reduce_all_givs = value;
964       break;
965
966     case OPT_freg_struct_return:
967       flag_pcc_struct_return = !value;
968       break;
969
970     case OPT_fregmove:
971       flag_regmove = value;
972       break;
973
974     case OPT_frename_registers:
975       flag_rename_registers = value;
976       break;
977
978     case OPT_freorder_blocks:
979       flag_reorder_blocks = value;
980       break;
981
982     case OPT_freorder_functions:
983       flag_reorder_functions = value;
984       break;
985
986     case OPT_frerun_cse_after_loop:
987       flag_rerun_cse_after_loop = value;
988       break;
989
990     case OPT_frerun_loop_opt:
991       flag_rerun_loop_opt = value;
992       break;
993
994     case OPT_fsched_interblock:
995       flag_schedule_interblock= value;
996       break;
997
998     case OPT_fsched_spec:
999       flag_schedule_speculative = value;
1000       break;
1001
1002     case OPT_fsched_spec_load:
1003       flag_schedule_speculative_load = value;
1004       break;
1005
1006     case OPT_fsched_spec_load_dangerous:
1007       flag_schedule_speculative_load_dangerous = value;
1008       break;
1009
1010     case OPT_fsched_verbose_:
1011 #ifdef INSN_SCHEDULING
1012       fix_sched_param ("verbose", arg);
1013       break;
1014 #else
1015       return 0;
1016 #endif
1017
1018     case OPT_fsched2_use_superblocks:
1019       flag_sched2_use_superblocks = value;
1020       break;
1021
1022     case OPT_fsched2_use_traces:
1023       flag_sched2_use_traces = value;
1024       break;
1025
1026     case OPT_fschedule_insns:
1027       flag_schedule_insns = value;
1028       break;
1029
1030     case OPT_fschedule_insns2:
1031       flag_schedule_insns_after_reload = value;
1032       break;
1033
1034     case OPT_fshared_data:
1035       flag_shared_data = value;
1036       break;
1037
1038     case OPT_fsignaling_nans:
1039       flag_signaling_nans = value;
1040       break;
1041
1042     case OPT_fsingle_precision_constant:
1043       flag_single_precision_constant = value;
1044       break;
1045
1046     case OPT_fssa:
1047       flag_ssa = value;
1048       break;
1049
1050     case OPT_fssa_ccp:
1051       flag_ssa_ccp = value;
1052       break;
1053
1054     case OPT_fssa_dce:
1055       flag_ssa_dce = value;
1056       break;
1057
1058     case OPT_fstack_check:
1059       flag_stack_check = value;
1060       break;
1061
1062     case OPT_fstack_limit:
1063       /* The real switch is -fno-stack-limit.  */
1064       if (value)
1065         return 0;
1066       stack_limit_rtx = NULL_RTX;
1067       break;
1068
1069     case OPT_fstack_limit_register_:
1070       {
1071         int reg = decode_reg_name (arg);
1072         if (reg < 0)
1073           error ("unrecognized register name \"%s\"", arg);
1074         else
1075           stack_limit_rtx = gen_rtx_REG (Pmode, reg);
1076       }
1077       break;
1078
1079     case OPT_fstack_limit_symbol_:
1080       stack_limit_rtx = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (arg));
1081       break;
1082
1083     case OPT_fstrength_reduce:
1084       flag_strength_reduce = value;
1085       break;
1086
1087     case OPT_fstrict_aliasing:
1088       flag_strict_aliasing = value;
1089       break;
1090
1091     case OPT_fsyntax_only:
1092       flag_syntax_only = value;
1093       break;
1094
1095     case OPT_ftest_coverage:
1096       flag_test_coverage = value;
1097       break;
1098
1099     case OPT_fthread_jumps:
1100       flag_thread_jumps = value;
1101       break;
1102
1103     case OPT_ftime_report:
1104       time_report = value;
1105       break;
1106
1107     case OPT_ftls_model_:
1108       if (!strcmp (arg, "global-dynamic"))
1109         flag_tls_default = TLS_MODEL_GLOBAL_DYNAMIC;
1110       else if (!strcmp (arg, "local-dynamic"))
1111         flag_tls_default = TLS_MODEL_LOCAL_DYNAMIC;
1112       else if (!strcmp (arg, "initial-exec"))
1113         flag_tls_default = TLS_MODEL_INITIAL_EXEC;
1114       else if (!strcmp (arg, "local-exec"))
1115         flag_tls_default = TLS_MODEL_LOCAL_EXEC;
1116       else
1117         warning ("unknown tls-model \"%s\"", arg);
1118       break;
1119
1120     case OPT_ftracer:
1121       flag_tracer = value;
1122       break;
1123
1124     case OPT_ftrapping_math:
1125       flag_trapping_math = value;
1126       break;
1127
1128     case OPT_ftrapv:
1129       flag_trapv = value;
1130       break;
1131
1132     case OPT_funit_at_a_time:
1133       flag_unit_at_a_time = value;
1134       break;
1135
1136     case OPT_funroll_all_loops:
1137       flag_unroll_all_loops = value;
1138       break;
1139
1140     case OPT_funroll_loops:
1141       flag_unroll_loops = value;
1142       break;
1143
1144     case OPT_funsafe_math_optimizations:
1145       flag_unsafe_math_optimizations = value;
1146       break;
1147
1148     case OPT_funswitch_loops:
1149       flag_unswitch_loops = value;
1150       break;
1151
1152     case OPT_funwind_tables:
1153       flag_unwind_tables = value;
1154       break;
1155
1156     case OPT_fverbose_asm:
1157       flag_verbose_asm = value;
1158       break;
1159       
1160     case OPT_fwrapv:
1161       flag_wrapv = value;
1162       break;
1163
1164     case OPT_fwritable_strings:
1165       flag_writable_strings = value;
1166       break;
1167
1168     case OPT_fzero_initialized_in_bss:
1169       flag_zero_initialized_in_bss = value;
1170       break;
1171
1172     case OPT_g:
1173       decode_g_option (arg);
1174       break;
1175
1176     case OPT_m:
1177       set_target_switch (arg);
1178       break;
1179
1180     case OPT_o:
1181       asm_file_name = arg;
1182       break;
1183
1184     case OPT_p:
1185       profile_flag = 1;
1186       break;
1187
1188     case OPT_pedantic:
1189       pedantic = 1;
1190       break;
1191
1192     case OPT_pedantic_errors:
1193       flag_pedantic_errors = pedantic = 1;
1194       break;
1195
1196     case OPT_quiet:
1197       quiet_flag = 1;
1198       break;
1199
1200     case OPT_version:
1201       version_flag = 1;
1202       break;
1203
1204     case OPT_w:
1205       inhibit_warnings = true;
1206       break;      
1207     }
1208
1209   return 1;
1210 }
1211
1212 /* Handle --param NAME=VALUE.  */
1213 static void
1214 handle_param (const char *carg)
1215 {
1216   char *equal, *arg;
1217   int value;
1218
1219   arg = xstrdup (carg);
1220   equal = strchr (arg, '=');
1221   if (!equal)
1222     error ("%s: --param arguments should be of the form NAME=VALUE", arg);
1223   else
1224     {
1225       value = integral_argument (equal + 1);
1226       if (value == -1)
1227         error ("invalid --param value `%s'", equal + 1);
1228       else
1229         {
1230           *equal = '\0';
1231           set_param_value (arg, value);
1232         }
1233     }
1234
1235   free (arg);
1236 }
1237
1238 /* Handle -W and -Wextra.  */
1239 static void
1240 set_Wextra (int setting)
1241 {
1242   extra_warnings = setting;
1243   warn_unused_value = setting;
1244   warn_unused_parameter = (setting && maybe_warn_unused_parameter);
1245
1246   /* We save the value of warn_uninitialized, since if they put
1247      -Wuninitialized on the command line, we need to generate a
1248      warning about not using it without also specifying -O.  */
1249   if (setting == 0)
1250     warn_uninitialized = 0;
1251   else if (warn_uninitialized != 1)
1252     warn_uninitialized = 2;
1253 }
1254
1255 /* Initialize unused warning flags.  */
1256 void
1257 set_Wunused (int setting)
1258 {
1259   warn_unused_function = setting;
1260   warn_unused_label = setting;
1261   /* Unused function parameter warnings are reported when either
1262      ``-Wextra -Wunused'' or ``-Wunused-parameter'' is specified.
1263      Thus, if -Wextra has already been seen, set warn_unused_parameter;
1264      otherwise set maybe_warn_extra_parameter, which will be picked up
1265      by set_Wextra.  */
1266   maybe_warn_unused_parameter = setting;
1267   warn_unused_parameter = (setting && extra_warnings);
1268   warn_unused_variable = setting;
1269   warn_unused_value = setting;
1270 }
1271
1272 /* The following routines are useful in setting all the flags that
1273    -ffast-math and -fno-fast-math imply.  */
1274 void
1275 set_fast_math_flags (int set)
1276 {
1277   flag_trapping_math = !set;
1278   flag_unsafe_math_optimizations = set;
1279   flag_finite_math_only = set;
1280   flag_errno_math = !set;
1281   if (set)
1282     flag_signaling_nans = 0;
1283 }
1284
1285 /* Return true iff flags are set as if -ffast-math.  */
1286 bool
1287 fast_math_flags_set_p (void)
1288 {
1289   return (!flag_trapping_math
1290           && flag_unsafe_math_optimizations
1291           && flag_finite_math_only
1292           && !flag_errno_math);
1293 }