1 /* Command line option handling.
2 Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
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
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 COPYING3. If not see
20 <http://www.gnu.org/licenses/>. */
25 #include "coretypes.h"
32 #include "langhooks.h"
38 #include "diagnostic.h"
39 #include "opts-diagnostic.h"
40 #include "insn-attr.h" /* For INSN_SCHEDULING. */
42 #include "tree-pass.h"
47 #include "lto-streamer.h"
49 /* True if we should exit after parsing options. */
50 bool exit_after_options;
52 /* True to warn about any objects definitions whose size is larger
53 than N bytes. Also want about function definitions whose returned
54 values are larger than N bytes, where N is `larger_than_size'. */
55 bool warn_larger_than;
56 HOST_WIDE_INT larger_than_size;
58 /* True to warn about any function whose frame size is larger
60 bool warn_frame_larger_than;
61 HOST_WIDE_INT frame_larger_than_size;
63 /* Type(s) of debugging information we are producing (if any). See
64 flags.h for the definitions of the different possible types of
65 debugging information. */
66 enum debug_info_type write_symbols = NO_DEBUG;
68 /* Level of debugging information we are producing. See flags.h for
69 the definitions of the different possible levels. */
70 enum debug_info_level debug_info_level = DINFO_LEVEL_NONE;
72 /* A major contribution to object and executable size is debug
73 information size. A major contribution to debug information size
74 is struct descriptions replicated in several object files. The
75 following flags attempt to reduce this information. The basic
76 idea is to not emit struct debugging information in the current
77 compilation unit when that information will be generated by
78 another compilation unit.
80 Debug information for a struct defined in the current source
81 file should be generated in the object file. Likewise the
82 debug information for a struct defined in a header should be
83 generated in the object file of the corresponding source file.
84 Both of these case are handled when the base name of the file of
85 the struct definition matches the base name of the source file
86 of the current compilation unit. This matching emits minimal
87 struct debugging information.
89 The base file name matching rule above will fail to emit debug
90 information for structs defined in system headers. So a second
91 category of files includes system headers in addition to files
94 The remaining types of files are library headers and application
95 headers. We cannot currently distinguish these two types. */
97 enum debug_struct_file
99 DINFO_STRUCT_FILE_NONE, /* Debug no structs. */
100 DINFO_STRUCT_FILE_BASE, /* Debug structs defined in files with the
101 same base name as the compilation unit. */
102 DINFO_STRUCT_FILE_SYS, /* Also debug structs defined in system
104 DINFO_STRUCT_FILE_ANY /* Debug structs defined in all files. */
107 /* Generic structs (e.g. templates not explicitly specialized)
108 may not have a compilation unit associated with them, and so
109 may need to be treated differently from ordinary structs.
111 Structs only handled by reference (indirectly), will also usually
112 not need as much debugging information. */
114 static enum debug_struct_file debug_struct_ordinary[DINFO_USAGE_NUM_ENUMS]
115 = { DINFO_STRUCT_FILE_ANY, DINFO_STRUCT_FILE_ANY, DINFO_STRUCT_FILE_ANY };
116 static enum debug_struct_file debug_struct_generic[DINFO_USAGE_NUM_ENUMS]
117 = { DINFO_STRUCT_FILE_ANY, DINFO_STRUCT_FILE_ANY, DINFO_STRUCT_FILE_ANY };
119 /* Run the second compilation of -fcompare-debug. Not defined using
120 Var in common.opt because this is used in Ada code and so must be
121 an actual variable not a macro. */
122 int flag_compare_debug;
124 /* Parse the -femit-struct-debug-detailed option value
125 and set the flag variables. */
127 #define MATCH( prefix, string ) \
128 ((strncmp (prefix, string, sizeof prefix - 1) == 0) \
129 ? ((string += sizeof prefix - 1), 1) : 0)
132 set_struct_debug_option (const char *spec)
134 /* various labels for comparison */
135 static char dfn_lbl[] = "dfn:", dir_lbl[] = "dir:", ind_lbl[] = "ind:";
136 static char ord_lbl[] = "ord:", gen_lbl[] = "gen:";
137 static char none_lbl[] = "none", any_lbl[] = "any";
138 static char base_lbl[] = "base", sys_lbl[] = "sys";
140 enum debug_struct_file files = DINFO_STRUCT_FILE_ANY;
141 /* Default is to apply to as much as possible. */
142 enum debug_info_usage usage = DINFO_USAGE_NUM_ENUMS;
143 int ord = 1, gen = 1;
146 if (MATCH (dfn_lbl, spec))
147 usage = DINFO_USAGE_DFN;
148 else if (MATCH (dir_lbl, spec))
149 usage = DINFO_USAGE_DIR_USE;
150 else if (MATCH (ind_lbl, spec))
151 usage = DINFO_USAGE_IND_USE;
153 /* Generics or not? */
154 if (MATCH (ord_lbl, spec))
156 else if (MATCH (gen_lbl, spec))
159 /* What allowable environment? */
160 if (MATCH (none_lbl, spec))
161 files = DINFO_STRUCT_FILE_NONE;
162 else if (MATCH (any_lbl, spec))
163 files = DINFO_STRUCT_FILE_ANY;
164 else if (MATCH (sys_lbl, spec))
165 files = DINFO_STRUCT_FILE_SYS;
166 else if (MATCH (base_lbl, spec))
167 files = DINFO_STRUCT_FILE_BASE;
169 error ("argument %qs to %<-femit-struct-debug-detailed%> not recognized",
172 /* Effect the specification. */
173 if (usage == DINFO_USAGE_NUM_ENUMS)
177 debug_struct_ordinary[DINFO_USAGE_DFN] = files;
178 debug_struct_ordinary[DINFO_USAGE_DIR_USE] = files;
179 debug_struct_ordinary[DINFO_USAGE_IND_USE] = files;
183 debug_struct_generic[DINFO_USAGE_DFN] = files;
184 debug_struct_generic[DINFO_USAGE_DIR_USE] = files;
185 debug_struct_generic[DINFO_USAGE_IND_USE] = files;
191 debug_struct_ordinary[usage] = files;
193 debug_struct_generic[usage] = files;
197 set_struct_debug_option (spec+1);
200 /* No more -femit-struct-debug-detailed specifications.
203 error ("argument %qs to %<-femit-struct-debug-detailed%> unknown",
205 if (debug_struct_ordinary[DINFO_USAGE_DIR_USE]
206 < debug_struct_ordinary[DINFO_USAGE_IND_USE]
207 || debug_struct_generic[DINFO_USAGE_DIR_USE]
208 < debug_struct_generic[DINFO_USAGE_IND_USE])
209 error ("%<-femit-struct-debug-detailed=dir:...%> must allow at least"
210 " as much as %<-femit-struct-debug-detailed=ind:...%>");
214 /* Find the base name of a path, stripping off both directories and
215 a single final extension. */
217 base_of_path (const char *path, const char **base_out)
219 const char *base = path;
221 const char *p = path;
225 if (IS_DIR_SEPARATOR(c))
240 /* Match the base name of a file to the base name of a compilation unit. */
242 static const char *main_input_basename;
243 static int main_input_baselength;
246 matches_main_base (const char *path)
248 /* Cache the last query. */
249 static const char *last_path = NULL;
250 static int last_match = 0;
251 if (path != last_path)
254 int length = base_of_path (path, &base);
256 last_match = (length == main_input_baselength
257 && memcmp (base, main_input_basename, length) == 0);
262 #ifdef DEBUG_DEBUG_STRUCT
265 dump_struct_debug (tree type, enum debug_info_usage usage,
266 enum debug_struct_file criterion, int generic,
267 int matches, int result)
269 /* Find the type name. */
270 tree type_decl = TYPE_STUB_DECL (type);
272 const char *name = 0;
273 if (TREE_CODE (t) == TYPE_DECL)
276 name = IDENTIFIER_POINTER (t);
278 fprintf (stderr, " struct %d %s %s %s %s %d %p %s\n",
280 DECL_IN_SYSTEM_HEADER (type_decl) ? "sys" : "usr",
281 matches ? "bas" : "hdr",
282 generic ? "gen" : "ord",
283 usage == DINFO_USAGE_DFN ? ";" :
284 usage == DINFO_USAGE_DIR_USE ? "." : "*",
286 (void*) type_decl, name);
289 #define DUMP_GSTRUCT(type, usage, criterion, generic, matches, result) \
290 dump_struct_debug (type, usage, criterion, generic, matches, result)
294 #define DUMP_GSTRUCT(type, usage, criterion, generic, matches, result) \
301 should_emit_struct_debug (tree type, enum debug_info_usage usage)
303 enum debug_struct_file criterion;
305 bool generic = lang_hooks.types.generic_p (type);
308 criterion = debug_struct_generic[usage];
310 criterion = debug_struct_ordinary[usage];
312 if (criterion == DINFO_STRUCT_FILE_NONE)
313 return DUMP_GSTRUCT (type, usage, criterion, generic, false, false);
314 if (criterion == DINFO_STRUCT_FILE_ANY)
315 return DUMP_GSTRUCT (type, usage, criterion, generic, false, true);
317 type_decl = TYPE_STUB_DECL (type);
319 if (criterion == DINFO_STRUCT_FILE_SYS && DECL_IN_SYSTEM_HEADER (type_decl))
320 return DUMP_GSTRUCT (type, usage, criterion, generic, false, true);
322 if (matches_main_base (DECL_SOURCE_FILE (type_decl)))
323 return DUMP_GSTRUCT (type, usage, criterion, generic, true, true);
324 return DUMP_GSTRUCT (type, usage, criterion, generic, false, false);
327 /* Nonzero means use GNU-only extensions in the generated symbolic
328 debugging information. Currently, this only has an effect when
329 write_symbols is set to DBX_DEBUG, XCOFF_DEBUG, or DWARF_DEBUG. */
330 bool use_gnu_debug_info_extensions;
332 /* The default visibility for all symbols (unless overridden) */
333 enum symbol_visibility default_visibility = VISIBILITY_DEFAULT;
335 /* Global visibility options. */
336 struct visibility_flags visibility_options;
338 /* What to print when a switch has no documentation. */
339 static const char undocumented_msg[] = N_("This switch lacks documentation");
341 /* Functions excluded from profiling. */
343 typedef char *char_p; /* For DEF_VEC_P. */
345 DEF_VEC_ALLOC_P(char_p,heap);
347 static VEC(char_p,heap) *flag_instrument_functions_exclude_functions;
348 static VEC(char_p,heap) *flag_instrument_functions_exclude_files;
350 typedef const char *const_char_p; /* For DEF_VEC_P. */
351 DEF_VEC_P(const_char_p);
352 DEF_VEC_ALLOC_P(const_char_p,heap);
354 static VEC(const_char_p,heap) *ignored_options;
356 /* Input file names. */
357 const char **in_fnames;
358 unsigned num_in_fnames;
360 static bool common_handle_option (struct gcc_options *opts,
361 struct gcc_options *opts_set,
362 const struct cl_decoded_option *decoded,
363 unsigned int lang_mask, int kind,
364 const struct cl_option_handlers *handlers);
365 static void handle_param (struct gcc_options *opts,
366 struct gcc_options *opts_set, const char *carg);
367 static char *write_langs (unsigned int lang_mask);
368 static void complain_wrong_lang (const struct cl_decoded_option *,
369 unsigned int lang_mask);
370 static void set_debug_level (enum debug_info_type type, int extended,
373 /* Return a malloced slash-separated list of languages in MASK. */
375 write_langs (unsigned int mask)
377 unsigned int n = 0, len = 0;
378 const char *lang_name;
381 for (n = 0; (lang_name = lang_names[n]) != 0; n++)
382 if (mask & (1U << n))
383 len += strlen (lang_name) + 1;
385 result = XNEWVEC (char, len);
387 for (n = 0; (lang_name = lang_names[n]) != 0; n++)
388 if (mask & (1U << n))
392 strcpy (result + len, lang_name);
393 len += strlen (lang_name);
401 /* Complain that switch DECODED does not apply to this front end (mask
404 complain_wrong_lang (const struct cl_decoded_option *decoded,
405 unsigned int lang_mask)
407 const struct cl_option *option = &cl_options[decoded->opt_index];
408 const char *text = decoded->orig_option_with_args_text;
409 char *ok_langs = NULL, *bad_lang = NULL;
410 unsigned int opt_flags = option->flags;
412 if (!lang_hooks.complain_wrong_lang_p (option))
415 opt_flags &= ((1U << cl_lang_count) - 1) | CL_DRIVER;
416 if (opt_flags != CL_DRIVER)
417 ok_langs = write_langs (opt_flags);
418 if (lang_mask != CL_DRIVER)
419 bad_lang = write_langs (lang_mask);
421 if (opt_flags == CL_DRIVER)
422 error ("command line option %qs is valid for the driver but not for %s",
424 else if (lang_mask == CL_DRIVER)
427 /* Eventually this should become a hard error IMO. */
428 warning (0, "command line option %qs is valid for %s but not for %s",
429 text, ok_langs, bad_lang);
435 /* Buffer the unknown option described by the string OPT. Currently,
436 we only complain about unknown -Wno-* options if they may have
437 prevented a diagnostic. Otherwise, we just ignore them.
438 Note that if we do complain, it is only as a warning, not an error;
439 passing the compiler an unrecognised -Wno-* option should never
440 change whether the compilation succeeds or fails. */
442 static void postpone_unknown_option_warning(const char *opt)
444 VEC_safe_push (const_char_p, heap, ignored_options, opt);
447 /* Produce a warning for each option previously buffered. */
449 void print_ignored_options (void)
451 location_t saved_loc = input_location;
455 while (!VEC_empty (const_char_p, ignored_options))
458 opt = VEC_pop (const_char_p, ignored_options);
459 warning (0, "unrecognized command line option \"%s\"", opt);
462 input_location = saved_loc;
465 /* Handle an unknown option DECODED, returning true if an error should be
469 unknown_option_callback (const struct cl_decoded_option *decoded)
471 const char *opt = decoded->arg;
473 if (opt[1] == 'W' && opt[2] == 'n' && opt[3] == 'o' && opt[4] == '-'
474 && !(decoded->errors & CL_ERR_NEGATIVE))
476 /* We don't generate warnings for unknown -Wno-* options unless
477 we issue diagnostics. */
478 postpone_unknown_option_warning (opt);
485 /* Note that an option DECODED has been successfully handled with a
486 handler for mask MASK. */
489 post_handling_callback (const struct cl_decoded_option *decoded ATTRIBUTE_UNUSED,
490 unsigned int mask ATTRIBUTE_UNUSED)
493 lto_register_user_option (decoded->opt_index, decoded->arg,
494 decoded->value, mask);
498 /* Handle a front-end option; arguments and return value as for
502 lang_handle_option (struct gcc_options *opts,
503 struct gcc_options *opts_set,
504 const struct cl_decoded_option *decoded,
505 unsigned int lang_mask ATTRIBUTE_UNUSED, int kind,
506 const struct cl_option_handlers *handlers)
508 gcc_assert (opts == &global_options);
509 gcc_assert (opts_set == &global_options_set);
510 gcc_assert (decoded->canonical_option_num_elements <= 2);
511 return lang_hooks.handle_option (decoded->opt_index, decoded->arg,
512 decoded->value, kind, handlers);
515 /* Handle a back-end option; arguments and return value as for
519 target_handle_option (struct gcc_options *opts,
520 struct gcc_options *opts_set,
521 const struct cl_decoded_option *decoded,
522 unsigned int lang_mask ATTRIBUTE_UNUSED, int kind,
523 const struct cl_option_handlers *handlers ATTRIBUTE_UNUSED)
525 gcc_assert (opts == &global_options);
526 gcc_assert (opts_set == &global_options_set);
527 gcc_assert (decoded->canonical_option_num_elements <= 2);
528 gcc_assert (kind == DK_UNSPECIFIED);
529 return targetm.handle_option (decoded->opt_index, decoded->arg,
533 /* Handle FILENAME from the command line. */
535 add_input_filename (const char *filename)
538 in_fnames = XRESIZEVEC (const char *, in_fnames, num_in_fnames);
539 in_fnames[num_in_fnames - 1] = filename;
542 /* Add comma-separated strings to a char_p vector. */
545 add_comma_separated_to_vector (VEC(char_p,heap) **pvec, const char* arg)
552 /* We never free this string. */
565 VEC_safe_push (char_p, heap, *pvec, token_start);
568 if (*r == '\\' && r[1] == ',')
576 if (*token_start != '\0')
577 VEC_safe_push (char_p, heap, *pvec, token_start);
580 /* Return whether we should exclude FNDECL from instrumentation. */
583 flag_instrument_functions_exclude_p (tree fndecl)
585 if (VEC_length (char_p, flag_instrument_functions_exclude_functions) > 0)
591 name = lang_hooks.decl_printable_name (fndecl, 0);
592 FOR_EACH_VEC_ELT (char_p, flag_instrument_functions_exclude_functions,
594 if (strstr (name, s) != NULL)
598 if (VEC_length (char_p, flag_instrument_functions_exclude_files) > 0)
604 name = DECL_SOURCE_FILE (fndecl);
605 FOR_EACH_VEC_ELT (char_p, flag_instrument_functions_exclude_files, i, s)
606 if (strstr (name, s) != NULL)
614 /* Handle the vector of command line options, storing the results of
615 processing DECODED_OPTIONS and DECODED_OPTIONS_COUNT in OPTS and
616 OPTS_SET. LANG_MASK contains has a single bit set representing the
617 current language. HANDLERS describes what functions to call for
620 read_cmdline_options (struct gcc_options *opts, struct gcc_options *opts_set,
621 struct cl_decoded_option *decoded_options,
622 unsigned int decoded_options_count,
623 unsigned int lang_mask,
624 const struct cl_option_handlers *handlers)
628 for (i = 1; i < decoded_options_count; i++)
630 if (decoded_options[i].opt_index == OPT_SPECIAL_input_file)
632 /* Input files should only ever appear on the main command
634 gcc_assert (opts == &global_options);
635 gcc_assert (opts_set == &global_options_set);
637 if (main_input_filename == NULL)
639 main_input_filename = decoded_options[i].arg;
640 main_input_baselength
641 = base_of_path (main_input_filename, &main_input_basename);
643 add_input_filename (decoded_options[i].arg);
647 read_cmdline_option (opts, opts_set,
648 decoded_options + i, lang_mask, handlers,
653 /* Language mask determined at initialization. */
654 static unsigned int initial_lang_mask;
656 /* Initialize global options-related settings at start-up. */
659 init_options_once (void)
661 /* Perform language-specific options initialization. */
662 initial_lang_mask = lang_hooks.option_lang_mask ();
664 lang_hooks.initialize_diagnostics (global_dc);
667 /* Initialize OPTS and OPTS_SET before using them in parsing options. */
670 init_options_struct (struct gcc_options *opts, struct gcc_options *opts_set)
672 size_t num_params = get_num_compiler_params ();
674 *opts = global_options_init;
675 memset (opts_set, 0, sizeof (*opts_set));
677 opts->x_param_values = XNEWVEC (int, num_params);
678 opts_set->x_param_values = XCNEWVEC (int, num_params);
679 init_param_values (opts->x_param_values);
681 /* Use priority coloring if cover classes is not defined for the
683 if (targetm.ira_cover_classes == NULL)
684 opts->x_flag_ira_algorithm = IRA_ALGORITHM_PRIORITY;
686 /* Initialize whether `char' is signed. */
687 opts->x_flag_signed_char = DEFAULT_SIGNED_CHAR;
688 /* Set this to a special "uninitialized" value. The actual default
689 is set after target options have been processed. */
690 opts->x_flag_short_enums = 2;
692 /* Initialize target_flags before targetm.target_option.optimization
693 so the latter can modify it. */
694 opts->x_target_flags = targetm.default_target_flags;
696 /* Some targets have ABI-specified unwind tables. */
697 opts->x_flag_unwind_tables = targetm.unwind_tables_default;
699 /* Some targets have other target-specific initialization. */
700 targetm.target_option.init_struct (opts);
703 /* Decode command-line options to an array, like
704 decode_cmdline_options_to_array and with the same arguments but
705 using the default lang_mask. */
708 decode_cmdline_options_to_array_default_mask (unsigned int argc,
710 struct cl_decoded_option **decoded_options,
711 unsigned int *decoded_options_count)
713 decode_cmdline_options_to_array (argc, argv,
714 initial_lang_mask | CL_COMMON | CL_TARGET,
715 decoded_options, decoded_options_count);
718 /* Default the options in OPTS and OPTS_SET based on the optimization
719 settings in DECODED_OPTIONS and DECODED_OPTIONS_COUNT. */
721 default_options_optimization (struct gcc_options *opts,
722 struct gcc_options *opts_set,
723 struct cl_decoded_option *decoded_options,
724 unsigned int decoded_options_count)
733 gcc_assert (opts == &global_options);
734 gcc_assert (opts_set = &global_options_set);
736 /* Scan to see what optimization level has been specified. That will
737 determine the default value of many flags. */
738 for (i = 1; i < decoded_options_count; i++)
740 struct cl_decoded_option *opt = &decoded_options[i];
741 switch (opt->opt_index)
744 if (*opt->arg == '\0')
752 const int optimize_val = integral_argument (opt->arg);
753 if (optimize_val == -1)
754 error ("argument to %qs should be a non-negative integer",
758 optimize = optimize_val;
759 if ((unsigned int) optimize > 255)
770 /* Optimizing for size forces optimize to be 2. */
776 /* -Ofast only adds flags to -O3. */
783 /* Ignore other options in this prescan. */
788 /* -O1 optimizations. */
789 opt1 = (optimize >= 1);
790 flag_defer_pop = opt1;
792 flag_delayed_branch = opt1;
794 #ifdef CAN_DEBUG_WITHOUT_FP
795 flag_omit_frame_pointer = opt1;
797 flag_guess_branch_prob = opt1;
798 flag_cprop_registers = opt1;
799 flag_forward_propagate = opt1;
800 flag_if_conversion = opt1;
801 flag_if_conversion2 = opt1;
802 flag_ipa_pure_const = opt1;
803 flag_ipa_reference = opt1;
804 flag_ipa_profile = opt1;
805 flag_merge_constants = opt1;
806 flag_split_wide_types = opt1;
807 flag_tree_ccp = opt1;
808 flag_tree_bit_ccp = opt1;
809 flag_tree_dce = opt1;
810 flag_tree_dom = opt1;
811 flag_tree_dse = opt1;
812 flag_tree_ter = opt1;
813 flag_tree_sra = opt1;
814 flag_tree_copyrename = opt1;
815 flag_tree_fre = opt1;
816 flag_tree_copy_prop = opt1;
817 flag_tree_sink = opt1;
819 flag_combine_stack_adjustments = opt1;
821 /* -O2 optimizations. */
822 opt2 = (optimize >= 2);
823 flag_inline_small_functions = opt2;
824 flag_indirect_inlining = opt2;
825 flag_partial_inlining = opt2;
826 flag_thread_jumps = opt2;
827 flag_crossjumping = opt2;
828 flag_optimize_sibling_calls = opt2;
829 flag_cse_follow_jumps = opt2;
831 flag_expensive_optimizations = opt2;
832 flag_rerun_cse_after_loop = opt2;
833 flag_caller_saves = opt2;
834 flag_peephole2 = opt2;
835 #ifdef INSN_SCHEDULING
836 /* Only run the pre-regalloc scheduling pass if optimizing for speed. */
837 flag_schedule_insns = opt2 && ! optimize_size;
838 flag_schedule_insns_after_reload = opt2;
841 flag_strict_aliasing = opt2;
842 flag_strict_overflow = opt2;
843 flag_reorder_blocks = opt2;
844 flag_reorder_functions = opt2;
845 flag_tree_vrp = opt2;
846 flag_tree_builtin_call_dce = opt2;
847 flag_tree_pre = opt2;
848 flag_tree_switch_conversion = opt2;
852 /* Track fields in field-sensitive alias analysis. */
853 maybe_set_param_value
854 (PARAM_MAX_FIELDS_FOR_FIELD_SENSITIVE,
855 opt2 ? 100 : default_param_value (PARAM_MAX_FIELDS_FOR_FIELD_SENSITIVE),
856 opts->x_param_values, opts_set->x_param_values);
858 /* For -O1 only do loop invariant motion for very small loops. */
859 maybe_set_param_value
860 (PARAM_LOOP_INVARIANT_MAX_BBS_IN_LOOP,
861 opt2 ? default_param_value (PARAM_LOOP_INVARIANT_MAX_BBS_IN_LOOP) : 1000,
862 opts->x_param_values, opts_set->x_param_values);
864 /* -O3 optimizations. */
865 opt3 = (optimize >= 3);
866 flag_tree_loop_distribute_patterns = opt3;
867 flag_predictive_commoning = opt3;
868 flag_inline_functions = opt3;
869 flag_unswitch_loops = opt3;
870 flag_gcse_after_reload = opt3;
871 flag_tree_vectorize = opt3;
872 flag_ipa_cp_clone = opt3;
873 if (flag_ipa_cp_clone)
876 /* Just -O1/-O0 optimizations. */
877 opt1_max = (optimize <= 1);
878 align_loops = opt1_max;
879 align_jumps = opt1_max;
880 align_labels = opt1_max;
881 align_functions = opt1_max;
885 /* Inlining of functions reducing size is a good idea regardless of them
886 being declared inline. */
887 flag_inline_functions = 1;
889 /* Basic optimization options. */
894 /* We want to crossjump as much as possible. */
895 maybe_set_param_value (PARAM_MIN_CROSSJUMP_INSNS, 1,
896 opts->x_param_values, opts_set->x_param_values);
899 maybe_set_param_value (PARAM_MIN_CROSSJUMP_INSNS,
900 default_param_value (PARAM_MIN_CROSSJUMP_INSNS),
901 opts->x_param_values, opts_set->x_param_values);
903 /* -Ofast adds optimizations to -O3. */
906 /* Which is -ffast-math for now. */
907 set_fast_math_flags (1);
908 /* Allow targets to enable extra options with -Ofast
909 before general options processing so disabling them
910 again afterwards works. */
911 targetm.handle_ofast ();
914 /* Allow default optimizations to be specified on a per-machine basis. */
915 targetm.target_option.optimization (optimize, optimize_size);
918 static void finish_options (struct gcc_options *, struct gcc_options *);
920 /* Parse command line options and set default flag values. Do minimal
921 options processing. The decoded options are in *DECODED_OPTIONS
922 and *DECODED_OPTIONS_COUNT. */
924 decode_options (struct gcc_options *opts, struct gcc_options *opts_set,
925 struct cl_decoded_option *decoded_options,
926 unsigned int decoded_options_count)
928 struct cl_option_handlers handlers;
930 unsigned int lang_mask;
932 lang_mask = initial_lang_mask;
934 handlers.unknown_option_callback = unknown_option_callback;
935 handlers.wrong_lang_callback = complain_wrong_lang;
936 handlers.post_handling_callback = post_handling_callback;
937 handlers.num_handlers = 3;
938 handlers.handlers[0].handler = lang_handle_option;
939 handlers.handlers[0].mask = lang_mask;
940 handlers.handlers[1].handler = common_handle_option;
941 handlers.handlers[1].mask = CL_COMMON;
942 handlers.handlers[2].handler = target_handle_option;
943 handlers.handlers[2].mask = CL_TARGET;
945 /* Enable -Werror=coverage-mismatch by default */
946 enable_warning_as_error ("coverage-mismatch", 1, lang_mask, &handlers,
949 default_options_optimization (opts, opts_set,
950 decoded_options, decoded_options_count);
953 /* Clear any options currently held for LTO. */
954 lto_clear_user_options ();
957 read_cmdline_options (opts, opts_set,
958 decoded_options, decoded_options_count, lang_mask,
961 finish_options (opts, opts_set);
964 /* After all options have been read into OPTS and OPTS_SET, finalize
965 settings of those options and diagnose incompatible
968 finish_options (struct gcc_options *opts, struct gcc_options *opts_set)
970 static bool first_time_p = true;
971 enum unwind_info_type ui_except;
973 gcc_assert (opts == &global_options);
974 gcc_assert (opts_set = &global_options_set);
976 if (dump_base_name && ! IS_ABSOLUTE_PATH (dump_base_name))
978 /* First try to make DUMP_BASE_NAME relative to the DUMP_DIR_NAME
979 directory. Then try to make DUMP_BASE_NAME relative to the
980 AUX_BASE_NAME directory, typically the directory to contain
983 dump_base_name = concat (dump_dir_name, dump_base_name, NULL);
984 else if (aux_base_name)
986 const char *aux_base;
988 base_of_path (aux_base_name, &aux_base);
989 if (aux_base_name != aux_base)
991 int dir_len = aux_base - aux_base_name;
992 char *new_dump_base_name =
993 XNEWVEC (char, strlen(dump_base_name) + dir_len + 1);
995 /* Copy directory component from AUX_BASE_NAME. */
996 memcpy (new_dump_base_name, aux_base_name, dir_len);
997 /* Append existing DUMP_BASE_NAME. */
998 strcpy (new_dump_base_name + dir_len, dump_base_name);
999 dump_base_name = new_dump_base_name;
1004 /* Handle related options for unit-at-a-time, toplevel-reorder, and
1006 if (!flag_unit_at_a_time)
1008 if (flag_section_anchors && opts_set->x_flag_section_anchors)
1009 error ("Section anchors must be disabled when unit-at-a-time "
1011 flag_section_anchors = 0;
1012 if (flag_toplevel_reorder == 1)
1013 error ("Toplevel reorder must be disabled when unit-at-a-time "
1015 flag_toplevel_reorder = 0;
1018 /* -Wmissing-noreturn is alias for -Wsuggest-attribute=noreturn. */
1019 if (warn_missing_noreturn)
1020 warn_suggest_attribute_noreturn = true;
1022 /* Unless the user has asked for section anchors, we disable toplevel
1023 reordering at -O0 to disable transformations that might be surprising
1024 to end users and to get -fno-toplevel-reorder tested. */
1026 && flag_toplevel_reorder == 2
1027 && !(flag_section_anchors && opts_set->x_flag_section_anchors))
1029 flag_toplevel_reorder = 0;
1030 flag_section_anchors = 0;
1032 if (!flag_toplevel_reorder)
1034 if (flag_section_anchors && opts_set->x_flag_section_anchors)
1035 error ("section anchors must be disabled when toplevel reorder"
1037 flag_section_anchors = 0;
1043 flag_pic = flag_pie;
1044 if (flag_pic && !flag_pie)
1046 first_time_p = false;
1051 /* Inlining does not work if not optimizing,
1052 so force it not to be done. */
1057 /* The optimization to partition hot and cold basic blocks into separate
1058 sections of the .o and executable files does not work (currently)
1059 with exception handling. This is because there is no support for
1060 generating unwind info. If flag_exceptions is turned on we need to
1061 turn off the partitioning optimization. */
1063 ui_except = targetm.except_unwind_info ();
1066 && flag_reorder_blocks_and_partition
1067 && (ui_except == UI_SJLJ || ui_except == UI_TARGET))
1069 inform (input_location,
1070 "-freorder-blocks-and-partition does not work "
1071 "with exceptions on this architecture");
1072 flag_reorder_blocks_and_partition = 0;
1073 flag_reorder_blocks = 1;
1076 /* If user requested unwind info, then turn off the partitioning
1079 if (flag_unwind_tables
1080 && !targetm.unwind_tables_default
1081 && flag_reorder_blocks_and_partition
1082 && (ui_except == UI_SJLJ || ui_except == UI_TARGET))
1084 inform (input_location,
1085 "-freorder-blocks-and-partition does not support "
1086 "unwind info on this architecture");
1087 flag_reorder_blocks_and_partition = 0;
1088 flag_reorder_blocks = 1;
1091 /* If the target requested unwind info, then turn off the partitioning
1092 optimization with a different message. Likewise, if the target does not
1093 support named sections. */
1095 if (flag_reorder_blocks_and_partition
1096 && (!targetm.have_named_sections
1097 || (flag_unwind_tables
1098 && targetm.unwind_tables_default
1099 && (ui_except == UI_SJLJ || ui_except == UI_TARGET))))
1101 inform (input_location,
1102 "-freorder-blocks-and-partition does not work "
1103 "on this architecture");
1104 flag_reorder_blocks_and_partition = 0;
1105 flag_reorder_blocks = 1;
1108 /* Pipelining of outer loops is only possible when general pipelining
1109 capabilities are requested. */
1110 if (!flag_sel_sched_pipelining)
1111 flag_sel_sched_pipelining_outer_loops = 0;
1113 if (!targetm.ira_cover_classes
1114 && flag_ira_algorithm == IRA_ALGORITHM_CB)
1116 inform (input_location,
1117 "-fira-algorithm=CB does not work on this architecture");
1118 flag_ira_algorithm = IRA_ALGORITHM_PRIORITY;
1121 if (flag_conserve_stack)
1123 maybe_set_param_value (PARAM_LARGE_STACK_FRAME, 100,
1124 opts->x_param_values, opts_set->x_param_values);
1125 maybe_set_param_value (PARAM_STACK_FRAME_GROWTH, 40,
1126 opts->x_param_values, opts_set->x_param_values);
1128 if (flag_wpa || flag_ltrans)
1130 /* These passes are not WHOPR compatible yet. */
1132 flag_ipa_struct_reorg = 0;
1135 if (flag_lto || flag_whopr)
1138 flag_generate_lto = 1;
1140 /* When generating IL, do not operate in whole-program mode.
1141 Otherwise, symbols will be privatized too early, causing link
1143 flag_whole_program = 0;
1145 error ("LTO support has not been enabled in this configuration");
1148 if (flag_lto_partition_balanced || flag_lto_partition_1to1)
1150 if (flag_lto_partition_balanced && flag_lto_partition_1to1)
1151 error ("Only one -flto-partitoin value can be specified");
1153 error ("-flto-partitoin has effect only with -fwhopr");
1156 /* Reconcile -flto and -fwhopr. Set additional flags as appropriate and
1157 check option consistency. */
1158 if (flag_lto && flag_whopr)
1159 error ("-flto and -fwhopr are mutually exclusive");
1161 /* We initialize flag_split_stack to -1 so that targets can set a
1162 default value if they choose based on other options. */
1163 if (flag_split_stack == -1)
1164 flag_split_stack = 0;
1165 else if (flag_split_stack)
1167 if (!targetm.supports_split_stack (true))
1169 error ("%<-fsplit-stack%> is not supported by "
1170 "this compiler configuration");
1171 flag_split_stack = 0;
1176 #define LEFT_COLUMN 27
1178 /* Output ITEM, of length ITEM_WIDTH, in the left column,
1179 followed by word-wrapped HELP in a second column. */
1181 wrap_help (const char *help,
1183 unsigned int item_width,
1184 unsigned int columns)
1186 unsigned int col_width = LEFT_COLUMN;
1187 unsigned int remaining, room, len;
1189 remaining = strlen (help);
1193 room = columns - 3 - MAX (col_width, item_width);
1202 for (i = 0; help[i]; i++)
1204 if (i >= room && len != remaining)
1208 else if ((help[i] == '-' || help[i] == '/')
1209 && help[i + 1] != ' '
1210 && i > 0 && ISALPHA (help[i - 1]))
1215 printf( " %-*.*s %.*s\n", col_width, item_width, item, len, help);
1217 while (help[len] == ' ')
1225 /* Print help for a specific front-end, etc. */
1227 print_filtered_help (unsigned int include_flags,
1228 unsigned int exclude_flags,
1229 unsigned int any_flags,
1230 unsigned int columns)
1234 static char *printed = NULL;
1236 bool displayed = false;
1238 if (include_flags == CL_PARAMS)
1240 for (i = 0; i < LAST_PARAM; i++)
1242 const char *param = compiler_params[i].option;
1244 help = compiler_params[i].help;
1245 if (help == NULL || *help == '\0')
1247 if (exclude_flags & CL_UNDOCUMENTED)
1249 help = undocumented_msg;
1252 /* Get the translation. */
1255 wrap_help (help, param, strlen (param), columns);
1262 printed = XCNEWVAR (char, cl_options_count);
1264 for (i = 0; i < cl_options_count; i++)
1266 static char new_help[128];
1267 const struct cl_option *option = cl_options + i;
1272 if (include_flags == 0
1273 || ((option->flags & include_flags) != include_flags))
1275 if ((option->flags & any_flags) == 0)
1279 /* Skip unwanted switches. */
1280 if ((option->flags & exclude_flags) != 0)
1283 /* The driver currently prints its own help text. */
1284 if ((option->flags & CL_DRIVER) != 0
1285 && (option->flags & (((1U << cl_lang_count) - 1)
1286 | CL_COMMON | CL_TARGET)) == 0)
1290 /* Skip switches that have already been printed. */
1296 help = option->help;
1299 if (exclude_flags & CL_UNDOCUMENTED)
1301 help = undocumented_msg;
1304 /* Get the translation. */
1307 /* Find the gap between the name of the
1308 option and its descriptive text. */
1309 tab = strchr (help, '\t');
1318 opt = option->opt_text;
1322 /* With the -Q option enabled we change the descriptive text associated
1323 with an option to be an indication of its current setting. */
1326 void *flag_var = option_flag_var (i, &global_options);
1328 if (len < (LEFT_COLUMN + 2))
1329 strcpy (new_help, "\t\t");
1331 strcpy (new_help, "\t");
1333 if (flag_var != NULL)
1335 if (option->flags & CL_JOINED)
1337 if (option->var_type == CLVC_STRING)
1339 if (* (const char **) flag_var != NULL)
1340 snprintf (new_help + strlen (new_help),
1341 sizeof (new_help) - strlen (new_help),
1342 * (const char **) flag_var);
1345 sprintf (new_help + strlen (new_help),
1346 "%#x", * (int *) flag_var);
1349 strcat (new_help, option_enabled (i, &global_options)
1350 ? _("[enabled]") : _("[disabled]"));
1356 wrap_help (help, opt, len, columns);
1362 unsigned int langs = include_flags & CL_LANG_ALL;
1365 printf (_(" No options with the desired characteristics were found\n"));
1370 /* PR 31349: Tell the user how to see all of the
1371 options supported by a specific front end. */
1372 for (i = 0; (1U << i) < CL_LANG_ALL; i ++)
1373 if ((1U << i) & langs)
1374 printf (_(" None found. Use --help=%s to show *all* the options supported by the %s front-end\n"),
1375 lang_names[i], lang_names[i]);
1379 else if (! displayed)
1380 printf (_(" All options with the desired characteristics have already been displayed\n"));
1385 /* Display help for a specified type of option.
1386 The options must have ALL of the INCLUDE_FLAGS set
1387 ANY of the flags in the ANY_FLAGS set
1388 and NONE of the EXCLUDE_FLAGS set. */
1390 print_specific_help (unsigned int include_flags,
1391 unsigned int exclude_flags,
1392 unsigned int any_flags)
1394 unsigned int all_langs_mask = (1U << cl_lang_count) - 1;
1395 const char * description = NULL;
1396 const char * descrip_extra = "";
1399 static unsigned int columns = 0;
1401 /* Sanity check: Make sure that we do not have more
1402 languages than we have bits available to enumerate them. */
1403 gcc_assert ((1U << cl_lang_count) < CL_MIN_OPTION_CLASS);
1405 /* If we have not done so already, obtain
1406 the desired maximum width of the output. */
1411 GET_ENVIRONMENT (p, "COLUMNS");
1414 int value = atoi (p);
1421 /* Use a reasonable default. */
1425 /* Decide upon the title for the options that we are going to display. */
1426 for (i = 0, flag = 1; flag <= CL_MAX_OPTION_CLASS; flag <<= 1, i ++)
1428 switch (flag & include_flags)
1435 description = _("The following options are target specific");
1438 description = _("The following options control compiler warning messages");
1440 case CL_OPTIMIZATION:
1441 description = _("The following options control optimizations");
1444 description = _("The following options are language-independent");
1447 description = _("The --param option recognizes the following as parameters");
1450 if (i >= cl_lang_count)
1452 if (exclude_flags & all_langs_mask)
1453 description = _("The following options are specific to just the language ");
1455 description = _("The following options are supported by the language ");
1456 descrip_extra = lang_names [i];
1461 if (description == NULL)
1465 if (include_flags & CL_UNDOCUMENTED)
1466 description = _("The following options are not documented");
1467 else if (include_flags & CL_SEPARATE)
1468 description = _("The following options take separate arguments");
1469 else if (include_flags & CL_JOINED)
1470 description = _("The following options take joined arguments");
1473 internal_error ("unrecognized include_flags 0x%x passed to print_specific_help",
1480 if (any_flags & all_langs_mask)
1481 description = _("The following options are language-related");
1483 description = _("The following options are language-independent");
1487 printf ("%s%s:\n", description, descrip_extra);
1488 print_filtered_help (include_flags, exclude_flags, any_flags, columns);
1491 /* Handle target- and language-independent options. Return zero to
1492 generate an "unknown option" message. Only options that need
1493 extra handling need to be listed here; if you simply want
1494 DECODED->value assigned to a variable, it happens automatically. */
1497 common_handle_option (struct gcc_options *opts,
1498 struct gcc_options *opts_set,
1499 const struct cl_decoded_option *decoded,
1500 unsigned int lang_mask, int kind ATTRIBUTE_UNUSED,
1501 const struct cl_option_handlers *handlers)
1503 size_t scode = decoded->opt_index;
1504 const char *arg = decoded->arg;
1505 int value = decoded->value;
1506 static bool verbose = false;
1507 enum opt_code code = (enum opt_code) scode;
1509 gcc_assert (opts == &global_options);
1510 gcc_assert (opts_set == &global_options_set);
1511 gcc_assert (decoded->canonical_option_num_elements <= 2);
1516 handle_param (opts, opts_set, arg);
1525 unsigned int all_langs_mask = (1U << cl_lang_count) - 1;
1526 unsigned int undoc_mask;
1529 undoc_mask = (verbose | extra_warnings) ? 0 : CL_UNDOCUMENTED;
1530 /* First display any single language specific options. */
1531 for (i = 0; i < cl_lang_count; i++)
1533 (1U << i, (all_langs_mask & (~ (1U << i))) | undoc_mask, 0);
1534 /* Next display any multi language specific options. */
1535 print_specific_help (0, undoc_mask, all_langs_mask);
1536 /* Then display any remaining, non-language options. */
1537 for (i = CL_MIN_OPTION_CLASS; i <= CL_MAX_OPTION_CLASS; i <<= 1)
1539 print_specific_help (i, undoc_mask, 0);
1540 exit_after_options = true;
1544 case OPT__target_help:
1545 print_specific_help (CL_TARGET, CL_UNDOCUMENTED, 0);
1546 exit_after_options = true;
1548 /* Allow the target a chance to give the user some additional information. */
1555 const char * a = arg;
1556 unsigned int include_flags = 0;
1557 /* Note - by default we include undocumented options when listing
1558 specific classes. If you only want to see documented options
1559 then add ",^undocumented" to the --help= option. E.g.:
1561 --help=target,^undocumented */
1562 unsigned int exclude_flags = 0;
1564 /* Walk along the argument string, parsing each word in turn.
1566 arg = [^]{word}[,{arg}]
1567 word = {optimizers|target|warnings|undocumented|
1568 params|common|<language>} */
1573 const char * string;
1578 { "optimizers", CL_OPTIMIZATION },
1579 { "target", CL_TARGET },
1580 { "warnings", CL_WARNING },
1581 { "undocumented", CL_UNDOCUMENTED },
1582 { "params", CL_PARAMS },
1583 { "joined", CL_JOINED },
1584 { "separate", CL_SEPARATE },
1585 { "common", CL_COMMON },
1588 unsigned int * pflags;
1590 unsigned int lang_flag, specific_flag;
1597 pflags = & exclude_flags;
1600 pflags = & include_flags;
1602 comma = strchr (a, ',');
1613 /* Check to see if the string matches an option class name. */
1614 for (i = 0, specific_flag = 0; specifics[i].string != NULL; i++)
1615 if (strncasecmp (a, specifics[i].string, len) == 0)
1617 specific_flag = specifics[i].flag;
1621 /* Check to see if the string matches a language name.
1622 Note - we rely upon the alpha-sorted nature of the entries in
1623 the lang_names array, specifically that shorter names appear
1624 before their longer variants. (i.e. C before C++). That way
1625 when we are attempting to match --help=c for example we will
1626 match with C first and not C++. */
1627 for (i = 0, lang_flag = 0; i < cl_lang_count; i++)
1628 if (strncasecmp (a, lang_names[i], len) == 0)
1630 lang_flag = 1U << i;
1634 if (specific_flag != 0)
1637 * pflags |= specific_flag;
1640 /* The option's argument matches both the start of a
1641 language name and the start of an option class name.
1642 We have a special case for when the user has
1643 specified "--help=c", but otherwise we have to issue
1645 if (strncasecmp (a, "c", len) == 0)
1646 * pflags |= lang_flag;
1649 "warning: --help argument %.*s is ambiguous, please be more specific\n",
1653 else if (lang_flag != 0)
1654 * pflags |= lang_flag;
1657 "warning: unrecognized argument to --help= option: %.*s\n",
1666 print_specific_help (include_flags, exclude_flags, 0);
1667 exit_after_options = true;
1672 exit_after_options = true;
1678 /* Currently handled in a prescan. */
1682 enable_warning_as_error (arg, value, lang_mask, handlers, global_dc);
1685 case OPT_Wlarger_than_:
1686 larger_than_size = value;
1687 warn_larger_than = value != -1;
1690 case OPT_Wfatal_errors:
1691 global_dc->fatal_errors = value;
1694 case OPT_Wframe_larger_than_:
1695 frame_larger_than_size = value;
1696 warn_frame_larger_than = value != -1;
1699 case OPT_Wstrict_aliasing:
1700 set_Wstrict_aliasing (value);
1703 case OPT_Wstrict_aliasing_:
1704 warn_strict_aliasing = value;
1707 case OPT_Wstrict_overflow:
1708 warn_strict_overflow = (value
1709 ? (int) WARN_STRICT_OVERFLOW_CONDITIONAL
1713 case OPT_Wstrict_overflow_:
1714 warn_strict_overflow = value;
1717 case OPT_Wsystem_headers:
1718 global_dc->dc_warn_system_headers = value;
1722 warn_unused = value;
1726 aux_info_file_name = arg;
1727 flag_gen_aux_info = 1;
1731 aux_base_name = arg;
1734 case OPT_auxbase_strip:
1736 char *tmp = xstrdup (arg);
1737 strip_off_ending (tmp, strlen (tmp));
1739 aux_base_name = tmp;
1744 decode_d_option (arg);
1748 dump_base_name = arg;
1752 dump_dir_name = arg;
1755 case OPT_falign_functions_:
1756 align_functions = value;
1759 case OPT_falign_jumps_:
1760 align_jumps = value;
1763 case OPT_falign_labels_:
1764 align_labels = value;
1767 case OPT_falign_loops_:
1768 align_loops = value;
1771 case OPT_fcall_used_:
1772 fix_register (arg, 0, 1);
1775 case OPT_fcall_saved_:
1776 fix_register (arg, 0, 0);
1779 case OPT_fcompare_debug_second:
1780 flag_compare_debug = value;
1784 dbg_cnt_process_opt (arg);
1787 case OPT_fdbg_cnt_list:
1788 dbg_cnt_list_all_counters ();
1791 case OPT_fdebug_prefix_map_:
1792 add_debug_prefix_map (arg);
1795 case OPT_fdiagnostics_show_location_:
1796 if (!strcmp (arg, "once"))
1797 diagnostic_prefixing_rule (global_dc) = DIAGNOSTICS_SHOW_PREFIX_ONCE;
1798 else if (!strcmp (arg, "every-line"))
1799 diagnostic_prefixing_rule (global_dc)
1800 = DIAGNOSTICS_SHOW_PREFIX_EVERY_LINE;
1805 case OPT_fdiagnostics_show_option:
1806 global_dc->show_option_requested = value;
1810 if (!dump_switch_p (arg))
1814 case OPT_fexcess_precision_:
1815 if (!strcmp (arg, "fast"))
1816 flag_excess_precision_cmdline = EXCESS_PRECISION_FAST;
1817 else if (!strcmp (arg, "standard"))
1818 flag_excess_precision_cmdline = EXCESS_PRECISION_STANDARD;
1820 error ("unknown excess precision style \"%s\"", arg);
1823 case OPT_ffast_math:
1824 set_fast_math_flags (value);
1827 case OPT_funsafe_math_optimizations:
1828 set_unsafe_math_optimizations_flags (value);
1832 fix_register (arg, 1, 1);
1835 case OPT_finline_limit_:
1836 set_param_value ("max-inline-insns-single", value / 2,
1837 opts->x_param_values, opts_set->x_param_values);
1838 set_param_value ("max-inline-insns-auto", value / 2,
1839 opts->x_param_values, opts_set->x_param_values);
1842 case OPT_finstrument_functions_exclude_function_list_:
1843 add_comma_separated_to_vector
1844 (&flag_instrument_functions_exclude_functions, arg);
1847 case OPT_finstrument_functions_exclude_file_list_:
1848 add_comma_separated_to_vector
1849 (&flag_instrument_functions_exclude_files, arg);
1852 case OPT_fmessage_length_:
1853 pp_set_line_maximum_length (global_dc->printer, value);
1856 case OPT_fpack_struct_:
1857 if (value <= 0 || (value & (value - 1)) || value > 16)
1858 error ("structure alignment must be a small power of two, not %d", value);
1861 initial_max_fld_align = value;
1862 maximum_field_alignment = value * BITS_PER_UNIT;
1867 #ifdef ENABLE_PLUGIN
1868 add_new_plugin (arg);
1870 error ("Plugin support is disabled. Configure with --enable-plugin.");
1874 case OPT_fplugin_arg_:
1875 #ifdef ENABLE_PLUGIN
1876 parse_plugin_arg_opt (arg);
1878 error ("Plugin support is disabled. Configure with --enable-plugin.");
1882 case OPT_fprofile_dir_:
1883 profile_data_prefix = xstrdup (arg);
1886 case OPT_fprofile_use_:
1887 profile_data_prefix = xstrdup (arg);
1888 flag_profile_use = true;
1890 /* No break here - do -fprofile-use processing. */
1891 case OPT_fprofile_use:
1892 if (!opts_set->x_flag_branch_probabilities)
1893 flag_branch_probabilities = value;
1894 if (!opts_set->x_flag_profile_values)
1895 flag_profile_values = value;
1896 if (!opts_set->x_flag_unroll_loops)
1897 flag_unroll_loops = value;
1898 if (!opts_set->x_flag_peel_loops)
1899 flag_peel_loops = value;
1900 if (!opts_set->x_flag_tracer)
1901 flag_tracer = value;
1902 if (!opts_set->x_flag_value_profile_transformations)
1903 flag_value_profile_transformations = value;
1904 if (!opts_set->x_flag_inline_functions)
1905 flag_inline_functions = value;
1906 if (!opts_set->x_flag_ipa_cp)
1907 flag_ipa_cp = value;
1908 if (!opts_set->x_flag_ipa_cp_clone
1909 && value && flag_ipa_cp)
1910 flag_ipa_cp_clone = value;
1911 if (!opts_set->x_flag_predictive_commoning)
1912 flag_predictive_commoning = value;
1913 if (!opts_set->x_flag_unswitch_loops)
1914 flag_unswitch_loops = value;
1915 if (!opts_set->x_flag_gcse_after_reload)
1916 flag_gcse_after_reload = value;
1919 case OPT_fprofile_generate_:
1920 profile_data_prefix = xstrdup (arg);
1922 /* No break here - do -fprofile-generate processing. */
1923 case OPT_fprofile_generate:
1924 if (!opts_set->x_profile_arc_flag)
1925 profile_arc_flag = value;
1926 if (!opts_set->x_flag_profile_values)
1927 flag_profile_values = value;
1928 if (!opts_set->x_flag_value_profile_transformations)
1929 flag_value_profile_transformations = value;
1930 if (!opts_set->x_flag_inline_functions)
1931 flag_inline_functions = value;
1934 case OPT_fshow_column:
1935 global_dc->show_column = value;
1938 case OPT_fvisibility_:
1940 if (!strcmp(arg, "default"))
1941 default_visibility = VISIBILITY_DEFAULT;
1942 else if (!strcmp(arg, "internal"))
1943 default_visibility = VISIBILITY_INTERNAL;
1944 else if (!strcmp(arg, "hidden"))
1945 default_visibility = VISIBILITY_HIDDEN;
1946 else if (!strcmp(arg, "protected"))
1947 default_visibility = VISIBILITY_PROTECTED;
1949 error ("unrecognized visibility value \"%s\"", arg);
1953 case OPT_frandom_seed:
1954 /* The real switch is -fno-random-seed. */
1957 set_random_seed (NULL);
1960 case OPT_frandom_seed_:
1961 set_random_seed (arg);
1964 case OPT_fsched_verbose_:
1965 #ifdef INSN_SCHEDULING
1966 fix_sched_param ("verbose", arg);
1972 case OPT_fsched_stalled_insns_:
1973 flag_sched_stalled_insns = value;
1974 if (flag_sched_stalled_insns == 0)
1975 flag_sched_stalled_insns = -1;
1978 case OPT_fsched_stalled_insns_dep_:
1979 flag_sched_stalled_insns_dep = value;
1982 case OPT_fstack_check_:
1983 if (!strcmp (arg, "no"))
1984 flag_stack_check = NO_STACK_CHECK;
1985 else if (!strcmp (arg, "generic"))
1986 /* This is the old stack checking method. */
1987 flag_stack_check = STACK_CHECK_BUILTIN
1988 ? FULL_BUILTIN_STACK_CHECK
1989 : GENERIC_STACK_CHECK;
1990 else if (!strcmp (arg, "specific"))
1991 /* This is the new stack checking method. */
1992 flag_stack_check = STACK_CHECK_BUILTIN
1993 ? FULL_BUILTIN_STACK_CHECK
1994 : STACK_CHECK_STATIC_BUILTIN
1995 ? STATIC_BUILTIN_STACK_CHECK
1996 : GENERIC_STACK_CHECK;
1998 warning (0, "unknown stack check parameter \"%s\"", arg);
2001 case OPT_fstack_limit:
2002 /* The real switch is -fno-stack-limit. */
2005 stack_limit_rtx = NULL_RTX;
2008 case OPT_fstack_limit_register_:
2010 int reg = decode_reg_name (arg);
2012 error ("unrecognized register name \"%s\"", arg);
2014 stack_limit_rtx = gen_rtx_REG (Pmode, reg);
2018 case OPT_fstack_limit_symbol_:
2019 stack_limit_rtx = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (arg));
2022 case OPT_ftree_vectorizer_verbose_:
2023 vect_set_verbosity_level (arg);
2026 case OPT_ftls_model_:
2027 if (!strcmp (arg, "global-dynamic"))
2028 flag_tls_default = TLS_MODEL_GLOBAL_DYNAMIC;
2029 else if (!strcmp (arg, "local-dynamic"))
2030 flag_tls_default = TLS_MODEL_LOCAL_DYNAMIC;
2031 else if (!strcmp (arg, "initial-exec"))
2032 flag_tls_default = TLS_MODEL_INITIAL_EXEC;
2033 else if (!strcmp (arg, "local-exec"))
2034 flag_tls_default = TLS_MODEL_LOCAL_EXEC;
2036 warning (0, "unknown tls-model \"%s\"", arg);
2039 case OPT_fira_algorithm_:
2040 if (!strcmp (arg, "CB"))
2041 flag_ira_algorithm = IRA_ALGORITHM_CB;
2042 else if (!strcmp (arg, "priority"))
2043 flag_ira_algorithm = IRA_ALGORITHM_PRIORITY;
2045 warning (0, "unknown ira algorithm \"%s\"", arg);
2048 case OPT_fira_region_:
2049 if (!strcmp (arg, "one"))
2050 flag_ira_region = IRA_REGION_ONE;
2051 else if (!strcmp (arg, "all"))
2052 flag_ira_region = IRA_REGION_ALL;
2053 else if (!strcmp (arg, "mixed"))
2054 flag_ira_region = IRA_REGION_MIXED;
2056 warning (0, "unknown ira region \"%s\"", arg);
2059 case OPT_fira_verbose_:
2060 flag_ira_verbose = value;
2064 set_debug_level (NO_DEBUG, DEFAULT_GDB_EXTENSIONS, arg);
2068 set_debug_level (SDB_DEBUG, false, arg);
2072 if (value < 2 || value > 4)
2073 error ("dwarf version %d is not supported", value);
2075 dwarf_version = value;
2076 set_debug_level (DWARF2_DEBUG, false, "");
2080 set_debug_level (NO_DEBUG, 2, arg);
2085 set_debug_level (DBX_DEBUG, code == OPT_gstabs_, arg);
2089 set_debug_level (VMS_DEBUG, false, arg);
2094 set_debug_level (XCOFF_DEBUG, code == OPT_gxcoff_, arg);
2098 asm_file_name = arg;
2101 case OPT_pedantic_errors:
2102 flag_pedantic_errors = pedantic = 1;
2103 global_dc->pedantic_errors = 1;
2115 global_dc->dc_inhibit_warnings = true;
2118 case OPT_fuse_linker_plugin:
2119 /* No-op. Used by the driver and passed to us because it starts with f.*/
2123 /* If the flag was handled in a standard way, assume the lack of
2124 processing here is intentional. */
2125 gcc_assert (option_flag_var (scode, opts));
2132 /* Handle --param NAME=VALUE. */
2134 handle_param (struct gcc_options *opts, struct gcc_options *opts_set,
2140 arg = xstrdup (carg);
2141 equal = strchr (arg, '=');
2143 error ("%s: --param arguments should be of the form NAME=VALUE", arg);
2146 value = integral_argument (equal + 1);
2148 error ("invalid --param value %qs", equal + 1);
2152 set_param_value (arg, value,
2153 opts->x_param_values, opts_set->x_param_values);
2160 /* Used to set the level of strict aliasing warnings,
2161 when no level is specified (i.e., when -Wstrict-aliasing, and not
2162 -Wstrict-aliasing=level was given).
2163 ONOFF is assumed to take value 1 when -Wstrict-aliasing is specified,
2164 and 0 otherwise. After calling this function, wstrict_aliasing will be
2165 set to the default value of -Wstrict_aliasing=level, currently 3. */
2167 set_Wstrict_aliasing (int onoff)
2169 gcc_assert (onoff == 0 || onoff == 1);
2171 warn_strict_aliasing = 3;
2173 warn_strict_aliasing = 0;
2176 /* The following routines are useful in setting all the flags that
2177 -ffast-math and -fno-fast-math imply. */
2179 set_fast_math_flags (int set)
2181 flag_unsafe_math_optimizations = set;
2182 set_unsafe_math_optimizations_flags (set);
2183 flag_finite_math_only = set;
2184 flag_errno_math = !set;
2187 flag_signaling_nans = 0;
2188 flag_rounding_math = 0;
2189 flag_cx_limited_range = 1;
2193 /* When -funsafe-math-optimizations is set the following
2194 flags are set as well. */
2196 set_unsafe_math_optimizations_flags (int set)
2198 flag_trapping_math = !set;
2199 flag_signed_zeros = !set;
2200 flag_associative_math = set;
2201 flag_reciprocal_math = set;
2204 /* Return true iff flags are set as if -ffast-math. */
2206 fast_math_flags_set_p (void)
2208 return (!flag_trapping_math
2209 && flag_unsafe_math_optimizations
2210 && flag_finite_math_only
2211 && !flag_signed_zeros
2212 && !flag_errno_math);
2215 /* Return true iff flags are set as if -ffast-math but using the flags stored
2216 in the struct cl_optimization structure. */
2218 fast_math_flags_struct_set_p (struct cl_optimization *opt)
2220 return (!opt->x_flag_trapping_math
2221 && opt->x_flag_unsafe_math_optimizations
2222 && opt->x_flag_finite_math_only
2223 && !opt->x_flag_signed_zeros
2224 && !opt->x_flag_errno_math);
2227 /* Handle a debug output -g switch. EXTENDED is true or false to support
2228 extended output (2 is special and means "-ggdb" was given). */
2230 set_debug_level (enum debug_info_type type, int extended, const char *arg)
2232 static bool type_explicit;
2234 use_gnu_debug_info_extensions = extended;
2236 if (type == NO_DEBUG)
2238 if (write_symbols == NO_DEBUG)
2240 write_symbols = PREFERRED_DEBUGGING_TYPE;
2244 #ifdef DWARF2_DEBUGGING_INFO
2245 write_symbols = DWARF2_DEBUG;
2246 #elif defined DBX_DEBUGGING_INFO
2247 write_symbols = DBX_DEBUG;
2251 if (write_symbols == NO_DEBUG)
2252 warning (0, "target system does not support debug output");
2257 /* Does it conflict with an already selected type? */
2258 if (type_explicit && write_symbols != NO_DEBUG && type != write_symbols)
2259 error ("debug format \"%s\" conflicts with prior selection",
2260 debug_type_names[type]);
2261 write_symbols = type;
2262 type_explicit = true;
2265 /* A debug flag without a level defaults to level 2. */
2268 if (!debug_info_level)
2269 debug_info_level = DINFO_LEVEL_NORMAL;
2273 int argval = integral_argument (arg);
2275 error ("unrecognised debug output level \"%s\"", arg);
2276 else if (argval > 3)
2277 error ("debug output level %s is too high", arg);
2279 debug_info_level = (enum debug_info_level) argval;
2283 /* Return 1 if option OPT_IDX is enabled in OPTS, 0 if it is disabled,
2284 or -1 if it isn't a simple on-off switch. */
2287 option_enabled (int opt_idx, void *opts)
2289 const struct cl_option *option = &(cl_options[opt_idx]);
2290 struct gcc_options *optsg = (struct gcc_options *) opts;
2291 void *flag_var = option_flag_var (opt_idx, optsg);
2294 switch (option->var_type)
2297 return *(int *) flag_var != 0;
2300 return *(int *) flag_var == option->var_value;
2302 case CLVC_BIT_CLEAR:
2303 return (*(int *) flag_var & option->var_value) == 0;
2306 return (*(int *) flag_var & option->var_value) != 0;
2314 /* Fill STATE with the current state of option OPTION in OPTS. Return
2315 true if there is some state to store. */
2318 get_option_state (struct gcc_options *opts, int option,
2319 struct cl_option_state *state)
2321 void *flag_var = option_flag_var (option, opts);
2326 switch (cl_options[option].var_type)
2330 state->data = flag_var;
2331 state->size = sizeof (int);
2334 case CLVC_BIT_CLEAR:
2336 state->ch = option_enabled (option, opts);
2337 state->data = &state->ch;
2342 state->data = *(const char **) flag_var;
2343 if (state->data == 0)
2345 state->size = strlen ((const char *) state->data) + 1;
2351 /* Callback function, called when -Werror= enables a warning. */
2353 static void (*warning_as_error_callback) (int) = NULL;
2355 /* Register a callback for enable_warning_as_error calls. */
2358 register_warning_as_error_callback (void (*callback) (int))
2360 gcc_assert (warning_as_error_callback == NULL || callback == NULL);
2361 warning_as_error_callback = callback;
2364 /* Enable (or disable if VALUE is 0) a warning option ARG (language
2365 mask LANG_MASK, option handlers HANDLERS) as an error for
2366 diagnostic context DC (possibly NULL). This is used by
2370 enable_warning_as_error (const char *arg, int value, unsigned int lang_mask,
2371 const struct cl_option_handlers *handlers,
2372 diagnostic_context *dc)
2377 new_option = XNEWVEC (char, strlen (arg) + 2);
2378 new_option[0] = 'W';
2379 strcpy (new_option + 1, arg);
2380 option_index = find_opt (new_option, lang_mask);
2381 if (option_index == OPT_SPECIAL_unknown)
2383 error ("-Werror=%s: No option -%s", arg, new_option);
2387 const struct cl_option *option = &cl_options[option_index];
2388 const diagnostic_t kind = value ? DK_ERROR : DK_WARNING;
2390 if (option->alias_target != N_OPTS)
2391 option_index = option->alias_target;
2392 if (option_index == OPT_SPECIAL_ignore)
2395 diagnostic_classify_diagnostic (dc, option_index, kind,
2397 if (kind == DK_ERROR)
2399 const struct cl_option * const option = cl_options + option_index;
2401 /* -Werror=foo implies -Wfoo. */
2402 if (option->var_type == CLVC_BOOLEAN)
2403 handle_generated_option (&global_options, &global_options_set,
2404 option_index, NULL, value, lang_mask,
2405 (int)kind, handlers,
2408 if (warning_as_error_callback)
2409 warning_as_error_callback (option_index);
2415 /* Return malloced memory for the name of the option OPTION_INDEX
2416 which enabled a diagnostic (context CONTEXT), originally of type
2417 ORIG_DIAG_KIND but possibly converted to DIAG_KIND by options such
2421 option_name (diagnostic_context *context, int option_index,
2422 diagnostic_t orig_diag_kind, diagnostic_t diag_kind)
2426 /* A warning classified as an error. */
2427 if ((orig_diag_kind == DK_WARNING || orig_diag_kind == DK_PEDWARN)
2428 && diag_kind == DK_ERROR)
2429 return concat (cl_options[OPT_Werror_].opt_text,
2430 /* Skip over "-W". */
2431 cl_options[option_index].opt_text + 2,
2433 /* A warning with option. */
2435 return xstrdup (cl_options[option_index].opt_text);
2437 /* A warning without option classified as an error. */
2438 else if (orig_diag_kind == DK_WARNING || orig_diag_kind == DK_PEDWARN
2439 || diag_kind == DK_WARNING)
2441 if (context->warning_as_error_requested)
2442 return xstrdup (cl_options[OPT_Werror].opt_text);
2444 return xstrdup (_("enabled by default"));