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"
29 #include "langhooks.h"
35 #include "diagnostic.h"
36 #include "opts-diagnostic.h"
37 #include "insn-attr.h" /* For INSN_SCHEDULING. */
42 #include "lto-streamer.h"
44 /* True if we should exit after parsing options. */
45 bool exit_after_options;
47 /* Type(s) of debugging information we are producing (if any). See
48 flags.h for the definitions of the different possible types of
49 debugging information. */
50 enum debug_info_type write_symbols = NO_DEBUG;
52 /* Level of debugging information we are producing. See flags.h for
53 the definitions of the different possible levels. */
54 enum debug_info_level debug_info_level = DINFO_LEVEL_NONE;
56 /* Run the second compilation of -fcompare-debug. Not defined using
57 Var in common.opt because this is used in Ada code and so must be
58 an actual variable not a macro. */
59 int flag_compare_debug;
61 /* Parse the -femit-struct-debug-detailed option value
62 and set the flag variables. */
64 #define MATCH( prefix, string ) \
65 ((strncmp (prefix, string, sizeof prefix - 1) == 0) \
66 ? ((string += sizeof prefix - 1), 1) : 0)
69 set_struct_debug_option (struct gcc_options *opts, const char *spec)
71 /* various labels for comparison */
72 static char dfn_lbl[] = "dfn:", dir_lbl[] = "dir:", ind_lbl[] = "ind:";
73 static char ord_lbl[] = "ord:", gen_lbl[] = "gen:";
74 static char none_lbl[] = "none", any_lbl[] = "any";
75 static char base_lbl[] = "base", sys_lbl[] = "sys";
77 enum debug_struct_file files = DINFO_STRUCT_FILE_ANY;
78 /* Default is to apply to as much as possible. */
79 enum debug_info_usage usage = DINFO_USAGE_NUM_ENUMS;
83 if (MATCH (dfn_lbl, spec))
84 usage = DINFO_USAGE_DFN;
85 else if (MATCH (dir_lbl, spec))
86 usage = DINFO_USAGE_DIR_USE;
87 else if (MATCH (ind_lbl, spec))
88 usage = DINFO_USAGE_IND_USE;
90 /* Generics or not? */
91 if (MATCH (ord_lbl, spec))
93 else if (MATCH (gen_lbl, spec))
96 /* What allowable environment? */
97 if (MATCH (none_lbl, spec))
98 files = DINFO_STRUCT_FILE_NONE;
99 else if (MATCH (any_lbl, spec))
100 files = DINFO_STRUCT_FILE_ANY;
101 else if (MATCH (sys_lbl, spec))
102 files = DINFO_STRUCT_FILE_SYS;
103 else if (MATCH (base_lbl, spec))
104 files = DINFO_STRUCT_FILE_BASE;
106 error ("argument %qs to %<-femit-struct-debug-detailed%> not recognized",
109 /* Effect the specification. */
110 if (usage == DINFO_USAGE_NUM_ENUMS)
114 opts->x_debug_struct_ordinary[DINFO_USAGE_DFN] = files;
115 opts->x_debug_struct_ordinary[DINFO_USAGE_DIR_USE] = files;
116 opts->x_debug_struct_ordinary[DINFO_USAGE_IND_USE] = files;
120 opts->x_debug_struct_generic[DINFO_USAGE_DFN] = files;
121 opts->x_debug_struct_generic[DINFO_USAGE_DIR_USE] = files;
122 opts->x_debug_struct_generic[DINFO_USAGE_IND_USE] = files;
128 opts->x_debug_struct_ordinary[usage] = files;
130 opts->x_debug_struct_generic[usage] = files;
134 set_struct_debug_option (opts, spec+1);
137 /* No more -femit-struct-debug-detailed specifications.
140 error ("argument %qs to %<-femit-struct-debug-detailed%> unknown",
142 if (opts->x_debug_struct_ordinary[DINFO_USAGE_DIR_USE]
143 < opts->x_debug_struct_ordinary[DINFO_USAGE_IND_USE]
144 || opts->x_debug_struct_generic[DINFO_USAGE_DIR_USE]
145 < opts->x_debug_struct_generic[DINFO_USAGE_IND_USE])
146 error ("%<-femit-struct-debug-detailed=dir:...%> must allow at least"
147 " as much as %<-femit-struct-debug-detailed=ind:...%>");
151 /* Find the base name of a path, stripping off both directories and
152 a single final extension. */
154 base_of_path (const char *path, const char **base_out)
156 const char *base = path;
158 const char *p = path;
162 if (IS_DIR_SEPARATOR(c))
177 /* Nonzero means use GNU-only extensions in the generated symbolic
178 debugging information. Currently, this only has an effect when
179 write_symbols is set to DBX_DEBUG, XCOFF_DEBUG, or DWARF_DEBUG. */
180 bool use_gnu_debug_info_extensions;
182 /* Global visibility options. */
183 struct visibility_flags visibility_options;
185 /* What to print when a switch has no documentation. */
186 static const char undocumented_msg[] = N_("This switch lacks documentation");
188 typedef char *char_p; /* For DEF_VEC_P. */
190 DEF_VEC_ALLOC_P(char_p,heap);
192 typedef const char *const_char_p; /* For DEF_VEC_P. */
193 DEF_VEC_P(const_char_p);
194 DEF_VEC_ALLOC_P(const_char_p,heap);
196 static VEC(const_char_p,heap) *ignored_options;
198 /* Input file names. */
199 const char **in_fnames;
200 unsigned num_in_fnames;
202 static bool common_handle_option (struct gcc_options *opts,
203 struct gcc_options *opts_set,
204 const struct cl_decoded_option *decoded,
205 unsigned int lang_mask, int kind,
207 const struct cl_option_handlers *handlers,
208 diagnostic_context *dc);
209 static void handle_param (struct gcc_options *opts,
210 struct gcc_options *opts_set, const char *carg);
211 static char *write_langs (unsigned int lang_mask);
212 static void complain_wrong_lang (const struct cl_decoded_option *,
213 unsigned int lang_mask);
214 static void set_debug_level (enum debug_info_type type, int extended,
216 static void set_fast_math_flags (struct gcc_options *opts, int set);
217 static void set_unsafe_math_optimizations_flags (struct gcc_options *opts,
219 static void enable_warning_as_error (const char *arg, int value,
220 unsigned int lang_mask,
221 const struct cl_option_handlers *handlers,
222 struct gcc_options *opts,
223 struct gcc_options *opts_set,
225 diagnostic_context *dc);
227 /* Return a malloced slash-separated list of languages in MASK. */
229 write_langs (unsigned int mask)
231 unsigned int n = 0, len = 0;
232 const char *lang_name;
235 for (n = 0; (lang_name = lang_names[n]) != 0; n++)
236 if (mask & (1U << n))
237 len += strlen (lang_name) + 1;
239 result = XNEWVEC (char, len);
241 for (n = 0; (lang_name = lang_names[n]) != 0; n++)
242 if (mask & (1U << n))
246 strcpy (result + len, lang_name);
247 len += strlen (lang_name);
255 /* Complain that switch DECODED does not apply to this front end (mask
258 complain_wrong_lang (const struct cl_decoded_option *decoded,
259 unsigned int lang_mask)
261 const struct cl_option *option = &cl_options[decoded->opt_index];
262 const char *text = decoded->orig_option_with_args_text;
263 char *ok_langs = NULL, *bad_lang = NULL;
264 unsigned int opt_flags = option->flags;
266 if (!lang_hooks.complain_wrong_lang_p (option))
269 opt_flags &= ((1U << cl_lang_count) - 1) | CL_DRIVER;
270 if (opt_flags != CL_DRIVER)
271 ok_langs = write_langs (opt_flags);
272 if (lang_mask != CL_DRIVER)
273 bad_lang = write_langs (lang_mask);
275 if (opt_flags == CL_DRIVER)
276 error ("command line option %qs is valid for the driver but not for %s",
278 else if (lang_mask == CL_DRIVER)
281 /* Eventually this should become a hard error IMO. */
282 warning (0, "command line option %qs is valid for %s but not for %s",
283 text, ok_langs, bad_lang);
289 /* Buffer the unknown option described by the string OPT. Currently,
290 we only complain about unknown -Wno-* options if they may have
291 prevented a diagnostic. Otherwise, we just ignore them.
292 Note that if we do complain, it is only as a warning, not an error;
293 passing the compiler an unrecognised -Wno-* option should never
294 change whether the compilation succeeds or fails. */
296 static void postpone_unknown_option_warning(const char *opt)
298 VEC_safe_push (const_char_p, heap, ignored_options, opt);
301 /* Produce a warning for each option previously buffered. */
303 void print_ignored_options (void)
305 location_t saved_loc = input_location;
309 while (!VEC_empty (const_char_p, ignored_options))
312 opt = VEC_pop (const_char_p, ignored_options);
313 warning (0, "unrecognized command line option \"%s\"", opt);
316 input_location = saved_loc;
319 /* Handle an unknown option DECODED, returning true if an error should be
323 unknown_option_callback (const struct cl_decoded_option *decoded)
325 const char *opt = decoded->arg;
327 if (opt[1] == 'W' && opt[2] == 'n' && opt[3] == 'o' && opt[4] == '-'
328 && !(decoded->errors & CL_ERR_NEGATIVE))
330 /* We don't generate warnings for unknown -Wno-* options unless
331 we issue diagnostics. */
332 postpone_unknown_option_warning (opt);
339 /* Note that an option DECODED has been successfully handled with a
340 handler for mask MASK. */
343 post_handling_callback (const struct cl_decoded_option *decoded ATTRIBUTE_UNUSED,
344 unsigned int mask ATTRIBUTE_UNUSED)
347 lto_register_user_option (decoded->opt_index, decoded->arg,
348 decoded->value, mask);
352 /* Handle a front-end option; arguments and return value as for
356 lang_handle_option (struct gcc_options *opts,
357 struct gcc_options *opts_set,
358 const struct cl_decoded_option *decoded,
359 unsigned int lang_mask ATTRIBUTE_UNUSED, int kind,
361 const struct cl_option_handlers *handlers,
362 diagnostic_context *dc)
364 gcc_assert (opts == &global_options);
365 gcc_assert (opts_set == &global_options_set);
366 gcc_assert (dc == global_dc);
367 gcc_assert (decoded->canonical_option_num_elements <= 2);
368 return lang_hooks.handle_option (decoded->opt_index, decoded->arg,
369 decoded->value, kind, loc, handlers);
372 /* Handle a back-end option; arguments and return value as for
376 target_handle_option (struct gcc_options *opts,
377 struct gcc_options *opts_set,
378 const struct cl_decoded_option *decoded,
379 unsigned int lang_mask ATTRIBUTE_UNUSED, int kind,
380 location_t loc ATTRIBUTE_UNUSED,
381 const struct cl_option_handlers *handlers ATTRIBUTE_UNUSED,
382 diagnostic_context *dc)
384 gcc_assert (opts == &global_options);
385 gcc_assert (opts_set == &global_options_set);
386 gcc_assert (dc == global_dc);
387 gcc_assert (decoded->canonical_option_num_elements <= 2);
388 gcc_assert (kind == DK_UNSPECIFIED);
389 /* Although the location is not passed down to
390 targetm.handle_option, do not make assertions about its value;
391 options may come from optimize attributes and having the correct
392 location in the handler is not generally important. */
393 return targetm.handle_option (decoded->opt_index, decoded->arg,
397 /* Handle FILENAME from the command line. */
399 add_input_filename (const char *filename)
402 in_fnames = XRESIZEVEC (const char *, in_fnames, num_in_fnames);
403 in_fnames[num_in_fnames - 1] = filename;
406 /* Add comma-separated strings to a char_p vector. */
409 add_comma_separated_to_vector (void **pvec, const char *arg)
415 VEC(char_p,heap) *vec = (VEC(char_p,heap) *) *pvec;
417 /* We never free this string. */
430 VEC_safe_push (char_p, heap, vec, token_start);
433 if (*r == '\\' && r[1] == ',')
441 if (*token_start != '\0')
442 VEC_safe_push (char_p, heap, vec, token_start);
447 /* Handle the vector of command line options (located at LOC), storing
448 the results of processing DECODED_OPTIONS and DECODED_OPTIONS_COUNT
449 in OPTS and OPTS_SET and using DC for diagnostic state. LANG_MASK
450 contains has a single bit set representing the current language.
451 HANDLERS describes what functions to call for the options. */
453 read_cmdline_options (struct gcc_options *opts, struct gcc_options *opts_set,
454 struct cl_decoded_option *decoded_options,
455 unsigned int decoded_options_count,
457 unsigned int lang_mask,
458 const struct cl_option_handlers *handlers,
459 diagnostic_context *dc)
463 for (i = 1; i < decoded_options_count; i++)
465 if (decoded_options[i].opt_index == OPT_SPECIAL_input_file)
467 /* Input files should only ever appear on the main command
469 gcc_assert (opts == &global_options);
470 gcc_assert (opts_set == &global_options_set);
472 if (main_input_filename == NULL)
474 main_input_filename = decoded_options[i].arg;
475 main_input_baselength
476 = base_of_path (main_input_filename, &main_input_basename);
478 add_input_filename (decoded_options[i].arg);
482 read_cmdline_option (opts, opts_set,
483 decoded_options + i, loc, lang_mask, handlers,
488 /* Language mask determined at initialization. */
489 static unsigned int initial_lang_mask;
491 /* Initialize global options-related settings at start-up. */
494 init_options_once (void)
496 /* Perform language-specific options initialization. */
497 initial_lang_mask = lang_hooks.option_lang_mask ();
499 lang_hooks.initialize_diagnostics (global_dc);
502 /* Initialize OPTS and OPTS_SET before using them in parsing options. */
505 init_options_struct (struct gcc_options *opts, struct gcc_options *opts_set)
507 size_t num_params = get_num_compiler_params ();
509 *opts = global_options_init;
510 memset (opts_set, 0, sizeof (*opts_set));
512 opts->x_param_values = XNEWVEC (int, num_params);
513 opts_set->x_param_values = XCNEWVEC (int, num_params);
514 init_param_values (opts->x_param_values);
516 /* Use priority coloring if cover classes is not defined for the
518 if (targetm.ira_cover_classes == NULL)
519 opts->x_flag_ira_algorithm = IRA_ALGORITHM_PRIORITY;
521 /* Initialize whether `char' is signed. */
522 opts->x_flag_signed_char = DEFAULT_SIGNED_CHAR;
523 /* Set this to a special "uninitialized" value. The actual default
524 is set after target options have been processed. */
525 opts->x_flag_short_enums = 2;
527 /* Initialize target_flags before targetm.target_option.optimization
528 so the latter can modify it. */
529 opts->x_target_flags = targetm.default_target_flags;
531 /* Some targets have ABI-specified unwind tables. */
532 opts->x_flag_unwind_tables = targetm.unwind_tables_default;
534 /* Some targets have other target-specific initialization. */
535 targetm.target_option.init_struct (opts);
538 /* Decode command-line options to an array, like
539 decode_cmdline_options_to_array and with the same arguments but
540 using the default lang_mask. */
543 decode_cmdline_options_to_array_default_mask (unsigned int argc,
545 struct cl_decoded_option **decoded_options,
546 unsigned int *decoded_options_count)
548 decode_cmdline_options_to_array (argc, argv,
549 initial_lang_mask | CL_COMMON | CL_TARGET,
550 decoded_options, decoded_options_count);
553 /* If indicated by the optimization level LEVEL (-Os if SIZE is set,
554 -Ofast if FAST is set), apply the option DEFAULT_OPT to OPTS and
555 OPTS_SET, diagnostic context DC, location LOC, with language mask
556 LANG_MASK and option handlers HANDLERS. */
559 maybe_default_option (struct gcc_options *opts,
560 struct gcc_options *opts_set,
561 const struct default_options *default_opt,
562 int level, bool size, bool fast,
563 unsigned int lang_mask,
564 const struct cl_option_handlers *handlers,
566 diagnostic_context *dc)
568 const struct cl_option *option = &cl_options[default_opt->opt_index];
572 gcc_assert (level == 2);
574 gcc_assert (level == 3);
576 switch (default_opt->levels)
582 case OPT_LEVELS_0_ONLY:
583 enabled = (level == 0);
586 case OPT_LEVELS_1_PLUS:
587 enabled = (level >= 1);
590 case OPT_LEVELS_1_PLUS_SPEED_ONLY:
591 enabled = (level >= 1 && !size);
594 case OPT_LEVELS_2_PLUS:
595 enabled = (level >= 2);
598 case OPT_LEVELS_2_PLUS_SPEED_ONLY:
599 enabled = (level >= 2 && !size);
602 case OPT_LEVELS_3_PLUS:
603 enabled = (level >= 3);
606 case OPT_LEVELS_3_PLUS_AND_SIZE:
607 enabled = (level >= 3 || size);
610 case OPT_LEVELS_SIZE:
614 case OPT_LEVELS_FAST:
618 case OPT_LEVELS_NONE:
624 handle_generated_option (opts, opts_set, default_opt->opt_index,
625 default_opt->arg, default_opt->value,
626 lang_mask, DK_UNSPECIFIED, loc,
628 else if (default_opt->arg == NULL
629 && !(option->flags & CL_REJECT_NEGATIVE))
630 handle_generated_option (opts, opts_set, default_opt->opt_index,
631 default_opt->arg, !default_opt->value,
632 lang_mask, DK_UNSPECIFIED, loc,
636 /* As indicated by the optimization level LEVEL (-Os if SIZE is set,
637 -Ofast if FAST is set), apply the options in array DEFAULT_OPTS to
638 OPTS and OPTS_SET, diagnostic context DC, location LOC, with
639 language mask LANG_MASK and option handlers HANDLERS. */
642 maybe_default_options (struct gcc_options *opts,
643 struct gcc_options *opts_set,
644 const struct default_options *default_opts,
645 int level, bool size, bool fast,
646 unsigned int lang_mask,
647 const struct cl_option_handlers *handlers,
649 diagnostic_context *dc)
653 for (i = 0; default_opts[i].levels != OPT_LEVELS_NONE; i++)
654 maybe_default_option (opts, opts_set, &default_opts[i],
655 level, size, fast, lang_mask, handlers, loc, dc);
658 /* Table of options enabled by default at different levels. */
660 static const struct default_options default_options_table[] =
662 /* -O1 optimizations. */
663 { OPT_LEVELS_1_PLUS, OPT_fdefer_pop, NULL, 1 },
665 { OPT_LEVELS_1_PLUS, OPT_fdelayed_branch, NULL, 1 },
667 { OPT_LEVELS_1_PLUS, OPT_fguess_branch_probability, NULL, 1 },
668 { OPT_LEVELS_1_PLUS, OPT_fcprop_registers, NULL, 1 },
669 { OPT_LEVELS_1_PLUS, OPT_fforward_propagate, NULL, 1 },
670 { OPT_LEVELS_1_PLUS, OPT_fif_conversion, NULL, 1 },
671 { OPT_LEVELS_1_PLUS, OPT_fif_conversion2, NULL, 1 },
672 { OPT_LEVELS_1_PLUS, OPT_fipa_pure_const, NULL, 1 },
673 { OPT_LEVELS_1_PLUS, OPT_fipa_reference, NULL, 1 },
674 { OPT_LEVELS_1_PLUS, OPT_fipa_profile, NULL, 1 },
675 { OPT_LEVELS_1_PLUS, OPT_fmerge_constants, NULL, 1 },
676 { OPT_LEVELS_1_PLUS, OPT_fsplit_wide_types, NULL, 1 },
677 { OPT_LEVELS_1_PLUS, OPT_ftree_ccp, NULL, 1 },
678 { OPT_LEVELS_1_PLUS, OPT_ftree_bit_ccp, NULL, 1 },
679 { OPT_LEVELS_1_PLUS, OPT_ftree_dce, NULL, 1 },
680 { OPT_LEVELS_1_PLUS, OPT_ftree_dominator_opts, NULL, 1 },
681 { OPT_LEVELS_1_PLUS, OPT_ftree_dse, NULL, 1 },
682 { OPT_LEVELS_1_PLUS, OPT_ftree_ter, NULL, 1 },
683 { OPT_LEVELS_1_PLUS, OPT_ftree_sra, NULL, 1 },
684 { OPT_LEVELS_1_PLUS, OPT_ftree_copyrename, NULL, 1 },
685 { OPT_LEVELS_1_PLUS, OPT_ftree_fre, NULL, 1 },
686 { OPT_LEVELS_1_PLUS, OPT_ftree_copy_prop, NULL, 1 },
687 { OPT_LEVELS_1_PLUS, OPT_ftree_sink, NULL, 1 },
688 { OPT_LEVELS_1_PLUS, OPT_ftree_ch, NULL, 1 },
689 { OPT_LEVELS_1_PLUS, OPT_fcombine_stack_adjustments, NULL, 1 },
691 /* -O2 optimizations. */
692 { OPT_LEVELS_2_PLUS, OPT_finline_small_functions, NULL, 1 },
693 { OPT_LEVELS_2_PLUS, OPT_findirect_inlining, NULL, 1 },
694 { OPT_LEVELS_2_PLUS, OPT_fpartial_inlining, NULL, 1 },
695 { OPT_LEVELS_2_PLUS, OPT_fthread_jumps, NULL, 1 },
696 { OPT_LEVELS_2_PLUS, OPT_fcrossjumping, NULL, 1 },
697 { OPT_LEVELS_2_PLUS, OPT_foptimize_sibling_calls, NULL, 1 },
698 { OPT_LEVELS_2_PLUS, OPT_fcse_follow_jumps, NULL, 1 },
699 { OPT_LEVELS_2_PLUS, OPT_fgcse, NULL, 1 },
700 { OPT_LEVELS_2_PLUS, OPT_fexpensive_optimizations, NULL, 1 },
701 { OPT_LEVELS_2_PLUS, OPT_frerun_cse_after_loop, NULL, 1 },
702 { OPT_LEVELS_2_PLUS, OPT_fcaller_saves, NULL, 1 },
703 { OPT_LEVELS_2_PLUS, OPT_fpeephole2, NULL, 1 },
704 #ifdef INSN_SCHEDULING
705 /* Only run the pre-regalloc scheduling pass if optimizing for speed. */
706 { OPT_LEVELS_2_PLUS_SPEED_ONLY, OPT_fschedule_insns, NULL, 1 },
707 { OPT_LEVELS_2_PLUS, OPT_fschedule_insns2, NULL, 1 },
709 { OPT_LEVELS_2_PLUS, OPT_fregmove, NULL, 1 },
710 { OPT_LEVELS_2_PLUS, OPT_fstrict_aliasing, NULL, 1 },
711 { OPT_LEVELS_2_PLUS, OPT_fstrict_overflow, NULL, 1 },
712 { OPT_LEVELS_2_PLUS, OPT_freorder_blocks, NULL, 1 },
713 { OPT_LEVELS_2_PLUS, OPT_freorder_functions, NULL, 1 },
714 { OPT_LEVELS_2_PLUS, OPT_ftree_vrp, NULL, 1 },
715 { OPT_LEVELS_2_PLUS, OPT_ftree_builtin_call_dce, NULL, 1 },
716 { OPT_LEVELS_2_PLUS, OPT_ftree_pre, NULL, 1 },
717 { OPT_LEVELS_2_PLUS, OPT_ftree_switch_conversion, NULL, 1 },
718 { OPT_LEVELS_2_PLUS, OPT_fipa_cp, NULL, 1 },
719 { OPT_LEVELS_2_PLUS, OPT_fipa_sra, NULL, 1 },
720 { OPT_LEVELS_2_PLUS, OPT_falign_loops, NULL, 1 },
721 { OPT_LEVELS_2_PLUS, OPT_falign_jumps, NULL, 1 },
722 { OPT_LEVELS_2_PLUS, OPT_falign_labels, NULL, 1 },
723 { OPT_LEVELS_2_PLUS, OPT_falign_functions, NULL, 1 },
725 /* -O3 optimizations. */
726 { OPT_LEVELS_3_PLUS, OPT_ftree_loop_distribute_patterns, NULL, 1 },
727 { OPT_LEVELS_3_PLUS, OPT_fpredictive_commoning, NULL, 1 },
728 /* Inlining of functions reducing size is a good idea with -Os
729 regardless of them being declared inline. */
730 { OPT_LEVELS_3_PLUS_AND_SIZE, OPT_finline_functions, NULL, 1 },
731 { OPT_LEVELS_3_PLUS, OPT_funswitch_loops, NULL, 1 },
732 { OPT_LEVELS_3_PLUS, OPT_fgcse_after_reload, NULL, 1 },
733 { OPT_LEVELS_3_PLUS, OPT_ftree_vectorize, NULL, 1 },
734 { OPT_LEVELS_3_PLUS, OPT_fipa_cp_clone, NULL, 1 },
736 /* -Ofast adds optimizations to -O3. */
737 { OPT_LEVELS_FAST, OPT_ffast_math, NULL, 1 },
739 { OPT_LEVELS_NONE, 0, NULL, 0 }
742 /* Default the options in OPTS and OPTS_SET based on the optimization
743 settings in DECODED_OPTIONS and DECODED_OPTIONS_COUNT. */
745 default_options_optimization (struct gcc_options *opts,
746 struct gcc_options *opts_set,
747 struct cl_decoded_option *decoded_options,
748 unsigned int decoded_options_count,
750 unsigned int lang_mask,
751 const struct cl_option_handlers *handlers,
752 diagnostic_context *dc)
758 /* Scan to see what optimization level has been specified. That will
759 determine the default value of many flags. */
760 for (i = 1; i < decoded_options_count; i++)
762 struct cl_decoded_option *opt = &decoded_options[i];
763 switch (opt->opt_index)
766 if (*opt->arg == '\0')
768 opts->x_optimize = 1;
769 opts->x_optimize_size = 0;
774 const int optimize_val = integral_argument (opt->arg);
775 if (optimize_val == -1)
776 error ("argument to %qs should be a non-negative integer",
780 opts->x_optimize = optimize_val;
781 if ((unsigned int) opts->x_optimize > 255)
782 opts->x_optimize = 255;
783 opts->x_optimize_size = 0;
790 opts->x_optimize_size = 1;
792 /* Optimizing for size forces optimize to be 2. */
793 opts->x_optimize = 2;
798 /* -Ofast only adds flags to -O3. */
799 opts->x_optimize_size = 0;
800 opts->x_optimize = 3;
805 /* Ignore other options in this prescan. */
810 maybe_default_options (opts, opts_set, default_options_table,
811 opts->x_optimize, opts->x_optimize_size,
812 ofast, lang_mask, handlers, loc, dc);
814 /* -O2 param settings. */
815 opt2 = (opts->x_optimize >= 2);
817 /* Track fields in field-sensitive alias analysis. */
818 maybe_set_param_value
819 (PARAM_MAX_FIELDS_FOR_FIELD_SENSITIVE,
820 opt2 ? 100 : default_param_value (PARAM_MAX_FIELDS_FOR_FIELD_SENSITIVE),
821 opts->x_param_values, opts_set->x_param_values);
823 /* For -O1 only do loop invariant motion for very small loops. */
824 maybe_set_param_value
825 (PARAM_LOOP_INVARIANT_MAX_BBS_IN_LOOP,
826 opt2 ? default_param_value (PARAM_LOOP_INVARIANT_MAX_BBS_IN_LOOP) : 1000,
827 opts->x_param_values, opts_set->x_param_values);
829 if (opts->x_optimize_size)
830 /* We want to crossjump as much as possible. */
831 maybe_set_param_value (PARAM_MIN_CROSSJUMP_INSNS, 1,
832 opts->x_param_values, opts_set->x_param_values);
834 maybe_set_param_value (PARAM_MIN_CROSSJUMP_INSNS,
835 default_param_value (PARAM_MIN_CROSSJUMP_INSNS),
836 opts->x_param_values, opts_set->x_param_values);
838 /* Allow default optimizations to be specified on a per-machine basis. */
839 maybe_default_options (opts, opts_set,
840 targetm.target_option.optimization_table,
841 opts->x_optimize, opts->x_optimize_size,
842 ofast, lang_mask, handlers, loc, dc);
845 static void finish_options (struct gcc_options *, struct gcc_options *);
847 /* Set *HANDLERS to the default set of option handlers for use in the
848 compilers proper (not the driver). */
850 set_default_handlers (struct cl_option_handlers *handlers)
852 handlers->unknown_option_callback = unknown_option_callback;
853 handlers->wrong_lang_callback = complain_wrong_lang;
854 handlers->post_handling_callback = post_handling_callback;
855 handlers->num_handlers = 3;
856 handlers->handlers[0].handler = lang_handle_option;
857 handlers->handlers[0].mask = initial_lang_mask;
858 handlers->handlers[1].handler = common_handle_option;
859 handlers->handlers[1].mask = CL_COMMON;
860 handlers->handlers[2].handler = target_handle_option;
861 handlers->handlers[2].mask = CL_TARGET;
864 /* Parse command line options and set default flag values. Do minimal
865 options processing. The decoded options are in *DECODED_OPTIONS
866 and *DECODED_OPTIONS_COUNT; settings go in OPTS, OPTS_SET and DC;
867 the options are located at LOC. */
869 decode_options (struct gcc_options *opts, struct gcc_options *opts_set,
870 struct cl_decoded_option *decoded_options,
871 unsigned int decoded_options_count,
872 location_t loc, diagnostic_context *dc)
874 struct cl_option_handlers handlers;
876 unsigned int lang_mask;
878 lang_mask = initial_lang_mask;
880 set_default_handlers (&handlers);
882 /* Enable -Werror=coverage-mismatch by default. */
883 control_warning_option (OPT_Wcoverage_mismatch, (int) DK_ERROR, true,
885 &handlers, opts, opts_set, dc);
887 default_options_optimization (opts, opts_set,
888 decoded_options, decoded_options_count,
889 loc, lang_mask, &handlers, dc);
892 /* Clear any options currently held for LTO. */
893 lto_clear_user_options ();
896 read_cmdline_options (opts, opts_set,
897 decoded_options, decoded_options_count,
901 finish_options (opts, opts_set);
904 /* After all options have been read into OPTS and OPTS_SET, finalize
905 settings of those options and diagnose incompatible
908 finish_options (struct gcc_options *opts, struct gcc_options *opts_set)
910 static bool first_time_p = true;
911 enum unwind_info_type ui_except;
913 gcc_assert (opts == &global_options);
914 gcc_assert (opts_set = &global_options_set);
916 if (opts->x_dump_base_name && ! IS_ABSOLUTE_PATH (opts->x_dump_base_name))
918 /* First try to make OPTS->X_DUMP_BASE_NAME relative to the
919 OPTS->X_DUMP_DIR_NAME directory. Then try to make
920 OPTS->X_DUMP_BASE_NAME relative to the OPTS->X_AUX_BASE_NAME
921 directory, typically the directory to contain the object
923 if (opts->x_dump_dir_name)
924 opts->x_dump_base_name = concat (opts->x_dump_dir_name,
925 opts->x_dump_base_name, NULL);
926 else if (opts->x_aux_base_name)
928 const char *aux_base;
930 base_of_path (opts->x_aux_base_name, &aux_base);
931 if (opts->x_aux_base_name != aux_base)
933 int dir_len = aux_base - opts->x_aux_base_name;
934 char *new_dump_base_name =
935 XNEWVEC (char, strlen (opts->x_dump_base_name) + dir_len + 1);
937 /* Copy directory component from OPTS->X_AUX_BASE_NAME. */
938 memcpy (new_dump_base_name, opts->x_aux_base_name, dir_len);
939 /* Append existing OPTS->X_DUMP_BASE_NAME. */
940 strcpy (new_dump_base_name + dir_len, opts->x_dump_base_name);
941 opts->x_dump_base_name = new_dump_base_name;
946 /* Handle related options for unit-at-a-time, toplevel-reorder, and
948 if (!opts->x_flag_unit_at_a_time)
950 if (opts->x_flag_section_anchors && opts_set->x_flag_section_anchors)
951 error ("section anchors must be disabled when unit-at-a-time "
953 opts->x_flag_section_anchors = 0;
954 if (opts->x_flag_toplevel_reorder == 1)
955 error ("toplevel reorder must be disabled when unit-at-a-time "
957 opts->x_flag_toplevel_reorder = 0;
960 /* -Wmissing-noreturn is alias for -Wsuggest-attribute=noreturn. */
961 if (opts->x_warn_missing_noreturn)
962 opts->x_warn_suggest_attribute_noreturn = true;
964 /* Unless the user has asked for section anchors, we disable toplevel
965 reordering at -O0 to disable transformations that might be surprising
966 to end users and to get -fno-toplevel-reorder tested. */
968 && opts->x_flag_toplevel_reorder == 2
969 && !(opts->x_flag_section_anchors && opts_set->x_flag_section_anchors))
971 opts->x_flag_toplevel_reorder = 0;
972 opts->x_flag_section_anchors = 0;
974 if (!opts->x_flag_toplevel_reorder)
976 if (opts->x_flag_section_anchors && opts_set->x_flag_section_anchors)
977 error ("section anchors must be disabled when toplevel reorder"
979 opts->x_flag_section_anchors = 0;
984 if (opts->x_flag_pie)
985 opts->x_flag_pic = opts->x_flag_pie;
986 if (opts->x_flag_pic && !opts->x_flag_pie)
987 opts->x_flag_shlib = 1;
988 first_time_p = false;
993 /* Inlining does not work if not optimizing,
994 so force it not to be done. */
995 opts->x_warn_inline = 0;
996 opts->x_flag_no_inline = 1;
999 /* The optimization to partition hot and cold basic blocks into separate
1000 sections of the .o and executable files does not work (currently)
1001 with exception handling. This is because there is no support for
1002 generating unwind info. If opts->x_flag_exceptions is turned on
1003 we need to turn off the partitioning optimization. */
1005 ui_except = targetm.except_unwind_info ();
1007 if (opts->x_flag_exceptions
1008 && opts->x_flag_reorder_blocks_and_partition
1009 && (ui_except == UI_SJLJ || ui_except == UI_TARGET))
1011 inform (input_location,
1012 "-freorder-blocks-and-partition does not work "
1013 "with exceptions on this architecture");
1014 opts->x_flag_reorder_blocks_and_partition = 0;
1015 opts->x_flag_reorder_blocks = 1;
1018 /* If user requested unwind info, then turn off the partitioning
1021 if (opts->x_flag_unwind_tables
1022 && !targetm.unwind_tables_default
1023 && opts->x_flag_reorder_blocks_and_partition
1024 && (ui_except == UI_SJLJ || ui_except == UI_TARGET))
1026 inform (input_location,
1027 "-freorder-blocks-and-partition does not support "
1028 "unwind info on this architecture");
1029 opts->x_flag_reorder_blocks_and_partition = 0;
1030 opts->x_flag_reorder_blocks = 1;
1033 /* If the target requested unwind info, then turn off the partitioning
1034 optimization with a different message. Likewise, if the target does not
1035 support named sections. */
1037 if (opts->x_flag_reorder_blocks_and_partition
1038 && (!targetm.have_named_sections
1039 || (opts->x_flag_unwind_tables
1040 && targetm.unwind_tables_default
1041 && (ui_except == UI_SJLJ || ui_except == UI_TARGET))))
1043 inform (input_location,
1044 "-freorder-blocks-and-partition does not work "
1045 "on this architecture");
1046 opts->x_flag_reorder_blocks_and_partition = 0;
1047 opts->x_flag_reorder_blocks = 1;
1050 /* Pipelining of outer loops is only possible when general pipelining
1051 capabilities are requested. */
1052 if (!opts->x_flag_sel_sched_pipelining)
1053 opts->x_flag_sel_sched_pipelining_outer_loops = 0;
1055 if (!targetm.ira_cover_classes
1056 && opts->x_flag_ira_algorithm == IRA_ALGORITHM_CB)
1058 inform (input_location,
1059 "-fira-algorithm=CB does not work on this architecture");
1060 opts->x_flag_ira_algorithm = IRA_ALGORITHM_PRIORITY;
1063 if (opts->x_flag_conserve_stack)
1065 maybe_set_param_value (PARAM_LARGE_STACK_FRAME, 100,
1066 opts->x_param_values, opts_set->x_param_values);
1067 maybe_set_param_value (PARAM_STACK_FRAME_GROWTH, 40,
1068 opts->x_param_values, opts_set->x_param_values);
1070 if (opts->x_flag_wpa || opts->x_flag_ltrans)
1072 /* These passes are not WHOPR compatible yet. */
1073 opts->x_flag_ipa_pta = 0;
1074 opts->x_flag_ipa_struct_reorg = 0;
1077 if (opts->x_flag_lto)
1080 opts->x_flag_generate_lto = 1;
1082 /* When generating IL, do not operate in whole-program mode.
1083 Otherwise, symbols will be privatized too early, causing link
1085 opts->x_flag_whole_program = 0;
1087 error ("LTO support has not been enabled in this configuration");
1090 if ((opts->x_flag_lto_partition_balanced != 0) + (opts->x_flag_lto_partition_1to1 != 0)
1091 + (opts->x_flag_lto_partition_none != 0) >= 1)
1093 if ((opts->x_flag_lto_partition_balanced != 0)
1094 + (opts->x_flag_lto_partition_1to1 != 0)
1095 + (opts->x_flag_lto_partition_none != 0) > 1)
1096 error ("only one -flto-partition value can be specified");
1099 /* We initialize opts->x_flag_split_stack to -1 so that targets can set a
1100 default value if they choose based on other options. */
1101 if (opts->x_flag_split_stack == -1)
1102 opts->x_flag_split_stack = 0;
1103 else if (opts->x_flag_split_stack)
1105 if (!targetm.supports_split_stack (true))
1107 error ("%<-fsplit-stack%> is not supported by "
1108 "this compiler configuration");
1109 opts->x_flag_split_stack = 0;
1114 #define LEFT_COLUMN 27
1116 /* Output ITEM, of length ITEM_WIDTH, in the left column,
1117 followed by word-wrapped HELP in a second column. */
1119 wrap_help (const char *help,
1121 unsigned int item_width,
1122 unsigned int columns)
1124 unsigned int col_width = LEFT_COLUMN;
1125 unsigned int remaining, room, len;
1127 remaining = strlen (help);
1131 room = columns - 3 - MAX (col_width, item_width);
1140 for (i = 0; help[i]; i++)
1142 if (i >= room && len != remaining)
1146 else if ((help[i] == '-' || help[i] == '/')
1147 && help[i + 1] != ' '
1148 && i > 0 && ISALPHA (help[i - 1]))
1153 printf( " %-*.*s %.*s\n", col_width, item_width, item, len, help);
1155 while (help[len] == ' ')
1163 /* Print help for a specific front-end, etc. */
1165 print_filtered_help (unsigned int include_flags,
1166 unsigned int exclude_flags,
1167 unsigned int any_flags,
1168 unsigned int columns)
1172 static char *printed = NULL;
1174 bool displayed = false;
1176 if (include_flags == CL_PARAMS)
1178 for (i = 0; i < LAST_PARAM; i++)
1180 const char *param = compiler_params[i].option;
1182 help = compiler_params[i].help;
1183 if (help == NULL || *help == '\0')
1185 if (exclude_flags & CL_UNDOCUMENTED)
1187 help = undocumented_msg;
1190 /* Get the translation. */
1193 wrap_help (help, param, strlen (param), columns);
1200 printed = XCNEWVAR (char, cl_options_count);
1202 for (i = 0; i < cl_options_count; i++)
1204 static char new_help[128];
1205 const struct cl_option *option = cl_options + i;
1210 if (include_flags == 0
1211 || ((option->flags & include_flags) != include_flags))
1213 if ((option->flags & any_flags) == 0)
1217 /* Skip unwanted switches. */
1218 if ((option->flags & exclude_flags) != 0)
1221 /* The driver currently prints its own help text. */
1222 if ((option->flags & CL_DRIVER) != 0
1223 && (option->flags & (((1U << cl_lang_count) - 1)
1224 | CL_COMMON | CL_TARGET)) == 0)
1228 /* Skip switches that have already been printed. */
1234 help = option->help;
1237 if (exclude_flags & CL_UNDOCUMENTED)
1239 help = undocumented_msg;
1242 /* Get the translation. */
1245 /* Find the gap between the name of the
1246 option and its descriptive text. */
1247 tab = strchr (help, '\t');
1256 opt = option->opt_text;
1260 /* With the -Q option enabled we change the descriptive text associated
1261 with an option to be an indication of its current setting. */
1264 void *flag_var = option_flag_var (i, &global_options);
1266 if (len < (LEFT_COLUMN + 2))
1267 strcpy (new_help, "\t\t");
1269 strcpy (new_help, "\t");
1271 if (flag_var != NULL
1272 && option->var_type != CLVC_DEFER)
1274 if (option->flags & CL_JOINED)
1276 if (option->var_type == CLVC_STRING)
1278 if (* (const char **) flag_var != NULL)
1279 snprintf (new_help + strlen (new_help),
1280 sizeof (new_help) - strlen (new_help),
1281 * (const char **) flag_var);
1284 sprintf (new_help + strlen (new_help),
1285 "%#x", * (int *) flag_var);
1288 strcat (new_help, option_enabled (i, &global_options)
1289 ? _("[enabled]") : _("[disabled]"));
1295 wrap_help (help, opt, len, columns);
1301 unsigned int langs = include_flags & CL_LANG_ALL;
1304 printf (_(" No options with the desired characteristics were found\n"));
1309 /* PR 31349: Tell the user how to see all of the
1310 options supported by a specific front end. */
1311 for (i = 0; (1U << i) < CL_LANG_ALL; i ++)
1312 if ((1U << i) & langs)
1313 printf (_(" None found. Use --help=%s to show *all* the options supported by the %s front-end\n"),
1314 lang_names[i], lang_names[i]);
1318 else if (! displayed)
1319 printf (_(" All options with the desired characteristics have already been displayed\n"));
1324 /* Display help for a specified type of option.
1325 The options must have ALL of the INCLUDE_FLAGS set
1326 ANY of the flags in the ANY_FLAGS set
1327 and NONE of the EXCLUDE_FLAGS set. */
1329 print_specific_help (unsigned int include_flags,
1330 unsigned int exclude_flags,
1331 unsigned int any_flags)
1333 unsigned int all_langs_mask = (1U << cl_lang_count) - 1;
1334 const char * description = NULL;
1335 const char * descrip_extra = "";
1338 static unsigned int columns = 0;
1340 /* Sanity check: Make sure that we do not have more
1341 languages than we have bits available to enumerate them. */
1342 gcc_assert ((1U << cl_lang_count) < CL_MIN_OPTION_CLASS);
1344 /* If we have not done so already, obtain
1345 the desired maximum width of the output. */
1350 GET_ENVIRONMENT (p, "COLUMNS");
1353 int value = atoi (p);
1360 /* Use a reasonable default. */
1364 /* Decide upon the title for the options that we are going to display. */
1365 for (i = 0, flag = 1; flag <= CL_MAX_OPTION_CLASS; flag <<= 1, i ++)
1367 switch (flag & include_flags)
1374 description = _("The following options are target specific");
1377 description = _("The following options control compiler warning messages");
1379 case CL_OPTIMIZATION:
1380 description = _("The following options control optimizations");
1383 description = _("The following options are language-independent");
1386 description = _("The --param option recognizes the following as parameters");
1389 if (i >= cl_lang_count)
1391 if (exclude_flags & all_langs_mask)
1392 description = _("The following options are specific to just the language ");
1394 description = _("The following options are supported by the language ");
1395 descrip_extra = lang_names [i];
1400 if (description == NULL)
1404 if (include_flags & CL_UNDOCUMENTED)
1405 description = _("The following options are not documented");
1406 else if (include_flags & CL_SEPARATE)
1407 description = _("The following options take separate arguments");
1408 else if (include_flags & CL_JOINED)
1409 description = _("The following options take joined arguments");
1412 internal_error ("unrecognized include_flags 0x%x passed to print_specific_help",
1419 if (any_flags & all_langs_mask)
1420 description = _("The following options are language-related");
1422 description = _("The following options are language-independent");
1426 printf ("%s%s:\n", description, descrip_extra);
1427 print_filtered_help (include_flags, exclude_flags, any_flags, columns);
1430 /* Handle target- and language-independent options. Return zero to
1431 generate an "unknown option" message. Only options that need
1432 extra handling need to be listed here; if you simply want
1433 DECODED->value assigned to a variable, it happens automatically. */
1436 common_handle_option (struct gcc_options *opts,
1437 struct gcc_options *opts_set,
1438 const struct cl_decoded_option *decoded,
1439 unsigned int lang_mask, int kind ATTRIBUTE_UNUSED,
1441 const struct cl_option_handlers *handlers,
1442 diagnostic_context *dc)
1444 size_t scode = decoded->opt_index;
1445 const char *arg = decoded->arg;
1446 int value = decoded->value;
1447 enum opt_code code = (enum opt_code) scode;
1449 gcc_assert (opts == &global_options);
1450 gcc_assert (opts_set == &global_options_set);
1451 gcc_assert (dc == global_dc);
1452 gcc_assert (decoded->canonical_option_num_elements <= 2);
1457 handle_param (opts, opts_set, arg);
1462 unsigned int all_langs_mask = (1U << cl_lang_count) - 1;
1463 unsigned int undoc_mask;
1466 undoc_mask = ((opts->x_verbose_flag | opts->x_extra_warnings)
1469 /* First display any single language specific options. */
1470 for (i = 0; i < cl_lang_count; i++)
1472 (1U << i, (all_langs_mask & (~ (1U << i))) | undoc_mask, 0);
1473 /* Next display any multi language specific options. */
1474 print_specific_help (0, undoc_mask, all_langs_mask);
1475 /* Then display any remaining, non-language options. */
1476 for (i = CL_MIN_OPTION_CLASS; i <= CL_MAX_OPTION_CLASS; i <<= 1)
1478 print_specific_help (i, undoc_mask, 0);
1479 exit_after_options = true;
1483 case OPT__target_help:
1484 print_specific_help (CL_TARGET, CL_UNDOCUMENTED, 0);
1485 exit_after_options = true;
1487 /* Allow the target a chance to give the user some additional information. */
1494 const char * a = arg;
1495 unsigned int include_flags = 0;
1496 /* Note - by default we include undocumented options when listing
1497 specific classes. If you only want to see documented options
1498 then add ",^undocumented" to the --help= option. E.g.:
1500 --help=target,^undocumented */
1501 unsigned int exclude_flags = 0;
1503 /* Walk along the argument string, parsing each word in turn.
1505 arg = [^]{word}[,{arg}]
1506 word = {optimizers|target|warnings|undocumented|
1507 params|common|<language>} */
1512 const char * string;
1517 { "optimizers", CL_OPTIMIZATION },
1518 { "target", CL_TARGET },
1519 { "warnings", CL_WARNING },
1520 { "undocumented", CL_UNDOCUMENTED },
1521 { "params", CL_PARAMS },
1522 { "joined", CL_JOINED },
1523 { "separate", CL_SEPARATE },
1524 { "common", CL_COMMON },
1527 unsigned int * pflags;
1529 unsigned int lang_flag, specific_flag;
1536 pflags = & exclude_flags;
1539 pflags = & include_flags;
1541 comma = strchr (a, ',');
1552 /* Check to see if the string matches an option class name. */
1553 for (i = 0, specific_flag = 0; specifics[i].string != NULL; i++)
1554 if (strncasecmp (a, specifics[i].string, len) == 0)
1556 specific_flag = specifics[i].flag;
1560 /* Check to see if the string matches a language name.
1561 Note - we rely upon the alpha-sorted nature of the entries in
1562 the lang_names array, specifically that shorter names appear
1563 before their longer variants. (i.e. C before C++). That way
1564 when we are attempting to match --help=c for example we will
1565 match with C first and not C++. */
1566 for (i = 0, lang_flag = 0; i < cl_lang_count; i++)
1567 if (strncasecmp (a, lang_names[i], len) == 0)
1569 lang_flag = 1U << i;
1573 if (specific_flag != 0)
1576 * pflags |= specific_flag;
1579 /* The option's argument matches both the start of a
1580 language name and the start of an option class name.
1581 We have a special case for when the user has
1582 specified "--help=c", but otherwise we have to issue
1584 if (strncasecmp (a, "c", len) == 0)
1585 * pflags |= lang_flag;
1588 "warning: --help argument %.*s is ambiguous, please be more specific\n",
1592 else if (lang_flag != 0)
1593 * pflags |= lang_flag;
1596 "warning: unrecognized argument to --help= option: %.*s\n",
1605 print_specific_help (include_flags, exclude_flags, 0);
1606 exit_after_options = true;
1611 exit_after_options = true;
1617 /* Currently handled in a prescan. */
1621 enable_warning_as_error (arg, value, lang_mask, handlers,
1622 opts, opts_set, loc, dc);
1625 case OPT_Wlarger_than_:
1626 opts->x_larger_than_size = value;
1627 opts->x_warn_larger_than = value != -1;
1630 case OPT_Wfatal_errors:
1631 dc->fatal_errors = value;
1634 case OPT_Wframe_larger_than_:
1635 opts->x_frame_larger_than_size = value;
1636 opts->x_warn_frame_larger_than = value != -1;
1639 case OPT_Wstrict_aliasing:
1640 set_Wstrict_aliasing (opts, value);
1643 case OPT_Wstrict_overflow:
1644 opts->x_warn_strict_overflow = (value
1645 ? (int) WARN_STRICT_OVERFLOW_CONDITIONAL
1649 case OPT_Wsystem_headers:
1650 dc->dc_warn_system_headers = value;
1654 opts->x_flag_gen_aux_info = 1;
1657 case OPT_auxbase_strip:
1659 char *tmp = xstrdup (arg);
1660 strip_off_ending (tmp, strlen (tmp));
1662 opts->x_aux_base_name = tmp;
1667 decode_d_option (arg);
1670 case OPT_fcall_used_:
1671 case OPT_fcall_saved_:
1675 case OPT_fcompare_debug_second:
1676 flag_compare_debug = value;
1680 dbg_cnt_process_opt (arg);
1683 case OPT_fdbg_cnt_list:
1684 dbg_cnt_list_all_counters ();
1687 case OPT_fdebug_prefix_map_:
1688 add_debug_prefix_map (arg);
1691 case OPT_fdiagnostics_show_location_:
1692 if (!strcmp (arg, "once"))
1693 diagnostic_prefixing_rule (dc) = DIAGNOSTICS_SHOW_PREFIX_ONCE;
1694 else if (!strcmp (arg, "every-line"))
1695 diagnostic_prefixing_rule (dc)
1696 = DIAGNOSTICS_SHOW_PREFIX_EVERY_LINE;
1701 case OPT_fdiagnostics_show_option:
1702 dc->show_option_requested = value;
1709 case OPT_ffp_contract_:
1710 if (!strcmp (arg, "on"))
1711 /* Not implemented, fall back to conservative FP_CONTRACT_OFF. */
1712 opts->x_flag_fp_contract_mode = FP_CONTRACT_OFF;
1713 else if (!strcmp (arg, "off"))
1714 opts->x_flag_fp_contract_mode = FP_CONTRACT_OFF;
1715 else if (!strcmp (arg, "fast"))
1716 opts->x_flag_fp_contract_mode = FP_CONTRACT_FAST;
1718 error ("unknown floating point contraction style \"%s\"", arg);
1721 case OPT_fexcess_precision_:
1722 if (!strcmp (arg, "fast"))
1723 opts->x_flag_excess_precision_cmdline = EXCESS_PRECISION_FAST;
1724 else if (!strcmp (arg, "standard"))
1725 opts->x_flag_excess_precision_cmdline = EXCESS_PRECISION_STANDARD;
1727 error ("unknown excess precision style \"%s\"", arg);
1730 case OPT_ffast_math:
1731 set_fast_math_flags (opts, value);
1734 case OPT_funsafe_math_optimizations:
1735 set_unsafe_math_optimizations_flags (opts, value);
1742 case OPT_finline_limit_:
1743 set_param_value ("max-inline-insns-single", value / 2,
1744 opts->x_param_values, opts_set->x_param_values);
1745 set_param_value ("max-inline-insns-auto", value / 2,
1746 opts->x_param_values, opts_set->x_param_values);
1749 case OPT_finstrument_functions_exclude_function_list_:
1750 add_comma_separated_to_vector
1751 (&opts->x_flag_instrument_functions_exclude_functions, arg);
1754 case OPT_finstrument_functions_exclude_file_list_:
1755 add_comma_separated_to_vector
1756 (&opts->x_flag_instrument_functions_exclude_files, arg);
1759 case OPT_fmessage_length_:
1760 pp_set_line_maximum_length (dc->printer, value);
1763 case OPT_fpack_struct_:
1764 if (value <= 0 || (value & (value - 1)) || value > 16)
1765 error ("structure alignment must be a small power of two, not %d", value);
1768 initial_max_fld_align = value;
1769 maximum_field_alignment = value * BITS_PER_UNIT;
1774 case OPT_fplugin_arg_:
1778 case OPT_fprofile_dir_:
1779 profile_data_prefix = xstrdup (arg);
1782 case OPT_fprofile_use_:
1783 profile_data_prefix = xstrdup (arg);
1784 opts->x_flag_profile_use = true;
1786 /* No break here - do -fprofile-use processing. */
1787 case OPT_fprofile_use:
1788 if (!opts_set->x_flag_branch_probabilities)
1789 opts->x_flag_branch_probabilities = value;
1790 if (!opts_set->x_flag_profile_values)
1791 opts->x_flag_profile_values = value;
1792 if (!opts_set->x_flag_unroll_loops)
1793 opts->x_flag_unroll_loops = value;
1794 if (!opts_set->x_flag_peel_loops)
1795 opts->x_flag_peel_loops = value;
1796 if (!opts_set->x_flag_tracer)
1797 opts->x_flag_tracer = value;
1798 if (!opts_set->x_flag_value_profile_transformations)
1799 opts->x_flag_value_profile_transformations = value;
1800 if (!opts_set->x_flag_inline_functions)
1801 opts->x_flag_inline_functions = value;
1802 if (!opts_set->x_flag_ipa_cp)
1803 opts->x_flag_ipa_cp = value;
1804 if (!opts_set->x_flag_ipa_cp_clone
1805 && value && opts->x_flag_ipa_cp)
1806 opts->x_flag_ipa_cp_clone = value;
1807 if (!opts_set->x_flag_predictive_commoning)
1808 opts->x_flag_predictive_commoning = value;
1809 if (!opts_set->x_flag_unswitch_loops)
1810 opts->x_flag_unswitch_loops = value;
1811 if (!opts_set->x_flag_gcse_after_reload)
1812 opts->x_flag_gcse_after_reload = value;
1815 case OPT_fprofile_generate_:
1816 profile_data_prefix = xstrdup (arg);
1818 /* No break here - do -fprofile-generate processing. */
1819 case OPT_fprofile_generate:
1820 if (!opts_set->x_profile_arc_flag)
1821 opts->x_profile_arc_flag = value;
1822 if (!opts_set->x_flag_profile_values)
1823 opts->x_flag_profile_values = value;
1824 if (!opts_set->x_flag_value_profile_transformations)
1825 opts->x_flag_value_profile_transformations = value;
1826 if (!opts_set->x_flag_inline_functions)
1827 opts->x_flag_inline_functions = value;
1830 case OPT_fshow_column:
1831 dc->show_column = value;
1834 case OPT_fvisibility_:
1836 if (!strcmp(arg, "default"))
1837 opts->x_default_visibility = VISIBILITY_DEFAULT;
1838 else if (!strcmp(arg, "internal"))
1839 opts->x_default_visibility = VISIBILITY_INTERNAL;
1840 else if (!strcmp(arg, "hidden"))
1841 opts->x_default_visibility = VISIBILITY_HIDDEN;
1842 else if (!strcmp(arg, "protected"))
1843 opts->x_default_visibility = VISIBILITY_PROTECTED;
1845 error ("unrecognized visibility value \"%s\"", arg);
1849 case OPT_frandom_seed:
1850 /* The real switch is -fno-random-seed. */
1853 set_random_seed (NULL);
1856 case OPT_frandom_seed_:
1857 set_random_seed (arg);
1860 case OPT_fsched_verbose_:
1861 #ifdef INSN_SCHEDULING
1862 fix_sched_param ("verbose", arg);
1868 case OPT_fsched_stalled_insns_:
1869 opts->x_flag_sched_stalled_insns = value;
1870 if (opts->x_flag_sched_stalled_insns == 0)
1871 opts->x_flag_sched_stalled_insns = -1;
1874 case OPT_fsched_stalled_insns_dep_:
1875 opts->x_flag_sched_stalled_insns_dep = value;
1878 case OPT_fstack_check_:
1879 if (!strcmp (arg, "no"))
1880 flag_stack_check = NO_STACK_CHECK;
1881 else if (!strcmp (arg, "generic"))
1882 /* This is the old stack checking method. */
1883 flag_stack_check = STACK_CHECK_BUILTIN
1884 ? FULL_BUILTIN_STACK_CHECK
1885 : GENERIC_STACK_CHECK;
1886 else if (!strcmp (arg, "specific"))
1887 /* This is the new stack checking method. */
1888 flag_stack_check = STACK_CHECK_BUILTIN
1889 ? FULL_BUILTIN_STACK_CHECK
1890 : STACK_CHECK_STATIC_BUILTIN
1891 ? STATIC_BUILTIN_STACK_CHECK
1892 : GENERIC_STACK_CHECK;
1894 warning (0, "unknown stack check parameter \"%s\"", arg);
1897 case OPT_fstack_limit:
1898 /* The real switch is -fno-stack-limit. */
1904 case OPT_fstack_limit_register_:
1905 case OPT_fstack_limit_symbol_:
1909 case OPT_ftree_vectorizer_verbose_:
1910 vect_set_verbosity_level (arg);
1913 case OPT_ftls_model_:
1914 if (!strcmp (arg, "global-dynamic"))
1915 opts->x_flag_tls_default = TLS_MODEL_GLOBAL_DYNAMIC;
1916 else if (!strcmp (arg, "local-dynamic"))
1917 opts->x_flag_tls_default = TLS_MODEL_LOCAL_DYNAMIC;
1918 else if (!strcmp (arg, "initial-exec"))
1919 opts->x_flag_tls_default = TLS_MODEL_INITIAL_EXEC;
1920 else if (!strcmp (arg, "local-exec"))
1921 opts->x_flag_tls_default = TLS_MODEL_LOCAL_EXEC;
1923 warning (0, "unknown tls-model \"%s\"", arg);
1926 case OPT_fira_algorithm_:
1927 if (!strcmp (arg, "CB"))
1928 opts->x_flag_ira_algorithm = IRA_ALGORITHM_CB;
1929 else if (!strcmp (arg, "priority"))
1930 opts->x_flag_ira_algorithm = IRA_ALGORITHM_PRIORITY;
1932 warning (0, "unknown ira algorithm \"%s\"", arg);
1935 case OPT_fira_region_:
1936 if (!strcmp (arg, "one"))
1937 opts->x_flag_ira_region = IRA_REGION_ONE;
1938 else if (!strcmp (arg, "all"))
1939 opts->x_flag_ira_region = IRA_REGION_ALL;
1940 else if (!strcmp (arg, "mixed"))
1941 opts->x_flag_ira_region = IRA_REGION_MIXED;
1943 warning (0, "unknown ira region \"%s\"", arg);
1947 set_debug_level (NO_DEBUG, DEFAULT_GDB_EXTENSIONS, arg);
1951 set_debug_level (SDB_DEBUG, false, arg);
1955 if (value < 2 || value > 4)
1956 error ("dwarf version %d is not supported", value);
1958 dwarf_version = value;
1959 set_debug_level (DWARF2_DEBUG, false, "");
1963 set_debug_level (NO_DEBUG, 2, arg);
1968 set_debug_level (DBX_DEBUG, code == OPT_gstabs_, arg);
1972 set_debug_level (VMS_DEBUG, false, arg);
1977 set_debug_level (XCOFF_DEBUG, code == OPT_gxcoff_, arg);
1980 case OPT_pedantic_errors:
1981 opts->x_pedantic = 1;
1982 dc->pedantic_errors = 1;
1986 opts->x_flag_lto = "";
1990 dc->dc_inhibit_warnings = true;
1993 case OPT_fmax_errors_:
1994 dc->max_errors = value;
1997 case OPT_fuse_linker_plugin:
1998 /* No-op. Used by the driver and passed to us because it starts with f.*/
2002 /* If the flag was handled in a standard way, assume the lack of
2003 processing here is intentional. */
2004 gcc_assert (option_flag_var (scode, opts));
2011 /* Handle --param NAME=VALUE. */
2013 handle_param (struct gcc_options *opts, struct gcc_options *opts_set,
2019 arg = xstrdup (carg);
2020 equal = strchr (arg, '=');
2022 error ("%s: --param arguments should be of the form NAME=VALUE", arg);
2025 value = integral_argument (equal + 1);
2027 error ("invalid --param value %qs", equal + 1);
2031 set_param_value (arg, value,
2032 opts->x_param_values, opts_set->x_param_values);
2039 /* Used to set the level of strict aliasing warnings in OPTS,
2040 when no level is specified (i.e., when -Wstrict-aliasing, and not
2041 -Wstrict-aliasing=level was given).
2042 ONOFF is assumed to take value 1 when -Wstrict-aliasing is specified,
2043 and 0 otherwise. After calling this function, wstrict_aliasing will be
2044 set to the default value of -Wstrict_aliasing=level, currently 3. */
2046 set_Wstrict_aliasing (struct gcc_options *opts, int onoff)
2048 gcc_assert (onoff == 0 || onoff == 1);
2050 opts->x_warn_strict_aliasing = 3;
2052 opts->x_warn_strict_aliasing = 0;
2055 /* The following routines are useful in setting all the flags that
2056 -ffast-math and -fno-fast-math imply. */
2058 set_fast_math_flags (struct gcc_options *opts, int set)
2060 opts->x_flag_unsafe_math_optimizations = set;
2061 set_unsafe_math_optimizations_flags (opts, set);
2062 opts->x_flag_finite_math_only = set;
2063 opts->x_flag_errno_math = !set;
2066 opts->x_flag_signaling_nans = 0;
2067 opts->x_flag_rounding_math = 0;
2068 opts->x_flag_cx_limited_range = 1;
2072 /* When -funsafe-math-optimizations is set the following
2073 flags are set as well. */
2075 set_unsafe_math_optimizations_flags (struct gcc_options *opts, int set)
2077 opts->x_flag_trapping_math = !set;
2078 opts->x_flag_signed_zeros = !set;
2079 opts->x_flag_associative_math = set;
2080 opts->x_flag_reciprocal_math = set;
2083 /* Return true iff flags are set as if -ffast-math. */
2085 fast_math_flags_set_p (void)
2087 return (!flag_trapping_math
2088 && flag_unsafe_math_optimizations
2089 && flag_finite_math_only
2090 && !flag_signed_zeros
2091 && !flag_errno_math);
2094 /* Return true iff flags are set as if -ffast-math but using the flags stored
2095 in the struct cl_optimization structure. */
2097 fast_math_flags_struct_set_p (struct cl_optimization *opt)
2099 return (!opt->x_flag_trapping_math
2100 && opt->x_flag_unsafe_math_optimizations
2101 && opt->x_flag_finite_math_only
2102 && !opt->x_flag_signed_zeros
2103 && !opt->x_flag_errno_math);
2106 /* Handle a debug output -g switch. EXTENDED is true or false to support
2107 extended output (2 is special and means "-ggdb" was given). */
2109 set_debug_level (enum debug_info_type type, int extended, const char *arg)
2111 static bool type_explicit;
2113 use_gnu_debug_info_extensions = extended;
2115 if (type == NO_DEBUG)
2117 if (write_symbols == NO_DEBUG)
2119 write_symbols = PREFERRED_DEBUGGING_TYPE;
2123 #ifdef DWARF2_DEBUGGING_INFO
2124 write_symbols = DWARF2_DEBUG;
2125 #elif defined DBX_DEBUGGING_INFO
2126 write_symbols = DBX_DEBUG;
2130 if (write_symbols == NO_DEBUG)
2131 warning (0, "target system does not support debug output");
2136 /* Does it conflict with an already selected type? */
2137 if (type_explicit && write_symbols != NO_DEBUG && type != write_symbols)
2138 error ("debug format \"%s\" conflicts with prior selection",
2139 debug_type_names[type]);
2140 write_symbols = type;
2141 type_explicit = true;
2144 /* A debug flag without a level defaults to level 2. */
2147 if (!debug_info_level)
2148 debug_info_level = DINFO_LEVEL_NORMAL;
2152 int argval = integral_argument (arg);
2154 error ("unrecognised debug output level \"%s\"", arg);
2155 else if (argval > 3)
2156 error ("debug output level %s is too high", arg);
2158 debug_info_level = (enum debug_info_level) argval;
2162 /* Return 1 if option OPT_IDX is enabled in OPTS, 0 if it is disabled,
2163 or -1 if it isn't a simple on-off switch. */
2166 option_enabled (int opt_idx, void *opts)
2168 const struct cl_option *option = &(cl_options[opt_idx]);
2169 struct gcc_options *optsg = (struct gcc_options *) opts;
2170 void *flag_var = option_flag_var (opt_idx, optsg);
2173 switch (option->var_type)
2176 return *(int *) flag_var != 0;
2179 return *(int *) flag_var == option->var_value;
2181 case CLVC_BIT_CLEAR:
2182 return (*(int *) flag_var & option->var_value) == 0;
2185 return (*(int *) flag_var & option->var_value) != 0;
2194 /* Fill STATE with the current state of option OPTION in OPTS. Return
2195 true if there is some state to store. */
2198 get_option_state (struct gcc_options *opts, int option,
2199 struct cl_option_state *state)
2201 void *flag_var = option_flag_var (option, opts);
2206 switch (cl_options[option].var_type)
2210 state->data = flag_var;
2211 state->size = sizeof (int);
2214 case CLVC_BIT_CLEAR:
2216 state->ch = option_enabled (option, opts);
2217 state->data = &state->ch;
2222 state->data = *(const char **) flag_var;
2223 if (state->data == 0)
2225 state->size = strlen ((const char *) state->data) + 1;
2234 /* Enable (or disable if VALUE is 0) a warning option ARG (language
2235 mask LANG_MASK, option handlers HANDLERS) as an error for option
2236 structures OPTS and OPTS_SET, diagnostic context DC (possibly
2237 NULL), location LOC. This is used by -Werror=. */
2240 enable_warning_as_error (const char *arg, int value, unsigned int lang_mask,
2241 const struct cl_option_handlers *handlers,
2242 struct gcc_options *opts,
2243 struct gcc_options *opts_set,
2244 location_t loc, diagnostic_context *dc)
2249 new_option = XNEWVEC (char, strlen (arg) + 2);
2250 new_option[0] = 'W';
2251 strcpy (new_option + 1, arg);
2252 option_index = find_opt (new_option, lang_mask);
2253 if (option_index == OPT_SPECIAL_unknown)
2255 error ("-Werror=%s: no option -%s", arg, new_option);
2259 const diagnostic_t kind = value ? DK_ERROR : DK_WARNING;
2261 control_warning_option (option_index, (int) kind, value,
2263 handlers, opts, opts_set, dc);
2268 /* Return malloced memory for the name of the option OPTION_INDEX
2269 which enabled a diagnostic (context CONTEXT), originally of type
2270 ORIG_DIAG_KIND but possibly converted to DIAG_KIND by options such
2274 option_name (diagnostic_context *context, int option_index,
2275 diagnostic_t orig_diag_kind, diagnostic_t diag_kind)
2279 /* A warning classified as an error. */
2280 if ((orig_diag_kind == DK_WARNING || orig_diag_kind == DK_PEDWARN)
2281 && diag_kind == DK_ERROR)
2282 return concat (cl_options[OPT_Werror_].opt_text,
2283 /* Skip over "-W". */
2284 cl_options[option_index].opt_text + 2,
2286 /* A warning with option. */
2288 return xstrdup (cl_options[option_index].opt_text);
2290 /* A warning without option classified as an error. */
2291 else if (orig_diag_kind == DK_WARNING || orig_diag_kind == DK_PEDWARN
2292 || diag_kind == DK_WARNING)
2294 if (context->warning_as_error_requested)
2295 return xstrdup (cl_options[OPT_Werror].opt_text);
2297 return xstrdup (_("enabled by default"));