Missed one in last change.
[official-gcc.git] / gcc / opts.c
blob626dc5aa662479aeaff5f332f72d293de03a2c21
1 /* Command line option handling.
2 Copyright (C) 2002, 2003 Free Software Foundation, Inc.
3 Contributed by Neil Booth.
5 This file is part of GCC.
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.
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.
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. */
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. */
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;
44 /* True if we should exit after parsing options. */
45 bool exit_after_options;
47 /* If -version. */
48 bool version_flag;
50 /* Print various extra warnings. -W/-Wextra. */
51 bool extra_warnings;
53 /* Don't print warning messages. -w. */
54 bool inhibit_warnings;
56 /* Treat warnings as errors. -Werror. */
57 bool warnings_are_errors;
59 /* Warn if a function returns an aggregate, since there are often
60 incompatible calling conventions for doing this. */
61 bool warn_aggregate_return;
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;
68 /* Nonzero means warn about uses of __attribute__((deprecated))
69 declarations. */
70 bool warn_deprecated_decl = true;
72 /* Warn when an optimization pass is disabled. */
73 bool warn_disabled_optimization;
75 /* Nonzero means warn if inline function is too large. */
76 bool warn_inline;
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;
84 /* Warn about functions which might be candidates for attribute noreturn. */
85 bool warn_missing_noreturn;
87 /* True to warn about code which is never reached. */
88 bool warn_notreached;
90 /* Warn if packed attribute on struct is unnecessary and inefficient. */
91 bool warn_packed;
93 /* Warn when gcc pads a structure to an alignment boundary. */
94 bool warn_padded;
96 /* True means warn about all declarations which shadow others. */
97 bool warn_shadow;
99 /* Nonzero means warn about constructs which might not be
100 strict-aliasing safe. */
101 bool warn_strict_aliasing;
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;
107 /* Warn if a switch does not have a default case. */
108 bool warn_switch_default;
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;
114 /* Don't suppress warnings from system headers. -Wsystem-headers. */
115 bool warn_system_headers;
117 /* True to warn about variables used before they are initialized. */
118 int warn_uninitialized;
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;
127 /* Hack for cooperation between set_Wunused and set_Wextra. */
128 static bool maybe_warn_unused_parameter;
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 (const 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, const char **, unsigned int);
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.
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".
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).
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)
167 size_t mn, mx, md, opt_len;
168 size_t match_wrong_lang;
169 int comp;
171 mn = 0;
172 mx = cl_options_count;
174 /* Find mn such this lexicographical inequality holds:
175 cl_options[mn] <= input < cl_options[mn + 1]. */
176 while (mx - mn > 1)
178 md = (mn + mx) / 2;
179 opt_len = cl_options[md].opt_len;
180 comp = strncmp (input, cl_options[md].opt_text, opt_len);
182 if (comp < 0)
183 mx = md;
184 else
185 mn = md;
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;
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. */
197 const struct cl_option *opt = &cl_options[mn];
199 /* Is this switch a prefix of the input? */
200 if (!strncmp (input, opt->opt_text, opt->opt_len))
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;
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;
214 /* Try the next possibility. This is cl_options_count if there
215 are no more. */
216 mn = opt->back_chain;
218 while (mn != cl_options_count);
220 /* Return the best wrong match, or cl_options_count if none. */
221 return match_wrong_lang;
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)
229 const char *p = arg;
231 while (*p && ISDIGIT (*p))
232 p++;
234 if (*p == '\0')
235 return atoi (arg);
237 return -1;
240 /* Return a malloced slash-separated list of languages in MASK. */
241 static char *
242 write_langs (unsigned int mask)
244 unsigned int n = 0, len = 0;
245 const char *lang_name;
246 char *result;
248 for (n = 0; (lang_name = lang_names[n]) != 0; n++)
249 if (mask & (1U << n))
250 len += strlen (lang_name) + 1;
252 result = xmalloc (len);
253 len = 0;
254 for (n = 0; (lang_name = lang_names[n]) != 0; n++)
255 if (mask & (1U << n))
257 if (len)
258 result[len++] = '/';
259 strcpy (result + len, lang_name);
260 len += strlen (lang_name);
263 result[len] = 0;
265 return result;
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)
273 char *ok_langs, *bad_lang;
275 ok_langs = write_langs (option->flags);
276 bad_lang = write_langs (lang_mask);
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);
282 free (ok_langs);
283 free (bad_lang);
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 (const char **argv, unsigned int lang_mask)
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;
298 opt = argv[0];
300 /* Interpret "-" or a non-switch as a file name. */
301 if (opt[0] != '-' || opt[1] == '\0')
303 opt_index = cl_options_count;
304 arg = opt;
305 main_input_filename = opt;
306 result = (*lang_hooks.handle_option) (opt_index, arg, value);
308 else
310 /* Drop the "no-" from negative switches. */
311 if ((opt[1] == 'W' || opt[1] == 'f')
312 && opt[2] == 'n' && opt[3] == 'o' && opt[4] == '-')
314 size_t len = strlen (opt) - 3;
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;
324 opt_index = find_opt (opt + 1, lang_mask | CL_COMMON);
325 if (opt_index == cl_options_count)
326 goto done;
328 option = &cl_options[opt_index];
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;
335 /* We've recognized this switch. */
336 result = 1;
338 /* Sort out any argument the switch takes. */
339 if (option->flags & CL_JOINED)
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-");
348 if (*arg == '\0' && !(option->flags & CL_MISSING_OK))
350 if (option->flags & CL_SEPARATE)
352 arg = argv[1];
353 result = 2;
355 else
356 /* Missing argument. */
357 arg = NULL;
360 else if (option->flags & CL_SEPARATE)
362 arg = argv[1];
363 result = 2;
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)))
370 complain_wrong_lang (argv[0], option, lang_mask);
371 goto done;
374 if (arg == NULL && (option->flags & (CL_JOINED | CL_SEPARATE)))
376 error ("missing argument to \"-%s\"", argv[0]);
377 goto done;
380 /* If the switch takes an integer, convert it. */
381 if (arg && (option->flags & CL_UINTEGER))
383 value = integral_argument (arg);
384 if (value == -1)
386 error ("argument to \"-%s\" should be a non-negative integer",
387 option->opt_text);
388 goto done;
392 if (option->flags & lang_mask)
393 if ((*lang_hooks.handle_option) (opt_index, arg, value) == 0)
394 result = 0;
396 if (result && (option->flags & CL_COMMON))
397 if (common_handle_option (opt_index, arg, value) == 0)
398 result = 0;
401 done:
402 if (dup)
403 free (dup);
404 return result;
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, const char **argv, unsigned int lang_mask)
413 unsigned int n, i;
415 for (i = 1; i < argc; i += n)
417 n = handle_option (argv + i, lang_mask);
419 if (!n)
421 n = 1;
422 error ("unrecognized command line option \"%s\"", argv[i]);
427 /* Parse command line options and set default flag values. Do minimal
428 options processing. */
429 void
430 decode_options (unsigned int argc, const char **argv)
432 unsigned int i, lang_mask;
434 /* Perform language-specific options initialization. */
435 lang_mask = (*lang_hooks.init_options) (argc, argv);
437 /* Scan to see what optimization level has been specified. That will
438 determine the default value of many flags. */
439 for (i = 1; i < argc; i++)
441 if (!strcmp (argv[i], "-O"))
443 optimize = 1;
444 optimize_size = 0;
446 else if (argv[i][0] == '-' && argv[i][1] == 'O')
448 /* Handle -Os, -O2, -O3, -O69, ... */
449 const char *p = &argv[i][2];
451 if ((p[0] == 's') && (p[1] == 0))
453 optimize_size = 1;
455 /* Optimizing for size forces optimize to be 2. */
456 optimize = 2;
458 else
460 const int optimize_val = read_integral_parameter (p, p - 2, -1);
461 if (optimize_val != -1)
463 optimize = optimize_val;
464 optimize_size = 0;
470 if (!optimize)
472 flag_merge_constants = 0;
475 if (optimize >= 1)
477 flag_defer_pop = 1;
478 flag_thread_jumps = 1;
479 #ifdef DELAY_SLOTS
480 flag_delayed_branch = 1;
481 #endif
482 #ifdef CAN_DEBUG_WITHOUT_FP
483 flag_omit_frame_pointer = 1;
484 #endif
485 flag_guess_branch_prob = 1;
486 flag_cprop_registers = 1;
487 flag_loop_optimize = 1;
488 flag_crossjumping = 1;
489 flag_if_conversion = 1;
490 flag_if_conversion2 = 1;
493 if (optimize >= 2)
495 flag_optimize_sibling_calls = 1;
496 flag_cse_follow_jumps = 1;
497 flag_cse_skip_blocks = 1;
498 flag_gcse = 1;
499 flag_expensive_optimizations = 1;
500 flag_strength_reduce = 1;
501 flag_rerun_cse_after_loop = 1;
502 flag_rerun_loop_opt = 1;
503 flag_caller_saves = 1;
504 flag_force_mem = 1;
505 flag_peephole2 = 1;
506 #ifdef INSN_SCHEDULING
507 flag_schedule_insns = 1;
508 flag_schedule_insns_after_reload = 1;
509 #endif
510 flag_regmove = 1;
511 flag_strict_aliasing = 1;
512 flag_delete_null_pointer_checks = 1;
513 flag_reorder_blocks = 1;
514 flag_reorder_functions = 1;
517 if (optimize >= 3)
519 flag_inline_functions = 1;
520 flag_rename_registers = 1;
521 flag_unswitch_loops = 1;
522 flag_unit_at_a_time = 1;
525 if (optimize < 2 || optimize_size)
527 align_loops = 1;
528 align_jumps = 1;
529 align_labels = 1;
530 align_functions = 1;
532 /* Don't reorder blocks when optimizing for size because extra
533 jump insns may be created; also barrier may create extra padding.
535 More correctly we should have a block reordering mode that tried
536 to minimize the combined size of all the jumps. This would more
537 or less automatically remove extra jumps, but would also try to
538 use more short jumps instead of long jumps. */
539 flag_reorder_blocks = 0;
542 /* Initialize whether `char' is signed. */
543 flag_signed_char = DEFAULT_SIGNED_CHAR;
544 #ifdef DEFAULT_SHORT_ENUMS
545 /* Initialize how much space enums occupy, by default. */
546 flag_short_enums = DEFAULT_SHORT_ENUMS;
547 #endif
549 /* Initialize target_flags before OPTIMIZATION_OPTIONS so the latter can
550 modify it. */
551 target_flags = 0;
552 set_target_switch ("");
554 /* Unwind tables are always present in an ABI-conformant IA-64
555 object file, so the default should be ON. */
556 #ifdef IA64_UNWIND_INFO
557 flag_unwind_tables = IA64_UNWIND_INFO;
558 #endif
560 #ifdef OPTIMIZATION_OPTIONS
561 /* Allow default optimizations to be specified on a per-machine basis. */
562 OPTIMIZATION_OPTIONS (optimize, optimize_size);
563 #endif
565 handle_options (argc, argv, lang_mask);
567 if (flag_pie)
568 flag_pic = flag_pie;
569 if (flag_pic && !flag_pie)
570 flag_shlib = 1;
572 if (flag_no_inline == 2)
573 flag_no_inline = 0;
574 else
575 flag_really_no_inline = flag_no_inline;
577 /* Set flag_no_inline before the post_options () hook. The C front
578 ends use it to determine tree inlining defaults. FIXME: such
579 code should be lang-independent when all front ends use tree
580 inlining, in which case it, and this condition, should be moved
581 to the top of process_options() instead. */
582 if (optimize == 0)
584 /* Inlining does not work if not optimizing,
585 so force it not to be done. */
586 flag_no_inline = 1;
587 warn_inline = 0;
589 /* The c_decode_option function and decode_option hook set
590 this to `2' if -Wall is used, so we can avoid giving out
591 lots of errors for people who don't realize what -Wall does. */
592 if (warn_uninitialized == 1)
593 warning ("-Wuninitialized is not supported without -O");
596 if (flag_really_no_inline == 2)
597 flag_really_no_inline = flag_no_inline;
600 /* Handle target- and language-independent options. Return zero to
601 generate an "unknown option" message. */
602 static int
603 common_handle_option (size_t scode, const char *arg,
604 int value ATTRIBUTE_UNUSED)
606 const struct cl_option *option = &cl_options[scode];
607 enum opt_code code = (enum opt_code) scode;
609 if (arg == NULL && (option->flags & (CL_JOINED | CL_SEPARATE)))
611 error ("missing argument to \"-%s\"", option->opt_text);
612 return 1;
615 switch (code)
617 default:
618 abort ();
620 case OPT__help:
621 display_help ();
622 exit_after_options = true;
623 break;
625 case OPT__param:
626 handle_param (arg);
627 break;
629 case OPT__target_help:
630 display_target_options ();
631 exit_after_options = true;
632 break;
634 case OPT__version:
635 print_version (stderr, "");
636 exit_after_options = true;
637 break;
639 case OPT_G:
640 g_switch_value = value;
641 g_switch_set = true;
642 break;
644 case OPT_O:
645 case OPT_Os:
646 /* Currently handled in a prescan. */
647 break;
649 case OPT_W:
650 /* For backward compatibility, -W is the same as -Wextra. */
651 set_Wextra (value);
652 break;
654 case OPT_Waggregate_return:
655 warn_aggregate_return = value;
656 break;
658 case OPT_Wcast_align:
659 warn_cast_align = value;
660 break;
662 case OPT_Wdeprecated_declarations:
663 warn_deprecated_decl = value;
664 break;
666 case OPT_Wdisabled_optimization:
667 warn_disabled_optimization = value;
668 break;
670 case OPT_Werror:
671 warnings_are_errors = value;
672 break;
674 case OPT_Wextra:
675 set_Wextra (value);
676 break;
678 case OPT_Winline:
679 warn_inline = value;
680 break;
682 case OPT_Wlarger_than_:
683 larger_than_size = value;
684 warn_larger_than = value != -1;
685 break;
687 case OPT_Wmissing_noreturn:
688 warn_missing_noreturn = value;
689 break;
691 case OPT_Wpacked:
692 warn_packed = value;
693 break;
695 case OPT_Wpadded:
696 warn_padded = value;
697 break;
699 case OPT_Wshadow:
700 warn_shadow = value;
701 break;
703 case OPT_Wstrict_aliasing:
704 warn_strict_aliasing = value;
705 break;
707 case OPT_Wswitch:
708 warn_switch = value;
709 break;
711 case OPT_Wswitch_default:
712 warn_switch_default = value;
713 break;
715 case OPT_Wswitch_enum:
716 warn_switch_enum = value;
717 break;
719 case OPT_Wsystem_headers:
720 warn_system_headers = value;
721 break;
723 case OPT_Wuninitialized:
724 warn_uninitialized = value;
725 break;
727 case OPT_Wunreachable_code:
728 warn_notreached = value;
729 break;
731 case OPT_Wunused:
732 set_Wunused (value);
733 break;
735 case OPT_Wunused_function:
736 warn_unused_function = value;
737 break;
739 case OPT_Wunused_label:
740 warn_unused_label = value;
741 break;
743 case OPT_Wunused_parameter:
744 warn_unused_parameter = value;
745 break;
747 case OPT_Wunused_value:
748 warn_unused_value = value;
749 break;
751 case OPT_Wunused_variable:
752 warn_unused_variable = value;
753 break;
755 case OPT_aux_info:
756 case OPT_aux_info_:
757 aux_info_file_name = arg;
758 flag_gen_aux_info = 1;
759 break;
761 case OPT_auxbase:
762 aux_base_name = arg;
763 break;
765 case OPT_auxbase_strip:
767 char *tmp = xstrdup (arg);
768 strip_off_ending (tmp, strlen (tmp));
769 if (tmp[0])
770 aux_base_name = tmp;
772 break;
774 case OPT_d:
775 decode_d_option (arg);
776 break;
778 case OPT_dumpbase:
779 dump_base_name = arg;
780 break;
782 case OPT_fPIC:
783 flag_pic = value + value;
784 break;
786 case OPT_fPIE:
787 flag_pie = value + value;
788 break;
790 case OPT_falign_functions:
791 case OPT_falign_functions_:
792 align_functions = !value;
793 break;
795 case OPT_falign_jumps:
796 case OPT_falign_jumps_:
797 align_jumps = !value;
798 break;
800 case OPT_falign_labels:
801 case OPT_falign_labels_:
802 align_labels = !value;
803 break;
805 case OPT_falign_loops:
806 case OPT_falign_loops_:
807 align_loops = !value;
808 break;
810 case OPT_fargument_alias:
811 flag_argument_noalias = !value;
812 break;
814 case OPT_fargument_noalias:
815 flag_argument_noalias = value;
816 break;
818 case OPT_fargument_noalias_global:
819 flag_argument_noalias = value + value;
820 break;
822 case OPT_fasynchronous_unwind_tables:
823 flag_asynchronous_unwind_tables = value;
824 break;
826 case OPT_fbounds_check:
827 flag_bounds_check = value;
828 break;
830 case OPT_fbranch_count_reg:
831 flag_branch_on_count_reg = value;
832 break;
834 case OPT_fbranch_probabilities:
835 flag_branch_probabilities = value;
836 break;
838 case OPT_fbranch_target_load_optimize:
839 flag_branch_target_load_optimize = value;
840 break;
842 case OPT_fbranch_target_load_optimize2:
843 flag_branch_target_load_optimize2 = value;
844 break;
846 case OPT_fcall_used_:
847 fix_register (arg, 0, 1);
848 break;
850 case OPT_fcall_saved_:
851 fix_register (arg, 0, 0);
852 break;
854 case OPT_fcaller_saves:
855 flag_caller_saves = value;
856 break;
858 case OPT_fcommon:
859 flag_no_common = !value;
860 break;
862 case OPT_fcprop_registers:
863 flag_cprop_registers = value;
864 break;
866 case OPT_fcrossjumping:
867 flag_crossjumping = value;
868 break;
870 case OPT_fcse_follow_jumps:
871 flag_cse_follow_jumps = value;
872 break;
874 case OPT_fcse_skip_blocks:
875 flag_cse_skip_blocks = value;
876 break;
878 case OPT_fdata_sections:
879 flag_data_sections = value;
880 break;
882 case OPT_fdefer_pop:
883 flag_defer_pop = value;
884 break;
886 case OPT_fdelayed_branch:
887 flag_delayed_branch = value;
888 break;
890 case OPT_fdelete_null_pointer_checks:
891 flag_delete_null_pointer_checks = value;
892 break;
894 case OPT_fdiagnostics_show_location_:
895 if (!strcmp (arg, "once"))
896 diagnostic_prefixing_rule (global_dc) = DIAGNOSTICS_SHOW_PREFIX_ONCE;
897 else if (!strcmp (arg, "every-line"))
898 diagnostic_prefixing_rule (global_dc)
899 = DIAGNOSTICS_SHOW_PREFIX_EVERY_LINE;
900 else
901 return 0;
902 break;
904 case OPT_fdump_unnumbered:
905 flag_dump_unnumbered = value;
906 break;
908 case OPT_feliminate_dwarf2_dups:
909 flag_eliminate_dwarf2_dups = value;
910 break;
912 case OPT_feliminate_unused_debug_types:
913 flag_eliminate_unused_debug_types = value;
914 break;
916 case OPT_feliminate_unused_debug_symbols:
917 flag_debug_only_used_symbols = value;
918 break;
920 case OPT_fexceptions:
921 flag_exceptions = value;
922 break;
924 case OPT_fexpensive_optimizations:
925 flag_expensive_optimizations = value;
926 break;
928 case OPT_ffast_math:
929 set_fast_math_flags (value);
930 break;
932 case OPT_ffinite_math_only:
933 flag_finite_math_only = value;
934 break;
936 case OPT_ffixed_:
937 fix_register (arg, 1, 1);
938 break;
940 case OPT_ffunction_cse:
941 flag_no_function_cse = !value;
942 break;
944 case OPT_ffloat_store:
945 flag_float_store = value;
946 break;
948 case OPT_fforce_addr:
949 flag_force_addr = value;
950 break;
952 case OPT_fforce_mem:
953 flag_force_mem = value;
954 break;
956 case OPT_ffunction_sections:
957 flag_function_sections = value;
958 break;
960 case OPT_fgcse:
961 flag_gcse = value;
962 break;
964 case OPT_fgcse_lm:
965 flag_gcse_lm = value;
966 break;
968 case OPT_fgcse_sm:
969 flag_gcse_sm = value;
970 break;
972 case OPT_fgnu_linker:
973 flag_gnu_linker = value;
974 break;
976 case OPT_fguess_branch_probability:
977 flag_guess_branch_prob = value;
978 break;
980 case OPT_fident:
981 flag_no_ident = !value;
982 break;
984 case OPT_fif_conversion:
985 flag_if_conversion = value;
986 break;
988 case OPT_fif_conversion2:
989 flag_if_conversion2 = value;
990 break;
992 case OPT_finhibit_size_directive:
993 flag_inhibit_size_directive = value;
994 break;
996 case OPT_finline:
997 flag_no_inline = !value;
998 break;
1000 case OPT_finline_functions:
1001 flag_inline_functions = value;
1002 break;
1004 case OPT_finline_limit_:
1005 case OPT_finline_limit_eq:
1006 set_param_value ("max-inline-insns", value);
1007 set_param_value ("max-inline-insns-single", value / 2);
1008 set_param_value ("max-inline-insns-auto", value / 2);
1009 set_param_value ("max-inline-insns-rtl", value);
1010 if (value / 4 < MIN_INLINE_INSNS)
1012 if (value / 4 > 10)
1013 set_param_value ("min-inline-insns", value / 4);
1014 else
1015 set_param_value ("min-inline-insns", 10);
1017 break;
1019 case OPT_finstrument_functions:
1020 flag_instrument_function_entry_exit = value;
1021 break;
1023 case OPT_fkeep_inline_functions:
1024 flag_keep_inline_functions =value;
1025 break;
1027 case OPT_fkeep_static_consts:
1028 flag_keep_static_consts = value;
1029 break;
1031 case OPT_fleading_underscore:
1032 flag_leading_underscore = value;
1033 break;
1035 case OPT_floop_optimize:
1036 flag_loop_optimize = value;
1037 break;
1039 case OPT_fmath_errno:
1040 flag_errno_math = value;
1041 break;
1043 case OPT_fmem_report:
1044 mem_report = value;
1045 break;
1047 case OPT_fmerge_all_constants:
1048 flag_merge_constants = value + value;
1049 break;
1051 case OPT_fmerge_constants:
1052 flag_merge_constants = value;
1053 break;
1055 case OPT_fmessage_length_:
1056 output_set_maximum_length (&global_dc->buffer, value);
1057 break;
1059 case OPT_fmove_all_movables:
1060 flag_move_all_movables = value;
1061 break;
1063 case OPT_fnew_ra:
1064 flag_new_regalloc = value;
1065 break;
1067 case OPT_fnon_call_exceptions:
1068 flag_non_call_exceptions = value;
1069 break;
1071 case OPT_fold_unroll_all_loops:
1072 flag_old_unroll_all_loops = value;
1073 break;
1075 case OPT_fold_unroll_loops:
1076 flag_old_unroll_loops = value;
1077 break;
1079 case OPT_fomit_frame_pointer:
1080 flag_omit_frame_pointer = value;
1081 break;
1083 case OPT_foptimize_register_move:
1084 flag_regmove = value;
1085 break;
1087 case OPT_foptimize_sibling_calls:
1088 flag_optimize_sibling_calls = value;
1089 break;
1091 case OPT_fpack_struct:
1092 flag_pack_struct = value;
1093 break;
1095 case OPT_fpeel_loops:
1096 flag_peel_loops = value;
1097 break;
1099 case OPT_fpcc_struct_return:
1100 flag_pcc_struct_return = value;
1101 break;
1103 case OPT_fpeephole:
1104 flag_no_peephole = !value;
1105 break;
1107 case OPT_fpeephole2:
1108 flag_peephole2 = value;
1109 break;
1111 case OPT_fpic:
1112 flag_pic = value;
1113 break;
1115 case OPT_fpie:
1116 flag_pie = value;
1117 break;
1119 case OPT_fprefetch_loop_arrays:
1120 flag_prefetch_loop_arrays = value;
1121 break;
1123 case OPT_fprofile:
1124 profile_flag = value;
1125 break;
1127 case OPT_fprofile_arcs:
1128 profile_arc_flag = value;
1129 break;
1131 case OPT_frandom_seed:
1132 /* The real switch is -fno-random-seed. */
1133 if (value)
1134 return 0;
1135 flag_random_seed = NULL;
1136 break;
1138 case OPT_frandom_seed_:
1139 flag_random_seed = arg;
1140 break;
1142 case OPT_freduce_all_givs:
1143 flag_reduce_all_givs = value;
1144 break;
1146 case OPT_freg_struct_return:
1147 flag_pcc_struct_return = !value;
1148 break;
1150 case OPT_fregmove:
1151 flag_regmove = value;
1152 break;
1154 case OPT_frename_registers:
1155 flag_rename_registers = value;
1156 break;
1158 case OPT_freorder_blocks:
1159 flag_reorder_blocks = value;
1160 break;
1162 case OPT_freorder_functions:
1163 flag_reorder_functions = value;
1164 break;
1166 case OPT_frerun_cse_after_loop:
1167 flag_rerun_cse_after_loop = value;
1168 break;
1170 case OPT_frerun_loop_opt:
1171 flag_rerun_loop_opt = value;
1172 break;
1174 case OPT_fsched_interblock:
1175 flag_schedule_interblock= value;
1176 break;
1178 case OPT_fsched_spec:
1179 flag_schedule_speculative = value;
1180 break;
1182 case OPT_fsched_spec_load:
1183 flag_schedule_speculative_load = value;
1184 break;
1186 case OPT_fsched_spec_load_dangerous:
1187 flag_schedule_speculative_load_dangerous = value;
1188 break;
1190 case OPT_fsched_verbose_:
1191 #ifdef INSN_SCHEDULING
1192 fix_sched_param ("verbose", arg);
1193 break;
1194 #else
1195 return 0;
1196 #endif
1198 case OPT_fsched2_use_superblocks:
1199 flag_sched2_use_superblocks = value;
1200 break;
1202 case OPT_fsched2_use_traces:
1203 flag_sched2_use_traces = value;
1204 break;
1206 case OPT_fschedule_insns:
1207 flag_schedule_insns = value;
1208 break;
1210 case OPT_fschedule_insns2:
1211 flag_schedule_insns_after_reload = value;
1212 break;
1214 case OPT_fshared_data:
1215 flag_shared_data = value;
1216 break;
1218 case OPT_fsignaling_nans:
1219 flag_signaling_nans = value;
1220 break;
1222 case OPT_fsingle_precision_constant:
1223 flag_single_precision_constant = value;
1224 break;
1226 case OPT_fssa:
1227 flag_ssa = value;
1228 break;
1230 case OPT_fssa_ccp:
1231 flag_ssa_ccp = value;
1232 break;
1234 case OPT_fssa_dce:
1235 flag_ssa_dce = value;
1236 break;
1238 case OPT_fstack_check:
1239 flag_stack_check = value;
1240 break;
1242 case OPT_fstack_limit:
1243 /* The real switch is -fno-stack-limit. */
1244 if (value)
1245 return 0;
1246 stack_limit_rtx = NULL_RTX;
1247 break;
1249 case OPT_fstack_limit_register_:
1251 int reg = decode_reg_name (arg);
1252 if (reg < 0)
1253 error ("unrecognized register name \"%s\"", arg);
1254 else
1255 stack_limit_rtx = gen_rtx_REG (Pmode, reg);
1257 break;
1259 case OPT_fstack_limit_symbol_:
1260 stack_limit_rtx = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (arg));
1261 break;
1263 case OPT_fstrength_reduce:
1264 flag_strength_reduce = value;
1265 break;
1267 case OPT_fstrict_aliasing:
1268 flag_strict_aliasing = value;
1269 break;
1271 case OPT_fsyntax_only:
1272 flag_syntax_only = value;
1273 break;
1275 case OPT_ftest_coverage:
1276 flag_test_coverage = value;
1277 break;
1279 case OPT_fthread_jumps:
1280 flag_thread_jumps = value;
1281 break;
1283 case OPT_ftime_report:
1284 time_report = value;
1285 break;
1287 case OPT_ftls_model_:
1288 if (!strcmp (arg, "global-dynamic"))
1289 flag_tls_default = TLS_MODEL_GLOBAL_DYNAMIC;
1290 else if (!strcmp (arg, "local-dynamic"))
1291 flag_tls_default = TLS_MODEL_LOCAL_DYNAMIC;
1292 else if (!strcmp (arg, "initial-exec"))
1293 flag_tls_default = TLS_MODEL_INITIAL_EXEC;
1294 else if (!strcmp (arg, "local-exec"))
1295 flag_tls_default = TLS_MODEL_LOCAL_EXEC;
1296 else
1297 warning ("unknown tls-model \"%s\"", arg);
1298 break;
1300 case OPT_ftracer:
1301 flag_tracer = value;
1302 break;
1304 case OPT_ftrapping_math:
1305 flag_trapping_math = value;
1306 break;
1308 case OPT_ftrapv:
1309 flag_trapv = value;
1310 break;
1312 case OPT_funit_at_a_time:
1313 flag_unit_at_a_time = value;
1314 break;
1316 case OPT_funroll_all_loops:
1317 flag_unroll_all_loops = value;
1318 break;
1320 case OPT_funroll_loops:
1321 flag_unroll_loops = value;
1322 break;
1324 case OPT_funsafe_math_optimizations:
1325 flag_unsafe_math_optimizations = value;
1326 break;
1328 case OPT_funswitch_loops:
1329 flag_unswitch_loops = value;
1330 break;
1332 case OPT_funwind_tables:
1333 flag_unwind_tables = value;
1334 break;
1336 case OPT_fverbose_asm:
1337 flag_verbose_asm = value;
1338 break;
1340 case OPT_fwrapv:
1341 flag_wrapv = value;
1342 break;
1344 case OPT_fwritable_strings:
1345 flag_writable_strings = value;
1346 break;
1348 case OPT_fzero_initialized_in_bss:
1349 flag_zero_initialized_in_bss = value;
1350 break;
1352 case OPT_g:
1353 decode_g_option (arg);
1354 break;
1356 case OPT_m:
1357 set_target_switch (arg);
1358 break;
1360 case OPT_o:
1361 asm_file_name = arg;
1362 break;
1364 case OPT_p:
1365 profile_flag = 1;
1366 break;
1368 case OPT_pedantic:
1369 pedantic = 1;
1370 break;
1372 case OPT_pedantic_errors:
1373 flag_pedantic_errors = pedantic = 1;
1374 break;
1376 case OPT_quiet:
1377 quiet_flag = 1;
1378 break;
1380 case OPT_version:
1381 version_flag = 1;
1382 break;
1384 case OPT_w:
1385 inhibit_warnings = true;
1386 break;
1389 return 1;
1392 /* Handle --param NAME=VALUE. */
1393 static void
1394 handle_param (const char *carg)
1396 char *equal, *arg;
1397 int value;
1399 arg = xstrdup (carg);
1400 equal = strchr (arg, '=');
1401 if (!equal)
1402 error ("%s: --param arguments should be of the form NAME=VALUE", arg);
1403 else
1405 value = integral_argument (equal + 1);
1406 if (value == -1)
1407 error ("invalid --param value `%s'", equal + 1);
1408 else
1410 *equal = '\0';
1411 set_param_value (arg, value);
1415 free (arg);
1418 /* Handle -W and -Wextra. */
1419 static void
1420 set_Wextra (int setting)
1422 extra_warnings = setting;
1423 warn_unused_value = setting;
1424 warn_unused_parameter = (setting && maybe_warn_unused_parameter);
1426 /* We save the value of warn_uninitialized, since if they put
1427 -Wuninitialized on the command line, we need to generate a
1428 warning about not using it without also specifying -O. */
1429 if (setting == 0)
1430 warn_uninitialized = 0;
1431 else if (warn_uninitialized != 1)
1432 warn_uninitialized = 2;
1435 /* Initialize unused warning flags. */
1436 void
1437 set_Wunused (int setting)
1439 warn_unused_function = setting;
1440 warn_unused_label = setting;
1441 /* Unused function parameter warnings are reported when either
1442 ``-Wextra -Wunused'' or ``-Wunused-parameter'' is specified.
1443 Thus, if -Wextra has already been seen, set warn_unused_parameter;
1444 otherwise set maybe_warn_extra_parameter, which will be picked up
1445 by set_Wextra. */
1446 maybe_warn_unused_parameter = setting;
1447 warn_unused_parameter = (setting && extra_warnings);
1448 warn_unused_variable = setting;
1449 warn_unused_value = setting;
1452 /* The following routines are useful in setting all the flags that
1453 -ffast-math and -fno-fast-math imply. */
1454 void
1455 set_fast_math_flags (int set)
1457 flag_trapping_math = !set;
1458 flag_unsafe_math_optimizations = set;
1459 flag_finite_math_only = set;
1460 flag_errno_math = !set;
1461 if (set)
1462 flag_signaling_nans = 0;
1465 /* Return true iff flags are set as if -ffast-math. */
1466 bool
1467 fast_math_flags_set_p (void)
1469 return (!flag_trapping_math
1470 && flag_unsafe_math_optimizations
1471 && flag_finite_math_only
1472 && !flag_errno_math);