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 /* True to warn about any function whose frame size is larger
64 bool warn_frame_larger_than;
65 HOST_WIDE_INT frame_larger_than_size;
67 /* Nonzero means warn about constructs which might not be
68 strict-aliasing safe. */
69 int warn_strict_aliasing;
71 /* Nonzero means warn about optimizations which rely on undefined
73 int warn_strict_overflow;
75 /* Hack for cooperation between set_Wunused and set_Wextra. */
76 static bool maybe_warn_unused_parameter;
78 /* Type(s) of debugging information we are producing (if any). See
79 flags.h for the definitions of the different possible types of
80 debugging information. */
81 enum debug_info_type write_symbols = NO_DEBUG;
83 /* Level of debugging information we are producing. See flags.h for
84 the definitions of the different possible levels. */
85 enum debug_info_level debug_info_level = DINFO_LEVEL_NONE;
87 /* A major contribution to object and executable size is debug
88 information size. A major contribution to debug information size
89 is struct descriptions replicated in several object files. The
90 following flags attempt to reduce this information. The basic
91 idea is to not emit struct debugging information in the current
92 compilation unit when that information will be generated by
93 another compilation unit.
95 Debug information for a struct defined in the current source
96 file should be generated in the object file. Likewise the
97 debug information for a struct defined in a header should be
98 generated in the object file of the corresponding source file.
99 Both of these case are handled when the base name of the file of
100 the struct definition matches the base name of the source file
101 of thet current compilation unit. This matching emits minimal
102 struct debugging information.
104 The base file name matching rule above will fail to emit debug
105 information for structs defined in system headers. So a second
106 category of files includes system headers in addition to files
109 The remaining types of files are library headers and application
110 headers. We cannot currently distinguish these two types. */
112 enum debug_struct_file
114 DINFO_STRUCT_FILE_NONE, /* Debug no structs. */
115 DINFO_STRUCT_FILE_BASE, /* Debug structs defined in files with the
116 same base name as the compilation unit. */
117 DINFO_STRUCT_FILE_SYS, /* Also debug structs defined in system
119 DINFO_STRUCT_FILE_ANY /* Debug structs defined in all files. */
122 /* Generic structs (e.g. templates not explicitly specialized)
123 may not have a compilation unit associated with them, and so
124 may need to be treated differently from ordinary structs.
126 Structs only handled by reference (indirectly), will also usually
127 not need as much debugging information. */
129 static enum debug_struct_file debug_struct_ordinary[DINFO_USAGE_NUM_ENUMS]
130 = { DINFO_STRUCT_FILE_ANY, DINFO_STRUCT_FILE_ANY, DINFO_STRUCT_FILE_ANY };
131 static enum debug_struct_file debug_struct_generic[DINFO_USAGE_NUM_ENUMS]
132 = { DINFO_STRUCT_FILE_ANY, DINFO_STRUCT_FILE_ANY, DINFO_STRUCT_FILE_ANY };
134 /* Parse the -femit-struct-debug-detailed option value
135 and set the flag variables. */
137 #define MATCH( prefix, string ) \
138 ((strncmp (prefix, string, sizeof prefix - 1) == 0) \
139 ? ((string += sizeof prefix - 1), 1) : 0)
142 set_struct_debug_option (const char *spec)
144 /* various labels for comparison */
145 static char dfn_lbl[] = "dfn:", dir_lbl[] = "dir:", ind_lbl[] = "ind:";
146 static char ord_lbl[] = "ord:", gen_lbl[] = "gen:";
147 static char none_lbl[] = "none", any_lbl[] = "any";
148 static char base_lbl[] = "base", sys_lbl[] = "sys";
150 enum debug_struct_file files = DINFO_STRUCT_FILE_ANY;
151 /* Default is to apply to as much as possible. */
152 enum debug_info_usage usage = DINFO_USAGE_NUM_ENUMS;
153 int ord = 1, gen = 1;
156 if (MATCH (dfn_lbl, spec))
157 usage = DINFO_USAGE_DFN;
158 else if (MATCH (dir_lbl, spec))
159 usage = DINFO_USAGE_DIR_USE;
160 else if (MATCH (ind_lbl, spec))
161 usage = DINFO_USAGE_IND_USE;
163 /* Generics or not? */
164 if (MATCH (ord_lbl, spec))
166 else if (MATCH (gen_lbl, spec))
169 /* What allowable environment? */
170 if (MATCH (none_lbl, spec))
171 files = DINFO_STRUCT_FILE_NONE;
172 else if (MATCH (any_lbl, spec))
173 files = DINFO_STRUCT_FILE_ANY;
174 else if (MATCH (sys_lbl, spec))
175 files = DINFO_STRUCT_FILE_SYS;
176 else if (MATCH (base_lbl, spec))
177 files = DINFO_STRUCT_FILE_BASE;
179 error ("argument %qs to %<-femit-struct-debug-detailed%> not recognized",
182 /* Effect the specification. */
183 if (usage == DINFO_USAGE_NUM_ENUMS)
187 debug_struct_ordinary[DINFO_USAGE_DFN] = files;
188 debug_struct_ordinary[DINFO_USAGE_DIR_USE] = files;
189 debug_struct_ordinary[DINFO_USAGE_IND_USE] = files;
193 debug_struct_generic[DINFO_USAGE_DFN] = files;
194 debug_struct_generic[DINFO_USAGE_DIR_USE] = files;
195 debug_struct_generic[DINFO_USAGE_IND_USE] = files;
201 debug_struct_ordinary[usage] = files;
203 debug_struct_generic[usage] = files;
207 set_struct_debug_option (spec+1);
210 /* No more -femit-struct-debug-detailed specifications.
213 error ("argument %qs to %<-femit-struct-debug-detailed%> unknown",
215 if (debug_struct_ordinary[DINFO_USAGE_DIR_USE]
216 < debug_struct_ordinary[DINFO_USAGE_IND_USE]
217 || debug_struct_generic[DINFO_USAGE_DIR_USE]
218 < debug_struct_generic[DINFO_USAGE_IND_USE])
219 error ("%<-femit-struct-debug-detailed=dir:...%> must allow at least"
220 " as much as %<-femit-struct-debug-detailed=ind:...%>");
224 /* Find the base name of a path, stripping off both directories and
225 a single final extension. */
227 base_of_path (const char *path, const char **base_out)
229 const char *base = path;
231 const char *p = path;
235 if (IS_DIR_SEPARATOR(c))
250 /* Match the base name of a file to the base name of a compilation unit. */
252 static const char *main_input_basename;
253 static int main_input_baselength;
256 matches_main_base (const char *path)
258 /* Cache the last query. */
259 static const char *last_path = NULL;
260 static int last_match = 0;
261 if (path != last_path)
264 int length = base_of_path (path, &base);
266 last_match = (length == main_input_baselength
267 && memcmp (base, main_input_basename, length) == 0);
272 #ifdef DEBUG_DEBUG_STRUCT
275 dump_struct_debug (tree type, enum debug_info_usage usage,
276 enum debug_struct_file criterion, int generic,
277 int matches, int result)
279 /* Find the type name. */
280 tree type_decl = TYPE_STUB_DECL (type);
282 const char *name = 0;
283 if (TREE_CODE (t) == TYPE_DECL)
286 name = IDENTIFIER_POINTER (t);
288 fprintf (stderr, " struct %d %s %s %s %s %d %p %s\n",
290 DECL_IN_SYSTEM_HEADER (type_decl) ? "sys" : "usr",
291 matches ? "bas" : "hdr",
292 generic ? "gen" : "ord",
293 usage == DINFO_USAGE_DFN ? ";" :
294 usage == DINFO_USAGE_DIR_USE ? "." : "*",
296 (void*) type_decl, name);
299 #define DUMP_GSTRUCT(type, usage, criterion, generic, matches, result) \
300 dump_struct_debug (type, usage, criterion, generic, matches, result)
304 #define DUMP_GSTRUCT(type, usage, criterion, generic, matches, result) \
311 should_emit_struct_debug (tree type, enum debug_info_usage usage)
313 enum debug_struct_file criterion;
315 bool generic = lang_hooks.types.generic_p (type);
318 criterion = debug_struct_generic[usage];
320 criterion = debug_struct_ordinary[usage];
322 if (criterion == DINFO_STRUCT_FILE_NONE)
323 return DUMP_GSTRUCT (type, usage, criterion, generic, false, false);
324 if (criterion == DINFO_STRUCT_FILE_ANY)
325 return DUMP_GSTRUCT (type, usage, criterion, generic, false, true);
327 type_decl = TYPE_STUB_DECL (type);
329 if (criterion == DINFO_STRUCT_FILE_SYS && DECL_IN_SYSTEM_HEADER (type_decl))
330 return DUMP_GSTRUCT (type, usage, criterion, generic, false, true);
332 if (matches_main_base (DECL_SOURCE_FILE (type_decl)))
333 return DUMP_GSTRUCT (type, usage, criterion, generic, true, true);
334 return DUMP_GSTRUCT (type, usage, criterion, generic, false, false);
337 /* Nonzero means use GNU-only extensions in the generated symbolic
338 debugging information. Currently, this only has an effect when
339 write_symbols is set to DBX_DEBUG, XCOFF_DEBUG, or DWARF_DEBUG. */
340 bool use_gnu_debug_info_extensions;
342 /* The default visibility for all symbols (unless overridden) */
343 enum symbol_visibility default_visibility = VISIBILITY_DEFAULT;
345 /* Disable unit-at-a-time for frontends that might be still broken in this
348 bool no_unit_at_a_time_default;
350 /* Global visibility options. */
351 struct visibility_flags visibility_options;
353 /* Columns of --help display. */
354 static unsigned int columns = 80;
356 /* What to print when a switch has no documentation. */
357 static const char undocumented_msg[] = N_("This switch lacks documentation");
359 /* Used for bookkeeping on whether user set these flags so
360 -fprofile-use/-fprofile-generate does not use them. */
361 static bool profile_arc_flag_set, flag_profile_values_set;
362 static bool flag_unroll_loops_set, flag_tracer_set;
363 static bool flag_value_profile_transformations_set;
364 static bool flag_peel_loops_set, flag_branch_probabilities_set;
366 /* Functions excluded from profiling. */
368 typedef char *char_p; /* For DEF_VEC_P. */
370 DEF_VEC_ALLOC_P(char_p,heap);
372 static VEC(char_p,heap) *flag_instrument_functions_exclude_functions;
373 static VEC(char_p,heap) *flag_instrument_functions_exclude_files;
375 /* Input file names. */
376 const char **in_fnames;
377 unsigned num_in_fnames;
379 static int common_handle_option (size_t scode, const char *arg, int value,
380 unsigned int lang_mask);
381 static void handle_param (const char *);
382 static void set_Wextra (int);
383 static unsigned int handle_option (const char **argv, unsigned int lang_mask);
384 static char *write_langs (unsigned int lang_mask);
385 static void complain_wrong_lang (const char *, const struct cl_option *,
386 unsigned int lang_mask);
387 static void handle_options (unsigned int, const char **, unsigned int);
388 static void wrap_help (const char *help, const char *item, unsigned int);
389 static void print_target_help (void);
390 static void print_help (void);
391 static void print_param_help (void);
392 static void print_filtered_help (unsigned int);
393 static unsigned int print_switch (const char *text, unsigned int indent);
394 static void set_debug_level (enum debug_info_type type, int extended,
397 /* If ARG is a non-negative integer made up solely of digits, return its
398 value, otherwise return -1. */
400 integral_argument (const char *arg)
404 while (*p && ISDIGIT (*p))
413 /* Return a malloced slash-separated list of languages in MASK. */
415 write_langs (unsigned int mask)
417 unsigned int n = 0, len = 0;
418 const char *lang_name;
421 for (n = 0; (lang_name = lang_names[n]) != 0; n++)
422 if (mask & (1U << n))
423 len += strlen (lang_name) + 1;
425 result = XNEWVEC (char, len);
427 for (n = 0; (lang_name = lang_names[n]) != 0; n++)
428 if (mask & (1U << n))
432 strcpy (result + len, lang_name);
433 len += strlen (lang_name);
441 /* Complain that switch OPT_INDEX does not apply to this front end. */
443 complain_wrong_lang (const char *text, const struct cl_option *option,
444 unsigned int lang_mask)
446 char *ok_langs, *bad_lang;
448 ok_langs = write_langs (option->flags);
449 bad_lang = write_langs (lang_mask);
451 /* Eventually this should become a hard error IMO. */
452 warning (0, "command line option \"%s\" is valid for %s but not for %s",
453 text, ok_langs, bad_lang);
459 /* Handle the switch beginning at ARGV for the language indicated by
460 LANG_MASK. Returns the number of switches consumed. */
462 handle_option (const char **argv, unsigned int lang_mask)
465 const char *opt, *arg = 0;
468 unsigned int result = 0;
469 const struct cl_option *option;
473 opt_index = find_opt (opt + 1, lang_mask | CL_COMMON | CL_TARGET);
474 if (opt_index == cl_options_count
475 && (opt[1] == 'W' || opt[1] == 'f' || opt[1] == 'm')
476 && opt[2] == 'n' && opt[3] == 'o' && opt[4] == '-')
478 /* Drop the "no-" from negative switches. */
479 size_t len = strlen (opt) - 3;
481 dup = XNEWVEC (char, len + 1);
484 memcpy (dup + 2, opt + 5, len - 2 + 1);
487 opt_index = find_opt (opt + 1, lang_mask | CL_COMMON | CL_TARGET);
490 if (opt_index == cl_options_count)
493 option = &cl_options[opt_index];
495 /* Reject negative form of switches that don't take negatives as
497 if (!value && (option->flags & CL_REJECT_NEGATIVE))
500 /* We've recognized this switch. */
503 /* Check to see if the option is disabled for this configuration. */
504 if (option->flags & CL_DISABLED)
506 error ("command line option %qs"
507 " is not supported by this configuration", opt);
511 /* Sort out any argument the switch takes. */
512 if (option->flags & CL_JOINED)
514 /* Have arg point to the original switch. This is because
515 some code, such as disable_builtin_function, expects its
516 argument to be persistent until the program exits. */
517 arg = argv[0] + cl_options[opt_index].opt_len + 1;
519 arg += strlen ("no-");
521 if (*arg == '\0' && !(option->flags & CL_MISSING_OK))
523 if (option->flags & CL_SEPARATE)
529 /* Missing argument. */
533 else if (option->flags & CL_SEPARATE)
539 /* Now we've swallowed any potential argument, complain if this
540 is a switch for a different front end. */
541 if (!(option->flags & (lang_mask | CL_COMMON | CL_TARGET)))
543 complain_wrong_lang (argv[0], option, lang_mask);
547 if (arg == NULL && (option->flags & (CL_JOINED | CL_SEPARATE)))
549 if (!lang_hooks.missing_argument (opt, opt_index))
550 error ("missing argument to \"%s\"", opt);
554 /* If the switch takes an integer, convert it. */
555 if (arg && (option->flags & CL_UINTEGER))
557 value = integral_argument (arg);
560 error ("argument to \"%s\" should be a non-negative integer",
566 if (option->flag_var)
567 switch (option->var_type)
570 *(int *) option->flag_var = value;
574 *(int *) option->flag_var = (value
576 : !option->var_value);
581 if ((value != 0) == (option->var_type == CLVC_BIT_SET))
582 *(int *) option->flag_var |= option->var_value;
584 *(int *) option->flag_var &= ~option->var_value;
585 if (option->flag_var == &target_flags)
586 target_flags_explicit |= option->var_value;
590 *(const char **) option->flag_var = arg;
594 if (option->flags & lang_mask)
595 if (lang_hooks.handle_option (opt_index, arg, value) == 0)
598 if (result && (option->flags & CL_COMMON))
599 if (common_handle_option (opt_index, arg, value, lang_mask) == 0)
602 if (result && (option->flags & CL_TARGET))
603 if (!targetm.handle_option (opt_index, arg, value))
612 /* Handle FILENAME from the command line. */
614 add_input_filename (const char *filename)
617 in_fnames = xrealloc (in_fnames, num_in_fnames * sizeof (in_fnames[0]));
618 in_fnames[num_in_fnames - 1] = filename;
621 /* Add functions or file names to a vector of names to exclude from
625 add_instrument_functions_exclude_list (VEC(char_p,heap) **pvec,
633 /* We never free this string. */
646 VEC_safe_push (char_p, heap, *pvec, token_start);
649 if (*r == '\\' && r[1] == ',')
657 if (*token_start != '\0')
658 VEC_safe_push (char_p, heap, *pvec, token_start);
661 /* Return whether we should exclude FNDECL from instrumentation. */
664 flag_instrument_functions_exclude_p (tree fndecl)
666 if (VEC_length (char_p, flag_instrument_functions_exclude_functions) > 0)
672 name = lang_hooks.decl_printable_name (fndecl, 0);
674 VEC_iterate (char_p, flag_instrument_functions_exclude_functions,
678 if (strstr (name, s) != NULL)
683 if (VEC_length (char_p, flag_instrument_functions_exclude_files) > 0)
689 name = DECL_SOURCE_FILE (fndecl);
691 VEC_iterate (char_p, flag_instrument_functions_exclude_files, i, s);
694 if (strstr (name, s) != NULL)
702 /* Decode and handle the vector of command line options. LANG_MASK
703 contains has a single bit set representing the current
706 handle_options (unsigned int argc, const char **argv, unsigned int lang_mask)
710 for (i = 1; i < argc; i += n)
712 const char *opt = argv[i];
714 /* Interpret "-" or a non-switch as a file name. */
715 if (opt[0] != '-' || opt[1] == '\0')
717 if (main_input_filename == NULL)
719 main_input_filename = opt;
720 main_input_baselength
721 = base_of_path (main_input_filename, &main_input_basename);
723 add_input_filename (opt);
728 n = handle_option (argv + i, lang_mask);
733 error ("unrecognized command line option \"%s\"", opt);
738 /* Parse command line options and set default flag values. Do minimal
739 options processing. */
741 decode_options (unsigned int argc, const char **argv)
743 unsigned int i, lang_mask;
745 /* Perform language-specific options initialization. */
746 lang_mask = lang_hooks.init_options (argc, argv);
748 lang_hooks.initialize_diagnostics (global_dc);
750 /* Scan to see what optimization level has been specified. That will
751 determine the default value of many flags. */
752 for (i = 1; i < argc; i++)
754 if (!strcmp (argv[i], "-O"))
759 else if (argv[i][0] == '-' && argv[i][1] == 'O')
761 /* Handle -Os, -O2, -O3, -O69, ... */
762 const char *p = &argv[i][2];
764 if ((p[0] == 's') && (p[1] == 0))
768 /* Optimizing for size forces optimize to be 2. */
773 const int optimize_val = read_integral_parameter (p, p - 2, -1);
774 if (optimize_val != -1)
776 optimize = optimize_val;
785 flag_merge_constants = 0;
792 flag_delayed_branch = 1;
794 #ifdef CAN_DEBUG_WITHOUT_FP
795 flag_omit_frame_pointer = 1;
797 flag_guess_branch_prob = 1;
798 flag_cprop_registers = 1;
799 flag_if_conversion = 1;
800 flag_if_conversion2 = 1;
801 flag_ipa_pure_const = 1;
802 flag_ipa_reference = 1;
808 flag_tree_live_range_split = 1;
810 flag_tree_copyrename = 1;
812 flag_tree_copy_prop = 1;
814 flag_tree_salias = 1;
815 if (!no_unit_at_a_time_default)
816 flag_unit_at_a_time = 1;
820 /* Loop header copying usually increases size of the code. This used
821 not to be true, since quite often it is possible to verify that
822 the condition is satisfied in the first iteration and therefore
823 to eliminate it. Jump threading handles these cases now. */
830 flag_thread_jumps = 1;
831 flag_crossjumping = 1;
832 flag_optimize_sibling_calls = 1;
833 flag_cse_follow_jumps = 1;
834 flag_cse_skip_blocks = 1;
836 flag_expensive_optimizations = 1;
837 flag_ipa_type_escape = 1;
838 flag_rerun_cse_after_loop = 1;
839 flag_caller_saves = 1;
841 #ifdef INSN_SCHEDULING
842 flag_schedule_insns = 1;
843 flag_schedule_insns_after_reload = 1;
846 flag_strict_aliasing = 1;
847 flag_strict_overflow = 1;
848 flag_delete_null_pointer_checks = 1;
849 flag_reorder_blocks = 1;
850 flag_reorder_functions = 1;
851 flag_tree_store_ccp = 1;
852 flag_tree_store_copy_prop = 1;
853 /* XXX: some issues with ports have been traced to -ftree-vrp.
854 So remove it from -O2 and above. Note that jdk1{5,6} are affected
855 and they build with w/-O3 - so we cannot just move it to -O3. */
856 /* flag_tree_vrp = 1; // See GCC tree-optimization/33099 */
860 /* PRE tends to generate bigger code. */
867 flag_inline_functions = 1;
868 flag_unswitch_loops = 1;
869 flag_gcse_after_reload = 1;
879 /* Don't reorder blocks when optimizing for size because extra
880 jump insns may be created; also barrier may create extra padding.
882 More correctly we should have a block reordering mode that tried
883 to minimize the combined size of all the jumps. This would more
884 or less automatically remove extra jumps, but would also try to
885 use more short jumps instead of long jumps. */
886 flag_reorder_blocks = 0;
887 flag_reorder_blocks_and_partition = 0;
892 /* Inlining of very small functions usually reduces total size. */
893 set_param_value ("max-inline-insns-single", 5);
894 set_param_value ("max-inline-insns-auto", 5);
895 flag_inline_functions = 1;
897 /* We want to crossjump as much as possible. */
898 set_param_value ("min-crossjump-insns", 1);
901 /* Initialize whether `char' is signed. */
902 flag_signed_char = DEFAULT_SIGNED_CHAR;
903 /* Set this to a special "uninitialized" value. The actual default is set
904 after target options have been processed. */
905 flag_short_enums = 2;
907 /* Initialize target_flags before OPTIMIZATION_OPTIONS so the latter can
909 target_flags = targetm.default_target_flags;
911 /* Some tagets have ABI-specified unwind tables. */
912 flag_unwind_tables = targetm.unwind_tables_default;
914 #ifdef OPTIMIZATION_OPTIONS
915 /* Allow default optimizations to be specified on a per-machine basis. */
916 OPTIMIZATION_OPTIONS (optimize, optimize_size);
919 handle_options (argc, argv, lang_mask);
923 if (flag_pic && !flag_pie)
926 if (flag_no_inline == 2)
929 flag_really_no_inline = flag_no_inline;
931 /* Set flag_no_inline before the post_options () hook. The C front
932 ends use it to determine tree inlining defaults. FIXME: such
933 code should be lang-independent when all front ends use tree
934 inlining, in which case it, and this condition, should be moved
935 to the top of process_options() instead. */
938 /* Inlining does not work if not optimizing,
939 so force it not to be done. */
943 /* The c_decode_option function and decode_option hook set
944 this to `2' if -Wall is used, so we can avoid giving out
945 lots of errors for people who don't realize what -Wall does. */
946 if (warn_uninitialized == 1)
947 warning (OPT_Wuninitialized,
948 "-Wuninitialized is not supported without -O");
951 if (flag_really_no_inline == 2)
952 flag_really_no_inline = flag_no_inline;
954 /* The optimization to partition hot and cold basic blocks into separate
955 sections of the .o and executable files does not work (currently)
956 with exception handling. This is because there is no support for
957 generating unwind info. If flag_exceptions is turned on we need to
958 turn off the partitioning optimization. */
960 if (flag_exceptions && flag_reorder_blocks_and_partition)
963 ("-freorder-blocks-and-partition does not work with exceptions");
964 flag_reorder_blocks_and_partition = 0;
965 flag_reorder_blocks = 1;
968 /* If user requested unwind info, then turn off the partitioning
971 if (flag_unwind_tables && ! targetm.unwind_tables_default
972 && flag_reorder_blocks_and_partition)
974 inform ("-freorder-blocks-and-partition does not support unwind info");
975 flag_reorder_blocks_and_partition = 0;
976 flag_reorder_blocks = 1;
979 /* If the target requested unwind info, then turn off the partitioning
980 optimization with a different message. Likewise, if the target does not
981 support named sections. */
983 if (flag_reorder_blocks_and_partition
984 && (!targetm.have_named_sections
985 || (flag_unwind_tables && targetm.unwind_tables_default)))
988 ("-freorder-blocks-and-partition does not work on this architecture");
989 flag_reorder_blocks_and_partition = 0;
990 flag_reorder_blocks = 1;
994 /* Handle target- and language-independent options. Return zero to
995 generate an "unknown option" message. Only options that need
996 extra handling need to be listed here; if you simply want
997 VALUE assigned to a variable, it happens automatically. */
1000 common_handle_option (size_t scode, const char *arg, int value,
1001 unsigned int lang_mask)
1003 enum opt_code code = (enum opt_code) scode;
1009 exit_after_options = true;
1016 case OPT__target_help:
1017 print_target_help ();
1018 exit_after_options = true;
1022 print_version (stderr, "");
1023 exit_after_options = true;
1027 g_switch_value = value;
1028 g_switch_set = true;
1033 /* Currently handled in a prescan. */
1037 /* For backward compatibility, -W is the same as -Wextra. */
1045 new_option = XNEWVEC (char, strlen (arg) + 2);
1046 new_option[0] = 'W';
1047 strcpy (new_option+1, arg);
1048 option_index = find_opt (new_option, lang_mask);
1049 if (option_index == N_OPTS)
1051 error ("-Werror=%s: No option -%s", arg, new_option);
1055 int kind = value ? DK_ERROR : DK_WARNING;
1056 diagnostic_classify_diagnostic (global_dc, option_index, kind);
1058 /* -Werror=foo implies -Wfoo. */
1059 if (cl_options[option_index].var_type == CLVC_BOOLEAN
1060 && cl_options[option_index].flag_var
1061 && kind == DK_ERROR)
1062 *(int *) cl_options[option_index].flag_var = 1;
1072 case OPT_Wlarger_than_:
1073 larger_than_size = value;
1074 warn_larger_than = value != -1;
1077 case OPT_Wframe_larger_than_:
1078 frame_larger_than_size = value;
1079 warn_frame_larger_than = value != -1;
1082 case OPT_Wstrict_aliasing:
1083 set_warn_strict_aliasing (value);
1086 case OPT_Wstrict_aliasing_:
1087 warn_strict_aliasing = value;
1090 case OPT_Wstrict_overflow:
1091 warn_strict_overflow = (value
1092 ? (int) WARN_STRICT_OVERFLOW_CONDITIONAL
1096 case OPT_Wstrict_overflow_:
1097 warn_strict_overflow = value;
1101 set_Wunused (value);
1106 aux_info_file_name = arg;
1107 flag_gen_aux_info = 1;
1111 aux_base_name = arg;
1114 case OPT_auxbase_strip:
1116 char *tmp = xstrdup (arg);
1117 strip_off_ending (tmp, strlen (tmp));
1119 aux_base_name = tmp;
1124 decode_d_option (arg);
1128 dump_base_name = arg;
1131 case OPT_falign_functions_:
1132 align_functions = value;
1135 case OPT_falign_jumps_:
1136 align_jumps = value;
1139 case OPT_falign_labels_:
1140 align_labels = value;
1143 case OPT_falign_loops_:
1144 align_loops = value;
1147 case OPT_fbranch_probabilities:
1148 flag_branch_probabilities_set = true;
1151 case OPT_fcall_used_:
1152 fix_register (arg, 0, 1);
1155 case OPT_fcall_saved_:
1156 fix_register (arg, 0, 0);
1159 case OPT_fdiagnostics_show_location_:
1160 if (!strcmp (arg, "once"))
1161 diagnostic_prefixing_rule (global_dc) = DIAGNOSTICS_SHOW_PREFIX_ONCE;
1162 else if (!strcmp (arg, "every-line"))
1163 diagnostic_prefixing_rule (global_dc)
1164 = DIAGNOSTICS_SHOW_PREFIX_EVERY_LINE;
1169 case OPT_fdiagnostics_show_option:
1170 global_dc->show_option_requested = true;
1174 if (!dump_switch_p (arg))
1178 case OPT_ffast_math:
1179 set_fast_math_flags (value);
1183 fix_register (arg, 1, 1);
1186 case OPT_finline_limit_:
1187 case OPT_finline_limit_eq:
1188 set_param_value ("max-inline-insns-single", value / 2);
1189 set_param_value ("max-inline-insns-auto", value / 2);
1192 case OPT_finstrument_functions_exclude_function_list_:
1193 add_instrument_functions_exclude_list
1194 (&flag_instrument_functions_exclude_functions, arg);
1197 case OPT_finstrument_functions_exclude_file_list_:
1198 add_instrument_functions_exclude_list
1199 (&flag_instrument_functions_exclude_files, arg);
1202 case OPT_fmessage_length_:
1203 pp_set_line_maximum_length (global_dc->printer, value);
1206 case OPT_fpack_struct_:
1207 if (value <= 0 || (value & (value - 1)) || value > 16)
1208 error("structure alignment must be a small power of two, not %d", value);
1211 initial_max_fld_align = value;
1212 maximum_field_alignment = value * BITS_PER_UNIT;
1216 case OPT_fpeel_loops:
1217 flag_peel_loops_set = true;
1220 case OPT_fprofile_arcs:
1221 profile_arc_flag_set = true;
1224 case OPT_fprofile_use:
1225 if (!flag_branch_probabilities_set)
1226 flag_branch_probabilities = value;
1227 if (!flag_profile_values_set)
1228 flag_profile_values = value;
1229 if (!flag_unroll_loops_set)
1230 flag_unroll_loops = value;
1231 if (!flag_peel_loops_set)
1232 flag_peel_loops = value;
1233 if (!flag_tracer_set)
1234 flag_tracer = value;
1235 if (!flag_value_profile_transformations_set)
1236 flag_value_profile_transformations = value;
1239 case OPT_fprofile_generate:
1240 if (!profile_arc_flag_set)
1241 profile_arc_flag = value;
1242 if (!flag_profile_values_set)
1243 flag_profile_values = value;
1244 if (!flag_value_profile_transformations_set)
1245 flag_value_profile_transformations = value;
1248 case OPT_fprofile_values:
1249 flag_profile_values_set = true;
1252 case OPT_fvisibility_:
1254 if (!strcmp(arg, "default"))
1255 default_visibility = VISIBILITY_DEFAULT;
1256 else if (!strcmp(arg, "internal"))
1257 default_visibility = VISIBILITY_INTERNAL;
1258 else if (!strcmp(arg, "hidden"))
1259 default_visibility = VISIBILITY_HIDDEN;
1260 else if (!strcmp(arg, "protected"))
1261 default_visibility = VISIBILITY_PROTECTED;
1263 error ("unrecognized visibility value \"%s\"", arg);
1268 flag_value_profile_transformations_set = true;
1271 case OPT_frandom_seed:
1272 /* The real switch is -fno-random-seed. */
1275 flag_random_seed = NULL;
1278 case OPT_frandom_seed_:
1279 flag_random_seed = arg;
1282 case OPT_fsched_verbose_:
1283 #ifdef INSN_SCHEDULING
1284 fix_sched_param ("verbose", arg);
1290 case OPT_fsched_stalled_insns_:
1291 flag_sched_stalled_insns = value;
1292 if (flag_sched_stalled_insns == 0)
1293 flag_sched_stalled_insns = -1;
1296 case OPT_fsched_stalled_insns_dep_:
1297 flag_sched_stalled_insns_dep = value;
1300 case OPT_fstack_limit:
1301 /* The real switch is -fno-stack-limit. */
1304 stack_limit_rtx = NULL_RTX;
1307 case OPT_fstack_limit_register_:
1309 int reg = decode_reg_name (arg);
1311 error ("unrecognized register name \"%s\"", arg);
1313 stack_limit_rtx = gen_rtx_REG (Pmode, reg);
1317 case OPT_fstack_limit_symbol_:
1318 stack_limit_rtx = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (arg));
1321 case OPT_ftree_vectorizer_verbose_:
1322 vect_set_verbosity_level (arg);
1325 case OPT_ftls_model_:
1326 if (!strcmp (arg, "global-dynamic"))
1327 flag_tls_default = TLS_MODEL_GLOBAL_DYNAMIC;
1328 else if (!strcmp (arg, "local-dynamic"))
1329 flag_tls_default = TLS_MODEL_LOCAL_DYNAMIC;
1330 else if (!strcmp (arg, "initial-exec"))
1331 flag_tls_default = TLS_MODEL_INITIAL_EXEC;
1332 else if (!strcmp (arg, "local-exec"))
1333 flag_tls_default = TLS_MODEL_LOCAL_EXEC;
1335 warning (0, "unknown tls-model \"%s\"", arg);
1339 flag_tracer_set = true;
1342 case OPT_funroll_loops:
1343 flag_unroll_loops_set = true;
1347 set_debug_level (NO_DEBUG, DEFAULT_GDB_EXTENSIONS, arg);
1351 set_debug_level (SDB_DEBUG, false, arg);
1355 set_debug_level (DWARF2_DEBUG, false, arg);
1359 set_debug_level (NO_DEBUG, 2, arg);
1364 set_debug_level (DBX_DEBUG, code == OPT_gstabs_, arg);
1368 set_debug_level (VMS_DEBUG, false, arg);
1373 set_debug_level (XCOFF_DEBUG, code == OPT_gxcoff_, arg);
1377 asm_file_name = arg;
1380 case OPT_pedantic_errors:
1381 flag_pedantic_errors = pedantic = 1;
1384 case OPT_fforce_mem:
1385 warning (0, "-f[no-]force-mem is nop and option will be removed in 4.3");
1388 case OPT_floop_optimize:
1389 case OPT_frerun_loop_opt:
1390 case OPT_fstrength_reduce:
1391 /* These are no-ops, preserved for backward compatibility. */
1395 /* If the flag was handled in a standard way, assume the lack of
1396 processing here is intentional. */
1397 gcc_assert (cl_options[scode].flag_var);
1404 /* Handle --param NAME=VALUE. */
1406 handle_param (const char *carg)
1411 arg = xstrdup (carg);
1412 equal = strchr (arg, '=');
1414 error ("%s: --param arguments should be of the form NAME=VALUE", arg);
1417 value = integral_argument (equal + 1);
1419 error ("invalid --param value %qs", equal + 1);
1423 set_param_value (arg, value);
1430 /* Handle -W and -Wextra. */
1432 set_Wextra (int setting)
1434 extra_warnings = setting;
1435 warn_unused_value = setting;
1436 warn_unused_parameter = (setting && maybe_warn_unused_parameter);
1438 /* We save the value of warn_uninitialized, since if they put
1439 -Wuninitialized on the command line, we need to generate a
1440 warning about not using it without also specifying -O. */
1442 warn_uninitialized = 0;
1443 else if (warn_uninitialized != 1)
1444 warn_uninitialized = 2;
1447 /* Initialize unused warning flags. */
1449 set_Wunused (int setting)
1451 warn_unused_function = setting;
1452 warn_unused_label = setting;
1453 /* Unused function parameter warnings are reported when either
1454 ``-Wextra -Wunused'' or ``-Wunused-parameter'' is specified.
1455 Thus, if -Wextra has already been seen, set warn_unused_parameter;
1456 otherwise set maybe_warn_extra_parameter, which will be picked up
1458 maybe_warn_unused_parameter = setting;
1459 warn_unused_parameter = (setting && extra_warnings);
1460 warn_unused_variable = setting;
1461 warn_unused_value = setting;
1464 /* Used to set the level of strict aliasing warnings,
1465 when no level is specified (i.e., when -Wstrict-aliasing, and not
1466 -Wstrict-aliasing=level was given).
1467 ONOFF is assumed to take value 1 when -Wstrict-aliasing is specified,
1468 and 0 otherwise. After calling this function, wstrict_aliasing will be
1469 set to the default value of -Wstrict_aliasing=level, currently 3. */
1471 set_warn_strict_aliasing (int onoff)
1473 gcc_assert (onoff == 0 || onoff == 1);
1475 warn_strict_aliasing = 3;
1478 /* The following routines are useful in setting all the flags that
1479 -ffast-math and -fno-fast-math imply. */
1481 set_fast_math_flags (int set)
1483 flag_trapping_math = !set;
1484 flag_unsafe_math_optimizations = set;
1485 flag_finite_math_only = set;
1486 flag_errno_math = !set;
1489 flag_signaling_nans = 0;
1490 flag_rounding_math = 0;
1491 flag_cx_limited_range = 1;
1495 /* Return true iff flags are set as if -ffast-math. */
1497 fast_math_flags_set_p (void)
1499 return (!flag_trapping_math
1500 && flag_unsafe_math_optimizations
1501 && flag_finite_math_only
1502 && !flag_errno_math);
1505 /* Handle a debug output -g switch. EXTENDED is true or false to support
1506 extended output (2 is special and means "-ggdb" was given). */
1508 set_debug_level (enum debug_info_type type, int extended, const char *arg)
1510 static bool type_explicit;
1512 use_gnu_debug_info_extensions = extended;
1514 if (type == NO_DEBUG)
1516 if (write_symbols == NO_DEBUG)
1518 write_symbols = PREFERRED_DEBUGGING_TYPE;
1522 #ifdef DWARF2_DEBUGGING_INFO
1523 write_symbols = DWARF2_DEBUG;
1524 #elif defined DBX_DEBUGGING_INFO
1525 write_symbols = DBX_DEBUG;
1529 if (write_symbols == NO_DEBUG)
1530 warning (0, "target system does not support debug output");
1535 /* Does it conflict with an already selected type? */
1536 if (type_explicit && write_symbols != NO_DEBUG && type != write_symbols)
1537 error ("debug format \"%s\" conflicts with prior selection",
1538 debug_type_names[type]);
1539 write_symbols = type;
1540 type_explicit = true;
1543 /* A debug flag without a level defaults to level 2. */
1546 if (!debug_info_level)
1547 debug_info_level = 2;
1551 debug_info_level = integral_argument (arg);
1552 if (debug_info_level == (unsigned int) -1)
1553 error ("unrecognised debug output level \"%s\"", arg);
1554 else if (debug_info_level > 3)
1555 error ("debug output level %s is too high", arg);
1559 /* Display help for target options. */
1561 print_target_help (void)
1564 static bool displayed = false;
1566 /* Avoid double printing for --help --target-help. */
1571 for (i = 0; i < cl_options_count; i++)
1572 if ((cl_options[i].flags & (CL_TARGET | CL_UNDOCUMENTED)) == CL_TARGET)
1574 printf (_("\nTarget specific options:\n"));
1575 print_filtered_help (CL_TARGET);
1580 /* Output --help text. */
1587 GET_ENVIRONMENT (p, "COLUMNS");
1590 int value = atoi (p);
1595 puts (_("The following options are language-independent:\n"));
1597 print_filtered_help (CL_COMMON);
1598 print_param_help ();
1600 for (i = 0; lang_names[i]; i++)
1602 printf (_("The %s front end recognizes the following options:\n\n"),
1604 print_filtered_help (1U << i);
1606 print_target_help ();
1609 /* Print the help for --param. */
1611 print_param_help (void)
1615 puts (_("The --param option recognizes the following as parameters:\n"));
1617 for (i = 0; i < LAST_PARAM; i++)
1619 const char *help = compiler_params[i].help;
1620 const char *param = compiler_params[i].option;
1622 if (help == NULL || *help == '\0')
1623 help = undocumented_msg;
1625 /* Get the translation. */
1628 wrap_help (help, param, strlen (param));
1634 /* Print help for a specific front-end, etc. */
1636 print_filtered_help (unsigned int flag)
1638 unsigned int i, len, filter, indent = 0;
1639 bool duplicates = false;
1640 const char *help, *opt, *tab;
1641 static char *printed;
1643 if (flag == CL_COMMON || flag == CL_TARGET)
1647 printed = xmalloc (cl_options_count);
1648 memset (printed, 0, cl_options_count);
1652 /* Don't print COMMON options twice. */
1653 filter = flag | CL_COMMON;
1655 for (i = 0; i < cl_options_count; i++)
1657 if ((cl_options[i].flags & filter) != flag)
1660 /* Skip help for internal switches. */
1661 if (cl_options[i].flags & CL_UNDOCUMENTED)
1664 /* Skip switches that have already been printed, mark them to be
1669 indent = print_switch (cl_options[i].opt_text, indent);
1680 for (i = 0; i < cl_options_count; i++)
1682 if ((cl_options[i].flags & filter) != flag)
1685 /* Skip help for internal switches. */
1686 if (cl_options[i].flags & CL_UNDOCUMENTED)
1689 /* Skip switches that have already been printed. */
1695 help = cl_options[i].help;
1697 help = undocumented_msg;
1699 /* Get the translation. */
1702 tab = strchr (help, '\t');
1711 opt = cl_options[i].opt_text;
1715 wrap_help (help, opt, len);
1721 /* Output ITEM, of length ITEM_WIDTH, in the left column, followed by
1722 word-wrapped HELP in a second column. */
1724 print_switch (const char *text, unsigned int indent)
1726 unsigned int len = strlen (text) + 1; /* trailing comma */
1731 if (indent + len > columns)
1742 fputs (text, stdout);
1744 return indent + len + 1;
1747 /* Output ITEM, of length ITEM_WIDTH, in the left column, followed by
1748 word-wrapped HELP in a second column. */
1750 wrap_help (const char *help, const char *item, unsigned int item_width)
1752 unsigned int col_width = 27;
1753 unsigned int remaining, room, len;
1755 remaining = strlen (help);
1759 room = columns - 3 - MAX (col_width, item_width);
1768 for (i = 0; help[i]; i++)
1770 if (i >= room && len != remaining)
1774 else if ((help[i] == '-' || help[i] == '/')
1775 && help[i + 1] != ' '
1776 && i > 0 && ISALPHA (help[i - 1]))
1781 printf( " %-*.*s %.*s\n", col_width, item_width, item, len, help);
1783 while (help[len] == ' ')
1791 /* Return 1 if OPTION is enabled, 0 if it is disabled, or -1 if it isn't
1792 a simple on-off switch. */
1795 option_enabled (int opt_idx)
1797 const struct cl_option *option = &(cl_options[opt_idx]);
1798 if (option->flag_var)
1799 switch (option->var_type)
1802 return *(int *) option->flag_var != 0;
1805 return *(int *) option->flag_var == option->var_value;
1807 case CLVC_BIT_CLEAR:
1808 return (*(int *) option->flag_var & option->var_value) == 0;
1811 return (*(int *) option->flag_var & option->var_value) != 0;
1819 /* Fill STATE with the current state of option OPTION. Return true if
1820 there is some state to store. */
1823 get_option_state (int option, struct cl_option_state *state)
1825 if (cl_options[option].flag_var == 0)
1828 switch (cl_options[option].var_type)
1832 state->data = cl_options[option].flag_var;
1833 state->size = sizeof (int);
1836 case CLVC_BIT_CLEAR:
1838 state->ch = option_enabled (option);
1839 state->data = &state->ch;
1844 state->data = *(const char **) cl_options[option].flag_var;
1845 if (state->data == 0)
1847 state->size = strlen (state->data) + 1;