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 2, or (at your option) any later
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
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING. If not, write to the Free
20 Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
28 #include "coretypes.h"
34 #include "langhooks.h"
40 #include "diagnostic.h"
41 #include "tm_p.h" /* For OPTIMIZATION_OPTIONS. */
42 #include "insn-attr.h" /* For INSN_SCHEDULING. */
44 #include "tree-pass.h"
46 /* Value of the -G xx switch, and whether it was passed or not. */
47 unsigned HOST_WIDE_INT g_switch_value;
50 /* True if we should exit after parsing options. */
51 bool exit_after_options;
53 /* Print various extra warnings. -W/-Wextra. */
56 /* True to warn about any objects definitions whose size is larger
57 than N bytes. Also want about function definitions whose returned
58 values are larger than N bytes, where N is `larger_than_size'. */
59 bool warn_larger_than;
60 HOST_WIDE_INT larger_than_size;
62 /* Nonzero means warn about constructs which might not be
63 strict-aliasing safe. */
64 int warn_strict_aliasing;
66 /* Nonzero means warn about optimizations which rely on undefined
68 int warn_strict_overflow;
70 /* Hack for cooperation between set_Wunused and set_Wextra. */
71 static bool maybe_warn_unused_parameter;
73 /* Type(s) of debugging information we are producing (if any). See
74 flags.h for the definitions of the different possible types of
75 debugging information. */
76 enum debug_info_type write_symbols = NO_DEBUG;
78 /* Level of debugging information we are producing. See flags.h for
79 the definitions of the different possible levels. */
80 enum debug_info_level debug_info_level = DINFO_LEVEL_NONE;
82 /* A major contribution to object and executable size is debug
83 information size. A major contribution to debug information size
84 is struct descriptions replicated in several object files. The
85 following flags attempt to reduce this information. The basic
86 idea is to not emit struct debugging information in the current
87 compilation unit when that information will be generated by
88 another compilation unit.
90 Debug information for a struct defined in the current source
91 file should be generated in the object file. Likewise the
92 debug information for a struct defined in a header should be
93 generated in the object file of the corresponding source file.
94 Both of these case are handled when the base name of the file of
95 the struct definition matches the base name of the source file
96 of thet current compilation unit. This matching emits minimal
97 struct debugging information.
99 The base file name matching rule above will fail to emit debug
100 information for structs defined in system headers. So a second
101 category of files includes system headers in addition to files
104 The remaining types of files are library headers and application
105 headers. We cannot currently distinguish these two types. */
107 enum debug_struct_file
109 DINFO_STRUCT_FILE_NONE, /* Debug no structs. */
110 DINFO_STRUCT_FILE_BASE, /* Debug structs defined in files with the
111 same base name as the compilation unit. */
112 DINFO_STRUCT_FILE_SYS, /* Also debug structs defined in system
114 DINFO_STRUCT_FILE_ANY /* Debug structs defined in all files. */
117 /* Generic structs (e.g. templates not explicitly specialized)
118 may not have a compilation unit associated with them, and so
119 may need to be treated differently from ordinary structs.
121 Structs only handled by reference (indirectly), will also usually
122 not need as much debugging information. */
124 static enum debug_struct_file debug_struct_ordinary[DINFO_USAGE_NUM_ENUMS]
125 = { DINFO_STRUCT_FILE_ANY, DINFO_STRUCT_FILE_ANY, DINFO_STRUCT_FILE_ANY };
126 static enum debug_struct_file debug_struct_generic[DINFO_USAGE_NUM_ENUMS]
127 = { DINFO_STRUCT_FILE_ANY, DINFO_STRUCT_FILE_ANY, DINFO_STRUCT_FILE_ANY };
129 /* Parse the -femit-struct-debug-detailed option value
130 and set the flag variables. */
132 #define MATCH( prefix, string ) \
133 ((strncmp (prefix, string, sizeof prefix - 1) == 0) \
134 ? ((string += sizeof prefix - 1), 1) : 0)
137 set_struct_debug_option (const char *spec)
139 /* various labels for comparison */
140 static char dfn_lbl[] = "dfn:", dir_lbl[] = "dir:", ind_lbl[] = "ind:";
141 static char ord_lbl[] = "ord:", gen_lbl[] = "gen:";
142 static char none_lbl[] = "none", any_lbl[] = "any";
143 static char base_lbl[] = "base", sys_lbl[] = "sys";
145 enum debug_struct_file files = DINFO_STRUCT_FILE_ANY;
146 /* Default is to apply to as much as possible. */
147 enum debug_info_usage usage = DINFO_USAGE_NUM_ENUMS;
148 int ord = 1, gen = 1;
151 if (MATCH (dfn_lbl, spec))
152 usage = DINFO_USAGE_DFN;
153 else if (MATCH (dir_lbl, spec))
154 usage = DINFO_USAGE_DIR_USE;
155 else if (MATCH (ind_lbl, spec))
156 usage = DINFO_USAGE_IND_USE;
158 /* Generics or not? */
159 if (MATCH (ord_lbl, spec))
161 else if (MATCH (gen_lbl, spec))
164 /* What allowable environment? */
165 if (MATCH (none_lbl, spec))
166 files = DINFO_STRUCT_FILE_NONE;
167 else if (MATCH (any_lbl, spec))
168 files = DINFO_STRUCT_FILE_ANY;
169 else if (MATCH (sys_lbl, spec))
170 files = DINFO_STRUCT_FILE_SYS;
171 else if (MATCH (base_lbl, spec))
172 files = DINFO_STRUCT_FILE_BASE;
174 error ("argument %qs to %<-femit-struct-debug-detailed%> not recognized",
177 /* Effect the specification. */
178 if (usage == DINFO_USAGE_NUM_ENUMS)
182 debug_struct_ordinary[DINFO_USAGE_DFN] = files;
183 debug_struct_ordinary[DINFO_USAGE_DIR_USE] = files;
184 debug_struct_ordinary[DINFO_USAGE_IND_USE] = files;
188 debug_struct_generic[DINFO_USAGE_DFN] = files;
189 debug_struct_generic[DINFO_USAGE_DIR_USE] = files;
190 debug_struct_generic[DINFO_USAGE_IND_USE] = files;
196 debug_struct_ordinary[usage] = files;
198 debug_struct_generic[usage] = files;
202 set_struct_debug_option (spec+1);
205 /* No more -femit-struct-debug-detailed specifications.
208 error ("argument %qs to %<-femit-struct-debug-detailed%> unknown",
210 if (debug_struct_ordinary[DINFO_USAGE_DIR_USE]
211 < debug_struct_ordinary[DINFO_USAGE_IND_USE]
212 || debug_struct_generic[DINFO_USAGE_DIR_USE]
213 < debug_struct_generic[DINFO_USAGE_IND_USE])
214 error ("%<-femit-struct-debug-detailed=dir:...%> must allow at least"
215 " as much as %<-femit-struct-debug-detailed=ind:...%>");
219 /* Find the base name of a path, stripping off both directories and
220 a single final extension. */
222 base_of_path (const char *path, const char **base_out)
224 const char *base = path;
226 const char *p = path;
230 if (IS_DIR_SEPARATOR(c))
245 /* Match the base name of a file to the base name of a compilation unit. */
247 static const char *main_input_basename;
248 static int main_input_baselength;
251 matches_main_base (const char *path)
253 /* Cache the last query. */
254 static const char *last_path = NULL;
255 static int last_match = 0;
256 if (path != last_path)
259 int length = base_of_path (path, &base);
261 last_match = (length == main_input_baselength
262 && memcmp (base, main_input_basename, length) == 0);
267 #ifdef DEBUG_DEBUG_STRUCT
270 dump_struct_debug (tree type, enum debug_info_usage usage,
271 enum debug_struct_file criterion, int generic,
272 int matches, int result)
274 /* Find the type name. */
275 tree type_decl = TYPE_STUB_DECL (type);
277 const char *name = 0;
278 if (TREE_CODE (t) == TYPE_DECL)
281 name = IDENTIFIER_POINTER (t);
283 fprintf (stderr, " struct %d %s %s %s %s %d %p %s\n",
285 DECL_IN_SYSTEM_HEADER (type_decl) ? "sys" : "usr",
286 matches ? "bas" : "hdr",
287 generic ? "gen" : "ord",
288 usage == DINFO_USAGE_DFN ? ";" :
289 usage == DINFO_USAGE_DIR_USE ? "." : "*",
291 (void*) type_decl, name);
294 #define DUMP_GSTRUCT(type, usage, criterion, generic, matches, result) \
295 dump_struct_debug (type, usage, criterion, generic, matches, result)
299 #define DUMP_GSTRUCT(type, usage, criterion, generic, matches, result) \
306 should_emit_struct_debug (tree type, enum debug_info_usage usage)
308 enum debug_struct_file criterion;
310 bool generic = lang_hooks.types.generic_p (type);
313 criterion = debug_struct_generic[usage];
315 criterion = debug_struct_ordinary[usage];
317 if (criterion == DINFO_STRUCT_FILE_NONE)
318 return DUMP_GSTRUCT (type, usage, criterion, generic, false, false);
319 if (criterion == DINFO_STRUCT_FILE_ANY)
320 return DUMP_GSTRUCT (type, usage, criterion, generic, false, true);
322 type_decl = TYPE_STUB_DECL (type);
324 if (criterion == DINFO_STRUCT_FILE_SYS && DECL_IN_SYSTEM_HEADER (type_decl))
325 return DUMP_GSTRUCT (type, usage, criterion, generic, false, true);
327 if (matches_main_base (DECL_SOURCE_FILE (type_decl)))
328 return DUMP_GSTRUCT (type, usage, criterion, generic, true, true);
329 return DUMP_GSTRUCT (type, usage, criterion, generic, false, false);
332 /* Nonzero means use GNU-only extensions in the generated symbolic
333 debugging information. Currently, this only has an effect when
334 write_symbols is set to DBX_DEBUG, XCOFF_DEBUG, or DWARF_DEBUG. */
335 bool use_gnu_debug_info_extensions;
337 /* The default visibility for all symbols (unless overridden) */
338 enum symbol_visibility default_visibility = VISIBILITY_DEFAULT;
340 /* Disable unit-at-a-time for frontends that might be still broken in this
343 bool no_unit_at_a_time_default;
345 /* Global visibility options. */
346 struct visibility_flags visibility_options;
348 /* Columns of --help display. */
349 static unsigned int columns = 80;
351 /* What to print when a switch has no documentation. */
352 static const char undocumented_msg[] = N_("This switch lacks documentation");
354 /* Used for bookkeeping on whether user set these flags so
355 -fprofile-use/-fprofile-generate does not use them. */
356 static bool profile_arc_flag_set, flag_profile_values_set;
357 static bool flag_unroll_loops_set, flag_tracer_set;
358 static bool flag_value_profile_transformations_set;
359 static bool flag_peel_loops_set, flag_branch_probabilities_set;
361 /* Input file names. */
362 const char **in_fnames;
363 unsigned num_in_fnames;
365 static int common_handle_option (size_t scode, const char *arg, int value,
366 unsigned int lang_mask);
367 static void handle_param (const char *);
368 static void set_Wextra (int);
369 static unsigned int handle_option (const char **argv, unsigned int lang_mask);
370 static char *write_langs (unsigned int lang_mask);
371 static void complain_wrong_lang (const char *, const struct cl_option *,
372 unsigned int lang_mask);
373 static void handle_options (unsigned int, const char **, unsigned int);
374 static void wrap_help (const char *help, const char *item, unsigned int);
375 static void print_target_help (void);
376 static void print_help (void);
377 static void print_param_help (void);
378 static void print_filtered_help (unsigned int);
379 static unsigned int print_switch (const char *text, unsigned int indent);
380 static void set_debug_level (enum debug_info_type type, int extended,
383 /* If ARG is a non-negative integer made up solely of digits, return its
384 value, otherwise return -1. */
386 integral_argument (const char *arg)
390 while (*p && ISDIGIT (*p))
399 /* Return a malloced slash-separated list of languages in MASK. */
401 write_langs (unsigned int mask)
403 unsigned int n = 0, len = 0;
404 const char *lang_name;
407 for (n = 0; (lang_name = lang_names[n]) != 0; n++)
408 if (mask & (1U << n))
409 len += strlen (lang_name) + 1;
411 result = XNEWVEC (char, len);
413 for (n = 0; (lang_name = lang_names[n]) != 0; n++)
414 if (mask & (1U << n))
418 strcpy (result + len, lang_name);
419 len += strlen (lang_name);
427 /* Complain that switch OPT_INDEX does not apply to this front end. */
429 complain_wrong_lang (const char *text, const struct cl_option *option,
430 unsigned int lang_mask)
432 char *ok_langs, *bad_lang;
434 ok_langs = write_langs (option->flags);
435 bad_lang = write_langs (lang_mask);
437 /* Eventually this should become a hard error IMO. */
438 warning (0, "command line option \"%s\" is valid for %s but not for %s",
439 text, ok_langs, bad_lang);
445 /* Handle the switch beginning at ARGV for the language indicated by
446 LANG_MASK. Returns the number of switches consumed. */
448 handle_option (const char **argv, unsigned int lang_mask)
451 const char *opt, *arg = 0;
454 unsigned int result = 0;
455 const struct cl_option *option;
459 opt_index = find_opt (opt + 1, lang_mask | CL_COMMON | CL_TARGET);
460 if (opt_index == cl_options_count
461 && (opt[1] == 'W' || opt[1] == 'f' || opt[1] == 'm')
462 && opt[2] == 'n' && opt[3] == 'o' && opt[4] == '-')
464 /* Drop the "no-" from negative switches. */
465 size_t len = strlen (opt) - 3;
467 dup = XNEWVEC (char, len + 1);
470 memcpy (dup + 2, opt + 5, len - 2 + 1);
473 opt_index = find_opt (opt + 1, lang_mask | CL_COMMON | CL_TARGET);
476 if (opt_index == cl_options_count)
479 option = &cl_options[opt_index];
481 /* Reject negative form of switches that don't take negatives as
483 if (!value && (option->flags & CL_REJECT_NEGATIVE))
486 /* We've recognized this switch. */
489 /* Check to see if the option is disabled for this configuration. */
490 if (option->flags & CL_DISABLED)
492 error ("command line option %qs"
493 " is not supported by this configuration", opt);
497 /* Sort out any argument the switch takes. */
498 if (option->flags & CL_JOINED)
500 /* Have arg point to the original switch. This is because
501 some code, such as disable_builtin_function, expects its
502 argument to be persistent until the program exits. */
503 arg = argv[0] + cl_options[opt_index].opt_len + 1;
505 arg += strlen ("no-");
507 if (*arg == '\0' && !(option->flags & CL_MISSING_OK))
509 if (option->flags & CL_SEPARATE)
515 /* Missing argument. */
519 else if (option->flags & CL_SEPARATE)
525 /* Now we've swallowed any potential argument, complain if this
526 is a switch for a different front end. */
527 if (!(option->flags & (lang_mask | CL_COMMON | CL_TARGET)))
529 complain_wrong_lang (argv[0], option, lang_mask);
533 if (arg == NULL && (option->flags & (CL_JOINED | CL_SEPARATE)))
535 if (!lang_hooks.missing_argument (opt, opt_index))
536 error ("missing argument to \"%s\"", opt);
540 /* If the switch takes an integer, convert it. */
541 if (arg && (option->flags & CL_UINTEGER))
543 value = integral_argument (arg);
546 error ("argument to \"%s\" should be a non-negative integer",
552 if (option->flag_var)
553 switch (option->var_type)
556 *(int *) option->flag_var = value;
560 *(int *) option->flag_var = (value
562 : !option->var_value);
567 if ((value != 0) == (option->var_type == CLVC_BIT_SET))
568 *(int *) option->flag_var |= option->var_value;
570 *(int *) option->flag_var &= ~option->var_value;
571 if (option->flag_var == &target_flags)
572 target_flags_explicit |= option->var_value;
576 *(const char **) option->flag_var = arg;
580 if (option->flags & lang_mask)
581 if (lang_hooks.handle_option (opt_index, arg, value) == 0)
584 if (result && (option->flags & CL_COMMON))
585 if (common_handle_option (opt_index, arg, value, lang_mask) == 0)
588 if (result && (option->flags & CL_TARGET))
589 if (!targetm.handle_option (opt_index, arg, value))
598 /* Handle FILENAME from the command line. */
600 add_input_filename (const char *filename)
603 in_fnames = xrealloc (in_fnames, num_in_fnames * sizeof (in_fnames[0]));
604 in_fnames[num_in_fnames - 1] = filename;
607 /* Decode and handle the vector of command line options. LANG_MASK
608 contains has a single bit set representing the current
611 handle_options (unsigned int argc, const char **argv, unsigned int lang_mask)
615 for (i = 1; i < argc; i += n)
617 const char *opt = argv[i];
619 /* Interpret "-" or a non-switch as a file name. */
620 if (opt[0] != '-' || opt[1] == '\0')
622 if (main_input_filename == NULL)
624 main_input_filename = opt;
625 main_input_baselength
626 = base_of_path (main_input_filename, &main_input_basename);
628 add_input_filename (opt);
633 n = handle_option (argv + i, lang_mask);
638 error ("unrecognized command line option \"%s\"", opt);
643 /* Parse command line options and set default flag values. Do minimal
644 options processing. */
646 decode_options (unsigned int argc, const char **argv)
648 unsigned int i, lang_mask;
650 /* Perform language-specific options initialization. */
651 lang_mask = lang_hooks.init_options (argc, argv);
653 lang_hooks.initialize_diagnostics (global_dc);
655 /* Scan to see what optimization level has been specified. That will
656 determine the default value of many flags. */
657 for (i = 1; i < argc; i++)
659 if (!strcmp (argv[i], "-O"))
664 else if (argv[i][0] == '-' && argv[i][1] == 'O')
666 /* Handle -Os, -O2, -O3, -O69, ... */
667 const char *p = &argv[i][2];
669 if ((p[0] == 's') && (p[1] == 0))
673 /* Optimizing for size forces optimize to be 2. */
678 const int optimize_val = read_integral_parameter (p, p - 2, -1);
679 if (optimize_val != -1)
681 optimize = optimize_val;
690 flag_merge_constants = 0;
697 flag_delayed_branch = 1;
699 #ifdef CAN_DEBUG_WITHOUT_FP
700 flag_omit_frame_pointer = 1;
702 flag_guess_branch_prob = 1;
703 flag_cprop_registers = 1;
704 flag_if_conversion = 1;
705 flag_if_conversion2 = 1;
706 flag_ipa_pure_const = 1;
707 flag_ipa_reference = 1;
713 flag_tree_live_range_split = 1;
715 flag_tree_copyrename = 1;
717 flag_tree_copy_prop = 1;
719 flag_tree_salias = 1;
720 if (!no_unit_at_a_time_default)
721 flag_unit_at_a_time = 1;
725 /* Loop header copying usually increases size of the code. This used
726 not to be true, since quite often it is possible to verify that
727 the condition is satisfied in the first iteration and therefore
728 to eliminate it. Jump threading handles these cases now. */
735 flag_thread_jumps = 1;
736 flag_crossjumping = 1;
737 flag_optimize_sibling_calls = 1;
738 flag_cse_follow_jumps = 1;
739 flag_cse_skip_blocks = 1;
741 flag_expensive_optimizations = 1;
742 flag_ipa_type_escape = 1;
743 flag_rerun_cse_after_loop = 1;
744 flag_caller_saves = 1;
746 #ifdef INSN_SCHEDULING
747 flag_schedule_insns = 1;
748 flag_schedule_insns_after_reload = 1;
751 flag_strict_aliasing = 1;
752 flag_strict_overflow = 1;
753 flag_delete_null_pointer_checks = 1;
754 flag_reorder_blocks = 1;
755 flag_reorder_functions = 1;
756 flag_tree_store_ccp = 1;
757 flag_tree_store_copy_prop = 1;
758 /* XXX: some issues with ports have been traced to -ftree-vrp.
759 So remove it from -O2 and above. Note that jdk1{5,6} are affected
760 and they build with w/-O3 - so we cannot just move it to -O3. */
761 /* flag_tree_vrp = 1; // See GCC tree-optimization/33099 */
765 /* PRE tends to generate bigger code. */
772 flag_inline_functions = 1;
773 flag_unswitch_loops = 1;
774 flag_gcse_after_reload = 1;
784 /* Don't reorder blocks when optimizing for size because extra
785 jump insns may be created; also barrier may create extra padding.
787 More correctly we should have a block reordering mode that tried
788 to minimize the combined size of all the jumps. This would more
789 or less automatically remove extra jumps, but would also try to
790 use more short jumps instead of long jumps. */
791 flag_reorder_blocks = 0;
792 flag_reorder_blocks_and_partition = 0;
797 /* Inlining of very small functions usually reduces total size. */
798 set_param_value ("max-inline-insns-single", 5);
799 set_param_value ("max-inline-insns-auto", 5);
800 flag_inline_functions = 1;
802 /* We want to crossjump as much as possible. */
803 set_param_value ("min-crossjump-insns", 1);
806 /* Initialize whether `char' is signed. */
807 flag_signed_char = DEFAULT_SIGNED_CHAR;
808 /* Set this to a special "uninitialized" value. The actual default is set
809 after target options have been processed. */
810 flag_short_enums = 2;
812 /* Initialize target_flags before OPTIMIZATION_OPTIONS so the latter can
814 target_flags = targetm.default_target_flags;
816 /* Some tagets have ABI-specified unwind tables. */
817 flag_unwind_tables = targetm.unwind_tables_default;
819 #ifdef OPTIMIZATION_OPTIONS
820 /* Allow default optimizations to be specified on a per-machine basis. */
821 OPTIMIZATION_OPTIONS (optimize, optimize_size);
824 handle_options (argc, argv, lang_mask);
828 if (flag_pic && !flag_pie)
831 if (flag_no_inline == 2)
834 flag_really_no_inline = flag_no_inline;
836 /* Set flag_no_inline before the post_options () hook. The C front
837 ends use it to determine tree inlining defaults. FIXME: such
838 code should be lang-independent when all front ends use tree
839 inlining, in which case it, and this condition, should be moved
840 to the top of process_options() instead. */
843 /* Inlining does not work if not optimizing,
844 so force it not to be done. */
848 /* The c_decode_option function and decode_option hook set
849 this to `2' if -Wall is used, so we can avoid giving out
850 lots of errors for people who don't realize what -Wall does. */
851 if (warn_uninitialized == 1)
852 warning (OPT_Wuninitialized,
853 "-Wuninitialized is not supported without -O");
856 if (flag_really_no_inline == 2)
857 flag_really_no_inline = flag_no_inline;
859 /* The optimization to partition hot and cold basic blocks into separate
860 sections of the .o and executable files does not work (currently)
861 with exception handling. This is because there is no support for
862 generating unwind info. If flag_exceptions is turned on we need to
863 turn off the partitioning optimization. */
865 if (flag_exceptions && flag_reorder_blocks_and_partition)
868 ("-freorder-blocks-and-partition does not work with exceptions");
869 flag_reorder_blocks_and_partition = 0;
870 flag_reorder_blocks = 1;
873 /* If user requested unwind info, then turn off the partitioning
876 if (flag_unwind_tables && ! targetm.unwind_tables_default
877 && flag_reorder_blocks_and_partition)
879 inform ("-freorder-blocks-and-partition does not support unwind info");
880 flag_reorder_blocks_and_partition = 0;
881 flag_reorder_blocks = 1;
884 /* If the target requested unwind info, then turn off the partitioning
885 optimization with a different message. Likewise, if the target does not
886 support named sections. */
888 if (flag_reorder_blocks_and_partition
889 && (!targetm.have_named_sections
890 || (flag_unwind_tables && targetm.unwind_tables_default)))
893 ("-freorder-blocks-and-partition does not work on this architecture");
894 flag_reorder_blocks_and_partition = 0;
895 flag_reorder_blocks = 1;
899 /* Handle target- and language-independent options. Return zero to
900 generate an "unknown option" message. Only options that need
901 extra handling need to be listed here; if you simply want
902 VALUE assigned to a variable, it happens automatically. */
905 common_handle_option (size_t scode, const char *arg, int value,
906 unsigned int lang_mask)
908 enum opt_code code = (enum opt_code) scode;
914 exit_after_options = true;
921 case OPT__target_help:
922 print_target_help ();
923 exit_after_options = true;
927 print_version (stderr, "");
928 exit_after_options = true;
932 g_switch_value = value;
938 /* Currently handled in a prescan. */
942 /* For backward compatibility, -W is the same as -Wextra. */
950 new_option = XNEWVEC (char, strlen (arg) + 2);
952 strcpy (new_option+1, arg);
953 option_index = find_opt (new_option, lang_mask);
954 if (option_index == N_OPTS)
956 error ("-Werror=%s: No option -%s", arg, new_option);
960 int kind = value ? DK_ERROR : DK_WARNING;
961 diagnostic_classify_diagnostic (global_dc, option_index, kind);
963 /* -Werror=foo implies -Wfoo. */
964 if (cl_options[option_index].var_type == CLVC_BOOLEAN
965 && cl_options[option_index].flag_var
967 *(int *) cl_options[option_index].flag_var = 1;
977 case OPT_Wlarger_than_:
978 larger_than_size = value;
979 warn_larger_than = value != -1;
982 case OPT_Wstrict_aliasing:
983 case OPT_Wstrict_aliasing_:
984 warn_strict_aliasing = value;
987 case OPT_Wstrict_overflow:
988 warn_strict_overflow = (value
989 ? (int) WARN_STRICT_OVERFLOW_CONDITIONAL
993 case OPT_Wstrict_overflow_:
994 warn_strict_overflow = value;
1003 aux_info_file_name = arg;
1004 flag_gen_aux_info = 1;
1008 aux_base_name = arg;
1011 case OPT_auxbase_strip:
1013 char *tmp = xstrdup (arg);
1014 strip_off_ending (tmp, strlen (tmp));
1016 aux_base_name = tmp;
1021 decode_d_option (arg);
1025 dump_base_name = arg;
1028 case OPT_falign_functions_:
1029 align_functions = value;
1032 case OPT_falign_jumps_:
1033 align_jumps = value;
1036 case OPT_falign_labels_:
1037 align_labels = value;
1040 case OPT_falign_loops_:
1041 align_loops = value;
1044 case OPT_fbranch_probabilities:
1045 flag_branch_probabilities_set = true;
1048 case OPT_fcall_used_:
1049 fix_register (arg, 0, 1);
1052 case OPT_fcall_saved_:
1053 fix_register (arg, 0, 0);
1056 case OPT_fdiagnostics_show_location_:
1057 if (!strcmp (arg, "once"))
1058 diagnostic_prefixing_rule (global_dc) = DIAGNOSTICS_SHOW_PREFIX_ONCE;
1059 else if (!strcmp (arg, "every-line"))
1060 diagnostic_prefixing_rule (global_dc)
1061 = DIAGNOSTICS_SHOW_PREFIX_EVERY_LINE;
1066 case OPT_fdiagnostics_show_option:
1067 global_dc->show_option_requested = true;
1071 if (!dump_switch_p (arg))
1075 case OPT_ffast_math:
1076 set_fast_math_flags (value);
1080 fix_register (arg, 1, 1);
1083 case OPT_finline_limit_:
1084 case OPT_finline_limit_eq:
1085 set_param_value ("max-inline-insns-single", value / 2);
1086 set_param_value ("max-inline-insns-auto", value / 2);
1089 case OPT_fmessage_length_:
1090 pp_set_line_maximum_length (global_dc->printer, value);
1093 case OPT_fpack_struct_:
1094 if (value <= 0 || (value & (value - 1)) || value > 16)
1095 error("structure alignment must be a small power of two, not %d", value);
1098 initial_max_fld_align = value;
1099 maximum_field_alignment = value * BITS_PER_UNIT;
1103 case OPT_fpeel_loops:
1104 flag_peel_loops_set = true;
1107 case OPT_fprofile_arcs:
1108 profile_arc_flag_set = true;
1111 case OPT_fprofile_use:
1112 if (!flag_branch_probabilities_set)
1113 flag_branch_probabilities = value;
1114 if (!flag_profile_values_set)
1115 flag_profile_values = value;
1116 if (!flag_unroll_loops_set)
1117 flag_unroll_loops = value;
1118 if (!flag_peel_loops_set)
1119 flag_peel_loops = value;
1120 if (!flag_tracer_set)
1121 flag_tracer = value;
1122 if (!flag_value_profile_transformations_set)
1123 flag_value_profile_transformations = value;
1126 case OPT_fprofile_generate:
1127 if (!profile_arc_flag_set)
1128 profile_arc_flag = value;
1129 if (!flag_profile_values_set)
1130 flag_profile_values = value;
1131 if (!flag_value_profile_transformations_set)
1132 flag_value_profile_transformations = value;
1135 case OPT_fprofile_values:
1136 flag_profile_values_set = true;
1139 case OPT_fvisibility_:
1141 if (!strcmp(arg, "default"))
1142 default_visibility = VISIBILITY_DEFAULT;
1143 else if (!strcmp(arg, "internal"))
1144 default_visibility = VISIBILITY_INTERNAL;
1145 else if (!strcmp(arg, "hidden"))
1146 default_visibility = VISIBILITY_HIDDEN;
1147 else if (!strcmp(arg, "protected"))
1148 default_visibility = VISIBILITY_PROTECTED;
1150 error ("unrecognized visibility value \"%s\"", arg);
1155 flag_value_profile_transformations_set = true;
1158 case OPT_frandom_seed:
1159 /* The real switch is -fno-random-seed. */
1162 flag_random_seed = NULL;
1165 case OPT_frandom_seed_:
1166 flag_random_seed = arg;
1169 case OPT_fsched_verbose_:
1170 #ifdef INSN_SCHEDULING
1171 fix_sched_param ("verbose", arg);
1177 case OPT_fsched_stalled_insns_:
1178 flag_sched_stalled_insns = value;
1179 if (flag_sched_stalled_insns == 0)
1180 flag_sched_stalled_insns = -1;
1183 case OPT_fsched_stalled_insns_dep_:
1184 flag_sched_stalled_insns_dep = value;
1187 case OPT_fstack_limit:
1188 /* The real switch is -fno-stack-limit. */
1191 stack_limit_rtx = NULL_RTX;
1194 case OPT_fstack_limit_register_:
1196 int reg = decode_reg_name (arg);
1198 error ("unrecognized register name \"%s\"", arg);
1200 stack_limit_rtx = gen_rtx_REG (Pmode, reg);
1204 case OPT_fstack_limit_symbol_:
1205 stack_limit_rtx = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (arg));
1208 case OPT_ftree_vectorizer_verbose_:
1209 vect_set_verbosity_level (arg);
1212 case OPT_ftls_model_:
1213 if (!strcmp (arg, "global-dynamic"))
1214 flag_tls_default = TLS_MODEL_GLOBAL_DYNAMIC;
1215 else if (!strcmp (arg, "local-dynamic"))
1216 flag_tls_default = TLS_MODEL_LOCAL_DYNAMIC;
1217 else if (!strcmp (arg, "initial-exec"))
1218 flag_tls_default = TLS_MODEL_INITIAL_EXEC;
1219 else if (!strcmp (arg, "local-exec"))
1220 flag_tls_default = TLS_MODEL_LOCAL_EXEC;
1222 warning (0, "unknown tls-model \"%s\"", arg);
1226 flag_tracer_set = true;
1229 case OPT_funroll_loops:
1230 flag_unroll_loops_set = true;
1234 set_debug_level (NO_DEBUG, DEFAULT_GDB_EXTENSIONS, arg);
1238 set_debug_level (SDB_DEBUG, false, arg);
1242 set_debug_level (DWARF2_DEBUG, false, arg);
1246 set_debug_level (NO_DEBUG, 2, arg);
1251 set_debug_level (DBX_DEBUG, code == OPT_gstabs_, arg);
1255 set_debug_level (VMS_DEBUG, false, arg);
1260 set_debug_level (XCOFF_DEBUG, code == OPT_gxcoff_, arg);
1264 asm_file_name = arg;
1267 case OPT_pedantic_errors:
1268 flag_pedantic_errors = pedantic = 1;
1271 case OPT_fforce_mem:
1272 warning (0, "-f[no-]force-mem is nop and option will be removed in 4.3");
1275 case OPT_floop_optimize:
1276 case OPT_frerun_loop_opt:
1277 case OPT_fstrength_reduce:
1278 /* These are no-ops, preserved for backward compatibility. */
1282 /* If the flag was handled in a standard way, assume the lack of
1283 processing here is intentional. */
1284 gcc_assert (cl_options[scode].flag_var);
1291 /* Handle --param NAME=VALUE. */
1293 handle_param (const char *carg)
1298 arg = xstrdup (carg);
1299 equal = strchr (arg, '=');
1301 error ("%s: --param arguments should be of the form NAME=VALUE", arg);
1304 value = integral_argument (equal + 1);
1306 error ("invalid --param value %qs", equal + 1);
1310 set_param_value (arg, value);
1317 /* Handle -W and -Wextra. */
1319 set_Wextra (int setting)
1321 extra_warnings = setting;
1322 warn_unused_value = setting;
1323 warn_unused_parameter = (setting && maybe_warn_unused_parameter);
1325 /* We save the value of warn_uninitialized, since if they put
1326 -Wuninitialized on the command line, we need to generate a
1327 warning about not using it without also specifying -O. */
1329 warn_uninitialized = 0;
1330 else if (warn_uninitialized != 1)
1331 warn_uninitialized = 2;
1334 /* Initialize unused warning flags. */
1336 set_Wunused (int setting)
1338 warn_unused_function = setting;
1339 warn_unused_label = setting;
1340 /* Unused function parameter warnings are reported when either
1341 ``-Wextra -Wunused'' or ``-Wunused-parameter'' is specified.
1342 Thus, if -Wextra has already been seen, set warn_unused_parameter;
1343 otherwise set maybe_warn_extra_parameter, which will be picked up
1345 maybe_warn_unused_parameter = setting;
1346 warn_unused_parameter = (setting && extra_warnings);
1347 warn_unused_variable = setting;
1348 warn_unused_value = setting;
1351 /* The following routines are useful in setting all the flags that
1352 -ffast-math and -fno-fast-math imply. */
1354 set_fast_math_flags (int set)
1356 flag_trapping_math = !set;
1357 flag_unsafe_math_optimizations = set;
1358 flag_finite_math_only = set;
1359 flag_errno_math = !set;
1362 flag_signaling_nans = 0;
1363 flag_rounding_math = 0;
1364 flag_cx_limited_range = 1;
1368 /* Return true iff flags are set as if -ffast-math. */
1370 fast_math_flags_set_p (void)
1372 return (!flag_trapping_math
1373 && flag_unsafe_math_optimizations
1374 && flag_finite_math_only
1375 && !flag_errno_math);
1378 /* Handle a debug output -g switch. EXTENDED is true or false to support
1379 extended output (2 is special and means "-ggdb" was given). */
1381 set_debug_level (enum debug_info_type type, int extended, const char *arg)
1383 static bool type_explicit;
1385 use_gnu_debug_info_extensions = extended;
1387 if (type == NO_DEBUG)
1389 if (write_symbols == NO_DEBUG)
1391 write_symbols = PREFERRED_DEBUGGING_TYPE;
1395 #ifdef DWARF2_DEBUGGING_INFO
1396 write_symbols = DWARF2_DEBUG;
1397 #elif defined DBX_DEBUGGING_INFO
1398 write_symbols = DBX_DEBUG;
1402 if (write_symbols == NO_DEBUG)
1403 warning (0, "target system does not support debug output");
1408 /* Does it conflict with an already selected type? */
1409 if (type_explicit && write_symbols != NO_DEBUG && type != write_symbols)
1410 error ("debug format \"%s\" conflicts with prior selection",
1411 debug_type_names[type]);
1412 write_symbols = type;
1413 type_explicit = true;
1416 /* A debug flag without a level defaults to level 2. */
1419 if (!debug_info_level)
1420 debug_info_level = 2;
1424 debug_info_level = integral_argument (arg);
1425 if (debug_info_level == (unsigned int) -1)
1426 error ("unrecognised debug output level \"%s\"", arg);
1427 else if (debug_info_level > 3)
1428 error ("debug output level %s is too high", arg);
1432 /* Display help for target options. */
1434 print_target_help (void)
1437 static bool displayed = false;
1439 /* Avoid double printing for --help --target-help. */
1444 for (i = 0; i < cl_options_count; i++)
1445 if ((cl_options[i].flags & (CL_TARGET | CL_UNDOCUMENTED)) == CL_TARGET)
1447 printf (_("\nTarget specific options:\n"));
1448 print_filtered_help (CL_TARGET);
1453 /* Output --help text. */
1460 GET_ENVIRONMENT (p, "COLUMNS");
1463 int value = atoi (p);
1468 puts (_("The following options are language-independent:\n"));
1470 print_filtered_help (CL_COMMON);
1471 print_param_help ();
1473 for (i = 0; lang_names[i]; i++)
1475 printf (_("The %s front end recognizes the following options:\n\n"),
1477 print_filtered_help (1U << i);
1479 print_target_help ();
1482 /* Print the help for --param. */
1484 print_param_help (void)
1488 puts (_("The --param option recognizes the following as parameters:\n"));
1490 for (i = 0; i < LAST_PARAM; i++)
1492 const char *help = compiler_params[i].help;
1493 const char *param = compiler_params[i].option;
1495 if (help == NULL || *help == '\0')
1496 help = undocumented_msg;
1498 /* Get the translation. */
1501 wrap_help (help, param, strlen (param));
1507 /* Print help for a specific front-end, etc. */
1509 print_filtered_help (unsigned int flag)
1511 unsigned int i, len, filter, indent = 0;
1512 bool duplicates = false;
1513 const char *help, *opt, *tab;
1514 static char *printed;
1516 if (flag == CL_COMMON || flag == CL_TARGET)
1520 printed = xmalloc (cl_options_count);
1521 memset (printed, 0, cl_options_count);
1525 /* Don't print COMMON options twice. */
1526 filter = flag | CL_COMMON;
1528 for (i = 0; i < cl_options_count; i++)
1530 if ((cl_options[i].flags & filter) != flag)
1533 /* Skip help for internal switches. */
1534 if (cl_options[i].flags & CL_UNDOCUMENTED)
1537 /* Skip switches that have already been printed, mark them to be
1542 indent = print_switch (cl_options[i].opt_text, indent);
1553 for (i = 0; i < cl_options_count; i++)
1555 if ((cl_options[i].flags & filter) != flag)
1558 /* Skip help for internal switches. */
1559 if (cl_options[i].flags & CL_UNDOCUMENTED)
1562 /* Skip switches that have already been printed. */
1568 help = cl_options[i].help;
1570 help = undocumented_msg;
1572 /* Get the translation. */
1575 tab = strchr (help, '\t');
1584 opt = cl_options[i].opt_text;
1588 wrap_help (help, opt, len);
1594 /* Output ITEM, of length ITEM_WIDTH, in the left column, followed by
1595 word-wrapped HELP in a second column. */
1597 print_switch (const char *text, unsigned int indent)
1599 unsigned int len = strlen (text) + 1; /* trailing comma */
1604 if (indent + len > columns)
1615 fputs (text, stdout);
1617 return indent + len + 1;
1620 /* Output ITEM, of length ITEM_WIDTH, in the left column, followed by
1621 word-wrapped HELP in a second column. */
1623 wrap_help (const char *help, const char *item, unsigned int item_width)
1625 unsigned int col_width = 27;
1626 unsigned int remaining, room, len;
1628 remaining = strlen (help);
1632 room = columns - 3 - MAX (col_width, item_width);
1641 for (i = 0; help[i]; i++)
1643 if (i >= room && len != remaining)
1647 else if ((help[i] == '-' || help[i] == '/')
1648 && help[i + 1] != ' '
1649 && i > 0 && ISALPHA (help[i - 1]))
1654 printf( " %-*.*s %.*s\n", col_width, item_width, item, len, help);
1656 while (help[len] == ' ')
1664 /* Return 1 if OPTION is enabled, 0 if it is disabled, or -1 if it isn't
1665 a simple on-off switch. */
1668 option_enabled (int opt_idx)
1670 const struct cl_option *option = &(cl_options[opt_idx]);
1671 if (option->flag_var)
1672 switch (option->var_type)
1675 return *(int *) option->flag_var != 0;
1678 return *(int *) option->flag_var == option->var_value;
1680 case CLVC_BIT_CLEAR:
1681 return (*(int *) option->flag_var & option->var_value) == 0;
1684 return (*(int *) option->flag_var & option->var_value) != 0;
1692 /* Fill STATE with the current state of option OPTION. Return true if
1693 there is some state to store. */
1696 get_option_state (int option, struct cl_option_state *state)
1698 if (cl_options[option].flag_var == 0)
1701 switch (cl_options[option].var_type)
1705 state->data = cl_options[option].flag_var;
1706 state->size = sizeof (int);
1709 case CLVC_BIT_CLEAR:
1711 state->ch = option_enabled (option);
1712 state->data = &state->ch;
1717 state->data = *(const char **) cl_options[option].flag_var;
1718 if (state->data == 0)
1720 state->size = strlen (state->data) + 1;