OSDN Git Service

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