2012-09-19 Tulio Magno Quites Machado Filho <tuliom@linux.vnet.ibm.com>
[official-gcc.git] / gcc / opts.c
blob5ab9ad9c42d973fcd89499068e3ff0d79e5baf80
1 /* Command line option handling.
2 Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011,
3 2012
5 Free Software Foundation, Inc.
6 Contributed by Neil Booth.
8 This file is part of GCC.
10 GCC is free software; you can redistribute it and/or modify it under
11 the terms of the GNU General Public License as published by the Free
12 Software Foundation; either version 3, or (at your option) any later
13 version.
15 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
16 WARRANTY; without even the implied warranty of MERCHANTABILITY or
17 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
18 for more details.
20 You should have received a copy of the GNU General Public License
21 along with GCC; see the file COPYING3. If not see
22 <http://www.gnu.org/licenses/>. */
24 #include "config.h"
25 #include "system.h"
26 #include "intl.h"
27 #include "coretypes.h"
28 #include "opts.h"
29 #include "options.h"
30 #include "tm.h" /* For STACK_CHECK_BUILTIN,
31 STACK_CHECK_STATIC_BUILTIN, DEFAULT_GDB_EXTENSIONS,
32 DWARF2_DEBUGGING_INFO and DBX_DEBUGGING_INFO. */
33 #include "flags.h"
34 #include "params.h"
35 #include "diagnostic.h"
36 #include "opts-diagnostic.h"
37 #include "insn-attr-common.h"
38 #include "common/common-target.h"
40 /* Indexed by enum debug_info_type. */
41 const char *const debug_type_names[] =
43 "none", "stabs", "coff", "dwarf-2", "xcoff", "vms"
46 /* Parse the -femit-struct-debug-detailed option value
47 and set the flag variables. */
49 #define MATCH( prefix, string ) \
50 ((strncmp (prefix, string, sizeof prefix - 1) == 0) \
51 ? ((string += sizeof prefix - 1), 1) : 0)
53 void
54 set_struct_debug_option (struct gcc_options *opts, location_t loc,
55 const char *spec)
57 /* various labels for comparison */
58 static const char dfn_lbl[] = "dfn:", dir_lbl[] = "dir:", ind_lbl[] = "ind:";
59 static const char ord_lbl[] = "ord:", gen_lbl[] = "gen:";
60 static const char none_lbl[] = "none", any_lbl[] = "any";
61 static const char base_lbl[] = "base", sys_lbl[] = "sys";
63 enum debug_struct_file files = DINFO_STRUCT_FILE_ANY;
64 /* Default is to apply to as much as possible. */
65 enum debug_info_usage usage = DINFO_USAGE_NUM_ENUMS;
66 int ord = 1, gen = 1;
68 /* What usage? */
69 if (MATCH (dfn_lbl, spec))
70 usage = DINFO_USAGE_DFN;
71 else if (MATCH (dir_lbl, spec))
72 usage = DINFO_USAGE_DIR_USE;
73 else if (MATCH (ind_lbl, spec))
74 usage = DINFO_USAGE_IND_USE;
76 /* Generics or not? */
77 if (MATCH (ord_lbl, spec))
78 gen = 0;
79 else if (MATCH (gen_lbl, spec))
80 ord = 0;
82 /* What allowable environment? */
83 if (MATCH (none_lbl, spec))
84 files = DINFO_STRUCT_FILE_NONE;
85 else if (MATCH (any_lbl, spec))
86 files = DINFO_STRUCT_FILE_ANY;
87 else if (MATCH (sys_lbl, spec))
88 files = DINFO_STRUCT_FILE_SYS;
89 else if (MATCH (base_lbl, spec))
90 files = DINFO_STRUCT_FILE_BASE;
91 else
92 error_at (loc,
93 "argument %qs to %<-femit-struct-debug-detailed%> "
94 "not recognized",
95 spec);
97 /* Effect the specification. */
98 if (usage == DINFO_USAGE_NUM_ENUMS)
100 if (ord)
102 opts->x_debug_struct_ordinary[DINFO_USAGE_DFN] = files;
103 opts->x_debug_struct_ordinary[DINFO_USAGE_DIR_USE] = files;
104 opts->x_debug_struct_ordinary[DINFO_USAGE_IND_USE] = files;
106 if (gen)
108 opts->x_debug_struct_generic[DINFO_USAGE_DFN] = files;
109 opts->x_debug_struct_generic[DINFO_USAGE_DIR_USE] = files;
110 opts->x_debug_struct_generic[DINFO_USAGE_IND_USE] = files;
113 else
115 if (ord)
116 opts->x_debug_struct_ordinary[usage] = files;
117 if (gen)
118 opts->x_debug_struct_generic[usage] = files;
121 if (*spec == ',')
122 set_struct_debug_option (opts, loc, spec+1);
123 else
125 /* No more -femit-struct-debug-detailed specifications.
126 Do final checks. */
127 if (*spec != '\0')
128 error_at (loc,
129 "argument %qs to %<-femit-struct-debug-detailed%> unknown",
130 spec);
131 if (opts->x_debug_struct_ordinary[DINFO_USAGE_DIR_USE]
132 < opts->x_debug_struct_ordinary[DINFO_USAGE_IND_USE]
133 || opts->x_debug_struct_generic[DINFO_USAGE_DIR_USE]
134 < opts->x_debug_struct_generic[DINFO_USAGE_IND_USE])
135 error_at (loc,
136 "%<-femit-struct-debug-detailed=dir:...%> must allow "
137 "at least as much as "
138 "%<-femit-struct-debug-detailed=ind:...%>");
142 /* Handle -ftree-vectorizer-verbose=VAL for options OPTS. */
144 static void
145 vect_set_verbosity_level (struct gcc_options *opts, int val)
147 if (val < MAX_VERBOSITY_LEVEL)
148 opts->x_user_vect_verbosity_level = (enum vect_verbosity_levels) val;
149 else
150 opts->x_user_vect_verbosity_level
151 = (enum vect_verbosity_levels) (MAX_VERBOSITY_LEVEL - 1);
155 /* Strip off a legitimate source ending from the input string NAME of
156 length LEN. Rather than having to know the names used by all of
157 our front ends, we strip off an ending of a period followed by
158 up to five characters. (Java uses ".class".) */
160 void
161 strip_off_ending (char *name, int len)
163 int i;
164 for (i = 2; i < 6 && len > i; i++)
166 if (name[len - i] == '.')
168 name[len - i] = '\0';
169 break;
174 /* Find the base name of a path, stripping off both directories and
175 a single final extension. */
177 base_of_path (const char *path, const char **base_out)
179 const char *base = path;
180 const char *dot = 0;
181 const char *p = path;
182 char c = *p;
183 while (c)
185 if (IS_DIR_SEPARATOR(c))
187 base = p + 1;
188 dot = 0;
190 else if (c == '.')
191 dot = p;
192 c = *++p;
194 if (!dot)
195 dot = p;
196 *base_out = base;
197 return dot - base;
200 /* What to print when a switch has no documentation. */
201 static const char undocumented_msg[] = N_("This switch lacks documentation");
203 typedef char *char_p; /* For DEF_VEC_P. */
204 DEF_VEC_P(char_p);
205 DEF_VEC_ALLOC_P(char_p,heap);
207 static void handle_param (struct gcc_options *opts,
208 struct gcc_options *opts_set, location_t loc,
209 const char *carg);
210 static void set_debug_level (enum debug_info_type type, int extended,
211 const char *arg, struct gcc_options *opts,
212 struct gcc_options *opts_set,
213 location_t loc);
214 static void set_fast_math_flags (struct gcc_options *opts, int set);
215 static void decode_d_option (const char *arg, struct gcc_options *opts,
216 location_t loc, diagnostic_context *dc);
217 static void set_unsafe_math_optimizations_flags (struct gcc_options *opts,
218 int set);
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,
224 location_t loc,
225 diagnostic_context *dc);
227 /* Handle a back-end option; arguments and return value as for
228 handle_option. */
230 bool
231 target_handle_option (struct gcc_options *opts,
232 struct gcc_options *opts_set,
233 const struct cl_decoded_option *decoded,
234 unsigned int lang_mask ATTRIBUTE_UNUSED, int kind,
235 location_t loc,
236 const struct cl_option_handlers *handlers ATTRIBUTE_UNUSED,
237 diagnostic_context *dc)
239 gcc_assert (dc == global_dc);
240 gcc_assert (kind == DK_UNSPECIFIED);
241 return targetm_common.handle_option (opts, opts_set, decoded, loc);
244 /* Add comma-separated strings to a char_p vector. */
246 static void
247 add_comma_separated_to_vector (void **pvec, const char *arg)
249 char *tmp;
250 char *r;
251 char *w;
252 char *token_start;
253 VEC(char_p,heap) *vec = (VEC(char_p,heap) *) *pvec;
255 /* We never free this string. */
256 tmp = xstrdup (arg);
258 r = tmp;
259 w = tmp;
260 token_start = tmp;
262 while (*r != '\0')
264 if (*r == ',')
266 *w++ = '\0';
267 ++r;
268 VEC_safe_push (char_p, heap, vec, token_start);
269 token_start = w;
271 if (*r == '\\' && r[1] == ',')
273 *w++ = ',';
274 r += 2;
276 else
277 *w++ = *r++;
279 if (*token_start != '\0')
280 VEC_safe_push (char_p, heap, vec, token_start);
282 *pvec = vec;
285 /* Initialize OPTS and OPTS_SET before using them in parsing options. */
287 void
288 init_options_struct (struct gcc_options *opts, struct gcc_options *opts_set)
290 size_t num_params = get_num_compiler_params ();
292 *opts = global_options_init;
293 memset (opts_set, 0, sizeof (*opts_set));
295 opts->x_param_values = XNEWVEC (int, num_params);
296 opts_set->x_param_values = XCNEWVEC (int, num_params);
297 init_param_values (opts->x_param_values);
299 /* Initialize whether `char' is signed. */
300 opts->x_flag_signed_char = DEFAULT_SIGNED_CHAR;
301 /* Set this to a special "uninitialized" value. The actual default
302 is set after target options have been processed. */
303 opts->x_flag_short_enums = 2;
305 /* Initialize target_flags before default_options_optimization
306 so the latter can modify it. */
307 opts->x_target_flags = targetm_common.default_target_flags;
309 /* Some targets have ABI-specified unwind tables. */
310 opts->x_flag_unwind_tables = targetm_common.unwind_tables_default;
312 /* Some targets have other target-specific initialization. */
313 targetm_common.option_init_struct (opts);
316 /* If indicated by the optimization level LEVEL (-Os if SIZE is set,
317 -Ofast if FAST is set, -Og if DEBUG is set), apply the option DEFAULT_OPT
318 to OPTS and OPTS_SET, diagnostic context DC, location LOC, with language
319 mask LANG_MASK and option handlers HANDLERS. */
321 static void
322 maybe_default_option (struct gcc_options *opts,
323 struct gcc_options *opts_set,
324 const struct default_options *default_opt,
325 int level, bool size, bool fast, bool debug,
326 unsigned int lang_mask,
327 const struct cl_option_handlers *handlers,
328 location_t loc,
329 diagnostic_context *dc)
331 const struct cl_option *option = &cl_options[default_opt->opt_index];
332 bool enabled;
334 if (size)
335 gcc_assert (level == 2);
336 if (fast)
337 gcc_assert (level == 3);
338 if (debug)
339 gcc_assert (level == 1);
341 switch (default_opt->levels)
343 case OPT_LEVELS_ALL:
344 enabled = true;
345 break;
347 case OPT_LEVELS_0_ONLY:
348 enabled = (level == 0);
349 break;
351 case OPT_LEVELS_1_PLUS:
352 enabled = (level >= 1);
353 break;
355 case OPT_LEVELS_1_PLUS_SPEED_ONLY:
356 enabled = (level >= 1 && !size && !debug);
357 break;
359 case OPT_LEVELS_1_PLUS_NOT_DEBUG:
360 enabled = (level >= 1 && !debug);
361 break;
363 case OPT_LEVELS_2_PLUS:
364 enabled = (level >= 2);
365 break;
367 case OPT_LEVELS_2_PLUS_SPEED_ONLY:
368 enabled = (level >= 2 && !size && !debug);
369 break;
371 case OPT_LEVELS_3_PLUS:
372 enabled = (level >= 3);
373 break;
375 case OPT_LEVELS_3_PLUS_AND_SIZE:
376 enabled = (level >= 3 || size);
377 break;
379 case OPT_LEVELS_SIZE:
380 enabled = size;
381 break;
383 case OPT_LEVELS_FAST:
384 enabled = fast;
385 break;
387 case OPT_LEVELS_NONE:
388 default:
389 gcc_unreachable ();
392 if (enabled)
393 handle_generated_option (opts, opts_set, default_opt->opt_index,
394 default_opt->arg, default_opt->value,
395 lang_mask, DK_UNSPECIFIED, loc,
396 handlers, dc);
397 else if (default_opt->arg == NULL
398 && !option->cl_reject_negative)
399 handle_generated_option (opts, opts_set, default_opt->opt_index,
400 default_opt->arg, !default_opt->value,
401 lang_mask, DK_UNSPECIFIED, loc,
402 handlers, dc);
405 /* As indicated by the optimization level LEVEL (-Os if SIZE is set,
406 -Ofast if FAST is set), apply the options in array DEFAULT_OPTS to
407 OPTS and OPTS_SET, diagnostic context DC, location LOC, with
408 language mask LANG_MASK and option handlers HANDLERS. */
410 static void
411 maybe_default_options (struct gcc_options *opts,
412 struct gcc_options *opts_set,
413 const struct default_options *default_opts,
414 int level, bool size, bool fast, bool debug,
415 unsigned int lang_mask,
416 const struct cl_option_handlers *handlers,
417 location_t loc,
418 diagnostic_context *dc)
420 size_t i;
422 for (i = 0; default_opts[i].levels != OPT_LEVELS_NONE; i++)
423 maybe_default_option (opts, opts_set, &default_opts[i],
424 level, size, fast, debug,
425 lang_mask, handlers, loc, dc);
428 /* Table of options enabled by default at different levels. */
430 static const struct default_options default_options_table[] =
432 /* -O1 optimizations. */
433 { OPT_LEVELS_1_PLUS, OPT_fdefer_pop, NULL, 1 },
434 #ifdef DELAY_SLOTS
435 { OPT_LEVELS_1_PLUS, OPT_fdelayed_branch, NULL, 1 },
436 #endif
437 { OPT_LEVELS_1_PLUS, OPT_fguess_branch_probability, NULL, 1 },
438 { OPT_LEVELS_1_PLUS, OPT_fcprop_registers, NULL, 1 },
439 { OPT_LEVELS_1_PLUS, OPT_fforward_propagate, NULL, 1 },
440 { OPT_LEVELS_1_PLUS, OPT_fif_conversion, NULL, 1 },
441 { OPT_LEVELS_1_PLUS, OPT_fif_conversion2, NULL, 1 },
442 { OPT_LEVELS_1_PLUS, OPT_fipa_pure_const, NULL, 1 },
443 { OPT_LEVELS_1_PLUS, OPT_fipa_reference, NULL, 1 },
444 { OPT_LEVELS_1_PLUS, OPT_fipa_profile, NULL, 1 },
445 { OPT_LEVELS_1_PLUS, OPT_fmerge_constants, NULL, 1 },
446 { OPT_LEVELS_1_PLUS, OPT_fshrink_wrap, NULL, 1 },
447 { OPT_LEVELS_1_PLUS, OPT_fsplit_wide_types, NULL, 1 },
448 { OPT_LEVELS_1_PLUS, OPT_ftree_ccp, NULL, 1 },
449 { OPT_LEVELS_1_PLUS, OPT_ftree_bit_ccp, NULL, 1 },
450 { OPT_LEVELS_1_PLUS, OPT_ftree_dce, NULL, 1 },
451 { OPT_LEVELS_1_PLUS, OPT_ftree_dominator_opts, NULL, 1 },
452 { OPT_LEVELS_1_PLUS, OPT_ftree_dse, NULL, 1 },
453 { OPT_LEVELS_1_PLUS, OPT_ftree_ter, NULL, 1 },
454 { OPT_LEVELS_1_PLUS_NOT_DEBUG, OPT_ftree_sra, NULL, 1 },
455 { OPT_LEVELS_1_PLUS, OPT_ftree_copyrename, NULL, 1 },
456 { OPT_LEVELS_1_PLUS, OPT_ftree_fre, NULL, 1 },
457 { OPT_LEVELS_1_PLUS, OPT_ftree_copy_prop, NULL, 1 },
458 { OPT_LEVELS_1_PLUS, OPT_ftree_sink, NULL, 1 },
459 { OPT_LEVELS_1_PLUS, OPT_ftree_ch, NULL, 1 },
460 { OPT_LEVELS_1_PLUS, OPT_fcombine_stack_adjustments, NULL, 1 },
461 { OPT_LEVELS_1_PLUS, OPT_fcompare_elim, NULL, 1 },
462 { OPT_LEVELS_1_PLUS, OPT_ftree_slsr, NULL, 1 },
464 /* -O2 optimizations. */
465 { OPT_LEVELS_2_PLUS, OPT_finline_small_functions, NULL, 1 },
466 { OPT_LEVELS_2_PLUS, OPT_findirect_inlining, NULL, 1 },
467 { OPT_LEVELS_2_PLUS, OPT_fpartial_inlining, NULL, 1 },
468 { OPT_LEVELS_2_PLUS, OPT_fthread_jumps, NULL, 1 },
469 { OPT_LEVELS_2_PLUS, OPT_fcrossjumping, NULL, 1 },
470 { OPT_LEVELS_2_PLUS, OPT_foptimize_sibling_calls, NULL, 1 },
471 { OPT_LEVELS_2_PLUS, OPT_fcse_follow_jumps, NULL, 1 },
472 { OPT_LEVELS_2_PLUS, OPT_fgcse, NULL, 1 },
473 { OPT_LEVELS_2_PLUS, OPT_fexpensive_optimizations, NULL, 1 },
474 { OPT_LEVELS_2_PLUS, OPT_frerun_cse_after_loop, NULL, 1 },
475 { OPT_LEVELS_2_PLUS, OPT_fcaller_saves, NULL, 1 },
476 { OPT_LEVELS_2_PLUS, OPT_fpeephole2, NULL, 1 },
477 #ifdef INSN_SCHEDULING
478 /* Only run the pre-regalloc scheduling pass if optimizing for speed. */
479 { OPT_LEVELS_2_PLUS_SPEED_ONLY, OPT_fschedule_insns, NULL, 1 },
480 { OPT_LEVELS_2_PLUS, OPT_fschedule_insns2, NULL, 1 },
481 #endif
482 { OPT_LEVELS_2_PLUS, OPT_fregmove, NULL, 1 },
483 { OPT_LEVELS_2_PLUS, OPT_fstrict_aliasing, NULL, 1 },
484 { OPT_LEVELS_2_PLUS, OPT_fstrict_overflow, NULL, 1 },
485 { OPT_LEVELS_2_PLUS, OPT_freorder_blocks, NULL, 1 },
486 { OPT_LEVELS_2_PLUS, OPT_freorder_functions, NULL, 1 },
487 { OPT_LEVELS_2_PLUS, OPT_ftree_vrp, NULL, 1 },
488 { OPT_LEVELS_2_PLUS, OPT_ftree_builtin_call_dce, NULL, 1 },
489 { OPT_LEVELS_2_PLUS, OPT_ftree_pre, NULL, 1 },
490 { OPT_LEVELS_2_PLUS, OPT_ftree_switch_conversion, NULL, 1 },
491 { OPT_LEVELS_2_PLUS, OPT_fipa_cp, NULL, 1 },
492 { OPT_LEVELS_2_PLUS, OPT_fdevirtualize, NULL, 1 },
493 { OPT_LEVELS_2_PLUS, OPT_fipa_sra, NULL, 1 },
494 { OPT_LEVELS_2_PLUS, OPT_falign_loops, NULL, 1 },
495 { OPT_LEVELS_2_PLUS, OPT_falign_jumps, NULL, 1 },
496 { OPT_LEVELS_2_PLUS, OPT_falign_labels, NULL, 1 },
497 { OPT_LEVELS_2_PLUS, OPT_falign_functions, NULL, 1 },
498 { OPT_LEVELS_2_PLUS, OPT_ftree_tail_merge, NULL, 1 },
499 { OPT_LEVELS_2_PLUS_SPEED_ONLY, OPT_foptimize_strlen, NULL, 1 },
500 { OPT_LEVELS_2_PLUS, OPT_fhoist_adjacent_loads, NULL, 1 },
502 /* -O3 optimizations. */
503 { OPT_LEVELS_3_PLUS, OPT_ftree_loop_distribute_patterns, NULL, 1 },
504 { OPT_LEVELS_3_PLUS, OPT_fpredictive_commoning, NULL, 1 },
505 /* Inlining of functions reducing size is a good idea with -Os
506 regardless of them being declared inline. */
507 { OPT_LEVELS_3_PLUS_AND_SIZE, OPT_finline_functions, NULL, 1 },
508 { OPT_LEVELS_1_PLUS_NOT_DEBUG, OPT_finline_functions_called_once, NULL, 1 },
509 { OPT_LEVELS_3_PLUS, OPT_funswitch_loops, NULL, 1 },
510 { OPT_LEVELS_3_PLUS, OPT_fgcse_after_reload, NULL, 1 },
511 { OPT_LEVELS_3_PLUS, OPT_ftree_vectorize, NULL, 1 },
512 { OPT_LEVELS_3_PLUS, OPT_fvect_cost_model, NULL, 1 },
513 { OPT_LEVELS_3_PLUS, OPT_fipa_cp_clone, NULL, 1 },
514 { OPT_LEVELS_3_PLUS, OPT_ftree_partial_pre, NULL, 1 },
516 /* -Ofast adds optimizations to -O3. */
517 { OPT_LEVELS_FAST, OPT_ffast_math, NULL, 1 },
519 { OPT_LEVELS_NONE, 0, NULL, 0 }
522 /* Default the options in OPTS and OPTS_SET based on the optimization
523 settings in DECODED_OPTIONS and DECODED_OPTIONS_COUNT. */
524 void
525 default_options_optimization (struct gcc_options *opts,
526 struct gcc_options *opts_set,
527 struct cl_decoded_option *decoded_options,
528 unsigned int decoded_options_count,
529 location_t loc,
530 unsigned int lang_mask,
531 const struct cl_option_handlers *handlers,
532 diagnostic_context *dc)
534 unsigned int i;
535 int opt2;
537 /* Scan to see what optimization level has been specified. That will
538 determine the default value of many flags. */
539 for (i = 1; i < decoded_options_count; i++)
541 struct cl_decoded_option *opt = &decoded_options[i];
542 switch (opt->opt_index)
544 case OPT_O:
545 if (*opt->arg == '\0')
547 opts->x_optimize = 1;
548 opts->x_optimize_size = 0;
549 opts->x_optimize_fast = 0;
550 opts->x_optimize_debug = 0;
552 else
554 const int optimize_val = integral_argument (opt->arg);
555 if (optimize_val == -1)
556 error_at (loc,
557 "argument to %qs should be a non-negative integer",
558 "-O");
559 else
561 opts->x_optimize = optimize_val;
562 if ((unsigned int) opts->x_optimize > 255)
563 opts->x_optimize = 255;
564 opts->x_optimize_size = 0;
565 opts->x_optimize_fast = 0;
566 opts->x_optimize_debug = 0;
569 break;
571 case OPT_Os:
572 opts->x_optimize_size = 1;
574 /* Optimizing for size forces optimize to be 2. */
575 opts->x_optimize = 2;
576 opts->x_optimize_fast = 0;
577 opts->x_optimize_debug = 0;
578 break;
580 case OPT_Ofast:
581 /* -Ofast only adds flags to -O3. */
582 opts->x_optimize_size = 0;
583 opts->x_optimize = 3;
584 opts->x_optimize_fast = 1;
585 opts->x_optimize_debug = 0;
586 break;
588 case OPT_Og:
589 /* -Og selects optimization level 1. */
590 opts->x_optimize_size = 0;
591 opts->x_optimize = 1;
592 opts->x_optimize_fast = 0;
593 opts->x_optimize_debug = 1;
594 break;
596 default:
597 /* Ignore other options in this prescan. */
598 break;
602 maybe_default_options (opts, opts_set, default_options_table,
603 opts->x_optimize, opts->x_optimize_size,
604 opts->x_optimize_fast, opts->x_optimize_debug,
605 lang_mask, handlers, loc, dc);
607 /* -O2 param settings. */
608 opt2 = (opts->x_optimize >= 2);
610 /* Track fields in field-sensitive alias analysis. */
611 maybe_set_param_value
612 (PARAM_MAX_FIELDS_FOR_FIELD_SENSITIVE,
613 opt2 ? 100 : default_param_value (PARAM_MAX_FIELDS_FOR_FIELD_SENSITIVE),
614 opts->x_param_values, opts_set->x_param_values);
616 /* For -O1 only do loop invariant motion for very small loops. */
617 maybe_set_param_value
618 (PARAM_LOOP_INVARIANT_MAX_BBS_IN_LOOP,
619 opt2 ? default_param_value (PARAM_LOOP_INVARIANT_MAX_BBS_IN_LOOP) : 1000,
620 opts->x_param_values, opts_set->x_param_values);
622 if (opts->x_optimize_size)
623 /* We want to crossjump as much as possible. */
624 maybe_set_param_value (PARAM_MIN_CROSSJUMP_INSNS, 1,
625 opts->x_param_values, opts_set->x_param_values);
626 else
627 maybe_set_param_value (PARAM_MIN_CROSSJUMP_INSNS,
628 default_param_value (PARAM_MIN_CROSSJUMP_INSNS),
629 opts->x_param_values, opts_set->x_param_values);
631 /* Allow default optimizations to be specified on a per-machine basis. */
632 maybe_default_options (opts, opts_set,
633 targetm_common.option_optimization_table,
634 opts->x_optimize, opts->x_optimize_size,
635 opts->x_optimize_fast, opts->x_optimize_debug,
636 lang_mask, handlers, loc, dc);
639 /* After all options at LOC have been read into OPTS and OPTS_SET,
640 finalize settings of those options and diagnose incompatible
641 combinations. */
642 void
643 finish_options (struct gcc_options *opts, struct gcc_options *opts_set,
644 location_t loc)
646 enum unwind_info_type ui_except;
648 if (opts->x_dump_base_name && ! IS_ABSOLUTE_PATH (opts->x_dump_base_name))
650 /* First try to make OPTS->X_DUMP_BASE_NAME relative to the
651 OPTS->X_DUMP_DIR_NAME directory. Then try to make
652 OPTS->X_DUMP_BASE_NAME relative to the OPTS->X_AUX_BASE_NAME
653 directory, typically the directory to contain the object
654 file. */
655 if (opts->x_dump_dir_name)
656 opts->x_dump_base_name = concat (opts->x_dump_dir_name,
657 opts->x_dump_base_name, NULL);
658 else if (opts->x_aux_base_name
659 && strcmp (opts->x_aux_base_name, HOST_BIT_BUCKET) != 0)
661 const char *aux_base;
663 base_of_path (opts->x_aux_base_name, &aux_base);
664 if (opts->x_aux_base_name != aux_base)
666 int dir_len = aux_base - opts->x_aux_base_name;
667 char *new_dump_base_name =
668 XNEWVEC (char, strlen (opts->x_dump_base_name) + dir_len + 1);
670 /* Copy directory component from OPTS->X_AUX_BASE_NAME. */
671 memcpy (new_dump_base_name, opts->x_aux_base_name, dir_len);
672 /* Append existing OPTS->X_DUMP_BASE_NAME. */
673 strcpy (new_dump_base_name + dir_len, opts->x_dump_base_name);
674 opts->x_dump_base_name = new_dump_base_name;
679 /* Handle related options for unit-at-a-time, toplevel-reorder, and
680 section-anchors. */
681 if (!opts->x_flag_unit_at_a_time)
683 if (opts->x_flag_section_anchors && opts_set->x_flag_section_anchors)
684 error_at (loc, "section anchors must be disabled when unit-at-a-time "
685 "is disabled");
686 opts->x_flag_section_anchors = 0;
687 if (opts->x_flag_toplevel_reorder == 1)
688 error_at (loc, "toplevel reorder must be disabled when unit-at-a-time "
689 "is disabled");
690 opts->x_flag_toplevel_reorder = 0;
693 if (opts->x_flag_tm && opts->x_flag_non_call_exceptions)
694 sorry ("transactional memory is not supported with non-call exceptions");
696 /* Unless the user has asked for section anchors, we disable toplevel
697 reordering at -O0 to disable transformations that might be surprising
698 to end users and to get -fno-toplevel-reorder tested. */
699 if (!opts->x_optimize
700 && opts->x_flag_toplevel_reorder == 2
701 && !(opts->x_flag_section_anchors && opts_set->x_flag_section_anchors))
703 opts->x_flag_toplevel_reorder = 0;
704 opts->x_flag_section_anchors = 0;
706 if (!opts->x_flag_toplevel_reorder)
708 if (opts->x_flag_section_anchors && opts_set->x_flag_section_anchors)
709 error_at (loc, "section anchors must be disabled when toplevel reorder"
710 " is disabled");
711 opts->x_flag_section_anchors = 0;
714 if (!opts->x_flag_opts_finished)
716 if (opts->x_flag_pie)
717 opts->x_flag_pic = opts->x_flag_pie;
718 if (opts->x_flag_pic && !opts->x_flag_pie)
719 opts->x_flag_shlib = 1;
720 opts->x_flag_opts_finished = true;
723 if (opts->x_optimize == 0)
725 /* Inlining does not work if not optimizing,
726 so force it not to be done. */
727 opts->x_warn_inline = 0;
728 opts->x_flag_no_inline = 1;
731 /* The optimization to partition hot and cold basic blocks into separate
732 sections of the .o and executable files does not work (currently)
733 with exception handling. This is because there is no support for
734 generating unwind info. If opts->x_flag_exceptions is turned on
735 we need to turn off the partitioning optimization. */
737 ui_except = targetm_common.except_unwind_info (opts);
739 if (opts->x_flag_exceptions
740 && opts->x_flag_reorder_blocks_and_partition
741 && (ui_except == UI_SJLJ || ui_except >= UI_TARGET))
743 inform (loc,
744 "-freorder-blocks-and-partition does not work "
745 "with exceptions on this architecture");
746 opts->x_flag_reorder_blocks_and_partition = 0;
747 opts->x_flag_reorder_blocks = 1;
750 /* If user requested unwind info, then turn off the partitioning
751 optimization. */
753 if (opts->x_flag_unwind_tables
754 && !targetm_common.unwind_tables_default
755 && opts->x_flag_reorder_blocks_and_partition
756 && (ui_except == UI_SJLJ || ui_except >= UI_TARGET))
758 inform (loc,
759 "-freorder-blocks-and-partition does not support "
760 "unwind info on this architecture");
761 opts->x_flag_reorder_blocks_and_partition = 0;
762 opts->x_flag_reorder_blocks = 1;
765 /* If the target requested unwind info, then turn off the partitioning
766 optimization with a different message. Likewise, if the target does not
767 support named sections. */
769 if (opts->x_flag_reorder_blocks_and_partition
770 && (!targetm_common.have_named_sections
771 || (opts->x_flag_unwind_tables
772 && targetm_common.unwind_tables_default
773 && (ui_except == UI_SJLJ || ui_except >= UI_TARGET))))
775 inform (loc,
776 "-freorder-blocks-and-partition does not work "
777 "on this architecture");
778 opts->x_flag_reorder_blocks_and_partition = 0;
779 opts->x_flag_reorder_blocks = 1;
782 if (opts->x_flag_reorder_blocks_and_partition
783 && !opts_set->x_flag_reorder_functions)
784 opts->x_flag_reorder_functions = 1;
786 /* Pipelining of outer loops is only possible when general pipelining
787 capabilities are requested. */
788 if (!opts->x_flag_sel_sched_pipelining)
789 opts->x_flag_sel_sched_pipelining_outer_loops = 0;
791 if (opts->x_flag_conserve_stack)
793 maybe_set_param_value (PARAM_LARGE_STACK_FRAME, 100,
794 opts->x_param_values, opts_set->x_param_values);
795 maybe_set_param_value (PARAM_STACK_FRAME_GROWTH, 40,
796 opts->x_param_values, opts_set->x_param_values);
799 if (opts->x_flag_lto)
801 #ifdef ENABLE_LTO
802 opts->x_flag_generate_lto = 1;
804 /* When generating IL, do not operate in whole-program mode.
805 Otherwise, symbols will be privatized too early, causing link
806 errors later. */
807 opts->x_flag_whole_program = 0;
808 #else
809 error_at (loc, "LTO support has not been enabled in this configuration");
810 #endif
811 if (!opts->x_flag_fat_lto_objects && !HAVE_LTO_PLUGIN)
812 error_at (loc, "-fno-fat-lto-objects are supported only with linker plugin.");
814 if ((opts->x_flag_lto_partition_balanced != 0) + (opts->x_flag_lto_partition_1to1 != 0)
815 + (opts->x_flag_lto_partition_none != 0) >= 1)
817 if ((opts->x_flag_lto_partition_balanced != 0)
818 + (opts->x_flag_lto_partition_1to1 != 0)
819 + (opts->x_flag_lto_partition_none != 0) > 1)
820 error_at (loc, "only one -flto-partition value can be specified");
823 /* We initialize opts->x_flag_split_stack to -1 so that targets can set a
824 default value if they choose based on other options. */
825 if (opts->x_flag_split_stack == -1)
826 opts->x_flag_split_stack = 0;
827 else if (opts->x_flag_split_stack)
829 if (!targetm_common.supports_split_stack (true, opts))
831 error_at (loc, "%<-fsplit-stack%> is not supported by "
832 "this compiler configuration");
833 opts->x_flag_split_stack = 0;
837 /* Set PARAM_MAX_STORES_TO_SINK to 0 if either vectorization or if-conversion
838 is disabled. */
839 if (!opts->x_flag_tree_vectorize || !opts->x_flag_tree_loop_if_convert)
840 maybe_set_param_value (PARAM_MAX_STORES_TO_SINK, 0,
841 opts->x_param_values, opts_set->x_param_values);
843 /* This replaces set_Wunused. */
844 /* Wunused-parameter is enabled if both -Wunused -Wextra are enabled. */
845 if (opts->x_warn_unused_parameter == -1)
846 opts->x_warn_unused_parameter = (opts->x_warn_unused
847 && opts->x_extra_warnings);
848 /* Wunused-but-set-parameter is enabled if both -Wunused -Wextra are
849 enabled. */
850 if (opts->x_warn_unused_but_set_parameter == -1)
851 opts->x_warn_unused_but_set_parameter = (opts->x_warn_unused
852 && opts->x_extra_warnings);
853 /* Wunused-local-typedefs is enabled by -Wunused or -Wall. */
854 if (opts->x_warn_unused_local_typedefs == -1)
855 opts->x_warn_unused_local_typedefs = opts->x_warn_unused;
858 #define LEFT_COLUMN 27
860 /* Output ITEM, of length ITEM_WIDTH, in the left column,
861 followed by word-wrapped HELP in a second column. */
862 static void
863 wrap_help (const char *help,
864 const char *item,
865 unsigned int item_width,
866 unsigned int columns)
868 unsigned int col_width = LEFT_COLUMN;
869 unsigned int remaining, room, len;
871 remaining = strlen (help);
875 room = columns - 3 - MAX (col_width, item_width);
876 if (room > columns)
877 room = 0;
878 len = remaining;
880 if (room < len)
882 unsigned int i;
884 for (i = 0; help[i]; i++)
886 if (i >= room && len != remaining)
887 break;
888 if (help[i] == ' ')
889 len = i;
890 else if ((help[i] == '-' || help[i] == '/')
891 && help[i + 1] != ' '
892 && i > 0 && ISALPHA (help[i - 1]))
893 len = i + 1;
897 printf( " %-*.*s %.*s\n", col_width, item_width, item, len, help);
898 item_width = 0;
899 while (help[len] == ' ')
900 len++;
901 help += len;
902 remaining -= len;
904 while (remaining);
907 /* Print help for a specific front-end, etc. */
908 static void
909 print_filtered_help (unsigned int include_flags,
910 unsigned int exclude_flags,
911 unsigned int any_flags,
912 unsigned int columns,
913 struct gcc_options *opts,
914 unsigned int lang_mask)
916 unsigned int i;
917 const char *help;
918 bool found = false;
919 bool displayed = false;
921 if (include_flags == CL_PARAMS)
923 for (i = 0; i < LAST_PARAM; i++)
925 const char *param = compiler_params[i].option;
927 help = compiler_params[i].help;
928 if (help == NULL || *help == '\0')
930 if (exclude_flags & CL_UNDOCUMENTED)
931 continue;
932 help = undocumented_msg;
935 /* Get the translation. */
936 help = _(help);
938 wrap_help (help, param, strlen (param), columns);
940 putchar ('\n');
941 return;
944 if (!opts->x_help_printed)
945 opts->x_help_printed = XCNEWVAR (char, cl_options_count);
947 if (!opts->x_help_enum_printed)
948 opts->x_help_enum_printed = XCNEWVAR (char, cl_enums_count);
950 for (i = 0; i < cl_options_count; i++)
952 char new_help[128];
953 const struct cl_option *option = cl_options + i;
954 unsigned int len;
955 const char *opt;
956 const char *tab;
958 if (include_flags == 0
959 || ((option->flags & include_flags) != include_flags))
961 if ((option->flags & any_flags) == 0)
962 continue;
965 /* Skip unwanted switches. */
966 if ((option->flags & exclude_flags) != 0)
967 continue;
969 /* The driver currently prints its own help text. */
970 if ((option->flags & CL_DRIVER) != 0
971 && (option->flags & (((1U << cl_lang_count) - 1)
972 | CL_COMMON | CL_TARGET)) == 0)
973 continue;
975 found = true;
976 /* Skip switches that have already been printed. */
977 if (opts->x_help_printed[i])
978 continue;
980 opts->x_help_printed[i] = true;
982 help = option->help;
983 if (help == NULL)
985 if (exclude_flags & CL_UNDOCUMENTED)
986 continue;
987 help = undocumented_msg;
990 /* Get the translation. */
991 help = _(help);
993 /* Find the gap between the name of the
994 option and its descriptive text. */
995 tab = strchr (help, '\t');
996 if (tab)
998 len = tab - help;
999 opt = help;
1000 help = tab + 1;
1002 else
1004 opt = option->opt_text;
1005 len = strlen (opt);
1008 /* With the -Q option enabled we change the descriptive text associated
1009 with an option to be an indication of its current setting. */
1010 if (!opts->x_quiet_flag)
1012 void *flag_var = option_flag_var (i, opts);
1014 if (len < (LEFT_COLUMN + 2))
1015 strcpy (new_help, "\t\t");
1016 else
1017 strcpy (new_help, "\t");
1019 if (flag_var != NULL
1020 && option->var_type != CLVC_DEFER)
1022 if (option->flags & CL_JOINED)
1024 if (option->var_type == CLVC_STRING)
1026 if (* (const char **) flag_var != NULL)
1027 snprintf (new_help + strlen (new_help),
1028 sizeof (new_help) - strlen (new_help),
1029 * (const char **) flag_var);
1031 else if (option->var_type == CLVC_ENUM)
1033 const struct cl_enum *e = &cl_enums[option->var_enum];
1034 int value;
1035 const char *arg = NULL;
1037 value = e->get (flag_var);
1038 enum_value_to_arg (e->values, &arg, value, lang_mask);
1039 if (arg == NULL)
1040 arg = _("[default]");
1041 snprintf (new_help + strlen (new_help),
1042 sizeof (new_help) - strlen (new_help),
1043 arg);
1045 else
1046 sprintf (new_help + strlen (new_help),
1047 "%#x", * (int *) flag_var);
1049 else
1050 strcat (new_help, option_enabled (i, opts)
1051 ? _("[enabled]") : _("[disabled]"));
1054 help = new_help;
1057 wrap_help (help, opt, len, columns);
1058 displayed = true;
1060 if (option->var_type == CLVC_ENUM
1061 && opts->x_help_enum_printed[option->var_enum] != 2)
1062 opts->x_help_enum_printed[option->var_enum] = 1;
1065 if (! found)
1067 unsigned int langs = include_flags & CL_LANG_ALL;
1069 if (langs == 0)
1070 printf (_(" No options with the desired characteristics were found\n"));
1071 else
1073 unsigned int i;
1075 /* PR 31349: Tell the user how to see all of the
1076 options supported by a specific front end. */
1077 for (i = 0; (1U << i) < CL_LANG_ALL; i ++)
1078 if ((1U << i) & langs)
1079 printf (_(" None found. Use --help=%s to show *all* the options supported by the %s front-end\n"),
1080 lang_names[i], lang_names[i]);
1084 else if (! displayed)
1085 printf (_(" All options with the desired characteristics have already been displayed\n"));
1087 putchar ('\n');
1089 /* Print details of enumerated option arguments, if those
1090 enumerations have help text headings provided. If no help text
1091 is provided, presume that the possible values are listed in the
1092 help text for the relevant options. */
1093 for (i = 0; i < cl_enums_count; i++)
1095 unsigned int j, pos;
1097 if (opts->x_help_enum_printed[i] != 1)
1098 continue;
1099 if (cl_enums[i].help == NULL)
1100 continue;
1101 printf (" %s\n ", _(cl_enums[i].help));
1102 pos = 4;
1103 for (j = 0; cl_enums[i].values[j].arg != NULL; j++)
1105 unsigned int len = strlen (cl_enums[i].values[j].arg);
1107 if (pos > 4 && pos + 1 + len <= columns)
1109 printf (" %s", cl_enums[i].values[j].arg);
1110 pos += 1 + len;
1112 else
1114 if (pos > 4)
1116 printf ("\n ");
1117 pos = 4;
1119 printf ("%s", cl_enums[i].values[j].arg);
1120 pos += len;
1123 printf ("\n\n");
1124 opts->x_help_enum_printed[i] = 2;
1128 /* Display help for a specified type of option.
1129 The options must have ALL of the INCLUDE_FLAGS set
1130 ANY of the flags in the ANY_FLAGS set
1131 and NONE of the EXCLUDE_FLAGS set. The current option state is in
1132 OPTS; LANG_MASK is used for interpreting enumerated option state. */
1133 static void
1134 print_specific_help (unsigned int include_flags,
1135 unsigned int exclude_flags,
1136 unsigned int any_flags,
1137 struct gcc_options *opts,
1138 unsigned int lang_mask)
1140 unsigned int all_langs_mask = (1U << cl_lang_count) - 1;
1141 const char * description = NULL;
1142 const char * descrip_extra = "";
1143 size_t i;
1144 unsigned int flag;
1146 /* Sanity check: Make sure that we do not have more
1147 languages than we have bits available to enumerate them. */
1148 gcc_assert ((1U << cl_lang_count) <= CL_MIN_OPTION_CLASS);
1150 /* If we have not done so already, obtain
1151 the desired maximum width of the output. */
1152 if (opts->x_help_columns == 0)
1154 const char *p;
1156 p = getenv ("COLUMNS");
1157 if (p != NULL)
1159 int value = atoi (p);
1161 if (value > 0)
1162 opts->x_help_columns = value;
1165 if (opts->x_help_columns == 0)
1166 /* Use a reasonable default. */
1167 opts->x_help_columns = 80;
1170 /* Decide upon the title for the options that we are going to display. */
1171 for (i = 0, flag = 1; flag <= CL_MAX_OPTION_CLASS; flag <<= 1, i ++)
1173 switch (flag & include_flags)
1175 case 0:
1176 case CL_DRIVER:
1177 break;
1179 case CL_TARGET:
1180 description = _("The following options are target specific");
1181 break;
1182 case CL_WARNING:
1183 description = _("The following options control compiler warning messages");
1184 break;
1185 case CL_OPTIMIZATION:
1186 description = _("The following options control optimizations");
1187 break;
1188 case CL_COMMON:
1189 description = _("The following options are language-independent");
1190 break;
1191 case CL_PARAMS:
1192 description = _("The --param option recognizes the following as parameters");
1193 break;
1194 default:
1195 if (i >= cl_lang_count)
1196 break;
1197 if (exclude_flags & all_langs_mask)
1198 description = _("The following options are specific to just the language ");
1199 else
1200 description = _("The following options are supported by the language ");
1201 descrip_extra = lang_names [i];
1202 break;
1206 if (description == NULL)
1208 if (any_flags == 0)
1210 if (include_flags & CL_UNDOCUMENTED)
1211 description = _("The following options are not documented");
1212 else if (include_flags & CL_SEPARATE)
1213 description = _("The following options take separate arguments");
1214 else if (include_flags & CL_JOINED)
1215 description = _("The following options take joined arguments");
1216 else
1218 internal_error ("unrecognized include_flags 0x%x passed to print_specific_help",
1219 include_flags);
1220 return;
1223 else
1225 if (any_flags & all_langs_mask)
1226 description = _("The following options are language-related");
1227 else
1228 description = _("The following options are language-independent");
1232 printf ("%s%s:\n", description, descrip_extra);
1233 print_filtered_help (include_flags, exclude_flags, any_flags,
1234 opts->x_help_columns, opts, lang_mask);
1237 /* Handle target- and language-independent options. Return zero to
1238 generate an "unknown option" message. Only options that need
1239 extra handling need to be listed here; if you simply want
1240 DECODED->value assigned to a variable, it happens automatically. */
1242 bool
1243 common_handle_option (struct gcc_options *opts,
1244 struct gcc_options *opts_set,
1245 const struct cl_decoded_option *decoded,
1246 unsigned int lang_mask, int kind ATTRIBUTE_UNUSED,
1247 location_t loc,
1248 const struct cl_option_handlers *handlers,
1249 diagnostic_context *dc)
1251 size_t scode = decoded->opt_index;
1252 const char *arg = decoded->arg;
1253 int value = decoded->value;
1254 enum opt_code code = (enum opt_code) scode;
1256 gcc_assert (decoded->canonical_option_num_elements <= 2);
1258 switch (code)
1260 case OPT__param:
1261 handle_param (opts, opts_set, loc, arg);
1262 break;
1264 case OPT__help:
1266 unsigned int all_langs_mask = (1U << cl_lang_count) - 1;
1267 unsigned int undoc_mask;
1268 unsigned int i;
1270 if (lang_mask == CL_DRIVER)
1271 break;;
1273 undoc_mask = ((opts->x_verbose_flag | opts->x_extra_warnings)
1275 : CL_UNDOCUMENTED);
1276 /* First display any single language specific options. */
1277 for (i = 0; i < cl_lang_count; i++)
1278 print_specific_help
1279 (1U << i, (all_langs_mask & (~ (1U << i))) | undoc_mask, 0, opts,
1280 lang_mask);
1281 /* Next display any multi language specific options. */
1282 print_specific_help (0, undoc_mask, all_langs_mask, opts, lang_mask);
1283 /* Then display any remaining, non-language options. */
1284 for (i = CL_MIN_OPTION_CLASS; i <= CL_MAX_OPTION_CLASS; i <<= 1)
1285 if (i != CL_DRIVER)
1286 print_specific_help (i, undoc_mask, 0, opts, lang_mask);
1287 opts->x_exit_after_options = true;
1288 break;
1291 case OPT__target_help:
1292 if (lang_mask == CL_DRIVER)
1293 break;
1295 print_specific_help (CL_TARGET, CL_UNDOCUMENTED, 0, opts, lang_mask);
1296 opts->x_exit_after_options = true;
1297 break;
1299 case OPT__help_:
1301 const char * a = arg;
1302 unsigned int include_flags = 0;
1303 /* Note - by default we include undocumented options when listing
1304 specific classes. If you only want to see documented options
1305 then add ",^undocumented" to the --help= option. E.g.:
1307 --help=target,^undocumented */
1308 unsigned int exclude_flags = 0;
1310 if (lang_mask == CL_DRIVER)
1311 break;
1313 /* Walk along the argument string, parsing each word in turn.
1314 The format is:
1315 arg = [^]{word}[,{arg}]
1316 word = {optimizers|target|warnings|undocumented|
1317 params|common|<language>} */
1318 while (* a != 0)
1320 static const struct
1322 const char * string;
1323 unsigned int flag;
1325 specifics[] =
1327 { "optimizers", CL_OPTIMIZATION },
1328 { "target", CL_TARGET },
1329 { "warnings", CL_WARNING },
1330 { "undocumented", CL_UNDOCUMENTED },
1331 { "params", CL_PARAMS },
1332 { "joined", CL_JOINED },
1333 { "separate", CL_SEPARATE },
1334 { "common", CL_COMMON },
1335 { NULL, 0 }
1337 unsigned int * pflags;
1338 const char * comma;
1339 unsigned int lang_flag, specific_flag;
1340 unsigned int len;
1341 unsigned int i;
1343 if (* a == '^')
1345 ++ a;
1346 pflags = & exclude_flags;
1348 else
1349 pflags = & include_flags;
1351 comma = strchr (a, ',');
1352 if (comma == NULL)
1353 len = strlen (a);
1354 else
1355 len = comma - a;
1356 if (len == 0)
1358 a = comma + 1;
1359 continue;
1362 /* Check to see if the string matches an option class name. */
1363 for (i = 0, specific_flag = 0; specifics[i].string != NULL; i++)
1364 if (strncasecmp (a, specifics[i].string, len) == 0)
1366 specific_flag = specifics[i].flag;
1367 break;
1370 /* Check to see if the string matches a language name.
1371 Note - we rely upon the alpha-sorted nature of the entries in
1372 the lang_names array, specifically that shorter names appear
1373 before their longer variants. (i.e. C before C++). That way
1374 when we are attempting to match --help=c for example we will
1375 match with C first and not C++. */
1376 for (i = 0, lang_flag = 0; i < cl_lang_count; i++)
1377 if (strncasecmp (a, lang_names[i], len) == 0)
1379 lang_flag = 1U << i;
1380 break;
1383 if (specific_flag != 0)
1385 if (lang_flag == 0)
1386 * pflags |= specific_flag;
1387 else
1389 /* The option's argument matches both the start of a
1390 language name and the start of an option class name.
1391 We have a special case for when the user has
1392 specified "--help=c", but otherwise we have to issue
1393 a warning. */
1394 if (strncasecmp (a, "c", len) == 0)
1395 * pflags |= lang_flag;
1396 else
1397 warning_at (loc, 0,
1398 "--help argument %q.*s is ambiguous, "
1399 "please be more specific",
1400 len, a);
1403 else if (lang_flag != 0)
1404 * pflags |= lang_flag;
1405 else
1406 warning_at (loc, 0,
1407 "unrecognized argument to --help= option: %q.*s",
1408 len, a);
1410 if (comma == NULL)
1411 break;
1412 a = comma + 1;
1415 if (include_flags)
1416 print_specific_help (include_flags, exclude_flags, 0, opts,
1417 lang_mask);
1418 opts->x_exit_after_options = true;
1419 break;
1422 case OPT__version:
1423 if (lang_mask == CL_DRIVER)
1424 break;
1426 opts->x_exit_after_options = true;
1427 break;
1429 case OPT_O:
1430 case OPT_Os:
1431 case OPT_Ofast:
1432 case OPT_Og:
1433 /* Currently handled in a prescan. */
1434 break;
1436 case OPT_Werror:
1437 dc->warning_as_error_requested = value;
1438 break;
1440 case OPT_Werror_:
1441 if (lang_mask == CL_DRIVER)
1442 break;
1444 enable_warning_as_error (arg, value, lang_mask, handlers,
1445 opts, opts_set, loc, dc);
1446 break;
1448 case OPT_Wlarger_than_:
1449 opts->x_larger_than_size = value;
1450 opts->x_warn_larger_than = value != -1;
1451 break;
1453 case OPT_Wfatal_errors:
1454 dc->fatal_errors = value;
1455 break;
1457 case OPT_Wframe_larger_than_:
1458 opts->x_frame_larger_than_size = value;
1459 opts->x_warn_frame_larger_than = value != -1;
1460 break;
1462 case OPT_Wstack_usage_:
1463 opts->x_warn_stack_usage = value;
1464 opts->x_flag_stack_usage_info = value != -1;
1465 break;
1467 case OPT_Wstrict_aliasing:
1468 set_Wstrict_aliasing (opts, value);
1469 break;
1471 case OPT_Wstrict_overflow:
1472 opts->x_warn_strict_overflow = (value
1473 ? (int) WARN_STRICT_OVERFLOW_CONDITIONAL
1474 : 0);
1475 break;
1477 case OPT_Wsystem_headers:
1478 dc->dc_warn_system_headers = value;
1479 break;
1481 case OPT_aux_info:
1482 opts->x_flag_gen_aux_info = 1;
1483 break;
1485 case OPT_auxbase_strip:
1487 char *tmp = xstrdup (arg);
1488 strip_off_ending (tmp, strlen (tmp));
1489 if (tmp[0])
1490 opts->x_aux_base_name = tmp;
1492 break;
1494 case OPT_d:
1495 decode_d_option (arg, opts, loc, dc);
1496 break;
1498 case OPT_fcall_used_:
1499 case OPT_fcall_saved_:
1500 /* Deferred. */
1501 break;
1503 case OPT_fdbg_cnt_:
1504 case OPT_fdbg_cnt_list:
1505 /* Deferred. */
1506 break;
1508 case OPT_fdebug_prefix_map_:
1509 /* Deferred. */
1510 break;
1512 case OPT_fdiagnostics_show_location_:
1513 diagnostic_prefixing_rule (dc) = (diagnostic_prefixing_rule_t) value;
1514 break;
1516 case OPT_fdiagnostics_show_caret:
1517 dc->show_caret = value;
1518 break;
1520 case OPT_fdiagnostics_show_option:
1521 dc->show_option_requested = value;
1522 break;
1524 case OPT_fdump_:
1525 /* Deferred. */
1526 break;
1528 case OPT_ffast_math:
1529 set_fast_math_flags (opts, value);
1530 break;
1532 case OPT_funsafe_math_optimizations:
1533 set_unsafe_math_optimizations_flags (opts, value);
1534 break;
1536 case OPT_ffixed_:
1537 /* Deferred. */
1538 break;
1540 case OPT_finline_limit_:
1541 set_param_value ("max-inline-insns-single", value / 2,
1542 opts->x_param_values, opts_set->x_param_values);
1543 set_param_value ("max-inline-insns-auto", value / 2,
1544 opts->x_param_values, opts_set->x_param_values);
1545 break;
1547 case OPT_finstrument_functions_exclude_function_list_:
1548 add_comma_separated_to_vector
1549 (&opts->x_flag_instrument_functions_exclude_functions, arg);
1550 break;
1552 case OPT_finstrument_functions_exclude_file_list_:
1553 add_comma_separated_to_vector
1554 (&opts->x_flag_instrument_functions_exclude_files, arg);
1555 break;
1557 case OPT_fmessage_length_:
1558 pp_set_line_maximum_length (dc->printer, value);
1559 diagnostic_set_caret_max_width (dc, value);
1560 break;
1562 case OPT_fpack_struct_:
1563 if (value <= 0 || (value & (value - 1)) || value > 16)
1564 error_at (loc,
1565 "structure alignment must be a small power of two, not %d",
1566 value);
1567 else
1568 opts->x_initial_max_fld_align = value;
1569 break;
1571 case OPT_fplugin_:
1572 case OPT_fplugin_arg_:
1573 /* Deferred. */
1574 break;
1576 case OPT_fprofile_use_:
1577 opts->x_profile_data_prefix = xstrdup (arg);
1578 opts->x_flag_profile_use = true;
1579 value = true;
1580 /* No break here - do -fprofile-use processing. */
1581 case OPT_fprofile_use:
1582 if (!opts_set->x_flag_branch_probabilities)
1583 opts->x_flag_branch_probabilities = value;
1584 if (!opts_set->x_flag_profile_values)
1585 opts->x_flag_profile_values = value;
1586 if (!opts_set->x_flag_unroll_loops)
1587 opts->x_flag_unroll_loops = value;
1588 if (!opts_set->x_flag_peel_loops)
1589 opts->x_flag_peel_loops = value;
1590 if (!opts_set->x_flag_tracer)
1591 opts->x_flag_tracer = value;
1592 if (!opts_set->x_flag_value_profile_transformations)
1593 opts->x_flag_value_profile_transformations = value;
1594 if (!opts_set->x_flag_inline_functions)
1595 opts->x_flag_inline_functions = value;
1596 if (!opts_set->x_flag_ipa_cp)
1597 opts->x_flag_ipa_cp = value;
1598 if (!opts_set->x_flag_ipa_cp_clone
1599 && value && opts->x_flag_ipa_cp)
1600 opts->x_flag_ipa_cp_clone = value;
1601 if (!opts_set->x_flag_predictive_commoning)
1602 opts->x_flag_predictive_commoning = value;
1603 if (!opts_set->x_flag_unswitch_loops)
1604 opts->x_flag_unswitch_loops = value;
1605 if (!opts_set->x_flag_gcse_after_reload)
1606 opts->x_flag_gcse_after_reload = value;
1607 break;
1609 case OPT_fprofile_generate_:
1610 opts->x_profile_data_prefix = xstrdup (arg);
1611 value = true;
1612 /* No break here - do -fprofile-generate processing. */
1613 case OPT_fprofile_generate:
1614 if (!opts_set->x_profile_arc_flag)
1615 opts->x_profile_arc_flag = value;
1616 if (!opts_set->x_flag_profile_values)
1617 opts->x_flag_profile_values = value;
1618 if (!opts_set->x_flag_inline_functions)
1619 opts->x_flag_inline_functions = value;
1620 /* FIXME: Instrumentation we insert makes ipa-reference bitmaps
1621 quadratic. Disable the pass until better memory representation
1622 is done. */
1623 if (!opts_set->x_flag_ipa_reference && opts->x_in_lto_p)
1624 opts->x_flag_ipa_reference = false;
1625 break;
1627 case OPT_fshow_column:
1628 dc->show_column = value;
1629 break;
1631 case OPT_frandom_seed:
1632 /* The real switch is -fno-random-seed. */
1633 if (value)
1634 return false;
1635 /* Deferred. */
1636 break;
1638 case OPT_frandom_seed_:
1639 /* Deferred. */
1640 break;
1642 case OPT_fsched_verbose_:
1643 #ifdef INSN_SCHEDULING
1644 /* Handled with Var in common.opt. */
1645 break;
1646 #else
1647 return false;
1648 #endif
1650 case OPT_fsched_stalled_insns_:
1651 opts->x_flag_sched_stalled_insns = value;
1652 if (opts->x_flag_sched_stalled_insns == 0)
1653 opts->x_flag_sched_stalled_insns = -1;
1654 break;
1656 case OPT_fsched_stalled_insns_dep_:
1657 opts->x_flag_sched_stalled_insns_dep = value;
1658 break;
1660 case OPT_fstack_check_:
1661 if (!strcmp (arg, "no"))
1662 opts->x_flag_stack_check = NO_STACK_CHECK;
1663 else if (!strcmp (arg, "generic"))
1664 /* This is the old stack checking method. */
1665 opts->x_flag_stack_check = STACK_CHECK_BUILTIN
1666 ? FULL_BUILTIN_STACK_CHECK
1667 : GENERIC_STACK_CHECK;
1668 else if (!strcmp (arg, "specific"))
1669 /* This is the new stack checking method. */
1670 opts->x_flag_stack_check = STACK_CHECK_BUILTIN
1671 ? FULL_BUILTIN_STACK_CHECK
1672 : STACK_CHECK_STATIC_BUILTIN
1673 ? STATIC_BUILTIN_STACK_CHECK
1674 : GENERIC_STACK_CHECK;
1675 else
1676 warning_at (loc, 0, "unknown stack check parameter \"%s\"", arg);
1677 break;
1679 case OPT_fstack_limit:
1680 /* The real switch is -fno-stack-limit. */
1681 if (value)
1682 return false;
1683 /* Deferred. */
1684 break;
1686 case OPT_fstack_limit_register_:
1687 case OPT_fstack_limit_symbol_:
1688 /* Deferred. */
1689 break;
1691 case OPT_fstack_usage:
1692 opts->x_flag_stack_usage = value;
1693 opts->x_flag_stack_usage_info = value != 0;
1694 break;
1696 case OPT_ftree_vectorizer_verbose_:
1697 vect_set_verbosity_level (opts, value);
1698 break;
1700 case OPT_g:
1701 set_debug_level (NO_DEBUG, DEFAULT_GDB_EXTENSIONS, arg, opts, opts_set,
1702 loc);
1703 break;
1705 case OPT_gcoff:
1706 set_debug_level (SDB_DEBUG, false, arg, opts, opts_set, loc);
1707 break;
1709 case OPT_gdwarf_:
1710 if (value < 2 || value > 4)
1711 error_at (loc, "dwarf version %d is not supported", value);
1712 else
1713 opts->x_dwarf_version = value;
1714 set_debug_level (DWARF2_DEBUG, false, "", opts, opts_set, loc);
1715 break;
1717 case OPT_ggdb:
1718 set_debug_level (NO_DEBUG, 2, arg, opts, opts_set, loc);
1719 break;
1721 case OPT_gstabs:
1722 case OPT_gstabs_:
1723 set_debug_level (DBX_DEBUG, code == OPT_gstabs_, arg, opts, opts_set,
1724 loc);
1725 break;
1727 case OPT_gvms:
1728 set_debug_level (VMS_DEBUG, false, arg, opts, opts_set, loc);
1729 break;
1731 case OPT_gxcoff:
1732 case OPT_gxcoff_:
1733 set_debug_level (XCOFF_DEBUG, code == OPT_gxcoff_, arg, opts, opts_set,
1734 loc);
1735 break;
1737 case OPT_pedantic_errors:
1738 dc->pedantic_errors = 1;
1739 control_warning_option (OPT_Wpedantic, DK_ERROR, value,
1740 loc, lang_mask,
1741 handlers, opts, opts_set,
1742 dc);
1743 break;
1745 case OPT_flto:
1746 opts->x_flag_lto = value ? "" : NULL;
1747 break;
1749 case OPT_w:
1750 dc->dc_inhibit_warnings = true;
1751 break;
1753 case OPT_fmax_errors_:
1754 dc->max_errors = value;
1755 break;
1757 case OPT_fuse_linker_plugin:
1758 /* No-op. Used by the driver and passed to us because it starts with f.*/
1759 break;
1761 default:
1762 /* If the flag was handled in a standard way, assume the lack of
1763 processing here is intentional. */
1764 gcc_assert (option_flag_var (scode, opts));
1765 break;
1768 common_handle_option_auto (opts, opts_set, decoded, lang_mask, kind,
1769 loc, handlers, dc);
1770 return true;
1773 /* Handle --param NAME=VALUE. */
1774 static void
1775 handle_param (struct gcc_options *opts, struct gcc_options *opts_set,
1776 location_t loc, const char *carg)
1778 char *equal, *arg;
1779 int value;
1781 arg = xstrdup (carg);
1782 equal = strchr (arg, '=');
1783 if (!equal)
1784 error_at (loc, "%s: --param arguments should be of the form NAME=VALUE",
1785 arg);
1786 else
1788 value = integral_argument (equal + 1);
1789 if (value == -1)
1790 error_at (loc, "invalid --param value %qs", equal + 1);
1791 else
1793 *equal = '\0';
1794 set_param_value (arg, value,
1795 opts->x_param_values, opts_set->x_param_values);
1799 free (arg);
1802 /* Used to set the level of strict aliasing warnings in OPTS,
1803 when no level is specified (i.e., when -Wstrict-aliasing, and not
1804 -Wstrict-aliasing=level was given).
1805 ONOFF is assumed to take value 1 when -Wstrict-aliasing is specified,
1806 and 0 otherwise. After calling this function, wstrict_aliasing will be
1807 set to the default value of -Wstrict_aliasing=level, currently 3. */
1808 void
1809 set_Wstrict_aliasing (struct gcc_options *opts, int onoff)
1811 gcc_assert (onoff == 0 || onoff == 1);
1812 if (onoff != 0)
1813 opts->x_warn_strict_aliasing = 3;
1814 else
1815 opts->x_warn_strict_aliasing = 0;
1818 /* The following routines are useful in setting all the flags that
1819 -ffast-math and -fno-fast-math imply. */
1820 static void
1821 set_fast_math_flags (struct gcc_options *opts, int set)
1823 if (!opts->frontend_set_flag_unsafe_math_optimizations)
1825 opts->x_flag_unsafe_math_optimizations = set;
1826 set_unsafe_math_optimizations_flags (opts, set);
1828 if (!opts->frontend_set_flag_finite_math_only)
1829 opts->x_flag_finite_math_only = set;
1830 if (!opts->frontend_set_flag_errno_math)
1831 opts->x_flag_errno_math = !set;
1832 if (set)
1834 if (!opts->frontend_set_flag_signaling_nans)
1835 opts->x_flag_signaling_nans = 0;
1836 if (!opts->frontend_set_flag_rounding_math)
1837 opts->x_flag_rounding_math = 0;
1838 if (!opts->frontend_set_flag_cx_limited_range)
1839 opts->x_flag_cx_limited_range = 1;
1843 /* When -funsafe-math-optimizations is set the following
1844 flags are set as well. */
1845 static void
1846 set_unsafe_math_optimizations_flags (struct gcc_options *opts, int set)
1848 if (!opts->frontend_set_flag_trapping_math)
1849 opts->x_flag_trapping_math = !set;
1850 if (!opts->frontend_set_flag_signed_zeros)
1851 opts->x_flag_signed_zeros = !set;
1852 if (!opts->frontend_set_flag_associative_math)
1853 opts->x_flag_associative_math = set;
1854 if (!opts->frontend_set_flag_reciprocal_math)
1855 opts->x_flag_reciprocal_math = set;
1858 /* Return true iff flags in OPTS are set as if -ffast-math. */
1859 bool
1860 fast_math_flags_set_p (const struct gcc_options *opts)
1862 return (!opts->x_flag_trapping_math
1863 && opts->x_flag_unsafe_math_optimizations
1864 && opts->x_flag_finite_math_only
1865 && !opts->x_flag_signed_zeros
1866 && !opts->x_flag_errno_math);
1869 /* Return true iff flags are set as if -ffast-math but using the flags stored
1870 in the struct cl_optimization structure. */
1871 bool
1872 fast_math_flags_struct_set_p (struct cl_optimization *opt)
1874 return (!opt->x_flag_trapping_math
1875 && opt->x_flag_unsafe_math_optimizations
1876 && opt->x_flag_finite_math_only
1877 && !opt->x_flag_signed_zeros
1878 && !opt->x_flag_errno_math);
1881 /* Handle a debug output -g switch for options OPTS
1882 (OPTS_SET->x_write_symbols storing whether a debug type was passed
1883 explicitly), location LOC. EXTENDED is true or false to support
1884 extended output (2 is special and means "-ggdb" was given). */
1885 static void
1886 set_debug_level (enum debug_info_type type, int extended, const char *arg,
1887 struct gcc_options *opts, struct gcc_options *opts_set,
1888 location_t loc)
1890 opts->x_use_gnu_debug_info_extensions = extended;
1892 if (type == NO_DEBUG)
1894 if (opts->x_write_symbols == NO_DEBUG)
1896 opts->x_write_symbols = PREFERRED_DEBUGGING_TYPE;
1898 if (extended == 2)
1900 #ifdef DWARF2_DEBUGGING_INFO
1901 opts->x_write_symbols = DWARF2_DEBUG;
1902 #elif defined DBX_DEBUGGING_INFO
1903 opts->x_write_symbols = DBX_DEBUG;
1904 #endif
1907 if (opts->x_write_symbols == NO_DEBUG)
1908 warning_at (loc, 0, "target system does not support debug output");
1911 else
1913 /* Does it conflict with an already selected type? */
1914 if (opts_set->x_write_symbols != NO_DEBUG
1915 && opts->x_write_symbols != NO_DEBUG
1916 && type != opts->x_write_symbols)
1917 error_at (loc, "debug format \"%s\" conflicts with prior selection",
1918 debug_type_names[type]);
1919 opts->x_write_symbols = type;
1920 opts_set->x_write_symbols = type;
1923 /* A debug flag without a level defaults to level 2. */
1924 if (*arg == '\0')
1926 if (!opts->x_debug_info_level)
1927 opts->x_debug_info_level = DINFO_LEVEL_NORMAL;
1929 else
1931 int argval = integral_argument (arg);
1932 if (argval == -1)
1933 error_at (loc, "unrecognised debug output level \"%s\"", arg);
1934 else if (argval > 3)
1935 error_at (loc, "debug output level %s is too high", arg);
1936 else
1937 opts->x_debug_info_level = (enum debug_info_levels) argval;
1941 /* Arrange to dump core on error for diagnostic context DC. (The
1942 regular error message is still printed first, except in the case of
1943 abort ().) */
1945 static void
1946 setup_core_dumping (diagnostic_context *dc)
1948 #ifdef SIGABRT
1949 signal (SIGABRT, SIG_DFL);
1950 #endif
1951 #if defined(HAVE_SETRLIMIT)
1953 struct rlimit rlim;
1954 if (getrlimit (RLIMIT_CORE, &rlim) != 0)
1955 fatal_error ("getting core file size maximum limit: %m");
1956 rlim.rlim_cur = rlim.rlim_max;
1957 if (setrlimit (RLIMIT_CORE, &rlim) != 0)
1958 fatal_error ("setting core file size limit to maximum: %m");
1960 #endif
1961 diagnostic_abort_on_error (dc);
1964 /* Parse a -d<ARG> command line switch for OPTS, location LOC,
1965 diagnostic context DC. */
1967 static void
1968 decode_d_option (const char *arg, struct gcc_options *opts,
1969 location_t loc, diagnostic_context *dc)
1971 int c;
1973 while (*arg)
1974 switch (c = *arg++)
1976 case 'A':
1977 opts->x_flag_debug_asm = 1;
1978 break;
1979 case 'p':
1980 opts->x_flag_print_asm_name = 1;
1981 break;
1982 case 'P':
1983 opts->x_flag_dump_rtl_in_asm = 1;
1984 opts->x_flag_print_asm_name = 1;
1985 break;
1986 case 'v':
1987 opts->x_graph_dump_format = vcg;
1988 break;
1989 case 'x':
1990 opts->x_rtl_dump_and_exit = 1;
1991 break;
1992 case 'D': /* These are handled by the preprocessor. */
1993 case 'I':
1994 case 'M':
1995 case 'N':
1996 case 'U':
1997 break;
1998 case 'H':
1999 setup_core_dumping (dc);
2000 break;
2001 case 'a':
2002 opts->x_flag_dump_all_passed = true;
2003 break;
2005 default:
2006 warning_at (loc, 0, "unrecognized gcc debugging option: %c", c);
2007 break;
2011 /* Enable (or disable if VALUE is 0) a warning option ARG (language
2012 mask LANG_MASK, option handlers HANDLERS) as an error for option
2013 structures OPTS and OPTS_SET, diagnostic context DC (possibly
2014 NULL), location LOC. This is used by -Werror=. */
2016 static void
2017 enable_warning_as_error (const char *arg, int value, unsigned int lang_mask,
2018 const struct cl_option_handlers *handlers,
2019 struct gcc_options *opts,
2020 struct gcc_options *opts_set,
2021 location_t loc, diagnostic_context *dc)
2023 char *new_option;
2024 int option_index;
2026 new_option = XNEWVEC (char, strlen (arg) + 2);
2027 new_option[0] = 'W';
2028 strcpy (new_option + 1, arg);
2029 option_index = find_opt (new_option, lang_mask);
2030 if (option_index == OPT_SPECIAL_unknown)
2032 error_at (loc, "-Werror=%s: no option -%s", arg, new_option);
2034 else
2036 const diagnostic_t kind = value ? DK_ERROR : DK_WARNING;
2038 control_warning_option (option_index, (int) kind, value,
2039 loc, lang_mask,
2040 handlers, opts, opts_set, dc);
2042 free (new_option);
2045 /* Return malloced memory for the name of the option OPTION_INDEX
2046 which enabled a diagnostic (context CONTEXT), originally of type
2047 ORIG_DIAG_KIND but possibly converted to DIAG_KIND by options such
2048 as -Werror. */
2050 char *
2051 option_name (diagnostic_context *context, int option_index,
2052 diagnostic_t orig_diag_kind, diagnostic_t diag_kind)
2054 if (option_index)
2056 /* A warning classified as an error. */
2057 if ((orig_diag_kind == DK_WARNING || orig_diag_kind == DK_PEDWARN)
2058 && diag_kind == DK_ERROR)
2059 return concat (cl_options[OPT_Werror_].opt_text,
2060 /* Skip over "-W". */
2061 cl_options[option_index].opt_text + 2,
2062 NULL);
2063 /* A warning with option. */
2064 else
2065 return xstrdup (cl_options[option_index].opt_text);
2067 /* A warning without option classified as an error. */
2068 else if (orig_diag_kind == DK_WARNING || orig_diag_kind == DK_PEDWARN
2069 || diag_kind == DK_WARNING)
2071 if (context->warning_as_error_requested)
2072 return xstrdup (cl_options[OPT_Werror].opt_text);
2073 else
2074 return xstrdup (_("enabled by default"));
2076 else
2077 return NULL;