Mark ChangeLog
[official-gcc.git] / gcc / opts.c
blob55cd965282d5a8af478feb5c528e23e97a881633
1 /* Command line option handling.
2 Copyright (C) 2002-2013 Free Software Foundation, Inc.
3 Contributed by Neil Booth.
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 3, or (at your option) any later
10 version.
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 for more details.
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING3. If not see
19 <http://www.gnu.org/licenses/>. */
21 #include "config.h"
22 #include "system.h"
23 #include "intl.h"
24 #include "coretypes.h"
25 #include "opts.h"
26 #include "options.h"
27 #include "tm.h" /* For STACK_CHECK_BUILTIN,
28 STACK_CHECK_STATIC_BUILTIN, DEFAULT_GDB_EXTENSIONS,
29 DWARF2_DEBUGGING_INFO and DBX_DEBUGGING_INFO. */
30 #include "flags.h"
31 #include "params.h"
32 #include "diagnostic.h"
33 #include "opts-diagnostic.h"
34 #include "insn-attr-common.h"
35 #include "common/common-target.h"
37 static void set_Wstrict_aliasing (struct gcc_options *opts, int onoff);
39 /* Indexed by enum debug_info_type. */
40 const char *const debug_type_names[] =
42 "none", "stabs", "coff", "dwarf-2", "xcoff", "vms"
45 /* Parse the -femit-struct-debug-detailed option value
46 and set the flag variables. */
48 #define MATCH( prefix, string ) \
49 ((strncmp (prefix, string, sizeof prefix - 1) == 0) \
50 ? ((string += sizeof prefix - 1), 1) : 0)
52 void
53 set_struct_debug_option (struct gcc_options *opts, location_t loc,
54 const char *spec)
56 /* various labels for comparison */
57 static const char dfn_lbl[] = "dfn:", dir_lbl[] = "dir:", ind_lbl[] = "ind:";
58 static const char ord_lbl[] = "ord:", gen_lbl[] = "gen:";
59 static const char none_lbl[] = "none", any_lbl[] = "any";
60 static const char base_lbl[] = "base", sys_lbl[] = "sys";
62 enum debug_struct_file files = DINFO_STRUCT_FILE_ANY;
63 /* Default is to apply to as much as possible. */
64 enum debug_info_usage usage = DINFO_USAGE_NUM_ENUMS;
65 int ord = 1, gen = 1;
67 /* What usage? */
68 if (MATCH (dfn_lbl, spec))
69 usage = DINFO_USAGE_DFN;
70 else if (MATCH (dir_lbl, spec))
71 usage = DINFO_USAGE_DIR_USE;
72 else if (MATCH (ind_lbl, spec))
73 usage = DINFO_USAGE_IND_USE;
75 /* Generics or not? */
76 if (MATCH (ord_lbl, spec))
77 gen = 0;
78 else if (MATCH (gen_lbl, spec))
79 ord = 0;
81 /* What allowable environment? */
82 if (MATCH (none_lbl, spec))
83 files = DINFO_STRUCT_FILE_NONE;
84 else if (MATCH (any_lbl, spec))
85 files = DINFO_STRUCT_FILE_ANY;
86 else if (MATCH (sys_lbl, spec))
87 files = DINFO_STRUCT_FILE_SYS;
88 else if (MATCH (base_lbl, spec))
89 files = DINFO_STRUCT_FILE_BASE;
90 else
91 error_at (loc,
92 "argument %qs to %<-femit-struct-debug-detailed%> "
93 "not recognized",
94 spec);
96 /* Effect the specification. */
97 if (usage == DINFO_USAGE_NUM_ENUMS)
99 if (ord)
101 opts->x_debug_struct_ordinary[DINFO_USAGE_DFN] = files;
102 opts->x_debug_struct_ordinary[DINFO_USAGE_DIR_USE] = files;
103 opts->x_debug_struct_ordinary[DINFO_USAGE_IND_USE] = files;
105 if (gen)
107 opts->x_debug_struct_generic[DINFO_USAGE_DFN] = files;
108 opts->x_debug_struct_generic[DINFO_USAGE_DIR_USE] = files;
109 opts->x_debug_struct_generic[DINFO_USAGE_IND_USE] = files;
112 else
114 if (ord)
115 opts->x_debug_struct_ordinary[usage] = files;
116 if (gen)
117 opts->x_debug_struct_generic[usage] = files;
120 if (*spec == ',')
121 set_struct_debug_option (opts, loc, spec+1);
122 else
124 /* No more -femit-struct-debug-detailed specifications.
125 Do final checks. */
126 if (*spec != '\0')
127 error_at (loc,
128 "argument %qs to %<-femit-struct-debug-detailed%> unknown",
129 spec);
130 if (opts->x_debug_struct_ordinary[DINFO_USAGE_DIR_USE]
131 < opts->x_debug_struct_ordinary[DINFO_USAGE_IND_USE]
132 || opts->x_debug_struct_generic[DINFO_USAGE_DIR_USE]
133 < opts->x_debug_struct_generic[DINFO_USAGE_IND_USE])
134 error_at (loc,
135 "%<-femit-struct-debug-detailed=dir:...%> must allow "
136 "at least as much as "
137 "%<-femit-struct-debug-detailed=ind:...%>");
141 /* Strip off a legitimate source ending from the input string NAME of
142 length LEN. Rather than having to know the names used by all of
143 our front ends, we strip off an ending of a period followed by
144 up to five characters. (Java uses ".class".) */
146 void
147 strip_off_ending (char *name, int len)
149 int i;
150 for (i = 2; i < 6 && len > i; i++)
152 if (name[len - i] == '.')
154 name[len - i] = '\0';
155 break;
160 /* Find the base name of a path, stripping off both directories and
161 a single final extension. */
163 base_of_path (const char *path, const char **base_out)
165 const char *base = path;
166 const char *dot = 0;
167 const char *p = path;
168 char c = *p;
169 while (c)
171 if (IS_DIR_SEPARATOR(c))
173 base = p + 1;
174 dot = 0;
176 else if (c == '.')
177 dot = p;
178 c = *++p;
180 if (!dot)
181 dot = p;
182 *base_out = base;
183 return dot - base;
186 /* What to print when a switch has no documentation. */
187 static const char undocumented_msg[] = N_("This switch lacks documentation");
189 typedef char *char_p; /* For DEF_VEC_P. */
191 static void handle_param (struct gcc_options *opts,
192 struct gcc_options *opts_set, location_t loc,
193 const char *carg);
194 static void set_debug_level (enum debug_info_type type, int extended,
195 const char *arg, struct gcc_options *opts,
196 struct gcc_options *opts_set,
197 location_t loc);
198 static void set_fast_math_flags (struct gcc_options *opts, int set);
199 static void decode_d_option (const char *arg, struct gcc_options *opts,
200 location_t loc, diagnostic_context *dc);
201 static void set_unsafe_math_optimizations_flags (struct gcc_options *opts,
202 int set);
203 static void enable_warning_as_error (const char *arg, int value,
204 unsigned int lang_mask,
205 const struct cl_option_handlers *handlers,
206 struct gcc_options *opts,
207 struct gcc_options *opts_set,
208 location_t loc,
209 diagnostic_context *dc);
211 /* Handle a back-end option; arguments and return value as for
212 handle_option. */
214 bool
215 target_handle_option (struct gcc_options *opts,
216 struct gcc_options *opts_set,
217 const struct cl_decoded_option *decoded,
218 unsigned int lang_mask ATTRIBUTE_UNUSED, int kind,
219 location_t loc,
220 const struct cl_option_handlers *handlers ATTRIBUTE_UNUSED,
221 diagnostic_context *dc)
223 gcc_assert (dc == global_dc);
224 gcc_assert (kind == DK_UNSPECIFIED);
225 return targetm_common.handle_option (opts, opts_set, decoded, loc);
228 /* Add comma-separated strings to a char_p vector. */
230 static void
231 add_comma_separated_to_vector (void **pvec, const char *arg)
233 char *tmp;
234 char *r;
235 char *w;
236 char *token_start;
237 vec<char_p> *v = (vec<char_p> *) *pvec;
239 vec_check_alloc (v, 1);
241 /* We never free this string. */
242 tmp = xstrdup (arg);
244 r = tmp;
245 w = tmp;
246 token_start = tmp;
248 while (*r != '\0')
250 if (*r == ',')
252 *w++ = '\0';
253 ++r;
254 v->safe_push (token_start);
255 token_start = w;
257 if (*r == '\\' && r[1] == ',')
259 *w++ = ',';
260 r += 2;
262 else
263 *w++ = *r++;
265 if (*token_start != '\0')
266 v->safe_push (token_start);
268 *pvec = v;
271 /* Initialize OPTS and OPTS_SET before using them in parsing options. */
273 void
274 init_options_struct (struct gcc_options *opts, struct gcc_options *opts_set)
276 size_t num_params = get_num_compiler_params ();
278 gcc_obstack_init (&opts_obstack);
280 *opts = global_options_init;
281 memset (opts_set, 0, sizeof (*opts_set));
283 opts->x_param_values = XNEWVEC (int, num_params);
284 opts_set->x_param_values = XCNEWVEC (int, num_params);
285 init_param_values (opts->x_param_values);
287 /* Initialize whether `char' is signed. */
288 opts->x_flag_signed_char = DEFAULT_SIGNED_CHAR;
289 /* Set this to a special "uninitialized" value. The actual default
290 is set after target options have been processed. */
291 opts->x_flag_short_enums = 2;
293 /* Initialize target_flags before default_options_optimization
294 so the latter can modify it. */
295 opts->x_target_flags = targetm_common.default_target_flags;
297 /* Some targets have ABI-specified unwind tables. */
298 opts->x_flag_unwind_tables = targetm_common.unwind_tables_default;
300 /* Some targets have other target-specific initialization. */
301 targetm_common.option_init_struct (opts);
304 /* If indicated by the optimization level LEVEL (-Os if SIZE is set,
305 -Ofast if FAST is set, -Og if DEBUG is set), apply the option DEFAULT_OPT
306 to OPTS and OPTS_SET, diagnostic context DC, location LOC, with language
307 mask LANG_MASK and option handlers HANDLERS. */
309 static void
310 maybe_default_option (struct gcc_options *opts,
311 struct gcc_options *opts_set,
312 const struct default_options *default_opt,
313 int level, bool size, bool fast, bool debug,
314 unsigned int lang_mask,
315 const struct cl_option_handlers *handlers,
316 location_t loc,
317 diagnostic_context *dc)
319 const struct cl_option *option = &cl_options[default_opt->opt_index];
320 bool enabled;
322 if (size)
323 gcc_assert (level == 2);
324 if (fast)
325 gcc_assert (level == 3);
326 if (debug)
327 gcc_assert (level == 1);
329 switch (default_opt->levels)
331 case OPT_LEVELS_ALL:
332 enabled = true;
333 break;
335 case OPT_LEVELS_0_ONLY:
336 enabled = (level == 0);
337 break;
339 case OPT_LEVELS_1_PLUS:
340 enabled = (level >= 1);
341 break;
343 case OPT_LEVELS_1_PLUS_SPEED_ONLY:
344 enabled = (level >= 1 && !size && !debug);
345 break;
347 case OPT_LEVELS_1_PLUS_NOT_DEBUG:
348 enabled = (level >= 1 && !debug);
349 break;
351 case OPT_LEVELS_2_PLUS:
352 enabled = (level >= 2);
353 break;
355 case OPT_LEVELS_2_PLUS_SPEED_ONLY:
356 enabled = (level >= 2 && !size && !debug);
357 break;
359 case OPT_LEVELS_3_PLUS:
360 enabled = (level >= 3);
361 break;
363 case OPT_LEVELS_3_PLUS_AND_SIZE:
364 enabled = (level >= 3 || size);
365 break;
367 case OPT_LEVELS_SIZE:
368 enabled = size;
369 break;
371 case OPT_LEVELS_FAST:
372 enabled = fast;
373 break;
375 case OPT_LEVELS_NONE:
376 default:
377 gcc_unreachable ();
380 if (enabled)
381 handle_generated_option (opts, opts_set, default_opt->opt_index,
382 default_opt->arg, default_opt->value,
383 lang_mask, DK_UNSPECIFIED, loc,
384 handlers, dc);
385 else if (default_opt->arg == NULL
386 && !option->cl_reject_negative)
387 handle_generated_option (opts, opts_set, default_opt->opt_index,
388 default_opt->arg, !default_opt->value,
389 lang_mask, DK_UNSPECIFIED, loc,
390 handlers, dc);
393 /* As indicated by the optimization level LEVEL (-Os if SIZE is set,
394 -Ofast if FAST is set), apply the options in array DEFAULT_OPTS to
395 OPTS and OPTS_SET, diagnostic context DC, location LOC, with
396 language mask LANG_MASK and option handlers HANDLERS. */
398 static void
399 maybe_default_options (struct gcc_options *opts,
400 struct gcc_options *opts_set,
401 const struct default_options *default_opts,
402 int level, bool size, bool fast, bool debug,
403 unsigned int lang_mask,
404 const struct cl_option_handlers *handlers,
405 location_t loc,
406 diagnostic_context *dc)
408 size_t i;
410 for (i = 0; default_opts[i].levels != OPT_LEVELS_NONE; i++)
411 maybe_default_option (opts, opts_set, &default_opts[i],
412 level, size, fast, debug,
413 lang_mask, handlers, loc, dc);
416 /* Table of options enabled by default at different levels. */
418 static const struct default_options default_options_table[] =
420 /* -O1 optimizations. */
421 { OPT_LEVELS_1_PLUS, OPT_fdefer_pop, NULL, 1 },
422 #ifdef DELAY_SLOTS
423 { OPT_LEVELS_1_PLUS, OPT_fdelayed_branch, NULL, 1 },
424 #endif
425 { OPT_LEVELS_1_PLUS, OPT_fguess_branch_probability, NULL, 1 },
426 { OPT_LEVELS_1_PLUS, OPT_fcprop_registers, NULL, 1 },
427 { OPT_LEVELS_1_PLUS, OPT_fforward_propagate, NULL, 1 },
428 { OPT_LEVELS_1_PLUS_NOT_DEBUG, OPT_fif_conversion, NULL, 1 },
429 { OPT_LEVELS_1_PLUS_NOT_DEBUG, OPT_fif_conversion2, NULL, 1 },
430 { OPT_LEVELS_1_PLUS, OPT_fipa_pure_const, NULL, 1 },
431 { OPT_LEVELS_1_PLUS, OPT_fipa_reference, NULL, 1 },
432 { OPT_LEVELS_1_PLUS, OPT_fipa_profile, NULL, 1 },
433 { OPT_LEVELS_1_PLUS, OPT_fmerge_constants, NULL, 1 },
434 { OPT_LEVELS_1_PLUS, OPT_fshrink_wrap, NULL, 1 },
435 { OPT_LEVELS_1_PLUS, OPT_fsplit_wide_types, NULL, 1 },
436 { OPT_LEVELS_1_PLUS, OPT_ftree_ccp, NULL, 1 },
437 { OPT_LEVELS_1_PLUS, OPT_ftree_bit_ccp, NULL, 1 },
438 { OPT_LEVELS_1_PLUS, OPT_ftree_dce, NULL, 1 },
439 { OPT_LEVELS_1_PLUS, OPT_ftree_dominator_opts, NULL, 1 },
440 { OPT_LEVELS_1_PLUS, OPT_ftree_dse, NULL, 1 },
441 { OPT_LEVELS_1_PLUS, OPT_ftree_ter, NULL, 1 },
442 { OPT_LEVELS_1_PLUS_NOT_DEBUG, OPT_ftree_sra, NULL, 1 },
443 { OPT_LEVELS_1_PLUS, OPT_ftree_copyrename, NULL, 1 },
444 { OPT_LEVELS_1_PLUS, OPT_ftree_fre, NULL, 1 },
445 { OPT_LEVELS_1_PLUS, OPT_ftree_copy_prop, NULL, 1 },
446 { OPT_LEVELS_1_PLUS, OPT_ftree_sink, NULL, 1 },
447 { OPT_LEVELS_1_PLUS, OPT_ftree_ch, NULL, 1 },
448 { OPT_LEVELS_1_PLUS, OPT_fcombine_stack_adjustments, NULL, 1 },
449 { OPT_LEVELS_1_PLUS, OPT_fcompare_elim, NULL, 1 },
450 { OPT_LEVELS_1_PLUS, OPT_ftree_slsr, NULL, 1 },
452 /* -O2 optimizations. */
453 { OPT_LEVELS_2_PLUS, OPT_finline_small_functions, NULL, 1 },
454 { OPT_LEVELS_2_PLUS, OPT_findirect_inlining, NULL, 1 },
455 { OPT_LEVELS_2_PLUS, OPT_fpartial_inlining, NULL, 1 },
456 { OPT_LEVELS_2_PLUS, OPT_fthread_jumps, NULL, 1 },
457 { OPT_LEVELS_2_PLUS, OPT_fcrossjumping, NULL, 1 },
458 { OPT_LEVELS_2_PLUS, OPT_foptimize_sibling_calls, NULL, 1 },
459 { OPT_LEVELS_2_PLUS, OPT_fcse_follow_jumps, NULL, 1 },
460 { OPT_LEVELS_2_PLUS, OPT_fgcse, NULL, 1 },
461 { OPT_LEVELS_2_PLUS, OPT_fexpensive_optimizations, NULL, 1 },
462 { OPT_LEVELS_2_PLUS, OPT_frerun_cse_after_loop, NULL, 1 },
463 { OPT_LEVELS_2_PLUS, OPT_fcaller_saves, NULL, 1 },
464 { OPT_LEVELS_2_PLUS, OPT_fpeephole2, NULL, 1 },
465 #ifdef INSN_SCHEDULING
466 /* Only run the pre-regalloc scheduling pass if optimizing for speed. */
467 { OPT_LEVELS_2_PLUS_SPEED_ONLY, OPT_fschedule_insns, NULL, 1 },
468 { OPT_LEVELS_2_PLUS, OPT_fschedule_insns2, NULL, 1 },
469 #endif
470 { OPT_LEVELS_2_PLUS, OPT_fregmove, NULL, 1 },
471 { OPT_LEVELS_2_PLUS, OPT_fstrict_aliasing, NULL, 1 },
472 { OPT_LEVELS_2_PLUS, OPT_fstrict_overflow, NULL, 1 },
473 { OPT_LEVELS_2_PLUS, OPT_freorder_blocks, NULL, 1 },
474 { OPT_LEVELS_2_PLUS, OPT_freorder_functions, NULL, 1 },
475 { OPT_LEVELS_2_PLUS, OPT_ftree_vrp, NULL, 1 },
476 { OPT_LEVELS_2_PLUS, OPT_ftree_builtin_call_dce, NULL, 1 },
477 { OPT_LEVELS_2_PLUS, OPT_ftree_pre, NULL, 1 },
478 { OPT_LEVELS_2_PLUS, OPT_ftree_switch_conversion, NULL, 1 },
479 { OPT_LEVELS_2_PLUS, OPT_fipa_cp, NULL, 1 },
480 { OPT_LEVELS_2_PLUS, OPT_fdevirtualize, NULL, 1 },
481 { OPT_LEVELS_2_PLUS, OPT_fipa_sra, NULL, 1 },
482 { OPT_LEVELS_2_PLUS, OPT_falign_loops, NULL, 1 },
483 { OPT_LEVELS_2_PLUS, OPT_falign_jumps, NULL, 1 },
484 { OPT_LEVELS_2_PLUS, OPT_falign_labels, NULL, 1 },
485 { OPT_LEVELS_2_PLUS, OPT_falign_functions, NULL, 1 },
486 { OPT_LEVELS_2_PLUS, OPT_ftree_tail_merge, NULL, 1 },
487 { OPT_LEVELS_2_PLUS_SPEED_ONLY, OPT_foptimize_strlen, NULL, 1 },
488 { OPT_LEVELS_2_PLUS, OPT_fhoist_adjacent_loads, NULL, 1 },
490 /* -O3 optimizations. */
491 { OPT_LEVELS_3_PLUS, OPT_ftree_loop_distribute_patterns, NULL, 1 },
492 { OPT_LEVELS_3_PLUS, OPT_fpredictive_commoning, NULL, 1 },
493 /* Inlining of functions reducing size is a good idea with -Os
494 regardless of them being declared inline. */
495 { OPT_LEVELS_3_PLUS_AND_SIZE, OPT_finline_functions, NULL, 1 },
496 { OPT_LEVELS_1_PLUS_NOT_DEBUG, OPT_finline_functions_called_once, NULL, 1 },
497 { OPT_LEVELS_3_PLUS, OPT_funswitch_loops, NULL, 1 },
498 { OPT_LEVELS_3_PLUS, OPT_fgcse_after_reload, NULL, 1 },
499 { OPT_LEVELS_3_PLUS, OPT_ftree_vectorize, NULL, 1 },
500 { OPT_LEVELS_3_PLUS, OPT_fvect_cost_model, NULL, 1 },
501 { OPT_LEVELS_3_PLUS, OPT_fipa_cp_clone, NULL, 1 },
502 { OPT_LEVELS_3_PLUS, OPT_ftree_partial_pre, NULL, 1 },
504 /* -Ofast adds optimizations to -O3. */
505 { OPT_LEVELS_FAST, OPT_ffast_math, NULL, 1 },
507 { OPT_LEVELS_NONE, 0, NULL, 0 }
510 /* Default the options in OPTS and OPTS_SET based on the optimization
511 settings in DECODED_OPTIONS and DECODED_OPTIONS_COUNT. */
512 void
513 default_options_optimization (struct gcc_options *opts,
514 struct gcc_options *opts_set,
515 struct cl_decoded_option *decoded_options,
516 unsigned int decoded_options_count,
517 location_t loc,
518 unsigned int lang_mask,
519 const struct cl_option_handlers *handlers,
520 diagnostic_context *dc)
522 unsigned int i;
523 int opt2;
525 /* Scan to see what optimization level has been specified. That will
526 determine the default value of many flags. */
527 for (i = 1; i < decoded_options_count; i++)
529 struct cl_decoded_option *opt = &decoded_options[i];
530 switch (opt->opt_index)
532 case OPT_O:
533 if (*opt->arg == '\0')
535 opts->x_optimize = 1;
536 opts->x_optimize_size = 0;
537 opts->x_optimize_fast = 0;
538 opts->x_optimize_debug = 0;
540 else
542 const int optimize_val = integral_argument (opt->arg);
543 if (optimize_val == -1)
544 error_at (loc, "argument to %<-O%> should be a non-negative "
545 "integer, %<g%>, %<s%> or %<fast%>");
546 else
548 opts->x_optimize = optimize_val;
549 if ((unsigned int) opts->x_optimize > 255)
550 opts->x_optimize = 255;
551 opts->x_optimize_size = 0;
552 opts->x_optimize_fast = 0;
553 opts->x_optimize_debug = 0;
556 break;
558 case OPT_Os:
559 opts->x_optimize_size = 1;
561 /* Optimizing for size forces optimize to be 2. */
562 opts->x_optimize = 2;
563 opts->x_optimize_fast = 0;
564 opts->x_optimize_debug = 0;
565 break;
567 case OPT_Ofast:
568 /* -Ofast only adds flags to -O3. */
569 opts->x_optimize_size = 0;
570 opts->x_optimize = 3;
571 opts->x_optimize_fast = 1;
572 opts->x_optimize_debug = 0;
573 break;
575 case OPT_Og:
576 /* -Og selects optimization level 1. */
577 opts->x_optimize_size = 0;
578 opts->x_optimize = 1;
579 opts->x_optimize_fast = 0;
580 opts->x_optimize_debug = 1;
581 break;
583 default:
584 /* Ignore other options in this prescan. */
585 break;
589 maybe_default_options (opts, opts_set, default_options_table,
590 opts->x_optimize, opts->x_optimize_size,
591 opts->x_optimize_fast, opts->x_optimize_debug,
592 lang_mask, handlers, loc, dc);
594 /* -O2 param settings. */
595 opt2 = (opts->x_optimize >= 2);
597 /* Track fields in field-sensitive alias analysis. */
598 maybe_set_param_value
599 (PARAM_MAX_FIELDS_FOR_FIELD_SENSITIVE,
600 opt2 ? 100 : default_param_value (PARAM_MAX_FIELDS_FOR_FIELD_SENSITIVE),
601 opts->x_param_values, opts_set->x_param_values);
603 /* For -O1 only do loop invariant motion for very small loops. */
604 maybe_set_param_value
605 (PARAM_LOOP_INVARIANT_MAX_BBS_IN_LOOP,
606 opt2 ? default_param_value (PARAM_LOOP_INVARIANT_MAX_BBS_IN_LOOP) : 1000,
607 opts->x_param_values, opts_set->x_param_values);
609 if (opts->x_optimize_size)
610 /* We want to crossjump as much as possible. */
611 maybe_set_param_value (PARAM_MIN_CROSSJUMP_INSNS, 1,
612 opts->x_param_values, opts_set->x_param_values);
613 else
614 maybe_set_param_value (PARAM_MIN_CROSSJUMP_INSNS,
615 default_param_value (PARAM_MIN_CROSSJUMP_INSNS),
616 opts->x_param_values, opts_set->x_param_values);
618 /* Allow default optimizations to be specified on a per-machine basis. */
619 maybe_default_options (opts, opts_set,
620 targetm_common.option_optimization_table,
621 opts->x_optimize, opts->x_optimize_size,
622 opts->x_optimize_fast, opts->x_optimize_debug,
623 lang_mask, handlers, loc, dc);
626 /* After all options at LOC have been read into OPTS and OPTS_SET,
627 finalize settings of those options and diagnose incompatible
628 combinations. */
629 void
630 finish_options (struct gcc_options *opts, struct gcc_options *opts_set,
631 location_t loc)
633 enum unwind_info_type ui_except;
635 if (opts->x_dump_base_name && ! IS_ABSOLUTE_PATH (opts->x_dump_base_name))
637 /* First try to make OPTS->X_DUMP_BASE_NAME relative to the
638 OPTS->X_DUMP_DIR_NAME directory. Then try to make
639 OPTS->X_DUMP_BASE_NAME relative to the OPTS->X_AUX_BASE_NAME
640 directory, typically the directory to contain the object
641 file. */
642 if (opts->x_dump_dir_name)
643 opts->x_dump_base_name = opts_concat (opts->x_dump_dir_name,
644 opts->x_dump_base_name, NULL);
645 else if (opts->x_aux_base_name
646 && strcmp (opts->x_aux_base_name, HOST_BIT_BUCKET) != 0)
648 const char *aux_base;
650 base_of_path (opts->x_aux_base_name, &aux_base);
651 if (opts->x_aux_base_name != aux_base)
653 int dir_len = aux_base - opts->x_aux_base_name;
654 char *new_dump_base_name
655 = XOBNEWVEC (&opts_obstack, char,
656 strlen (opts->x_dump_base_name) + dir_len + 1);
658 /* Copy directory component from OPTS->X_AUX_BASE_NAME. */
659 memcpy (new_dump_base_name, opts->x_aux_base_name, dir_len);
660 /* Append existing OPTS->X_DUMP_BASE_NAME. */
661 strcpy (new_dump_base_name + dir_len, opts->x_dump_base_name);
662 opts->x_dump_base_name = new_dump_base_name;
667 /* Handle related options for unit-at-a-time, toplevel-reorder, and
668 section-anchors. */
669 if (!opts->x_flag_unit_at_a_time)
671 if (opts->x_flag_section_anchors && opts_set->x_flag_section_anchors)
672 error_at (loc, "section anchors must be disabled when unit-at-a-time "
673 "is disabled");
674 opts->x_flag_section_anchors = 0;
675 if (opts->x_flag_toplevel_reorder == 1)
676 error_at (loc, "toplevel reorder must be disabled when unit-at-a-time "
677 "is disabled");
678 opts->x_flag_toplevel_reorder = 0;
681 if (opts->x_flag_tm && opts->x_flag_non_call_exceptions)
682 sorry ("transactional memory is not supported with non-call exceptions");
684 /* Unless the user has asked for section anchors, we disable toplevel
685 reordering at -O0 to disable transformations that might be surprising
686 to end users and to get -fno-toplevel-reorder tested. */
687 if (!opts->x_optimize
688 && opts->x_flag_toplevel_reorder == 2
689 && !(opts->x_flag_section_anchors && opts_set->x_flag_section_anchors))
691 opts->x_flag_toplevel_reorder = 0;
692 opts->x_flag_section_anchors = 0;
694 if (!opts->x_flag_toplevel_reorder)
696 if (opts->x_flag_section_anchors && opts_set->x_flag_section_anchors)
697 error_at (loc, "section anchors must be disabled when toplevel reorder"
698 " is disabled");
699 opts->x_flag_section_anchors = 0;
702 if (!opts->x_flag_opts_finished)
704 if (opts->x_flag_pie)
705 opts->x_flag_pic = opts->x_flag_pie;
706 if (opts->x_flag_pic && !opts->x_flag_pie)
707 opts->x_flag_shlib = 1;
708 opts->x_flag_opts_finished = true;
711 if (opts->x_optimize == 0)
713 /* Inlining does not work if not optimizing,
714 so force it not to be done. */
715 opts->x_warn_inline = 0;
716 opts->x_flag_no_inline = 1;
719 /* The optimization to partition hot and cold basic blocks into separate
720 sections of the .o and executable files does not work (currently)
721 with exception handling. This is because there is no support for
722 generating unwind info. If opts->x_flag_exceptions is turned on
723 we need to turn off the partitioning optimization. */
725 ui_except = targetm_common.except_unwind_info (opts);
727 if (opts->x_flag_exceptions
728 && opts->x_flag_reorder_blocks_and_partition
729 && (ui_except == UI_SJLJ || ui_except >= UI_TARGET))
731 inform (loc,
732 "-freorder-blocks-and-partition does not work "
733 "with exceptions on this architecture");
734 opts->x_flag_reorder_blocks_and_partition = 0;
735 opts->x_flag_reorder_blocks = 1;
738 /* If user requested unwind info, then turn off the partitioning
739 optimization. */
741 if (opts->x_flag_unwind_tables
742 && !targetm_common.unwind_tables_default
743 && opts->x_flag_reorder_blocks_and_partition
744 && (ui_except == UI_SJLJ || ui_except >= UI_TARGET))
746 inform (loc,
747 "-freorder-blocks-and-partition does not support "
748 "unwind info on this architecture");
749 opts->x_flag_reorder_blocks_and_partition = 0;
750 opts->x_flag_reorder_blocks = 1;
753 /* If the target requested unwind info, then turn off the partitioning
754 optimization with a different message. Likewise, if the target does not
755 support named sections. */
757 if (opts->x_flag_reorder_blocks_and_partition
758 && (!targetm_common.have_named_sections
759 || (opts->x_flag_unwind_tables
760 && targetm_common.unwind_tables_default
761 && (ui_except == UI_SJLJ || ui_except >= UI_TARGET))))
763 inform (loc,
764 "-freorder-blocks-and-partition does not work "
765 "on this architecture");
766 opts->x_flag_reorder_blocks_and_partition = 0;
767 opts->x_flag_reorder_blocks = 1;
770 if (opts->x_flag_reorder_blocks_and_partition
771 && !opts_set->x_flag_reorder_functions)
772 opts->x_flag_reorder_functions = 1;
774 /* Pipelining of outer loops is only possible when general pipelining
775 capabilities are requested. */
776 if (!opts->x_flag_sel_sched_pipelining)
777 opts->x_flag_sel_sched_pipelining_outer_loops = 0;
779 if (opts->x_flag_conserve_stack)
781 maybe_set_param_value (PARAM_LARGE_STACK_FRAME, 100,
782 opts->x_param_values, opts_set->x_param_values);
783 maybe_set_param_value (PARAM_STACK_FRAME_GROWTH, 40,
784 opts->x_param_values, opts_set->x_param_values);
787 if (opts->x_flag_lto)
789 #ifdef ENABLE_LTO
790 opts->x_flag_generate_lto = 1;
792 /* When generating IL, do not operate in whole-program mode.
793 Otherwise, symbols will be privatized too early, causing link
794 errors later. */
795 opts->x_flag_whole_program = 0;
796 #else
797 error_at (loc, "LTO support has not been enabled in this configuration");
798 #endif
799 if (!opts->x_flag_fat_lto_objects && !HAVE_LTO_PLUGIN)
800 error_at (loc, "-fno-fat-lto-objects are supported only with linker plugin.");
802 if ((opts->x_flag_lto_partition_balanced != 0) + (opts->x_flag_lto_partition_1to1 != 0)
803 + (opts->x_flag_lto_partition_none != 0) >= 1)
805 if ((opts->x_flag_lto_partition_balanced != 0)
806 + (opts->x_flag_lto_partition_1to1 != 0)
807 + (opts->x_flag_lto_partition_none != 0) > 1)
808 error_at (loc, "only one -flto-partition value can be specified");
811 /* We initialize opts->x_flag_split_stack to -1 so that targets can set a
812 default value if they choose based on other options. */
813 if (opts->x_flag_split_stack == -1)
814 opts->x_flag_split_stack = 0;
815 else if (opts->x_flag_split_stack)
817 if (!targetm_common.supports_split_stack (true, opts))
819 error_at (loc, "%<-fsplit-stack%> is not supported by "
820 "this compiler configuration");
821 opts->x_flag_split_stack = 0;
825 /* Set PARAM_MAX_STORES_TO_SINK to 0 if either vectorization or if-conversion
826 is disabled. */
827 if (!opts->x_flag_tree_vectorize || !opts->x_flag_tree_loop_if_convert)
828 maybe_set_param_value (PARAM_MAX_STORES_TO_SINK, 0,
829 opts->x_param_values, opts_set->x_param_values);
831 /* The -gsplit-dwarf option requires -gpubnames. */
832 if (opts->x_dwarf_split_debug_info)
833 opts->x_debug_generate_pub_sections = 1;
836 #define LEFT_COLUMN 27
838 /* Output ITEM, of length ITEM_WIDTH, in the left column,
839 followed by word-wrapped HELP in a second column. */
840 static void
841 wrap_help (const char *help,
842 const char *item,
843 unsigned int item_width,
844 unsigned int columns)
846 unsigned int col_width = LEFT_COLUMN;
847 unsigned int remaining, room, len;
849 remaining = strlen (help);
853 room = columns - 3 - MAX (col_width, item_width);
854 if (room > columns)
855 room = 0;
856 len = remaining;
858 if (room < len)
860 unsigned int i;
862 for (i = 0; help[i]; i++)
864 if (i >= room && len != remaining)
865 break;
866 if (help[i] == ' ')
867 len = i;
868 else if ((help[i] == '-' || help[i] == '/')
869 && help[i + 1] != ' '
870 && i > 0 && ISALPHA (help[i - 1]))
871 len = i + 1;
875 printf( " %-*.*s %.*s\n", col_width, item_width, item, len, help);
876 item_width = 0;
877 while (help[len] == ' ')
878 len++;
879 help += len;
880 remaining -= len;
882 while (remaining);
885 /* Print help for a specific front-end, etc. */
886 static void
887 print_filtered_help (unsigned int include_flags,
888 unsigned int exclude_flags,
889 unsigned int any_flags,
890 unsigned int columns,
891 struct gcc_options *opts,
892 unsigned int lang_mask)
894 unsigned int i;
895 const char *help;
896 bool found = false;
897 bool displayed = false;
899 if (include_flags == CL_PARAMS)
901 for (i = 0; i < LAST_PARAM; i++)
903 const char *param = compiler_params[i].option;
905 help = compiler_params[i].help;
906 if (help == NULL || *help == '\0')
908 if (exclude_flags & CL_UNDOCUMENTED)
909 continue;
910 help = undocumented_msg;
913 /* Get the translation. */
914 help = _(help);
916 wrap_help (help, param, strlen (param), columns);
918 putchar ('\n');
919 return;
922 if (!opts->x_help_printed)
923 opts->x_help_printed = XCNEWVAR (char, cl_options_count);
925 if (!opts->x_help_enum_printed)
926 opts->x_help_enum_printed = XCNEWVAR (char, cl_enums_count);
928 for (i = 0; i < cl_options_count; i++)
930 char new_help[128];
931 const struct cl_option *option = cl_options + i;
932 unsigned int len;
933 const char *opt;
934 const char *tab;
936 if (include_flags == 0
937 || ((option->flags & include_flags) != include_flags))
939 if ((option->flags & any_flags) == 0)
940 continue;
943 /* Skip unwanted switches. */
944 if ((option->flags & exclude_flags) != 0)
945 continue;
947 /* The driver currently prints its own help text. */
948 if ((option->flags & CL_DRIVER) != 0
949 && (option->flags & (((1U << cl_lang_count) - 1)
950 | CL_COMMON | CL_TARGET)) == 0)
951 continue;
953 found = true;
954 /* Skip switches that have already been printed. */
955 if (opts->x_help_printed[i])
956 continue;
958 opts->x_help_printed[i] = true;
960 help = option->help;
961 if (help == NULL)
963 if (exclude_flags & CL_UNDOCUMENTED)
964 continue;
965 help = undocumented_msg;
968 /* Get the translation. */
969 help = _(help);
971 /* Find the gap between the name of the
972 option and its descriptive text. */
973 tab = strchr (help, '\t');
974 if (tab)
976 len = tab - help;
977 opt = help;
978 help = tab + 1;
980 else
982 opt = option->opt_text;
983 len = strlen (opt);
986 /* With the -Q option enabled we change the descriptive text associated
987 with an option to be an indication of its current setting. */
988 if (!opts->x_quiet_flag)
990 void *flag_var = option_flag_var (i, opts);
992 if (len < (LEFT_COLUMN + 2))
993 strcpy (new_help, "\t\t");
994 else
995 strcpy (new_help, "\t");
997 if (flag_var != NULL
998 && option->var_type != CLVC_DEFER)
1000 if (option->flags & CL_JOINED)
1002 if (option->var_type == CLVC_STRING)
1004 if (* (const char **) flag_var != NULL)
1005 snprintf (new_help + strlen (new_help),
1006 sizeof (new_help) - strlen (new_help),
1007 * (const char **) flag_var);
1009 else if (option->var_type == CLVC_ENUM)
1011 const struct cl_enum *e = &cl_enums[option->var_enum];
1012 int value;
1013 const char *arg = NULL;
1015 value = e->get (flag_var);
1016 enum_value_to_arg (e->values, &arg, value, lang_mask);
1017 if (arg == NULL)
1018 arg = _("[default]");
1019 snprintf (new_help + strlen (new_help),
1020 sizeof (new_help) - strlen (new_help),
1021 arg);
1023 else
1024 sprintf (new_help + strlen (new_help),
1025 "%#x", * (int *) flag_var);
1027 else
1028 strcat (new_help, option_enabled (i, opts)
1029 ? _("[enabled]") : _("[disabled]"));
1032 help = new_help;
1035 wrap_help (help, opt, len, columns);
1036 displayed = true;
1038 if (option->var_type == CLVC_ENUM
1039 && opts->x_help_enum_printed[option->var_enum] != 2)
1040 opts->x_help_enum_printed[option->var_enum] = 1;
1043 if (! found)
1045 unsigned int langs = include_flags & CL_LANG_ALL;
1047 if (langs == 0)
1048 printf (_(" No options with the desired characteristics were found\n"));
1049 else
1051 unsigned int i;
1053 /* PR 31349: Tell the user how to see all of the
1054 options supported by a specific front end. */
1055 for (i = 0; (1U << i) < CL_LANG_ALL; i ++)
1056 if ((1U << i) & langs)
1057 printf (_(" None found. Use --help=%s to show *all* the options supported by the %s front-end\n"),
1058 lang_names[i], lang_names[i]);
1062 else if (! displayed)
1063 printf (_(" All options with the desired characteristics have already been displayed\n"));
1065 putchar ('\n');
1067 /* Print details of enumerated option arguments, if those
1068 enumerations have help text headings provided. If no help text
1069 is provided, presume that the possible values are listed in the
1070 help text for the relevant options. */
1071 for (i = 0; i < cl_enums_count; i++)
1073 unsigned int j, pos;
1075 if (opts->x_help_enum_printed[i] != 1)
1076 continue;
1077 if (cl_enums[i].help == NULL)
1078 continue;
1079 printf (" %s\n ", _(cl_enums[i].help));
1080 pos = 4;
1081 for (j = 0; cl_enums[i].values[j].arg != NULL; j++)
1083 unsigned int len = strlen (cl_enums[i].values[j].arg);
1085 if (pos > 4 && pos + 1 + len <= columns)
1087 printf (" %s", cl_enums[i].values[j].arg);
1088 pos += 1 + len;
1090 else
1092 if (pos > 4)
1094 printf ("\n ");
1095 pos = 4;
1097 printf ("%s", cl_enums[i].values[j].arg);
1098 pos += len;
1101 printf ("\n\n");
1102 opts->x_help_enum_printed[i] = 2;
1106 /* Display help for a specified type of option.
1107 The options must have ALL of the INCLUDE_FLAGS set
1108 ANY of the flags in the ANY_FLAGS set
1109 and NONE of the EXCLUDE_FLAGS set. The current option state is in
1110 OPTS; LANG_MASK is used for interpreting enumerated option state. */
1111 static void
1112 print_specific_help (unsigned int include_flags,
1113 unsigned int exclude_flags,
1114 unsigned int any_flags,
1115 struct gcc_options *opts,
1116 unsigned int lang_mask)
1118 unsigned int all_langs_mask = (1U << cl_lang_count) - 1;
1119 const char * description = NULL;
1120 const char * descrip_extra = "";
1121 size_t i;
1122 unsigned int flag;
1124 /* Sanity check: Make sure that we do not have more
1125 languages than we have bits available to enumerate them. */
1126 gcc_assert ((1U << cl_lang_count) <= CL_MIN_OPTION_CLASS);
1128 /* If we have not done so already, obtain
1129 the desired maximum width of the output. */
1130 if (opts->x_help_columns == 0)
1132 const char *p;
1134 p = getenv ("COLUMNS");
1135 if (p != NULL)
1137 int value = atoi (p);
1139 if (value > 0)
1140 opts->x_help_columns = value;
1143 if (opts->x_help_columns == 0)
1144 /* Use a reasonable default. */
1145 opts->x_help_columns = 80;
1148 /* Decide upon the title for the options that we are going to display. */
1149 for (i = 0, flag = 1; flag <= CL_MAX_OPTION_CLASS; flag <<= 1, i ++)
1151 switch (flag & include_flags)
1153 case 0:
1154 case CL_DRIVER:
1155 break;
1157 case CL_TARGET:
1158 description = _("The following options are target specific");
1159 break;
1160 case CL_WARNING:
1161 description = _("The following options control compiler warning messages");
1162 break;
1163 case CL_OPTIMIZATION:
1164 description = _("The following options control optimizations");
1165 break;
1166 case CL_COMMON:
1167 description = _("The following options are language-independent");
1168 break;
1169 case CL_PARAMS:
1170 description = _("The --param option recognizes the following as parameters");
1171 break;
1172 default:
1173 if (i >= cl_lang_count)
1174 break;
1175 if (exclude_flags & all_langs_mask)
1176 description = _("The following options are specific to just the language ");
1177 else
1178 description = _("The following options are supported by the language ");
1179 descrip_extra = lang_names [i];
1180 break;
1184 if (description == NULL)
1186 if (any_flags == 0)
1188 if (include_flags & CL_UNDOCUMENTED)
1189 description = _("The following options are not documented");
1190 else if (include_flags & CL_SEPARATE)
1191 description = _("The following options take separate arguments");
1192 else if (include_flags & CL_JOINED)
1193 description = _("The following options take joined arguments");
1194 else
1196 internal_error ("unrecognized include_flags 0x%x passed to print_specific_help",
1197 include_flags);
1198 return;
1201 else
1203 if (any_flags & all_langs_mask)
1204 description = _("The following options are language-related");
1205 else
1206 description = _("The following options are language-independent");
1210 printf ("%s%s:\n", description, descrip_extra);
1211 print_filtered_help (include_flags, exclude_flags, any_flags,
1212 opts->x_help_columns, opts, lang_mask);
1215 /* Handle target- and language-independent options. Return zero to
1216 generate an "unknown option" message. Only options that need
1217 extra handling need to be listed here; if you simply want
1218 DECODED->value assigned to a variable, it happens automatically. */
1220 bool
1221 common_handle_option (struct gcc_options *opts,
1222 struct gcc_options *opts_set,
1223 const struct cl_decoded_option *decoded,
1224 unsigned int lang_mask, int kind ATTRIBUTE_UNUSED,
1225 location_t loc,
1226 const struct cl_option_handlers *handlers,
1227 diagnostic_context *dc)
1229 size_t scode = decoded->opt_index;
1230 const char *arg = decoded->arg;
1231 int value = decoded->value;
1232 enum opt_code code = (enum opt_code) scode;
1234 gcc_assert (decoded->canonical_option_num_elements <= 2);
1236 switch (code)
1238 case OPT__param:
1239 handle_param (opts, opts_set, loc, arg);
1240 break;
1242 case OPT__help:
1244 unsigned int all_langs_mask = (1U << cl_lang_count) - 1;
1245 unsigned int undoc_mask;
1246 unsigned int i;
1248 if (lang_mask == CL_DRIVER)
1249 break;;
1251 undoc_mask = ((opts->x_verbose_flag | opts->x_extra_warnings)
1253 : CL_UNDOCUMENTED);
1254 /* First display any single language specific options. */
1255 for (i = 0; i < cl_lang_count; i++)
1256 print_specific_help
1257 (1U << i, (all_langs_mask & (~ (1U << i))) | undoc_mask, 0, opts,
1258 lang_mask);
1259 /* Next display any multi language specific options. */
1260 print_specific_help (0, undoc_mask, all_langs_mask, opts, lang_mask);
1261 /* Then display any remaining, non-language options. */
1262 for (i = CL_MIN_OPTION_CLASS; i <= CL_MAX_OPTION_CLASS; i <<= 1)
1263 if (i != CL_DRIVER)
1264 print_specific_help (i, undoc_mask, 0, opts, lang_mask);
1265 opts->x_exit_after_options = true;
1266 break;
1269 case OPT__target_help:
1270 if (lang_mask == CL_DRIVER)
1271 break;
1273 print_specific_help (CL_TARGET, CL_UNDOCUMENTED, 0, opts, lang_mask);
1274 opts->x_exit_after_options = true;
1275 break;
1277 case OPT__help_:
1279 const char * a = arg;
1280 unsigned int include_flags = 0;
1281 /* Note - by default we include undocumented options when listing
1282 specific classes. If you only want to see documented options
1283 then add ",^undocumented" to the --help= option. E.g.:
1285 --help=target,^undocumented */
1286 unsigned int exclude_flags = 0;
1288 if (lang_mask == CL_DRIVER)
1289 break;
1291 /* Walk along the argument string, parsing each word in turn.
1292 The format is:
1293 arg = [^]{word}[,{arg}]
1294 word = {optimizers|target|warnings|undocumented|
1295 params|common|<language>} */
1296 while (* a != 0)
1298 static const struct
1300 const char * string;
1301 unsigned int flag;
1303 specifics[] =
1305 { "optimizers", CL_OPTIMIZATION },
1306 { "target", CL_TARGET },
1307 { "warnings", CL_WARNING },
1308 { "undocumented", CL_UNDOCUMENTED },
1309 { "params", CL_PARAMS },
1310 { "joined", CL_JOINED },
1311 { "separate", CL_SEPARATE },
1312 { "common", CL_COMMON },
1313 { NULL, 0 }
1315 unsigned int * pflags;
1316 const char * comma;
1317 unsigned int lang_flag, specific_flag;
1318 unsigned int len;
1319 unsigned int i;
1321 if (* a == '^')
1323 ++ a;
1324 pflags = & exclude_flags;
1326 else
1327 pflags = & include_flags;
1329 comma = strchr (a, ',');
1330 if (comma == NULL)
1331 len = strlen (a);
1332 else
1333 len = comma - a;
1334 if (len == 0)
1336 a = comma + 1;
1337 continue;
1340 /* Check to see if the string matches an option class name. */
1341 for (i = 0, specific_flag = 0; specifics[i].string != NULL; i++)
1342 if (strncasecmp (a, specifics[i].string, len) == 0)
1344 specific_flag = specifics[i].flag;
1345 break;
1348 /* Check to see if the string matches a language name.
1349 Note - we rely upon the alpha-sorted nature of the entries in
1350 the lang_names array, specifically that shorter names appear
1351 before their longer variants. (i.e. C before C++). That way
1352 when we are attempting to match --help=c for example we will
1353 match with C first and not C++. */
1354 for (i = 0, lang_flag = 0; i < cl_lang_count; i++)
1355 if (strncasecmp (a, lang_names[i], len) == 0)
1357 lang_flag = 1U << i;
1358 break;
1361 if (specific_flag != 0)
1363 if (lang_flag == 0)
1364 * pflags |= specific_flag;
1365 else
1367 /* The option's argument matches both the start of a
1368 language name and the start of an option class name.
1369 We have a special case for when the user has
1370 specified "--help=c", but otherwise we have to issue
1371 a warning. */
1372 if (strncasecmp (a, "c", len) == 0)
1373 * pflags |= lang_flag;
1374 else
1375 warning_at (loc, 0,
1376 "--help argument %q.*s is ambiguous, "
1377 "please be more specific",
1378 len, a);
1381 else if (lang_flag != 0)
1382 * pflags |= lang_flag;
1383 else
1384 warning_at (loc, 0,
1385 "unrecognized argument to --help= option: %q.*s",
1386 len, a);
1388 if (comma == NULL)
1389 break;
1390 a = comma + 1;
1393 if (include_flags)
1394 print_specific_help (include_flags, exclude_flags, 0, opts,
1395 lang_mask);
1396 opts->x_exit_after_options = true;
1397 break;
1400 case OPT__version:
1401 if (lang_mask == CL_DRIVER)
1402 break;
1404 opts->x_exit_after_options = true;
1405 break;
1407 case OPT_O:
1408 case OPT_Os:
1409 case OPT_Ofast:
1410 case OPT_Og:
1411 /* Currently handled in a prescan. */
1412 break;
1414 case OPT_Werror:
1415 dc->warning_as_error_requested = value;
1416 break;
1418 case OPT_Werror_:
1419 if (lang_mask == CL_DRIVER)
1420 break;
1422 enable_warning_as_error (arg, value, lang_mask, handlers,
1423 opts, opts_set, loc, dc);
1424 break;
1426 case OPT_Wlarger_than_:
1427 opts->x_larger_than_size = value;
1428 opts->x_warn_larger_than = value != -1;
1429 break;
1431 case OPT_Wfatal_errors:
1432 dc->fatal_errors = value;
1433 break;
1435 case OPT_Wframe_larger_than_:
1436 opts->x_frame_larger_than_size = value;
1437 opts->x_warn_frame_larger_than = value != -1;
1438 break;
1440 case OPT_Wstack_usage_:
1441 opts->x_warn_stack_usage = value;
1442 opts->x_flag_stack_usage_info = value != -1;
1443 break;
1445 case OPT_Wstrict_aliasing:
1446 set_Wstrict_aliasing (opts, value);
1447 break;
1449 case OPT_Wstrict_overflow:
1450 opts->x_warn_strict_overflow = (value
1451 ? (int) WARN_STRICT_OVERFLOW_CONDITIONAL
1452 : 0);
1453 break;
1455 case OPT_Wsystem_headers:
1456 dc->dc_warn_system_headers = value;
1457 break;
1459 case OPT_aux_info:
1460 opts->x_flag_gen_aux_info = 1;
1461 break;
1463 case OPT_auxbase_strip:
1465 char *tmp = xstrdup (arg);
1466 strip_off_ending (tmp, strlen (tmp));
1467 if (tmp[0])
1468 opts->x_aux_base_name = tmp;
1469 else
1470 free (tmp);
1472 break;
1474 case OPT_d:
1475 decode_d_option (arg, opts, loc, dc);
1476 break;
1478 case OPT_fcall_used_:
1479 case OPT_fcall_saved_:
1480 /* Deferred. */
1481 break;
1483 case OPT_fdbg_cnt_:
1484 case OPT_fdbg_cnt_list:
1485 /* Deferred. */
1486 break;
1488 case OPT_fdebug_prefix_map_:
1489 /* Deferred. */
1490 break;
1492 case OPT_fdiagnostics_show_location_:
1493 diagnostic_prefixing_rule (dc) = (diagnostic_prefixing_rule_t) value;
1494 break;
1496 case OPT_fdiagnostics_show_caret:
1497 dc->show_caret = value;
1498 break;
1500 case OPT_fdiagnostics_show_option:
1501 dc->show_option_requested = value;
1502 break;
1504 case OPT_fdump_:
1505 /* Deferred. */
1506 break;
1508 case OPT_ffast_math:
1509 set_fast_math_flags (opts, value);
1510 break;
1512 case OPT_funsafe_math_optimizations:
1513 set_unsafe_math_optimizations_flags (opts, value);
1514 break;
1516 case OPT_ffixed_:
1517 /* Deferred. */
1518 break;
1520 case OPT_finline_limit_:
1521 set_param_value ("max-inline-insns-single", value / 2,
1522 opts->x_param_values, opts_set->x_param_values);
1523 set_param_value ("max-inline-insns-auto", value / 2,
1524 opts->x_param_values, opts_set->x_param_values);
1525 break;
1527 case OPT_finstrument_functions_exclude_function_list_:
1528 add_comma_separated_to_vector
1529 (&opts->x_flag_instrument_functions_exclude_functions, arg);
1530 break;
1532 case OPT_finstrument_functions_exclude_file_list_:
1533 add_comma_separated_to_vector
1534 (&opts->x_flag_instrument_functions_exclude_files, arg);
1535 break;
1537 case OPT_fmessage_length_:
1538 pp_set_line_maximum_length (dc->printer, value);
1539 diagnostic_set_caret_max_width (dc, value);
1540 break;
1542 case OPT_fopt_info:
1543 case OPT_fopt_info_:
1544 /* Deferred. */
1545 break;
1547 case OPT_fpack_struct_:
1548 if (value <= 0 || (value & (value - 1)) || value > 16)
1549 error_at (loc,
1550 "structure alignment must be a small power of two, not %d",
1551 value);
1552 else
1553 opts->x_initial_max_fld_align = value;
1554 break;
1556 case OPT_fplugin_:
1557 case OPT_fplugin_arg_:
1558 /* Deferred. */
1559 break;
1561 case OPT_fprofile_use_:
1562 opts->x_profile_data_prefix = xstrdup (arg);
1563 opts->x_flag_profile_use = true;
1564 value = true;
1565 /* No break here - do -fprofile-use processing. */
1566 case OPT_fprofile_use:
1567 if (!opts_set->x_flag_branch_probabilities)
1568 opts->x_flag_branch_probabilities = value;
1569 if (!opts_set->x_flag_profile_values)
1570 opts->x_flag_profile_values = value;
1571 if (!opts_set->x_flag_unroll_loops)
1572 opts->x_flag_unroll_loops = value;
1573 if (!opts_set->x_flag_peel_loops)
1574 opts->x_flag_peel_loops = value;
1575 if (!opts_set->x_flag_tracer)
1576 opts->x_flag_tracer = value;
1577 if (!opts_set->x_flag_value_profile_transformations)
1578 opts->x_flag_value_profile_transformations = value;
1579 if (!opts_set->x_flag_inline_functions)
1580 opts->x_flag_inline_functions = value;
1581 if (!opts_set->x_flag_ipa_cp)
1582 opts->x_flag_ipa_cp = value;
1583 if (!opts_set->x_flag_ipa_cp_clone
1584 && value && opts->x_flag_ipa_cp)
1585 opts->x_flag_ipa_cp_clone = value;
1586 if (!opts_set->x_flag_predictive_commoning)
1587 opts->x_flag_predictive_commoning = value;
1588 if (!opts_set->x_flag_unswitch_loops)
1589 opts->x_flag_unswitch_loops = value;
1590 if (!opts_set->x_flag_gcse_after_reload)
1591 opts->x_flag_gcse_after_reload = value;
1592 if (!opts_set->x_flag_tree_vectorize)
1593 opts->x_flag_tree_vectorize = value;
1594 if (!opts_set->x_flag_vect_cost_model)
1595 opts->x_flag_vect_cost_model = value;
1596 if (!opts_set->x_flag_tree_loop_distribute_patterns)
1597 opts->x_flag_tree_loop_distribute_patterns = value;
1598 break;
1600 case OPT_fprofile_generate_:
1601 opts->x_profile_data_prefix = xstrdup (arg);
1602 value = true;
1603 /* No break here - do -fprofile-generate processing. */
1604 case OPT_fprofile_generate:
1605 if (!opts_set->x_profile_arc_flag)
1606 opts->x_profile_arc_flag = value;
1607 if (!opts_set->x_flag_profile_values)
1608 opts->x_flag_profile_values = value;
1609 if (!opts_set->x_flag_inline_functions)
1610 opts->x_flag_inline_functions = value;
1611 /* FIXME: Instrumentation we insert makes ipa-reference bitmaps
1612 quadratic. Disable the pass until better memory representation
1613 is done. */
1614 if (!opts_set->x_flag_ipa_reference && opts->x_in_lto_p)
1615 opts->x_flag_ipa_reference = false;
1616 break;
1618 case OPT_fshow_column:
1619 dc->show_column = value;
1620 break;
1622 case OPT_frandom_seed:
1623 /* The real switch is -fno-random-seed. */
1624 if (value)
1625 return false;
1626 /* Deferred. */
1627 break;
1629 case OPT_frandom_seed_:
1630 /* Deferred. */
1631 break;
1633 case OPT_fsched_verbose_:
1634 #ifdef INSN_SCHEDULING
1635 /* Handled with Var in common.opt. */
1636 break;
1637 #else
1638 return false;
1639 #endif
1641 case OPT_fsched_stalled_insns_:
1642 opts->x_flag_sched_stalled_insns = value;
1643 if (opts->x_flag_sched_stalled_insns == 0)
1644 opts->x_flag_sched_stalled_insns = -1;
1645 break;
1647 case OPT_fsched_stalled_insns_dep_:
1648 opts->x_flag_sched_stalled_insns_dep = value;
1649 break;
1651 case OPT_fstack_check_:
1652 if (!strcmp (arg, "no"))
1653 opts->x_flag_stack_check = NO_STACK_CHECK;
1654 else if (!strcmp (arg, "generic"))
1655 /* This is the old stack checking method. */
1656 opts->x_flag_stack_check = STACK_CHECK_BUILTIN
1657 ? FULL_BUILTIN_STACK_CHECK
1658 : GENERIC_STACK_CHECK;
1659 else if (!strcmp (arg, "specific"))
1660 /* This is the new stack checking method. */
1661 opts->x_flag_stack_check = STACK_CHECK_BUILTIN
1662 ? FULL_BUILTIN_STACK_CHECK
1663 : STACK_CHECK_STATIC_BUILTIN
1664 ? STATIC_BUILTIN_STACK_CHECK
1665 : GENERIC_STACK_CHECK;
1666 else
1667 warning_at (loc, 0, "unknown stack check parameter \"%s\"", arg);
1668 break;
1670 case OPT_fstack_limit:
1671 /* The real switch is -fno-stack-limit. */
1672 if (value)
1673 return false;
1674 /* Deferred. */
1675 break;
1677 case OPT_fstack_limit_register_:
1678 case OPT_fstack_limit_symbol_:
1679 /* Deferred. */
1680 break;
1682 case OPT_fstack_usage:
1683 opts->x_flag_stack_usage = value;
1684 opts->x_flag_stack_usage_info = value != 0;
1685 break;
1687 case OPT_ftree_vectorizer_verbose_:
1688 /* -ftree-vectorizer-verbose is deprecated. It is defined in
1689 -terms of fopt-info=N. */
1690 /* Deferred. */
1691 break;
1693 case OPT_g:
1694 set_debug_level (NO_DEBUG, DEFAULT_GDB_EXTENSIONS, arg, opts, opts_set,
1695 loc);
1696 break;
1698 case OPT_gcoff:
1699 set_debug_level (SDB_DEBUG, false, arg, opts, opts_set, loc);
1700 break;
1702 case OPT_gdwarf_:
1703 if (value < 2 || value > 4)
1704 error_at (loc, "dwarf version %d is not supported", value);
1705 else
1706 opts->x_dwarf_version = value;
1707 set_debug_level (DWARF2_DEBUG, false, "", opts, opts_set, loc);
1708 break;
1710 case OPT_gsplit_dwarf:
1711 set_debug_level (NO_DEBUG, DEFAULT_GDB_EXTENSIONS, "", opts, opts_set,
1712 loc);
1713 break;
1715 case OPT_ggdb:
1716 set_debug_level (NO_DEBUG, 2, arg, opts, opts_set, loc);
1717 break;
1719 case OPT_gstabs:
1720 case OPT_gstabs_:
1721 set_debug_level (DBX_DEBUG, code == OPT_gstabs_, arg, opts, opts_set,
1722 loc);
1723 break;
1725 case OPT_gvms:
1726 set_debug_level (VMS_DEBUG, false, arg, opts, opts_set, loc);
1727 break;
1729 case OPT_gxcoff:
1730 case OPT_gxcoff_:
1731 set_debug_level (XCOFF_DEBUG, code == OPT_gxcoff_, arg, opts, opts_set,
1732 loc);
1733 break;
1735 case OPT_pedantic_errors:
1736 dc->pedantic_errors = 1;
1737 control_warning_option (OPT_Wpedantic, DK_ERROR, value,
1738 loc, lang_mask,
1739 handlers, opts, opts_set,
1740 dc);
1741 break;
1743 case OPT_flto:
1744 opts->x_flag_lto = value ? "" : NULL;
1745 break;
1747 case OPT_w:
1748 dc->dc_inhibit_warnings = true;
1749 break;
1751 case OPT_fmax_errors_:
1752 dc->max_errors = value;
1753 break;
1755 case OPT_fuse_ld_bfd:
1756 case OPT_fuse_ld_gold:
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 case OPT_fwrapv:
1762 if (value)
1763 opts->x_flag_trapv = 0;
1764 break;
1766 case OPT_ftrapv:
1767 if (value)
1768 opts->x_flag_wrapv = 0;
1769 break;
1771 default:
1772 /* If the flag was handled in a standard way, assume the lack of
1773 processing here is intentional. */
1774 gcc_assert (option_flag_var (scode, opts));
1775 break;
1778 common_handle_option_auto (opts, opts_set, decoded, lang_mask, kind,
1779 loc, handlers, dc);
1780 return true;
1783 /* Handle --param NAME=VALUE. */
1784 static void
1785 handle_param (struct gcc_options *opts, struct gcc_options *opts_set,
1786 location_t loc, const char *carg)
1788 char *equal, *arg;
1789 int value;
1791 arg = xstrdup (carg);
1792 equal = strchr (arg, '=');
1793 if (!equal)
1794 error_at (loc, "%s: --param arguments should be of the form NAME=VALUE",
1795 arg);
1796 else
1798 value = integral_argument (equal + 1);
1799 if (value == -1)
1800 error_at (loc, "invalid --param value %qs", equal + 1);
1801 else
1803 *equal = '\0';
1804 set_param_value (arg, value,
1805 opts->x_param_values, opts_set->x_param_values);
1809 free (arg);
1812 /* Used to set the level of strict aliasing warnings in OPTS,
1813 when no level is specified (i.e., when -Wstrict-aliasing, and not
1814 -Wstrict-aliasing=level was given).
1815 ONOFF is assumed to take value 1 when -Wstrict-aliasing is specified,
1816 and 0 otherwise. After calling this function, wstrict_aliasing will be
1817 set to the default value of -Wstrict_aliasing=level, currently 3. */
1818 static void
1819 set_Wstrict_aliasing (struct gcc_options *opts, int onoff)
1821 gcc_assert (onoff == 0 || onoff == 1);
1822 if (onoff != 0)
1823 opts->x_warn_strict_aliasing = 3;
1824 else
1825 opts->x_warn_strict_aliasing = 0;
1828 /* The following routines are useful in setting all the flags that
1829 -ffast-math and -fno-fast-math imply. */
1830 static void
1831 set_fast_math_flags (struct gcc_options *opts, int set)
1833 if (!opts->frontend_set_flag_unsafe_math_optimizations)
1835 opts->x_flag_unsafe_math_optimizations = set;
1836 set_unsafe_math_optimizations_flags (opts, set);
1838 if (!opts->frontend_set_flag_finite_math_only)
1839 opts->x_flag_finite_math_only = set;
1840 if (!opts->frontend_set_flag_errno_math)
1841 opts->x_flag_errno_math = !set;
1842 if (set)
1844 if (!opts->frontend_set_flag_signaling_nans)
1845 opts->x_flag_signaling_nans = 0;
1846 if (!opts->frontend_set_flag_rounding_math)
1847 opts->x_flag_rounding_math = 0;
1848 if (!opts->frontend_set_flag_cx_limited_range)
1849 opts->x_flag_cx_limited_range = 1;
1853 /* When -funsafe-math-optimizations is set the following
1854 flags are set as well. */
1855 static void
1856 set_unsafe_math_optimizations_flags (struct gcc_options *opts, int set)
1858 if (!opts->frontend_set_flag_trapping_math)
1859 opts->x_flag_trapping_math = !set;
1860 if (!opts->frontend_set_flag_signed_zeros)
1861 opts->x_flag_signed_zeros = !set;
1862 if (!opts->frontend_set_flag_associative_math)
1863 opts->x_flag_associative_math = set;
1864 if (!opts->frontend_set_flag_reciprocal_math)
1865 opts->x_flag_reciprocal_math = set;
1868 /* Return true iff flags in OPTS are set as if -ffast-math. */
1869 bool
1870 fast_math_flags_set_p (const struct gcc_options *opts)
1872 return (!opts->x_flag_trapping_math
1873 && opts->x_flag_unsafe_math_optimizations
1874 && opts->x_flag_finite_math_only
1875 && !opts->x_flag_signed_zeros
1876 && !opts->x_flag_errno_math);
1879 /* Return true iff flags are set as if -ffast-math but using the flags stored
1880 in the struct cl_optimization structure. */
1881 bool
1882 fast_math_flags_struct_set_p (struct cl_optimization *opt)
1884 return (!opt->x_flag_trapping_math
1885 && opt->x_flag_unsafe_math_optimizations
1886 && opt->x_flag_finite_math_only
1887 && !opt->x_flag_signed_zeros
1888 && !opt->x_flag_errno_math);
1891 /* Handle a debug output -g switch for options OPTS
1892 (OPTS_SET->x_write_symbols storing whether a debug type was passed
1893 explicitly), location LOC. EXTENDED is true or false to support
1894 extended output (2 is special and means "-ggdb" was given). */
1895 static void
1896 set_debug_level (enum debug_info_type type, int extended, const char *arg,
1897 struct gcc_options *opts, struct gcc_options *opts_set,
1898 location_t loc)
1900 opts->x_use_gnu_debug_info_extensions = extended;
1902 if (type == NO_DEBUG)
1904 if (opts->x_write_symbols == NO_DEBUG)
1906 opts->x_write_symbols = PREFERRED_DEBUGGING_TYPE;
1908 if (extended == 2)
1910 #ifdef DWARF2_DEBUGGING_INFO
1911 opts->x_write_symbols = DWARF2_DEBUG;
1912 #elif defined DBX_DEBUGGING_INFO
1913 opts->x_write_symbols = DBX_DEBUG;
1914 #endif
1917 if (opts->x_write_symbols == NO_DEBUG)
1918 warning_at (loc, 0, "target system does not support debug output");
1921 else
1923 /* Does it conflict with an already selected type? */
1924 if (opts_set->x_write_symbols != NO_DEBUG
1925 && opts->x_write_symbols != NO_DEBUG
1926 && type != opts->x_write_symbols)
1927 error_at (loc, "debug format \"%s\" conflicts with prior selection",
1928 debug_type_names[type]);
1929 opts->x_write_symbols = type;
1930 opts_set->x_write_symbols = type;
1933 /* A debug flag without a level defaults to level 2. */
1934 if (*arg == '\0')
1936 if (!opts->x_debug_info_level)
1937 opts->x_debug_info_level = DINFO_LEVEL_NORMAL;
1939 else
1941 int argval = integral_argument (arg);
1942 if (argval == -1)
1943 error_at (loc, "unrecognised debug output level \"%s\"", arg);
1944 else if (argval > 3)
1945 error_at (loc, "debug output level %s is too high", arg);
1946 else
1947 opts->x_debug_info_level = (enum debug_info_levels) argval;
1951 /* Arrange to dump core on error for diagnostic context DC. (The
1952 regular error message is still printed first, except in the case of
1953 abort ().) */
1955 static void
1956 setup_core_dumping (diagnostic_context *dc)
1958 #ifdef SIGABRT
1959 signal (SIGABRT, SIG_DFL);
1960 #endif
1961 #if defined(HAVE_SETRLIMIT)
1963 struct rlimit rlim;
1964 if (getrlimit (RLIMIT_CORE, &rlim) != 0)
1965 fatal_error ("getting core file size maximum limit: %m");
1966 rlim.rlim_cur = rlim.rlim_max;
1967 if (setrlimit (RLIMIT_CORE, &rlim) != 0)
1968 fatal_error ("setting core file size limit to maximum: %m");
1970 #endif
1971 diagnostic_abort_on_error (dc);
1974 /* Parse a -d<ARG> command line switch for OPTS, location LOC,
1975 diagnostic context DC. */
1977 static void
1978 decode_d_option (const char *arg, struct gcc_options *opts,
1979 location_t loc, diagnostic_context *dc)
1981 int c;
1983 while (*arg)
1984 switch (c = *arg++)
1986 case 'A':
1987 opts->x_flag_debug_asm = 1;
1988 break;
1989 case 'p':
1990 opts->x_flag_print_asm_name = 1;
1991 break;
1992 case 'P':
1993 opts->x_flag_dump_rtl_in_asm = 1;
1994 opts->x_flag_print_asm_name = 1;
1995 break;
1996 case 'x':
1997 opts->x_rtl_dump_and_exit = 1;
1998 break;
1999 case 'D': /* These are handled by the preprocessor. */
2000 case 'I':
2001 case 'M':
2002 case 'N':
2003 case 'U':
2004 break;
2005 case 'H':
2006 setup_core_dumping (dc);
2007 break;
2008 case 'a':
2009 opts->x_flag_dump_all_passed = true;
2010 break;
2012 default:
2013 warning_at (loc, 0, "unrecognized gcc debugging option: %c", c);
2014 break;
2018 /* Enable (or disable if VALUE is 0) a warning option ARG (language
2019 mask LANG_MASK, option handlers HANDLERS) as an error for option
2020 structures OPTS and OPTS_SET, diagnostic context DC (possibly
2021 NULL), location LOC. This is used by -Werror=. */
2023 static void
2024 enable_warning_as_error (const char *arg, int value, unsigned int lang_mask,
2025 const struct cl_option_handlers *handlers,
2026 struct gcc_options *opts,
2027 struct gcc_options *opts_set,
2028 location_t loc, diagnostic_context *dc)
2030 char *new_option;
2031 int option_index;
2033 new_option = XNEWVEC (char, strlen (arg) + 2);
2034 new_option[0] = 'W';
2035 strcpy (new_option + 1, arg);
2036 option_index = find_opt (new_option, lang_mask);
2037 if (option_index == OPT_SPECIAL_unknown)
2039 error_at (loc, "-Werror=%s: no option -%s", arg, new_option);
2041 else
2043 const diagnostic_t kind = value ? DK_ERROR : DK_WARNING;
2045 control_warning_option (option_index, (int) kind, value,
2046 loc, lang_mask,
2047 handlers, opts, opts_set, dc);
2049 free (new_option);
2052 /* Return malloced memory for the name of the option OPTION_INDEX
2053 which enabled a diagnostic (context CONTEXT), originally of type
2054 ORIG_DIAG_KIND but possibly converted to DIAG_KIND by options such
2055 as -Werror. */
2057 char *
2058 option_name (diagnostic_context *context, int option_index,
2059 diagnostic_t orig_diag_kind, diagnostic_t diag_kind)
2061 if (option_index)
2063 /* A warning classified as an error. */
2064 if ((orig_diag_kind == DK_WARNING || orig_diag_kind == DK_PEDWARN)
2065 && diag_kind == DK_ERROR)
2066 return concat (cl_options[OPT_Werror_].opt_text,
2067 /* Skip over "-W". */
2068 cl_options[option_index].opt_text + 2,
2069 NULL);
2070 /* A warning with option. */
2071 else
2072 return xstrdup (cl_options[option_index].opt_text);
2074 /* A warning without option classified as an error. */
2075 else if (orig_diag_kind == DK_WARNING || orig_diag_kind == DK_PEDWARN
2076 || diag_kind == DK_WARNING)
2078 if (context->warning_as_error_requested)
2079 return xstrdup (cl_options[OPT_Werror].opt_text);
2080 else
2081 return xstrdup (_("enabled by default"));
2083 else
2084 return NULL;