1 /* Command line option handling.
2 Copyright (C) 2002-2019 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
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
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/>. */
24 #include "coretypes.h"
29 #include "diagnostic.h"
30 #include "opts-diagnostic.h"
31 #include "insn-attr-common.h"
32 #include "common/common-target.h"
33 #include "spellcheck.h"
34 #include "opt-suggestions.h"
36 static void set_Wstrict_aliasing (struct gcc_options
*opts
, int onoff
);
38 /* Indexed by enum debug_info_type. */
39 const char *const debug_type_names
[] =
41 "none", "stabs", "dwarf-2", "xcoff", "vms"
44 /* Parse the -femit-struct-debug-detailed option value
45 and set the flag variables. */
47 #define MATCH( prefix, string ) \
48 ((strncmp (prefix, string, sizeof prefix - 1) == 0) \
49 ? ((string += sizeof prefix - 1), 1) : 0)
52 set_struct_debug_option (struct gcc_options
*opts
, location_t loc
,
55 /* various labels for comparison */
56 static const char dfn_lbl
[] = "dfn:", dir_lbl
[] = "dir:", ind_lbl
[] = "ind:";
57 static const char ord_lbl
[] = "ord:", gen_lbl
[] = "gen:";
58 static const char none_lbl
[] = "none", any_lbl
[] = "any";
59 static const char base_lbl
[] = "base", sys_lbl
[] = "sys";
61 enum debug_struct_file files
= DINFO_STRUCT_FILE_ANY
;
62 /* Default is to apply to as much as possible. */
63 enum debug_info_usage usage
= DINFO_USAGE_NUM_ENUMS
;
67 if (MATCH (dfn_lbl
, spec
))
68 usage
= DINFO_USAGE_DFN
;
69 else if (MATCH (dir_lbl
, spec
))
70 usage
= DINFO_USAGE_DIR_USE
;
71 else if (MATCH (ind_lbl
, spec
))
72 usage
= DINFO_USAGE_IND_USE
;
74 /* Generics or not? */
75 if (MATCH (ord_lbl
, spec
))
77 else if (MATCH (gen_lbl
, spec
))
80 /* What allowable environment? */
81 if (MATCH (none_lbl
, spec
))
82 files
= DINFO_STRUCT_FILE_NONE
;
83 else if (MATCH (any_lbl
, spec
))
84 files
= DINFO_STRUCT_FILE_ANY
;
85 else if (MATCH (sys_lbl
, spec
))
86 files
= DINFO_STRUCT_FILE_SYS
;
87 else if (MATCH (base_lbl
, spec
))
88 files
= DINFO_STRUCT_FILE_BASE
;
91 "argument %qs to %<-femit-struct-debug-detailed%> "
95 /* Effect the specification. */
96 if (usage
== DINFO_USAGE_NUM_ENUMS
)
100 opts
->x_debug_struct_ordinary
[DINFO_USAGE_DFN
] = files
;
101 opts
->x_debug_struct_ordinary
[DINFO_USAGE_DIR_USE
] = files
;
102 opts
->x_debug_struct_ordinary
[DINFO_USAGE_IND_USE
] = files
;
106 opts
->x_debug_struct_generic
[DINFO_USAGE_DFN
] = files
;
107 opts
->x_debug_struct_generic
[DINFO_USAGE_DIR_USE
] = files
;
108 opts
->x_debug_struct_generic
[DINFO_USAGE_IND_USE
] = files
;
114 opts
->x_debug_struct_ordinary
[usage
] = files
;
116 opts
->x_debug_struct_generic
[usage
] = files
;
120 set_struct_debug_option (opts
, loc
, spec
+1);
123 /* No more -femit-struct-debug-detailed specifications.
127 "argument %qs to %<-femit-struct-debug-detailed%> unknown",
129 if (opts
->x_debug_struct_ordinary
[DINFO_USAGE_DIR_USE
]
130 < opts
->x_debug_struct_ordinary
[DINFO_USAGE_IND_USE
]
131 || opts
->x_debug_struct_generic
[DINFO_USAGE_DIR_USE
]
132 < opts
->x_debug_struct_generic
[DINFO_USAGE_IND_USE
])
134 "%<-femit-struct-debug-detailed=dir:...%> must allow "
135 "at least as much as "
136 "%<-femit-struct-debug-detailed=ind:...%>");
140 /* Strip off a legitimate source ending from the input string NAME of
141 length LEN. Rather than having to know the names used by all of
142 our front ends, we strip off an ending of a period followed by
143 up to fource characters. (C++ uses ".cpp".) */
146 strip_off_ending (char *name
, int len
)
149 for (i
= 2; i
< 5 && len
> i
; i
++)
151 if (name
[len
- i
] == '.')
153 name
[len
- i
] = '\0';
159 /* Find the base name of a path, stripping off both directories and
160 a single final extension. */
162 base_of_path (const char *path
, const char **base_out
)
164 const char *base
= path
;
166 const char *p
= path
;
170 if (IS_DIR_SEPARATOR (c
))
185 /* What to print when a switch has no documentation. */
186 static const char undocumented_msg
[] = N_("This option lacks documentation.");
187 static const char use_diagnosed_msg
[] = N_("Uses of this option are diagnosed.");
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
,
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
,
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
,
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
,
209 diagnostic_context
*dc
);
211 /* Handle a back-end option; arguments and return value as for
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
,
220 const struct cl_option_handlers
*handlers ATTRIBUTE_UNUSED
,
221 diagnostic_context
*dc
, void (*) (void))
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. */
231 add_comma_separated_to_vector (void **pvec
, const char *arg
)
237 vec
<char_p
> *v
= (vec
<char_p
> *) *pvec
;
239 vec_check_alloc (v
, 1);
241 /* We never free this string. */
254 v
->safe_push (token_start
);
257 if (*r
== '\\' && r
[1] == ',')
267 if (*token_start
!= '\0')
268 v
->safe_push (token_start
);
273 /* Initialize opts_obstack. */
276 init_opts_obstack (void)
278 gcc_obstack_init (&opts_obstack
);
281 /* Initialize OPTS and OPTS_SET before using them in parsing options. */
284 init_options_struct (struct gcc_options
*opts
, struct gcc_options
*opts_set
)
286 size_t num_params
= get_num_compiler_params ();
288 /* Ensure that opts_obstack has already been initialized by the time
289 that we initialize any gcc_options instances (PR jit/68446). */
290 gcc_assert (opts_obstack
.chunk_size
> 0);
292 *opts
= global_options_init
;
295 memset (opts_set
, 0, sizeof (*opts_set
));
297 opts
->x_param_values
= XNEWVEC (int, num_params
);
300 opts_set
->x_param_values
= XCNEWVEC (int, num_params
);
302 init_param_values (opts
->x_param_values
);
304 /* Initialize whether `char' is signed. */
305 opts
->x_flag_signed_char
= DEFAULT_SIGNED_CHAR
;
306 /* Set this to a special "uninitialized" value. The actual default
307 is set after target options have been processed. */
308 opts
->x_flag_short_enums
= 2;
310 /* Initialize target_flags before default_options_optimization
311 so the latter can modify it. */
312 opts
->x_target_flags
= targetm_common
.default_target_flags
;
314 /* Some targets have ABI-specified unwind tables. */
315 opts
->x_flag_unwind_tables
= targetm_common
.unwind_tables_default
;
317 /* Some targets have other target-specific initialization. */
318 targetm_common
.option_init_struct (opts
);
321 /* Release any allocations owned by OPTS. */
324 finalize_options_struct (struct gcc_options
*opts
)
326 XDELETEVEC (opts
->x_param_values
);
329 /* If indicated by the optimization level LEVEL (-Os if SIZE is set,
330 -Ofast if FAST is set, -Og if DEBUG is set), apply the option DEFAULT_OPT
331 to OPTS and OPTS_SET, diagnostic context DC, location LOC, with language
332 mask LANG_MASK and option handlers HANDLERS. */
335 maybe_default_option (struct gcc_options
*opts
,
336 struct gcc_options
*opts_set
,
337 const struct default_options
*default_opt
,
338 int level
, bool size
, bool fast
, bool debug
,
339 unsigned int lang_mask
,
340 const struct cl_option_handlers
*handlers
,
342 diagnostic_context
*dc
)
344 const struct cl_option
*option
= &cl_options
[default_opt
->opt_index
];
348 gcc_assert (level
== 2);
350 gcc_assert (level
== 3);
352 gcc_assert (level
== 1);
354 switch (default_opt
->levels
)
360 case OPT_LEVELS_0_ONLY
:
361 enabled
= (level
== 0);
364 case OPT_LEVELS_1_PLUS
:
365 enabled
= (level
>= 1);
368 case OPT_LEVELS_1_PLUS_SPEED_ONLY
:
369 enabled
= (level
>= 1 && !size
&& !debug
);
372 case OPT_LEVELS_1_PLUS_NOT_DEBUG
:
373 enabled
= (level
>= 1 && !debug
);
376 case OPT_LEVELS_2_PLUS
:
377 enabled
= (level
>= 2);
380 case OPT_LEVELS_2_PLUS_SPEED_ONLY
:
381 enabled
= (level
>= 2 && !size
&& !debug
);
384 case OPT_LEVELS_3_PLUS
:
385 enabled
= (level
>= 3);
388 case OPT_LEVELS_3_PLUS_AND_SIZE
:
389 enabled
= (level
>= 3 || size
);
392 case OPT_LEVELS_SIZE
:
396 case OPT_LEVELS_FAST
:
400 case OPT_LEVELS_NONE
:
406 handle_generated_option (opts
, opts_set
, default_opt
->opt_index
,
407 default_opt
->arg
, default_opt
->value
,
408 lang_mask
, DK_UNSPECIFIED
, loc
,
410 else if (default_opt
->arg
== NULL
411 && !option
->cl_reject_negative
)
412 handle_generated_option (opts
, opts_set
, default_opt
->opt_index
,
413 default_opt
->arg
, !default_opt
->value
,
414 lang_mask
, DK_UNSPECIFIED
, loc
,
418 /* As indicated by the optimization level LEVEL (-Os if SIZE is set,
419 -Ofast if FAST is set), apply the options in array DEFAULT_OPTS to
420 OPTS and OPTS_SET, diagnostic context DC, location LOC, with
421 language mask LANG_MASK and option handlers HANDLERS. */
424 maybe_default_options (struct gcc_options
*opts
,
425 struct gcc_options
*opts_set
,
426 const struct default_options
*default_opts
,
427 int level
, bool size
, bool fast
, bool debug
,
428 unsigned int lang_mask
,
429 const struct cl_option_handlers
*handlers
,
431 diagnostic_context
*dc
)
435 for (i
= 0; default_opts
[i
].levels
!= OPT_LEVELS_NONE
; i
++)
436 maybe_default_option (opts
, opts_set
, &default_opts
[i
],
437 level
, size
, fast
, debug
,
438 lang_mask
, handlers
, loc
, dc
);
441 /* Table of options enabled by default at different levels.
442 Please keep this list sorted by level and alphabetized within
443 each level; this makes it easier to keep the documentation
446 static const struct default_options default_options_table
[] =
448 /* -O1 and -Og optimizations. */
449 { OPT_LEVELS_1_PLUS
, OPT_fcombine_stack_adjustments
, NULL
, 1 },
450 { OPT_LEVELS_1_PLUS
, OPT_fcompare_elim
, NULL
, 1 },
451 { OPT_LEVELS_1_PLUS
, OPT_fcprop_registers
, NULL
, 1 },
452 { OPT_LEVELS_1_PLUS
, OPT_fdefer_pop
, NULL
, 1 },
453 { OPT_LEVELS_1_PLUS
, OPT_fforward_propagate
, NULL
, 1 },
454 { OPT_LEVELS_1_PLUS
, OPT_fguess_branch_probability
, NULL
, 1 },
455 { OPT_LEVELS_1_PLUS
, OPT_fipa_profile
, NULL
, 1 },
456 { OPT_LEVELS_1_PLUS
, OPT_fipa_pure_const
, NULL
, 1 },
457 { OPT_LEVELS_1_PLUS
, OPT_fipa_reference
, NULL
, 1 },
458 { OPT_LEVELS_1_PLUS
, OPT_fipa_reference_addressable
, NULL
, 1 },
459 { OPT_LEVELS_1_PLUS
, OPT_fmerge_constants
, NULL
, 1 },
460 { OPT_LEVELS_1_PLUS
, OPT_fomit_frame_pointer
, NULL
, 1 },
461 { OPT_LEVELS_1_PLUS
, OPT_freorder_blocks
, NULL
, 1 },
462 { OPT_LEVELS_1_PLUS
, OPT_fshrink_wrap
, NULL
, 1 },
463 { OPT_LEVELS_1_PLUS
, OPT_fsplit_wide_types
, NULL
, 1 },
464 { OPT_LEVELS_1_PLUS
, OPT_ftree_builtin_call_dce
, NULL
, 1 },
465 { OPT_LEVELS_1_PLUS
, OPT_ftree_ccp
, NULL
, 1 },
466 { OPT_LEVELS_1_PLUS
, OPT_ftree_ch
, NULL
, 1 },
467 { OPT_LEVELS_1_PLUS
, OPT_ftree_coalesce_vars
, NULL
, 1 },
468 { OPT_LEVELS_1_PLUS
, OPT_ftree_copy_prop
, NULL
, 1 },
469 { OPT_LEVELS_1_PLUS
, OPT_ftree_dce
, NULL
, 1 },
470 { OPT_LEVELS_1_PLUS
, OPT_ftree_dominator_opts
, NULL
, 1 },
471 { OPT_LEVELS_1_PLUS
, OPT_ftree_dse
, NULL
, 1 },
472 { OPT_LEVELS_1_PLUS
, OPT_ftree_fre
, NULL
, 1 },
473 { OPT_LEVELS_1_PLUS
, OPT_ftree_sink
, NULL
, 1 },
474 { OPT_LEVELS_1_PLUS
, OPT_ftree_slsr
, NULL
, 1 },
475 { OPT_LEVELS_1_PLUS
, OPT_ftree_ter
, NULL
, 1 },
477 /* -O1 (and not -Og) optimizations. */
478 { OPT_LEVELS_1_PLUS_NOT_DEBUG
, OPT_fbranch_count_reg
, NULL
, 1 },
480 { OPT_LEVELS_1_PLUS_NOT_DEBUG
, OPT_fdelayed_branch
, NULL
, 1 },
482 { OPT_LEVELS_1_PLUS_NOT_DEBUG
, OPT_fif_conversion
, NULL
, 1 },
483 { OPT_LEVELS_1_PLUS_NOT_DEBUG
, OPT_fif_conversion2
, NULL
, 1 },
484 { OPT_LEVELS_1_PLUS_NOT_DEBUG
, OPT_finline_functions_called_once
, NULL
, 1 },
485 { OPT_LEVELS_1_PLUS_NOT_DEBUG
, OPT_fmove_loop_invariants
, NULL
, 1 },
486 { OPT_LEVELS_1_PLUS_NOT_DEBUG
, OPT_fssa_phiopt
, NULL
, 1 },
487 { OPT_LEVELS_1_PLUS_NOT_DEBUG
, OPT_ftree_bit_ccp
, NULL
, 1 },
488 { OPT_LEVELS_1_PLUS_NOT_DEBUG
, OPT_ftree_sra
, NULL
, 1 },
489 { OPT_LEVELS_1_PLUS_NOT_DEBUG
, OPT_ftree_pta
, NULL
, 1 },
491 /* -O2 and -Os optimizations. */
492 { OPT_LEVELS_2_PLUS
, OPT_fcaller_saves
, NULL
, 1 },
493 { OPT_LEVELS_2_PLUS
, OPT_fcode_hoisting
, NULL
, 1 },
494 { OPT_LEVELS_2_PLUS
, OPT_fcrossjumping
, NULL
, 1 },
495 { OPT_LEVELS_2_PLUS
, OPT_fcse_follow_jumps
, NULL
, 1 },
496 { OPT_LEVELS_2_PLUS
, OPT_fdevirtualize
, NULL
, 1 },
497 { OPT_LEVELS_2_PLUS
, OPT_fdevirtualize_speculatively
, NULL
, 1 },
498 { OPT_LEVELS_2_PLUS
, OPT_fexpensive_optimizations
, NULL
, 1 },
499 { OPT_LEVELS_2_PLUS
, OPT_ffinite_loops
, NULL
, 1 },
500 { OPT_LEVELS_2_PLUS
, OPT_fgcse
, NULL
, 1 },
501 { OPT_LEVELS_2_PLUS
, OPT_fhoist_adjacent_loads
, NULL
, 1 },
502 { OPT_LEVELS_2_PLUS
, OPT_findirect_inlining
, NULL
, 1 },
503 { OPT_LEVELS_2_PLUS
, OPT_finline_small_functions
, NULL
, 1 },
504 { OPT_LEVELS_2_PLUS
, OPT_fipa_bit_cp
, NULL
, 1 },
505 { OPT_LEVELS_2_PLUS
, OPT_fipa_cp
, NULL
, 1 },
506 { OPT_LEVELS_2_PLUS
, OPT_fipa_icf
, NULL
, 1 },
507 { OPT_LEVELS_2_PLUS
, OPT_fipa_ra
, NULL
, 1 },
508 { OPT_LEVELS_2_PLUS
, OPT_fipa_sra
, NULL
, 1 },
509 { OPT_LEVELS_2_PLUS
, OPT_fipa_vrp
, NULL
, 1 },
510 { OPT_LEVELS_2_PLUS
, OPT_fisolate_erroneous_paths_dereference
, NULL
, 1 },
511 { OPT_LEVELS_2_PLUS
, OPT_flra_remat
, NULL
, 1 },
512 { OPT_LEVELS_2_PLUS
, OPT_foptimize_sibling_calls
, NULL
, 1 },
513 { OPT_LEVELS_2_PLUS
, OPT_fpartial_inlining
, NULL
, 1 },
514 { OPT_LEVELS_2_PLUS
, OPT_fpeephole2
, NULL
, 1 },
515 { OPT_LEVELS_2_PLUS
, OPT_freorder_functions
, NULL
, 1 },
516 { OPT_LEVELS_2_PLUS
, OPT_frerun_cse_after_loop
, NULL
, 1 },
517 #ifdef INSN_SCHEDULING
518 { OPT_LEVELS_2_PLUS
, OPT_fschedule_insns2
, NULL
, 1 },
520 { OPT_LEVELS_2_PLUS
, OPT_fstrict_aliasing
, NULL
, 1 },
521 { OPT_LEVELS_2_PLUS
, OPT_fstore_merging
, NULL
, 1 },
522 { OPT_LEVELS_2_PLUS
, OPT_fthread_jumps
, NULL
, 1 },
523 { OPT_LEVELS_2_PLUS
, OPT_ftree_pre
, NULL
, 1 },
524 { OPT_LEVELS_2_PLUS
, OPT_ftree_switch_conversion
, NULL
, 1 },
525 { OPT_LEVELS_2_PLUS
, OPT_ftree_tail_merge
, NULL
, 1 },
526 { OPT_LEVELS_2_PLUS
, OPT_ftree_vrp
, NULL
, 1 },
527 { OPT_LEVELS_2_PLUS
, OPT_fvect_cost_model_
, NULL
, VECT_COST_MODEL_CHEAP
},
529 /* -O2 and -Os optimizations. */
530 { OPT_LEVELS_2_PLUS_SPEED_ONLY
, OPT_falign_functions
, NULL
, 1 },
531 { OPT_LEVELS_2_PLUS_SPEED_ONLY
, OPT_falign_jumps
, NULL
, 1 },
532 { OPT_LEVELS_2_PLUS_SPEED_ONLY
, OPT_falign_labels
, NULL
, 1 },
533 { OPT_LEVELS_2_PLUS_SPEED_ONLY
, OPT_falign_loops
, NULL
, 1 },
534 { OPT_LEVELS_2_PLUS_SPEED_ONLY
, OPT_foptimize_strlen
, NULL
, 1 },
535 { OPT_LEVELS_2_PLUS_SPEED_ONLY
, OPT_freorder_blocks_algorithm_
, NULL
,
536 REORDER_BLOCKS_ALGORITHM_STC
},
537 #ifdef INSN_SCHEDULING
538 /* Only run the pre-regalloc scheduling pass if optimizing for speed. */
539 { OPT_LEVELS_2_PLUS_SPEED_ONLY
, OPT_fschedule_insns
, NULL
, 1 },
542 /* -O3 and -Os optimizations. */
543 /* Inlining of functions reducing size is a good idea with -Os
544 regardless of them being declared inline. */
545 { OPT_LEVELS_3_PLUS_AND_SIZE
, OPT_finline_functions
, NULL
, 1 },
547 /* -O3 optimizations. */
548 { OPT_LEVELS_3_PLUS
, OPT_fgcse_after_reload
, NULL
, 1 },
549 { OPT_LEVELS_3_PLUS
, OPT_fipa_cp_clone
, NULL
, 1 },
550 { OPT_LEVELS_3_PLUS
, OPT_floop_interchange
, NULL
, 1 },
551 { OPT_LEVELS_3_PLUS
, OPT_floop_unroll_and_jam
, NULL
, 1 },
552 { OPT_LEVELS_3_PLUS
, OPT_fpeel_loops
, NULL
, 1 },
553 { OPT_LEVELS_3_PLUS
, OPT_fpredictive_commoning
, NULL
, 1 },
554 { OPT_LEVELS_3_PLUS
, OPT_fsplit_loops
, NULL
, 1 },
555 { OPT_LEVELS_3_PLUS
, OPT_fsplit_paths
, NULL
, 1 },
556 { OPT_LEVELS_2_PLUS
, OPT_ftree_loop_distribute_patterns
, NULL
, 1 },
557 { OPT_LEVELS_3_PLUS
, OPT_ftree_loop_distribution
, NULL
, 1 },
558 { OPT_LEVELS_3_PLUS
, OPT_ftree_loop_vectorize
, NULL
, 1 },
559 { OPT_LEVELS_3_PLUS
, OPT_ftree_partial_pre
, NULL
, 1 },
560 { OPT_LEVELS_3_PLUS
, OPT_ftree_slp_vectorize
, NULL
, 1 },
561 { OPT_LEVELS_3_PLUS
, OPT_funswitch_loops
, NULL
, 1 },
562 { OPT_LEVELS_3_PLUS
, OPT_fvect_cost_model_
, NULL
, VECT_COST_MODEL_DYNAMIC
},
563 { OPT_LEVELS_3_PLUS
, OPT_fversion_loops_for_strides
, NULL
, 1 },
565 /* -Ofast adds optimizations to -O3. */
566 { OPT_LEVELS_FAST
, OPT_ffast_math
, NULL
, 1 },
568 { OPT_LEVELS_NONE
, 0, NULL
, 0 }
571 /* Default the options in OPTS and OPTS_SET based on the optimization
572 settings in DECODED_OPTIONS and DECODED_OPTIONS_COUNT. */
574 default_options_optimization (struct gcc_options
*opts
,
575 struct gcc_options
*opts_set
,
576 struct cl_decoded_option
*decoded_options
,
577 unsigned int decoded_options_count
,
579 unsigned int lang_mask
,
580 const struct cl_option_handlers
*handlers
,
581 diagnostic_context
*dc
)
585 bool openacc_mode
= false;
587 /* Scan to see what optimization level has been specified. That will
588 determine the default value of many flags. */
589 for (i
= 1; i
< decoded_options_count
; i
++)
591 struct cl_decoded_option
*opt
= &decoded_options
[i
];
592 switch (opt
->opt_index
)
595 if (*opt
->arg
== '\0')
597 opts
->x_optimize
= 1;
598 opts
->x_optimize_size
= 0;
599 opts
->x_optimize_fast
= 0;
600 opts
->x_optimize_debug
= 0;
604 const int optimize_val
= integral_argument (opt
->arg
);
605 if (optimize_val
== -1)
606 error_at (loc
, "argument to %<-O%> should be a non-negative "
607 "integer, %<g%>, %<s%> or %<fast%>");
610 opts
->x_optimize
= optimize_val
;
611 if ((unsigned int) opts
->x_optimize
> 255)
612 opts
->x_optimize
= 255;
613 opts
->x_optimize_size
= 0;
614 opts
->x_optimize_fast
= 0;
615 opts
->x_optimize_debug
= 0;
621 opts
->x_optimize_size
= 1;
623 /* Optimizing for size forces optimize to be 2. */
624 opts
->x_optimize
= 2;
625 opts
->x_optimize_fast
= 0;
626 opts
->x_optimize_debug
= 0;
630 /* -Ofast only adds flags to -O3. */
631 opts
->x_optimize_size
= 0;
632 opts
->x_optimize
= 3;
633 opts
->x_optimize_fast
= 1;
634 opts
->x_optimize_debug
= 0;
638 /* -Og selects optimization level 1. */
639 opts
->x_optimize_size
= 0;
640 opts
->x_optimize
= 1;
641 opts
->x_optimize_fast
= 0;
642 opts
->x_optimize_debug
= 1;
651 /* Ignore other options in this prescan. */
656 maybe_default_options (opts
, opts_set
, default_options_table
,
657 opts
->x_optimize
, opts
->x_optimize_size
,
658 opts
->x_optimize_fast
, opts
->x_optimize_debug
,
659 lang_mask
, handlers
, loc
, dc
);
661 /* -O2 param settings. */
662 opt2
= (opts
->x_optimize
>= 2);
665 && !opts_set
->x_flag_ipa_pta
)
666 opts
->x_flag_ipa_pta
= true;
668 /* Track fields in field-sensitive alias analysis. */
669 maybe_set_param_value
670 (PARAM_MAX_FIELDS_FOR_FIELD_SENSITIVE
,
671 opt2
? 100 : default_param_value (PARAM_MAX_FIELDS_FOR_FIELD_SENSITIVE
),
672 opts
->x_param_values
, opts_set
->x_param_values
);
674 /* For -O1 only do loop invariant motion for very small loops. */
675 maybe_set_param_value
676 (PARAM_LOOP_INVARIANT_MAX_BBS_IN_LOOP
,
677 opt2
? default_param_value (PARAM_LOOP_INVARIANT_MAX_BBS_IN_LOOP
)
678 : default_param_value (PARAM_LOOP_INVARIANT_MAX_BBS_IN_LOOP
) / 10,
679 opts
->x_param_values
, opts_set
->x_param_values
);
681 /* For -O1 reduce the maximum number of active local stores for RTL DSE
682 since this can consume huge amounts of memory (PR89115). */
683 maybe_set_param_value
684 (PARAM_MAX_DSE_ACTIVE_LOCAL_STORES
,
685 opt2
? default_param_value (PARAM_MAX_DSE_ACTIVE_LOCAL_STORES
)
686 : default_param_value (PARAM_MAX_DSE_ACTIVE_LOCAL_STORES
) / 10,
687 opts
->x_param_values
, opts_set
->x_param_values
);
689 /* At -Ofast, allow store motion to introduce potential race conditions. */
690 maybe_set_param_value
691 (PARAM_ALLOW_STORE_DATA_RACES
,
692 opts
->x_optimize_fast
? 1
693 : default_param_value (PARAM_ALLOW_STORE_DATA_RACES
),
694 opts
->x_param_values
, opts_set
->x_param_values
);
696 if (opts
->x_optimize_size
)
697 /* We want to crossjump as much as possible. */
698 maybe_set_param_value (PARAM_MIN_CROSSJUMP_INSNS
, 1,
699 opts
->x_param_values
, opts_set
->x_param_values
);
701 maybe_set_param_value (PARAM_MIN_CROSSJUMP_INSNS
,
702 default_param_value (PARAM_MIN_CROSSJUMP_INSNS
),
703 opts
->x_param_values
, opts_set
->x_param_values
);
705 /* Restrict the amount of work combine does at -Og while retaining
706 most of its useful transforms. */
707 if (opts
->x_optimize_debug
)
708 maybe_set_param_value (PARAM_MAX_COMBINE_INSNS
, 2,
709 opts
->x_param_values
, opts_set
->x_param_values
);
711 /* Allow default optimizations to be specified on a per-machine basis. */
712 maybe_default_options (opts
, opts_set
,
713 targetm_common
.option_optimization_table
,
714 opts
->x_optimize
, opts
->x_optimize_size
,
715 opts
->x_optimize_fast
, opts
->x_optimize_debug
,
716 lang_mask
, handlers
, loc
, dc
);
719 /* Control IPA optimizations based on different live patching LEVEL. */
721 control_options_for_live_patching (struct gcc_options
*opts
,
722 struct gcc_options
*opts_set
,
723 enum live_patching_level level
,
726 gcc_assert (level
> LIVE_PATCHING_NONE
);
730 case LIVE_PATCHING_INLINE_ONLY_STATIC
:
731 if (opts_set
->x_flag_ipa_cp_clone
&& opts
->x_flag_ipa_cp_clone
)
733 "%<-fipa-cp-clone%> is incompatible with "
734 "%<-flive-patching=inline-only-static%>");
736 opts
->x_flag_ipa_cp_clone
= 0;
738 if (opts_set
->x_flag_ipa_sra
&& opts
->x_flag_ipa_sra
)
740 "%<-fipa-sra%> is incompatible with "
741 "%<-flive-patching=inline-only-static%>");
743 opts
->x_flag_ipa_sra
= 0;
745 if (opts_set
->x_flag_partial_inlining
&& opts
->x_flag_partial_inlining
)
747 "%<-fpartial-inlining%> is incompatible with "
748 "%<-flive-patching=inline-only-static%>");
750 opts
->x_flag_partial_inlining
= 0;
752 if (opts_set
->x_flag_ipa_cp
&& opts
->x_flag_ipa_cp
)
754 "%<-fipa-cp%> is incompatible with "
755 "%<-flive-patching=inline-only-static%>");
757 opts
->x_flag_ipa_cp
= 0;
760 case LIVE_PATCHING_INLINE_CLONE
:
761 /* live patching should disable whole-program optimization. */
762 if (opts_set
->x_flag_whole_program
&& opts
->x_flag_whole_program
)
764 "%<-fwhole-program%> is incompatible with "
765 "%<-flive-patching=inline-only-static|inline-clone%>");
767 opts
->x_flag_whole_program
= 0;
769 /* visibility change should be excluded by !flag_whole_program
770 && !in_lto_p && !flag_ipa_cp_clone && !flag_ipa_sra
771 && !flag_partial_inlining. */
773 if (opts_set
->x_flag_ipa_pta
&& opts
->x_flag_ipa_pta
)
775 "%<-fipa-pta%> is incompatible with "
776 "%<-flive-patching=inline-only-static|inline-clone%>");
778 opts
->x_flag_ipa_pta
= 0;
780 if (opts_set
->x_flag_ipa_reference
&& opts
->x_flag_ipa_reference
)
782 "%<-fipa-reference%> is incompatible with "
783 "%<-flive-patching=inline-only-static|inline-clone%>");
785 opts
->x_flag_ipa_reference
= 0;
787 if (opts_set
->x_flag_ipa_ra
&& opts
->x_flag_ipa_ra
)
789 "%<-fipa-ra%> is incompatible with "
790 "%<-flive-patching=inline-only-static|inline-clone%>");
792 opts
->x_flag_ipa_ra
= 0;
794 if (opts_set
->x_flag_ipa_icf
&& opts
->x_flag_ipa_icf
)
796 "%<-fipa-icf%> is incompatible with "
797 "%<-flive-patching=inline-only-static|inline-clone%>");
799 opts
->x_flag_ipa_icf
= 0;
801 if (opts_set
->x_flag_ipa_icf_functions
&& opts
->x_flag_ipa_icf_functions
)
803 "%<-fipa-icf-functions%> is incompatible with "
804 "%<-flive-patching=inline-only-static|inline-clone%>");
806 opts
->x_flag_ipa_icf_functions
= 0;
808 if (opts_set
->x_flag_ipa_icf_variables
&& opts
->x_flag_ipa_icf_variables
)
810 "%<-fipa-icf-variables%> is incompatible with "
811 "%<-flive-patching=inline-only-static|inline-clone%>");
813 opts
->x_flag_ipa_icf_variables
= 0;
815 if (opts_set
->x_flag_ipa_bit_cp
&& opts
->x_flag_ipa_bit_cp
)
817 "%<-fipa-bit-cp%> is incompatible with "
818 "%<-flive-patching=inline-only-static|inline-clone%>");
820 opts
->x_flag_ipa_bit_cp
= 0;
822 if (opts_set
->x_flag_ipa_vrp
&& opts
->x_flag_ipa_vrp
)
824 "%<-fipa-vrp%> is incompatible with "
825 "%<-flive-patching=inline-only-static|inline-clone%>");
827 opts
->x_flag_ipa_vrp
= 0;
829 if (opts_set
->x_flag_ipa_pure_const
&& opts
->x_flag_ipa_pure_const
)
831 "%<-fipa-pure-const%> is incompatible with "
832 "%<-flive-patching=inline-only-static|inline-clone%>");
834 opts
->x_flag_ipa_pure_const
= 0;
836 /* FIXME: disable unreachable code removal. */
838 /* discovery of functions/variables with no address taken. */
839 if (opts_set
->x_flag_ipa_reference_addressable
840 && opts
->x_flag_ipa_reference_addressable
)
842 "%<-fipa-reference-addressable%> is incompatible with "
843 "%<-flive-patching=inline-only-static|inline-clone%>");
845 opts
->x_flag_ipa_reference_addressable
= 0;
847 /* ipa stack alignment propagation. */
848 if (opts_set
->x_flag_ipa_stack_alignment
849 && opts
->x_flag_ipa_stack_alignment
)
851 "%<-fipa-stack-alignment%> is incompatible with "
852 "%<-flive-patching=inline-only-static|inline-clone%>");
854 opts
->x_flag_ipa_stack_alignment
= 0;
861 /* --help option argument if set. */
862 vec
<const char *> help_option_arguments
;
865 /* After all options at LOC have been read into OPTS and OPTS_SET,
866 finalize settings of those options and diagnose incompatible
869 finish_options (struct gcc_options
*opts
, struct gcc_options
*opts_set
,
872 enum unwind_info_type ui_except
;
874 if (opts
->x_dump_base_name
875 && ! opts
->x_dump_base_name_prefixed
)
877 const char *sep
= opts
->x_dump_base_name
;
880 if (IS_DIR_SEPARATOR (*sep
))
884 /* If dump_base_path contains subdirectories, don't prepend
886 else if (opts
->x_dump_dir_name
)
887 /* We have a DUMP_DIR_NAME, prepend that. */
888 opts
->x_dump_base_name
= opts_concat (opts
->x_dump_dir_name
,
889 opts
->x_dump_base_name
, NULL
);
890 else if (opts
->x_aux_base_name
891 && strcmp (opts
->x_aux_base_name
, HOST_BIT_BUCKET
) != 0)
892 /* AUX_BASE_NAME is set and is not the bit bucket. If it
893 contains a directory component, prepend those directories.
894 Typically this places things in the same directory as the
897 const char *aux_base
;
899 base_of_path (opts
->x_aux_base_name
, &aux_base
);
900 if (opts
->x_aux_base_name
!= aux_base
)
902 int dir_len
= aux_base
- opts
->x_aux_base_name
;
903 char *new_dump_base_name
904 = XOBNEWVEC (&opts_obstack
, char,
905 strlen (opts
->x_dump_base_name
) + dir_len
+ 1);
907 /* Copy directory component from OPTS->X_AUX_BASE_NAME. */
908 memcpy (new_dump_base_name
, opts
->x_aux_base_name
, dir_len
);
909 /* Append existing OPTS->X_DUMP_BASE_NAME. */
910 strcpy (new_dump_base_name
+ dir_len
, opts
->x_dump_base_name
);
911 opts
->x_dump_base_name
= new_dump_base_name
;
915 /* It is definitely prefixed now. */
916 opts
->x_dump_base_name_prefixed
= true;
919 /* Handle related options for unit-at-a-time, toplevel-reorder, and
921 if (!opts
->x_flag_unit_at_a_time
)
923 if (opts
->x_flag_section_anchors
&& opts_set
->x_flag_section_anchors
)
924 error_at (loc
, "section anchors must be disabled when unit-at-a-time "
926 opts
->x_flag_section_anchors
= 0;
927 if (opts
->x_flag_toplevel_reorder
== 1)
928 error_at (loc
, "toplevel reorder must be disabled when unit-at-a-time "
930 opts
->x_flag_toplevel_reorder
= 0;
933 /* -fself-test depends on the state of the compiler prior to
934 compiling anything. Ideally it should be run on an empty source
935 file. However, in case we get run with actual source, assume
936 -fsyntax-only which will inhibit any compiler initialization
937 which may confuse the self tests. */
938 if (opts
->x_flag_self_test
)
939 opts
->x_flag_syntax_only
= 1;
941 if (opts
->x_flag_tm
&& opts
->x_flag_non_call_exceptions
)
942 sorry ("transactional memory is not supported with non-call exceptions");
944 /* Unless the user has asked for section anchors, we disable toplevel
945 reordering at -O0 to disable transformations that might be surprising
946 to end users and to get -fno-toplevel-reorder tested. */
947 if (!opts
->x_optimize
948 && opts
->x_flag_toplevel_reorder
== 2
949 && !(opts
->x_flag_section_anchors
&& opts_set
->x_flag_section_anchors
))
951 opts
->x_flag_toplevel_reorder
= 0;
952 opts
->x_flag_section_anchors
= 0;
954 if (!opts
->x_flag_toplevel_reorder
)
956 if (opts
->x_flag_section_anchors
&& opts_set
->x_flag_section_anchors
)
957 error_at (loc
, "section anchors must be disabled when toplevel reorder"
959 opts
->x_flag_section_anchors
= 0;
962 if (!opts
->x_flag_opts_finished
)
964 /* We initialize opts->x_flag_pie to -1 so that targets can set a
966 if (opts
->x_flag_pie
== -1)
968 /* We initialize opts->x_flag_pic to -1 so that we can tell if
969 -fpic, -fPIC, -fno-pic or -fno-PIC is used. */
970 if (opts
->x_flag_pic
== -1)
971 opts
->x_flag_pie
= DEFAULT_FLAG_PIE
;
973 opts
->x_flag_pie
= 0;
975 /* If -fPIE or -fpie is used, turn on PIC. */
976 if (opts
->x_flag_pie
)
977 opts
->x_flag_pic
= opts
->x_flag_pie
;
978 else if (opts
->x_flag_pic
== -1)
979 opts
->x_flag_pic
= 0;
980 if (opts
->x_flag_pic
&& !opts
->x_flag_pie
)
981 opts
->x_flag_shlib
= 1;
982 opts
->x_flag_opts_finished
= true;
985 /* We initialize opts->x_flag_stack_protect to -1 so that targets
986 can set a default value. */
987 if (opts
->x_flag_stack_protect
== -1)
988 opts
->x_flag_stack_protect
= DEFAULT_FLAG_SSP
;
990 if (opts
->x_optimize
== 0)
992 /* Inlining does not work if not optimizing,
993 so force it not to be done. */
994 opts
->x_warn_inline
= 0;
995 opts
->x_flag_no_inline
= 1;
998 /* The optimization to partition hot and cold basic blocks into separate
999 sections of the .o and executable files does not work (currently)
1000 with exception handling. This is because there is no support for
1001 generating unwind info. If opts->x_flag_exceptions is turned on
1002 we need to turn off the partitioning optimization. */
1004 ui_except
= targetm_common
.except_unwind_info (opts
);
1006 if (opts
->x_flag_exceptions
1007 && opts
->x_flag_reorder_blocks_and_partition
1008 && (ui_except
== UI_SJLJ
|| ui_except
>= UI_TARGET
))
1010 if (opts_set
->x_flag_reorder_blocks_and_partition
)
1012 "%<-freorder-blocks-and-partition%> does not work "
1013 "with exceptions on this architecture");
1014 opts
->x_flag_reorder_blocks_and_partition
= 0;
1015 opts
->x_flag_reorder_blocks
= 1;
1018 /* If user requested unwind info, then turn off the partitioning
1021 if (opts
->x_flag_unwind_tables
1022 && !targetm_common
.unwind_tables_default
1023 && opts
->x_flag_reorder_blocks_and_partition
1024 && (ui_except
== UI_SJLJ
|| ui_except
>= UI_TARGET
))
1026 if (opts_set
->x_flag_reorder_blocks_and_partition
)
1028 "%<-freorder-blocks-and-partition%> does not support "
1029 "unwind info on this architecture");
1030 opts
->x_flag_reorder_blocks_and_partition
= 0;
1031 opts
->x_flag_reorder_blocks
= 1;
1034 /* If the target requested unwind info, then turn off the partitioning
1035 optimization with a different message. Likewise, if the target does not
1036 support named sections. */
1038 if (opts
->x_flag_reorder_blocks_and_partition
1039 && (!targetm_common
.have_named_sections
1040 || (opts
->x_flag_unwind_tables
1041 && targetm_common
.unwind_tables_default
1042 && (ui_except
== UI_SJLJ
|| ui_except
>= UI_TARGET
))))
1044 if (opts_set
->x_flag_reorder_blocks_and_partition
)
1046 "%<-freorder-blocks-and-partition%> does not work "
1047 "on this architecture");
1048 opts
->x_flag_reorder_blocks_and_partition
= 0;
1049 opts
->x_flag_reorder_blocks
= 1;
1053 /* Pipelining of outer loops is only possible when general pipelining
1054 capabilities are requested. */
1055 if (!opts
->x_flag_sel_sched_pipelining
)
1056 opts
->x_flag_sel_sched_pipelining_outer_loops
= 0;
1058 if (opts
->x_flag_conserve_stack
)
1060 maybe_set_param_value (PARAM_LARGE_STACK_FRAME
, 100,
1061 opts
->x_param_values
, opts_set
->x_param_values
);
1062 maybe_set_param_value (PARAM_STACK_FRAME_GROWTH
, 40,
1063 opts
->x_param_values
, opts_set
->x_param_values
);
1066 if (opts
->x_flag_lto
)
1069 opts
->x_flag_generate_lto
= 1;
1071 /* When generating IL, do not operate in whole-program mode.
1072 Otherwise, symbols will be privatized too early, causing link
1074 opts
->x_flag_whole_program
= 0;
1076 error_at (loc
, "LTO support has not been enabled in this configuration");
1078 if (!opts
->x_flag_fat_lto_objects
1079 && (!HAVE_LTO_PLUGIN
1080 || (opts_set
->x_flag_use_linker_plugin
1081 && !opts
->x_flag_use_linker_plugin
)))
1083 if (opts_set
->x_flag_fat_lto_objects
)
1084 error_at (loc
, "%<-fno-fat-lto-objects%> are supported only with "
1086 opts
->x_flag_fat_lto_objects
= 1;
1089 /* -gsplit-dwarf isn't compatible with LTO, see PR88389. */
1090 if (opts
->x_dwarf_split_debug_info
)
1092 inform (loc
, "%<-gsplit-dwarf%> is not supported with LTO,"
1094 opts
->x_dwarf_split_debug_info
= 0;
1098 /* We initialize opts->x_flag_split_stack to -1 so that targets can set a
1099 default value if they choose based on other options. */
1100 if (opts
->x_flag_split_stack
== -1)
1101 opts
->x_flag_split_stack
= 0;
1102 else if (opts
->x_flag_split_stack
)
1104 if (!targetm_common
.supports_split_stack (true, opts
))
1106 error_at (loc
, "%<-fsplit-stack%> is not supported by "
1107 "this compiler configuration");
1108 opts
->x_flag_split_stack
= 0;
1112 /* If stack splitting is turned on, and the user did not explicitly
1113 request function partitioning, turn off partitioning, as it
1114 confuses the linker when trying to handle partitioned split-stack
1115 code that calls a non-split-stack functions. But if partitioning
1116 was turned on explicitly just hope for the best. */
1117 if (opts
->x_flag_split_stack
1118 && opts
->x_flag_reorder_blocks_and_partition
1119 && !opts_set
->x_flag_reorder_blocks_and_partition
)
1120 opts
->x_flag_reorder_blocks_and_partition
= 0;
1122 if (opts
->x_flag_reorder_blocks_and_partition
1123 && !opts_set
->x_flag_reorder_functions
)
1124 opts
->x_flag_reorder_functions
= 1;
1126 /* Tune vectorization related parametees according to cost model. */
1127 if (opts
->x_flag_vect_cost_model
== VECT_COST_MODEL_CHEAP
)
1129 maybe_set_param_value (PARAM_VECT_MAX_VERSION_FOR_ALIAS_CHECKS
,
1130 6, opts
->x_param_values
, opts_set
->x_param_values
);
1131 maybe_set_param_value (PARAM_VECT_MAX_VERSION_FOR_ALIGNMENT_CHECKS
,
1132 0, opts
->x_param_values
, opts_set
->x_param_values
);
1133 maybe_set_param_value (PARAM_VECT_MAX_PEELING_FOR_ALIGNMENT
,
1134 0, opts
->x_param_values
, opts_set
->x_param_values
);
1137 /* Set PARAM_MAX_STORES_TO_SINK to 0 if either vectorization or if-conversion
1139 if ((!opts
->x_flag_tree_loop_vectorize
&& !opts
->x_flag_tree_slp_vectorize
)
1140 || !opts
->x_flag_tree_loop_if_convert
)
1141 maybe_set_param_value (PARAM_MAX_STORES_TO_SINK
, 0,
1142 opts
->x_param_values
, opts_set
->x_param_values
);
1144 /* The -gsplit-dwarf option requires -ggnu-pubnames. */
1145 if (opts
->x_dwarf_split_debug_info
)
1146 opts
->x_debug_generate_pub_sections
= 2;
1148 if ((opts
->x_flag_sanitize
1149 & (SANITIZE_USER_ADDRESS
| SANITIZE_KERNEL_ADDRESS
)) == 0)
1151 if (opts
->x_flag_sanitize
& SANITIZE_POINTER_COMPARE
)
1153 "%<-fsanitize=pointer-compare%> must be combined with "
1154 "%<-fsanitize=address%> or %<-fsanitize=kernel-address%>");
1155 if (opts
->x_flag_sanitize
& SANITIZE_POINTER_SUBTRACT
)
1157 "%<-fsanitize=pointer-subtract%> must be combined with "
1158 "%<-fsanitize=address%> or %<-fsanitize=kernel-address%>");
1161 /* Userspace and kernel ASan conflict with each other. */
1162 if ((opts
->x_flag_sanitize
& SANITIZE_USER_ADDRESS
)
1163 && (opts
->x_flag_sanitize
& SANITIZE_KERNEL_ADDRESS
))
1165 "%<-fsanitize=address%> is incompatible with "
1166 "%<-fsanitize=kernel-address%>");
1168 /* And with TSan. */
1169 if ((opts
->x_flag_sanitize
& SANITIZE_ADDRESS
)
1170 && (opts
->x_flag_sanitize
& SANITIZE_THREAD
))
1172 "%<-fsanitize=address%> and %<-fsanitize=kernel-address%> "
1173 "are incompatible with %<-fsanitize=thread%>");
1175 if ((opts
->x_flag_sanitize
& SANITIZE_LEAK
)
1176 && (opts
->x_flag_sanitize
& SANITIZE_THREAD
))
1178 "%<-fsanitize=leak%> is incompatible with %<-fsanitize=thread%>");
1180 /* Check error recovery for -fsanitize-recover option. */
1181 for (int i
= 0; sanitizer_opts
[i
].name
!= NULL
; ++i
)
1182 if ((opts
->x_flag_sanitize_recover
& sanitizer_opts
[i
].flag
)
1183 && !sanitizer_opts
[i
].can_recover
)
1184 error_at (loc
, "%<-fsanitize-recover=%s%> is not supported",
1185 sanitizer_opts
[i
].name
);
1187 /* When instrumenting the pointers, we don't want to remove
1188 the null pointer checks. */
1189 if (opts
->x_flag_sanitize
& (SANITIZE_NULL
| SANITIZE_NONNULL_ATTRIBUTE
1190 | SANITIZE_RETURNS_NONNULL_ATTRIBUTE
))
1191 opts
->x_flag_delete_null_pointer_checks
= 0;
1193 /* Aggressive compiler optimizations may cause false negatives. */
1194 if (opts
->x_flag_sanitize
& ~(SANITIZE_LEAK
| SANITIZE_UNREACHABLE
))
1195 opts
->x_flag_aggressive_loop_optimizations
= 0;
1197 /* Enable -fsanitize-address-use-after-scope if address sanitizer is
1199 if ((opts
->x_flag_sanitize
& SANITIZE_USER_ADDRESS
)
1200 && !opts_set
->x_flag_sanitize_address_use_after_scope
)
1201 opts
->x_flag_sanitize_address_use_after_scope
= true;
1203 /* Force -fstack-reuse=none in case -fsanitize-address-use-after-scope
1205 if (opts
->x_flag_sanitize_address_use_after_scope
)
1207 if (opts
->x_flag_stack_reuse
!= SR_NONE
1208 && opts_set
->x_flag_stack_reuse
!= SR_NONE
)
1210 "%<-fsanitize-address-use-after-scope%> requires "
1211 "%<-fstack-reuse=none%> option");
1213 opts
->x_flag_stack_reuse
= SR_NONE
;
1216 if ((opts
->x_flag_sanitize
& SANITIZE_USER_ADDRESS
) && opts
->x_flag_tm
)
1217 sorry ("transactional memory is not supported with %<-fsanitize=address%>");
1219 if ((opts
->x_flag_sanitize
& SANITIZE_KERNEL_ADDRESS
) && opts
->x_flag_tm
)
1220 sorry ("transactional memory is not supported with "
1221 "%<-fsanitize=kernel-address%>");
1223 /* Currently live patching is not support for LTO. */
1224 if (opts
->x_flag_live_patching
&& opts
->x_flag_lto
)
1225 sorry ("live patching is not supported with LTO");
1227 /* Control IPA optimizations based on different -flive-patching level. */
1228 if (opts
->x_flag_live_patching
)
1230 control_options_for_live_patching (opts
, opts_set
,
1231 opts
->x_flag_live_patching
,
1236 #define LEFT_COLUMN 27
1238 /* Output ITEM, of length ITEM_WIDTH, in the left column,
1239 followed by word-wrapped HELP in a second column. */
1241 wrap_help (const char *help
,
1243 unsigned int item_width
,
1244 unsigned int columns
)
1246 unsigned int col_width
= LEFT_COLUMN
;
1247 unsigned int remaining
, room
, len
;
1249 remaining
= strlen (help
);
1253 room
= columns
- 3 - MAX (col_width
, item_width
);
1262 for (i
= 0; help
[i
]; i
++)
1264 if (i
>= room
&& len
!= remaining
)
1268 else if ((help
[i
] == '-' || help
[i
] == '/')
1269 && help
[i
+ 1] != ' '
1270 && i
> 0 && ISALPHA (help
[i
- 1]))
1275 printf (" %-*.*s %.*s\n", col_width
, item_width
, item
, len
, help
);
1277 while (help
[len
] == ' ')
1285 /* Data structure used to print list of valid option values. */
1287 class option_help_tuple
1290 option_help_tuple (int code
, vec
<const char *> values
):
1291 m_code (code
), m_values (values
)
1294 /* Code of an option. */
1297 /* List of possible values. */
1298 vec
<const char *> m_values
;
1301 /* Print help for a specific front-end, etc. */
1303 print_filtered_help (unsigned int include_flags
,
1304 unsigned int exclude_flags
,
1305 unsigned int any_flags
,
1306 unsigned int columns
,
1307 struct gcc_options
*opts
,
1308 unsigned int lang_mask
)
1313 bool displayed
= false;
1316 if (include_flags
== CL_PARAMS
)
1318 for (i
= 0; i
< LAST_PARAM
; i
++)
1320 const char *param
= compiler_params
[i
].option
;
1322 help
= compiler_params
[i
].help
;
1323 if (help
== NULL
|| *help
== '\0')
1325 if (exclude_flags
& CL_UNDOCUMENTED
)
1327 help
= undocumented_msg
;
1330 /* Get the translation. */
1333 if (!opts
->x_quiet_flag
)
1335 snprintf (new_help
, sizeof (new_help
),
1336 _("default %d minimum %d maximum %d"),
1337 compiler_params
[i
].default_value
,
1338 compiler_params
[i
].min_value
,
1339 compiler_params
[i
].max_value
);
1342 wrap_help (help
, param
, strlen (param
), columns
);
1348 if (!opts
->x_help_printed
)
1349 opts
->x_help_printed
= XCNEWVAR (char, cl_options_count
);
1351 if (!opts
->x_help_enum_printed
)
1352 opts
->x_help_enum_printed
= XCNEWVAR (char, cl_enums_count
);
1354 auto_vec
<option_help_tuple
> help_tuples
;
1356 for (i
= 0; i
< cl_options_count
; i
++)
1358 const struct cl_option
*option
= cl_options
+ i
;
1363 if (include_flags
== 0
1364 || ((option
->flags
& include_flags
) != include_flags
))
1366 if ((option
->flags
& any_flags
) == 0)
1370 /* Skip unwanted switches. */
1371 if ((option
->flags
& exclude_flags
) != 0)
1374 /* The driver currently prints its own help text. */
1375 if ((option
->flags
& CL_DRIVER
) != 0
1376 && (option
->flags
& (((1U << cl_lang_count
) - 1)
1377 | CL_COMMON
| CL_TARGET
)) == 0)
1381 /* Skip switches that have already been printed. */
1382 if (opts
->x_help_printed
[i
])
1385 opts
->x_help_printed
[i
] = true;
1387 help
= option
->help
;
1390 if (exclude_flags
& CL_UNDOCUMENTED
)
1393 help
= undocumented_msg
;
1396 if (option
->alias_target
< N_OPTS
1397 && cl_options
[option
->alias_target
].help
)
1399 if (help
== undocumented_msg
)
1401 /* For undocumented options that are aliases for other options
1402 that are documented, point the reader to the other option in
1403 preference of the former. */
1404 snprintf (new_help
, sizeof new_help
,
1405 _("Same as %s. Use the latter option instead."),
1406 cl_options
[option
->alias_target
].opt_text
);
1410 /* For documented options with aliases, mention the aliased
1411 option's name for reference. */
1412 snprintf (new_help
, sizeof new_help
,
1413 _("%s Same as %s."),
1414 help
, cl_options
[option
->alias_target
].opt_text
);
1420 if (option
->warn_message
)
1422 /* Mention that the use of the option will trigger a warning. */
1423 if (help
== new_help
)
1424 snprintf (new_help
+ strlen (new_help
),
1425 sizeof new_help
- strlen (new_help
),
1426 " %s", _(use_diagnosed_msg
));
1428 snprintf (new_help
, sizeof new_help
,
1429 "%s %s", help
, _(use_diagnosed_msg
));
1434 /* Get the translation. */
1437 /* Find the gap between the name of the
1438 option and its descriptive text. */
1439 tab
= strchr (help
, '\t');
1448 opt
= option
->opt_text
;
1452 /* With the -Q option enabled we change the descriptive text associated
1453 with an option to be an indication of its current setting. */
1454 if (!opts
->x_quiet_flag
)
1456 void *flag_var
= option_flag_var (i
, opts
);
1458 if (len
< (LEFT_COLUMN
+ 2))
1459 strcpy (new_help
, "\t\t");
1461 strcpy (new_help
, "\t");
1463 if (flag_var
!= NULL
1464 && option
->var_type
!= CLVC_DEFER
)
1466 if (option
->flags
& CL_JOINED
)
1468 if (option
->var_type
== CLVC_STRING
)
1470 if (* (const char **) flag_var
!= NULL
)
1471 snprintf (new_help
+ strlen (new_help
),
1472 sizeof (new_help
) - strlen (new_help
),
1473 "%s", * (const char **) flag_var
);
1475 else if (option
->var_type
== CLVC_ENUM
)
1477 const struct cl_enum
*e
= &cl_enums
[option
->var_enum
];
1479 const char *arg
= NULL
;
1481 value
= e
->get (flag_var
);
1482 enum_value_to_arg (e
->values
, &arg
, value
, lang_mask
);
1484 arg
= _("[default]");
1485 snprintf (new_help
+ strlen (new_help
),
1486 sizeof (new_help
) - strlen (new_help
),
1490 sprintf (new_help
+ strlen (new_help
),
1491 "%d", * (int *) flag_var
);
1494 strcat (new_help
, option_enabled (i
, opts
)
1495 ? _("[enabled]") : _("[disabled]"));
1501 if (option
->range_max
!= -1)
1504 snprintf (b
, sizeof (b
), "<%d,%d>", option
->range_min
,
1506 opt
= concat (opt
, b
, NULL
);
1510 wrap_help (help
, opt
, len
, columns
);
1513 if (option
->var_type
== CLVC_ENUM
1514 && opts
->x_help_enum_printed
[option
->var_enum
] != 2)
1515 opts
->x_help_enum_printed
[option
->var_enum
] = 1;
1518 vec
<const char *> option_values
1519 = targetm_common
.get_valid_option_values (i
, NULL
);
1520 if (!option_values
.is_empty ())
1521 help_tuples
.safe_push (option_help_tuple (i
, option_values
));
1527 unsigned int langs
= include_flags
& CL_LANG_ALL
;
1530 printf (_(" No options with the desired characteristics were found\n"));
1535 /* PR 31349: Tell the user how to see all of the
1536 options supported by a specific front end. */
1537 for (i
= 0; (1U << i
) < CL_LANG_ALL
; i
++)
1538 if ((1U << i
) & langs
)
1539 printf (_(" None found. Use --help=%s to show *all* the options supported by the %s front-end.\n"),
1540 lang_names
[i
], lang_names
[i
]);
1544 else if (! displayed
)
1545 printf (_(" All options with the desired characteristics have already been displayed\n"));
1549 /* Print details of enumerated option arguments, if those
1550 enumerations have help text headings provided. If no help text
1551 is provided, presume that the possible values are listed in the
1552 help text for the relevant options. */
1553 for (i
= 0; i
< cl_enums_count
; i
++)
1555 unsigned int j
, pos
;
1557 if (opts
->x_help_enum_printed
[i
] != 1)
1559 if (cl_enums
[i
].help
== NULL
)
1561 printf (" %s\n ", _(cl_enums
[i
].help
));
1563 for (j
= 0; cl_enums
[i
].values
[j
].arg
!= NULL
; j
++)
1565 unsigned int len
= strlen (cl_enums
[i
].values
[j
].arg
);
1567 if (pos
> 4 && pos
+ 1 + len
<= columns
)
1569 printf (" %s", cl_enums
[i
].values
[j
].arg
);
1579 printf ("%s", cl_enums
[i
].values
[j
].arg
);
1584 opts
->x_help_enum_printed
[i
] = 2;
1587 for (unsigned i
= 0; i
< help_tuples
.length (); i
++)
1589 const struct cl_option
*option
= cl_options
+ help_tuples
[i
].m_code
;
1590 printf (_(" Known valid arguments for %s option:\n "),
1592 for (unsigned j
= 0; j
< help_tuples
[i
].m_values
.length (); j
++)
1593 printf (" %s", help_tuples
[i
].m_values
[j
]);
1598 /* Display help for a specified type of option.
1599 The options must have ALL of the INCLUDE_FLAGS set
1600 ANY of the flags in the ANY_FLAGS set
1601 and NONE of the EXCLUDE_FLAGS set. The current option state is in
1602 OPTS; LANG_MASK is used for interpreting enumerated option state. */
1604 print_specific_help (unsigned int include_flags
,
1605 unsigned int exclude_flags
,
1606 unsigned int any_flags
,
1607 struct gcc_options
*opts
,
1608 unsigned int lang_mask
)
1610 unsigned int all_langs_mask
= (1U << cl_lang_count
) - 1;
1611 const char * description
= NULL
;
1612 const char * descrip_extra
= "";
1616 /* Sanity check: Make sure that we do not have more
1617 languages than we have bits available to enumerate them. */
1618 gcc_assert ((1U << cl_lang_count
) <= CL_MIN_OPTION_CLASS
);
1620 /* If we have not done so already, obtain
1621 the desired maximum width of the output. */
1622 if (opts
->x_help_columns
== 0)
1624 opts
->x_help_columns
= get_terminal_width ();
1625 if (opts
->x_help_columns
== INT_MAX
)
1626 /* Use a reasonable default. */
1627 opts
->x_help_columns
= 80;
1630 /* Decide upon the title for the options that we are going to display. */
1631 for (i
= 0, flag
= 1; flag
<= CL_MAX_OPTION_CLASS
; flag
<<= 1, i
++)
1633 switch (flag
& include_flags
)
1640 description
= _("The following options are target specific");
1643 description
= _("The following options control compiler warning messages");
1645 case CL_OPTIMIZATION
:
1646 description
= _("The following options control optimizations");
1649 description
= _("The following options are language-independent");
1652 description
= _("The --param option recognizes the following as parameters");
1655 if (i
>= cl_lang_count
)
1657 if (exclude_flags
& all_langs_mask
)
1658 description
= _("The following options are specific to just the language ");
1660 description
= _("The following options are supported by the language ");
1661 descrip_extra
= lang_names
[i
];
1666 if (description
== NULL
)
1670 if (include_flags
& CL_UNDOCUMENTED
)
1671 description
= _("The following options are not documented");
1672 else if (include_flags
& CL_SEPARATE
)
1673 description
= _("The following options take separate arguments");
1674 else if (include_flags
& CL_JOINED
)
1675 description
= _("The following options take joined arguments");
1678 internal_error ("unrecognized %<include_flags 0x%x%> passed "
1679 "to %<print_specific_help%>",
1686 if (any_flags
& all_langs_mask
)
1687 description
= _("The following options are language-related");
1689 description
= _("The following options are language-independent");
1693 printf ("%s%s:\n", description
, descrip_extra
);
1694 print_filtered_help (include_flags
, exclude_flags
, any_flags
,
1695 opts
->x_help_columns
, opts
, lang_mask
);
1698 /* Enable FDO-related flags. */
1701 enable_fdo_optimizations (struct gcc_options
*opts
,
1702 struct gcc_options
*opts_set
,
1705 if (!opts_set
->x_flag_branch_probabilities
)
1706 opts
->x_flag_branch_probabilities
= value
;
1707 if (!opts_set
->x_flag_profile_values
)
1708 opts
->x_flag_profile_values
= value
;
1709 if (!opts_set
->x_flag_unroll_loops
)
1710 opts
->x_flag_unroll_loops
= value
;
1711 if (!opts_set
->x_flag_peel_loops
)
1712 opts
->x_flag_peel_loops
= value
;
1713 if (!opts_set
->x_flag_tracer
)
1714 opts
->x_flag_tracer
= value
;
1715 if (!opts_set
->x_flag_value_profile_transformations
)
1716 opts
->x_flag_value_profile_transformations
= value
;
1717 if (!opts_set
->x_flag_inline_functions
)
1718 opts
->x_flag_inline_functions
= value
;
1719 if (!opts_set
->x_flag_ipa_cp
)
1720 opts
->x_flag_ipa_cp
= value
;
1721 if (!opts_set
->x_flag_ipa_cp_clone
1722 && value
&& opts
->x_flag_ipa_cp
)
1723 opts
->x_flag_ipa_cp_clone
= value
;
1724 if (!opts_set
->x_flag_ipa_bit_cp
1725 && value
&& opts
->x_flag_ipa_cp
)
1726 opts
->x_flag_ipa_bit_cp
= value
;
1727 if (!opts_set
->x_flag_predictive_commoning
)
1728 opts
->x_flag_predictive_commoning
= value
;
1729 if (!opts_set
->x_flag_split_loops
)
1730 opts
->x_flag_split_loops
= value
;
1731 if (!opts_set
->x_flag_unswitch_loops
)
1732 opts
->x_flag_unswitch_loops
= value
;
1733 if (!opts_set
->x_flag_gcse_after_reload
)
1734 opts
->x_flag_gcse_after_reload
= value
;
1735 if (!opts_set
->x_flag_tree_loop_vectorize
)
1736 opts
->x_flag_tree_loop_vectorize
= value
;
1737 if (!opts_set
->x_flag_tree_slp_vectorize
)
1738 opts
->x_flag_tree_slp_vectorize
= value
;
1739 if (!opts_set
->x_flag_version_loops_for_strides
)
1740 opts
->x_flag_version_loops_for_strides
= value
;
1741 if (!opts_set
->x_flag_vect_cost_model
)
1742 opts
->x_flag_vect_cost_model
= VECT_COST_MODEL_DYNAMIC
;
1743 if (!opts_set
->x_flag_tree_loop_distribute_patterns
)
1744 opts
->x_flag_tree_loop_distribute_patterns
= value
;
1745 if (!opts_set
->x_flag_loop_interchange
)
1746 opts
->x_flag_loop_interchange
= value
;
1747 if (!opts_set
->x_flag_unroll_jam
)
1748 opts
->x_flag_unroll_jam
= value
;
1749 if (!opts_set
->x_flag_tree_loop_distribution
)
1750 opts
->x_flag_tree_loop_distribution
= value
;
1753 /* -f{,no-}sanitize{,-recover}= suboptions. */
1754 const struct sanitizer_opts_s sanitizer_opts
[] =
1756 #define SANITIZER_OPT(name, flags, recover) \
1757 { #name, flags, sizeof #name - 1, recover }
1758 SANITIZER_OPT (address
, (SANITIZE_ADDRESS
| SANITIZE_USER_ADDRESS
), true),
1759 SANITIZER_OPT (kernel
-address
, (SANITIZE_ADDRESS
| SANITIZE_KERNEL_ADDRESS
),
1761 SANITIZER_OPT (pointer
-compare
, SANITIZE_POINTER_COMPARE
, true),
1762 SANITIZER_OPT (pointer
-subtract
, SANITIZE_POINTER_SUBTRACT
, true),
1763 SANITIZER_OPT (thread
, SANITIZE_THREAD
, false),
1764 SANITIZER_OPT (leak
, SANITIZE_LEAK
, false),
1765 SANITIZER_OPT (shift
, SANITIZE_SHIFT
, true),
1766 SANITIZER_OPT (shift
-base
, SANITIZE_SHIFT_BASE
, true),
1767 SANITIZER_OPT (shift
-exponent
, SANITIZE_SHIFT_EXPONENT
, true),
1768 SANITIZER_OPT (integer
-divide
-by
-zero
, SANITIZE_DIVIDE
, true),
1769 SANITIZER_OPT (undefined
, SANITIZE_UNDEFINED
, true),
1770 SANITIZER_OPT (unreachable
, SANITIZE_UNREACHABLE
, false),
1771 SANITIZER_OPT (vla
-bound
, SANITIZE_VLA
, true),
1772 SANITIZER_OPT (return, SANITIZE_RETURN
, false),
1773 SANITIZER_OPT (null
, SANITIZE_NULL
, true),
1774 SANITIZER_OPT (signed-integer
-overflow
, SANITIZE_SI_OVERFLOW
, true),
1775 SANITIZER_OPT (bool, SANITIZE_BOOL
, true),
1776 SANITIZER_OPT (enum, SANITIZE_ENUM
, true),
1777 SANITIZER_OPT (float-divide
-by
-zero
, SANITIZE_FLOAT_DIVIDE
, true),
1778 SANITIZER_OPT (float-cast
-overflow
, SANITIZE_FLOAT_CAST
, true),
1779 SANITIZER_OPT (bounds
, SANITIZE_BOUNDS
, true),
1780 SANITIZER_OPT (bounds
-strict
, SANITIZE_BOUNDS
| SANITIZE_BOUNDS_STRICT
, true),
1781 SANITIZER_OPT (alignment
, SANITIZE_ALIGNMENT
, true),
1782 SANITIZER_OPT (nonnull
-attribute
, SANITIZE_NONNULL_ATTRIBUTE
, true),
1783 SANITIZER_OPT (returns
-nonnull
-attribute
, SANITIZE_RETURNS_NONNULL_ATTRIBUTE
,
1785 SANITIZER_OPT (object
-size
, SANITIZE_OBJECT_SIZE
, true),
1786 SANITIZER_OPT (vptr
, SANITIZE_VPTR
, true),
1787 SANITIZER_OPT (pointer
-overflow
, SANITIZE_POINTER_OVERFLOW
, true),
1788 SANITIZER_OPT (builtin
, SANITIZE_BUILTIN
, true),
1789 SANITIZER_OPT (all
, ~0U, true),
1790 #undef SANITIZER_OPT
1791 { NULL
, 0U, 0UL, false }
1794 /* -f{,no-}sanitize-coverage= suboptions. */
1795 const struct sanitizer_opts_s coverage_sanitizer_opts
[] =
1797 #define COVERAGE_SANITIZER_OPT(name, flags) \
1798 { #name, flags, sizeof #name - 1, true }
1799 COVERAGE_SANITIZER_OPT (trace
-pc
, SANITIZE_COV_TRACE_PC
),
1800 COVERAGE_SANITIZER_OPT (trace
-cmp
, SANITIZE_COV_TRACE_CMP
),
1801 #undef COVERAGE_SANITIZER_OPT
1802 { NULL
, 0U, 0UL, false }
1805 /* A struct for describing a run of chars within a string. */
1807 class string_fragment
1810 string_fragment (const char *start
, size_t len
)
1811 : m_start (start
), m_len (len
) {}
1813 const char *m_start
;
1817 /* Specialization of edit_distance_traits for string_fragment,
1818 for use by get_closest_sanitizer_option. */
1821 struct edit_distance_traits
<const string_fragment
&>
1823 static size_t get_length (const string_fragment
&fragment
)
1825 return fragment
.m_len
;
1828 static const char *get_string (const string_fragment
&fragment
)
1830 return fragment
.m_start
;
1834 /* Given ARG, an unrecognized sanitizer option, return the best
1835 matching sanitizer option, or NULL if there isn't one.
1836 OPTS is array of candidate sanitizer options.
1837 CODE is OPT_fsanitize_, OPT_fsanitize_recover_ or
1838 OPT_fsanitize_coverage_.
1839 VALUE is non-zero for the regular form of the option, zero
1840 for the "no-" form (e.g. "-fno-sanitize-recover="). */
1843 get_closest_sanitizer_option (const string_fragment
&arg
,
1844 const struct sanitizer_opts_s
*opts
,
1845 enum opt_code code
, int value
)
1847 best_match
<const string_fragment
&, const char*> bm (arg
);
1848 for (int i
= 0; opts
[i
].name
!= NULL
; ++i
)
1850 /* -fsanitize=all is not valid, so don't offer it. */
1851 if (code
== OPT_fsanitize_
1852 && opts
[i
].flag
== ~0U
1856 /* For -fsanitize-recover= (and not -fno-sanitize-recover=),
1857 don't offer the non-recoverable options. */
1858 if (code
== OPT_fsanitize_recover_
1859 && !opts
[i
].can_recover
1863 bm
.consider (opts
[i
].name
);
1865 return bm
.get_best_meaningful_candidate ();
1868 /* Parse comma separated sanitizer suboptions from P for option SCODE,
1869 adjust previous FLAGS and return new ones. If COMPLAIN is false,
1870 don't issue diagnostics. */
1873 parse_sanitizer_options (const char *p
, location_t loc
, int scode
,
1874 unsigned int flags
, int value
, bool complain
)
1876 enum opt_code code
= (enum opt_code
) scode
;
1878 const struct sanitizer_opts_s
*opts
;
1879 if (code
== OPT_fsanitize_coverage_
)
1880 opts
= coverage_sanitizer_opts
;
1882 opts
= sanitizer_opts
;
1888 const char *comma
= strchr (p
, ',');
1900 /* Check to see if the string matches an option class name. */
1901 for (i
= 0; opts
[i
].name
!= NULL
; ++i
)
1902 if (len
== opts
[i
].len
&& memcmp (p
, opts
[i
].name
, len
) == 0)
1904 /* Handle both -fsanitize and -fno-sanitize cases. */
1905 if (value
&& opts
[i
].flag
== ~0U)
1907 if (code
== OPT_fsanitize_
)
1910 error_at (loc
, "%<-fsanitize=all%> option is not valid");
1913 flags
|= ~(SANITIZE_THREAD
| SANITIZE_LEAK
1914 | SANITIZE_UNREACHABLE
| SANITIZE_RETURN
);
1918 /* Do not enable -fsanitize-recover=unreachable and
1919 -fsanitize-recover=return if -fsanitize-recover=undefined
1921 if (code
== OPT_fsanitize_recover_
1922 && opts
[i
].flag
== SANITIZE_UNDEFINED
)
1923 flags
|= (SANITIZE_UNDEFINED
1924 & ~(SANITIZE_UNREACHABLE
| SANITIZE_RETURN
));
1926 flags
|= opts
[i
].flag
;
1929 flags
&= ~opts
[i
].flag
;
1934 if (! found
&& complain
)
1937 = get_closest_sanitizer_option (string_fragment (p
, len
),
1941 if (code
== OPT_fsanitize_recover_
)
1942 suffix
= "-recover";
1943 else if (code
== OPT_fsanitize_coverage_
)
1944 suffix
= "-coverage";
1950 "unrecognized argument to %<-f%ssanitize%s=%> "
1951 "option: %q.*s; did you mean %qs?",
1953 suffix
, (int) len
, p
, hint
);
1956 "unrecognized argument to %<-f%ssanitize%s=%> option: "
1957 "%q.*s", value
? "" : "no-",
1958 suffix
, (int) len
, p
);
1968 /* Parse string values of no_sanitize attribute passed in VALUE.
1969 Values are separated with comma. */
1972 parse_no_sanitize_attribute (char *value
)
1974 unsigned int flags
= 0;
1976 char *q
= strtok (value
, ",");
1980 for (i
= 0; sanitizer_opts
[i
].name
!= NULL
; ++i
)
1981 if (strcmp (sanitizer_opts
[i
].name
, q
) == 0)
1983 flags
|= sanitizer_opts
[i
].flag
;
1984 if (sanitizer_opts
[i
].flag
== SANITIZE_UNDEFINED
)
1985 flags
|= SANITIZE_UNDEFINED_NONDEFAULT
;
1989 if (sanitizer_opts
[i
].name
== NULL
)
1990 warning (OPT_Wattributes
,
1991 "%qs attribute directive ignored", q
);
1993 q
= strtok (NULL
, ",");
1999 /* Parse -falign-NAME format for a FLAG value. Return individual
2000 parsed integer values into RESULT_VALUES array. If REPORT_ERROR is
2001 set, print error message at LOC location. */
2004 parse_and_check_align_values (const char *flag
,
2006 auto_vec
<unsigned> &result_values
,
2010 char *str
= xstrdup (flag
);
2011 for (char *p
= strtok (str
, ":"); p
; p
= strtok (NULL
, ":"))
2014 int v
= strtol (p
, &end
, 10);
2015 if (*end
!= '\0' || v
< 0)
2018 error_at (loc
, "invalid arguments for %<-falign-%s%> option: %qs",
2024 result_values
.safe_push ((unsigned)v
);
2029 /* Check that we have a correct number of values. */
2030 if (result_values
.is_empty () || result_values
.length () > 4)
2033 error_at (loc
, "invalid number of arguments for %<-falign-%s%> "
2034 "option: %qs", name
, flag
);
2038 for (unsigned i
= 0; i
< result_values
.length (); i
++)
2039 if (result_values
[i
] > MAX_CODE_ALIGN_VALUE
)
2042 error_at (loc
, "%<-falign-%s%> is not between 0 and %d",
2043 name
, MAX_CODE_ALIGN_VALUE
);
2050 /* Check that alignment value FLAG for -falign-NAME is valid at a given
2054 check_alignment_argument (location_t loc
, const char *flag
, const char *name
)
2056 auto_vec
<unsigned> align_result
;
2057 parse_and_check_align_values (flag
, name
, align_result
, true, loc
);
2060 /* Print help when OPT__help_ is set. */
2063 print_help (struct gcc_options
*opts
, unsigned int lang_mask
,
2064 const char *help_option_argument
)
2066 const char *a
= help_option_argument
;
2067 unsigned int include_flags
= 0;
2068 /* Note - by default we include undocumented options when listing
2069 specific classes. If you only want to see documented options
2070 then add ",^undocumented" to the --help= option. E.g.:
2072 --help=target,^undocumented */
2073 unsigned int exclude_flags
= 0;
2075 if (lang_mask
== CL_DRIVER
)
2078 /* Walk along the argument string, parsing each word in turn.
2080 arg = [^]{word}[,{arg}]
2081 word = {optimizers|target|warnings|undocumented|
2082 params|common|<language>} */
2092 { "optimizers", CL_OPTIMIZATION
},
2093 { "target", CL_TARGET
},
2094 { "warnings", CL_WARNING
},
2095 { "undocumented", CL_UNDOCUMENTED
},
2096 { "params", CL_PARAMS
},
2097 { "joined", CL_JOINED
},
2098 { "separate", CL_SEPARATE
},
2099 { "common", CL_COMMON
},
2102 unsigned int *pflags
;
2104 unsigned int lang_flag
, specific_flag
;
2113 error ("missing argument to %qs", "--help=^");
2116 pflags
= &exclude_flags
;
2119 pflags
= &include_flags
;
2121 comma
= strchr (a
, ',');
2132 /* Check to see if the string matches an option class name. */
2133 for (i
= 0, specific_flag
= 0; specifics
[i
].string
!= NULL
; i
++)
2134 if (strncasecmp (a
, specifics
[i
].string
, len
) == 0)
2136 specific_flag
= specifics
[i
].flag
;
2140 /* Check to see if the string matches a language name.
2141 Note - we rely upon the alpha-sorted nature of the entries in
2142 the lang_names array, specifically that shorter names appear
2143 before their longer variants. (i.e. C before C++). That way
2144 when we are attempting to match --help=c for example we will
2145 match with C first and not C++. */
2146 for (i
= 0, lang_flag
= 0; i
< cl_lang_count
; i
++)
2147 if (strncasecmp (a
, lang_names
[i
], len
) == 0)
2149 lang_flag
= 1U << i
;
2153 if (specific_flag
!= 0)
2156 *pflags
|= specific_flag
;
2159 /* The option's argument matches both the start of a
2160 language name and the start of an option class name.
2161 We have a special case for when the user has
2162 specified "--help=c", but otherwise we have to issue
2164 if (strncasecmp (a
, "c", len
) == 0)
2165 *pflags
|= lang_flag
;
2168 "%<--help%> argument %q.*s is ambiguous, "
2169 "please be more specific",
2173 else if (lang_flag
!= 0)
2174 *pflags
|= lang_flag
;
2177 "unrecognized argument to %<--help=%> option: %q.*s",
2186 print_specific_help (include_flags
, exclude_flags
, 0, opts
,
2190 /* Handle target- and language-independent options. Return zero to
2191 generate an "unknown option" message. Only options that need
2192 extra handling need to be listed here; if you simply want
2193 DECODED->value assigned to a variable, it happens automatically. */
2196 common_handle_option (struct gcc_options
*opts
,
2197 struct gcc_options
*opts_set
,
2198 const struct cl_decoded_option
*decoded
,
2199 unsigned int lang_mask
, int kind ATTRIBUTE_UNUSED
,
2201 const struct cl_option_handlers
*handlers
,
2202 diagnostic_context
*dc
,
2203 void (*target_option_override_hook
) (void))
2205 size_t scode
= decoded
->opt_index
;
2206 const char *arg
= decoded
->arg
;
2207 HOST_WIDE_INT value
= decoded
->value
;
2208 enum opt_code code
= (enum opt_code
) scode
;
2210 gcc_assert (decoded
->canonical_option_num_elements
<= 2);
2215 handle_param (opts
, opts_set
, loc
, arg
);
2220 unsigned int all_langs_mask
= (1U << cl_lang_count
) - 1;
2221 unsigned int undoc_mask
;
2224 if (lang_mask
== CL_DRIVER
)
2227 undoc_mask
= ((opts
->x_verbose_flag
| opts
->x_extra_warnings
)
2230 target_option_override_hook ();
2231 /* First display any single language specific options. */
2232 for (i
= 0; i
< cl_lang_count
; i
++)
2234 (1U << i
, (all_langs_mask
& (~ (1U << i
))) | undoc_mask
, 0, opts
,
2236 /* Next display any multi language specific options. */
2237 print_specific_help (0, undoc_mask
, all_langs_mask
, opts
, lang_mask
);
2238 /* Then display any remaining, non-language options. */
2239 for (i
= CL_MIN_OPTION_CLASS
; i
<= CL_MAX_OPTION_CLASS
; i
<<= 1)
2241 print_specific_help (i
, undoc_mask
, 0, opts
, lang_mask
);
2242 opts
->x_exit_after_options
= true;
2246 case OPT__target_help
:
2247 if (lang_mask
== CL_DRIVER
)
2250 target_option_override_hook ();
2251 print_specific_help (CL_TARGET
, CL_UNDOCUMENTED
, 0, opts
, lang_mask
);
2252 opts
->x_exit_after_options
= true;
2257 help_option_arguments
.safe_push (arg
);
2258 opts
->x_exit_after_options
= true;
2263 if (lang_mask
== CL_DRIVER
)
2266 opts
->x_exit_after_options
= true;
2269 case OPT__completion_
:
2272 case OPT_fsanitize_
:
2273 opts
->x_flag_sanitize
2274 = parse_sanitizer_options (arg
, loc
, code
,
2275 opts
->x_flag_sanitize
, value
, true);
2277 /* Kernel ASan implies normal ASan but does not yet support
2279 if (opts
->x_flag_sanitize
& SANITIZE_KERNEL_ADDRESS
)
2281 maybe_set_param_value (PARAM_ASAN_INSTRUMENTATION_WITH_CALL_THRESHOLD
,
2282 0, opts
->x_param_values
,
2283 opts_set
->x_param_values
);
2284 maybe_set_param_value (PARAM_ASAN_GLOBALS
, 0, opts
->x_param_values
,
2285 opts_set
->x_param_values
);
2286 maybe_set_param_value (PARAM_ASAN_STACK
, 0, opts
->x_param_values
,
2287 opts_set
->x_param_values
);
2288 maybe_set_param_value (PARAM_ASAN_PROTECT_ALLOCAS
, 0,
2289 opts
->x_param_values
,
2290 opts_set
->x_param_values
);
2291 maybe_set_param_value (PARAM_ASAN_USE_AFTER_RETURN
, 0,
2292 opts
->x_param_values
,
2293 opts_set
->x_param_values
);
2297 case OPT_fsanitize_recover_
:
2298 opts
->x_flag_sanitize_recover
2299 = parse_sanitizer_options (arg
, loc
, code
,
2300 opts
->x_flag_sanitize_recover
, value
, true);
2303 case OPT_fasan_shadow_offset_
:
2307 case OPT_fsanitize_address_use_after_scope
:
2308 opts
->x_flag_sanitize_address_use_after_scope
= value
;
2311 case OPT_fsanitize_recover
:
2313 opts
->x_flag_sanitize_recover
2314 |= (SANITIZE_UNDEFINED
| SANITIZE_UNDEFINED_NONDEFAULT
)
2315 & ~(SANITIZE_UNREACHABLE
| SANITIZE_RETURN
);
2317 opts
->x_flag_sanitize_recover
2318 &= ~(SANITIZE_UNDEFINED
| SANITIZE_UNDEFINED_NONDEFAULT
);
2321 case OPT_fsanitize_coverage_
:
2322 opts
->x_flag_sanitize_coverage
2323 = parse_sanitizer_options (arg
, loc
, code
,
2324 opts
->x_flag_sanitize_coverage
, value
, true);
2331 /* Currently handled in a prescan. */
2335 dc
->warning_as_error_requested
= value
;
2339 if (lang_mask
== CL_DRIVER
)
2342 enable_warning_as_error (arg
, value
, lang_mask
, handlers
,
2343 opts
, opts_set
, loc
, dc
);
2346 case OPT_Wfatal_errors
:
2347 dc
->fatal_errors
= value
;
2350 case OPT_Wstack_usage_
:
2351 opts
->x_flag_stack_usage_info
= value
!= -1;
2354 case OPT_Wstrict_aliasing
:
2355 set_Wstrict_aliasing (opts
, value
);
2358 case OPT_Wstrict_overflow
:
2359 opts
->x_warn_strict_overflow
= (value
2360 ? (int) WARN_STRICT_OVERFLOW_CONDITIONAL
2364 case OPT_Wsystem_headers
:
2365 dc
->dc_warn_system_headers
= value
;
2369 opts
->x_flag_gen_aux_info
= 1;
2372 case OPT_auxbase_strip
:
2374 char *tmp
= xstrdup (arg
);
2375 strip_off_ending (tmp
, strlen (tmp
));
2377 opts
->x_aux_base_name
= tmp
;
2384 decode_d_option (arg
, opts
, loc
, dc
);
2387 case OPT_fcall_used_
:
2388 case OPT_fcall_saved_
:
2396 case OPT_fdbg_cnt_list
:
2398 opts
->x_exit_after_options
= true;
2401 case OPT_fdebug_prefix_map_
:
2402 case OPT_ffile_prefix_map_
:
2406 case OPT_fdiagnostics_show_location_
:
2407 diagnostic_prefixing_rule (dc
) = (diagnostic_prefixing_rule_t
) value
;
2410 case OPT_fdiagnostics_show_caret
:
2411 dc
->show_caret
= value
;
2414 case OPT_fdiagnostics_show_labels
:
2415 dc
->show_labels_p
= value
;
2418 case OPT_fdiagnostics_show_line_numbers
:
2419 dc
->show_line_numbers_p
= value
;
2422 case OPT_fdiagnostics_color_
:
2423 diagnostic_color_init (dc
, value
);
2426 case OPT_fdiagnostics_format_
:
2427 diagnostic_output_format_init (dc
,
2428 (enum diagnostics_output_format
)value
);
2431 case OPT_fdiagnostics_parseable_fixits
:
2432 dc
->parseable_fixits_p
= value
;
2435 case OPT_fdiagnostics_show_option
:
2436 dc
->show_option_requested
= value
;
2439 case OPT_fdiagnostics_minimum_margin_width_
:
2440 dc
->min_margin_width
= value
;
2447 case OPT_ffast_math
:
2448 set_fast_math_flags (opts
, value
);
2451 case OPT_funsafe_math_optimizations
:
2452 set_unsafe_math_optimizations_flags (opts
, value
);
2459 case OPT_finline_limit_
:
2460 set_param_value ("max-inline-insns-single", value
/ 2,
2461 opts
->x_param_values
, opts_set
->x_param_values
);
2462 set_param_value ("max-inline-insns-auto", value
/ 2,
2463 opts
->x_param_values
, opts_set
->x_param_values
);
2466 case OPT_finstrument_functions_exclude_function_list_
:
2467 add_comma_separated_to_vector
2468 (&opts
->x_flag_instrument_functions_exclude_functions
, arg
);
2471 case OPT_finstrument_functions_exclude_file_list_
:
2472 add_comma_separated_to_vector
2473 (&opts
->x_flag_instrument_functions_exclude_files
, arg
);
2476 case OPT_fmessage_length_
:
2477 pp_set_line_maximum_length (dc
->printer
, value
);
2478 diagnostic_set_caret_max_width (dc
, value
);
2482 case OPT_fopt_info_
:
2488 const char *p
= arg
;
2489 opts
->x_flag_disable_hsa
= true;
2492 const char *comma
= strchr (p
, ',');
2494 if ((strncmp (p
, "disable", 7) == 0)
2495 && (p
[7] == ',' || p
[7] == '\0'))
2497 opts
->x_flag_disable_hsa
= true;
2501 if ((strncmp (p
, "hsa", 3) == 0)
2502 && (p
[3] == ',' || p
[3] == '\0'))
2505 opts
->x_flag_disable_hsa
= false;
2507 sorry ("HSA has not been enabled during configuration");
2517 #ifndef ACCEL_COMPILER
2518 case OPT_foffload_abi_
:
2519 error_at (loc
, "%<-foffload-abi%> option can be specified only for "
2520 "offload compiler");
2524 case OPT_fpack_struct_
:
2525 if (value
<= 0 || (value
& (value
- 1)) || value
> 16)
2527 "structure alignment must be a small power of two, not %wu",
2530 opts
->x_initial_max_fld_align
= value
;
2534 case OPT_fplugin_arg_
:
2538 case OPT_fprofile_use_
:
2539 opts
->x_profile_data_prefix
= xstrdup (arg
);
2540 opts
->x_flag_profile_use
= true;
2542 /* No break here - do -fprofile-use processing. */
2544 case OPT_fprofile_use
:
2545 enable_fdo_optimizations (opts
, opts_set
, value
);
2546 if (!opts_set
->x_flag_profile_reorder_functions
)
2547 opts
->x_flag_profile_reorder_functions
= value
;
2548 /* Indirect call profiling should do all useful transformations
2549 speculative devirtualization does. */
2550 if (!opts_set
->x_flag_devirtualize_speculatively
2551 && opts
->x_flag_value_profile_transformations
)
2552 opts
->x_flag_devirtualize_speculatively
= false;
2555 case OPT_fauto_profile_
:
2556 opts
->x_auto_profile_file
= xstrdup (arg
);
2557 opts
->x_flag_auto_profile
= true;
2559 /* No break here - do -fauto-profile processing. */
2561 case OPT_fauto_profile
:
2562 enable_fdo_optimizations (opts
, opts_set
, value
);
2563 if (!opts_set
->x_flag_profile_correction
)
2564 opts
->x_flag_profile_correction
= value
;
2565 maybe_set_param_value (
2566 PARAM_EARLY_INLINER_MAX_ITERATIONS
, 10,
2567 opts
->x_param_values
, opts_set
->x_param_values
);
2570 case OPT_fprofile_generate_
:
2571 opts
->x_profile_data_prefix
= xstrdup (arg
);
2573 /* No break here - do -fprofile-generate processing. */
2575 case OPT_fprofile_generate
:
2576 if (!opts_set
->x_profile_arc_flag
)
2577 opts
->x_profile_arc_flag
= value
;
2578 if (!opts_set
->x_flag_profile_values
)
2579 opts
->x_flag_profile_values
= value
;
2580 if (!opts_set
->x_flag_inline_functions
)
2581 opts
->x_flag_inline_functions
= value
;
2582 if (!opts_set
->x_flag_ipa_bit_cp
)
2583 opts
->x_flag_ipa_bit_cp
= value
;
2584 /* FIXME: Instrumentation we insert makes ipa-reference bitmaps
2585 quadratic. Disable the pass until better memory representation
2587 if (!opts_set
->x_flag_ipa_reference
)
2588 opts
->x_flag_ipa_reference
= false;
2591 case OPT_fpatchable_function_entry_
:
2593 char *patch_area_arg
= xstrdup (arg
);
2594 char *comma
= strchr (patch_area_arg
, ',');
2598 function_entry_patch_area_size
=
2599 integral_argument (patch_area_arg
);
2600 function_entry_patch_area_start
=
2601 integral_argument (comma
+ 1);
2605 function_entry_patch_area_size
=
2606 integral_argument (patch_area_arg
);
2607 function_entry_patch_area_start
= 0;
2609 if (function_entry_patch_area_size
< 0
2610 || function_entry_patch_area_start
< 0
2611 || function_entry_patch_area_size
2612 < function_entry_patch_area_start
)
2613 error ("invalid arguments for %<-fpatchable_function_entry%>");
2614 free (patch_area_arg
);
2618 case OPT_ftree_vectorize
:
2619 /* Automatically sets -ftree-loop-vectorize and
2620 -ftree-slp-vectorize. Nothing more to do here. */
2622 case OPT_fshow_column
:
2623 dc
->show_column
= value
;
2626 case OPT_frandom_seed
:
2627 /* The real switch is -fno-random-seed. */
2633 case OPT_frandom_seed_
:
2637 case OPT_fsched_verbose_
:
2638 #ifdef INSN_SCHEDULING
2639 /* Handled with Var in common.opt. */
2645 case OPT_fsched_stalled_insns_
:
2646 opts
->x_flag_sched_stalled_insns
= value
;
2647 if (opts
->x_flag_sched_stalled_insns
== 0)
2648 opts
->x_flag_sched_stalled_insns
= -1;
2651 case OPT_fsched_stalled_insns_dep_
:
2652 opts
->x_flag_sched_stalled_insns_dep
= value
;
2655 case OPT_fstack_check_
:
2656 if (!strcmp (arg
, "no"))
2657 opts
->x_flag_stack_check
= NO_STACK_CHECK
;
2658 else if (!strcmp (arg
, "generic"))
2659 /* This is the old stack checking method. */
2660 opts
->x_flag_stack_check
= STACK_CHECK_BUILTIN
2661 ? FULL_BUILTIN_STACK_CHECK
2662 : GENERIC_STACK_CHECK
;
2663 else if (!strcmp (arg
, "specific"))
2664 /* This is the new stack checking method. */
2665 opts
->x_flag_stack_check
= STACK_CHECK_BUILTIN
2666 ? FULL_BUILTIN_STACK_CHECK
2667 : STACK_CHECK_STATIC_BUILTIN
2668 ? STATIC_BUILTIN_STACK_CHECK
2669 : GENERIC_STACK_CHECK
;
2671 warning_at (loc
, 0, "unknown stack check parameter %qs", arg
);
2674 case OPT_fstack_limit
:
2675 /* The real switch is -fno-stack-limit. */
2681 case OPT_fstack_limit_register_
:
2682 case OPT_fstack_limit_symbol_
:
2686 case OPT_fstack_usage
:
2687 opts
->x_flag_stack_usage
= value
;
2688 opts
->x_flag_stack_usage_info
= value
!= 0;
2692 set_debug_level (NO_DEBUG
, DEFAULT_GDB_EXTENSIONS
, arg
, opts
, opts_set
,
2697 if (arg
&& strlen (arg
) != 0)
2699 error_at (loc
, "%<-gdwarf%s%> is ambiguous; "
2700 "use %<-gdwarf-%s%> for DWARF version "
2701 "or %<-gdwarf%> %<-g%s%> for debug level", arg
, arg
, arg
);
2705 value
= opts
->x_dwarf_version
;
2709 if (value
< 2 || value
> 5)
2710 error_at (loc
, "dwarf version %wu is not supported", value
);
2712 opts
->x_dwarf_version
= value
;
2713 set_debug_level (DWARF2_DEBUG
, false, "", opts
, opts_set
, loc
);
2716 case OPT_gsplit_dwarf
:
2717 set_debug_level (NO_DEBUG
, DEFAULT_GDB_EXTENSIONS
, "", opts
, opts_set
,
2722 set_debug_level (NO_DEBUG
, 2, arg
, opts
, opts_set
, loc
);
2727 set_debug_level (DBX_DEBUG
, code
== OPT_gstabs_
, arg
, opts
, opts_set
,
2732 set_debug_level (VMS_DEBUG
, false, arg
, opts
, opts_set
, loc
);
2737 set_debug_level (XCOFF_DEBUG
, code
== OPT_gxcoff_
, arg
, opts
, opts_set
,
2743 /* Handled completely via specs. */
2746 case OPT_pedantic_errors
:
2747 dc
->pedantic_errors
= 1;
2748 control_warning_option (OPT_Wpedantic
, DK_ERROR
, NULL
, value
,
2750 handlers
, opts
, opts_set
,
2755 opts
->x_flag_lto
= value
? "" : NULL
;
2759 dc
->dc_inhibit_warnings
= true;
2762 case OPT_fmax_errors_
:
2763 dc
->max_errors
= value
;
2766 case OPT_fuse_ld_bfd
:
2767 case OPT_fuse_ld_gold
:
2768 case OPT_fuse_ld_lld
:
2769 case OPT_fuse_linker_plugin
:
2770 /* No-op. Used by the driver and passed to us because it starts with f.*/
2775 opts
->x_flag_trapv
= 0;
2780 opts
->x_flag_wrapv
= 0;
2783 case OPT_fstrict_overflow
:
2784 opts
->x_flag_wrapv
= !value
;
2785 opts
->x_flag_wrapv_pointer
= !value
;
2787 opts
->x_flag_trapv
= 0;
2791 opts
->x_flag_ipa_icf_functions
= value
;
2792 opts
->x_flag_ipa_icf_variables
= value
;
2795 case OPT_falign_loops_
:
2796 check_alignment_argument (loc
, arg
, "loops");
2799 case OPT_falign_jumps_
:
2800 check_alignment_argument (loc
, arg
, "jumps");
2803 case OPT_falign_labels_
:
2804 check_alignment_argument (loc
, arg
, "labels");
2807 case OPT_falign_functions_
:
2808 check_alignment_argument (loc
, arg
, "functions");
2812 /* If the flag was handled in a standard way, assume the lack of
2813 processing here is intentional. */
2814 gcc_assert (option_flag_var (scode
, opts
));
2818 common_handle_option_auto (opts
, opts_set
, decoded
, lang_mask
, kind
,
2823 /* Handle --param NAME=VALUE. */
2825 handle_param (struct gcc_options
*opts
, struct gcc_options
*opts_set
,
2826 location_t loc
, const char *carg
)
2831 arg
= xstrdup (carg
);
2832 equal
= strchr (arg
, '=');
2834 error_at (loc
, "%s: %qs arguments should be of the form NAME=VALUE",
2840 enum compiler_param index
;
2841 if (!find_param (arg
, &index
))
2843 const char *suggestion
= find_param_fuzzy (arg
);
2845 error_at (loc
, "invalid %qs name %qs; did you mean %qs?",
2846 "--param", arg
, suggestion
);
2848 error_at (loc
, "invalid %qs name %qs", "--param", arg
);
2852 if (!param_string_value_p (index
, equal
+ 1, &value
))
2853 value
= integral_argument (equal
+ 1);
2856 error_at (loc
, "invalid %qs value %qs", "--param", equal
+ 1);
2858 set_param_value (arg
, value
,
2859 opts
->x_param_values
, opts_set
->x_param_values
);
2866 /* Used to set the level of strict aliasing warnings in OPTS,
2867 when no level is specified (i.e., when -Wstrict-aliasing, and not
2868 -Wstrict-aliasing=level was given).
2869 ONOFF is assumed to take value 1 when -Wstrict-aliasing is specified,
2870 and 0 otherwise. After calling this function, wstrict_aliasing will be
2871 set to the default value of -Wstrict_aliasing=level, currently 3. */
2873 set_Wstrict_aliasing (struct gcc_options
*opts
, int onoff
)
2875 gcc_assert (onoff
== 0 || onoff
== 1);
2877 opts
->x_warn_strict_aliasing
= 3;
2879 opts
->x_warn_strict_aliasing
= 0;
2882 /* The following routines are useful in setting all the flags that
2883 -ffast-math and -fno-fast-math imply. */
2885 set_fast_math_flags (struct gcc_options
*opts
, int set
)
2887 if (!opts
->frontend_set_flag_unsafe_math_optimizations
)
2889 opts
->x_flag_unsafe_math_optimizations
= set
;
2890 set_unsafe_math_optimizations_flags (opts
, set
);
2892 if (!opts
->frontend_set_flag_finite_math_only
)
2893 opts
->x_flag_finite_math_only
= set
;
2894 if (!opts
->frontend_set_flag_errno_math
)
2895 opts
->x_flag_errno_math
= !set
;
2898 if (opts
->frontend_set_flag_excess_precision_cmdline
2899 == EXCESS_PRECISION_DEFAULT
)
2900 opts
->x_flag_excess_precision_cmdline
2901 = set
? EXCESS_PRECISION_FAST
: EXCESS_PRECISION_DEFAULT
;
2902 if (!opts
->frontend_set_flag_signaling_nans
)
2903 opts
->x_flag_signaling_nans
= 0;
2904 if (!opts
->frontend_set_flag_rounding_math
)
2905 opts
->x_flag_rounding_math
= 0;
2906 if (!opts
->frontend_set_flag_cx_limited_range
)
2907 opts
->x_flag_cx_limited_range
= 1;
2911 /* When -funsafe-math-optimizations is set the following
2912 flags are set as well. */
2914 set_unsafe_math_optimizations_flags (struct gcc_options
*opts
, int set
)
2916 if (!opts
->frontend_set_flag_trapping_math
)
2917 opts
->x_flag_trapping_math
= !set
;
2918 if (!opts
->frontend_set_flag_signed_zeros
)
2919 opts
->x_flag_signed_zeros
= !set
;
2920 if (!opts
->frontend_set_flag_associative_math
)
2921 opts
->x_flag_associative_math
= set
;
2922 if (!opts
->frontend_set_flag_reciprocal_math
)
2923 opts
->x_flag_reciprocal_math
= set
;
2926 /* Return true iff flags in OPTS are set as if -ffast-math. */
2928 fast_math_flags_set_p (const struct gcc_options
*opts
)
2930 return (!opts
->x_flag_trapping_math
2931 && opts
->x_flag_unsafe_math_optimizations
2932 && opts
->x_flag_finite_math_only
2933 && !opts
->x_flag_signed_zeros
2934 && !opts
->x_flag_errno_math
2935 && opts
->x_flag_excess_precision_cmdline
2936 == EXCESS_PRECISION_FAST
);
2939 /* Return true iff flags are set as if -ffast-math but using the flags stored
2940 in the struct cl_optimization structure. */
2942 fast_math_flags_struct_set_p (struct cl_optimization
*opt
)
2944 return (!opt
->x_flag_trapping_math
2945 && opt
->x_flag_unsafe_math_optimizations
2946 && opt
->x_flag_finite_math_only
2947 && !opt
->x_flag_signed_zeros
2948 && !opt
->x_flag_errno_math
);
2951 /* Handle a debug output -g switch for options OPTS
2952 (OPTS_SET->x_write_symbols storing whether a debug type was passed
2953 explicitly), location LOC. EXTENDED is true or false to support
2954 extended output (2 is special and means "-ggdb" was given). */
2956 set_debug_level (enum debug_info_type type
, int extended
, const char *arg
,
2957 struct gcc_options
*opts
, struct gcc_options
*opts_set
,
2960 opts
->x_use_gnu_debug_info_extensions
= extended
;
2962 if (type
== NO_DEBUG
)
2964 if (opts
->x_write_symbols
== NO_DEBUG
)
2966 opts
->x_write_symbols
= PREFERRED_DEBUGGING_TYPE
;
2970 #if defined DWARF2_DEBUGGING_INFO || defined DWARF2_LINENO_DEBUGGING_INFO
2971 opts
->x_write_symbols
= DWARF2_DEBUG
;
2972 #elif defined DBX_DEBUGGING_INFO
2973 opts
->x_write_symbols
= DBX_DEBUG
;
2977 if (opts
->x_write_symbols
== NO_DEBUG
)
2978 warning_at (loc
, 0, "target system does not support debug output");
2983 /* Does it conflict with an already selected type? */
2984 if (opts_set
->x_write_symbols
!= NO_DEBUG
2985 && opts
->x_write_symbols
!= NO_DEBUG
2986 && type
!= opts
->x_write_symbols
)
2987 error_at (loc
, "debug format %qs conflicts with prior selection",
2988 debug_type_names
[type
]);
2989 opts
->x_write_symbols
= type
;
2990 opts_set
->x_write_symbols
= type
;
2993 /* A debug flag without a level defaults to level 2.
2994 If off or at level 1, set it to level 2, but if already
2995 at level 3, don't lower it. */
2998 if (opts
->x_debug_info_level
< DINFO_LEVEL_NORMAL
)
2999 opts
->x_debug_info_level
= DINFO_LEVEL_NORMAL
;
3003 int argval
= integral_argument (arg
);
3005 error_at (loc
, "unrecognized debug output level %qs", arg
);
3006 else if (argval
> 3)
3007 error_at (loc
, "debug output level %qs is too high", arg
);
3009 opts
->x_debug_info_level
= (enum debug_info_levels
) argval
;
3013 /* Arrange to dump core on error for diagnostic context DC. (The
3014 regular error message is still printed first, except in the case of
3018 setup_core_dumping (diagnostic_context
*dc
)
3021 signal (SIGABRT
, SIG_DFL
);
3023 #if defined(HAVE_SETRLIMIT)
3026 if (getrlimit (RLIMIT_CORE
, &rlim
) != 0)
3027 fatal_error (input_location
, "getting core file size maximum limit: %m");
3028 rlim
.rlim_cur
= rlim
.rlim_max
;
3029 if (setrlimit (RLIMIT_CORE
, &rlim
) != 0)
3030 fatal_error (input_location
,
3031 "setting core file size limit to maximum: %m");
3034 diagnostic_abort_on_error (dc
);
3037 /* Parse a -d<ARG> command line switch for OPTS, location LOC,
3038 diagnostic context DC. */
3041 decode_d_option (const char *arg
, struct gcc_options
*opts
,
3042 location_t loc
, diagnostic_context
*dc
)
3050 opts
->x_flag_debug_asm
= 1;
3053 opts
->x_flag_print_asm_name
= 1;
3056 opts
->x_flag_dump_rtl_in_asm
= 1;
3057 opts
->x_flag_print_asm_name
= 1;
3060 opts
->x_rtl_dump_and_exit
= 1;
3062 case 'D': /* These are handled by the preprocessor. */
3069 setup_core_dumping (dc
);
3072 opts
->x_flag_dump_all_passed
= true;
3076 warning_at (loc
, 0, "unrecognized gcc debugging option: %c", c
);
3081 /* Enable (or disable if VALUE is 0) a warning option ARG (language
3082 mask LANG_MASK, option handlers HANDLERS) as an error for option
3083 structures OPTS and OPTS_SET, diagnostic context DC (possibly
3084 NULL), location LOC. This is used by -Werror=. */
3087 enable_warning_as_error (const char *arg
, int value
, unsigned int lang_mask
,
3088 const struct cl_option_handlers
*handlers
,
3089 struct gcc_options
*opts
,
3090 struct gcc_options
*opts_set
,
3091 location_t loc
, diagnostic_context
*dc
)
3096 new_option
= XNEWVEC (char, strlen (arg
) + 2);
3097 new_option
[0] = 'W';
3098 strcpy (new_option
+ 1, arg
);
3099 option_index
= find_opt (new_option
, lang_mask
);
3100 if (option_index
== OPT_SPECIAL_unknown
)
3103 const char *hint
= op
.suggest_option (new_option
);
3105 error_at (loc
, "%<-W%serror=%s%>: no option %<-%s%>;"
3106 " did you mean %<-%s%>?", value
? "" : "no-",
3107 arg
, new_option
, hint
);
3109 error_at (loc
, "%<-W%serror=%s%>: no option %<-%s%>",
3110 value
? "" : "no-", arg
, new_option
);
3112 else if (!(cl_options
[option_index
].flags
& CL_WARNING
))
3113 error_at (loc
, "%<-Werror=%s%>: %<-%s%> is not an option that "
3114 "controls warnings", arg
, new_option
);
3117 const diagnostic_t kind
= value
? DK_ERROR
: DK_WARNING
;
3118 const char *arg
= NULL
;
3120 if (cl_options
[option_index
].flags
& CL_JOINED
)
3121 arg
= new_option
+ cl_options
[option_index
].opt_len
;
3122 control_warning_option (option_index
, (int) kind
, arg
, value
,
3124 handlers
, opts
, opts_set
, dc
);
3129 /* Return malloced memory for the name of the option OPTION_INDEX
3130 which enabled a diagnostic (context CONTEXT), originally of type
3131 ORIG_DIAG_KIND but possibly converted to DIAG_KIND by options such
3135 option_name (diagnostic_context
*context
, int option_index
,
3136 diagnostic_t orig_diag_kind
, diagnostic_t diag_kind
)
3140 /* A warning classified as an error. */
3141 if ((orig_diag_kind
== DK_WARNING
|| orig_diag_kind
== DK_PEDWARN
)
3142 && diag_kind
== DK_ERROR
)
3143 return concat (cl_options
[OPT_Werror_
].opt_text
,
3144 /* Skip over "-W". */
3145 cl_options
[option_index
].opt_text
+ 2,
3147 /* A warning with option. */
3149 return xstrdup (cl_options
[option_index
].opt_text
);
3151 /* A warning without option classified as an error. */
3152 else if ((orig_diag_kind
== DK_WARNING
|| orig_diag_kind
== DK_PEDWARN
3153 || diag_kind
== DK_WARNING
)
3154 && context
->warning_as_error_requested
)
3155 return xstrdup (cl_options
[OPT_Werror
].opt_text
);