1 /* Command line option handling.
2 Copyright (C) 2002-2022 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/>. */
25 #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"
35 #include "diagnostic-color.h"
39 #define untested() { fprintf (stderr, "@@#\n@@@:%s:%d:%s\n", __FILE__, __LINE__, __func__); }
42 // #include "defaults.h"
44 static void set_Wstrict_aliasing (struct gcc_options
*opts
, int onoff
);
46 /* Names of fundamental debug info formats indexed by enum
49 const char *const debug_type_names
[] =
51 "none", "stabs", "dwarf-2", "xcoff", "vms", "ctf", "btf"
54 /* Bitmasks of fundamental debug info formats indexed by enum
57 static uint32_t debug_type_masks
[] =
59 NO_DEBUG
, DBX_DEBUG
, DWARF2_DEBUG
, XCOFF_DEBUG
, VMS_DEBUG
,
63 /* Names of the set of debug formats requested by user. Updated and accessed
64 via debug_set_names. */
66 static char df_set_names
[sizeof "none stabs dwarf-2 xcoff vms ctf btf"];
68 /* Get enum debug_info_type of the specified debug format, for error messages.
69 Can be used only for individual debug format types. */
72 debug_set_to_format (uint32_t debug_info_set
)
75 enum debug_info_type dinfo_type
= DINFO_TYPE_NONE
;
76 /* Find first set bit. */
78 idx
= exact_log2 (debug_info_set
& - debug_info_set
);
79 /* Check that only one bit is set, if at all. This function is meant to be
80 used only for vanilla debug_info_set bitmask values, i.e. for individual
81 debug format types upto DINFO_TYPE_MAX. */
82 gcc_assert ((debug_info_set
& (debug_info_set
- 1)) == 0);
83 dinfo_type
= (enum debug_info_type
)idx
;
84 gcc_assert (dinfo_type
<= DINFO_TYPE_MAX
);
88 /* Get the number of debug formats enabled for output. */
91 debug_set_count (uint32_t w_symbols
)
93 unsigned int count
= 0;
97 w_symbols
&= ~ (w_symbols
& - w_symbols
);
102 /* Get the names of the debug formats enabled for output. */
105 debug_set_names (uint32_t w_symbols
)
107 uint32_t df_mask
= 0;
108 /* Reset the string to be returned. */
109 memset (df_set_names
, 0, sizeof (df_set_names
));
110 /* Get the popcount. */
111 int num_set_df
= debug_set_count (w_symbols
);
112 /* Iterate over the debug formats. Add name string for those enabled. */
113 for (int i
= DINFO_TYPE_NONE
; i
<= DINFO_TYPE_MAX
; i
++)
115 df_mask
= debug_type_masks
[i
];
116 if (w_symbols
& df_mask
)
118 strcat (df_set_names
, debug_type_names
[i
]);
121 strcat (df_set_names
, " ");
127 /* No debug formats enabled. */
128 gcc_assert (i
== DINFO_TYPE_NONE
);
129 strcat (df_set_names
, debug_type_names
[i
]);
136 /* Return TRUE iff BTF debug info is enabled. */
141 return (write_symbols
& BTF_DEBUG
);
144 /* Return TRUE iff BTF with CO-RE debug info is enabled. */
147 btf_with_core_debuginfo_p ()
149 return (write_symbols
& BTF_WITH_CORE_DEBUG
);
152 /* Return TRUE iff CTF debug info is enabled. */
157 return (write_symbols
& CTF_DEBUG
);
160 /* Return TRUE iff dwarf2 debug info is enabled. */
165 return (write_symbols
& DWARF2_DEBUG
);
168 /* Return true iff the debug info format is to be generated based on DWARF
169 DIEs (like CTF and BTF debug info formats). */
171 bool dwarf_based_debuginfo_p ()
173 return ((write_symbols
& CTF_DEBUG
)
174 || (write_symbols
& BTF_DEBUG
));
177 /* Parse the -femit-struct-debug-detailed option value
178 and set the flag variables. */
180 #define MATCH( prefix, string ) \
181 ((strncmp (prefix, string, sizeof prefix - 1) == 0) \
182 ? ((string += sizeof prefix - 1), 1) : 0)
185 set_struct_debug_option (struct gcc_options
*opts
, location_t loc
,
188 /* various labels for comparison */
189 static const char dfn_lbl
[] = "dfn:", dir_lbl
[] = "dir:", ind_lbl
[] = "ind:";
190 static const char ord_lbl
[] = "ord:", gen_lbl
[] = "gen:";
191 static const char none_lbl
[] = "none", any_lbl
[] = "any";
192 static const char base_lbl
[] = "base", sys_lbl
[] = "sys";
194 enum debug_struct_file files
= DINFO_STRUCT_FILE_ANY
;
195 /* Default is to apply to as much as possible. */
196 enum debug_info_usage usage
= DINFO_USAGE_NUM_ENUMS
;
197 int ord
= 1, gen
= 1;
200 if (MATCH (dfn_lbl
, spec
))
201 usage
= DINFO_USAGE_DFN
;
202 else if (MATCH (dir_lbl
, spec
))
203 usage
= DINFO_USAGE_DIR_USE
;
204 else if (MATCH (ind_lbl
, spec
))
205 usage
= DINFO_USAGE_IND_USE
;
207 /* Generics or not? */
208 if (MATCH (ord_lbl
, spec
))
210 else if (MATCH (gen_lbl
, spec
))
213 /* What allowable environment? */
214 if (MATCH (none_lbl
, spec
))
215 files
= DINFO_STRUCT_FILE_NONE
;
216 else if (MATCH (any_lbl
, spec
))
217 files
= DINFO_STRUCT_FILE_ANY
;
218 else if (MATCH (sys_lbl
, spec
))
219 files
= DINFO_STRUCT_FILE_SYS
;
220 else if (MATCH (base_lbl
, spec
))
221 files
= DINFO_STRUCT_FILE_BASE
;
224 "argument %qs to %<-femit-struct-debug-detailed%> "
228 /* Effect the specification. */
229 if (usage
== DINFO_USAGE_NUM_ENUMS
)
233 opts
->x_debug_struct_ordinary
[DINFO_USAGE_DFN
] = files
;
234 opts
->x_debug_struct_ordinary
[DINFO_USAGE_DIR_USE
] = files
;
235 opts
->x_debug_struct_ordinary
[DINFO_USAGE_IND_USE
] = files
;
239 opts
->x_debug_struct_generic
[DINFO_USAGE_DFN
] = files
;
240 opts
->x_debug_struct_generic
[DINFO_USAGE_DIR_USE
] = files
;
241 opts
->x_debug_struct_generic
[DINFO_USAGE_IND_USE
] = files
;
247 opts
->x_debug_struct_ordinary
[usage
] = files
;
249 opts
->x_debug_struct_generic
[usage
] = files
;
253 set_struct_debug_option (opts
, loc
, spec
+1);
256 /* No more -femit-struct-debug-detailed specifications.
260 "argument %qs to %<-femit-struct-debug-detailed%> unknown",
262 if (opts
->x_debug_struct_ordinary
[DINFO_USAGE_DIR_USE
]
263 < opts
->x_debug_struct_ordinary
[DINFO_USAGE_IND_USE
]
264 || opts
->x_debug_struct_generic
[DINFO_USAGE_DIR_USE
]
265 < opts
->x_debug_struct_generic
[DINFO_USAGE_IND_USE
])
267 "%<-femit-struct-debug-detailed=dir:...%> must allow "
268 "at least as much as "
269 "%<-femit-struct-debug-detailed=ind:...%>");
273 /* Strip off a legitimate source ending from the input string NAME of
274 length LEN. Rather than having to know the names used by all of
275 our front ends, we strip off an ending of a period followed by
276 up to fource characters. (C++ uses ".cpp".) */
279 strip_off_ending (char *name
, int len
)
282 for (i
= 2; i
< 5 && len
> i
; i
++)
284 if (name
[len
- i
] == '.')
286 name
[len
- i
] = '\0';
292 /* Find the base name of a path, stripping off both directories and
293 a single final extension. */
295 base_of_path (const char *path
, const char **base_out
)
297 const char *base
= path
;
299 const char *p
= path
;
303 if (IS_DIR_SEPARATOR (c
))
318 /* What to print when a switch has no documentation. */
319 static const char undocumented_msg
[] = N_("This option lacks documentation.");
320 static const char use_diagnosed_msg
[] = N_("Uses of this option are diagnosed.");
322 typedef char *char_p
; /* For DEF_VEC_P. */
324 static void set_debug_level (uint32_t dinfo
, int extended
,
325 const char *arg
, struct gcc_options
*opts
,
326 struct gcc_options
*opts_set
,
328 static void set_fast_math_flags (struct gcc_options
*opts
, int set
);
329 static void decode_d_option (const char *arg
, struct gcc_options
*opts
,
330 location_t loc
, diagnostic_context
*dc
);
331 static void set_unsafe_math_optimizations_flags (struct gcc_options
*opts
,
333 static void enable_warning_as_error (const char *arg
, int value
,
334 unsigned int lang_mask
,
335 const struct cl_option_handlers
*handlers
,
336 struct gcc_options
*opts
,
337 struct gcc_options
*opts_set
,
339 diagnostic_context
*dc
);
341 /* Handle a back-end option; arguments and return value as for
346 target_handle_option (struct gcc_options
*opts
,
347 struct gcc_options
*opts_set
,
348 const struct cl_decoded_option
*decoded
,
349 unsigned int lang_mask ATTRIBUTE_UNUSED
, int kind
,
351 const struct cl_option_handlers
*handlers ATTRIBUTE_UNUSED
,
352 diagnostic_context
*dc
, void (*) (void))
354 gcc_assert (dc
== global_dc
);
355 gcc_assert (kind
== DK_UNSPECIFIED
);
356 return targetm_common
.handle_option (opts
, opts_set
, decoded
, loc
);
360 /* Add comma-separated strings to a char_p vector. */
363 add_comma_separated_to_vector (void **pvec
, const char *arg
)
369 vec
<char_p
> *v
= (vec
<char_p
> *) *pvec
;
371 vec_check_alloc (v
, 1);
373 /* We never free this string. */
386 v
->safe_push (token_start
);
389 if (*r
== '\\' && r
[1] == ',')
399 if (*token_start
!= '\0')
400 v
->safe_push (token_start
);
405 /* Initialize opts_obstack. */
408 init_opts_obstack (void)
410 gcc_obstack_init (&opts_obstack
);
413 /* Initialize OPTS and OPTS_SET before using them in parsing options. */
416 init_options_struct (struct gcc_options
*opts
, struct gcc_options
*opts_set
)
418 /* Ensure that opts_obstack has already been initialized by the time
419 that we initialize any gcc_options instances (PR jit/68446). */
420 gcc_assert (opts_obstack
.chunk_size
> 0);
422 *opts
= global_options_init
;
425 memset (opts_set
, 0, sizeof (*opts_set
));
427 /* Initialize whether `char' is signed. */
428 opts
->x_flag_signed_char
= DEFAULT_SIGNED_CHAR
;
429 /* Set this to a special "uninitialized" value. The actual default
430 is set after target options have been processed. */
431 opts
->x_flag_short_enums
= 2;
434 /* Initialize target_flags before default_options_optimization
435 so the latter can modify it. */
436 opts
->x_target_flags
= targetm_common
.default_target_flags
;
438 /* Some targets have ABI-specified unwind tables. */
439 opts
->x_flag_unwind_tables
= targetm_common
.unwind_tables_default
;
441 /* Some targets have other target-specific initialization. */
442 targetm_common
.option_init_struct (opts
);
446 /* If indicated by the optimization level LEVEL (-Os if SIZE is set,
447 -Ofast if FAST is set, -Og if DEBUG is set), apply the option DEFAULT_OPT
448 to OPTS and OPTS_SET, diagnostic context DC, location LOC, with language
449 mask LANG_MASK and option handlers HANDLERS. */
453 maybe_default_option (struct gcc_options
*opts
,
454 struct gcc_options
*opts_set
,
455 const struct default_options
*default_opt
,
456 int level
, bool size
, bool fast
, bool debug
,
457 unsigned int lang_mask
,
458 const struct cl_option_handlers
*handlers
,
460 diagnostic_context
*dc
)
462 const struct cl_option
*option
= &cl_options
[default_opt
->opt_index
];
466 gcc_assert (level
== 2);
468 gcc_assert (level
== 3);
470 gcc_assert (level
== 1);
472 switch (default_opt
->levels
)
478 case OPT_LEVELS_0_ONLY
:
479 enabled
= (level
== 0);
482 case OPT_LEVELS_1_PLUS
:
483 enabled
= (level
>= 1);
486 case OPT_LEVELS_1_PLUS_SPEED_ONLY
:
487 enabled
= (level
>= 1 && !size
&& !debug
);
490 case OPT_LEVELS_1_PLUS_NOT_DEBUG
:
491 enabled
= (level
>= 1 && !debug
);
494 case OPT_LEVELS_2_PLUS
:
495 enabled
= (level
>= 2);
498 case OPT_LEVELS_2_PLUS_SPEED_ONLY
:
499 enabled
= (level
>= 2 && !size
&& !debug
);
502 case OPT_LEVELS_3_PLUS
:
503 enabled
= (level
>= 3);
506 case OPT_LEVELS_3_PLUS_AND_SIZE
:
507 enabled
= (level
>= 3 || size
);
510 case OPT_LEVELS_SIZE
:
514 case OPT_LEVELS_FAST
:
518 case OPT_LEVELS_NONE
:
524 handle_generated_option (opts
, opts_set
, default_opt
->opt_index
,
525 default_opt
->arg
, default_opt
->value
,
526 lang_mask
, DK_UNSPECIFIED
, loc
,
528 else if (default_opt
->arg
== NULL
529 && !option
->cl_reject_negative
530 && !(option
->flags
& CL_PARAMS
))
531 handle_generated_option (opts
, opts_set
, default_opt
->opt_index
,
532 default_opt
->arg
, !default_opt
->value
,
533 lang_mask
, DK_UNSPECIFIED
, loc
,
537 /* As indicated by the optimization level LEVEL (-Os if SIZE is set,
538 -Ofast if FAST is set), apply the options in array DEFAULT_OPTS to
539 OPTS and OPTS_SET, diagnostic context DC, location LOC, with
540 language mask LANG_MASK and option handlers HANDLERS. */
543 maybe_default_options (struct gcc_options
*opts
,
544 struct gcc_options
*opts_set
,
545 const struct default_options
*default_opts
,
546 int level
, bool size
, bool fast
, bool debug
,
547 unsigned int lang_mask
,
548 const struct cl_option_handlers
*handlers
,
550 diagnostic_context
*dc
)
554 for (i
= 0; default_opts
[i
].levels
!= OPT_LEVELS_NONE
; i
++)
555 maybe_default_option (opts
, opts_set
, &default_opts
[i
],
556 level
, size
, fast
, debug
,
557 lang_mask
, handlers
, loc
, dc
);
561 /* Table of options enabled by default at different levels.
562 Please keep this list sorted by level and alphabetized within
563 each level; this makes it easier to keep the documentation
566 static const struct default_options default_options_table
[] =
568 /* -O1 and -Og optimizations. */
569 { OPT_LEVELS_1_PLUS
, OPT_fcombine_stack_adjustments
, NULL
, 1 },
570 { OPT_LEVELS_1_PLUS
, OPT_fcompare_elim
, NULL
, 1 },
571 { OPT_LEVELS_1_PLUS
, OPT_fcprop_registers
, NULL
, 1 },
572 { OPT_LEVELS_1_PLUS
, OPT_fdefer_pop
, NULL
, 1 },
573 { OPT_LEVELS_1_PLUS
, OPT_fforward_propagate
, NULL
, 1 },
574 { OPT_LEVELS_1_PLUS
, OPT_fguess_branch_probability
, NULL
, 1 },
575 { OPT_LEVELS_1_PLUS
, OPT_fipa_profile
, NULL
, 1 },
576 { OPT_LEVELS_1_PLUS
, OPT_fipa_pure_const
, NULL
, 1 },
577 { OPT_LEVELS_1_PLUS
, OPT_fipa_reference
, NULL
, 1 },
578 { OPT_LEVELS_1_PLUS
, OPT_fipa_reference_addressable
, NULL
, 1 },
579 { OPT_LEVELS_1_PLUS
, OPT_fmerge_constants
, NULL
, 1 },
580 { OPT_LEVELS_1_PLUS
, OPT_fomit_frame_pointer
, NULL
, 1 },
581 { OPT_LEVELS_1_PLUS
, OPT_freorder_blocks
, NULL
, 1 },
582 { OPT_LEVELS_1_PLUS
, OPT_fshrink_wrap
, NULL
, 1 },
583 { OPT_LEVELS_1_PLUS
, OPT_fsplit_wide_types
, NULL
, 1 },
584 { OPT_LEVELS_1_PLUS
, OPT_fthread_jumps
, NULL
, 1 },
585 { OPT_LEVELS_1_PLUS
, OPT_ftree_builtin_call_dce
, NULL
, 1 },
586 { OPT_LEVELS_1_PLUS
, OPT_ftree_ccp
, NULL
, 1 },
587 { OPT_LEVELS_1_PLUS
, OPT_ftree_ch
, NULL
, 1 },
588 { OPT_LEVELS_1_PLUS
, OPT_ftree_coalesce_vars
, NULL
, 1 },
589 { OPT_LEVELS_1_PLUS
, OPT_ftree_copy_prop
, NULL
, 1 },
590 { OPT_LEVELS_1_PLUS
, OPT_ftree_dce
, NULL
, 1 },
591 { OPT_LEVELS_1_PLUS
, OPT_ftree_dominator_opts
, NULL
, 1 },
592 { OPT_LEVELS_1_PLUS
, OPT_ftree_fre
, NULL
, 1 },
593 { OPT_LEVELS_1_PLUS
, OPT_ftree_sink
, NULL
, 1 },
594 { OPT_LEVELS_1_PLUS
, OPT_ftree_slsr
, NULL
, 1 },
595 { OPT_LEVELS_1_PLUS
, OPT_ftree_ter
, NULL
, 1 },
596 { OPT_LEVELS_1_PLUS
, OPT_fvar_tracking
, NULL
, 1 },
598 /* -O1 (and not -Og) optimizations. */
599 { OPT_LEVELS_1_PLUS_NOT_DEBUG
, OPT_fbranch_count_reg
, NULL
, 1 },
601 { OPT_LEVELS_1_PLUS_NOT_DEBUG
, OPT_fdelayed_branch
, NULL
, 1 },
603 { OPT_LEVELS_1_PLUS_NOT_DEBUG
, OPT_fdse
, NULL
, 1 },
604 { OPT_LEVELS_1_PLUS_NOT_DEBUG
, OPT_fif_conversion
, NULL
, 1 },
605 { OPT_LEVELS_1_PLUS_NOT_DEBUG
, OPT_fif_conversion2
, NULL
, 1 },
606 { OPT_LEVELS_1_PLUS_NOT_DEBUG
, OPT_finline_functions_called_once
, NULL
, 1 },
607 { OPT_LEVELS_1_PLUS_NOT_DEBUG
, OPT_fmove_loop_invariants
, NULL
, 1 },
608 { OPT_LEVELS_1_PLUS_NOT_DEBUG
, OPT_fmove_loop_stores
, NULL
, 1 },
609 { OPT_LEVELS_1_PLUS_NOT_DEBUG
, OPT_fssa_phiopt
, NULL
, 1 },
610 { OPT_LEVELS_1_PLUS_NOT_DEBUG
, OPT_fipa_modref
, NULL
, 1 },
611 { OPT_LEVELS_1_PLUS_NOT_DEBUG
, OPT_ftree_bit_ccp
, NULL
, 1 },
612 { OPT_LEVELS_1_PLUS_NOT_DEBUG
, OPT_ftree_dse
, NULL
, 1 },
613 { OPT_LEVELS_1_PLUS_NOT_DEBUG
, OPT_ftree_pta
, NULL
, 1 },
614 { OPT_LEVELS_1_PLUS_NOT_DEBUG
, OPT_ftree_sra
, NULL
, 1 },
616 /* -O2 and -Os optimizations. */
617 { OPT_LEVELS_2_PLUS
, OPT_fcaller_saves
, NULL
, 1 },
618 { OPT_LEVELS_2_PLUS
, OPT_fcode_hoisting
, NULL
, 1 },
619 { OPT_LEVELS_2_PLUS
, OPT_fcrossjumping
, NULL
, 1 },
620 { OPT_LEVELS_2_PLUS
, OPT_fcse_follow_jumps
, NULL
, 1 },
621 { OPT_LEVELS_2_PLUS
, OPT_fdevirtualize
, NULL
, 1 },
622 { OPT_LEVELS_2_PLUS
, OPT_fdevirtualize_speculatively
, NULL
, 1 },
623 { OPT_LEVELS_2_PLUS
, OPT_fexpensive_optimizations
, NULL
, 1 },
624 { OPT_LEVELS_2_PLUS
, OPT_fgcse
, NULL
, 1 },
625 { OPT_LEVELS_2_PLUS
, OPT_fhoist_adjacent_loads
, NULL
, 1 },
626 { OPT_LEVELS_2_PLUS
, OPT_findirect_inlining
, NULL
, 1 },
627 { OPT_LEVELS_2_PLUS
, OPT_finline_small_functions
, NULL
, 1 },
628 { OPT_LEVELS_2_PLUS
, OPT_fipa_bit_cp
, NULL
, 1 },
629 { OPT_LEVELS_2_PLUS
, OPT_fipa_cp
, NULL
, 1 },
630 { OPT_LEVELS_2_PLUS
, OPT_fipa_icf
, NULL
, 1 },
631 { OPT_LEVELS_2_PLUS
, OPT_fipa_ra
, NULL
, 1 },
632 { OPT_LEVELS_2_PLUS
, OPT_fipa_sra
, NULL
, 1 },
633 { OPT_LEVELS_2_PLUS
, OPT_fipa_vrp
, NULL
, 1 },
634 { OPT_LEVELS_2_PLUS
, OPT_fisolate_erroneous_paths_dereference
, NULL
, 1 },
635 { OPT_LEVELS_2_PLUS
, OPT_flra_remat
, NULL
, 1 },
636 { OPT_LEVELS_2_PLUS
, OPT_foptimize_sibling_calls
, NULL
, 1 },
637 { OPT_LEVELS_2_PLUS
, OPT_fpartial_inlining
, NULL
, 1 },
638 { OPT_LEVELS_2_PLUS
, OPT_fpeephole2
, NULL
, 1 },
639 { OPT_LEVELS_2_PLUS
, OPT_freorder_functions
, NULL
, 1 },
640 { OPT_LEVELS_2_PLUS
, OPT_frerun_cse_after_loop
, NULL
, 1 },
641 #ifdef INSN_SCHEDULING
642 { OPT_LEVELS_2_PLUS
, OPT_fschedule_insns2
, NULL
, 1 },
644 { OPT_LEVELS_2_PLUS
, OPT_fstrict_aliasing
, NULL
, 1 },
645 { OPT_LEVELS_2_PLUS
, OPT_fstore_merging
, NULL
, 1 },
646 { OPT_LEVELS_2_PLUS
, OPT_ftree_pre
, NULL
, 1 },
647 { OPT_LEVELS_2_PLUS
, OPT_ftree_switch_conversion
, NULL
, 1 },
648 { OPT_LEVELS_2_PLUS
, OPT_ftree_tail_merge
, NULL
, 1 },
649 { OPT_LEVELS_2_PLUS
, OPT_ftree_vrp
, NULL
, 1 },
650 { OPT_LEVELS_2_PLUS
, OPT_fvect_cost_model_
, NULL
,
651 VECT_COST_MODEL_VERY_CHEAP
},
652 { OPT_LEVELS_2_PLUS
, OPT_finline_functions
, NULL
, 1 },
653 { OPT_LEVELS_2_PLUS
, OPT_ftree_loop_distribute_patterns
, NULL
, 1 },
655 /* -O2 and above optimizations, but not -Os or -Og. */
656 { OPT_LEVELS_2_PLUS_SPEED_ONLY
, OPT_falign_functions
, NULL
, 1 },
657 { OPT_LEVELS_2_PLUS_SPEED_ONLY
, OPT_falign_jumps
, NULL
, 1 },
658 { OPT_LEVELS_2_PLUS_SPEED_ONLY
, OPT_falign_labels
, NULL
, 1 },
659 { OPT_LEVELS_2_PLUS_SPEED_ONLY
, OPT_falign_loops
, NULL
, 1 },
660 { OPT_LEVELS_2_PLUS_SPEED_ONLY
, OPT_foptimize_strlen
, NULL
, 1 },
661 { OPT_LEVELS_2_PLUS_SPEED_ONLY
, OPT_freorder_blocks_algorithm_
, NULL
,
662 REORDER_BLOCKS_ALGORITHM_STC
},
663 { OPT_LEVELS_2_PLUS_SPEED_ONLY
, OPT_ftree_loop_vectorize
, NULL
, 1 },
664 { OPT_LEVELS_2_PLUS_SPEED_ONLY
, OPT_ftree_slp_vectorize
, NULL
, 1 },
665 #ifdef INSN_SCHEDULING
666 /* Only run the pre-regalloc scheduling pass if optimizing for speed. */
667 { OPT_LEVELS_2_PLUS_SPEED_ONLY
, OPT_fschedule_insns
, NULL
, 1 },
670 /* -O3 and -Os optimizations. */
672 /* -O3 optimizations. */
673 { OPT_LEVELS_3_PLUS
, OPT_fgcse_after_reload
, NULL
, 1 },
674 { OPT_LEVELS_3_PLUS
, OPT_fipa_cp_clone
, NULL
, 1 },
675 { OPT_LEVELS_3_PLUS
, OPT_floop_interchange
, NULL
, 1 },
676 { OPT_LEVELS_3_PLUS
, OPT_floop_unroll_and_jam
, NULL
, 1 },
677 { OPT_LEVELS_3_PLUS
, OPT_fpeel_loops
, NULL
, 1 },
678 { OPT_LEVELS_3_PLUS
, OPT_fpredictive_commoning
, NULL
, 1 },
679 { OPT_LEVELS_3_PLUS
, OPT_fsplit_loops
, NULL
, 1 },
680 { OPT_LEVELS_3_PLUS
, OPT_fsplit_paths
, NULL
, 1 },
681 { OPT_LEVELS_3_PLUS
, OPT_ftree_loop_distribution
, NULL
, 1 },
682 { OPT_LEVELS_3_PLUS
, OPT_ftree_partial_pre
, NULL
, 1 },
683 { OPT_LEVELS_3_PLUS
, OPT_funswitch_loops
, NULL
, 1 },
684 { OPT_LEVELS_3_PLUS
, OPT_fvect_cost_model_
, NULL
, VECT_COST_MODEL_DYNAMIC
},
685 { OPT_LEVELS_3_PLUS
, OPT_fversion_loops_for_strides
, NULL
, 1 },
687 /* -O3 parameters. */
688 { OPT_LEVELS_3_PLUS
, OPT__param_max_inline_insns_auto_
, NULL
, 30 },
689 { OPT_LEVELS_3_PLUS
, OPT__param_early_inlining_insns_
, NULL
, 14 },
690 { OPT_LEVELS_3_PLUS
, OPT__param_inline_heuristics_hint_percent_
, NULL
, 600 },
691 { OPT_LEVELS_3_PLUS
, OPT__param_inline_min_speedup_
, NULL
, 15 },
692 { OPT_LEVELS_3_PLUS
, OPT__param_max_inline_insns_single_
, NULL
, 200 },
694 /* -Ofast adds optimizations to -O3. */
695 { OPT_LEVELS_FAST
, OPT_ffast_math
, NULL
, 1 },
696 { OPT_LEVELS_FAST
, OPT_fallow_store_data_races
, NULL
, 1 },
697 { OPT_LEVELS_FAST
, OPT_fsemantic_interposition
, NULL
, 0 },
699 { OPT_LEVELS_NONE
, 0, NULL
, 0 }
703 /* Default the options in OPTS and OPTS_SET based on the optimization
704 settings in DECODED_OPTIONS and DECODED_OPTIONS_COUNT. */
706 default_options_optimization (struct gcc_options
*opts
,
707 struct gcc_options
*opts_set
,
708 struct cl_decoded_option
*decoded_options
,
709 unsigned int decoded_options_count
,
711 unsigned int lang_mask
,
712 const struct cl_option_handlers
*handlers
,
713 diagnostic_context
*dc
)
717 bool openacc_mode
= false;
719 /* Scan to see what optimization level has been specified. That will
720 determine the default value of many flags. */
721 for (i
= 1; i
< decoded_options_count
; i
++)
723 struct cl_decoded_option
*opt
= &decoded_options
[i
];
724 switch (opt
->opt_index
)
727 if (*opt
->arg
== '\0')
729 opts
->x_optimize
= 1;
730 opts
->x_optimize_size
= 0;
731 opts
->x_optimize_fast
= 0;
732 opts
->x_optimize_debug
= 0;
736 const int optimize_val
= integral_argument (opt
->arg
);
737 if (optimize_val
== -1)
738 error_at (loc
, "argument to %<-O%> should be a non-negative "
739 "integer, %<g%>, %<s%>, %<z%> or %<fast%>");
742 opts
->x_optimize
= optimize_val
;
743 if ((unsigned int) opts
->x_optimize
> 255)
744 opts
->x_optimize
= 255;
745 opts
->x_optimize_size
= 0;
746 opts
->x_optimize_fast
= 0;
747 opts
->x_optimize_debug
= 0;
753 opts
->x_optimize_size
= 1;
755 /* Optimizing for size forces optimize to be 2. */
756 opts
->x_optimize
= 2;
757 opts
->x_optimize_fast
= 0;
758 opts
->x_optimize_debug
= 0;
762 opts
->x_optimize_size
= 2;
764 /* Optimizing for size forces optimize to be 2. */
765 opts
->x_optimize
= 2;
766 opts
->x_optimize_fast
= 0;
767 opts
->x_optimize_debug
= 0;
771 /* -Ofast only adds flags to -O3. */
772 opts
->x_optimize_size
= 0;
773 opts
->x_optimize
= 3;
774 opts
->x_optimize_fast
= 1;
775 opts
->x_optimize_debug
= 0;
779 /* -Og selects optimization level 1. */
780 opts
->x_optimize_size
= 0;
781 opts
->x_optimize
= 1;
782 opts
->x_optimize_fast
= 0;
783 opts
->x_optimize_debug
= 1;
792 /* Ignore other options in this prescan. */
797 maybe_default_options (opts
, opts_set
, default_options_table
,
798 opts
->x_optimize
, opts
->x_optimize_size
,
799 opts
->x_optimize_fast
, opts
->x_optimize_debug
,
800 lang_mask
, handlers
, loc
, dc
);
802 /* -O2 param settings. */
803 opt2
= (opts
->x_optimize
>= 2);
806 SET_OPTION_IF_UNSET (opts
, opts_set
, flag_ipa_pta
, true);
808 /* Track fields in field-sensitive alias analysis. */
810 SET_OPTION_IF_UNSET (opts
, opts_set
, param_max_fields_for_field_sensitive
,
813 if (opts
->x_optimize_size
)
814 /* We want to crossjump as much as possible. */
815 SET_OPTION_IF_UNSET (opts
, opts_set
, param_min_crossjump_insns
, 1);
817 /* Restrict the amount of work combine does at -Og while retaining
818 most of its useful transforms. */
819 if (opts
->x_optimize_debug
)
820 SET_OPTION_IF_UNSET (opts
, opts_set
, param_max_combine_insns
, 2);
822 /* Allow default optimizations to be specified on a per-machine basis. */
823 maybe_default_options (opts
, opts_set
,
824 targetm_common
.option_optimization_table
,
825 opts
->x_optimize
, opts
->x_optimize_size
,
826 opts
->x_optimize_fast
, opts
->x_optimize_debug
,
827 lang_mask
, handlers
, loc
, dc
);
831 /* Control IPA optimizations based on different live patching LEVEL. */
833 control_options_for_live_patching (struct gcc_options
*opts
,
834 struct gcc_options
*opts_set
,
835 enum live_patching_level level
,
838 gcc_assert (level
> LIVE_PATCHING_NONE
);
842 case LIVE_PATCHING_INLINE_ONLY_STATIC
:
843 #define LIVE_PATCHING_OPTION "-flive-patching=inline-only-static"
844 if (opts_set
->x_flag_ipa_cp_clone
&& opts
->x_flag_ipa_cp_clone
)
845 error_at (loc
, "%qs is incompatible with %qs",
846 "-fipa-cp-clone", LIVE_PATCHING_OPTION
);
848 opts
->x_flag_ipa_cp_clone
= 0;
850 if (opts_set
->x_flag_ipa_sra
&& opts
->x_flag_ipa_sra
)
851 error_at (loc
, "%qs is incompatible with %qs",
852 "-fipa-sra", LIVE_PATCHING_OPTION
);
854 opts
->x_flag_ipa_sra
= 0;
856 if (opts_set
->x_flag_partial_inlining
&& opts
->x_flag_partial_inlining
)
857 error_at (loc
, "%qs is incompatible with %qs",
858 "-fpartial-inlining", LIVE_PATCHING_OPTION
);
860 opts
->x_flag_partial_inlining
= 0;
862 if (opts_set
->x_flag_ipa_cp
&& opts
->x_flag_ipa_cp
)
863 error_at (loc
, "%qs is incompatible with %qs",
864 "-fipa-cp", LIVE_PATCHING_OPTION
);
866 opts
->x_flag_ipa_cp
= 0;
869 case LIVE_PATCHING_INLINE_CLONE
:
870 #undef LIVE_PATCHING_OPTION
871 #define LIVE_PATCHING_OPTION "-flive-patching=inline-only-static|inline-clone"
872 /* live patching should disable whole-program optimization. */
873 if (opts_set
->x_flag_whole_program
&& opts
->x_flag_whole_program
)
874 error_at (loc
, "%qs is incompatible with %qs",
875 "-fwhole-program", LIVE_PATCHING_OPTION
);
877 opts
->x_flag_whole_program
= 0;
879 /* visibility change should be excluded by !flag_whole_program
880 && !in_lto_p && !flag_ipa_cp_clone && !flag_ipa_sra
881 && !flag_partial_inlining. */
883 if (opts_set
->x_flag_ipa_pta
&& opts
->x_flag_ipa_pta
)
884 error_at (loc
, "%qs is incompatible with %qs",
885 "-fipa-pta", LIVE_PATCHING_OPTION
);
887 opts
->x_flag_ipa_pta
= 0;
889 if (opts_set
->x_flag_ipa_reference
&& opts
->x_flag_ipa_reference
)
890 error_at (loc
, "%qs is incompatible with %qs",
891 "-fipa-reference", LIVE_PATCHING_OPTION
);
893 opts
->x_flag_ipa_reference
= 0;
895 if (opts_set
->x_flag_ipa_ra
&& opts
->x_flag_ipa_ra
)
896 error_at (loc
, "%qs is incompatible with %qs",
897 "-fipa-ra", LIVE_PATCHING_OPTION
);
899 opts
->x_flag_ipa_ra
= 0;
901 if (opts_set
->x_flag_ipa_icf
&& opts
->x_flag_ipa_icf
)
902 error_at (loc
, "%qs is incompatible with %qs",
903 "-fipa-icf", LIVE_PATCHING_OPTION
);
905 opts
->x_flag_ipa_icf
= 0;
907 if (opts_set
->x_flag_ipa_icf_functions
&& opts
->x_flag_ipa_icf_functions
)
908 error_at (loc
, "%qs is incompatible with %qs",
909 "-fipa-icf-functions", LIVE_PATCHING_OPTION
);
911 opts
->x_flag_ipa_icf_functions
= 0;
913 if (opts_set
->x_flag_ipa_icf_variables
&& opts
->x_flag_ipa_icf_variables
)
914 error_at (loc
, "%qs is incompatible with %qs",
915 "-fipa-icf-variables", LIVE_PATCHING_OPTION
);
917 opts
->x_flag_ipa_icf_variables
= 0;
919 if (opts_set
->x_flag_ipa_bit_cp
&& opts
->x_flag_ipa_bit_cp
)
920 error_at (loc
, "%qs is incompatible with %qs",
921 "-fipa-bit-cp", LIVE_PATCHING_OPTION
);
923 opts
->x_flag_ipa_bit_cp
= 0;
925 if (opts_set
->x_flag_ipa_vrp
&& opts
->x_flag_ipa_vrp
)
926 error_at (loc
, "%qs is incompatible with %qs",
927 "-fipa-vrp", LIVE_PATCHING_OPTION
);
929 opts
->x_flag_ipa_vrp
= 0;
931 if (opts_set
->x_flag_ipa_pure_const
&& opts
->x_flag_ipa_pure_const
)
932 error_at (loc
, "%qs is incompatible with %qs",
933 "-fipa-pure-const", LIVE_PATCHING_OPTION
);
935 opts
->x_flag_ipa_pure_const
= 0;
937 if (opts_set
->x_flag_ipa_modref
&& opts
->x_flag_ipa_modref
)
939 "%<-fipa-modref%> is incompatible with %qs",
940 LIVE_PATCHING_OPTION
);
942 opts
->x_flag_ipa_modref
= 0;
944 /* FIXME: disable unreachable code removal. */
946 /* discovery of functions/variables with no address taken. */
947 if (opts_set
->x_flag_ipa_reference_addressable
948 && opts
->x_flag_ipa_reference_addressable
)
949 error_at (loc
, "%qs is incompatible with %qs",
950 "-fipa-reference-addressable", LIVE_PATCHING_OPTION
);
952 opts
->x_flag_ipa_reference_addressable
= 0;
954 /* ipa stack alignment propagation. */
955 if (opts_set
->x_flag_ipa_stack_alignment
956 && opts
->x_flag_ipa_stack_alignment
)
957 error_at (loc
, "%qs is incompatible with %qs",
958 "-fipa-stack-alignment", LIVE_PATCHING_OPTION
);
960 opts
->x_flag_ipa_stack_alignment
= 0;
966 #undef LIVE_PATCHING_OPTION
969 /* --help option argument if set. */
970 vec
<const char *> help_option_arguments
;
972 /* Return the string name describing a sanitizer argument which has been
973 provided on the command line and has set this particular flag. */
975 find_sanitizer_argument (struct gcc_options
*opts
, unsigned int flags
)
977 for (int i
= 0; sanitizer_opts
[i
].name
!= NULL
; ++i
)
979 /* Need to find the sanitizer_opts element which:
980 a) Could have set the flags requested.
981 b) Has been set on the command line.
983 Can have (a) without (b) if the flag requested is e.g.
984 SANITIZE_ADDRESS, since both -fsanitize=address and
985 -fsanitize=kernel-address set this flag.
987 Can have (b) without (a) by requesting more than one sanitizer on the
989 if ((sanitizer_opts
[i
].flag
& opts
->x_flag_sanitize
)
990 != sanitizer_opts
[i
].flag
)
992 if ((sanitizer_opts
[i
].flag
& flags
) != flags
)
994 return sanitizer_opts
[i
].name
;
1000 /* Report an error to the user about sanitizer options they have requested
1001 which have set conflicting flags.
1003 LEFT and RIGHT indicate sanitizer flags which conflict with each other, this
1004 function reports an error if both have been set in OPTS->x_flag_sanitize and
1005 ensures the error identifies the requested command line options that have
1008 report_conflicting_sanitizer_options (struct gcc_options
*opts
, location_t loc
,
1009 unsigned int left
, unsigned int right
)
1011 unsigned int left_seen
= (opts
->x_flag_sanitize
& left
);
1012 unsigned int right_seen
= (opts
->x_flag_sanitize
& right
);
1013 if (left_seen
&& right_seen
)
1015 const char* left_arg
= find_sanitizer_argument (opts
, left_seen
);
1016 const char* right_arg
= find_sanitizer_argument (opts
, right_seen
);
1017 gcc_assert (left_arg
&& right_arg
);
1019 "%<-fsanitize=%s%> is incompatible with %<-fsanitize=%s%>",
1020 left_arg
, right_arg
);
1024 /* After all options at LOC have been read into OPTS and OPTS_SET,
1025 finalize settings of those options and diagnose incompatible
1028 finish_options (struct gcc_options
*opts
, struct gcc_options
*opts_set
,
1031 if (opts
->x_dump_base_name
1032 && ! opts
->x_dump_base_name_prefixed
)
1034 const char *sep
= opts
->x_dump_base_name
;
1037 if (IS_DIR_SEPARATOR (*sep
))
1041 /* If dump_base_path contains subdirectories, don't prepend
1043 else if (opts
->x_dump_dir_name
)
1044 /* We have a DUMP_DIR_NAME, prepend that. */
1045 opts
->x_dump_base_name
= opts_concat (opts
->x_dump_dir_name
,
1046 opts
->x_dump_base_name
, NULL
);
1048 /* It is definitely prefixed now. */
1049 opts
->x_dump_base_name_prefixed
= true;
1052 /* Handle related options for unit-at-a-time, toplevel-reorder, and
1054 if (!opts
->x_flag_unit_at_a_time
)
1056 if (opts
->x_flag_section_anchors
&& opts_set
->x_flag_section_anchors
)
1057 error_at (loc
, "section anchors must be disabled when unit-at-a-time "
1059 opts
->x_flag_section_anchors
= 0;
1060 if (opts
->x_flag_toplevel_reorder
== 1)
1061 error_at (loc
, "toplevel reorder must be disabled when unit-at-a-time "
1063 opts
->x_flag_toplevel_reorder
= 0;
1066 /* -fself-test depends on the state of the compiler prior to
1067 compiling anything. Ideally it should be run on an empty source
1068 file. However, in case we get run with actual source, assume
1069 -fsyntax-only which will inhibit any compiler initialization
1070 which may confuse the self tests. */
1071 if (opts
->x_flag_self_test
)
1072 opts
->x_flag_syntax_only
= 1;
1074 if (opts
->x_flag_tm
&& opts
->x_flag_non_call_exceptions
)
1075 sorry ("transactional memory is not supported with non-call exceptions");
1077 /* Unless the user has asked for section anchors, we disable toplevel
1078 reordering at -O0 to disable transformations that might be surprising
1079 to end users and to get -fno-toplevel-reorder tested. */
1080 if (!opts
->x_optimize
1081 && opts
->x_flag_toplevel_reorder
== 2
1082 && !(opts
->x_flag_section_anchors
&& opts_set
->x_flag_section_anchors
))
1084 opts
->x_flag_toplevel_reorder
= 0;
1085 opts
->x_flag_section_anchors
= 0;
1087 if (!opts
->x_flag_toplevel_reorder
)
1089 if (opts
->x_flag_section_anchors
&& opts_set
->x_flag_section_anchors
)
1090 error_at (loc
, "section anchors must be disabled when toplevel reorder"
1092 opts
->x_flag_section_anchors
= 0;
1095 if (!opts
->x_flag_opts_finished
)
1097 /* We initialize opts->x_flag_pie to -1 so that targets can set a
1099 if (opts
->x_flag_pie
== -1)
1101 /* We initialize opts->x_flag_pic to -1 so that we can tell if
1102 -fpic, -fPIC, -fno-pic or -fno-PIC is used. */
1103 if (opts
->x_flag_pic
== -1)
1104 opts
->x_flag_pie
= DEFAULT_FLAG_PIE
;
1106 opts
->x_flag_pie
= 0;
1108 /* If -fPIE or -fpie is used, turn on PIC. */
1109 if (opts
->x_flag_pie
)
1110 opts
->x_flag_pic
= opts
->x_flag_pie
;
1111 else if (opts
->x_flag_pic
== -1)
1112 opts
->x_flag_pic
= 0;
1113 if (opts
->x_flag_pic
&& !opts
->x_flag_pie
)
1114 opts
->x_flag_shlib
= 1;
1115 opts
->x_flag_opts_finished
= true;
1118 /* We initialize opts->x_flag_stack_protect to -1 so that targets
1119 can set a default value. */
1120 if (opts
->x_flag_stack_protect
== -1)
1121 opts
->x_flag_stack_protect
= DEFAULT_FLAG_SSP
;
1123 if (opts
->x_optimize
== 0)
1125 /* Inlining does not work if not optimizing,
1126 so force it not to be done. */
1127 opts
->x_warn_inline
= 0;
1128 opts
->x_flag_no_inline
= 1;
1131 /* Pipelining of outer loops is only possible when general pipelining
1132 capabilities are requested. */
1133 if (!opts
->x_flag_sel_sched_pipelining
)
1134 opts
->x_flag_sel_sched_pipelining_outer_loops
= 0;
1136 if (opts
->x_flag_conserve_stack
)
1138 SET_OPTION_IF_UNSET (opts
, opts_set
, param_large_stack_frame
, 100);
1139 SET_OPTION_IF_UNSET (opts
, opts_set
, param_stack_frame_growth
, 40);
1142 if (opts
->x_flag_lto
)
1145 opts
->x_flag_generate_lto
= 1;
1147 /* When generating IL, do not operate in whole-program mode.
1148 Otherwise, symbols will be privatized too early, causing link
1150 opts
->x_flag_whole_program
= 0;
1152 error_at (loc
, "LTO support has not been enabled in this configuration");
1154 if (!opts
->x_flag_fat_lto_objects
1155 && (!HAVE_LTO_PLUGIN
1156 || (opts_set
->x_flag_use_linker_plugin
1157 && !opts
->x_flag_use_linker_plugin
)))
1159 if (opts_set
->x_flag_fat_lto_objects
)
1160 error_at (loc
, "%<-fno-fat-lto-objects%> are supported only with "
1162 opts
->x_flag_fat_lto_objects
= 1;
1165 /* -gsplit-dwarf isn't compatible with LTO, see PR88389. */
1166 if (opts
->x_dwarf_split_debug_info
)
1168 inform (loc
, "%<-gsplit-dwarf%> is not supported with LTO,"
1170 opts
->x_dwarf_split_debug_info
= 0;
1174 /* We initialize opts->x_flag_split_stack to -1 so that targets can set a
1175 default value if they choose based on other options. */
1176 if (opts
->x_flag_split_stack
== -1)
1177 opts
->x_flag_split_stack
= 0;
1178 else if (opts
->x_flag_split_stack
)
1180 // sdcpp if (!targetm_common.supports_split_stack (true, opts))
1182 error_at (loc
, "%<-fsplit-stack%> is not supported by "
1183 "this compiler configuration");
1184 opts
->x_flag_split_stack
= 0;
1188 /* If stack splitting is turned on, and the user did not explicitly
1189 request function partitioning, turn off partitioning, as it
1190 confuses the linker when trying to handle partitioned split-stack
1191 code that calls a non-split-stack functions. But if partitioning
1192 was turned on explicitly just hope for the best. */
1193 if (opts
->x_flag_split_stack
1194 && opts
->x_flag_reorder_blocks_and_partition
)
1195 SET_OPTION_IF_UNSET (opts
, opts_set
, flag_reorder_blocks_and_partition
, 0);
1197 if (opts
->x_flag_reorder_blocks_and_partition
)
1198 SET_OPTION_IF_UNSET (opts
, opts_set
, flag_reorder_functions
, 1);
1200 /* The -gsplit-dwarf option requires -ggnu-pubnames. */
1201 if (opts
->x_dwarf_split_debug_info
)
1202 opts
->x_debug_generate_pub_sections
= 2;
1204 if ((opts
->x_flag_sanitize
1205 & (SANITIZE_USER_ADDRESS
| SANITIZE_KERNEL_ADDRESS
)) == 0)
1207 if (opts
->x_flag_sanitize
& SANITIZE_POINTER_COMPARE
)
1209 "%<-fsanitize=pointer-compare%> must be combined with "
1210 "%<-fsanitize=address%> or %<-fsanitize=kernel-address%>");
1211 if (opts
->x_flag_sanitize
& SANITIZE_POINTER_SUBTRACT
)
1213 "%<-fsanitize=pointer-subtract%> must be combined with "
1214 "%<-fsanitize=address%> or %<-fsanitize=kernel-address%>");
1217 /* Address sanitizers conflict with the thread sanitizer. */
1218 report_conflicting_sanitizer_options (opts
, loc
, SANITIZE_THREAD
,
1219 SANITIZE_ADDRESS
| SANITIZE_HWADDRESS
);
1220 /* The leak sanitizer conflicts with the thread sanitizer. */
1221 report_conflicting_sanitizer_options (opts
, loc
, SANITIZE_LEAK
,
1224 /* No combination of HWASAN and ASAN work together. */
1225 report_conflicting_sanitizer_options (opts
, loc
,
1226 SANITIZE_HWADDRESS
, SANITIZE_ADDRESS
);
1228 /* The userspace and kernel address sanitizers conflict with each other. */
1229 report_conflicting_sanitizer_options (opts
, loc
, SANITIZE_USER_HWADDRESS
,
1230 SANITIZE_KERNEL_HWADDRESS
);
1231 report_conflicting_sanitizer_options (opts
, loc
, SANITIZE_USER_ADDRESS
,
1232 SANITIZE_KERNEL_ADDRESS
);
1234 /* Check error recovery for -fsanitize-recover option. */
1235 for (int i
= 0; sanitizer_opts
[i
].name
!= NULL
; ++i
)
1236 if ((opts
->x_flag_sanitize_recover
& sanitizer_opts
[i
].flag
)
1237 && !sanitizer_opts
[i
].can_recover
)
1238 error_at (loc
, "%<-fsanitize-recover=%s%> is not supported",
1239 sanitizer_opts
[i
].name
);
1241 /* When instrumenting the pointers, we don't want to remove
1242 the null pointer checks. */
1243 if (opts
->x_flag_sanitize
& (SANITIZE_NULL
| SANITIZE_NONNULL_ATTRIBUTE
1244 | SANITIZE_RETURNS_NONNULL_ATTRIBUTE
))
1245 opts
->x_flag_delete_null_pointer_checks
= 0;
1247 /* Aggressive compiler optimizations may cause false negatives. */
1248 if (opts
->x_flag_sanitize
& ~(SANITIZE_LEAK
| SANITIZE_UNREACHABLE
))
1249 opts
->x_flag_aggressive_loop_optimizations
= 0;
1251 /* Enable -fsanitize-address-use-after-scope if either address sanitizer is
1253 if (opts
->x_flag_sanitize
1254 & (SANITIZE_USER_ADDRESS
| SANITIZE_USER_HWADDRESS
))
1255 SET_OPTION_IF_UNSET (opts
, opts_set
, flag_sanitize_address_use_after_scope
,
1258 /* Force -fstack-reuse=none in case -fsanitize-address-use-after-scope
1260 if (opts
->x_flag_sanitize_address_use_after_scope
)
1262 if (opts
->x_flag_stack_reuse
!= SR_NONE
1263 && opts_set
->x_flag_stack_reuse
!= SR_NONE
)
1265 "%<-fsanitize-address-use-after-scope%> requires "
1266 "%<-fstack-reuse=none%> option");
1268 opts
->x_flag_stack_reuse
= SR_NONE
;
1271 if ((opts
->x_flag_sanitize
& SANITIZE_USER_ADDRESS
) && opts
->x_flag_tm
)
1272 sorry ("transactional memory is not supported with %<-fsanitize=address%>");
1274 if ((opts
->x_flag_sanitize
& SANITIZE_KERNEL_ADDRESS
) && opts
->x_flag_tm
)
1275 sorry ("transactional memory is not supported with "
1276 "%<-fsanitize=kernel-address%>");
1278 /* Currently live patching is not support for LTO. */
1279 if (opts
->x_flag_live_patching
&& opts
->x_flag_lto
)
1280 sorry ("live patching is not supported with LTO");
1282 /* Currently vtable verification is not supported for LTO */
1283 if (opts
->x_flag_vtable_verify
&& opts
->x_flag_lto
)
1284 sorry ("vtable verification is not supported with LTO");
1286 /* Control IPA optimizations based on different -flive-patching level. */
1287 if (opts
->x_flag_live_patching
)
1288 control_options_for_live_patching (opts
, opts_set
,
1289 opts
->x_flag_live_patching
,
1292 /* Allow cunroll to grow size accordingly. */
1293 if (!opts_set
->x_flag_cunroll_grow_size
)
1294 opts
->x_flag_cunroll_grow_size
1295 = (opts
->x_flag_unroll_loops
1296 || opts
->x_flag_peel_loops
1297 || opts
->x_optimize
>= 3);
1299 /* With -fcx-limited-range, we do cheap and quick complex arithmetic. */
1300 if (opts
->x_flag_cx_limited_range
)
1301 opts
->x_flag_complex_method
= 0;
1302 else if (opts_set
->x_flag_cx_limited_range
)
1303 opts
->x_flag_complex_method
= opts
->x_flag_default_complex_method
;
1305 /* With -fcx-fortran-rules, we do something in-between cheap and C99. */
1306 if (opts
->x_flag_cx_fortran_rules
)
1307 opts
->x_flag_complex_method
= 1;
1308 else if (opts_set
->x_flag_cx_fortran_rules
)
1309 opts
->x_flag_complex_method
= opts
->x_flag_default_complex_method
;
1311 /* Use -fvect-cost-model=cheap instead of -fvect-cost-mode=very-cheap
1312 by default with explicit -ftree-{loop,slp}-vectorize. */
1313 if (opts
->x_optimize
== 2
1314 && (opts_set
->x_flag_tree_loop_vectorize
1315 || opts_set
->x_flag_tree_vectorize
))
1316 SET_OPTION_IF_UNSET (opts
, opts_set
, flag_vect_cost_model
,
1317 VECT_COST_MODEL_CHEAP
);
1321 /* Make sure to process -gtoggle only once. */
1322 flag_gtoggle
= false;
1323 if (debug_info_level
== DINFO_LEVEL_NONE
)
1325 debug_info_level
= DINFO_LEVEL_NORMAL
;
1327 if (write_symbols
== NO_DEBUG
)
1328 write_symbols
= PREFERRED_DEBUGGING_TYPE
;
1331 debug_info_level
= DINFO_LEVEL_NONE
;
1334 if (!OPTION_SET_P (debug_nonbind_markers_p
))
1335 debug_nonbind_markers_p
1337 && debug_info_level
>= DINFO_LEVEL_NORMAL
1338 && dwarf_debuginfo_p ()
1339 && !(flag_selective_scheduling
|| flag_selective_scheduling2
));
1341 /* Note -fvar-tracking is enabled automatically with OPT_LEVELS_1_PLUS and
1342 so we need to drop it if we are called from optimize attribute. */
1343 if (debug_info_level
== DINFO_LEVEL_NONE
1344 && !OPTION_SET_P (flag_var_tracking
))
1345 flag_var_tracking
= false;
1347 /* One could use EnabledBy, but it would lead to a circular dependency. */
1348 if (!OPTION_SET_P (flag_var_tracking_uninit
))
1349 flag_var_tracking_uninit
= flag_var_tracking
;
1351 if (!OPTION_SET_P (flag_var_tracking_assignments
))
1352 flag_var_tracking_assignments
1353 = (flag_var_tracking
1354 && !(flag_selective_scheduling
|| flag_selective_scheduling2
));
1356 if (flag_var_tracking_assignments_toggle
)
1357 flag_var_tracking_assignments
= !flag_var_tracking_assignments
;
1359 if (flag_var_tracking_assignments
&& !flag_var_tracking
)
1360 flag_var_tracking
= flag_var_tracking_assignments
= -1;
1362 if (flag_var_tracking_assignments
1363 && (flag_selective_scheduling
|| flag_selective_scheduling2
))
1365 "var-tracking-assignments changes selective scheduling");
1367 if (flag_syntax_only
)
1369 write_symbols
= NO_DEBUG
;
1374 diagnose_options (opts
, opts_set
, loc
);
1377 /* The function diagnoses incompatible combinations for provided options
1378 (OPTS and OPTS_SET) at a given LOCation. The function is called both
1379 when command line is parsed (after the target optimization hook) and
1380 when an optimize/target attribute (or pragma) is used. */
1382 void diagnose_options (gcc_options
*opts
, gcc_options
*opts_set
,
1385 /* The optimization to partition hot and cold basic blocks into separate
1386 sections of the .o and executable files does not work (currently)
1387 with exception handling. This is because there is no support for
1388 generating unwind info. If opts->x_flag_exceptions is turned on
1389 we need to turn off the partitioning optimization. */
1391 enum unwind_info_type ui_except
1392 = unwind_info_type(); // sdcpp targetm_common.except_unwind_info (opts);
1394 if (opts
->x_flag_exceptions
1395 && opts
->x_flag_reorder_blocks_and_partition
1396 && (ui_except
== UI_SJLJ
|| ui_except
>= UI_TARGET
))
1398 if (opts_set
->x_flag_reorder_blocks_and_partition
)
1400 "%<-freorder-blocks-and-partition%> does not work "
1401 "with exceptions on this architecture");
1402 opts
->x_flag_reorder_blocks_and_partition
= 0;
1403 opts
->x_flag_reorder_blocks
= 1;
1406 /* If user requested unwind info, then turn off the partitioning
1409 if (opts
->x_flag_unwind_tables
1410 // sdcpp && !targetm_common.unwind_tables_default
1411 && opts
->x_flag_reorder_blocks_and_partition
1412 && (ui_except
== UI_SJLJ
|| ui_except
>= UI_TARGET
))
1414 if (opts_set
->x_flag_reorder_blocks_and_partition
)
1416 "%<-freorder-blocks-and-partition%> does not support "
1417 "unwind info on this architecture");
1418 opts
->x_flag_reorder_blocks_and_partition
= 0;
1419 opts
->x_flag_reorder_blocks
= 1;
1422 /* If the target requested unwind info, then turn off the partitioning
1423 optimization with a different message. Likewise, if the target does not
1424 support named sections. */
1426 if (opts
->x_flag_reorder_blocks_and_partition
1427 && (0 // sdcpp !targetm_common.have_named_sections
1428 || (opts
->x_flag_unwind_tables
1429 // sdcpp && targetm_common.unwind_tables_default
1430 && (ui_except
== UI_SJLJ
|| ui_except
>= UI_TARGET
))))
1432 if (opts_set
->x_flag_reorder_blocks_and_partition
)
1434 "%<-freorder-blocks-and-partition%> does not work "
1435 "on this architecture");
1436 opts
->x_flag_reorder_blocks_and_partition
= 0;
1437 opts
->x_flag_reorder_blocks
= 1;
1443 #define LEFT_COLUMN 27
1445 /* Output ITEM, of length ITEM_WIDTH, in the left column,
1446 followed by word-wrapped HELP in a second column. */
1448 wrap_help (const char *help
,
1450 unsigned int item_width
,
1451 unsigned int columns
)
1453 unsigned int col_width
= LEFT_COLUMN
;
1454 unsigned int remaining
, room
, len
;
1456 remaining
= strlen (help
);
1460 room
= columns
- 3 - MAX (col_width
, item_width
);
1469 for (i
= 0; help
[i
]; i
++)
1471 if (i
>= room
&& len
!= remaining
)
1475 else if ((help
[i
] == '-' || help
[i
] == '/')
1476 && help
[i
+ 1] != ' '
1477 && i
> 0 && ISALPHA (help
[i
- 1]))
1482 printf (" %-*.*s %.*s\n", col_width
, item_width
, item
, len
, help
);
1484 while (help
[len
] == ' ')
1492 /* Data structure used to print list of valid option values. */
1494 class option_help_tuple
1497 option_help_tuple (int code
, vec
<const char *> values
):
1498 m_code (code
), m_values (values
)
1501 /* Code of an option. */
1504 /* List of possible values. */
1505 vec
<const char *> m_values
;
1508 /* Print help for a specific front-end, etc. */
1510 print_filtered_help (unsigned int include_flags
,
1511 unsigned int exclude_flags
,
1512 unsigned int any_flags
,
1513 unsigned int columns
,
1514 struct gcc_options
*opts
,
1515 unsigned int lang_mask
)
1520 bool displayed
= false;
1523 if (!opts
->x_help_printed
)
1524 opts
->x_help_printed
= XCNEWVAR (char, cl_options_count
);
1526 if (!opts
->x_help_enum_printed
)
1527 opts
->x_help_enum_printed
= XCNEWVAR (char, cl_enums_count
);
1529 auto_vec
<option_help_tuple
> help_tuples
;
1531 for (i
= 0; i
< cl_options_count
; i
++)
1533 const struct cl_option
*option
= cl_options
+ i
;
1538 if (include_flags
== 0
1539 || ((option
->flags
& include_flags
) != include_flags
))
1541 if ((option
->flags
& any_flags
) == 0)
1545 /* Skip unwanted switches. */
1546 if ((option
->flags
& exclude_flags
) != 0)
1549 /* The driver currently prints its own help text. */
1550 if ((option
->flags
& CL_DRIVER
) != 0
1551 && (option
->flags
& (((1U << cl_lang_count
) - 1)
1552 | CL_COMMON
| CL_TARGET
)) == 0)
1555 /* If an option contains a language specification,
1556 exclude it from common unless all languages are present. */
1557 if ((include_flags
& CL_COMMON
)
1558 && !(option
->flags
& CL_DRIVER
)
1559 && (option
->flags
& CL_LANG_ALL
)
1560 && (option
->flags
& CL_LANG_ALL
) != CL_LANG_ALL
)
1564 /* Skip switches that have already been printed. */
1565 if (opts
->x_help_printed
[i
])
1568 opts
->x_help_printed
[i
] = true;
1570 help
= option
->help
;
1573 if (exclude_flags
& CL_UNDOCUMENTED
)
1576 help
= undocumented_msg
;
1579 /* Get the translation. */
1582 if (option
->alias_target
< N_OPTS
1583 && cl_options
[option
->alias_target
].help
)
1585 const struct cl_option
*target
= cl_options
+ option
->alias_target
;
1586 if (option
->help
== NULL
)
1588 /* The option is undocumented but is an alias for an option that
1589 is documented. If the option has alias arguments, then its
1590 purpose is to provide certain arguments to the other option, so
1591 inform the reader of this. Otherwise, point the reader to the
1592 other option in preference to the former. */
1594 if (option
->alias_arg
)
1596 if (option
->neg_alias_arg
)
1597 snprintf (new_help
, sizeof new_help
,
1598 _("Same as %s%s (or, in negated form, %s%s)."),
1599 target
->opt_text
, option
->alias_arg
,
1600 target
->opt_text
, option
->neg_alias_arg
);
1602 snprintf (new_help
, sizeof new_help
,
1604 target
->opt_text
, option
->alias_arg
);
1607 snprintf (new_help
, sizeof new_help
,
1613 /* For documented options with aliases, mention the aliased
1614 option's name for reference. */
1615 snprintf (new_help
, sizeof new_help
,
1616 _("%s Same as %s."),
1617 help
, cl_options
[option
->alias_target
].opt_text
);
1623 if (option
->warn_message
)
1625 /* Mention that the use of the option will trigger a warning. */
1626 if (help
== new_help
)
1627 snprintf (new_help
+ strlen (new_help
),
1628 sizeof new_help
- strlen (new_help
),
1629 " %s", _(use_diagnosed_msg
));
1631 snprintf (new_help
, sizeof new_help
,
1632 "%s %s", help
, _(use_diagnosed_msg
));
1637 /* Find the gap between the name of the
1638 option and its descriptive text. */
1639 tab
= strchr (help
, '\t');
1648 opt
= option
->opt_text
;
1652 /* With the -Q option enabled we change the descriptive text associated
1653 with an option to be an indication of its current setting. */
1654 if (!opts
->x_quiet_flag
)
1656 void *flag_var
= option_flag_var (i
, opts
);
1658 if (len
< (LEFT_COLUMN
+ 2))
1659 strcpy (new_help
, "\t\t");
1661 strcpy (new_help
, "\t");
1663 /* Set to print whether the option is enabled or disabled,
1664 or, if it's an alias for another option, the name of
1665 the aliased option. */
1666 bool print_state
= false;
1668 if (flag_var
!= NULL
1669 && option
->var_type
!= CLVC_DEFER
)
1671 /* If OPTION is only available for a specific subset
1672 of languages other than this one, mention them. */
1673 bool avail_for_lang
= true;
1674 if (unsigned langset
= option
->flags
& CL_LANG_ALL
)
1676 if (!(langset
& lang_mask
))
1678 avail_for_lang
= false;
1679 strcat (new_help
, _("[available in "));
1680 for (unsigned i
= 0, n
= 0; (1U << i
) < CL_LANG_ALL
; ++i
)
1681 if (langset
& (1U << i
))
1684 strcat (new_help
, ", ");
1685 strcat (new_help
, lang_names
[i
]);
1687 strcat (new_help
, "]");
1690 if (!avail_for_lang
)
1691 ; /* Print nothing else if the option is not available
1692 in the current language. */
1693 else if (option
->flags
& CL_JOINED
)
1695 if (option
->var_type
== CLVC_STRING
)
1697 if (* (const char **) flag_var
!= NULL
)
1698 snprintf (new_help
+ strlen (new_help
),
1699 sizeof (new_help
) - strlen (new_help
),
1700 "%s", * (const char **) flag_var
);
1702 else if (option
->var_type
== CLVC_ENUM
)
1704 const struct cl_enum
*e
= &cl_enums
[option
->var_enum
];
1706 const char *arg
= NULL
;
1708 value
= e
->get (flag_var
);
1709 enum_value_to_arg (e
->values
, &arg
, value
, lang_mask
);
1711 arg
= _("[default]");
1712 snprintf (new_help
+ strlen (new_help
),
1713 sizeof (new_help
) - strlen (new_help
),
1718 if (option
->cl_host_wide_int
)
1719 sprintf (new_help
+ strlen (new_help
),
1720 _("%llu bytes"), (unsigned long long)
1721 *(unsigned HOST_WIDE_INT
*) flag_var
);
1723 sprintf (new_help
+ strlen (new_help
),
1724 "%i", * (int *) flag_var
);
1731 /* When there is no argument, print the option state only
1732 if the option takes no argument. */
1733 print_state
= !(option
->flags
& CL_JOINED
);
1737 if (option
->alias_target
< N_OPTS
1738 && option
->alias_target
!= OPT_SPECIAL_warn_removed
1739 && option
->alias_target
!= OPT_SPECIAL_ignore
1740 && option
->alias_target
!= OPT_SPECIAL_input_file
1741 && option
->alias_target
!= OPT_SPECIAL_program_name
1742 && option
->alias_target
!= OPT_SPECIAL_unknown
)
1744 const struct cl_option
*target
1745 = &cl_options
[option
->alias_target
];
1746 sprintf (new_help
+ strlen (new_help
), "%s%s",
1748 option
->alias_arg
? option
->alias_arg
: "");
1750 else if (option
->alias_target
== OPT_SPECIAL_ignore
)
1751 strcat (new_help
, ("[ignored]"));
1754 /* Print the state for an on/off option. */
1755 int ena
= option_enabled (i
, lang_mask
, opts
);
1757 strcat (new_help
, _("[enabled]"));
1759 strcat (new_help
, _("[disabled]"));
1766 if (option
->range_max
!= -1)
1769 snprintf (b
, sizeof (b
), "<%d,%d>", option
->range_min
,
1771 opt
= concat (opt
, b
, NULL
);
1775 wrap_help (help
, opt
, len
, columns
);
1778 if (option
->var_type
== CLVC_ENUM
1779 && opts
->x_help_enum_printed
[option
->var_enum
] != 2)
1780 opts
->x_help_enum_printed
[option
->var_enum
] = 1;
1783 vec
<const char *> option_values
1784 ; // sdcpp = targetm_common.get_valid_option_values (i, NULL);
1785 if (!option_values
.is_empty ())
1786 help_tuples
.safe_push (option_help_tuple (i
, option_values
));
1792 unsigned int langs
= include_flags
& CL_LANG_ALL
;
1795 printf (_(" No options with the desired characteristics were found\n"));
1800 /* PR 31349: Tell the user how to see all of the
1801 options supported by a specific front end. */
1802 for (i
= 0; (1U << i
) < CL_LANG_ALL
; i
++)
1803 if ((1U << i
) & langs
)
1804 printf (_(" None found. Use --help=%s to show *all* the options supported by the %s front-end.\n"),
1805 lang_names
[i
], lang_names
[i
]);
1809 else if (! displayed
)
1810 printf (_(" All options with the desired characteristics have already been displayed\n"));
1814 /* Print details of enumerated option arguments, if those
1815 enumerations have help text headings provided. If no help text
1816 is provided, presume that the possible values are listed in the
1817 help text for the relevant options. */
1818 for (i
= 0; i
< cl_enums_count
; i
++)
1820 unsigned int j
, pos
;
1822 if (opts
->x_help_enum_printed
[i
] != 1)
1824 if (cl_enums
[i
].help
== NULL
)
1826 printf (" %s\n ", _(cl_enums
[i
].help
));
1828 for (j
= 0; cl_enums
[i
].values
[j
].arg
!= NULL
; j
++)
1830 unsigned int len
= strlen (cl_enums
[i
].values
[j
].arg
);
1832 if (pos
> 4 && pos
+ 1 + len
<= columns
)
1834 printf (" %s", cl_enums
[i
].values
[j
].arg
);
1844 printf ("%s", cl_enums
[i
].values
[j
].arg
);
1849 opts
->x_help_enum_printed
[i
] = 2;
1852 for (unsigned i
= 0; i
< help_tuples
.length (); i
++)
1854 const struct cl_option
*option
= cl_options
+ help_tuples
[i
].m_code
;
1855 printf (_(" Known valid arguments for %s option:\n "),
1857 for (unsigned j
= 0; j
< help_tuples
[i
].m_values
.length (); j
++)
1858 printf (" %s", help_tuples
[i
].m_values
[j
]);
1863 /* Display help for a specified type of option.
1864 The options must have ALL of the INCLUDE_FLAGS set
1865 ANY of the flags in the ANY_FLAGS set
1866 and NONE of the EXCLUDE_FLAGS set. The current option state is in
1867 OPTS; LANG_MASK is used for interpreting enumerated option state. */
1869 print_specific_help (unsigned int include_flags
,
1870 unsigned int exclude_flags
,
1871 unsigned int any_flags
,
1872 struct gcc_options
*opts
,
1873 unsigned int lang_mask
)
1875 unsigned int all_langs_mask
= (1U << cl_lang_count
) - 1;
1876 const char * description
= NULL
;
1877 const char * descrip_extra
= "";
1881 /* Sanity check: Make sure that we do not have more
1882 languages than we have bits available to enumerate them. */
1883 gcc_assert ((1U << cl_lang_count
) <= CL_MIN_OPTION_CLASS
);
1885 /* If we have not done so already, obtain
1886 the desired maximum width of the output. */
1887 if (opts
->x_help_columns
== 0)
1889 opts
->x_help_columns
= get_terminal_width ();
1890 if (opts
->x_help_columns
== INT_MAX
)
1891 /* Use a reasonable default. */
1892 opts
->x_help_columns
= 80;
1895 /* Decide upon the title for the options that we are going to display. */
1896 for (i
= 0, flag
= 1; flag
<= CL_MAX_OPTION_CLASS
; flag
<<= 1, i
++)
1898 switch (flag
& include_flags
)
1905 description
= _("The following options are target specific");
1908 description
= _("The following options control compiler warning messages");
1910 case CL_OPTIMIZATION
:
1911 description
= _("The following options control optimizations");
1914 description
= _("The following options are language-independent");
1917 description
= _("The following options control parameters");
1920 if (i
>= cl_lang_count
)
1922 if (exclude_flags
& all_langs_mask
)
1923 description
= _("The following options are specific to just the language ");
1925 description
= _("The following options are supported by the language ");
1926 descrip_extra
= lang_names
[i
];
1931 if (description
== NULL
)
1935 if (include_flags
& CL_UNDOCUMENTED
)
1936 description
= _("The following options are not documented");
1937 else if (include_flags
& CL_SEPARATE
)
1938 description
= _("The following options take separate arguments");
1939 else if (include_flags
& CL_JOINED
)
1940 description
= _("The following options take joined arguments");
1943 internal_error ("unrecognized %<include_flags 0x%x%> passed "
1944 "to %<print_specific_help%>",
1951 if (any_flags
& all_langs_mask
)
1952 description
= _("The following options are language-related");
1954 description
= _("The following options are language-independent");
1958 printf ("%s%s:\n", description
, descrip_extra
);
1959 print_filtered_help (include_flags
, exclude_flags
, any_flags
,
1960 opts
->x_help_columns
, opts
, lang_mask
);
1963 /* Enable FDO-related flags. */
1966 enable_fdo_optimizations (struct gcc_options
*opts
,
1967 struct gcc_options
*opts_set
,
1970 SET_OPTION_IF_UNSET (opts
, opts_set
, flag_branch_probabilities
, value
);
1971 SET_OPTION_IF_UNSET (opts
, opts_set
, flag_profile_values
, value
);
1972 SET_OPTION_IF_UNSET (opts
, opts_set
, flag_unroll_loops
, value
);
1973 SET_OPTION_IF_UNSET (opts
, opts_set
, flag_peel_loops
, value
);
1974 SET_OPTION_IF_UNSET (opts
, opts_set
, flag_tracer
, value
);
1975 SET_OPTION_IF_UNSET (opts
, opts_set
, flag_value_profile_transformations
,
1977 SET_OPTION_IF_UNSET (opts
, opts_set
, flag_inline_functions
, value
);
1978 SET_OPTION_IF_UNSET (opts
, opts_set
, flag_ipa_cp
, value
);
1981 SET_OPTION_IF_UNSET (opts
, opts_set
, flag_ipa_cp_clone
, 1);
1982 SET_OPTION_IF_UNSET (opts
, opts_set
, flag_ipa_bit_cp
, 1);
1984 SET_OPTION_IF_UNSET (opts
, opts_set
, flag_predictive_commoning
, value
);
1985 SET_OPTION_IF_UNSET (opts
, opts_set
, flag_split_loops
, value
);
1986 SET_OPTION_IF_UNSET (opts
, opts_set
, flag_unswitch_loops
, value
);
1987 SET_OPTION_IF_UNSET (opts
, opts_set
, flag_gcse_after_reload
, value
);
1988 SET_OPTION_IF_UNSET (opts
, opts_set
, flag_tree_loop_vectorize
, value
);
1989 SET_OPTION_IF_UNSET (opts
, opts_set
, flag_tree_slp_vectorize
, value
);
1990 SET_OPTION_IF_UNSET (opts
, opts_set
, flag_version_loops_for_strides
, value
);
1991 SET_OPTION_IF_UNSET (opts
, opts_set
, flag_vect_cost_model
,
1992 VECT_COST_MODEL_DYNAMIC
);
1993 SET_OPTION_IF_UNSET (opts
, opts_set
, flag_tree_loop_distribute_patterns
,
1995 SET_OPTION_IF_UNSET (opts
, opts_set
, flag_loop_interchange
, value
);
1996 SET_OPTION_IF_UNSET (opts
, opts_set
, flag_unroll_jam
, value
);
1997 SET_OPTION_IF_UNSET (opts
, opts_set
, flag_tree_loop_distribution
, value
);
2000 /* -f{,no-}sanitize{,-recover}= suboptions. */
2001 const struct sanitizer_opts_s sanitizer_opts
[] =
2003 #define SANITIZER_OPT(name, flags, recover) \
2004 { #name, flags, sizeof #name - 1, recover }
2005 SANITIZER_OPT (address
, (SANITIZE_ADDRESS
| SANITIZE_USER_ADDRESS
), true),
2006 SANITIZER_OPT (hwaddress
, (SANITIZE_HWADDRESS
| SANITIZE_USER_HWADDRESS
),
2008 SANITIZER_OPT (kernel
-address
, (SANITIZE_ADDRESS
| SANITIZE_KERNEL_ADDRESS
),
2010 SANITIZER_OPT (kernel
-hwaddress
,
2011 (SANITIZE_HWADDRESS
| SANITIZE_KERNEL_HWADDRESS
),
2013 SANITIZER_OPT (pointer
-compare
, SANITIZE_POINTER_COMPARE
, true),
2014 SANITIZER_OPT (pointer
-subtract
, SANITIZE_POINTER_SUBTRACT
, true),
2015 SANITIZER_OPT (thread
, SANITIZE_THREAD
, false),
2016 SANITIZER_OPT (leak
, SANITIZE_LEAK
, false),
2017 SANITIZER_OPT (shift
, SANITIZE_SHIFT
, true),
2018 SANITIZER_OPT (shift
-base
, SANITIZE_SHIFT_BASE
, true),
2019 SANITIZER_OPT (shift
-exponent
, SANITIZE_SHIFT_EXPONENT
, true),
2020 SANITIZER_OPT (integer
-divide
-by
-zero
, SANITIZE_DIVIDE
, true),
2021 SANITIZER_OPT (undefined
, SANITIZE_UNDEFINED
, true),
2022 SANITIZER_OPT (unreachable
, SANITIZE_UNREACHABLE
, false),
2023 SANITIZER_OPT (vla
-bound
, SANITIZE_VLA
, true),
2024 SANITIZER_OPT (return, SANITIZE_RETURN
, false),
2025 SANITIZER_OPT (null
, SANITIZE_NULL
, true),
2026 SANITIZER_OPT (signed-integer
-overflow
, SANITIZE_SI_OVERFLOW
, true),
2027 SANITIZER_OPT (bool, SANITIZE_BOOL
, true),
2028 SANITIZER_OPT (enum, SANITIZE_ENUM
, true),
2029 SANITIZER_OPT (float-divide
-by
-zero
, SANITIZE_FLOAT_DIVIDE
, true),
2030 SANITIZER_OPT (float-cast
-overflow
, SANITIZE_FLOAT_CAST
, true),
2031 SANITIZER_OPT (bounds
, SANITIZE_BOUNDS
, true),
2032 SANITIZER_OPT (bounds
-strict
, SANITIZE_BOUNDS
| SANITIZE_BOUNDS_STRICT
, true),
2033 SANITIZER_OPT (alignment
, SANITIZE_ALIGNMENT
, true),
2034 SANITIZER_OPT (nonnull
-attribute
, SANITIZE_NONNULL_ATTRIBUTE
, true),
2035 SANITIZER_OPT (returns
-nonnull
-attribute
, SANITIZE_RETURNS_NONNULL_ATTRIBUTE
,
2037 SANITIZER_OPT (object
-size
, SANITIZE_OBJECT_SIZE
, true),
2038 SANITIZER_OPT (vptr
, SANITIZE_VPTR
, true),
2039 SANITIZER_OPT (pointer
-overflow
, SANITIZE_POINTER_OVERFLOW
, true),
2040 SANITIZER_OPT (builtin
, SANITIZE_BUILTIN
, true),
2041 SANITIZER_OPT (shadow
-call
-stack
, SANITIZE_SHADOW_CALL_STACK
, false),
2042 SANITIZER_OPT (all
, ~0U, true),
2043 #undef SANITIZER_OPT
2044 { NULL
, 0U, 0UL, false }
2047 /* -fzero-call-used-regs= suboptions. */
2048 const struct zero_call_used_regs_opts_s zero_call_used_regs_opts
[] =
2050 #define ZERO_CALL_USED_REGS_OPT(name, flags) \
2052 ZERO_CALL_USED_REGS_OPT (skip
, zero_regs_flags::SKIP
),
2053 ZERO_CALL_USED_REGS_OPT (used
-gpr
-arg
, zero_regs_flags::USED_GPR_ARG
),
2054 ZERO_CALL_USED_REGS_OPT (used
-gpr
, zero_regs_flags::USED_GPR
),
2055 ZERO_CALL_USED_REGS_OPT (used
-arg
, zero_regs_flags::USED_ARG
),
2056 ZERO_CALL_USED_REGS_OPT (used
, zero_regs_flags::USED
),
2057 ZERO_CALL_USED_REGS_OPT (all
-gpr
-arg
, zero_regs_flags::ALL_GPR_ARG
),
2058 ZERO_CALL_USED_REGS_OPT (all
-gpr
, zero_regs_flags::ALL_GPR
),
2059 ZERO_CALL_USED_REGS_OPT (all
-arg
, zero_regs_flags::ALL_ARG
),
2060 ZERO_CALL_USED_REGS_OPT (all
, zero_regs_flags::ALL
),
2061 #undef ZERO_CALL_USED_REGS_OPT
2065 /* A struct for describing a run of chars within a string. */
2067 class string_fragment
2070 string_fragment (const char *start
, size_t len
)
2071 : m_start (start
), m_len (len
) {}
2073 const char *m_start
;
2077 /* Specialization of edit_distance_traits for string_fragment,
2078 for use by get_closest_sanitizer_option. */
2081 struct edit_distance_traits
<const string_fragment
&>
2083 static size_t get_length (const string_fragment
&fragment
)
2085 return fragment
.m_len
;
2088 static const char *get_string (const string_fragment
&fragment
)
2090 return fragment
.m_start
;
2094 /* Given ARG, an unrecognized sanitizer option, return the best
2095 matching sanitizer option, or NULL if there isn't one.
2096 OPTS is array of candidate sanitizer options.
2097 CODE is OPT_fsanitize_ or OPT_fsanitize_recover_.
2098 VALUE is non-zero for the regular form of the option, zero
2099 for the "no-" form (e.g. "-fno-sanitize-recover="). */
2102 get_closest_sanitizer_option (const string_fragment
&arg
,
2103 const struct sanitizer_opts_s
*opts
,
2104 enum opt_code code
, int value
)
2106 best_match
<const string_fragment
&, const char*> bm (arg
);
2107 for (int i
= 0; opts
[i
].name
!= NULL
; ++i
)
2109 /* -fsanitize=all is not valid, so don't offer it. */
2110 if (code
== OPT_fsanitize_
2111 && opts
[i
].flag
== ~0U
2115 /* For -fsanitize-recover= (and not -fno-sanitize-recover=),
2116 don't offer the non-recoverable options. */
2117 if (code
== OPT_fsanitize_recover_
2118 && !opts
[i
].can_recover
2122 bm
.consider (opts
[i
].name
);
2124 return bm
.get_best_meaningful_candidate ();
2127 /* Parse comma separated sanitizer suboptions from P for option SCODE,
2128 adjust previous FLAGS and return new ones. If COMPLAIN is false,
2129 don't issue diagnostics. */
2132 parse_sanitizer_options (const char *p
, location_t loc
, int scode
,
2133 unsigned int flags
, int value
, bool complain
)
2135 enum opt_code code
= (enum opt_code
) scode
;
2141 const char *comma
= strchr (p
, ',');
2153 /* Check to see if the string matches an option class name. */
2154 for (i
= 0; sanitizer_opts
[i
].name
!= NULL
; ++i
)
2155 if (len
== sanitizer_opts
[i
].len
2156 && memcmp (p
, sanitizer_opts
[i
].name
, len
) == 0)
2158 /* Handle both -fsanitize and -fno-sanitize cases. */
2159 if (value
&& sanitizer_opts
[i
].flag
== ~0U)
2161 if (code
== OPT_fsanitize_
)
2164 error_at (loc
, "%<-fsanitize=all%> option is not valid");
2167 flags
|= ~(SANITIZE_THREAD
| SANITIZE_LEAK
2168 | SANITIZE_UNREACHABLE
| SANITIZE_RETURN
2169 | SANITIZE_SHADOW_CALL_STACK
);
2173 /* Do not enable -fsanitize-recover=unreachable and
2174 -fsanitize-recover=return if -fsanitize-recover=undefined
2176 if (code
== OPT_fsanitize_recover_
2177 && sanitizer_opts
[i
].flag
== SANITIZE_UNDEFINED
)
2178 flags
|= (SANITIZE_UNDEFINED
2179 & ~(SANITIZE_UNREACHABLE
| SANITIZE_RETURN
));
2181 flags
|= sanitizer_opts
[i
].flag
;
2184 flags
&= ~sanitizer_opts
[i
].flag
;
2189 if (! found
&& complain
)
2192 = get_closest_sanitizer_option (string_fragment (p
, len
),
2193 sanitizer_opts
, code
, value
);
2196 if (code
== OPT_fsanitize_recover_
)
2197 suffix
= "-recover";
2203 "unrecognized argument to %<-f%ssanitize%s=%> "
2204 "option: %q.*s; did you mean %qs?",
2206 suffix
, (int) len
, p
, hint
);
2209 "unrecognized argument to %<-f%ssanitize%s=%> option: "
2210 "%q.*s", value
? "" : "no-",
2211 suffix
, (int) len
, p
);
2221 /* Parse string values of no_sanitize attribute passed in VALUE.
2222 Values are separated with comma. */
2225 parse_no_sanitize_attribute (char *value
)
2227 unsigned int flags
= 0;
2229 char *q
= strtok (value
, ",");
2233 for (i
= 0; sanitizer_opts
[i
].name
!= NULL
; ++i
)
2234 if (strcmp (sanitizer_opts
[i
].name
, q
) == 0)
2236 flags
|= sanitizer_opts
[i
].flag
;
2237 if (sanitizer_opts
[i
].flag
== SANITIZE_UNDEFINED
)
2238 flags
|= SANITIZE_UNDEFINED_NONDEFAULT
;
2242 if (sanitizer_opts
[i
].name
== NULL
)
2243 warning (OPT_Wattributes
,
2244 "%qs attribute directive ignored", q
);
2246 q
= strtok (NULL
, ",");
2252 /* Parse -fzero-call-used-regs suboptions from ARG, return the FLAGS. */
2255 parse_zero_call_used_regs_options (const char *arg
)
2257 unsigned int flags
= 0;
2259 /* Check to see if the string matches a sub-option name. */
2260 for (unsigned int i
= 0; zero_call_used_regs_opts
[i
].name
!= NULL
; ++i
)
2261 if (strcmp (arg
, zero_call_used_regs_opts
[i
].name
) == 0)
2263 flags
= zero_call_used_regs_opts
[i
].flag
;
2268 error ("unrecognized argument to %<-fzero-call-used-regs=%>: %qs", arg
);
2273 /* Parse -falign-NAME format for a FLAG value. Return individual
2274 parsed integer values into RESULT_VALUES array. If REPORT_ERROR is
2275 set, print error message at LOC location. */
2278 parse_and_check_align_values (const char *flag
,
2280 auto_vec
<unsigned> &result_values
,
2284 char *str
= xstrdup (flag
);
2285 for (char *p
= strtok (str
, ":"); p
; p
= strtok (NULL
, ":"))
2288 int v
= strtol (p
, &end
, 10);
2289 if (*end
!= '\0' || v
< 0)
2292 error_at (loc
, "invalid arguments for %<-falign-%s%> option: %qs",
2298 result_values
.safe_push ((unsigned)v
);
2303 /* Check that we have a correct number of values. */
2304 if (result_values
.is_empty () || result_values
.length () > 4)
2307 error_at (loc
, "invalid number of arguments for %<-falign-%s%> "
2308 "option: %qs", name
, flag
);
2312 for (unsigned i
= 0; i
< result_values
.length (); i
++)
2313 if (result_values
[i
] > MAX_CODE_ALIGN_VALUE
)
2316 error_at (loc
, "%<-falign-%s%> is not between 0 and %d",
2317 name
, MAX_CODE_ALIGN_VALUE
);
2324 /* Check that alignment value FLAG for -falign-NAME is valid at a given
2325 location LOC. OPT_STR points to the stored -falign-NAME=argument and
2326 OPT_FLAG points to the associated -falign-NAME on/off flag. */
2329 check_alignment_argument (location_t loc
, const char *flag
, const char *name
,
2330 int *opt_flag
, const char **opt_str
)
2332 auto_vec
<unsigned> align_result
;
2333 parse_and_check_align_values (flag
, name
, align_result
, true, loc
);
2335 if (align_result
.length() >= 1 && align_result
[0] == 0)
2342 /* Parse argument of -fpatchable-function-entry option ARG and store
2343 corresponding values to PATCH_AREA_SIZE and PATCH_AREA_START.
2344 If REPORT_ERROR is set to true, generate error for a problematic
2345 option arguments. */
2348 parse_and_check_patch_area (const char *arg
, bool report_error
,
2349 HOST_WIDE_INT
*patch_area_size
,
2350 HOST_WIDE_INT
*patch_area_start
)
2352 *patch_area_size
= 0;
2353 *patch_area_start
= 0;
2358 char *patch_area_arg
= xstrdup (arg
);
2359 char *comma
= strchr (patch_area_arg
, ',');
2363 *patch_area_size
= integral_argument (patch_area_arg
);
2364 *patch_area_start
= integral_argument (comma
+ 1);
2367 *patch_area_size
= integral_argument (patch_area_arg
);
2369 if (*patch_area_size
< 0
2370 || *patch_area_size
> USHRT_MAX
2371 || *patch_area_start
< 0
2372 || *patch_area_start
> USHRT_MAX
2373 || *patch_area_size
< *patch_area_start
)
2375 error ("invalid arguments for %<-fpatchable-function-entry%>");
2377 free (patch_area_arg
);
2380 /* Print help when OPT__help_ is set. */
2383 print_help (struct gcc_options
*opts
, unsigned int lang_mask
,
2384 const char *help_option_argument
)
2386 const char *a
= help_option_argument
;
2387 unsigned int include_flags
= 0;
2388 /* Note - by default we include undocumented options when listing
2389 specific classes. If you only want to see documented options
2390 then add ",^undocumented" to the --help= option. E.g.:
2392 --help=target,^undocumented */
2393 unsigned int exclude_flags
= 0;
2395 if (lang_mask
== CL_DRIVER
)
2398 /* Walk along the argument string, parsing each word in turn.
2400 arg = [^]{word}[,{arg}]
2401 word = {optimizers|target|warnings|undocumented|
2402 params|common|<language>} */
2412 { "optimizers", CL_OPTIMIZATION
},
2413 { "target", CL_TARGET
},
2414 { "warnings", CL_WARNING
},
2415 { "undocumented", CL_UNDOCUMENTED
},
2416 { "params", CL_PARAMS
},
2417 { "joined", CL_JOINED
},
2418 { "separate", CL_SEPARATE
},
2419 { "common", CL_COMMON
},
2422 unsigned int *pflags
;
2424 unsigned int lang_flag
, specific_flag
;
2433 error ("missing argument to %qs", "--help=^");
2436 pflags
= &exclude_flags
;
2439 pflags
= &include_flags
;
2441 comma
= strchr (a
, ',');
2452 /* Check to see if the string matches an option class name. */
2453 for (i
= 0, specific_flag
= 0; specifics
[i
].string
!= NULL
; i
++)
2454 if (strncasecmp (a
, specifics
[i
].string
, len
) == 0)
2456 specific_flag
= specifics
[i
].flag
;
2460 /* Check to see if the string matches a language name.
2461 Note - we rely upon the alpha-sorted nature of the entries in
2462 the lang_names array, specifically that shorter names appear
2463 before their longer variants. (i.e. C before C++). That way
2464 when we are attempting to match --help=c for example we will
2465 match with C first and not C++. */
2466 for (i
= 0, lang_flag
= 0; i
< cl_lang_count
; i
++)
2467 if (strncasecmp (a
, lang_names
[i
], len
) == 0)
2469 lang_flag
= 1U << i
;
2473 if (specific_flag
!= 0)
2476 *pflags
|= specific_flag
;
2479 /* The option's argument matches both the start of a
2480 language name and the start of an option class name.
2481 We have a special case for when the user has
2482 specified "--help=c", but otherwise we have to issue
2484 if (strncasecmp (a
, "c", len
) == 0)
2485 *pflags
|= lang_flag
;
2488 "%<--help%> argument %q.*s is ambiguous, "
2489 "please be more specific",
2493 else if (lang_flag
!= 0)
2494 *pflags
|= lang_flag
;
2497 "unrecognized argument to %<--help=%> option: %q.*s",
2505 /* We started using PerFunction/Optimization for parameters and
2506 a warning. We should exclude these from optimization options. */
2507 if (include_flags
& CL_OPTIMIZATION
)
2508 exclude_flags
|= CL_WARNING
;
2509 if (!(include_flags
& CL_PARAMS
))
2510 exclude_flags
|= CL_PARAMS
;
2513 print_specific_help (include_flags
, exclude_flags
, 0, opts
,
2517 /* Handle target- and language-independent options. Return zero to
2518 generate an "unknown option" message. Only options that need
2519 extra handling need to be listed here; if you simply want
2520 DECODED->value assigned to a variable, it happens automatically. */
2523 common_handle_option (struct gcc_options
*opts
,
2524 struct gcc_options
*opts_set
,
2525 const struct cl_decoded_option
*decoded
,
2526 unsigned int lang_mask
, int kind ATTRIBUTE_UNUSED
,
2528 const struct cl_option_handlers
*handlers
,
2529 diagnostic_context
*dc
,
2530 void (*target_option_override_hook
) (void))
2532 size_t scode
= decoded
->opt_index
;
2533 const char *arg
= decoded
->arg
;
2534 HOST_WIDE_INT value
= decoded
->value
;
2535 enum opt_code code
= (enum opt_code
) scode
;
2537 gcc_assert (decoded
->canonical_option_num_elements
<= 2);
2543 unsigned int all_langs_mask
= (1U << cl_lang_count
) - 1;
2544 unsigned int undoc_mask
;
2547 if (lang_mask
== CL_DRIVER
)
2550 undoc_mask
= ((opts
->x_verbose_flag
| opts
->x_extra_warnings
)
2553 target_option_override_hook ();
2554 /* First display any single language specific options. */
2555 for (i
= 0; i
< cl_lang_count
; i
++)
2557 (1U << i
, (all_langs_mask
& (~ (1U << i
))) | undoc_mask
, 0, opts
,
2559 /* Next display any multi language specific options. */
2560 print_specific_help (0, undoc_mask
, all_langs_mask
, opts
, lang_mask
);
2561 /* Then display any remaining, non-language options. */
2562 for (i
= CL_MIN_OPTION_CLASS
; i
<= CL_MAX_OPTION_CLASS
; i
<<= 1)
2564 print_specific_help (i
, undoc_mask
, 0, opts
, lang_mask
);
2565 opts
->x_exit_after_options
= true;
2569 case OPT__target_help
:
2570 if (lang_mask
== CL_DRIVER
)
2573 target_option_override_hook ();
2574 print_specific_help (CL_TARGET
, 0, 0, opts
, lang_mask
);
2575 opts
->x_exit_after_options
= true;
2580 help_option_arguments
.safe_push (arg
);
2581 opts
->x_exit_after_options
= true;
2586 if (lang_mask
== CL_DRIVER
)
2589 opts
->x_exit_after_options
= true;
2592 case OPT__completion_
:
2595 case OPT_fsanitize_
:
2596 opts
->x_flag_sanitize
2597 = parse_sanitizer_options (arg
, loc
, code
,
2598 opts
->x_flag_sanitize
, value
, true);
2600 /* Kernel ASan implies normal ASan but does not yet support
2602 if (opts
->x_flag_sanitize
& SANITIZE_KERNEL_ADDRESS
)
2604 SET_OPTION_IF_UNSET (opts
, opts_set
,
2605 param_asan_instrumentation_with_call_threshold
,
2607 SET_OPTION_IF_UNSET (opts
, opts_set
, param_asan_globals
, 0);
2608 SET_OPTION_IF_UNSET (opts
, opts_set
, param_asan_stack
, 0);
2609 SET_OPTION_IF_UNSET (opts
, opts_set
, param_asan_protect_allocas
, 0);
2610 SET_OPTION_IF_UNSET (opts
, opts_set
, param_asan_use_after_return
, 0);
2612 if (opts
->x_flag_sanitize
& SANITIZE_KERNEL_HWADDRESS
)
2614 SET_OPTION_IF_UNSET (opts
, opts_set
,
2615 param_hwasan_instrument_stack
, 0);
2616 SET_OPTION_IF_UNSET (opts
, opts_set
,
2617 param_hwasan_random_frame_tag
, 0);
2618 SET_OPTION_IF_UNSET (opts
, opts_set
,
2619 param_hwasan_instrument_allocas
, 0);
2623 case OPT_fsanitize_recover_
:
2624 opts
->x_flag_sanitize_recover
2625 = parse_sanitizer_options (arg
, loc
, code
,
2626 opts
->x_flag_sanitize_recover
, value
, true);
2629 case OPT_fasan_shadow_offset_
:
2633 case OPT_fsanitize_address_use_after_scope
:
2634 opts
->x_flag_sanitize_address_use_after_scope
= value
;
2637 case OPT_fsanitize_recover
:
2639 opts
->x_flag_sanitize_recover
2640 |= (SANITIZE_UNDEFINED
| SANITIZE_UNDEFINED_NONDEFAULT
)
2641 & ~(SANITIZE_UNREACHABLE
| SANITIZE_RETURN
);
2643 opts
->x_flag_sanitize_recover
2644 &= ~(SANITIZE_UNDEFINED
| SANITIZE_UNDEFINED_NONDEFAULT
);
2652 /* Currently handled in a prescan. */
2655 case OPT_Wattributes_
:
2656 if (lang_mask
== CL_DRIVER
)
2661 error_at (loc
, "arguments ignored for %<-Wattributes=%>; use "
2662 "%<-Wno-attributes=%> instead");
2665 else if (arg
[strlen (arg
) - 1] == ',')
2667 error_at (loc
, "trailing %<,%> in arguments for "
2668 "%<-Wno-attributes=%>");
2672 add_comma_separated_to_vector (&opts
->x_flag_ignored_attributes
, arg
);
2676 dc
->warning_as_error_requested
= value
;
2680 if (lang_mask
== CL_DRIVER
)
2683 enable_warning_as_error (arg
, value
, lang_mask
, handlers
,
2684 opts
, opts_set
, loc
, dc
);
2687 case OPT_Wfatal_errors
:
2688 dc
->fatal_errors
= value
;
2691 case OPT_Wstack_usage_
:
2692 opts
->x_flag_stack_usage_info
= value
!= -1;
2695 case OPT_Wstrict_aliasing
:
2696 set_Wstrict_aliasing (opts
, value
);
2699 case OPT_Wstrict_overflow
:
2700 opts
->x_warn_strict_overflow
= (value
2701 ? (int) WARN_STRICT_OVERFLOW_CONDITIONAL
2705 case OPT_Wsystem_headers
:
2706 dc
->dc_warn_system_headers
= value
;
2710 opts
->x_flag_gen_aux_info
= 1;
2714 decode_d_option (arg
, opts
, loc
, dc
);
2717 case OPT_fcall_used_
:
2718 case OPT_fcall_saved_
:
2726 case OPT_fdebug_prefix_map_
:
2727 case OPT_ffile_prefix_map_
:
2728 case OPT_fprofile_prefix_map_
:
2732 case OPT_fcallgraph_info
:
2733 opts
->x_flag_callgraph_info
= CALLGRAPH_INFO_NAKED
;
2736 case OPT_fcallgraph_info_
:
2739 my_arg
= xstrdup (arg
);
2740 p
= strtok (my_arg
, ",");
2743 if (strcmp (p
, "su") == 0)
2745 opts
->x_flag_callgraph_info
|= CALLGRAPH_INFO_STACK_USAGE
;
2746 opts
->x_flag_stack_usage_info
= true;
2748 else if (strcmp (p
, "da") == 0)
2749 opts
->x_flag_callgraph_info
|= CALLGRAPH_INFO_DYNAMIC_ALLOC
;
2752 p
= strtok (NULL
, ",");
2758 case OPT_fdiagnostics_show_location_
:
2759 diagnostic_prefixing_rule (dc
) = (diagnostic_prefixing_rule_t
) value
;
2762 case OPT_fdiagnostics_show_caret
:
2763 dc
->show_caret
= value
;
2766 case OPT_fdiagnostics_show_labels
:
2767 dc
->show_labels_p
= value
;
2770 case OPT_fdiagnostics_show_line_numbers
:
2771 dc
->show_line_numbers_p
= value
;
2774 case OPT_fdiagnostics_color_
:
2775 diagnostic_color_init (dc
, value
);
2778 case OPT_fdiagnostics_urls_
:
2779 diagnostic_urls_init (dc
, value
);
2782 case OPT_fdiagnostics_format_
:
2783 diagnostic_output_format_init (dc
,
2784 (enum diagnostics_output_format
)value
);
2787 case OPT_fdiagnostics_parseable_fixits
:
2788 dc
->extra_output_kind
= (value
2789 ? EXTRA_DIAGNOSTIC_OUTPUT_fixits_v1
2790 : EXTRA_DIAGNOSTIC_OUTPUT_none
);
2793 case OPT_fdiagnostics_column_unit_
:
2794 dc
->column_unit
= (enum diagnostics_column_unit
)value
;
2797 case OPT_fdiagnostics_column_origin_
:
2798 dc
->column_origin
= value
;
2801 case OPT_fdiagnostics_escape_format_
:
2802 dc
->escape_format
= (enum diagnostics_escape_format
)value
;
2805 case OPT_fdiagnostics_show_cwe
:
2806 dc
->show_cwe
= value
;
2809 case OPT_fdiagnostics_path_format_
:
2810 dc
->path_format
= (enum diagnostic_path_format
)value
;
2813 case OPT_fdiagnostics_show_path_depths
:
2814 dc
->show_path_depths
= value
;
2817 case OPT_fdiagnostics_show_option
:
2818 dc
->show_option_requested
= value
;
2821 case OPT_fdiagnostics_minimum_margin_width_
:
2822 dc
->min_margin_width
= value
;
2829 case OPT_ffast_math
:
2830 set_fast_math_flags (opts
, value
);
2833 case OPT_funsafe_math_optimizations
:
2834 set_unsafe_math_optimizations_flags (opts
, value
);
2841 case OPT_finline_limit_
:
2842 SET_OPTION_IF_UNSET (opts
, opts_set
, param_max_inline_insns_single
,
2844 SET_OPTION_IF_UNSET (opts
, opts_set
, param_max_inline_insns_auto
,
2848 case OPT_finstrument_functions_exclude_function_list_
:
2849 add_comma_separated_to_vector
2850 (&opts
->x_flag_instrument_functions_exclude_functions
, arg
);
2853 case OPT_finstrument_functions_exclude_file_list_
:
2854 add_comma_separated_to_vector
2855 (&opts
->x_flag_instrument_functions_exclude_files
, arg
);
2858 case OPT_fmessage_length_
:
2859 pp_set_line_maximum_length (dc
->printer
, value
);
2860 diagnostic_set_caret_max_width (dc
, value
);
2864 case OPT_fopt_info_
:
2868 case OPT_foffload_options_
:
2872 case OPT_foffload_abi_
:
2873 #ifdef ACCEL_COMPILER
2874 /* Handled in the 'mkoffload's. */
2876 error_at (loc
, "%<-foffload-abi%> option can be specified only for "
2877 "offload compiler");
2881 case OPT_fpack_struct_
:
2882 if (value
<= 0 || (value
& (value
- 1)) || value
> 16)
2884 "structure alignment must be a small power of two, not %wu",
2887 opts
->x_initial_max_fld_align
= value
;
2891 case OPT_fplugin_arg_
:
2895 case OPT_fprofile_use_
:
2896 opts
->x_profile_data_prefix
= xstrdup (arg
);
2897 opts
->x_flag_profile_use
= true;
2899 /* No break here - do -fprofile-use processing. */
2901 case OPT_fprofile_use
:
2902 enable_fdo_optimizations (opts
, opts_set
, value
);
2903 SET_OPTION_IF_UNSET (opts
, opts_set
, flag_profile_reorder_functions
,
2905 /* Indirect call profiling should do all useful transformations
2906 speculative devirtualization does. */
2907 if (opts
->x_flag_value_profile_transformations
)
2908 SET_OPTION_IF_UNSET (opts
, opts_set
, flag_devirtualize_speculatively
,
2912 case OPT_fauto_profile_
:
2913 opts
->x_auto_profile_file
= xstrdup (arg
);
2914 opts
->x_flag_auto_profile
= true;
2916 /* No break here - do -fauto-profile processing. */
2918 case OPT_fauto_profile
:
2919 enable_fdo_optimizations (opts
, opts_set
, value
);
2920 SET_OPTION_IF_UNSET (opts
, opts_set
, flag_profile_correction
, value
);
2923 case OPT_fprofile_generate_
:
2924 opts
->x_profile_data_prefix
= xstrdup (arg
);
2926 /* No break here - do -fprofile-generate processing. */
2928 case OPT_fprofile_generate
:
2929 SET_OPTION_IF_UNSET (opts
, opts_set
, profile_arc_flag
, value
);
2930 SET_OPTION_IF_UNSET (opts
, opts_set
, flag_profile_values
, value
);
2931 SET_OPTION_IF_UNSET (opts
, opts_set
, flag_inline_functions
, value
);
2932 SET_OPTION_IF_UNSET (opts
, opts_set
, flag_ipa_bit_cp
, value
);
2935 case OPT_fprofile_info_section
:
2936 opts
->x_profile_info_section
= ".gcov_info";
2939 case OPT_fpatchable_function_entry_
:
2941 HOST_WIDE_INT patch_area_size
, patch_area_start
;
2942 parse_and_check_patch_area (arg
, true, &patch_area_size
,
2947 case OPT_ftree_vectorize
:
2948 /* Automatically sets -ftree-loop-vectorize and
2949 -ftree-slp-vectorize. Nothing more to do here. */
2951 case OPT_fzero_call_used_regs_
:
2952 opts
->x_flag_zero_call_used_regs
2953 = parse_zero_call_used_regs_options (arg
);
2956 case OPT_fshow_column
:
2957 dc
->show_column
= value
;
2960 case OPT_frandom_seed
:
2961 /* The real switch is -fno-random-seed. */
2967 case OPT_frandom_seed_
:
2971 case OPT_fsched_verbose_
:
2972 #ifdef INSN_SCHEDULING
2973 /* Handled with Var in common.opt. */
2979 case OPT_fsched_stalled_insns_
:
2980 opts
->x_flag_sched_stalled_insns
= value
;
2981 if (opts
->x_flag_sched_stalled_insns
== 0)
2982 opts
->x_flag_sched_stalled_insns
= -1;
2985 case OPT_fsched_stalled_insns_dep_
:
2986 opts
->x_flag_sched_stalled_insns_dep
= value
;
2989 case OPT_fstack_check_
:
2990 if (!strcmp (arg
, "no"))
2991 opts
->x_flag_stack_check
= NO_STACK_CHECK
;
2992 else if (!strcmp (arg
, "generic"))
2993 /* This is the old stack checking method. */
2994 opts
->x_flag_stack_check
= STACK_CHECK_BUILTIN
2995 ? FULL_BUILTIN_STACK_CHECK
2996 : GENERIC_STACK_CHECK
;
2997 else if (!strcmp (arg
, "specific"))
2998 /* This is the new stack checking method. */
2999 opts
->x_flag_stack_check
= STACK_CHECK_BUILTIN
3000 ? FULL_BUILTIN_STACK_CHECK
3001 : STACK_CHECK_STATIC_BUILTIN
3002 ? STATIC_BUILTIN_STACK_CHECK
3003 : GENERIC_STACK_CHECK
;
3005 warning_at (loc
, 0, "unknown stack check parameter %qs", arg
);
3008 case OPT_fstack_limit
:
3009 /* The real switch is -fno-stack-limit. */
3015 case OPT_fstack_limit_register_
:
3016 case OPT_fstack_limit_symbol_
:
3020 case OPT_fstack_usage
:
3021 opts
->x_flag_stack_usage
= value
;
3022 opts
->x_flag_stack_usage_info
= value
!= 0;
3026 set_debug_level (NO_DEBUG
, DEFAULT_GDB_EXTENSIONS
, arg
, opts
, opts_set
,
3031 set_debug_level (BTF_DEBUG
, false, arg
, opts
, opts_set
, loc
);
3032 /* set the debug level to level 2, but if already at level 3,
3034 if (opts
->x_debug_info_level
< DINFO_LEVEL_NORMAL
)
3035 opts
->x_debug_info_level
= DINFO_LEVEL_NORMAL
;
3039 set_debug_level (CTF_DEBUG
, false, arg
, opts
, opts_set
, loc
);
3040 /* CTF generation feeds off DWARF dies. For optimal CTF, switch debug
3041 info level to 2. If off or at level 1, set it to level 2, but if
3042 already at level 3, don't lower it. */
3043 if (opts
->x_debug_info_level
< DINFO_LEVEL_NORMAL
3044 && opts
->x_ctf_debug_info_level
> CTFINFO_LEVEL_NONE
)
3045 opts
->x_debug_info_level
= DINFO_LEVEL_NORMAL
;
3049 if (arg
&& strlen (arg
) != 0)
3051 error_at (loc
, "%<-gdwarf%s%> is ambiguous; "
3052 "use %<-gdwarf-%s%> for DWARF version "
3053 "or %<-gdwarf%> %<-g%s%> for debug level", arg
, arg
, arg
);
3057 value
= opts
->x_dwarf_version
;
3061 if (value
< 2 || value
> 5)
3062 error_at (loc
, "dwarf version %wu is not supported", value
);
3064 opts
->x_dwarf_version
= value
;
3065 set_debug_level (DWARF2_DEBUG
, false, "", opts
, opts_set
, loc
);
3069 set_debug_level (NO_DEBUG
, 2, arg
, opts
, opts_set
, loc
);
3074 set_debug_level (DBX_DEBUG
, code
== OPT_gstabs_
, arg
, opts
, opts_set
,
3079 set_debug_level (VMS_DEBUG
, false, arg
, opts
, opts_set
, loc
);
3084 set_debug_level (XCOFF_DEBUG
, code
== OPT_gxcoff_
, arg
, opts
, opts_set
,
3090 /* Handled completely via specs. */
3093 case OPT_pedantic_errors
:
3094 dc
->pedantic_errors
= 1;
3095 control_warning_option (OPT_Wpedantic
, DK_ERROR
, NULL
, value
,
3097 handlers
, opts
, opts_set
,
3102 opts
->x_flag_lto
= value
? "" : NULL
;
3106 if (strcmp (arg
, "none") != 0
3107 && strcmp (arg
, "jobserver") != 0
3108 && strcmp (arg
, "auto") != 0
3111 "unrecognized argument to %<-flto=%> option: %qs", arg
);
3115 dc
->dc_inhibit_warnings
= true;
3118 case OPT_fmax_errors_
:
3119 dc
->max_errors
= value
;
3122 case OPT_fuse_ld_bfd
:
3123 case OPT_fuse_ld_gold
:
3124 case OPT_fuse_ld_lld
:
3125 case OPT_fuse_ld_mold
:
3126 case OPT_fuse_linker_plugin
:
3127 /* No-op. Used by the driver and passed to us because it starts with f.*/
3132 opts
->x_flag_trapv
= 0;
3137 opts
->x_flag_wrapv
= 0;
3140 case OPT_fstrict_overflow
:
3141 opts
->x_flag_wrapv
= !value
;
3142 opts
->x_flag_wrapv_pointer
= !value
;
3144 opts
->x_flag_trapv
= 0;
3148 opts
->x_flag_ipa_icf_functions
= value
;
3149 opts
->x_flag_ipa_icf_variables
= value
;
3152 case OPT_falign_loops_
:
3153 check_alignment_argument (loc
, arg
, "loops",
3154 &opts
->x_flag_align_loops
,
3155 &opts
->x_str_align_loops
);
3158 case OPT_falign_jumps_
:
3159 check_alignment_argument (loc
, arg
, "jumps",
3160 &opts
->x_flag_align_jumps
,
3161 &opts
->x_str_align_jumps
);
3164 case OPT_falign_labels_
:
3165 check_alignment_argument (loc
, arg
, "labels",
3166 &opts
->x_flag_align_labels
,
3167 &opts
->x_str_align_labels
);
3170 case OPT_falign_functions_
:
3171 check_alignment_argument (loc
, arg
, "functions",
3172 &opts
->x_flag_align_functions
,
3173 &opts
->x_str_align_functions
);
3177 /* It is documented that we silently ignore silly values. */
3178 if (value
>= 1 && value
<= 100)
3179 dc
->tabstop
= value
;
3182 case OPT_freport_bug
:
3183 dc
->report_bug
= value
;
3187 /* If the flag was handled in a standard way, assume the lack of
3188 processing here is intentional. */
3189 gcc_assert (option_flag_var (scode
, opts
));
3193 common_handle_option_auto (opts
, opts_set
, decoded
, lang_mask
, kind
,
3198 /* Used to set the level of strict aliasing warnings in OPTS,
3199 when no level is specified (i.e., when -Wstrict-aliasing, and not
3200 -Wstrict-aliasing=level was given).
3201 ONOFF is assumed to take value 1 when -Wstrict-aliasing is specified,
3202 and 0 otherwise. After calling this function, wstrict_aliasing will be
3203 set to the default value of -Wstrict_aliasing=level, currently 3. */
3205 set_Wstrict_aliasing (struct gcc_options
*opts
, int onoff
)
3207 gcc_assert (onoff
== 0 || onoff
== 1);
3209 opts
->x_warn_strict_aliasing
= 3;
3211 opts
->x_warn_strict_aliasing
= 0;
3214 /* The following routines are useful in setting all the flags that
3215 -ffast-math and -fno-fast-math imply. */
3217 set_fast_math_flags (struct gcc_options
*opts
, int set
)
3219 if (!opts
->frontend_set_flag_unsafe_math_optimizations
)
3221 opts
->x_flag_unsafe_math_optimizations
= set
;
3222 set_unsafe_math_optimizations_flags (opts
, set
);
3224 if (!opts
->frontend_set_flag_finite_math_only
)
3225 opts
->x_flag_finite_math_only
= set
;
3226 if (!opts
->frontend_set_flag_errno_math
)
3227 opts
->x_flag_errno_math
= !set
;
3230 if (opts
->frontend_set_flag_excess_precision
== EXCESS_PRECISION_DEFAULT
)
3231 opts
->x_flag_excess_precision
3232 = set
? EXCESS_PRECISION_FAST
: EXCESS_PRECISION_DEFAULT
;
3233 if (!opts
->frontend_set_flag_signaling_nans
)
3234 opts
->x_flag_signaling_nans
= 0;
3235 if (!opts
->frontend_set_flag_rounding_math
)
3236 opts
->x_flag_rounding_math
= 0;
3237 if (!opts
->frontend_set_flag_cx_limited_range
)
3238 opts
->x_flag_cx_limited_range
= 1;
3242 /* When -funsafe-math-optimizations is set the following
3243 flags are set as well. */
3245 set_unsafe_math_optimizations_flags (struct gcc_options
*opts
, int set
)
3247 if (!opts
->frontend_set_flag_trapping_math
)
3248 opts
->x_flag_trapping_math
= !set
;
3249 if (!opts
->frontend_set_flag_signed_zeros
)
3250 opts
->x_flag_signed_zeros
= !set
;
3251 if (!opts
->frontend_set_flag_associative_math
)
3252 opts
->x_flag_associative_math
= set
;
3253 if (!opts
->frontend_set_flag_reciprocal_math
)
3254 opts
->x_flag_reciprocal_math
= set
;
3257 /* Return true iff flags in OPTS are set as if -ffast-math. */
3259 fast_math_flags_set_p (const struct gcc_options
*opts
)
3261 return (!opts
->x_flag_trapping_math
3262 && opts
->x_flag_unsafe_math_optimizations
3263 && opts
->x_flag_finite_math_only
3264 && !opts
->x_flag_signed_zeros
3265 && !opts
->x_flag_errno_math
3266 && opts
->x_flag_excess_precision
== EXCESS_PRECISION_FAST
);
3269 /* Return true iff flags are set as if -ffast-math but using the flags stored
3270 in the struct cl_optimization structure. */
3272 fast_math_flags_struct_set_p (struct cl_optimization
*opt
)
3274 return (!opt
->x_flag_trapping_math
3275 && opt
->x_flag_unsafe_math_optimizations
3276 && opt
->x_flag_finite_math_only
3277 && !opt
->x_flag_signed_zeros
3278 && !opt
->x_flag_errno_math
);
3281 /* Handle a debug output -g switch for options OPTS
3282 (OPTS_SET->x_write_symbols storing whether a debug format was passed
3283 explicitly), location LOC. EXTENDED is true or false to support
3284 extended output (2 is special and means "-ggdb" was given). */
3286 set_debug_level (uint32_t dinfo
, int extended
, const char *arg
,
3287 struct gcc_options
*opts
, struct gcc_options
*opts_set
,
3290 opts
->x_use_gnu_debug_info_extensions
= extended
;
3292 if (dinfo
== NO_DEBUG
)
3294 if (opts
->x_write_symbols
== NO_DEBUG
)
3296 opts
->x_write_symbols
= PREFERRED_DEBUGGING_TYPE
;
3300 #if defined DWARF2_DEBUGGING_INFO || defined DWARF2_LINENO_DEBUGGING_INFO
3301 if (opts
->x_write_symbols
& CTF_DEBUG
)
3302 opts
->x_write_symbols
|= DWARF2_DEBUG
;
3304 opts
->x_write_symbols
= DWARF2_DEBUG
;
3305 #elif defined DBX_DEBUGGING_INFO
3306 opts
->x_write_symbols
= DBX_DEBUG
;
3310 if (opts
->x_write_symbols
== NO_DEBUG
)
3311 warning_at (loc
, 0, "target system does not support debug output");
3313 else if ((opts
->x_write_symbols
& CTF_DEBUG
)
3314 || (opts
->x_write_symbols
& BTF_DEBUG
))
3316 opts
->x_write_symbols
|= DWARF2_DEBUG
;
3317 opts_set
->x_write_symbols
|= DWARF2_DEBUG
;
3322 /* Make and retain the choice if both CTF and DWARF debug info are to
3324 if (((dinfo
== DWARF2_DEBUG
) || (dinfo
== CTF_DEBUG
))
3325 && ((opts
->x_write_symbols
== (DWARF2_DEBUG
|CTF_DEBUG
))
3326 || (opts
->x_write_symbols
== DWARF2_DEBUG
)
3327 || (opts
->x_write_symbols
== CTF_DEBUG
)))
3329 opts
->x_write_symbols
|= dinfo
;
3330 opts_set
->x_write_symbols
|= dinfo
;
3332 /* However, CTF and BTF are not allowed together at this time. */
3333 else if (((dinfo
== DWARF2_DEBUG
) || (dinfo
== BTF_DEBUG
))
3334 && ((opts
->x_write_symbols
== (DWARF2_DEBUG
|BTF_DEBUG
))
3335 || (opts
->x_write_symbols
== DWARF2_DEBUG
)
3336 || (opts
->x_write_symbols
== BTF_DEBUG
)))
3338 opts
->x_write_symbols
|= dinfo
;
3339 opts_set
->x_write_symbols
|= dinfo
;
3343 /* Does it conflict with an already selected debug format? */
3344 if (opts_set
->x_write_symbols
!= NO_DEBUG
3345 && opts
->x_write_symbols
!= NO_DEBUG
3346 && dinfo
!= opts
->x_write_symbols
)
3348 gcc_assert (debug_set_count (dinfo
) <= 1);
3349 error_at (loc
, "debug format %qs conflicts with prior selection",
3350 debug_type_names
[debug_set_to_format (dinfo
)]);
3352 opts
->x_write_symbols
= dinfo
;
3353 opts_set
->x_write_symbols
= dinfo
;
3357 if (dinfo
!= BTF_DEBUG
)
3359 /* A debug flag without a level defaults to level 2.
3360 If off or at level 1, set it to level 2, but if already
3361 at level 3, don't lower it. */
3364 if (dinfo
== CTF_DEBUG
)
3365 opts
->x_ctf_debug_info_level
= CTFINFO_LEVEL_NORMAL
;
3366 else if (opts
->x_debug_info_level
< DINFO_LEVEL_NORMAL
)
3367 opts
->x_debug_info_level
= DINFO_LEVEL_NORMAL
;
3371 int argval
= integral_argument (arg
);
3373 error_at (loc
, "unrecognized debug output level %qs", arg
);
3374 else if (argval
> 3)
3375 error_at (loc
, "debug output level %qs is too high", arg
);
3378 if (dinfo
== CTF_DEBUG
)
3379 opts
->x_ctf_debug_info_level
3380 = (enum ctf_debug_info_levels
) argval
;
3382 opts
->x_debug_info_level
= (enum debug_info_levels
) argval
;
3386 else if (*arg
!= '\0')
3387 error_at (loc
, "unrecognized btf debug output level %qs", arg
);
3390 /* Arrange to dump core on error for diagnostic context DC. (The
3391 regular error message is still printed first, except in the case of
3395 setup_core_dumping (diagnostic_context
*dc
)
3398 signal (SIGABRT
, SIG_DFL
);
3400 #if defined(HAVE_SETRLIMIT)
3403 if (getrlimit (RLIMIT_CORE
, &rlim
) != 0)
3404 fatal_error (input_location
, "getting core file size maximum limit: %m");
3405 rlim
.rlim_cur
= rlim
.rlim_max
;
3406 if (setrlimit (RLIMIT_CORE
, &rlim
) != 0)
3407 fatal_error (input_location
,
3408 "setting core file size limit to maximum: %m");
3411 diagnostic_abort_on_error (dc
);
3414 /* Parse a -d<ARG> command line switch for OPTS, location LOC,
3415 diagnostic context DC. */
3418 decode_d_option (const char *arg
, struct gcc_options
*opts
,
3419 location_t loc
, diagnostic_context
*dc
)
3427 opts
->x_flag_debug_asm
= 1;
3430 opts
->x_flag_print_asm_name
= 1;
3433 opts
->x_flag_dump_rtl_in_asm
= 1;
3434 opts
->x_flag_print_asm_name
= 1;
3437 opts
->x_rtl_dump_and_exit
= 1;
3439 case 'D': /* These are handled by the preprocessor. */
3446 setup_core_dumping (dc
);
3449 opts
->x_flag_dump_all_passed
= true;
3453 warning_at (loc
, 0, "unrecognized gcc debugging option: %c", c
);
3458 /* Enable (or disable if VALUE is 0) a warning option ARG (language
3459 mask LANG_MASK, option handlers HANDLERS) as an error for option
3460 structures OPTS and OPTS_SET, diagnostic context DC (possibly
3461 NULL), location LOC. This is used by -Werror=. */
3464 enable_warning_as_error (const char *arg
, int value
, unsigned int lang_mask
,
3465 const struct cl_option_handlers
*handlers
,
3466 struct gcc_options
*opts
,
3467 struct gcc_options
*opts_set
,
3468 location_t loc
, diagnostic_context
*dc
)
3473 new_option
= XNEWVEC (char, strlen (arg
) + 2);
3474 new_option
[0] = 'W';
3475 strcpy (new_option
+ 1, arg
);
3476 option_index
= find_opt (new_option
, lang_mask
);
3477 if (option_index
== OPT_SPECIAL_unknown
)
3479 // sdcpp option_proposer op;
3480 const char *hint
= 0; // sdcpp op.suggest_option (new_option);
3482 error_at (loc
, "%<-W%serror=%s%>: no option %<-%s%>;"
3483 " did you mean %<-%s%>?", value
? "" : "no-",
3484 arg
, new_option
, hint
);
3486 error_at (loc
, "%<-W%serror=%s%>: no option %<-%s%>",
3487 value
? "" : "no-", arg
, new_option
);
3489 else if (!(cl_options
[option_index
].flags
& CL_WARNING
))
3490 error_at (loc
, "%<-Werror=%s%>: %<-%s%> is not an option that "
3491 "controls warnings", arg
, new_option
);
3494 const diagnostic_t kind
= value
? DK_ERROR
: DK_WARNING
;
3495 const char *arg
= NULL
;
3497 if (cl_options
[option_index
].flags
& CL_JOINED
)
3498 arg
= new_option
+ cl_options
[option_index
].opt_len
;
3499 control_warning_option (option_index
, (int) kind
, arg
, value
,
3501 handlers
, opts
, opts_set
, dc
);
3506 /* Return malloced memory for the name of the option OPTION_INDEX
3507 which enabled a diagnostic (context CONTEXT), originally of type
3508 ORIG_DIAG_KIND but possibly converted to DIAG_KIND by options such
3512 option_name (diagnostic_context
*context
, int option_index
,
3513 diagnostic_t orig_diag_kind
, diagnostic_t diag_kind
)
3517 /* A warning classified as an error. */
3518 if ((orig_diag_kind
== DK_WARNING
|| orig_diag_kind
== DK_PEDWARN
)
3519 && diag_kind
== DK_ERROR
)
3520 return concat (cl_options
[OPT_Werror_
].opt_text
,
3521 /* Skip over "-W". */
3522 cl_options
[option_index
].opt_text
+ 2,
3524 /* A warning with option. */
3526 return xstrdup (cl_options
[option_index
].opt_text
);
3528 /* A warning without option classified as an error. */
3529 else if ((orig_diag_kind
== DK_WARNING
|| orig_diag_kind
== DK_PEDWARN
3530 || diag_kind
== DK_WARNING
)
3531 && context
->warning_as_error_requested
)
3532 return xstrdup (cl_options
[OPT_Werror
].opt_text
);
3537 /* Get the page within the documentation for this option. */
3540 get_option_html_page (int option_index
)
3542 const cl_option
*cl_opt
= &cl_options
[option_index
];
3544 /* Analyzer options are on their own page. */
3545 if (strstr (cl_opt
->opt_text
, "analyzer-"))
3546 return "gcc/Static-Analyzer-Options.html";
3548 /* Handle -flto= option. */
3549 if (strstr (cl_opt
->opt_text
, "flto"))
3550 return "gcc/Optimize-Options.html";
3553 if ((cl_opt
->flags
& CL_Fortran
) != 0
3554 /* If it is option common to both C/C++ and Fortran, it is documented
3555 in gcc/ rather than gfortran/ docs. */
3556 && (cl_opt
->flags
& CL_C
) == 0
3558 && (cl_opt
->flags
& CL_CXX
) == 0
3561 return "gfortran/Error-and-Warning-Options.html";
3564 return "gcc/Warning-Options.html";
3567 /* Return malloced memory for a URL describing the option OPTION_INDEX
3568 which enabled a diagnostic (context CONTEXT). */
3571 get_option_url (diagnostic_context
*, int option_index
)
3574 return concat (/* DOCUMENTATION_ROOT_URL should be supplied via -D by
3575 the Makefile (see --with-documentation-root-url), and
3576 should have a trailing slash. */
3577 DOCUMENTATION_ROOT_URL
,
3579 /* get_option_html_page will return something like
3580 "gcc/Warning-Options.html". */
3581 get_option_html_page (option_index
),
3583 /* Expect an anchor of the form "index-Wfoo" e.g.
3584 <a name="index-Wformat"></a>, and thus an id within
3585 the URL of "#index-Wformat". */
3586 "#index", cl_options
[option_index
].opt_text
,
3592 /* Return a heap allocated producer with command line options. */
3595 gen_command_line_string (cl_decoded_option
*options
,
3596 unsigned int options_count
)
3598 auto_vec
<const char *> switches
;
3599 char *options_string
, *tail
;
3603 for (unsigned i
= 0; i
< options_count
; i
++)
3604 switch (options
[i
].opt_index
)
3609 case OPT_dumpbase_ext
:
3619 case OPT_SPECIAL_unknown
:
3620 case OPT_SPECIAL_ignore
:
3621 case OPT_SPECIAL_warn_removed
:
3622 case OPT_SPECIAL_program_name
:
3623 case OPT_SPECIAL_input_file
:
3624 case OPT_grecord_gcc_switches
:
3625 case OPT_frecord_gcc_switches
:
3626 case OPT__output_pch_
:
3627 case OPT_fdiagnostics_show_location_
:
3628 case OPT_fdiagnostics_show_option
:
3629 case OPT_fdiagnostics_show_caret
:
3630 case OPT_fdiagnostics_show_labels
:
3631 case OPT_fdiagnostics_show_line_numbers
:
3632 case OPT_fdiagnostics_color_
:
3633 case OPT_fdiagnostics_format_
:
3634 case OPT_fverbose_asm
:
3638 case OPT_nostdinc__
:
3639 case OPT_fpreprocessed
:
3640 // case OPT_fltrans_output_list_:
3641 // case OPT_fresolution_:
3642 case OPT_fdebug_prefix_map_
:
3643 case OPT_fmacro_prefix_map_
:
3644 case OPT_ffile_prefix_map_
:
3645 case OPT_fprofile_prefix_map_
:
3646 case OPT_fcompare_debug
:
3648 case OPT_fchecking_
:
3653 const char *lto_canonical
= "-flto";
3654 switches
.safe_push (lto_canonical
);
3655 len
+= strlen (lto_canonical
) + 1;
3659 if (cl_options
[options
[i
].opt_index
].flags
3660 & CL_NO_DWARF_RECORD
)
3662 gcc_checking_assert (options
[i
].canonical_option
[0][0] == '-');
3663 switch (options
[i
].canonical_option
[0][1])
3670 if (strncmp (options
[i
].canonical_option
[0] + 2,
3677 switches
.safe_push (options
[i
].orig_option_with_args_text
);
3678 len
+= strlen (options
[i
].orig_option_with_args_text
) + 1;
3682 options_string
= XNEWVEC (char, len
+ 1);
3683 tail
= options_string
;
3686 FOR_EACH_VEC_ELT (switches
, i
, p
)
3689 memcpy (tail
, p
, len
);
3691 if (i
!= switches
.length () - 1)
3699 return options_string
;
3702 /* Return a heap allocated producer string including command line options. */
3705 gen_producer_string (const char *language_string
, cl_decoded_option
*options
,
3706 unsigned int options_count
)
3708 char *cmdline
= gen_command_line_string (options
, options_count
);
3709 char *combined
= concat (language_string
, " ", version_string
, " ",
3717 namespace selftest
{
3719 /* Verify that get_option_html_page works as expected. */
3722 test_get_option_html_page ()
3724 ASSERT_STREQ (get_option_html_page (OPT_Wcpp
), "gcc/Warning-Options.html");
3725 ASSERT_STREQ (get_option_html_page (OPT_Wanalyzer_double_free
),
3726 "gcc/Static-Analyzer-Options.html");
3728 ASSERT_STREQ (get_option_html_page (OPT_Wline_truncation
),
3729 "gfortran/Error-and-Warning-Options.html");
3733 /* Verify EnumSet and EnumBitSet requirements. */
3738 for (unsigned i
= 0; i
< cl_options_count
; ++i
)
3739 if (cl_options
[i
].var_type
== CLVC_ENUM
3740 && cl_options
[i
].var_value
!= CLEV_NORMAL
)
3742 const struct cl_enum
*e
= &cl_enums
[cl_options
[i
].var_enum
];
3743 unsigned HOST_WIDE_INT used_sets
= 0;
3744 unsigned HOST_WIDE_INT mask
= 0;
3745 unsigned highest_set
= 0;
3746 for (unsigned j
= 0; e
->values
[j
].arg
; ++j
)
3748 unsigned set
= e
->values
[j
].flags
>> CL_ENUM_SET_SHIFT
;
3749 if (cl_options
[i
].var_value
== CLEV_BITSET
)
3751 /* For EnumBitSet Set shouldn't be used and Value should
3752 be a power of two. */
3753 ASSERT_TRUE (set
== 0);
3754 ASSERT_TRUE (pow2p_hwi (e
->values
[j
].value
));
3757 /* Test that enumerators referenced in EnumSet have all
3758 Set(n) on them within the valid range. */
3759 ASSERT_TRUE (set
>= 1 && set
<= HOST_BITS_PER_WIDE_INT
);
3760 highest_set
= MAX (set
, highest_set
);
3761 used_sets
|= HOST_WIDE_INT_1U
<< (set
- 1);
3763 if (cl_options
[i
].var_value
== CLEV_BITSET
)
3765 /* If there is just one set, no point to using EnumSet. */
3766 ASSERT_TRUE (highest_set
>= 2);
3767 /* Test that there are no gaps in between the sets. */
3768 if (highest_set
== HOST_BITS_PER_WIDE_INT
)
3769 ASSERT_TRUE (used_sets
== HOST_WIDE_INT_M1U
);
3771 ASSERT_TRUE (used_sets
== (HOST_WIDE_INT_1U
<< highest_set
) - 1);
3772 for (unsigned int j
= 1; j
<= highest_set
; ++j
)
3774 unsigned HOST_WIDE_INT this_mask
= 0;
3775 for (unsigned k
= 0; e
->values
[k
].arg
; ++k
)
3777 unsigned set
= e
->values
[j
].flags
>> CL_ENUM_SET_SHIFT
;
3779 this_mask
|= e
->values
[j
].value
;
3781 ASSERT_TRUE ((mask
& this_mask
) == 0);
3787 /* Run all of the selftests within this file. */
3792 test_get_option_html_page ();
3796 } // namespace selftest
3798 #endif /* #if CHECKING_P */