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