* opts.c (decode_options): Do language-specific initialization for
[official-gcc.git] / gcc / opts.c
blob31041932723541aefc9c3011024c6d57eccf93de
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 /* Input file names. */
138 const char **in_fnames;
139 unsigned num_in_fnames;
141 static size_t find_opt (const char *, int);
142 static int common_handle_option (size_t scode, const char *arg, int value);
143 static void handle_param (const char *);
144 static void set_Wextra (int);
145 static unsigned int handle_option (const char **argv, unsigned int lang_mask);
146 static char *write_langs (unsigned int lang_mask);
147 static void complain_wrong_lang (const char *, const struct cl_option *,
148 unsigned int lang_mask);
149 static void handle_options (unsigned int, const char **, unsigned int);
150 static void wrap_help (const char *help, const char *item, unsigned int);
151 static void print_help (void);
152 static void print_param_help (void);
153 static void print_filtered_help (unsigned int flag);
154 static unsigned int print_switch (const char *text, unsigned int indent);
156 /* Perform a binary search to find which option the command-line INPUT
157 matches. Returns its index in the option array, and N_OPTS
158 (cl_options_count) on failure.
160 This routine is quite subtle. A normal binary search is not good
161 enough because some options can be suffixed with an argument, and
162 multiple sub-matches can occur, e.g. input of "-pedantic" matching
163 the initial substring of "-pedantic-errors".
165 A more complicated example is -gstabs. It should match "-g" with
166 an argument of "stabs". Suppose, however, that the number and list
167 of switches are such that the binary search tests "-gen-decls"
168 before having tested "-g". This doesn't match, and as "-gen-decls"
169 is less than "-gstabs", it will become the lower bound of the
170 binary search range, and "-g" will never be seen. To resolve this
171 issue, opts.sh makes "-gen-decls" point, via the back_chain member,
172 to "-g" so that failed searches that end between "-gen-decls" and
173 the lexicographically subsequent switch know to go back and see if
174 "-g" causes a match (which it does in this example).
176 This search is done in such a way that the longest match for the
177 front end in question wins. If there is no match for the current
178 front end, the longest match for a different front end is returned
179 (or N_OPTS if none) and the caller emits an error message. */
180 static size_t
181 find_opt (const char *input, int lang_mask)
183 size_t mn, mx, md, opt_len;
184 size_t match_wrong_lang;
185 int comp;
187 mn = 0;
188 mx = cl_options_count;
190 /* Find mn such this lexicographical inequality holds:
191 cl_options[mn] <= input < cl_options[mn + 1]. */
192 while (mx - mn > 1)
194 md = (mn + mx) / 2;
195 opt_len = cl_options[md].opt_len;
196 comp = strncmp (input, cl_options[md].opt_text + 1, opt_len);
198 if (comp < 0)
199 mx = md;
200 else
201 mn = md;
204 /* This is the switch that is the best match but for a different
205 front end, or cl_options_count if there is no match at all. */
206 match_wrong_lang = cl_options_count;
208 /* Backtrace the chain of possible matches, returning the longest
209 one, if any, that fits best. With current GCC switches, this
210 loop executes at most twice. */
213 const struct cl_option *opt = &cl_options[mn];
215 /* Is this switch a prefix of the input? */
216 if (!strncmp (input, opt->opt_text + 1, opt->opt_len))
218 /* If language is OK, and the match is exact or the switch
219 takes a joined argument, return it. */
220 if ((opt->flags & lang_mask)
221 && (input[opt->opt_len] == '\0' || (opt->flags & CL_JOINED)))
222 return mn;
224 /* If we haven't remembered a prior match, remember this
225 one. Any prior match is necessarily better. */
226 if (match_wrong_lang == cl_options_count)
227 match_wrong_lang = mn;
230 /* Try the next possibility. This is cl_options_count if there
231 are no more. */
232 mn = opt->back_chain;
234 while (mn != cl_options_count);
236 /* Return the best wrong match, or cl_options_count if none. */
237 return match_wrong_lang;
240 /* If ARG is a non-negative integer made up solely of digits, return its
241 value, otherwise return -1. */
242 static int
243 integral_argument (const char *arg)
245 const char *p = arg;
247 while (*p && ISDIGIT (*p))
248 p++;
250 if (*p == '\0')
251 return atoi (arg);
253 return -1;
256 /* Return a malloced slash-separated list of languages in MASK. */
257 static char *
258 write_langs (unsigned int mask)
260 unsigned int n = 0, len = 0;
261 const char *lang_name;
262 char *result;
264 for (n = 0; (lang_name = lang_names[n]) != 0; n++)
265 if (mask & (1U << n))
266 len += strlen (lang_name) + 1;
268 result = xmalloc (len);
269 len = 0;
270 for (n = 0; (lang_name = lang_names[n]) != 0; n++)
271 if (mask & (1U << n))
273 if (len)
274 result[len++] = '/';
275 strcpy (result + len, lang_name);
276 len += strlen (lang_name);
279 result[len] = 0;
281 return result;
284 /* Complain that switch OPT_INDEX does not apply to this front end. */
285 static void
286 complain_wrong_lang (const char *text, const struct cl_option *option,
287 unsigned int lang_mask)
289 char *ok_langs, *bad_lang;
291 ok_langs = write_langs (option->flags);
292 bad_lang = write_langs (lang_mask);
294 /* Eventually this should become a hard error IMO. */
295 warning ("command line option \"%s\" is valid for %s but not for %s",
296 text, ok_langs, bad_lang);
298 free (ok_langs);
299 free (bad_lang);
302 /* Handle the switch beginning at ARGV for the language indicated by
303 LANG_MASK. Returns the number of switches consumed. */
304 static unsigned int
305 handle_option (const char **argv, unsigned int lang_mask)
307 size_t opt_index;
308 const char *opt, *arg = 0;
309 char *dup = 0;
310 int value = 1;
311 unsigned int result = 0;
312 const struct cl_option *option;
314 opt = argv[0];
316 /* Drop the "no-" from negative switches. */
317 if ((opt[1] == 'W' || opt[1] == 'f')
318 && opt[2] == 'n' && opt[3] == 'o' && opt[4] == '-')
320 size_t len = strlen (opt) - 3;
322 dup = xmalloc (len + 1);
323 dup[0] = '-';
324 dup[1] = opt[1];
325 memcpy (dup + 2, opt + 5, len - 2 + 1);
326 opt = dup;
327 value = 0;
330 opt_index = find_opt (opt + 1, lang_mask | CL_COMMON);
331 if (opt_index == cl_options_count)
332 goto done;
334 option = &cl_options[opt_index];
336 /* Reject negative form of switches that don't take negatives as
337 unrecognized. */
338 if (!value && (option->flags & CL_REJECT_NEGATIVE))
339 goto done;
341 /* We've recognized this switch. */
342 result = 1;
344 /* Sort out any argument the switch takes. */
345 if (option->flags & CL_JOINED)
347 /* Have arg point to the original switch. This is because
348 some code, such as disable_builtin_function, expects its
349 argument to be persistent until the program exits. */
350 arg = argv[0] + cl_options[opt_index].opt_len + 1;
351 if (!value)
352 arg += strlen ("no-");
354 if (*arg == '\0' && !(option->flags & CL_MISSING_OK))
356 if (option->flags & CL_SEPARATE)
358 arg = argv[1];
359 result = 2;
361 else
362 /* Missing argument. */
363 arg = NULL;
366 else if (option->flags & CL_SEPARATE)
368 arg = argv[1];
369 result = 2;
372 /* Now we've swallowed any potential argument, complain if this
373 is a switch for a different front end. */
374 if (!(option->flags & (lang_mask | CL_COMMON)))
376 complain_wrong_lang (argv[0], option, lang_mask);
377 goto done;
380 if (arg == NULL && (option->flags & (CL_JOINED | CL_SEPARATE)))
382 if (!(*lang_hooks.missing_argument) (opt, opt_index))
383 error ("missing argument to \"%s\"", opt);
384 goto done;
387 /* If the switch takes an integer, convert it. */
388 if (arg && (option->flags & CL_UINTEGER))
390 value = integral_argument (arg);
391 if (value == -1)
393 error ("argument to \"%s\" should be a non-negative integer",
394 option->opt_text);
395 goto done;
399 if (option->flags & lang_mask)
400 if ((*lang_hooks.handle_option) (opt_index, arg, value) == 0)
401 result = 0;
403 if (result && (option->flags & CL_COMMON))
404 if (common_handle_option (opt_index, arg, value) == 0)
405 result = 0;
407 done:
408 if (dup)
409 free (dup);
410 return result;
413 /* Decode and handle the vector of command line options. LANG_MASK
414 contains has a single bit set representing the current
415 language. */
416 static void
417 handle_options (unsigned int argc, const char **argv, unsigned int lang_mask)
419 unsigned int n, i;
421 for (i = 1; i < argc; i += n)
423 const char *opt = argv[i];
425 /* Interpret "-" or a non-switch as a file name. */
426 if (opt[0] != '-' || opt[1] == '\0')
428 main_input_filename = opt;
429 add_input_filename (opt);
430 n = 1;
431 continue;
434 n = handle_option (argv + i, lang_mask);
436 if (!n)
438 n = 1;
439 error ("unrecognized command line option \"%s\"", opt);
444 /* Handle FILENAME from the command line. */
445 void
446 add_input_filename (const char *filename)
448 num_in_fnames++;
449 in_fnames = xrealloc (in_fnames, num_in_fnames * sizeof (in_fnames[0]));
450 in_fnames[num_in_fnames - 1] = filename;
453 /* Parse command line options and set default flag values. Do minimal
454 options processing. */
455 void
456 decode_options (unsigned int argc, const char **argv)
458 unsigned int i, lang_mask;
460 /* Perform language-specific options initialization. */
461 lang_mask = (*lang_hooks.init_options) (argc, argv);
463 lang_hooks.initialize_diagnostics (global_dc);
465 /* Scan to see what optimization level has been specified. That will
466 determine the default value of many flags. */
467 for (i = 1; i < argc; i++)
469 if (!strcmp (argv[i], "-O"))
471 optimize = 1;
472 optimize_size = 0;
474 else if (argv[i][0] == '-' && argv[i][1] == 'O')
476 /* Handle -Os, -O2, -O3, -O69, ... */
477 const char *p = &argv[i][2];
479 if ((p[0] == 's') && (p[1] == 0))
481 optimize_size = 1;
483 /* Optimizing for size forces optimize to be 2. */
484 optimize = 2;
486 else
488 const int optimize_val = read_integral_parameter (p, p - 2, -1);
489 if (optimize_val != -1)
491 optimize = optimize_val;
492 optimize_size = 0;
498 if (!optimize)
500 flag_merge_constants = 0;
503 if (optimize >= 1)
505 flag_defer_pop = 1;
506 flag_thread_jumps = 1;
507 #ifdef DELAY_SLOTS
508 flag_delayed_branch = 1;
509 #endif
510 #ifdef CAN_DEBUG_WITHOUT_FP
511 flag_omit_frame_pointer = 1;
512 #endif
513 flag_guess_branch_prob = 1;
514 flag_cprop_registers = 1;
515 flag_loop_optimize = 1;
516 flag_crossjumping = 1;
517 flag_if_conversion = 1;
518 flag_if_conversion2 = 1;
521 if (optimize >= 2)
523 flag_optimize_sibling_calls = 1;
524 flag_cse_follow_jumps = 1;
525 flag_cse_skip_blocks = 1;
526 flag_gcse = 1;
527 flag_expensive_optimizations = 1;
528 flag_strength_reduce = 1;
529 flag_rerun_cse_after_loop = 1;
530 flag_rerun_loop_opt = 1;
531 flag_caller_saves = 1;
532 flag_force_mem = 1;
533 flag_peephole2 = 1;
534 #ifdef INSN_SCHEDULING
535 flag_schedule_insns = 1;
536 flag_schedule_insns_after_reload = 1;
537 #endif
538 flag_regmove = 1;
539 flag_strict_aliasing = 1;
540 flag_delete_null_pointer_checks = 1;
541 flag_reorder_blocks = 1;
542 flag_reorder_functions = 1;
545 if (optimize >= 3)
547 flag_inline_functions = 1;
548 flag_rename_registers = 1;
549 flag_unswitch_loops = 1;
550 flag_unit_at_a_time = 1;
553 if (optimize < 2 || optimize_size)
555 align_loops = 1;
556 align_jumps = 1;
557 align_labels = 1;
558 align_functions = 1;
560 /* Don't reorder blocks when optimizing for size because extra
561 jump insns may be created; also barrier may create extra padding.
563 More correctly we should have a block reordering mode that tried
564 to minimize the combined size of all the jumps. This would more
565 or less automatically remove extra jumps, but would also try to
566 use more short jumps instead of long jumps. */
567 flag_reorder_blocks = 0;
570 /* Initialize whether `char' is signed. */
571 flag_signed_char = DEFAULT_SIGNED_CHAR;
572 #ifdef DEFAULT_SHORT_ENUMS
573 /* Initialize how much space enums occupy, by default. */
574 flag_short_enums = DEFAULT_SHORT_ENUMS;
575 #endif
577 /* Initialize target_flags before OPTIMIZATION_OPTIONS so the latter can
578 modify it. */
579 target_flags = 0;
580 set_target_switch ("");
582 /* Unwind tables are always present in an ABI-conformant IA-64
583 object file, so the default should be ON. */
584 #ifdef IA64_UNWIND_INFO
585 flag_unwind_tables = IA64_UNWIND_INFO;
586 #endif
588 #ifdef OPTIMIZATION_OPTIONS
589 /* Allow default optimizations to be specified on a per-machine basis. */
590 OPTIMIZATION_OPTIONS (optimize, optimize_size);
591 #endif
593 handle_options (argc, argv, lang_mask);
595 if (flag_pie)
596 flag_pic = flag_pie;
597 if (flag_pic && !flag_pie)
598 flag_shlib = 1;
600 if (flag_no_inline == 2)
601 flag_no_inline = 0;
602 else
603 flag_really_no_inline = flag_no_inline;
605 /* Set flag_no_inline before the post_options () hook. The C front
606 ends use it to determine tree inlining defaults. FIXME: such
607 code should be lang-independent when all front ends use tree
608 inlining, in which case it, and this condition, should be moved
609 to the top of process_options() instead. */
610 if (optimize == 0)
612 /* Inlining does not work if not optimizing,
613 so force it not to be done. */
614 flag_no_inline = 1;
615 warn_inline = 0;
617 /* The c_decode_option function and decode_option hook set
618 this to `2' if -Wall is used, so we can avoid giving out
619 lots of errors for people who don't realize what -Wall does. */
620 if (warn_uninitialized == 1)
621 warning ("-Wuninitialized is not supported without -O");
624 if (flag_really_no_inline == 2)
625 flag_really_no_inline = flag_no_inline;
628 /* Handle target- and language-independent options. Return zero to
629 generate an "unknown option" message. */
630 static int
631 common_handle_option (size_t scode, const char *arg,
632 int value ATTRIBUTE_UNUSED)
634 enum opt_code code = (enum opt_code) scode;
636 switch (code)
638 default:
639 abort ();
641 case OPT__help:
642 print_help ();
643 exit_after_options = true;
644 break;
646 case OPT__param:
647 handle_param (arg);
648 break;
650 case OPT__target_help:
651 display_target_options ();
652 exit_after_options = true;
653 break;
655 case OPT__version:
656 print_version (stderr, "");
657 exit_after_options = true;
658 break;
660 case OPT_G:
661 g_switch_value = value;
662 g_switch_set = true;
663 break;
665 case OPT_O:
666 case OPT_Os:
667 /* Currently handled in a prescan. */
668 break;
670 case OPT_W:
671 /* For backward compatibility, -W is the same as -Wextra. */
672 set_Wextra (value);
673 break;
675 case OPT_Waggregate_return:
676 warn_aggregate_return = value;
677 break;
679 case OPT_Wcast_align:
680 warn_cast_align = value;
681 break;
683 case OPT_Wdeprecated_declarations:
684 warn_deprecated_decl = value;
685 break;
687 case OPT_Wdisabled_optimization:
688 warn_disabled_optimization = value;
689 break;
691 case OPT_Werror:
692 warnings_are_errors = value;
693 break;
695 case OPT_Wextra:
696 set_Wextra (value);
697 break;
699 case OPT_Winline:
700 warn_inline = value;
701 break;
703 case OPT_Wlarger_than_:
704 larger_than_size = value;
705 warn_larger_than = value != -1;
706 break;
708 case OPT_Wmissing_noreturn:
709 warn_missing_noreturn = value;
710 break;
712 case OPT_Wpacked:
713 warn_packed = value;
714 break;
716 case OPT_Wpadded:
717 warn_padded = value;
718 break;
720 case OPT_Wshadow:
721 warn_shadow = value;
722 break;
724 case OPT_Wstrict_aliasing:
725 warn_strict_aliasing = value;
726 break;
728 case OPT_Wswitch:
729 warn_switch = value;
730 break;
732 case OPT_Wswitch_default:
733 warn_switch_default = value;
734 break;
736 case OPT_Wswitch_enum:
737 warn_switch_enum = value;
738 break;
740 case OPT_Wsystem_headers:
741 warn_system_headers = value;
742 break;
744 case OPT_Wuninitialized:
745 warn_uninitialized = value;
746 break;
748 case OPT_Wunreachable_code:
749 warn_notreached = value;
750 break;
752 case OPT_Wunused:
753 set_Wunused (value);
754 break;
756 case OPT_Wunused_function:
757 warn_unused_function = value;
758 break;
760 case OPT_Wunused_label:
761 warn_unused_label = value;
762 break;
764 case OPT_Wunused_parameter:
765 warn_unused_parameter = value;
766 break;
768 case OPT_Wunused_value:
769 warn_unused_value = value;
770 break;
772 case OPT_Wunused_variable:
773 warn_unused_variable = value;
774 break;
776 case OPT_aux_info:
777 case OPT_aux_info_:
778 aux_info_file_name = arg;
779 flag_gen_aux_info = 1;
780 break;
782 case OPT_auxbase:
783 aux_base_name = arg;
784 break;
786 case OPT_auxbase_strip:
788 char *tmp = xstrdup (arg);
789 strip_off_ending (tmp, strlen (tmp));
790 if (tmp[0])
791 aux_base_name = tmp;
793 break;
795 case OPT_d:
796 decode_d_option (arg);
797 break;
799 case OPT_dumpbase:
800 dump_base_name = arg;
801 break;
803 case OPT_fPIC:
804 flag_pic = value + value;
805 break;
807 case OPT_fPIE:
808 flag_pie = value + value;
809 break;
811 case OPT_falign_functions:
812 align_functions = !value;
813 break;
815 case OPT_falign_functions_:
816 align_functions = value;
817 break;
819 case OPT_falign_jumps:
820 align_jumps = !value;
821 break;
823 case OPT_falign_jumps_:
824 align_jumps = value;
825 break;
827 case OPT_falign_labels:
828 align_labels = !value;
829 break;
831 case OPT_falign_labels_:
832 align_labels = value;
833 break;
835 case OPT_falign_loops:
836 align_loops = !value;
837 break;
839 case OPT_falign_loops_:
840 align_loops = value;
841 break;
843 case OPT_fargument_alias:
844 flag_argument_noalias = !value;
845 break;
847 case OPT_fargument_noalias:
848 flag_argument_noalias = value;
849 break;
851 case OPT_fargument_noalias_global:
852 flag_argument_noalias = value + value;
853 break;
855 case OPT_fasynchronous_unwind_tables:
856 flag_asynchronous_unwind_tables = value;
857 break;
859 case OPT_fbounds_check:
860 flag_bounds_check = value;
861 break;
863 case OPT_fbranch_count_reg:
864 flag_branch_on_count_reg = value;
865 break;
867 case OPT_fbranch_probabilities:
868 flag_branch_probabilities = value;
869 break;
871 case OPT_fbranch_target_load_optimize:
872 flag_branch_target_load_optimize = value;
873 break;
875 case OPT_fbranch_target_load_optimize2:
876 flag_branch_target_load_optimize2 = value;
877 break;
879 case OPT_fcall_used_:
880 fix_register (arg, 0, 1);
881 break;
883 case OPT_fcall_saved_:
884 fix_register (arg, 0, 0);
885 break;
887 case OPT_fcaller_saves:
888 flag_caller_saves = value;
889 break;
891 case OPT_fcommon:
892 flag_no_common = !value;
893 break;
895 case OPT_fcprop_registers:
896 flag_cprop_registers = value;
897 break;
899 case OPT_fcrossjumping:
900 flag_crossjumping = value;
901 break;
903 case OPT_fcse_follow_jumps:
904 flag_cse_follow_jumps = value;
905 break;
907 case OPT_fcse_skip_blocks:
908 flag_cse_skip_blocks = value;
909 break;
911 case OPT_fdata_sections:
912 flag_data_sections = value;
913 break;
915 case OPT_fdefer_pop:
916 flag_defer_pop = value;
917 break;
919 case OPT_fdelayed_branch:
920 flag_delayed_branch = value;
921 break;
923 case OPT_fdelete_null_pointer_checks:
924 flag_delete_null_pointer_checks = value;
925 break;
927 case OPT_fdiagnostics_show_location_:
928 if (!strcmp (arg, "once"))
929 diagnostic_prefixing_rule (global_dc) = DIAGNOSTICS_SHOW_PREFIX_ONCE;
930 else if (!strcmp (arg, "every-line"))
931 diagnostic_prefixing_rule (global_dc)
932 = DIAGNOSTICS_SHOW_PREFIX_EVERY_LINE;
933 else
934 return 0;
935 break;
937 case OPT_fdump_unnumbered:
938 flag_dump_unnumbered = value;
939 break;
941 case OPT_feliminate_dwarf2_dups:
942 flag_eliminate_dwarf2_dups = value;
943 break;
945 case OPT_feliminate_unused_debug_types:
946 flag_eliminate_unused_debug_types = value;
947 break;
949 case OPT_feliminate_unused_debug_symbols:
950 flag_debug_only_used_symbols = value;
951 break;
953 case OPT_fexceptions:
954 flag_exceptions = value;
955 break;
957 case OPT_fexpensive_optimizations:
958 flag_expensive_optimizations = value;
959 break;
961 case OPT_ffast_math:
962 set_fast_math_flags (value);
963 break;
965 case OPT_ffinite_math_only:
966 flag_finite_math_only = value;
967 break;
969 case OPT_ffixed_:
970 fix_register (arg, 1, 1);
971 break;
973 case OPT_ffunction_cse:
974 flag_no_function_cse = !value;
975 break;
977 case OPT_ffloat_store:
978 flag_float_store = value;
979 break;
981 case OPT_fforce_addr:
982 flag_force_addr = value;
983 break;
985 case OPT_fforce_mem:
986 flag_force_mem = value;
987 break;
989 case OPT_ffunction_sections:
990 flag_function_sections = value;
991 break;
993 case OPT_fgcse:
994 flag_gcse = value;
995 break;
997 case OPT_fgcse_lm:
998 flag_gcse_lm = value;
999 break;
1001 case OPT_fgcse_sm:
1002 flag_gcse_sm = value;
1003 break;
1005 case OPT_fgnu_linker:
1006 flag_gnu_linker = value;
1007 break;
1009 case OPT_fguess_branch_probability:
1010 flag_guess_branch_prob = value;
1011 break;
1013 case OPT_fident:
1014 flag_no_ident = !value;
1015 break;
1017 case OPT_fif_conversion:
1018 flag_if_conversion = value;
1019 break;
1021 case OPT_fif_conversion2:
1022 flag_if_conversion2 = value;
1023 break;
1025 case OPT_finhibit_size_directive:
1026 flag_inhibit_size_directive = value;
1027 break;
1029 case OPT_finline:
1030 flag_no_inline = !value;
1031 break;
1033 case OPT_finline_functions:
1034 flag_inline_functions = value;
1035 break;
1037 case OPT_finline_limit_:
1038 case OPT_finline_limit_eq:
1039 set_param_value ("max-inline-insns", value);
1040 set_param_value ("max-inline-insns-single", value / 2);
1041 set_param_value ("max-inline-insns-auto", value / 2);
1042 set_param_value ("max-inline-insns-rtl", value);
1043 if (value / 4 < MIN_INLINE_INSNS)
1045 if (value / 4 > 10)
1046 set_param_value ("min-inline-insns", value / 4);
1047 else
1048 set_param_value ("min-inline-insns", 10);
1050 break;
1052 case OPT_finstrument_functions:
1053 flag_instrument_function_entry_exit = value;
1054 break;
1056 case OPT_fkeep_inline_functions:
1057 flag_keep_inline_functions =value;
1058 break;
1060 case OPT_fkeep_static_consts:
1061 flag_keep_static_consts = value;
1062 break;
1064 case OPT_fleading_underscore:
1065 flag_leading_underscore = value;
1066 break;
1068 case OPT_floop_optimize:
1069 flag_loop_optimize = value;
1070 break;
1072 case OPT_fmath_errno:
1073 flag_errno_math = value;
1074 break;
1076 case OPT_fmem_report:
1077 mem_report = value;
1078 break;
1080 case OPT_fmerge_all_constants:
1081 flag_merge_constants = value + value;
1082 break;
1084 case OPT_fmerge_constants:
1085 flag_merge_constants = value;
1086 break;
1088 case OPT_fmessage_length_:
1089 pp_set_line_maximum_length (global_dc->printer, value);
1090 break;
1092 case OPT_fmove_all_movables:
1093 flag_move_all_movables = value;
1094 break;
1096 case OPT_fnew_ra:
1097 flag_new_regalloc = value;
1098 break;
1100 case OPT_fnon_call_exceptions:
1101 flag_non_call_exceptions = value;
1102 break;
1104 case OPT_fold_unroll_all_loops:
1105 flag_old_unroll_all_loops = value;
1106 break;
1108 case OPT_fold_unroll_loops:
1109 flag_old_unroll_loops = value;
1110 break;
1112 case OPT_fomit_frame_pointer:
1113 flag_omit_frame_pointer = value;
1114 break;
1116 case OPT_foptimize_register_move:
1117 flag_regmove = value;
1118 break;
1120 case OPT_foptimize_sibling_calls:
1121 flag_optimize_sibling_calls = value;
1122 break;
1124 case OPT_fpack_struct:
1125 flag_pack_struct = value;
1126 break;
1128 case OPT_fpeel_loops:
1129 flag_peel_loops = value;
1130 break;
1132 case OPT_fpcc_struct_return:
1133 flag_pcc_struct_return = value;
1134 break;
1136 case OPT_fpeephole:
1137 flag_no_peephole = !value;
1138 break;
1140 case OPT_fpeephole2:
1141 flag_peephole2 = value;
1142 break;
1144 case OPT_fpic:
1145 flag_pic = value;
1146 break;
1148 case OPT_fpie:
1149 flag_pie = value;
1150 break;
1152 case OPT_fprefetch_loop_arrays:
1153 flag_prefetch_loop_arrays = value;
1154 break;
1156 case OPT_fprofile:
1157 profile_flag = value;
1158 break;
1160 case OPT_fprofile_arcs:
1161 profile_arc_flag = value;
1162 break;
1164 case OPT_frandom_seed:
1165 /* The real switch is -fno-random-seed. */
1166 if (value)
1167 return 0;
1168 flag_random_seed = NULL;
1169 break;
1171 case OPT_frandom_seed_:
1172 flag_random_seed = arg;
1173 break;
1175 case OPT_freduce_all_givs:
1176 flag_reduce_all_givs = value;
1177 break;
1179 case OPT_freg_struct_return:
1180 flag_pcc_struct_return = !value;
1181 break;
1183 case OPT_fregmove:
1184 flag_regmove = value;
1185 break;
1187 case OPT_frename_registers:
1188 flag_rename_registers = value;
1189 break;
1191 case OPT_freorder_blocks:
1192 flag_reorder_blocks = value;
1193 break;
1195 case OPT_freorder_functions:
1196 flag_reorder_functions = value;
1197 break;
1199 case OPT_frerun_cse_after_loop:
1200 flag_rerun_cse_after_loop = value;
1201 break;
1203 case OPT_frerun_loop_opt:
1204 flag_rerun_loop_opt = value;
1205 break;
1207 case OPT_fsched_interblock:
1208 flag_schedule_interblock= value;
1209 break;
1211 case OPT_fsched_spec:
1212 flag_schedule_speculative = value;
1213 break;
1215 case OPT_fsched_spec_load:
1216 flag_schedule_speculative_load = value;
1217 break;
1219 case OPT_fsched_spec_load_dangerous:
1220 flag_schedule_speculative_load_dangerous = value;
1221 break;
1223 case OPT_fsched_verbose_:
1224 #ifdef INSN_SCHEDULING
1225 fix_sched_param ("verbose", arg);
1226 break;
1227 #else
1228 return 0;
1229 #endif
1231 case OPT_fsched2_use_superblocks:
1232 flag_sched2_use_superblocks = value;
1233 break;
1235 case OPT_fsched2_use_traces:
1236 flag_sched2_use_traces = value;
1237 break;
1239 case OPT_fschedule_insns:
1240 flag_schedule_insns = value;
1241 break;
1243 case OPT_fschedule_insns2:
1244 flag_schedule_insns_after_reload = value;
1245 break;
1247 case OPT_fshared_data:
1248 flag_shared_data = value;
1249 break;
1251 case OPT_fsignaling_nans:
1252 flag_signaling_nans = value;
1253 break;
1255 case OPT_fsingle_precision_constant:
1256 flag_single_precision_constant = value;
1257 break;
1259 case OPT_fssa:
1260 flag_ssa = value;
1261 break;
1263 case OPT_fssa_ccp:
1264 flag_ssa_ccp = value;
1265 break;
1267 case OPT_fssa_dce:
1268 flag_ssa_dce = value;
1269 break;
1271 case OPT_fstack_check:
1272 flag_stack_check = value;
1273 break;
1275 case OPT_fstack_limit:
1276 /* The real switch is -fno-stack-limit. */
1277 if (value)
1278 return 0;
1279 stack_limit_rtx = NULL_RTX;
1280 break;
1282 case OPT_fstack_limit_register_:
1284 int reg = decode_reg_name (arg);
1285 if (reg < 0)
1286 error ("unrecognized register name \"%s\"", arg);
1287 else
1288 stack_limit_rtx = gen_rtx_REG (Pmode, reg);
1290 break;
1292 case OPT_fstack_limit_symbol_:
1293 stack_limit_rtx = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (arg));
1294 break;
1296 case OPT_fstrength_reduce:
1297 flag_strength_reduce = value;
1298 break;
1300 case OPT_fstrict_aliasing:
1301 flag_strict_aliasing = value;
1302 break;
1304 case OPT_fsyntax_only:
1305 flag_syntax_only = value;
1306 break;
1308 case OPT_ftest_coverage:
1309 flag_test_coverage = value;
1310 break;
1312 case OPT_fthread_jumps:
1313 flag_thread_jumps = value;
1314 break;
1316 case OPT_ftime_report:
1317 time_report = value;
1318 break;
1320 case OPT_ftls_model_:
1321 if (!strcmp (arg, "global-dynamic"))
1322 flag_tls_default = TLS_MODEL_GLOBAL_DYNAMIC;
1323 else if (!strcmp (arg, "local-dynamic"))
1324 flag_tls_default = TLS_MODEL_LOCAL_DYNAMIC;
1325 else if (!strcmp (arg, "initial-exec"))
1326 flag_tls_default = TLS_MODEL_INITIAL_EXEC;
1327 else if (!strcmp (arg, "local-exec"))
1328 flag_tls_default = TLS_MODEL_LOCAL_EXEC;
1329 else
1330 warning ("unknown tls-model \"%s\"", arg);
1331 break;
1333 case OPT_ftracer:
1334 flag_tracer = value;
1335 break;
1337 case OPT_ftrapping_math:
1338 flag_trapping_math = value;
1339 break;
1341 case OPT_ftrapv:
1342 flag_trapv = value;
1343 break;
1345 case OPT_funit_at_a_time:
1346 flag_unit_at_a_time = value;
1347 break;
1349 case OPT_funroll_all_loops:
1350 flag_unroll_all_loops = value;
1351 break;
1353 case OPT_funroll_loops:
1354 flag_unroll_loops = value;
1355 break;
1357 case OPT_funsafe_math_optimizations:
1358 flag_unsafe_math_optimizations = value;
1359 break;
1361 case OPT_funswitch_loops:
1362 flag_unswitch_loops = value;
1363 break;
1365 case OPT_funwind_tables:
1366 flag_unwind_tables = value;
1367 break;
1369 case OPT_fverbose_asm:
1370 flag_verbose_asm = value;
1371 break;
1373 case OPT_fwrapv:
1374 flag_wrapv = value;
1375 break;
1377 case OPT_fwritable_strings:
1378 flag_writable_strings = value;
1379 break;
1381 case OPT_fzero_initialized_in_bss:
1382 flag_zero_initialized_in_bss = value;
1383 break;
1385 case OPT_g:
1386 decode_g_option (arg);
1387 break;
1389 case OPT_m:
1390 set_target_switch (arg);
1391 break;
1393 case OPT_o:
1394 asm_file_name = arg;
1395 break;
1397 case OPT_p:
1398 profile_flag = 1;
1399 break;
1401 case OPT_pedantic:
1402 pedantic = 1;
1403 break;
1405 case OPT_pedantic_errors:
1406 flag_pedantic_errors = pedantic = 1;
1407 break;
1409 case OPT_quiet:
1410 quiet_flag = 1;
1411 break;
1413 case OPT_version:
1414 version_flag = 1;
1415 break;
1417 case OPT_w:
1418 inhibit_warnings = true;
1419 break;
1422 return 1;
1425 /* Handle --param NAME=VALUE. */
1426 static void
1427 handle_param (const char *carg)
1429 char *equal, *arg;
1430 int value;
1432 arg = xstrdup (carg);
1433 equal = strchr (arg, '=');
1434 if (!equal)
1435 error ("%s: --param arguments should be of the form NAME=VALUE", arg);
1436 else
1438 value = integral_argument (equal + 1);
1439 if (value == -1)
1440 error ("invalid --param value `%s'", equal + 1);
1441 else
1443 *equal = '\0';
1444 set_param_value (arg, value);
1448 free (arg);
1451 /* Handle -W and -Wextra. */
1452 static void
1453 set_Wextra (int setting)
1455 extra_warnings = setting;
1456 warn_unused_value = setting;
1457 warn_unused_parameter = (setting && maybe_warn_unused_parameter);
1459 /* We save the value of warn_uninitialized, since if they put
1460 -Wuninitialized on the command line, we need to generate a
1461 warning about not using it without also specifying -O. */
1462 if (setting == 0)
1463 warn_uninitialized = 0;
1464 else if (warn_uninitialized != 1)
1465 warn_uninitialized = 2;
1468 /* Initialize unused warning flags. */
1469 void
1470 set_Wunused (int setting)
1472 warn_unused_function = setting;
1473 warn_unused_label = setting;
1474 /* Unused function parameter warnings are reported when either
1475 ``-Wextra -Wunused'' or ``-Wunused-parameter'' is specified.
1476 Thus, if -Wextra has already been seen, set warn_unused_parameter;
1477 otherwise set maybe_warn_extra_parameter, which will be picked up
1478 by set_Wextra. */
1479 maybe_warn_unused_parameter = setting;
1480 warn_unused_parameter = (setting && extra_warnings);
1481 warn_unused_variable = setting;
1482 warn_unused_value = setting;
1485 /* The following routines are useful in setting all the flags that
1486 -ffast-math and -fno-fast-math imply. */
1487 void
1488 set_fast_math_flags (int set)
1490 flag_trapping_math = !set;
1491 flag_unsafe_math_optimizations = set;
1492 flag_finite_math_only = set;
1493 flag_errno_math = !set;
1494 if (set)
1495 flag_signaling_nans = 0;
1498 /* Return true iff flags are set as if -ffast-math. */
1499 bool
1500 fast_math_flags_set_p (void)
1502 return (!flag_trapping_math
1503 && flag_unsafe_math_optimizations
1504 && flag_finite_math_only
1505 && !flag_errno_math);
1508 /* Output --help text. */
1509 static void
1510 print_help (void)
1512 size_t i;
1513 const char *p;
1515 GET_ENVIRONMENT (p, "COLUMNS");
1516 if (p)
1518 int value = atoi (p);
1519 if (value > 0)
1520 columns = value;
1523 puts (_("The following options are language-independent:\n"));
1525 print_filtered_help (CL_COMMON);
1526 print_param_help ();
1528 for (i = 0; lang_names[i]; i++)
1530 printf (_("The %s front end recognizes the following options:\n\n"),
1531 lang_names[i]);
1532 print_filtered_help (1U << i);
1535 display_help ();
1538 /* Print the help for --param. */
1539 static void
1540 print_param_help (void)
1542 size_t i;
1544 puts (_("The --param option recognizes the following as parameters:\n"));
1546 for (i = 0; i < LAST_PARAM; i++)
1548 const char *help = compiler_params[i].help;
1549 const char *param = compiler_params[i].option;
1551 if (help == NULL || *help == '\0')
1552 help = undocumented_msg;
1554 /* Get the translation. */
1555 help = _(help);
1557 wrap_help (help, param, strlen (param));
1560 putchar ('\n');
1563 /* Print help for a specific front-end, etc. */
1564 static void
1565 print_filtered_help (unsigned int flag)
1567 unsigned int i, len, filter, indent = 0;
1568 bool duplicates = false;
1569 const char *help, *opt, *tab;
1570 static char *printed;
1572 if (flag == CL_COMMON)
1574 filter = flag;
1575 if (!printed)
1576 printed = xmalloc (cl_options_count);
1577 memset (printed, 0, cl_options_count);
1579 else
1581 /* Don't print COMMON options twice. */
1582 filter = flag | CL_COMMON;
1584 for (i = 0; i < cl_options_count; i++)
1586 if ((cl_options[i].flags & filter) != flag)
1587 continue;
1589 /* Skip help for internal switches. */
1590 if (cl_options[i].flags & CL_UNDOCUMENTED)
1591 continue;
1593 /* Skip switches that have already been printed, mark them to be
1594 listed later. */
1595 if (printed[i])
1597 duplicates = true;
1598 indent = print_switch (cl_options[i].opt_text, indent);
1602 if (duplicates)
1604 putchar ('\n');
1605 putchar ('\n');
1609 for (i = 0; i < cl_options_count; i++)
1611 if ((cl_options[i].flags & filter) != flag)
1612 continue;
1614 /* Skip help for internal switches. */
1615 if (cl_options[i].flags & CL_UNDOCUMENTED)
1616 continue;
1618 /* Skip switches that have already been printed. */
1619 if (printed[i])
1620 continue;
1622 printed[i] = true;
1624 help = cl_options[i].help;
1625 if (!help)
1626 help = undocumented_msg;
1628 /* Get the translation. */
1629 help = _(help);
1631 tab = strchr (help, '\t');
1632 if (tab)
1634 len = tab - help;
1635 opt = help;
1636 help = tab + 1;
1638 else
1640 opt = cl_options[i].opt_text;
1641 len = strlen (opt);
1644 wrap_help (help, opt, len);
1647 putchar ('\n');
1650 /* Output ITEM, of length ITEM_WIDTH, in the left column, followed by
1651 word-wrapped HELP in a second column. */
1652 static unsigned int
1653 print_switch (const char *text, unsigned int indent)
1655 unsigned int len = strlen (text) + 1; /* trailing comma */
1657 if (indent)
1659 putchar (',');
1660 if (indent + len > columns)
1662 putchar ('\n');
1663 putchar (' ');
1664 indent = 1;
1667 else
1668 putchar (' ');
1670 putchar (' ');
1671 fputs (text, stdout);
1673 return indent + len + 1;
1676 /* Output ITEM, of length ITEM_WIDTH, in the left column, followed by
1677 word-wrapped HELP in a second column. */
1678 static void
1679 wrap_help (const char *help, const char *item, unsigned int item_width)
1681 unsigned int col_width = 27;
1682 unsigned int remaining, room, len;
1684 remaining = strlen (help);
1688 room = columns - 3 - MAX (col_width, item_width);
1689 if (room > columns)
1690 room = 0;
1691 len = remaining;
1693 if (room < len)
1695 unsigned int i;
1697 for (i = 0; help[i]; i++)
1699 if (i >= room && len != remaining)
1700 break;
1701 if (help[i] == ' ')
1702 len = i;
1703 else if ((help[i] == '-' || help[i] == '/')
1704 && help[i + 1] != ' '
1705 && ISALPHA (help[i - 1]))
1706 len = i + 1;
1710 printf( " %-*.*s %.*s\n", col_width, item_width, item, len, help);
1711 item_width = 0;
1712 while (help[len] == ' ')
1713 len++;
1714 help += len;
1715 remaining -= len;
1717 while (remaining);