2010-11-13 Tobias Burnus <burnus@net-b.de>
[official-gcc.git] / gcc / opts.c
blobd4d7f1d82cc69b6cd5c56230ce79b48b91ea7350
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
11 version.
13 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 for more details.
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING3. If not see
20 <http://www.gnu.org/licenses/>. */
22 #include "config.h"
23 #include "system.h"
24 #include "intl.h"
25 #include "coretypes.h"
26 #include "tm.h"
27 #include "tree.h"
28 #include "rtl.h"
29 #include "expr.h"
30 #include "ggc.h"
31 #include "output.h"
32 #include "langhooks.h"
33 #include "opts.h"
34 #include "options.h"
35 #include "flags.h"
36 #include "toplev.h"
37 #include "params.h"
38 #include "diagnostic.h"
39 #include "opts-diagnostic.h"
40 #include "insn-attr.h" /* For INSN_SCHEDULING. */
41 #include "target.h"
42 #include "tree-pass.h"
43 #include "dbgcnt.h"
44 #include "debug.h"
45 #include "plugin.h"
46 #include "except.h"
47 #include "lto-streamer.h"
49 /* True if we should exit after parsing options. */
50 bool exit_after_options;
52 /* Type(s) of debugging information we are producing (if any). See
53 flags.h for the definitions of the different possible types of
54 debugging information. */
55 enum debug_info_type write_symbols = NO_DEBUG;
57 /* Level of debugging information we are producing. See flags.h for
58 the definitions of the different possible levels. */
59 enum debug_info_level debug_info_level = DINFO_LEVEL_NONE;
61 /* A major contribution to object and executable size is debug
62 information size. A major contribution to debug information size
63 is struct descriptions replicated in several object files. The
64 following flags attempt to reduce this information. The basic
65 idea is to not emit struct debugging information in the current
66 compilation unit when that information will be generated by
67 another compilation unit.
69 Debug information for a struct defined in the current source
70 file should be generated in the object file. Likewise the
71 debug information for a struct defined in a header should be
72 generated in the object file of the corresponding source file.
73 Both of these case are handled when the base name of the file of
74 the struct definition matches the base name of the source file
75 of the current compilation unit. This matching emits minimal
76 struct debugging information.
78 The base file name matching rule above will fail to emit debug
79 information for structs defined in system headers. So a second
80 category of files includes system headers in addition to files
81 with matching bases.
83 The remaining types of files are library headers and application
84 headers. We cannot currently distinguish these two types. */
86 enum debug_struct_file
88 DINFO_STRUCT_FILE_NONE, /* Debug no structs. */
89 DINFO_STRUCT_FILE_BASE, /* Debug structs defined in files with the
90 same base name as the compilation unit. */
91 DINFO_STRUCT_FILE_SYS, /* Also debug structs defined in system
92 header files. */
93 DINFO_STRUCT_FILE_ANY /* Debug structs defined in all files. */
96 /* Generic structs (e.g. templates not explicitly specialized)
97 may not have a compilation unit associated with them, and so
98 may need to be treated differently from ordinary structs.
100 Structs only handled by reference (indirectly), will also usually
101 not need as much debugging information. */
103 static enum debug_struct_file debug_struct_ordinary[DINFO_USAGE_NUM_ENUMS]
104 = { DINFO_STRUCT_FILE_ANY, DINFO_STRUCT_FILE_ANY, DINFO_STRUCT_FILE_ANY };
105 static enum debug_struct_file debug_struct_generic[DINFO_USAGE_NUM_ENUMS]
106 = { DINFO_STRUCT_FILE_ANY, DINFO_STRUCT_FILE_ANY, DINFO_STRUCT_FILE_ANY };
108 /* Run the second compilation of -fcompare-debug. Not defined using
109 Var in common.opt because this is used in Ada code and so must be
110 an actual variable not a macro. */
111 int flag_compare_debug;
113 /* Parse the -femit-struct-debug-detailed option value
114 and set the flag variables. */
116 #define MATCH( prefix, string ) \
117 ((strncmp (prefix, string, sizeof prefix - 1) == 0) \
118 ? ((string += sizeof prefix - 1), 1) : 0)
120 void
121 set_struct_debug_option (const char *spec)
123 /* various labels for comparison */
124 static char dfn_lbl[] = "dfn:", dir_lbl[] = "dir:", ind_lbl[] = "ind:";
125 static char ord_lbl[] = "ord:", gen_lbl[] = "gen:";
126 static char none_lbl[] = "none", any_lbl[] = "any";
127 static char base_lbl[] = "base", sys_lbl[] = "sys";
129 enum debug_struct_file files = DINFO_STRUCT_FILE_ANY;
130 /* Default is to apply to as much as possible. */
131 enum debug_info_usage usage = DINFO_USAGE_NUM_ENUMS;
132 int ord = 1, gen = 1;
134 /* What usage? */
135 if (MATCH (dfn_lbl, spec))
136 usage = DINFO_USAGE_DFN;
137 else if (MATCH (dir_lbl, spec))
138 usage = DINFO_USAGE_DIR_USE;
139 else if (MATCH (ind_lbl, spec))
140 usage = DINFO_USAGE_IND_USE;
142 /* Generics or not? */
143 if (MATCH (ord_lbl, spec))
144 gen = 0;
145 else if (MATCH (gen_lbl, spec))
146 ord = 0;
148 /* What allowable environment? */
149 if (MATCH (none_lbl, spec))
150 files = DINFO_STRUCT_FILE_NONE;
151 else if (MATCH (any_lbl, spec))
152 files = DINFO_STRUCT_FILE_ANY;
153 else if (MATCH (sys_lbl, spec))
154 files = DINFO_STRUCT_FILE_SYS;
155 else if (MATCH (base_lbl, spec))
156 files = DINFO_STRUCT_FILE_BASE;
157 else
158 error ("argument %qs to %<-femit-struct-debug-detailed%> not recognized",
159 spec);
161 /* Effect the specification. */
162 if (usage == DINFO_USAGE_NUM_ENUMS)
164 if (ord)
166 debug_struct_ordinary[DINFO_USAGE_DFN] = files;
167 debug_struct_ordinary[DINFO_USAGE_DIR_USE] = files;
168 debug_struct_ordinary[DINFO_USAGE_IND_USE] = files;
170 if (gen)
172 debug_struct_generic[DINFO_USAGE_DFN] = files;
173 debug_struct_generic[DINFO_USAGE_DIR_USE] = files;
174 debug_struct_generic[DINFO_USAGE_IND_USE] = files;
177 else
179 if (ord)
180 debug_struct_ordinary[usage] = files;
181 if (gen)
182 debug_struct_generic[usage] = files;
185 if (*spec == ',')
186 set_struct_debug_option (spec+1);
187 else
189 /* No more -femit-struct-debug-detailed specifications.
190 Do final checks. */
191 if (*spec != '\0')
192 error ("argument %qs to %<-femit-struct-debug-detailed%> unknown",
193 spec);
194 if (debug_struct_ordinary[DINFO_USAGE_DIR_USE]
195 < debug_struct_ordinary[DINFO_USAGE_IND_USE]
196 || debug_struct_generic[DINFO_USAGE_DIR_USE]
197 < debug_struct_generic[DINFO_USAGE_IND_USE])
198 error ("%<-femit-struct-debug-detailed=dir:...%> must allow at least"
199 " as much as %<-femit-struct-debug-detailed=ind:...%>");
203 /* Find the base name of a path, stripping off both directories and
204 a single final extension. */
205 static int
206 base_of_path (const char *path, const char **base_out)
208 const char *base = path;
209 const char *dot = 0;
210 const char *p = path;
211 char c = *p;
212 while (c)
214 if (IS_DIR_SEPARATOR(c))
216 base = p + 1;
217 dot = 0;
219 else if (c == '.')
220 dot = p;
221 c = *++p;
223 if (!dot)
224 dot = p;
225 *base_out = base;
226 return dot - base;
229 /* Match the base name of a file to the base name of a compilation unit. */
231 static const char *main_input_basename;
232 static int main_input_baselength;
234 static int
235 matches_main_base (const char *path)
237 /* Cache the last query. */
238 static const char *last_path = NULL;
239 static int last_match = 0;
240 if (path != last_path)
242 const char *base;
243 int length = base_of_path (path, &base);
244 last_path = path;
245 last_match = (length == main_input_baselength
246 && memcmp (base, main_input_basename, length) == 0);
248 return last_match;
251 #ifdef DEBUG_DEBUG_STRUCT
253 static int
254 dump_struct_debug (tree type, enum debug_info_usage usage,
255 enum debug_struct_file criterion, int generic,
256 int matches, int result)
258 /* Find the type name. */
259 tree type_decl = TYPE_STUB_DECL (type);
260 tree t = type_decl;
261 const char *name = 0;
262 if (TREE_CODE (t) == TYPE_DECL)
263 t = DECL_NAME (t);
264 if (t)
265 name = IDENTIFIER_POINTER (t);
267 fprintf (stderr, " struct %d %s %s %s %s %d %p %s\n",
268 criterion,
269 DECL_IN_SYSTEM_HEADER (type_decl) ? "sys" : "usr",
270 matches ? "bas" : "hdr",
271 generic ? "gen" : "ord",
272 usage == DINFO_USAGE_DFN ? ";" :
273 usage == DINFO_USAGE_DIR_USE ? "." : "*",
274 result,
275 (void*) type_decl, name);
276 return result;
278 #define DUMP_GSTRUCT(type, usage, criterion, generic, matches, result) \
279 dump_struct_debug (type, usage, criterion, generic, matches, result)
281 #else
283 #define DUMP_GSTRUCT(type, usage, criterion, generic, matches, result) \
284 (result)
286 #endif
289 bool
290 should_emit_struct_debug (tree type, enum debug_info_usage usage)
292 enum debug_struct_file criterion;
293 tree type_decl;
294 bool generic = lang_hooks.types.generic_p (type);
296 if (generic)
297 criterion = debug_struct_generic[usage];
298 else
299 criterion = debug_struct_ordinary[usage];
301 if (criterion == DINFO_STRUCT_FILE_NONE)
302 return DUMP_GSTRUCT (type, usage, criterion, generic, false, false);
303 if (criterion == DINFO_STRUCT_FILE_ANY)
304 return DUMP_GSTRUCT (type, usage, criterion, generic, false, true);
306 type_decl = TYPE_STUB_DECL (type);
308 if (criterion == DINFO_STRUCT_FILE_SYS && DECL_IN_SYSTEM_HEADER (type_decl))
309 return DUMP_GSTRUCT (type, usage, criterion, generic, false, true);
311 if (matches_main_base (DECL_SOURCE_FILE (type_decl)))
312 return DUMP_GSTRUCT (type, usage, criterion, generic, true, true);
313 return DUMP_GSTRUCT (type, usage, criterion, generic, false, false);
316 /* Nonzero means use GNU-only extensions in the generated symbolic
317 debugging information. Currently, this only has an effect when
318 write_symbols is set to DBX_DEBUG, XCOFF_DEBUG, or DWARF_DEBUG. */
319 bool use_gnu_debug_info_extensions;
321 /* Global visibility options. */
322 struct visibility_flags visibility_options;
324 /* What to print when a switch has no documentation. */
325 static const char undocumented_msg[] = N_("This switch lacks documentation");
327 /* Functions excluded from profiling. */
329 typedef char *char_p; /* For DEF_VEC_P. */
330 DEF_VEC_P(char_p);
331 DEF_VEC_ALLOC_P(char_p,heap);
333 static VEC(char_p,heap) *flag_instrument_functions_exclude_functions;
334 static VEC(char_p,heap) *flag_instrument_functions_exclude_files;
336 typedef const char *const_char_p; /* For DEF_VEC_P. */
337 DEF_VEC_P(const_char_p);
338 DEF_VEC_ALLOC_P(const_char_p,heap);
340 static VEC(const_char_p,heap) *ignored_options;
342 /* Input file names. */
343 const char **in_fnames;
344 unsigned num_in_fnames;
346 static bool common_handle_option (struct gcc_options *opts,
347 struct gcc_options *opts_set,
348 const struct cl_decoded_option *decoded,
349 unsigned int lang_mask, int kind,
350 location_t loc,
351 const struct cl_option_handlers *handlers,
352 diagnostic_context *dc);
353 static void handle_param (struct gcc_options *opts,
354 struct gcc_options *opts_set, const char *carg);
355 static char *write_langs (unsigned int lang_mask);
356 static void complain_wrong_lang (const struct cl_decoded_option *,
357 unsigned int lang_mask);
358 static void set_debug_level (enum debug_info_type type, int extended,
359 const char *arg);
360 static void set_fast_math_flags (struct gcc_options *opts, int set);
361 static void set_unsafe_math_optimizations_flags (struct gcc_options *opts,
362 int set);
363 static void enable_warning_as_error (const char *arg, int value,
364 unsigned int lang_mask,
365 const struct cl_option_handlers *handlers,
366 struct gcc_options *opts,
367 struct gcc_options *opts_set,
368 location_t loc,
369 diagnostic_context *dc);
371 /* Return a malloced slash-separated list of languages in MASK. */
372 static char *
373 write_langs (unsigned int mask)
375 unsigned int n = 0, len = 0;
376 const char *lang_name;
377 char *result;
379 for (n = 0; (lang_name = lang_names[n]) != 0; n++)
380 if (mask & (1U << n))
381 len += strlen (lang_name) + 1;
383 result = XNEWVEC (char, len);
384 len = 0;
385 for (n = 0; (lang_name = lang_names[n]) != 0; n++)
386 if (mask & (1U << n))
388 if (len)
389 result[len++] = '/';
390 strcpy (result + len, lang_name);
391 len += strlen (lang_name);
394 result[len] = 0;
396 return result;
399 /* Complain that switch DECODED does not apply to this front end (mask
400 LANG_MASK). */
401 static void
402 complain_wrong_lang (const struct cl_decoded_option *decoded,
403 unsigned int lang_mask)
405 const struct cl_option *option = &cl_options[decoded->opt_index];
406 const char *text = decoded->orig_option_with_args_text;
407 char *ok_langs = NULL, *bad_lang = NULL;
408 unsigned int opt_flags = option->flags;
410 if (!lang_hooks.complain_wrong_lang_p (option))
411 return;
413 opt_flags &= ((1U << cl_lang_count) - 1) | CL_DRIVER;
414 if (opt_flags != CL_DRIVER)
415 ok_langs = write_langs (opt_flags);
416 if (lang_mask != CL_DRIVER)
417 bad_lang = write_langs (lang_mask);
419 if (opt_flags == CL_DRIVER)
420 error ("command line option %qs is valid for the driver but not for %s",
421 text, bad_lang);
422 else if (lang_mask == CL_DRIVER)
423 gcc_unreachable ();
424 else
425 /* Eventually this should become a hard error IMO. */
426 warning (0, "command line option %qs is valid for %s but not for %s",
427 text, ok_langs, bad_lang);
429 free (ok_langs);
430 free (bad_lang);
433 /* Buffer the unknown option described by the string OPT. Currently,
434 we only complain about unknown -Wno-* options if they may have
435 prevented a diagnostic. Otherwise, we just ignore them.
436 Note that if we do complain, it is only as a warning, not an error;
437 passing the compiler an unrecognised -Wno-* option should never
438 change whether the compilation succeeds or fails. */
440 static void postpone_unknown_option_warning(const char *opt)
442 VEC_safe_push (const_char_p, heap, ignored_options, opt);
445 /* Produce a warning for each option previously buffered. */
447 void print_ignored_options (void)
449 location_t saved_loc = input_location;
451 input_location = 0;
453 while (!VEC_empty (const_char_p, ignored_options))
455 const char *opt;
456 opt = VEC_pop (const_char_p, ignored_options);
457 warning (0, "unrecognized command line option \"%s\"", opt);
460 input_location = saved_loc;
463 /* Handle an unknown option DECODED, returning true if an error should be
464 given. */
466 static bool
467 unknown_option_callback (const struct cl_decoded_option *decoded)
469 const char *opt = decoded->arg;
471 if (opt[1] == 'W' && opt[2] == 'n' && opt[3] == 'o' && opt[4] == '-'
472 && !(decoded->errors & CL_ERR_NEGATIVE))
474 /* We don't generate warnings for unknown -Wno-* options unless
475 we issue diagnostics. */
476 postpone_unknown_option_warning (opt);
477 return false;
479 else
480 return true;
483 /* Note that an option DECODED has been successfully handled with a
484 handler for mask MASK. */
486 static void
487 post_handling_callback (const struct cl_decoded_option *decoded ATTRIBUTE_UNUSED,
488 unsigned int mask ATTRIBUTE_UNUSED)
490 #ifdef ENABLE_LTO
491 lto_register_user_option (decoded->opt_index, decoded->arg,
492 decoded->value, mask);
493 #endif
496 /* Handle a front-end option; arguments and return value as for
497 handle_option. */
499 static bool
500 lang_handle_option (struct gcc_options *opts,
501 struct gcc_options *opts_set,
502 const struct cl_decoded_option *decoded,
503 unsigned int lang_mask ATTRIBUTE_UNUSED, int kind,
504 location_t loc,
505 const struct cl_option_handlers *handlers,
506 diagnostic_context *dc)
508 gcc_assert (opts == &global_options);
509 gcc_assert (opts_set == &global_options_set);
510 gcc_assert (dc == global_dc);
511 gcc_assert (decoded->canonical_option_num_elements <= 2);
512 return lang_hooks.handle_option (decoded->opt_index, decoded->arg,
513 decoded->value, kind, loc, handlers);
516 /* Handle a back-end option; arguments and return value as for
517 handle_option. */
519 static bool
520 target_handle_option (struct gcc_options *opts,
521 struct gcc_options *opts_set,
522 const struct cl_decoded_option *decoded,
523 unsigned int lang_mask ATTRIBUTE_UNUSED, int kind,
524 location_t loc,
525 const struct cl_option_handlers *handlers ATTRIBUTE_UNUSED,
526 diagnostic_context *dc)
528 gcc_assert (opts == &global_options);
529 gcc_assert (opts_set == &global_options_set);
530 gcc_assert (dc == global_dc);
531 gcc_assert (decoded->canonical_option_num_elements <= 2);
532 gcc_assert (kind == DK_UNSPECIFIED);
533 gcc_assert (loc == UNKNOWN_LOCATION);
534 return targetm.handle_option (decoded->opt_index, decoded->arg,
535 decoded->value);
538 /* Handle FILENAME from the command line. */
539 static void
540 add_input_filename (const char *filename)
542 num_in_fnames++;
543 in_fnames = XRESIZEVEC (const char *, in_fnames, num_in_fnames);
544 in_fnames[num_in_fnames - 1] = filename;
547 /* Add comma-separated strings to a char_p vector. */
549 static void
550 add_comma_separated_to_vector (VEC(char_p,heap) **pvec, const char* arg)
552 char *tmp;
553 char *r;
554 char *w;
555 char *token_start;
557 /* We never free this string. */
558 tmp = xstrdup (arg);
560 r = tmp;
561 w = tmp;
562 token_start = tmp;
564 while (*r != '\0')
566 if (*r == ',')
568 *w++ = '\0';
569 ++r;
570 VEC_safe_push (char_p, heap, *pvec, token_start);
571 token_start = w;
573 if (*r == '\\' && r[1] == ',')
575 *w++ = ',';
576 r += 2;
578 else
579 *w++ = *r++;
581 if (*token_start != '\0')
582 VEC_safe_push (char_p, heap, *pvec, token_start);
585 /* Return whether we should exclude FNDECL from instrumentation. */
587 bool
588 flag_instrument_functions_exclude_p (tree fndecl)
590 if (VEC_length (char_p, flag_instrument_functions_exclude_functions) > 0)
592 const char *name;
593 int i;
594 char *s;
596 name = lang_hooks.decl_printable_name (fndecl, 0);
597 FOR_EACH_VEC_ELT (char_p, flag_instrument_functions_exclude_functions,
598 i, s)
599 if (strstr (name, s) != NULL)
600 return true;
603 if (VEC_length (char_p, flag_instrument_functions_exclude_files) > 0)
605 const char *name;
606 int i;
607 char *s;
609 name = DECL_SOURCE_FILE (fndecl);
610 FOR_EACH_VEC_ELT (char_p, flag_instrument_functions_exclude_files, i, s)
611 if (strstr (name, s) != NULL)
612 return true;
615 return false;
619 /* Handle the vector of command line options (located at LOC), storing
620 the results of processing DECODED_OPTIONS and DECODED_OPTIONS_COUNT
621 in OPTS and OPTS_SET and using DC for diagnostic state. LANG_MASK
622 contains has a single bit set representing the current language.
623 HANDLERS describes what functions to call for the options. */
624 static void
625 read_cmdline_options (struct gcc_options *opts, struct gcc_options *opts_set,
626 struct cl_decoded_option *decoded_options,
627 unsigned int decoded_options_count,
628 location_t loc,
629 unsigned int lang_mask,
630 const struct cl_option_handlers *handlers,
631 diagnostic_context *dc)
633 unsigned int i;
635 for (i = 1; i < decoded_options_count; i++)
637 if (decoded_options[i].opt_index == OPT_SPECIAL_input_file)
639 /* Input files should only ever appear on the main command
640 line. */
641 gcc_assert (opts == &global_options);
642 gcc_assert (opts_set == &global_options_set);
644 if (main_input_filename == NULL)
646 main_input_filename = decoded_options[i].arg;
647 main_input_baselength
648 = base_of_path (main_input_filename, &main_input_basename);
650 add_input_filename (decoded_options[i].arg);
651 continue;
654 read_cmdline_option (opts, opts_set,
655 decoded_options + i, loc, lang_mask, handlers,
656 dc);
660 /* Language mask determined at initialization. */
661 static unsigned int initial_lang_mask;
663 /* Initialize global options-related settings at start-up. */
665 void
666 init_options_once (void)
668 /* Perform language-specific options initialization. */
669 initial_lang_mask = lang_hooks.option_lang_mask ();
671 lang_hooks.initialize_diagnostics (global_dc);
674 /* Initialize OPTS and OPTS_SET before using them in parsing options. */
676 void
677 init_options_struct (struct gcc_options *opts, struct gcc_options *opts_set)
679 size_t num_params = get_num_compiler_params ();
681 *opts = global_options_init;
682 memset (opts_set, 0, sizeof (*opts_set));
684 opts->x_param_values = XNEWVEC (int, num_params);
685 opts_set->x_param_values = XCNEWVEC (int, num_params);
686 init_param_values (opts->x_param_values);
688 /* Use priority coloring if cover classes is not defined for the
689 target. */
690 if (targetm.ira_cover_classes == NULL)
691 opts->x_flag_ira_algorithm = IRA_ALGORITHM_PRIORITY;
693 /* Initialize whether `char' is signed. */
694 opts->x_flag_signed_char = DEFAULT_SIGNED_CHAR;
695 /* Set this to a special "uninitialized" value. The actual default
696 is set after target options have been processed. */
697 opts->x_flag_short_enums = 2;
699 /* Initialize target_flags before targetm.target_option.optimization
700 so the latter can modify it. */
701 opts->x_target_flags = targetm.default_target_flags;
703 /* Some targets have ABI-specified unwind tables. */
704 opts->x_flag_unwind_tables = targetm.unwind_tables_default;
706 /* Some targets have other target-specific initialization. */
707 targetm.target_option.init_struct (opts);
710 /* Decode command-line options to an array, like
711 decode_cmdline_options_to_array and with the same arguments but
712 using the default lang_mask. */
714 void
715 decode_cmdline_options_to_array_default_mask (unsigned int argc,
716 const char **argv,
717 struct cl_decoded_option **decoded_options,
718 unsigned int *decoded_options_count)
720 decode_cmdline_options_to_array (argc, argv,
721 initial_lang_mask | CL_COMMON | CL_TARGET,
722 decoded_options, decoded_options_count);
725 /* If indicated by the optimization level LEVEL (-Os if SIZE is set,
726 -Ofast if FAST is set), apply the option DEFAULT_OPT to OPTS and
727 OPTS_SET, diagnostic context DC, location LOC, with language mask
728 LANG_MASK and option handlers HANDLERS. */
730 static void
731 maybe_default_option (struct gcc_options *opts,
732 struct gcc_options *opts_set,
733 const struct default_options *default_opt,
734 int level, bool size, bool fast,
735 unsigned int lang_mask,
736 const struct cl_option_handlers *handlers,
737 location_t loc,
738 diagnostic_context *dc)
740 const struct cl_option *option = &cl_options[default_opt->opt_index];
741 bool enabled;
743 if (size)
744 gcc_assert (level == 2);
745 if (fast)
746 gcc_assert (level == 3);
748 switch (default_opt->levels)
750 case OPT_LEVELS_ALL:
751 enabled = true;
752 break;
754 case OPT_LEVELS_0_ONLY:
755 enabled = (level == 0);
756 break;
758 case OPT_LEVELS_1_PLUS:
759 enabled = (level >= 1);
760 break;
762 case OPT_LEVELS_1_PLUS_SPEED_ONLY:
763 enabled = (level >= 1 && !size);
764 break;
766 case OPT_LEVELS_2_PLUS:
767 enabled = (level >= 2);
768 break;
770 case OPT_LEVELS_2_PLUS_SPEED_ONLY:
771 enabled = (level >= 2 && !size);
772 break;
774 case OPT_LEVELS_3_PLUS:
775 enabled = (level >= 3);
776 break;
778 case OPT_LEVELS_3_PLUS_AND_SIZE:
779 enabled = (level >= 3 || size);
780 break;
782 case OPT_LEVELS_SIZE:
783 enabled = size;
784 break;
786 case OPT_LEVELS_FAST:
787 enabled = fast;
788 break;
790 case OPT_LEVELS_NONE:
791 default:
792 gcc_unreachable ();
795 if (enabled)
796 handle_generated_option (opts, opts_set, default_opt->opt_index,
797 default_opt->arg, default_opt->value,
798 lang_mask, DK_UNSPECIFIED, loc,
799 handlers, dc);
800 else if (default_opt->arg == NULL
801 && !(option->flags & CL_REJECT_NEGATIVE))
802 handle_generated_option (opts, opts_set, default_opt->opt_index,
803 default_opt->arg, !default_opt->value,
804 lang_mask, DK_UNSPECIFIED, loc,
805 handlers, dc);
808 /* As indicated by the optimization level LEVEL (-Os if SIZE is set,
809 -Ofast if FAST is set), apply the options in array DEFAULT_OPTS to
810 OPTS and OPTS_SET, diagnostic context DC, location LOC, with
811 language mask LANG_MASK and option handlers HANDLERS. */
813 static void
814 maybe_default_options (struct gcc_options *opts,
815 struct gcc_options *opts_set,
816 const struct default_options *default_opts,
817 int level, bool size, bool fast,
818 unsigned int lang_mask,
819 const struct cl_option_handlers *handlers,
820 location_t loc,
821 diagnostic_context *dc)
823 size_t i;
825 for (i = 0; default_opts[i].levels != OPT_LEVELS_NONE; i++)
826 maybe_default_option (opts, opts_set, &default_opts[i],
827 level, size, fast, lang_mask, handlers, loc, dc);
830 /* Table of options enabled by default at different levels. */
832 static const struct default_options default_options_table[] =
834 /* -O1 optimizations. */
835 { OPT_LEVELS_1_PLUS, OPT_fdefer_pop, NULL, 1 },
836 #ifdef DELAY_SLOTS
837 { OPT_LEVELS_1_PLUS, OPT_fdelayed_branch, NULL, 1 },
838 #endif
839 { OPT_LEVELS_1_PLUS, OPT_fguess_branch_probability, NULL, 1 },
840 { OPT_LEVELS_1_PLUS, OPT_fcprop_registers, NULL, 1 },
841 { OPT_LEVELS_1_PLUS, OPT_fforward_propagate, NULL, 1 },
842 { OPT_LEVELS_1_PLUS, OPT_fif_conversion, NULL, 1 },
843 { OPT_LEVELS_1_PLUS, OPT_fif_conversion2, NULL, 1 },
844 { OPT_LEVELS_1_PLUS, OPT_fipa_pure_const, NULL, 1 },
845 { OPT_LEVELS_1_PLUS, OPT_fipa_reference, NULL, 1 },
846 { OPT_LEVELS_1_PLUS, OPT_fipa_profile, NULL, 1 },
847 { OPT_LEVELS_1_PLUS, OPT_fmerge_constants, NULL, 1 },
848 { OPT_LEVELS_1_PLUS, OPT_fsplit_wide_types, NULL, 1 },
849 { OPT_LEVELS_1_PLUS, OPT_ftree_ccp, NULL, 1 },
850 { OPT_LEVELS_1_PLUS, OPT_ftree_bit_ccp, NULL, 1 },
851 { OPT_LEVELS_1_PLUS, OPT_ftree_dce, NULL, 1 },
852 { OPT_LEVELS_1_PLUS, OPT_ftree_dominator_opts, NULL, 1 },
853 { OPT_LEVELS_1_PLUS, OPT_ftree_dse, NULL, 1 },
854 { OPT_LEVELS_1_PLUS, OPT_ftree_ter, NULL, 1 },
855 { OPT_LEVELS_1_PLUS, OPT_ftree_sra, NULL, 1 },
856 { OPT_LEVELS_1_PLUS, OPT_ftree_copyrename, NULL, 1 },
857 { OPT_LEVELS_1_PLUS, OPT_ftree_fre, NULL, 1 },
858 { OPT_LEVELS_1_PLUS, OPT_ftree_copy_prop, NULL, 1 },
859 { OPT_LEVELS_1_PLUS, OPT_ftree_sink, NULL, 1 },
860 { OPT_LEVELS_1_PLUS, OPT_ftree_ch, NULL, 1 },
861 { OPT_LEVELS_1_PLUS, OPT_fcombine_stack_adjustments, NULL, 1 },
863 /* -O2 optimizations. */
864 { OPT_LEVELS_2_PLUS, OPT_finline_small_functions, NULL, 1 },
865 { OPT_LEVELS_2_PLUS, OPT_findirect_inlining, NULL, 1 },
866 { OPT_LEVELS_2_PLUS, OPT_fpartial_inlining, NULL, 1 },
867 { OPT_LEVELS_2_PLUS, OPT_fthread_jumps, NULL, 1 },
868 { OPT_LEVELS_2_PLUS, OPT_fcrossjumping, NULL, 1 },
869 { OPT_LEVELS_2_PLUS, OPT_foptimize_sibling_calls, NULL, 1 },
870 { OPT_LEVELS_2_PLUS, OPT_fcse_follow_jumps, NULL, 1 },
871 { OPT_LEVELS_2_PLUS, OPT_fgcse, NULL, 1 },
872 { OPT_LEVELS_2_PLUS, OPT_fexpensive_optimizations, NULL, 1 },
873 { OPT_LEVELS_2_PLUS, OPT_frerun_cse_after_loop, NULL, 1 },
874 { OPT_LEVELS_2_PLUS, OPT_fcaller_saves, NULL, 1 },
875 { OPT_LEVELS_2_PLUS, OPT_fpeephole2, NULL, 1 },
876 #ifdef INSN_SCHEDULING
877 /* Only run the pre-regalloc scheduling pass if optimizing for speed. */
878 { OPT_LEVELS_2_PLUS_SPEED_ONLY, OPT_fschedule_insns, NULL, 1 },
879 { OPT_LEVELS_2_PLUS, OPT_fschedule_insns2, NULL, 1 },
880 #endif
881 { OPT_LEVELS_2_PLUS, OPT_fregmove, NULL, 1 },
882 { OPT_LEVELS_2_PLUS, OPT_fstrict_aliasing, NULL, 1 },
883 { OPT_LEVELS_2_PLUS, OPT_fstrict_overflow, NULL, 1 },
884 { OPT_LEVELS_2_PLUS, OPT_freorder_blocks, NULL, 1 },
885 { OPT_LEVELS_2_PLUS, OPT_freorder_functions, NULL, 1 },
886 { OPT_LEVELS_2_PLUS, OPT_ftree_vrp, NULL, 1 },
887 { OPT_LEVELS_2_PLUS, OPT_ftree_builtin_call_dce, NULL, 1 },
888 { OPT_LEVELS_2_PLUS, OPT_ftree_pre, NULL, 1 },
889 { OPT_LEVELS_2_PLUS, OPT_ftree_switch_conversion, NULL, 1 },
890 { OPT_LEVELS_2_PLUS, OPT_fipa_cp, NULL, 1 },
891 { OPT_LEVELS_2_PLUS, OPT_fipa_sra, NULL, 1 },
892 { OPT_LEVELS_2_PLUS, OPT_falign_loops, NULL, 1 },
893 { OPT_LEVELS_2_PLUS, OPT_falign_jumps, NULL, 1 },
894 { OPT_LEVELS_2_PLUS, OPT_falign_labels, NULL, 1 },
895 { OPT_LEVELS_2_PLUS, OPT_falign_functions, NULL, 1 },
897 /* -O3 optimizations. */
898 { OPT_LEVELS_3_PLUS, OPT_ftree_loop_distribute_patterns, NULL, 1 },
899 { OPT_LEVELS_3_PLUS, OPT_fpredictive_commoning, NULL, 1 },
900 /* Inlining of functions reducing size is a good idea with -Os
901 regardless of them being declared inline. */
902 { OPT_LEVELS_3_PLUS_AND_SIZE, OPT_finline_functions, NULL, 1 },
903 { OPT_LEVELS_3_PLUS, OPT_funswitch_loops, NULL, 1 },
904 { OPT_LEVELS_3_PLUS, OPT_fgcse_after_reload, NULL, 1 },
905 { OPT_LEVELS_3_PLUS, OPT_ftree_vectorize, NULL, 1 },
906 { OPT_LEVELS_3_PLUS, OPT_fipa_cp_clone, NULL, 1 },
908 /* -Ofast adds optimizations to -O3. */
909 { OPT_LEVELS_FAST, OPT_ffast_math, NULL, 1 },
911 { OPT_LEVELS_NONE, 0, NULL, 0 }
914 /* Default the options in OPTS and OPTS_SET based on the optimization
915 settings in DECODED_OPTIONS and DECODED_OPTIONS_COUNT. */
916 static void
917 default_options_optimization (struct gcc_options *opts,
918 struct gcc_options *opts_set,
919 struct cl_decoded_option *decoded_options,
920 unsigned int decoded_options_count,
921 location_t loc,
922 unsigned int lang_mask,
923 const struct cl_option_handlers *handlers,
924 diagnostic_context *dc)
926 unsigned int i;
927 int opt2;
928 int ofast = 0;
930 /* Scan to see what optimization level has been specified. That will
931 determine the default value of many flags. */
932 for (i = 1; i < decoded_options_count; i++)
934 struct cl_decoded_option *opt = &decoded_options[i];
935 switch (opt->opt_index)
937 case OPT_O:
938 if (*opt->arg == '\0')
940 opts->x_optimize = 1;
941 opts->x_optimize_size = 0;
942 ofast = 0;
944 else
946 const int optimize_val = integral_argument (opt->arg);
947 if (optimize_val == -1)
948 error ("argument to %qs should be a non-negative integer",
949 "-O");
950 else
952 opts->x_optimize = optimize_val;
953 if ((unsigned int) opts->x_optimize > 255)
954 opts->x_optimize = 255;
955 opts->x_optimize_size = 0;
956 ofast = 0;
959 break;
961 case OPT_Os:
962 opts->x_optimize_size = 1;
964 /* Optimizing for size forces optimize to be 2. */
965 opts->x_optimize = 2;
966 ofast = 0;
967 break;
969 case OPT_Ofast:
970 /* -Ofast only adds flags to -O3. */
971 opts->x_optimize_size = 0;
972 opts->x_optimize = 3;
973 ofast = 1;
974 break;
976 default:
977 /* Ignore other options in this prescan. */
978 break;
982 maybe_default_options (opts, opts_set, default_options_table,
983 opts->x_optimize, opts->x_optimize_size,
984 ofast, lang_mask, handlers, loc, dc);
986 /* -O2 param settings. */
987 opt2 = (opts->x_optimize >= 2);
989 /* Track fields in field-sensitive alias analysis. */
990 maybe_set_param_value
991 (PARAM_MAX_FIELDS_FOR_FIELD_SENSITIVE,
992 opt2 ? 100 : default_param_value (PARAM_MAX_FIELDS_FOR_FIELD_SENSITIVE),
993 opts->x_param_values, opts_set->x_param_values);
995 /* For -O1 only do loop invariant motion for very small loops. */
996 maybe_set_param_value
997 (PARAM_LOOP_INVARIANT_MAX_BBS_IN_LOOP,
998 opt2 ? default_param_value (PARAM_LOOP_INVARIANT_MAX_BBS_IN_LOOP) : 1000,
999 opts->x_param_values, opts_set->x_param_values);
1001 if (opts->x_optimize_size)
1002 /* We want to crossjump as much as possible. */
1003 maybe_set_param_value (PARAM_MIN_CROSSJUMP_INSNS, 1,
1004 opts->x_param_values, opts_set->x_param_values);
1005 else
1006 maybe_set_param_value (PARAM_MIN_CROSSJUMP_INSNS,
1007 default_param_value (PARAM_MIN_CROSSJUMP_INSNS),
1008 opts->x_param_values, opts_set->x_param_values);
1010 /* Allow default optimizations to be specified on a per-machine basis. */
1011 maybe_default_options (opts, opts_set,
1012 targetm.target_option.optimization_table,
1013 opts->x_optimize, opts->x_optimize_size,
1014 ofast, lang_mask, handlers, loc, dc);
1017 static void finish_options (struct gcc_options *, struct gcc_options *);
1019 /* Set *HANDLERS to the default set of option handlers for use in the
1020 compilers proper (not the driver). */
1021 void
1022 set_default_handlers (struct cl_option_handlers *handlers)
1024 handlers->unknown_option_callback = unknown_option_callback;
1025 handlers->wrong_lang_callback = complain_wrong_lang;
1026 handlers->post_handling_callback = post_handling_callback;
1027 handlers->num_handlers = 3;
1028 handlers->handlers[0].handler = lang_handle_option;
1029 handlers->handlers[0].mask = initial_lang_mask;
1030 handlers->handlers[1].handler = common_handle_option;
1031 handlers->handlers[1].mask = CL_COMMON;
1032 handlers->handlers[2].handler = target_handle_option;
1033 handlers->handlers[2].mask = CL_TARGET;
1036 /* Parse command line options and set default flag values. Do minimal
1037 options processing. The decoded options are in *DECODED_OPTIONS
1038 and *DECODED_OPTIONS_COUNT; settings go in OPTS, OPTS_SET and DC;
1039 the options are located at LOC. */
1040 void
1041 decode_options (struct gcc_options *opts, struct gcc_options *opts_set,
1042 struct cl_decoded_option *decoded_options,
1043 unsigned int decoded_options_count,
1044 location_t loc, diagnostic_context *dc)
1046 struct cl_option_handlers handlers;
1048 unsigned int lang_mask;
1050 lang_mask = initial_lang_mask;
1052 set_default_handlers (&handlers);
1054 /* Enable -Werror=coverage-mismatch by default. */
1055 control_warning_option (OPT_Wcoverage_mismatch, (int) DK_ERROR, true,
1056 loc, lang_mask,
1057 &handlers, opts, opts_set, dc);
1059 default_options_optimization (opts, opts_set,
1060 decoded_options, decoded_options_count,
1061 loc, lang_mask, &handlers, dc);
1063 #ifdef ENABLE_LTO
1064 /* Clear any options currently held for LTO. */
1065 lto_clear_user_options ();
1066 #endif
1068 read_cmdline_options (opts, opts_set,
1069 decoded_options, decoded_options_count,
1070 loc, lang_mask,
1071 &handlers, dc);
1073 finish_options (opts, opts_set);
1076 /* After all options have been read into OPTS and OPTS_SET, finalize
1077 settings of those options and diagnose incompatible
1078 combinations. */
1079 static void
1080 finish_options (struct gcc_options *opts, struct gcc_options *opts_set)
1082 static bool first_time_p = true;
1083 enum unwind_info_type ui_except;
1085 gcc_assert (opts == &global_options);
1086 gcc_assert (opts_set = &global_options_set);
1088 if (opts->x_dump_base_name && ! IS_ABSOLUTE_PATH (opts->x_dump_base_name))
1090 /* First try to make OPTS->X_DUMP_BASE_NAME relative to the
1091 OPTS->X_DUMP_DIR_NAME directory. Then try to make
1092 OPTS->X_DUMP_BASE_NAME relative to the OPTS->X_AUX_BASE_NAME
1093 directory, typically the directory to contain the object
1094 file. */
1095 if (opts->x_dump_dir_name)
1096 opts->x_dump_base_name = concat (opts->x_dump_dir_name,
1097 opts->x_dump_base_name, NULL);
1098 else if (opts->x_aux_base_name)
1100 const char *aux_base;
1102 base_of_path (opts->x_aux_base_name, &aux_base);
1103 if (opts->x_aux_base_name != aux_base)
1105 int dir_len = aux_base - opts->x_aux_base_name;
1106 char *new_dump_base_name =
1107 XNEWVEC (char, strlen (opts->x_dump_base_name) + dir_len + 1);
1109 /* Copy directory component from OPTS->X_AUX_BASE_NAME. */
1110 memcpy (new_dump_base_name, opts->x_aux_base_name, dir_len);
1111 /* Append existing OPTS->X_DUMP_BASE_NAME. */
1112 strcpy (new_dump_base_name + dir_len, opts->x_dump_base_name);
1113 opts->x_dump_base_name = new_dump_base_name;
1118 /* Handle related options for unit-at-a-time, toplevel-reorder, and
1119 section-anchors. */
1120 if (!opts->x_flag_unit_at_a_time)
1122 if (opts->x_flag_section_anchors && opts_set->x_flag_section_anchors)
1123 error ("section anchors must be disabled when unit-at-a-time "
1124 "is disabled");
1125 opts->x_flag_section_anchors = 0;
1126 if (opts->x_flag_toplevel_reorder == 1)
1127 error ("toplevel reorder must be disabled when unit-at-a-time "
1128 "is disabled");
1129 opts->x_flag_toplevel_reorder = 0;
1132 /* -Wmissing-noreturn is alias for -Wsuggest-attribute=noreturn. */
1133 if (opts->x_warn_missing_noreturn)
1134 opts->x_warn_suggest_attribute_noreturn = true;
1136 /* Unless the user has asked for section anchors, we disable toplevel
1137 reordering at -O0 to disable transformations that might be surprising
1138 to end users and to get -fno-toplevel-reorder tested. */
1139 if (!optimize
1140 && opts->x_flag_toplevel_reorder == 2
1141 && !(opts->x_flag_section_anchors && opts_set->x_flag_section_anchors))
1143 opts->x_flag_toplevel_reorder = 0;
1144 opts->x_flag_section_anchors = 0;
1146 if (!opts->x_flag_toplevel_reorder)
1148 if (opts->x_flag_section_anchors && opts_set->x_flag_section_anchors)
1149 error ("section anchors must be disabled when toplevel reorder"
1150 " is disabled");
1151 opts->x_flag_section_anchors = 0;
1154 if (first_time_p)
1156 if (opts->x_flag_pie)
1157 opts->x_flag_pic = opts->x_flag_pie;
1158 if (opts->x_flag_pic && !opts->x_flag_pie)
1159 opts->x_flag_shlib = 1;
1160 first_time_p = false;
1163 if (optimize == 0)
1165 /* Inlining does not work if not optimizing,
1166 so force it not to be done. */
1167 opts->x_warn_inline = 0;
1168 opts->x_flag_no_inline = 1;
1171 /* The optimization to partition hot and cold basic blocks into separate
1172 sections of the .o and executable files does not work (currently)
1173 with exception handling. This is because there is no support for
1174 generating unwind info. If opts->x_flag_exceptions is turned on
1175 we need to turn off the partitioning optimization. */
1177 ui_except = targetm.except_unwind_info ();
1179 if (opts->x_flag_exceptions
1180 && opts->x_flag_reorder_blocks_and_partition
1181 && (ui_except == UI_SJLJ || ui_except == UI_TARGET))
1183 inform (input_location,
1184 "-freorder-blocks-and-partition does not work "
1185 "with exceptions on this architecture");
1186 opts->x_flag_reorder_blocks_and_partition = 0;
1187 opts->x_flag_reorder_blocks = 1;
1190 /* If user requested unwind info, then turn off the partitioning
1191 optimization. */
1193 if (opts->x_flag_unwind_tables
1194 && !targetm.unwind_tables_default
1195 && opts->x_flag_reorder_blocks_and_partition
1196 && (ui_except == UI_SJLJ || ui_except == UI_TARGET))
1198 inform (input_location,
1199 "-freorder-blocks-and-partition does not support "
1200 "unwind info on this architecture");
1201 opts->x_flag_reorder_blocks_and_partition = 0;
1202 opts->x_flag_reorder_blocks = 1;
1205 /* If the target requested unwind info, then turn off the partitioning
1206 optimization with a different message. Likewise, if the target does not
1207 support named sections. */
1209 if (opts->x_flag_reorder_blocks_and_partition
1210 && (!targetm.have_named_sections
1211 || (opts->x_flag_unwind_tables
1212 && targetm.unwind_tables_default
1213 && (ui_except == UI_SJLJ || ui_except == UI_TARGET))))
1215 inform (input_location,
1216 "-freorder-blocks-and-partition does not work "
1217 "on this architecture");
1218 opts->x_flag_reorder_blocks_and_partition = 0;
1219 opts->x_flag_reorder_blocks = 1;
1222 /* Pipelining of outer loops is only possible when general pipelining
1223 capabilities are requested. */
1224 if (!opts->x_flag_sel_sched_pipelining)
1225 opts->x_flag_sel_sched_pipelining_outer_loops = 0;
1227 if (!targetm.ira_cover_classes
1228 && opts->x_flag_ira_algorithm == IRA_ALGORITHM_CB)
1230 inform (input_location,
1231 "-fira-algorithm=CB does not work on this architecture");
1232 opts->x_flag_ira_algorithm = IRA_ALGORITHM_PRIORITY;
1235 if (opts->x_flag_conserve_stack)
1237 maybe_set_param_value (PARAM_LARGE_STACK_FRAME, 100,
1238 opts->x_param_values, opts_set->x_param_values);
1239 maybe_set_param_value (PARAM_STACK_FRAME_GROWTH, 40,
1240 opts->x_param_values, opts_set->x_param_values);
1242 if (opts->x_flag_wpa || opts->x_flag_ltrans)
1244 /* These passes are not WHOPR compatible yet. */
1245 opts->x_flag_ipa_pta = 0;
1246 opts->x_flag_ipa_struct_reorg = 0;
1249 if (opts->x_flag_lto)
1251 #ifdef ENABLE_LTO
1252 opts->x_flag_generate_lto = 1;
1254 /* When generating IL, do not operate in whole-program mode.
1255 Otherwise, symbols will be privatized too early, causing link
1256 errors later. */
1257 opts->x_flag_whole_program = 0;
1258 #else
1259 error ("LTO support has not been enabled in this configuration");
1260 #endif
1262 if ((opts->x_flag_lto_partition_balanced != 0) + (opts->x_flag_lto_partition_1to1 != 0)
1263 + (opts->x_flag_lto_partition_none != 0) >= 1)
1265 if ((opts->x_flag_lto_partition_balanced != 0)
1266 + (opts->x_flag_lto_partition_1to1 != 0)
1267 + (opts->x_flag_lto_partition_none != 0) > 1)
1268 error ("only one -flto-partition value can be specified");
1271 /* We initialize opts->x_flag_split_stack to -1 so that targets can set a
1272 default value if they choose based on other options. */
1273 if (opts->x_flag_split_stack == -1)
1274 opts->x_flag_split_stack = 0;
1275 else if (opts->x_flag_split_stack)
1277 if (!targetm.supports_split_stack (true))
1279 error ("%<-fsplit-stack%> is not supported by "
1280 "this compiler configuration");
1281 opts->x_flag_split_stack = 0;
1286 #define LEFT_COLUMN 27
1288 /* Output ITEM, of length ITEM_WIDTH, in the left column,
1289 followed by word-wrapped HELP in a second column. */
1290 static void
1291 wrap_help (const char *help,
1292 const char *item,
1293 unsigned int item_width,
1294 unsigned int columns)
1296 unsigned int col_width = LEFT_COLUMN;
1297 unsigned int remaining, room, len;
1299 remaining = strlen (help);
1303 room = columns - 3 - MAX (col_width, item_width);
1304 if (room > columns)
1305 room = 0;
1306 len = remaining;
1308 if (room < len)
1310 unsigned int i;
1312 for (i = 0; help[i]; i++)
1314 if (i >= room && len != remaining)
1315 break;
1316 if (help[i] == ' ')
1317 len = i;
1318 else if ((help[i] == '-' || help[i] == '/')
1319 && help[i + 1] != ' '
1320 && i > 0 && ISALPHA (help[i - 1]))
1321 len = i + 1;
1325 printf( " %-*.*s %.*s\n", col_width, item_width, item, len, help);
1326 item_width = 0;
1327 while (help[len] == ' ')
1328 len++;
1329 help += len;
1330 remaining -= len;
1332 while (remaining);
1335 /* Print help for a specific front-end, etc. */
1336 static void
1337 print_filtered_help (unsigned int include_flags,
1338 unsigned int exclude_flags,
1339 unsigned int any_flags,
1340 unsigned int columns)
1342 unsigned int i;
1343 const char *help;
1344 static char *printed = NULL;
1345 bool found = false;
1346 bool displayed = false;
1348 if (include_flags == CL_PARAMS)
1350 for (i = 0; i < LAST_PARAM; i++)
1352 const char *param = compiler_params[i].option;
1354 help = compiler_params[i].help;
1355 if (help == NULL || *help == '\0')
1357 if (exclude_flags & CL_UNDOCUMENTED)
1358 continue;
1359 help = undocumented_msg;
1362 /* Get the translation. */
1363 help = _(help);
1365 wrap_help (help, param, strlen (param), columns);
1367 putchar ('\n');
1368 return;
1371 if (!printed)
1372 printed = XCNEWVAR (char, cl_options_count);
1374 for (i = 0; i < cl_options_count; i++)
1376 static char new_help[128];
1377 const struct cl_option *option = cl_options + i;
1378 unsigned int len;
1379 const char *opt;
1380 const char *tab;
1382 if (include_flags == 0
1383 || ((option->flags & include_flags) != include_flags))
1385 if ((option->flags & any_flags) == 0)
1386 continue;
1389 /* Skip unwanted switches. */
1390 if ((option->flags & exclude_flags) != 0)
1391 continue;
1393 /* The driver currently prints its own help text. */
1394 if ((option->flags & CL_DRIVER) != 0
1395 && (option->flags & (((1U << cl_lang_count) - 1)
1396 | CL_COMMON | CL_TARGET)) == 0)
1397 continue;
1399 found = true;
1400 /* Skip switches that have already been printed. */
1401 if (printed[i])
1402 continue;
1404 printed[i] = true;
1406 help = option->help;
1407 if (help == NULL)
1409 if (exclude_flags & CL_UNDOCUMENTED)
1410 continue;
1411 help = undocumented_msg;
1414 /* Get the translation. */
1415 help = _(help);
1417 /* Find the gap between the name of the
1418 option and its descriptive text. */
1419 tab = strchr (help, '\t');
1420 if (tab)
1422 len = tab - help;
1423 opt = help;
1424 help = tab + 1;
1426 else
1428 opt = option->opt_text;
1429 len = strlen (opt);
1432 /* With the -Q option enabled we change the descriptive text associated
1433 with an option to be an indication of its current setting. */
1434 if (!quiet_flag)
1436 void *flag_var = option_flag_var (i, &global_options);
1438 if (len < (LEFT_COLUMN + 2))
1439 strcpy (new_help, "\t\t");
1440 else
1441 strcpy (new_help, "\t");
1443 if (flag_var != NULL)
1445 if (option->flags & CL_JOINED)
1447 if (option->var_type == CLVC_STRING)
1449 if (* (const char **) flag_var != NULL)
1450 snprintf (new_help + strlen (new_help),
1451 sizeof (new_help) - strlen (new_help),
1452 * (const char **) flag_var);
1454 else
1455 sprintf (new_help + strlen (new_help),
1456 "%#x", * (int *) flag_var);
1458 else
1459 strcat (new_help, option_enabled (i, &global_options)
1460 ? _("[enabled]") : _("[disabled]"));
1463 help = new_help;
1466 wrap_help (help, opt, len, columns);
1467 displayed = true;
1470 if (! found)
1472 unsigned int langs = include_flags & CL_LANG_ALL;
1474 if (langs == 0)
1475 printf (_(" No options with the desired characteristics were found\n"));
1476 else
1478 unsigned int i;
1480 /* PR 31349: Tell the user how to see all of the
1481 options supported by a specific front end. */
1482 for (i = 0; (1U << i) < CL_LANG_ALL; i ++)
1483 if ((1U << i) & langs)
1484 printf (_(" None found. Use --help=%s to show *all* the options supported by the %s front-end\n"),
1485 lang_names[i], lang_names[i]);
1489 else if (! displayed)
1490 printf (_(" All options with the desired characteristics have already been displayed\n"));
1492 putchar ('\n');
1495 /* Display help for a specified type of option.
1496 The options must have ALL of the INCLUDE_FLAGS set
1497 ANY of the flags in the ANY_FLAGS set
1498 and NONE of the EXCLUDE_FLAGS set. */
1499 static void
1500 print_specific_help (unsigned int include_flags,
1501 unsigned int exclude_flags,
1502 unsigned int any_flags)
1504 unsigned int all_langs_mask = (1U << cl_lang_count) - 1;
1505 const char * description = NULL;
1506 const char * descrip_extra = "";
1507 size_t i;
1508 unsigned int flag;
1509 static unsigned int columns = 0;
1511 /* Sanity check: Make sure that we do not have more
1512 languages than we have bits available to enumerate them. */
1513 gcc_assert ((1U << cl_lang_count) < CL_MIN_OPTION_CLASS);
1515 /* If we have not done so already, obtain
1516 the desired maximum width of the output. */
1517 if (columns == 0)
1519 const char *p;
1521 GET_ENVIRONMENT (p, "COLUMNS");
1522 if (p != NULL)
1524 int value = atoi (p);
1526 if (value > 0)
1527 columns = value;
1530 if (columns == 0)
1531 /* Use a reasonable default. */
1532 columns = 80;
1535 /* Decide upon the title for the options that we are going to display. */
1536 for (i = 0, flag = 1; flag <= CL_MAX_OPTION_CLASS; flag <<= 1, i ++)
1538 switch (flag & include_flags)
1540 case 0:
1541 case CL_DRIVER:
1542 break;
1544 case CL_TARGET:
1545 description = _("The following options are target specific");
1546 break;
1547 case CL_WARNING:
1548 description = _("The following options control compiler warning messages");
1549 break;
1550 case CL_OPTIMIZATION:
1551 description = _("The following options control optimizations");
1552 break;
1553 case CL_COMMON:
1554 description = _("The following options are language-independent");
1555 break;
1556 case CL_PARAMS:
1557 description = _("The --param option recognizes the following as parameters");
1558 break;
1559 default:
1560 if (i >= cl_lang_count)
1561 break;
1562 if (exclude_flags & all_langs_mask)
1563 description = _("The following options are specific to just the language ");
1564 else
1565 description = _("The following options are supported by the language ");
1566 descrip_extra = lang_names [i];
1567 break;
1571 if (description == NULL)
1573 if (any_flags == 0)
1575 if (include_flags & CL_UNDOCUMENTED)
1576 description = _("The following options are not documented");
1577 else if (include_flags & CL_SEPARATE)
1578 description = _("The following options take separate arguments");
1579 else if (include_flags & CL_JOINED)
1580 description = _("The following options take joined arguments");
1581 else
1583 internal_error ("unrecognized include_flags 0x%x passed to print_specific_help",
1584 include_flags);
1585 return;
1588 else
1590 if (any_flags & all_langs_mask)
1591 description = _("The following options are language-related");
1592 else
1593 description = _("The following options are language-independent");
1597 printf ("%s%s:\n", description, descrip_extra);
1598 print_filtered_help (include_flags, exclude_flags, any_flags, columns);
1601 /* Handle target- and language-independent options. Return zero to
1602 generate an "unknown option" message. Only options that need
1603 extra handling need to be listed here; if you simply want
1604 DECODED->value assigned to a variable, it happens automatically. */
1606 static bool
1607 common_handle_option (struct gcc_options *opts,
1608 struct gcc_options *opts_set,
1609 const struct cl_decoded_option *decoded,
1610 unsigned int lang_mask, int kind ATTRIBUTE_UNUSED,
1611 location_t loc,
1612 const struct cl_option_handlers *handlers,
1613 diagnostic_context *dc)
1615 size_t scode = decoded->opt_index;
1616 const char *arg = decoded->arg;
1617 int value = decoded->value;
1618 enum opt_code code = (enum opt_code) scode;
1620 gcc_assert (opts == &global_options);
1621 gcc_assert (opts_set == &global_options_set);
1622 gcc_assert (dc == global_dc);
1623 gcc_assert (decoded->canonical_option_num_elements <= 2);
1625 switch (code)
1627 case OPT__param:
1628 handle_param (opts, opts_set, arg);
1629 break;
1631 case OPT__help:
1633 unsigned int all_langs_mask = (1U << cl_lang_count) - 1;
1634 unsigned int undoc_mask;
1635 unsigned int i;
1637 undoc_mask = ((opts->x_verbose_flag | opts->x_extra_warnings)
1639 : CL_UNDOCUMENTED);
1640 /* First display any single language specific options. */
1641 for (i = 0; i < cl_lang_count; i++)
1642 print_specific_help
1643 (1U << i, (all_langs_mask & (~ (1U << i))) | undoc_mask, 0);
1644 /* Next display any multi language specific options. */
1645 print_specific_help (0, undoc_mask, all_langs_mask);
1646 /* Then display any remaining, non-language options. */
1647 for (i = CL_MIN_OPTION_CLASS; i <= CL_MAX_OPTION_CLASS; i <<= 1)
1648 if (i != CL_DRIVER)
1649 print_specific_help (i, undoc_mask, 0);
1650 exit_after_options = true;
1651 break;
1654 case OPT__target_help:
1655 print_specific_help (CL_TARGET, CL_UNDOCUMENTED, 0);
1656 exit_after_options = true;
1658 /* Allow the target a chance to give the user some additional information. */
1659 if (targetm.help)
1660 targetm.help ();
1661 break;
1663 case OPT__help_:
1665 const char * a = arg;
1666 unsigned int include_flags = 0;
1667 /* Note - by default we include undocumented options when listing
1668 specific classes. If you only want to see documented options
1669 then add ",^undocumented" to the --help= option. E.g.:
1671 --help=target,^undocumented */
1672 unsigned int exclude_flags = 0;
1674 /* Walk along the argument string, parsing each word in turn.
1675 The format is:
1676 arg = [^]{word}[,{arg}]
1677 word = {optimizers|target|warnings|undocumented|
1678 params|common|<language>} */
1679 while (* a != 0)
1681 static struct
1683 const char * string;
1684 unsigned int flag;
1686 specifics[] =
1688 { "optimizers", CL_OPTIMIZATION },
1689 { "target", CL_TARGET },
1690 { "warnings", CL_WARNING },
1691 { "undocumented", CL_UNDOCUMENTED },
1692 { "params", CL_PARAMS },
1693 { "joined", CL_JOINED },
1694 { "separate", CL_SEPARATE },
1695 { "common", CL_COMMON },
1696 { NULL, 0 }
1698 unsigned int * pflags;
1699 const char * comma;
1700 unsigned int lang_flag, specific_flag;
1701 unsigned int len;
1702 unsigned int i;
1704 if (* a == '^')
1706 ++ a;
1707 pflags = & exclude_flags;
1709 else
1710 pflags = & include_flags;
1712 comma = strchr (a, ',');
1713 if (comma == NULL)
1714 len = strlen (a);
1715 else
1716 len = comma - a;
1717 if (len == 0)
1719 a = comma + 1;
1720 continue;
1723 /* Check to see if the string matches an option class name. */
1724 for (i = 0, specific_flag = 0; specifics[i].string != NULL; i++)
1725 if (strncasecmp (a, specifics[i].string, len) == 0)
1727 specific_flag = specifics[i].flag;
1728 break;
1731 /* Check to see if the string matches a language name.
1732 Note - we rely upon the alpha-sorted nature of the entries in
1733 the lang_names array, specifically that shorter names appear
1734 before their longer variants. (i.e. C before C++). That way
1735 when we are attempting to match --help=c for example we will
1736 match with C first and not C++. */
1737 for (i = 0, lang_flag = 0; i < cl_lang_count; i++)
1738 if (strncasecmp (a, lang_names[i], len) == 0)
1740 lang_flag = 1U << i;
1741 break;
1744 if (specific_flag != 0)
1746 if (lang_flag == 0)
1747 * pflags |= specific_flag;
1748 else
1750 /* The option's argument matches both the start of a
1751 language name and the start of an option class name.
1752 We have a special case for when the user has
1753 specified "--help=c", but otherwise we have to issue
1754 a warning. */
1755 if (strncasecmp (a, "c", len) == 0)
1756 * pflags |= lang_flag;
1757 else
1758 fnotice (stderr,
1759 "warning: --help argument %.*s is ambiguous, please be more specific\n",
1760 len, a);
1763 else if (lang_flag != 0)
1764 * pflags |= lang_flag;
1765 else
1766 fnotice (stderr,
1767 "warning: unrecognized argument to --help= option: %.*s\n",
1768 len, a);
1770 if (comma == NULL)
1771 break;
1772 a = comma + 1;
1775 if (include_flags)
1776 print_specific_help (include_flags, exclude_flags, 0);
1777 exit_after_options = true;
1778 break;
1781 case OPT__version:
1782 exit_after_options = true;
1783 break;
1785 case OPT_O:
1786 case OPT_Os:
1787 case OPT_Ofast:
1788 /* Currently handled in a prescan. */
1789 break;
1791 case OPT_Werror_:
1792 enable_warning_as_error (arg, value, lang_mask, handlers,
1793 opts, opts_set, loc, dc);
1794 break;
1796 case OPT_Wlarger_than_:
1797 opts->x_larger_than_size = value;
1798 opts->x_warn_larger_than = value != -1;
1799 break;
1801 case OPT_Wfatal_errors:
1802 dc->fatal_errors = value;
1803 break;
1805 case OPT_Wframe_larger_than_:
1806 opts->x_frame_larger_than_size = value;
1807 opts->x_warn_frame_larger_than = value != -1;
1808 break;
1810 case OPT_Wstrict_aliasing:
1811 set_Wstrict_aliasing (opts, value);
1812 break;
1814 case OPT_Wstrict_overflow:
1815 opts->x_warn_strict_overflow = (value
1816 ? (int) WARN_STRICT_OVERFLOW_CONDITIONAL
1817 : 0);
1818 break;
1820 case OPT_Wsystem_headers:
1821 dc->dc_warn_system_headers = value;
1822 break;
1824 case OPT_aux_info:
1825 opts->x_flag_gen_aux_info = 1;
1826 break;
1828 case OPT_auxbase_strip:
1830 char *tmp = xstrdup (arg);
1831 strip_off_ending (tmp, strlen (tmp));
1832 if (tmp[0])
1833 opts->x_aux_base_name = tmp;
1835 break;
1837 case OPT_d:
1838 decode_d_option (arg);
1839 break;
1841 case OPT_fcall_used_:
1842 fix_register (arg, 0, 1);
1843 break;
1845 case OPT_fcall_saved_:
1846 fix_register (arg, 0, 0);
1847 break;
1849 case OPT_fcompare_debug_second:
1850 flag_compare_debug = value;
1851 break;
1853 case OPT_fdbg_cnt_:
1854 dbg_cnt_process_opt (arg);
1855 break;
1857 case OPT_fdbg_cnt_list:
1858 dbg_cnt_list_all_counters ();
1859 break;
1861 case OPT_fdebug_prefix_map_:
1862 add_debug_prefix_map (arg);
1863 break;
1865 case OPT_fdiagnostics_show_location_:
1866 if (!strcmp (arg, "once"))
1867 diagnostic_prefixing_rule (dc) = DIAGNOSTICS_SHOW_PREFIX_ONCE;
1868 else if (!strcmp (arg, "every-line"))
1869 diagnostic_prefixing_rule (dc)
1870 = DIAGNOSTICS_SHOW_PREFIX_EVERY_LINE;
1871 else
1872 return false;
1873 break;
1875 case OPT_fdiagnostics_show_option:
1876 dc->show_option_requested = value;
1877 break;
1879 case OPT_fdump_:
1880 if (!dump_switch_p (arg))
1881 return false;
1882 break;
1884 case OPT_ffp_contract_:
1885 if (!strcmp (arg, "on"))
1886 /* Not implemented, fall back to conservative FP_CONTRACT_OFF. */
1887 opts->x_flag_fp_contract_mode = FP_CONTRACT_OFF;
1888 else if (!strcmp (arg, "off"))
1889 opts->x_flag_fp_contract_mode = FP_CONTRACT_OFF;
1890 else if (!strcmp (arg, "fast"))
1891 opts->x_flag_fp_contract_mode = FP_CONTRACT_FAST;
1892 else
1893 error ("unknown floating point contraction style \"%s\"", arg);
1894 break;
1896 case OPT_fexcess_precision_:
1897 if (!strcmp (arg, "fast"))
1898 opts->x_flag_excess_precision_cmdline = EXCESS_PRECISION_FAST;
1899 else if (!strcmp (arg, "standard"))
1900 opts->x_flag_excess_precision_cmdline = EXCESS_PRECISION_STANDARD;
1901 else
1902 error ("unknown excess precision style \"%s\"", arg);
1903 break;
1905 case OPT_ffast_math:
1906 set_fast_math_flags (opts, value);
1907 break;
1909 case OPT_funsafe_math_optimizations:
1910 set_unsafe_math_optimizations_flags (opts, value);
1911 break;
1913 case OPT_ffixed_:
1914 fix_register (arg, 1, 1);
1915 break;
1917 case OPT_finline_limit_:
1918 set_param_value ("max-inline-insns-single", value / 2,
1919 opts->x_param_values, opts_set->x_param_values);
1920 set_param_value ("max-inline-insns-auto", value / 2,
1921 opts->x_param_values, opts_set->x_param_values);
1922 break;
1924 case OPT_finstrument_functions_exclude_function_list_:
1925 add_comma_separated_to_vector
1926 (&flag_instrument_functions_exclude_functions, arg);
1927 break;
1929 case OPT_finstrument_functions_exclude_file_list_:
1930 add_comma_separated_to_vector
1931 (&flag_instrument_functions_exclude_files, arg);
1932 break;
1934 case OPT_fmessage_length_:
1935 pp_set_line_maximum_length (dc->printer, value);
1936 break;
1938 case OPT_fpack_struct_:
1939 if (value <= 0 || (value & (value - 1)) || value > 16)
1940 error ("structure alignment must be a small power of two, not %d", value);
1941 else
1943 initial_max_fld_align = value;
1944 maximum_field_alignment = value * BITS_PER_UNIT;
1946 break;
1948 case OPT_fplugin_:
1949 #ifdef ENABLE_PLUGIN
1950 add_new_plugin (arg);
1951 #else
1952 error ("plugin support is disabled; configure with --enable-plugin");
1953 #endif
1954 break;
1956 case OPT_fplugin_arg_:
1957 #ifdef ENABLE_PLUGIN
1958 parse_plugin_arg_opt (arg);
1959 #else
1960 error ("plugin support is disabled; configure with --enable-plugin");
1961 #endif
1962 break;
1964 case OPT_fprofile_dir_:
1965 profile_data_prefix = xstrdup (arg);
1966 break;
1968 case OPT_fprofile_use_:
1969 profile_data_prefix = xstrdup (arg);
1970 opts->x_flag_profile_use = true;
1971 value = true;
1972 /* No break here - do -fprofile-use processing. */
1973 case OPT_fprofile_use:
1974 if (!opts_set->x_flag_branch_probabilities)
1975 opts->x_flag_branch_probabilities = value;
1976 if (!opts_set->x_flag_profile_values)
1977 opts->x_flag_profile_values = value;
1978 if (!opts_set->x_flag_unroll_loops)
1979 opts->x_flag_unroll_loops = value;
1980 if (!opts_set->x_flag_peel_loops)
1981 opts->x_flag_peel_loops = value;
1982 if (!opts_set->x_flag_tracer)
1983 opts->x_flag_tracer = value;
1984 if (!opts_set->x_flag_value_profile_transformations)
1985 opts->x_flag_value_profile_transformations = value;
1986 if (!opts_set->x_flag_inline_functions)
1987 opts->x_flag_inline_functions = value;
1988 if (!opts_set->x_flag_ipa_cp)
1989 opts->x_flag_ipa_cp = value;
1990 if (!opts_set->x_flag_ipa_cp_clone
1991 && value && opts->x_flag_ipa_cp)
1992 opts->x_flag_ipa_cp_clone = value;
1993 if (!opts_set->x_flag_predictive_commoning)
1994 opts->x_flag_predictive_commoning = value;
1995 if (!opts_set->x_flag_unswitch_loops)
1996 opts->x_flag_unswitch_loops = value;
1997 if (!opts_set->x_flag_gcse_after_reload)
1998 opts->x_flag_gcse_after_reload = value;
1999 break;
2001 case OPT_fprofile_generate_:
2002 profile_data_prefix = xstrdup (arg);
2003 value = true;
2004 /* No break here - do -fprofile-generate processing. */
2005 case OPT_fprofile_generate:
2006 if (!opts_set->x_profile_arc_flag)
2007 opts->x_profile_arc_flag = value;
2008 if (!opts_set->x_flag_profile_values)
2009 opts->x_flag_profile_values = value;
2010 if (!opts_set->x_flag_value_profile_transformations)
2011 opts->x_flag_value_profile_transformations = value;
2012 if (!opts_set->x_flag_inline_functions)
2013 opts->x_flag_inline_functions = value;
2014 break;
2016 case OPT_fshow_column:
2017 dc->show_column = value;
2018 break;
2020 case OPT_fvisibility_:
2022 if (!strcmp(arg, "default"))
2023 opts->x_default_visibility = VISIBILITY_DEFAULT;
2024 else if (!strcmp(arg, "internal"))
2025 opts->x_default_visibility = VISIBILITY_INTERNAL;
2026 else if (!strcmp(arg, "hidden"))
2027 opts->x_default_visibility = VISIBILITY_HIDDEN;
2028 else if (!strcmp(arg, "protected"))
2029 opts->x_default_visibility = VISIBILITY_PROTECTED;
2030 else
2031 error ("unrecognized visibility value \"%s\"", arg);
2033 break;
2035 case OPT_frandom_seed:
2036 /* The real switch is -fno-random-seed. */
2037 if (value)
2038 return false;
2039 set_random_seed (NULL);
2040 break;
2042 case OPT_frandom_seed_:
2043 set_random_seed (arg);
2044 break;
2046 case OPT_fsched_verbose_:
2047 #ifdef INSN_SCHEDULING
2048 fix_sched_param ("verbose", arg);
2049 break;
2050 #else
2051 return false;
2052 #endif
2054 case OPT_fsched_stalled_insns_:
2055 opts->x_flag_sched_stalled_insns = value;
2056 if (opts->x_flag_sched_stalled_insns == 0)
2057 opts->x_flag_sched_stalled_insns = -1;
2058 break;
2060 case OPT_fsched_stalled_insns_dep_:
2061 opts->x_flag_sched_stalled_insns_dep = value;
2062 break;
2064 case OPT_fstack_check_:
2065 if (!strcmp (arg, "no"))
2066 flag_stack_check = NO_STACK_CHECK;
2067 else if (!strcmp (arg, "generic"))
2068 /* This is the old stack checking method. */
2069 flag_stack_check = STACK_CHECK_BUILTIN
2070 ? FULL_BUILTIN_STACK_CHECK
2071 : GENERIC_STACK_CHECK;
2072 else if (!strcmp (arg, "specific"))
2073 /* This is the new stack checking method. */
2074 flag_stack_check = STACK_CHECK_BUILTIN
2075 ? FULL_BUILTIN_STACK_CHECK
2076 : STACK_CHECK_STATIC_BUILTIN
2077 ? STATIC_BUILTIN_STACK_CHECK
2078 : GENERIC_STACK_CHECK;
2079 else
2080 warning (0, "unknown stack check parameter \"%s\"", arg);
2081 break;
2083 case OPT_fstack_limit:
2084 /* The real switch is -fno-stack-limit. */
2085 if (value)
2086 return false;
2087 stack_limit_rtx = NULL_RTX;
2088 break;
2090 case OPT_fstack_limit_register_:
2092 int reg = decode_reg_name (arg);
2093 if (reg < 0)
2094 error ("unrecognized register name \"%s\"", arg);
2095 else
2096 stack_limit_rtx = gen_rtx_REG (Pmode, reg);
2098 break;
2100 case OPT_fstack_limit_symbol_:
2101 stack_limit_rtx = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (arg));
2102 break;
2104 case OPT_ftree_vectorizer_verbose_:
2105 vect_set_verbosity_level (arg);
2106 break;
2108 case OPT_ftls_model_:
2109 if (!strcmp (arg, "global-dynamic"))
2110 opts->x_flag_tls_default = TLS_MODEL_GLOBAL_DYNAMIC;
2111 else if (!strcmp (arg, "local-dynamic"))
2112 opts->x_flag_tls_default = TLS_MODEL_LOCAL_DYNAMIC;
2113 else if (!strcmp (arg, "initial-exec"))
2114 opts->x_flag_tls_default = TLS_MODEL_INITIAL_EXEC;
2115 else if (!strcmp (arg, "local-exec"))
2116 opts->x_flag_tls_default = TLS_MODEL_LOCAL_EXEC;
2117 else
2118 warning (0, "unknown tls-model \"%s\"", arg);
2119 break;
2121 case OPT_fira_algorithm_:
2122 if (!strcmp (arg, "CB"))
2123 opts->x_flag_ira_algorithm = IRA_ALGORITHM_CB;
2124 else if (!strcmp (arg, "priority"))
2125 opts->x_flag_ira_algorithm = IRA_ALGORITHM_PRIORITY;
2126 else
2127 warning (0, "unknown ira algorithm \"%s\"", arg);
2128 break;
2130 case OPT_fira_region_:
2131 if (!strcmp (arg, "one"))
2132 opts->x_flag_ira_region = IRA_REGION_ONE;
2133 else if (!strcmp (arg, "all"))
2134 opts->x_flag_ira_region = IRA_REGION_ALL;
2135 else if (!strcmp (arg, "mixed"))
2136 opts->x_flag_ira_region = IRA_REGION_MIXED;
2137 else
2138 warning (0, "unknown ira region \"%s\"", arg);
2139 break;
2141 case OPT_g:
2142 set_debug_level (NO_DEBUG, DEFAULT_GDB_EXTENSIONS, arg);
2143 break;
2145 case OPT_gcoff:
2146 set_debug_level (SDB_DEBUG, false, arg);
2147 break;
2149 case OPT_gdwarf_:
2150 if (value < 2 || value > 4)
2151 error ("dwarf version %d is not supported", value);
2152 else
2153 dwarf_version = value;
2154 set_debug_level (DWARF2_DEBUG, false, "");
2155 break;
2157 case OPT_ggdb:
2158 set_debug_level (NO_DEBUG, 2, arg);
2159 break;
2161 case OPT_gstabs:
2162 case OPT_gstabs_:
2163 set_debug_level (DBX_DEBUG, code == OPT_gstabs_, arg);
2164 break;
2166 case OPT_gvms:
2167 set_debug_level (VMS_DEBUG, false, arg);
2168 break;
2170 case OPT_gxcoff:
2171 case OPT_gxcoff_:
2172 set_debug_level (XCOFF_DEBUG, code == OPT_gxcoff_, arg);
2173 break;
2175 case OPT_pedantic_errors:
2176 opts->x_pedantic = 1;
2177 dc->pedantic_errors = 1;
2178 break;
2180 case OPT_flto:
2181 opts->x_flag_lto = "";
2182 break;
2184 case OPT_w:
2185 dc->dc_inhibit_warnings = true;
2186 break;
2188 case OPT_fmax_errors_:
2189 dc->max_errors = value;
2190 break;
2192 case OPT_fuse_linker_plugin:
2193 /* No-op. Used by the driver and passed to us because it starts with f.*/
2194 break;
2196 default:
2197 /* If the flag was handled in a standard way, assume the lack of
2198 processing here is intentional. */
2199 gcc_assert (option_flag_var (scode, opts));
2200 break;
2203 return true;
2206 /* Handle --param NAME=VALUE. */
2207 static void
2208 handle_param (struct gcc_options *opts, struct gcc_options *opts_set,
2209 const char *carg)
2211 char *equal, *arg;
2212 int value;
2214 arg = xstrdup (carg);
2215 equal = strchr (arg, '=');
2216 if (!equal)
2217 error ("%s: --param arguments should be of the form NAME=VALUE", arg);
2218 else
2220 value = integral_argument (equal + 1);
2221 if (value == -1)
2222 error ("invalid --param value %qs", equal + 1);
2223 else
2225 *equal = '\0';
2226 set_param_value (arg, value,
2227 opts->x_param_values, opts_set->x_param_values);
2231 free (arg);
2234 /* Used to set the level of strict aliasing warnings in OPTS,
2235 when no level is specified (i.e., when -Wstrict-aliasing, and not
2236 -Wstrict-aliasing=level was given).
2237 ONOFF is assumed to take value 1 when -Wstrict-aliasing is specified,
2238 and 0 otherwise. After calling this function, wstrict_aliasing will be
2239 set to the default value of -Wstrict_aliasing=level, currently 3. */
2240 void
2241 set_Wstrict_aliasing (struct gcc_options *opts, int onoff)
2243 gcc_assert (onoff == 0 || onoff == 1);
2244 if (onoff != 0)
2245 opts->x_warn_strict_aliasing = 3;
2246 else
2247 opts->x_warn_strict_aliasing = 0;
2250 /* The following routines are useful in setting all the flags that
2251 -ffast-math and -fno-fast-math imply. */
2252 static void
2253 set_fast_math_flags (struct gcc_options *opts, int set)
2255 opts->x_flag_unsafe_math_optimizations = set;
2256 set_unsafe_math_optimizations_flags (opts, set);
2257 opts->x_flag_finite_math_only = set;
2258 opts->x_flag_errno_math = !set;
2259 if (set)
2261 opts->x_flag_signaling_nans = 0;
2262 opts->x_flag_rounding_math = 0;
2263 opts->x_flag_cx_limited_range = 1;
2267 /* When -funsafe-math-optimizations is set the following
2268 flags are set as well. */
2269 static void
2270 set_unsafe_math_optimizations_flags (struct gcc_options *opts, int set)
2272 opts->x_flag_trapping_math = !set;
2273 opts->x_flag_signed_zeros = !set;
2274 opts->x_flag_associative_math = set;
2275 opts->x_flag_reciprocal_math = set;
2278 /* Return true iff flags are set as if -ffast-math. */
2279 bool
2280 fast_math_flags_set_p (void)
2282 return (!flag_trapping_math
2283 && flag_unsafe_math_optimizations
2284 && flag_finite_math_only
2285 && !flag_signed_zeros
2286 && !flag_errno_math);
2289 /* Return true iff flags are set as if -ffast-math but using the flags stored
2290 in the struct cl_optimization structure. */
2291 bool
2292 fast_math_flags_struct_set_p (struct cl_optimization *opt)
2294 return (!opt->x_flag_trapping_math
2295 && opt->x_flag_unsafe_math_optimizations
2296 && opt->x_flag_finite_math_only
2297 && !opt->x_flag_signed_zeros
2298 && !opt->x_flag_errno_math);
2301 /* Handle a debug output -g switch. EXTENDED is true or false to support
2302 extended output (2 is special and means "-ggdb" was given). */
2303 static void
2304 set_debug_level (enum debug_info_type type, int extended, const char *arg)
2306 static bool type_explicit;
2308 use_gnu_debug_info_extensions = extended;
2310 if (type == NO_DEBUG)
2312 if (write_symbols == NO_DEBUG)
2314 write_symbols = PREFERRED_DEBUGGING_TYPE;
2316 if (extended == 2)
2318 #ifdef DWARF2_DEBUGGING_INFO
2319 write_symbols = DWARF2_DEBUG;
2320 #elif defined DBX_DEBUGGING_INFO
2321 write_symbols = DBX_DEBUG;
2322 #endif
2325 if (write_symbols == NO_DEBUG)
2326 warning (0, "target system does not support debug output");
2329 else
2331 /* Does it conflict with an already selected type? */
2332 if (type_explicit && write_symbols != NO_DEBUG && type != write_symbols)
2333 error ("debug format \"%s\" conflicts with prior selection",
2334 debug_type_names[type]);
2335 write_symbols = type;
2336 type_explicit = true;
2339 /* A debug flag without a level defaults to level 2. */
2340 if (*arg == '\0')
2342 if (!debug_info_level)
2343 debug_info_level = DINFO_LEVEL_NORMAL;
2345 else
2347 int argval = integral_argument (arg);
2348 if (argval == -1)
2349 error ("unrecognised debug output level \"%s\"", arg);
2350 else if (argval > 3)
2351 error ("debug output level %s is too high", arg);
2352 else
2353 debug_info_level = (enum debug_info_level) argval;
2357 /* Return 1 if option OPT_IDX is enabled in OPTS, 0 if it is disabled,
2358 or -1 if it isn't a simple on-off switch. */
2361 option_enabled (int opt_idx, void *opts)
2363 const struct cl_option *option = &(cl_options[opt_idx]);
2364 struct gcc_options *optsg = (struct gcc_options *) opts;
2365 void *flag_var = option_flag_var (opt_idx, optsg);
2367 if (flag_var)
2368 switch (option->var_type)
2370 case CLVC_BOOLEAN:
2371 return *(int *) flag_var != 0;
2373 case CLVC_EQUAL:
2374 return *(int *) flag_var == option->var_value;
2376 case CLVC_BIT_CLEAR:
2377 return (*(int *) flag_var & option->var_value) == 0;
2379 case CLVC_BIT_SET:
2380 return (*(int *) flag_var & option->var_value) != 0;
2382 case CLVC_STRING:
2383 break;
2385 return -1;
2388 /* Fill STATE with the current state of option OPTION in OPTS. Return
2389 true if there is some state to store. */
2391 bool
2392 get_option_state (struct gcc_options *opts, int option,
2393 struct cl_option_state *state)
2395 void *flag_var = option_flag_var (option, opts);
2397 if (flag_var == 0)
2398 return false;
2400 switch (cl_options[option].var_type)
2402 case CLVC_BOOLEAN:
2403 case CLVC_EQUAL:
2404 state->data = flag_var;
2405 state->size = sizeof (int);
2406 break;
2408 case CLVC_BIT_CLEAR:
2409 case CLVC_BIT_SET:
2410 state->ch = option_enabled (option, opts);
2411 state->data = &state->ch;
2412 state->size = 1;
2413 break;
2415 case CLVC_STRING:
2416 state->data = *(const char **) flag_var;
2417 if (state->data == 0)
2418 state->data = "";
2419 state->size = strlen ((const char *) state->data) + 1;
2420 break;
2422 return true;
2425 /* Enable (or disable if VALUE is 0) a warning option ARG (language
2426 mask LANG_MASK, option handlers HANDLERS) as an error for option
2427 structures OPTS and OPTS_SET, diagnostic context DC (possibly
2428 NULL), location LOC. This is used by -Werror=. */
2430 static void
2431 enable_warning_as_error (const char *arg, int value, unsigned int lang_mask,
2432 const struct cl_option_handlers *handlers,
2433 struct gcc_options *opts,
2434 struct gcc_options *opts_set,
2435 location_t loc, diagnostic_context *dc)
2437 char *new_option;
2438 int option_index;
2440 new_option = XNEWVEC (char, strlen (arg) + 2);
2441 new_option[0] = 'W';
2442 strcpy (new_option + 1, arg);
2443 option_index = find_opt (new_option, lang_mask);
2444 if (option_index == OPT_SPECIAL_unknown)
2446 error ("-Werror=%s: no option -%s", arg, new_option);
2448 else
2450 const diagnostic_t kind = value ? DK_ERROR : DK_WARNING;
2452 control_warning_option (option_index, (int) kind, value,
2453 loc, lang_mask,
2454 handlers, opts, opts_set, dc);
2456 free (new_option);
2459 /* Return malloced memory for the name of the option OPTION_INDEX
2460 which enabled a diagnostic (context CONTEXT), originally of type
2461 ORIG_DIAG_KIND but possibly converted to DIAG_KIND by options such
2462 as -Werror. */
2464 char *
2465 option_name (diagnostic_context *context, int option_index,
2466 diagnostic_t orig_diag_kind, diagnostic_t diag_kind)
2468 if (option_index)
2470 /* A warning classified as an error. */
2471 if ((orig_diag_kind == DK_WARNING || orig_diag_kind == DK_PEDWARN)
2472 && diag_kind == DK_ERROR)
2473 return concat (cl_options[OPT_Werror_].opt_text,
2474 /* Skip over "-W". */
2475 cl_options[option_index].opt_text + 2,
2476 NULL);
2477 /* A warning with option. */
2478 else
2479 return xstrdup (cl_options[option_index].opt_text);
2481 /* A warning without option classified as an error. */
2482 else if (orig_diag_kind == DK_WARNING || orig_diag_kind == DK_PEDWARN
2483 || diag_kind == DK_WARNING)
2485 if (context->warning_as_error_requested)
2486 return xstrdup (cl_options[OPT_Werror].opt_text);
2487 else
2488 return xstrdup (_("enabled by default"));
2490 else
2491 return NULL;