* ca.po, rw.po: Remove.
[official-gcc.git] / gcc / opts.c
blob3b5f0cc019a56a104e1f8e2f08299b5a8b522523
1 /* Command line option handling.
2 Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007
3 Free Software Foundation, Inc.
4 Contributed by Neil Booth.
6 This file is part of GCC.
8 GCC is free software; you can redistribute it and/or modify it under
9 the terms of the GNU General Public License as published by the Free
10 Software Foundation; either version 3, or (at your option) any later
11 version.
13 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 for more details.
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING3. If not see
20 <http://www.gnu.org/licenses/>. */
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. */
40 #include "target.h"
41 #include "tree-pass.h"
43 /* Value of the -G xx switch, and whether it was passed or not. */
44 unsigned HOST_WIDE_INT g_switch_value;
45 bool g_switch_set;
47 /* True if we should exit after parsing options. */
48 bool exit_after_options;
50 /* Print various extra warnings. -W/-Wextra. */
51 bool extra_warnings;
53 /* True to warn about any objects definitions whose size is larger
54 than N bytes. Also want about function definitions whose returned
55 values are larger than N bytes, where N is `larger_than_size'. */
56 bool warn_larger_than;
57 HOST_WIDE_INT larger_than_size;
59 /* Hack for cooperation between set_Wunused and set_Wextra. */
60 static bool maybe_warn_unused_parameter;
62 /* Type(s) of debugging information we are producing (if any). See
63 flags.h for the definitions of the different possible types of
64 debugging information. */
65 enum debug_info_type write_symbols = NO_DEBUG;
67 /* Level of debugging information we are producing. See flags.h for
68 the definitions of the different possible levels. */
69 enum debug_info_level debug_info_level = DINFO_LEVEL_NONE;
71 /* Nonzero means use GNU-only extensions in the generated symbolic
72 debugging information. Currently, this only has an effect when
73 write_symbols is set to DBX_DEBUG, XCOFF_DEBUG, or DWARF_DEBUG. */
74 bool use_gnu_debug_info_extensions;
76 /* The default visibility for all symbols (unless overridden) */
77 enum symbol_visibility default_visibility = VISIBILITY_DEFAULT;
79 /* Disable unit-at-a-time for frontends that might be still broken in this
80 respect. */
82 bool no_unit_at_a_time_default;
84 /* Global visibility options. */
85 struct visibility_flags visibility_options;
87 /* Columns of --help display. */
88 static unsigned int columns = 80;
90 /* What to print when a switch has no documentation. */
91 static const char undocumented_msg[] = N_("This switch lacks documentation");
93 /* Used for bookkeeping on whether user set these flags so
94 -fprofile-use/-fprofile-generate does not use them. */
95 static bool profile_arc_flag_set, flag_profile_values_set;
96 static bool flag_unroll_loops_set, flag_tracer_set;
97 static bool flag_value_profile_transformations_set;
98 static bool flag_peel_loops_set, flag_branch_probabilities_set;
100 /* Input file names. */
101 const char **in_fnames;
102 unsigned num_in_fnames;
104 static int common_handle_option (size_t scode, const char *arg, int value,
105 unsigned int lang_mask);
106 static void handle_param (const char *);
107 static void set_Wextra (int);
108 static unsigned int handle_option (const char **argv, unsigned int lang_mask);
109 static char *write_langs (unsigned int lang_mask);
110 static void complain_wrong_lang (const char *, const struct cl_option *,
111 unsigned int lang_mask);
112 static void handle_options (unsigned int, const char **, unsigned int);
113 static void wrap_help (const char *help, const char *item, unsigned int);
114 static void print_target_help (void);
115 static void print_help (void);
116 static void print_param_help (void);
117 static void print_filtered_help (unsigned int);
118 static unsigned int print_switch (const char *text, unsigned int indent);
119 static void set_debug_level (enum debug_info_type type, int extended,
120 const char *arg);
122 /* If ARG is a non-negative integer made up solely of digits, return its
123 value, otherwise return -1. */
124 static int
125 integral_argument (const char *arg)
127 const char *p = arg;
129 while (*p && ISDIGIT (*p))
130 p++;
132 if (*p == '\0')
133 return atoi (arg);
135 return -1;
138 /* Return a malloced slash-separated list of languages in MASK. */
139 static char *
140 write_langs (unsigned int mask)
142 unsigned int n = 0, len = 0;
143 const char *lang_name;
144 char *result;
146 for (n = 0; (lang_name = lang_names[n]) != 0; n++)
147 if (mask & (1U << n))
148 len += strlen (lang_name) + 1;
150 result = XNEWVEC (char, len);
151 len = 0;
152 for (n = 0; (lang_name = lang_names[n]) != 0; n++)
153 if (mask & (1U << n))
155 if (len)
156 result[len++] = '/';
157 strcpy (result + len, lang_name);
158 len += strlen (lang_name);
161 result[len] = 0;
163 return result;
166 /* Complain that switch OPT_INDEX does not apply to this front end. */
167 static void
168 complain_wrong_lang (const char *text, const struct cl_option *option,
169 unsigned int lang_mask)
171 char *ok_langs, *bad_lang;
173 ok_langs = write_langs (option->flags);
174 bad_lang = write_langs (lang_mask);
176 /* Eventually this should become a hard error IMO. */
177 warning (0, "command line option \"%s\" is valid for %s but not for %s",
178 text, ok_langs, bad_lang);
180 free (ok_langs);
181 free (bad_lang);
184 /* Handle the switch beginning at ARGV for the language indicated by
185 LANG_MASK. Returns the number of switches consumed. */
186 static unsigned int
187 handle_option (const char **argv, unsigned int lang_mask)
189 size_t opt_index;
190 const char *opt, *arg = 0;
191 char *dup = 0;
192 int value = 1;
193 unsigned int result = 0;
194 const struct cl_option *option;
196 opt = argv[0];
198 opt_index = find_opt (opt + 1, lang_mask | CL_COMMON | CL_TARGET);
199 if (opt_index == cl_options_count
200 && (opt[1] == 'W' || opt[1] == 'f' || opt[1] == 'm')
201 && opt[2] == 'n' && opt[3] == 'o' && opt[4] == '-')
203 /* Drop the "no-" from negative switches. */
204 size_t len = strlen (opt) - 3;
206 dup = XNEWVEC (char, len + 1);
207 dup[0] = '-';
208 dup[1] = opt[1];
209 memcpy (dup + 2, opt + 5, len - 2 + 1);
210 opt = dup;
211 value = 0;
212 opt_index = find_opt (opt + 1, lang_mask | CL_COMMON | CL_TARGET);
215 if (opt_index == cl_options_count)
216 goto done;
218 option = &cl_options[opt_index];
220 /* Reject negative form of switches that don't take negatives as
221 unrecognized. */
222 if (!value && (option->flags & CL_REJECT_NEGATIVE))
223 goto done;
225 /* We've recognized this switch. */
226 result = 1;
228 /* Check to see if the option is disabled for this configuration. */
229 if (option->flags & CL_DISABLED)
231 error ("command line option %qs"
232 " is not supported by this configuration", opt);
233 goto done;
236 /* Sort out any argument the switch takes. */
237 if (option->flags & CL_JOINED)
239 /* Have arg point to the original switch. This is because
240 some code, such as disable_builtin_function, expects its
241 argument to be persistent until the program exits. */
242 arg = argv[0] + cl_options[opt_index].opt_len + 1;
243 if (!value)
244 arg += strlen ("no-");
246 if (*arg == '\0' && !(option->flags & CL_MISSING_OK))
248 if (option->flags & CL_SEPARATE)
250 arg = argv[1];
251 result = 2;
253 else
254 /* Missing argument. */
255 arg = NULL;
258 else if (option->flags & CL_SEPARATE)
260 arg = argv[1];
261 result = 2;
264 /* Now we've swallowed any potential argument, complain if this
265 is a switch for a different front end. */
266 if (!(option->flags & (lang_mask | CL_COMMON | CL_TARGET)))
268 complain_wrong_lang (argv[0], option, lang_mask);
269 goto done;
272 if (arg == NULL && (option->flags & (CL_JOINED | CL_SEPARATE)))
274 if (!lang_hooks.missing_argument (opt, opt_index))
275 error ("missing argument to \"%s\"", opt);
276 goto done;
279 /* If the switch takes an integer, convert it. */
280 if (arg && (option->flags & CL_UINTEGER))
282 value = integral_argument (arg);
283 if (value == -1)
285 error ("argument to \"%s\" should be a non-negative integer",
286 option->opt_text);
287 goto done;
291 if (option->flag_var)
292 switch (option->var_type)
294 case CLVC_BOOLEAN:
295 *(int *) option->flag_var = value;
296 break;
298 case CLVC_EQUAL:
299 *(int *) option->flag_var = (value
300 ? option->var_value
301 : !option->var_value);
302 break;
304 case CLVC_BIT_CLEAR:
305 case CLVC_BIT_SET:
306 if ((value != 0) == (option->var_type == CLVC_BIT_SET))
307 *(int *) option->flag_var |= option->var_value;
308 else
309 *(int *) option->flag_var &= ~option->var_value;
310 if (option->flag_var == &target_flags)
311 target_flags_explicit |= option->var_value;
312 break;
314 case CLVC_STRING:
315 *(const char **) option->flag_var = arg;
316 break;
319 if (option->flags & lang_mask)
320 if (lang_hooks.handle_option (opt_index, arg, value) == 0)
321 result = 0;
323 if (result && (option->flags & CL_COMMON))
324 if (common_handle_option (opt_index, arg, value, lang_mask) == 0)
325 result = 0;
327 if (result && (option->flags & CL_TARGET))
328 if (!targetm.handle_option (opt_index, arg, value))
329 result = 0;
331 done:
332 if (dup)
333 free (dup);
334 return result;
337 /* Handle FILENAME from the command line. */
338 static void
339 add_input_filename (const char *filename)
341 num_in_fnames++;
342 in_fnames = xrealloc (in_fnames, num_in_fnames * sizeof (in_fnames[0]));
343 in_fnames[num_in_fnames - 1] = filename;
346 /* Decode and handle the vector of command line options. LANG_MASK
347 contains has a single bit set representing the current
348 language. */
349 static void
350 handle_options (unsigned int argc, const char **argv, unsigned int lang_mask)
352 unsigned int n, i;
354 for (i = 1; i < argc; i += n)
356 const char *opt = argv[i];
358 /* Interpret "-" or a non-switch as a file name. */
359 if (opt[0] != '-' || opt[1] == '\0')
361 if (main_input_filename == NULL)
362 main_input_filename = opt;
363 add_input_filename (opt);
364 n = 1;
365 continue;
368 n = handle_option (argv + i, lang_mask);
370 if (!n)
372 n = 1;
373 error ("unrecognized command line option \"%s\"", opt);
378 /* Parse command line options and set default flag values. Do minimal
379 options processing. */
380 void
381 decode_options (unsigned int argc, const char **argv)
383 unsigned int i, lang_mask;
385 /* Perform language-specific options initialization. */
386 lang_mask = lang_hooks.init_options (argc, argv);
388 lang_hooks.initialize_diagnostics (global_dc);
390 /* Scan to see what optimization level has been specified. That will
391 determine the default value of many flags. */
392 for (i = 1; i < argc; i++)
394 if (!strcmp (argv[i], "-O"))
396 optimize = 1;
397 optimize_size = 0;
399 else if (argv[i][0] == '-' && argv[i][1] == 'O')
401 /* Handle -Os, -O2, -O3, -O69, ... */
402 const char *p = &argv[i][2];
404 if ((p[0] == 's') && (p[1] == 0))
406 optimize_size = 1;
408 /* Optimizing for size forces optimize to be 2. */
409 optimize = 2;
411 else
413 const int optimize_val = read_integral_parameter (p, p - 2, -1);
414 if (optimize_val != -1)
416 optimize = optimize_val;
417 optimize_size = 0;
423 if (!optimize)
425 flag_merge_constants = 0;
428 if (optimize >= 1)
430 flag_defer_pop = 1;
431 #ifdef DELAY_SLOTS
432 flag_delayed_branch = 1;
433 #endif
434 #ifdef CAN_DEBUG_WITHOUT_FP
435 flag_omit_frame_pointer = 1;
436 #endif
437 flag_guess_branch_prob = 1;
438 flag_cprop_registers = 1;
439 flag_if_conversion = 1;
440 flag_if_conversion2 = 1;
441 flag_ipa_pure_const = 1;
442 flag_ipa_reference = 1;
443 flag_tree_ccp = 1;
444 flag_tree_dce = 1;
445 flag_tree_dom = 1;
446 flag_tree_dse = 1;
447 flag_tree_ter = 1;
448 flag_tree_live_range_split = 1;
449 flag_tree_sra = 1;
450 flag_tree_copyrename = 1;
451 flag_tree_fre = 1;
452 flag_tree_copy_prop = 1;
453 flag_tree_sink = 1;
454 flag_tree_salias = 1;
455 if (!no_unit_at_a_time_default)
456 flag_unit_at_a_time = 1;
458 if (!optimize_size)
460 /* Loop header copying usually increases size of the code. This used
461 not to be true, since quite often it is possible to verify that
462 the condition is satisfied in the first iteration and therefore
463 to eliminate it. Jump threading handles these cases now. */
464 flag_tree_ch = 1;
468 if (optimize >= 2)
470 flag_thread_jumps = 1;
471 flag_crossjumping = 1;
472 flag_optimize_sibling_calls = 1;
473 flag_cse_follow_jumps = 1;
474 flag_cse_skip_blocks = 1;
475 flag_gcse = 1;
476 flag_expensive_optimizations = 1;
477 flag_ipa_type_escape = 1;
478 flag_rerun_cse_after_loop = 1;
479 flag_caller_saves = 1;
480 flag_peephole2 = 1;
481 #ifdef INSN_SCHEDULING
482 flag_schedule_insns = 1;
483 flag_schedule_insns_after_reload = 1;
484 #endif
485 flag_regmove = 1;
486 flag_strict_aliasing = 1;
487 flag_strict_overflow = 1;
488 flag_delete_null_pointer_checks = 1;
489 flag_reorder_blocks = 1;
490 flag_reorder_functions = 1;
491 flag_tree_store_ccp = 1;
492 flag_tree_store_copy_prop = 1;
493 flag_tree_vrp = 1;
495 if (!optimize_size)
497 /* PRE tends to generate bigger code. */
498 flag_tree_pre = 1;
502 if (optimize >= 3)
504 flag_inline_functions = 1;
505 flag_unswitch_loops = 1;
506 flag_gcse_after_reload = 1;
509 if (optimize < 2 || optimize_size)
511 align_loops = 1;
512 align_jumps = 1;
513 align_labels = 1;
514 align_functions = 1;
516 /* Don't reorder blocks when optimizing for size because extra
517 jump insns may be created; also barrier may create extra padding.
519 More correctly we should have a block reordering mode that tried
520 to minimize the combined size of all the jumps. This would more
521 or less automatically remove extra jumps, but would also try to
522 use more short jumps instead of long jumps. */
523 flag_reorder_blocks = 0;
524 flag_reorder_blocks_and_partition = 0;
527 if (optimize_size)
529 /* Inlining of very small functions usually reduces total size. */
530 set_param_value ("max-inline-insns-single", 5);
531 set_param_value ("max-inline-insns-auto", 5);
532 flag_inline_functions = 1;
534 /* We want to crossjump as much as possible. */
535 set_param_value ("min-crossjump-insns", 1);
538 /* Initialize whether `char' is signed. */
539 flag_signed_char = DEFAULT_SIGNED_CHAR;
540 /* Set this to a special "uninitialized" value. The actual default is set
541 after target options have been processed. */
542 flag_short_enums = 2;
544 /* Initialize target_flags before OPTIMIZATION_OPTIONS so the latter can
545 modify it. */
546 target_flags = targetm.default_target_flags;
548 /* Some tagets have ABI-specified unwind tables. */
549 flag_unwind_tables = targetm.unwind_tables_default;
551 #ifdef OPTIMIZATION_OPTIONS
552 /* Allow default optimizations to be specified on a per-machine basis. */
553 OPTIMIZATION_OPTIONS (optimize, optimize_size);
554 #endif
556 handle_options (argc, argv, lang_mask);
558 if (flag_pie)
559 flag_pic = flag_pie;
560 if (flag_pic && !flag_pie)
561 flag_shlib = 1;
563 if (flag_no_inline == 2)
564 flag_no_inline = 0;
565 else
566 flag_really_no_inline = flag_no_inline;
568 /* Set flag_no_inline before the post_options () hook. The C front
569 ends use it to determine tree inlining defaults. FIXME: such
570 code should be lang-independent when all front ends use tree
571 inlining, in which case it, and this condition, should be moved
572 to the top of process_options() instead. */
573 if (optimize == 0)
575 /* Inlining does not work if not optimizing,
576 so force it not to be done. */
577 flag_no_inline = 1;
578 warn_inline = 0;
580 /* The c_decode_option function and decode_option hook set
581 this to `2' if -Wall is used, so we can avoid giving out
582 lots of errors for people who don't realize what -Wall does. */
583 if (warn_uninitialized == 1)
584 warning (OPT_Wuninitialized,
585 "-Wuninitialized is not supported without -O");
588 if (flag_really_no_inline == 2)
589 flag_really_no_inline = flag_no_inline;
591 /* The optimization to partition hot and cold basic blocks into separate
592 sections of the .o and executable files does not work (currently)
593 with exception handling. This is because there is no support for
594 generating unwind info. If flag_exceptions is turned on we need to
595 turn off the partitioning optimization. */
597 if (flag_exceptions && flag_reorder_blocks_and_partition)
599 inform
600 ("-freorder-blocks-and-partition does not work with exceptions");
601 flag_reorder_blocks_and_partition = 0;
602 flag_reorder_blocks = 1;
605 /* If user requested unwind info, then turn off the partitioning
606 optimization. */
608 if (flag_unwind_tables && ! targetm.unwind_tables_default
609 && flag_reorder_blocks_and_partition)
611 inform ("-freorder-blocks-and-partition does not support unwind info");
612 flag_reorder_blocks_and_partition = 0;
613 flag_reorder_blocks = 1;
616 /* If the target requested unwind info, then turn off the partitioning
617 optimization with a different message. Likewise, if the target does not
618 support named sections. */
620 if (flag_reorder_blocks_and_partition
621 && (!targetm.have_named_sections
622 || (flag_unwind_tables && targetm.unwind_tables_default)))
624 inform
625 ("-freorder-blocks-and-partition does not work on this architecture");
626 flag_reorder_blocks_and_partition = 0;
627 flag_reorder_blocks = 1;
631 /* Handle target- and language-independent options. Return zero to
632 generate an "unknown option" message. Only options that need
633 extra handling need to be listed here; if you simply want
634 VALUE assigned to a variable, it happens automatically. */
636 static int
637 common_handle_option (size_t scode, const char *arg, int value,
638 unsigned int lang_mask)
640 enum opt_code code = (enum opt_code) scode;
642 switch (code)
644 case OPT__help:
645 print_help ();
646 exit_after_options = true;
647 break;
649 case OPT__param:
650 handle_param (arg);
651 break;
653 case OPT__target_help:
654 print_target_help ();
655 exit_after_options = true;
656 break;
658 case OPT__version:
659 print_version (stderr, "");
660 exit_after_options = true;
661 break;
663 case OPT_G:
664 g_switch_value = value;
665 g_switch_set = true;
666 break;
668 case OPT_O:
669 case OPT_Os:
670 /* Currently handled in a prescan. */
671 break;
673 case OPT_W:
674 /* For backward compatibility, -W is the same as -Wextra. */
675 set_Wextra (value);
676 break;
678 case OPT_Werror_:
680 char *new_option;
681 int option_index;
682 new_option = XNEWVEC (char, strlen (arg) + 2);
683 new_option[0] = 'W';
684 strcpy (new_option+1, arg);
685 option_index = find_opt (new_option, lang_mask);
686 if (option_index == N_OPTS)
688 error ("-Werror=%s: No option -%s", arg, new_option);
690 else
692 int kind = value ? DK_ERROR : DK_WARNING;
693 diagnostic_classify_diagnostic (global_dc, option_index, kind);
695 /* -Werror=foo implies -Wfoo. */
696 if (cl_options[option_index].var_type == CLVC_BOOLEAN
697 && cl_options[option_index].flag_var
698 && kind == DK_ERROR)
699 *(int *) cl_options[option_index].flag_var = 1;
700 free (new_option);
703 break;
705 case OPT_Wextra:
706 set_Wextra (value);
707 break;
709 case OPT_Wlarger_than_:
710 larger_than_size = value;
711 warn_larger_than = value != -1;
712 break;
714 case OPT_Wstrict_aliasing:
715 case OPT_Wstrict_aliasing_:
716 warn_strict_aliasing = value;
717 break;
719 case OPT_Wstrict_overflow:
720 warn_strict_overflow = (value
721 ? (int) WARN_STRICT_OVERFLOW_CONDITIONAL
722 : 0);
723 break;
725 case OPT_Wstrict_overflow_:
726 warn_strict_overflow = value;
727 break;
729 case OPT_Wunused:
730 set_Wunused (value);
731 break;
733 case OPT_aux_info:
734 case OPT_aux_info_:
735 aux_info_file_name = arg;
736 flag_gen_aux_info = 1;
737 break;
739 case OPT_auxbase:
740 aux_base_name = arg;
741 break;
743 case OPT_auxbase_strip:
745 char *tmp = xstrdup (arg);
746 strip_off_ending (tmp, strlen (tmp));
747 if (tmp[0])
748 aux_base_name = tmp;
750 break;
752 case OPT_d:
753 decode_d_option (arg);
754 break;
756 case OPT_dumpbase:
757 dump_base_name = arg;
758 break;
760 case OPT_falign_functions_:
761 align_functions = value;
762 break;
764 case OPT_falign_jumps_:
765 align_jumps = value;
766 break;
768 case OPT_falign_labels_:
769 align_labels = value;
770 break;
772 case OPT_falign_loops_:
773 align_loops = value;
774 break;
776 case OPT_fbranch_probabilities:
777 flag_branch_probabilities_set = true;
778 break;
780 case OPT_fcall_used_:
781 fix_register (arg, 0, 1);
782 break;
784 case OPT_fcall_saved_:
785 fix_register (arg, 0, 0);
786 break;
788 case OPT_fdiagnostics_show_location_:
789 if (!strcmp (arg, "once"))
790 diagnostic_prefixing_rule (global_dc) = DIAGNOSTICS_SHOW_PREFIX_ONCE;
791 else if (!strcmp (arg, "every-line"))
792 diagnostic_prefixing_rule (global_dc)
793 = DIAGNOSTICS_SHOW_PREFIX_EVERY_LINE;
794 else
795 return 0;
796 break;
798 case OPT_fdiagnostics_show_option:
799 global_dc->show_option_requested = true;
800 break;
802 case OPT_fdump_:
803 if (!dump_switch_p (arg))
804 return 0;
805 break;
807 case OPT_ffast_math:
808 set_fast_math_flags (value);
809 break;
811 case OPT_ffixed_:
812 fix_register (arg, 1, 1);
813 break;
815 case OPT_finline_limit_:
816 case OPT_finline_limit_eq:
817 set_param_value ("max-inline-insns-single", value / 2);
818 set_param_value ("max-inline-insns-auto", value / 2);
819 break;
821 case OPT_fmessage_length_:
822 pp_set_line_maximum_length (global_dc->printer, value);
823 break;
825 case OPT_fpack_struct_:
826 if (value <= 0 || (value & (value - 1)) || value > 16)
827 error("structure alignment must be a small power of two, not %d", value);
828 else
830 initial_max_fld_align = value;
831 maximum_field_alignment = value * BITS_PER_UNIT;
833 break;
835 case OPT_fpeel_loops:
836 flag_peel_loops_set = true;
837 break;
839 case OPT_fprofile_arcs:
840 profile_arc_flag_set = true;
841 break;
843 case OPT_fprofile_use:
844 if (!flag_branch_probabilities_set)
845 flag_branch_probabilities = value;
846 if (!flag_profile_values_set)
847 flag_profile_values = value;
848 if (!flag_unroll_loops_set)
849 flag_unroll_loops = value;
850 if (!flag_peel_loops_set)
851 flag_peel_loops = value;
852 if (!flag_tracer_set)
853 flag_tracer = value;
854 if (!flag_value_profile_transformations_set)
855 flag_value_profile_transformations = value;
856 break;
858 case OPT_fprofile_generate:
859 if (!profile_arc_flag_set)
860 profile_arc_flag = value;
861 if (!flag_profile_values_set)
862 flag_profile_values = value;
863 if (!flag_value_profile_transformations_set)
864 flag_value_profile_transformations = value;
865 break;
867 case OPT_fprofile_values:
868 flag_profile_values_set = true;
869 break;
871 case OPT_fvisibility_:
873 if (!strcmp(arg, "default"))
874 default_visibility = VISIBILITY_DEFAULT;
875 else if (!strcmp(arg, "internal"))
876 default_visibility = VISIBILITY_INTERNAL;
877 else if (!strcmp(arg, "hidden"))
878 default_visibility = VISIBILITY_HIDDEN;
879 else if (!strcmp(arg, "protected"))
880 default_visibility = VISIBILITY_PROTECTED;
881 else
882 error ("unrecognized visibility value \"%s\"", arg);
884 break;
886 case OPT_fvpt:
887 flag_value_profile_transformations_set = true;
888 break;
890 case OPT_frandom_seed:
891 /* The real switch is -fno-random-seed. */
892 if (value)
893 return 0;
894 flag_random_seed = NULL;
895 break;
897 case OPT_frandom_seed_:
898 flag_random_seed = arg;
899 break;
901 case OPT_fsched_verbose_:
902 #ifdef INSN_SCHEDULING
903 fix_sched_param ("verbose", arg);
904 break;
905 #else
906 return 0;
907 #endif
909 case OPT_fsched_stalled_insns_:
910 flag_sched_stalled_insns = value;
911 if (flag_sched_stalled_insns == 0)
912 flag_sched_stalled_insns = -1;
913 break;
915 case OPT_fsched_stalled_insns_dep_:
916 flag_sched_stalled_insns_dep = value;
917 break;
919 case OPT_fstack_limit:
920 /* The real switch is -fno-stack-limit. */
921 if (value)
922 return 0;
923 stack_limit_rtx = NULL_RTX;
924 break;
926 case OPT_fstack_limit_register_:
928 int reg = decode_reg_name (arg);
929 if (reg < 0)
930 error ("unrecognized register name \"%s\"", arg);
931 else
932 stack_limit_rtx = gen_rtx_REG (Pmode, reg);
934 break;
936 case OPT_fstack_limit_symbol_:
937 stack_limit_rtx = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (arg));
938 break;
940 case OPT_ftree_vectorizer_verbose_:
941 vect_set_verbosity_level (arg);
942 break;
944 case OPT_ftls_model_:
945 if (!strcmp (arg, "global-dynamic"))
946 flag_tls_default = TLS_MODEL_GLOBAL_DYNAMIC;
947 else if (!strcmp (arg, "local-dynamic"))
948 flag_tls_default = TLS_MODEL_LOCAL_DYNAMIC;
949 else if (!strcmp (arg, "initial-exec"))
950 flag_tls_default = TLS_MODEL_INITIAL_EXEC;
951 else if (!strcmp (arg, "local-exec"))
952 flag_tls_default = TLS_MODEL_LOCAL_EXEC;
953 else
954 warning (0, "unknown tls-model \"%s\"", arg);
955 break;
957 case OPT_ftracer:
958 flag_tracer_set = true;
959 break;
961 case OPT_funroll_loops:
962 flag_unroll_loops_set = true;
963 break;
965 case OPT_g:
966 set_debug_level (NO_DEBUG, DEFAULT_GDB_EXTENSIONS, arg);
967 break;
969 case OPT_gcoff:
970 set_debug_level (SDB_DEBUG, false, arg);
971 break;
973 case OPT_gdwarf_2:
974 set_debug_level (DWARF2_DEBUG, false, arg);
975 break;
977 case OPT_ggdb:
978 set_debug_level (NO_DEBUG, 2, arg);
979 break;
981 case OPT_gstabs:
982 case OPT_gstabs_:
983 set_debug_level (DBX_DEBUG, code == OPT_gstabs_, arg);
984 break;
986 case OPT_gvms:
987 set_debug_level (VMS_DEBUG, false, arg);
988 break;
990 case OPT_gxcoff:
991 case OPT_gxcoff_:
992 set_debug_level (XCOFF_DEBUG, code == OPT_gxcoff_, arg);
993 break;
995 case OPT_o:
996 asm_file_name = arg;
997 break;
999 case OPT_pedantic_errors:
1000 flag_pedantic_errors = pedantic = 1;
1001 break;
1003 case OPT_fforce_mem:
1004 warning (0, "-f[no-]force-mem is nop and option will be removed in 4.3");
1005 break;
1007 case OPT_floop_optimize:
1008 case OPT_frerun_loop_opt:
1009 case OPT_fstrength_reduce:
1010 /* These are no-ops, preserved for backward compatibility. */
1011 break;
1013 default:
1014 /* If the flag was handled in a standard way, assume the lack of
1015 processing here is intentional. */
1016 gcc_assert (cl_options[scode].flag_var);
1017 break;
1020 return 1;
1023 /* Handle --param NAME=VALUE. */
1024 static void
1025 handle_param (const char *carg)
1027 char *equal, *arg;
1028 int value;
1030 arg = xstrdup (carg);
1031 equal = strchr (arg, '=');
1032 if (!equal)
1033 error ("%s: --param arguments should be of the form NAME=VALUE", arg);
1034 else
1036 value = integral_argument (equal + 1);
1037 if (value == -1)
1038 error ("invalid --param value %qs", equal + 1);
1039 else
1041 *equal = '\0';
1042 set_param_value (arg, value);
1046 free (arg);
1049 /* Handle -W and -Wextra. */
1050 static void
1051 set_Wextra (int setting)
1053 extra_warnings = setting;
1054 warn_unused_value = setting;
1055 warn_unused_parameter = (setting && maybe_warn_unused_parameter);
1057 /* We save the value of warn_uninitialized, since if they put
1058 -Wuninitialized on the command line, we need to generate a
1059 warning about not using it without also specifying -O. */
1060 if (setting == 0)
1061 warn_uninitialized = 0;
1062 else if (warn_uninitialized != 1)
1063 warn_uninitialized = 2;
1066 /* Initialize unused warning flags. */
1067 void
1068 set_Wunused (int setting)
1070 warn_unused_function = setting;
1071 warn_unused_label = setting;
1072 /* Unused function parameter warnings are reported when either
1073 ``-Wextra -Wunused'' or ``-Wunused-parameter'' is specified.
1074 Thus, if -Wextra has already been seen, set warn_unused_parameter;
1075 otherwise set maybe_warn_extra_parameter, which will be picked up
1076 by set_Wextra. */
1077 maybe_warn_unused_parameter = setting;
1078 warn_unused_parameter = (setting && extra_warnings);
1079 warn_unused_variable = setting;
1080 warn_unused_value = setting;
1083 /* The following routines are useful in setting all the flags that
1084 -ffast-math and -fno-fast-math imply. */
1085 void
1086 set_fast_math_flags (int set)
1088 flag_trapping_math = !set;
1089 flag_unsafe_math_optimizations = set;
1090 flag_finite_math_only = set;
1091 flag_errno_math = !set;
1092 if (set)
1094 flag_signaling_nans = 0;
1095 flag_rounding_math = 0;
1096 flag_cx_limited_range = 1;
1100 /* Return true iff flags are set as if -ffast-math. */
1101 bool
1102 fast_math_flags_set_p (void)
1104 return (!flag_trapping_math
1105 && flag_unsafe_math_optimizations
1106 && flag_finite_math_only
1107 && !flag_errno_math);
1110 /* Handle a debug output -g switch. EXTENDED is true or false to support
1111 extended output (2 is special and means "-ggdb" was given). */
1112 static void
1113 set_debug_level (enum debug_info_type type, int extended, const char *arg)
1115 static bool type_explicit;
1117 use_gnu_debug_info_extensions = extended;
1119 if (type == NO_DEBUG)
1121 if (write_symbols == NO_DEBUG)
1123 write_symbols = PREFERRED_DEBUGGING_TYPE;
1125 if (extended == 2)
1127 #ifdef DWARF2_DEBUGGING_INFO
1128 write_symbols = DWARF2_DEBUG;
1129 #elif defined DBX_DEBUGGING_INFO
1130 write_symbols = DBX_DEBUG;
1131 #endif
1134 if (write_symbols == NO_DEBUG)
1135 warning (0, "target system does not support debug output");
1138 else
1140 /* Does it conflict with an already selected type? */
1141 if (type_explicit && write_symbols != NO_DEBUG && type != write_symbols)
1142 error ("debug format \"%s\" conflicts with prior selection",
1143 debug_type_names[type]);
1144 write_symbols = type;
1145 type_explicit = true;
1148 /* A debug flag without a level defaults to level 2. */
1149 if (*arg == '\0')
1151 if (!debug_info_level)
1152 debug_info_level = 2;
1154 else
1156 debug_info_level = integral_argument (arg);
1157 if (debug_info_level == (unsigned int) -1)
1158 error ("unrecognised debug output level \"%s\"", arg);
1159 else if (debug_info_level > 3)
1160 error ("debug output level %s is too high", arg);
1164 /* Display help for target options. */
1165 static void
1166 print_target_help (void)
1168 unsigned int i;
1169 static bool displayed = false;
1171 /* Avoid double printing for --help --target-help. */
1172 if (displayed)
1173 return;
1175 displayed = true;
1176 for (i = 0; i < cl_options_count; i++)
1177 if ((cl_options[i].flags & (CL_TARGET | CL_UNDOCUMENTED)) == CL_TARGET)
1179 printf (_("\nTarget specific options:\n"));
1180 print_filtered_help (CL_TARGET);
1181 break;
1185 /* Output --help text. */
1186 static void
1187 print_help (void)
1189 size_t i;
1190 const char *p;
1192 GET_ENVIRONMENT (p, "COLUMNS");
1193 if (p)
1195 int value = atoi (p);
1196 if (value > 0)
1197 columns = value;
1200 puts (_("The following options are language-independent:\n"));
1202 print_filtered_help (CL_COMMON);
1203 print_param_help ();
1205 for (i = 0; lang_names[i]; i++)
1207 printf (_("The %s front end recognizes the following options:\n\n"),
1208 lang_names[i]);
1209 print_filtered_help (1U << i);
1211 print_target_help ();
1214 /* Print the help for --param. */
1215 static void
1216 print_param_help (void)
1218 size_t i;
1220 puts (_("The --param option recognizes the following as parameters:\n"));
1222 for (i = 0; i < LAST_PARAM; i++)
1224 const char *help = compiler_params[i].help;
1225 const char *param = compiler_params[i].option;
1227 if (help == NULL || *help == '\0')
1228 help = undocumented_msg;
1230 /* Get the translation. */
1231 help = _(help);
1233 wrap_help (help, param, strlen (param));
1236 putchar ('\n');
1239 /* Print help for a specific front-end, etc. */
1240 static void
1241 print_filtered_help (unsigned int flag)
1243 unsigned int i, len, filter, indent = 0;
1244 bool duplicates = false;
1245 const char *help, *opt, *tab;
1246 static char *printed;
1248 if (flag == CL_COMMON || flag == CL_TARGET)
1250 filter = flag;
1251 if (!printed)
1252 printed = xmalloc (cl_options_count);
1253 memset (printed, 0, cl_options_count);
1255 else
1257 /* Don't print COMMON options twice. */
1258 filter = flag | CL_COMMON;
1260 for (i = 0; i < cl_options_count; i++)
1262 if ((cl_options[i].flags & filter) != flag)
1263 continue;
1265 /* Skip help for internal switches. */
1266 if (cl_options[i].flags & CL_UNDOCUMENTED)
1267 continue;
1269 /* Skip switches that have already been printed, mark them to be
1270 listed later. */
1271 if (printed[i])
1273 duplicates = true;
1274 indent = print_switch (cl_options[i].opt_text, indent);
1278 if (duplicates)
1280 putchar ('\n');
1281 putchar ('\n');
1285 for (i = 0; i < cl_options_count; i++)
1287 if ((cl_options[i].flags & filter) != flag)
1288 continue;
1290 /* Skip help for internal switches. */
1291 if (cl_options[i].flags & CL_UNDOCUMENTED)
1292 continue;
1294 /* Skip switches that have already been printed. */
1295 if (printed[i])
1296 continue;
1298 printed[i] = true;
1300 help = cl_options[i].help;
1301 if (!help)
1302 help = undocumented_msg;
1304 /* Get the translation. */
1305 help = _(help);
1307 tab = strchr (help, '\t');
1308 if (tab)
1310 len = tab - help;
1311 opt = help;
1312 help = tab + 1;
1314 else
1316 opt = cl_options[i].opt_text;
1317 len = strlen (opt);
1320 wrap_help (help, opt, len);
1323 putchar ('\n');
1326 /* Output ITEM, of length ITEM_WIDTH, in the left column, followed by
1327 word-wrapped HELP in a second column. */
1328 static unsigned int
1329 print_switch (const char *text, unsigned int indent)
1331 unsigned int len = strlen (text) + 1; /* trailing comma */
1333 if (indent)
1335 putchar (',');
1336 if (indent + len > columns)
1338 putchar ('\n');
1339 putchar (' ');
1340 indent = 1;
1343 else
1344 putchar (' ');
1346 putchar (' ');
1347 fputs (text, stdout);
1349 return indent + len + 1;
1352 /* Output ITEM, of length ITEM_WIDTH, in the left column, followed by
1353 word-wrapped HELP in a second column. */
1354 static void
1355 wrap_help (const char *help, const char *item, unsigned int item_width)
1357 unsigned int col_width = 27;
1358 unsigned int remaining, room, len;
1360 remaining = strlen (help);
1364 room = columns - 3 - MAX (col_width, item_width);
1365 if (room > columns)
1366 room = 0;
1367 len = remaining;
1369 if (room < len)
1371 unsigned int i;
1373 for (i = 0; help[i]; i++)
1375 if (i >= room && len != remaining)
1376 break;
1377 if (help[i] == ' ')
1378 len = i;
1379 else if ((help[i] == '-' || help[i] == '/')
1380 && help[i + 1] != ' '
1381 && i > 0 && ISALPHA (help[i - 1]))
1382 len = i + 1;
1386 printf( " %-*.*s %.*s\n", col_width, item_width, item, len, help);
1387 item_width = 0;
1388 while (help[len] == ' ')
1389 len++;
1390 help += len;
1391 remaining -= len;
1393 while (remaining);
1396 /* Return 1 if OPTION is enabled, 0 if it is disabled, or -1 if it isn't
1397 a simple on-off switch. */
1400 option_enabled (int opt_idx)
1402 const struct cl_option *option = &(cl_options[opt_idx]);
1403 if (option->flag_var)
1404 switch (option->var_type)
1406 case CLVC_BOOLEAN:
1407 return *(int *) option->flag_var != 0;
1409 case CLVC_EQUAL:
1410 return *(int *) option->flag_var == option->var_value;
1412 case CLVC_BIT_CLEAR:
1413 return (*(int *) option->flag_var & option->var_value) == 0;
1415 case CLVC_BIT_SET:
1416 return (*(int *) option->flag_var & option->var_value) != 0;
1418 case CLVC_STRING:
1419 break;
1421 return -1;
1424 /* Fill STATE with the current state of option OPTION. Return true if
1425 there is some state to store. */
1427 bool
1428 get_option_state (int option, struct cl_option_state *state)
1430 if (cl_options[option].flag_var == 0)
1431 return false;
1433 switch (cl_options[option].var_type)
1435 case CLVC_BOOLEAN:
1436 case CLVC_EQUAL:
1437 state->data = cl_options[option].flag_var;
1438 state->size = sizeof (int);
1439 break;
1441 case CLVC_BIT_CLEAR:
1442 case CLVC_BIT_SET:
1443 state->ch = option_enabled (option);
1444 state->data = &state->ch;
1445 state->size = 1;
1446 break;
1448 case CLVC_STRING:
1449 state->data = *(const char **) cl_options[option].flag_var;
1450 if (state->data == 0)
1451 state->data = "";
1452 state->size = strlen (state->data) + 1;
1453 break;
1455 return true;