struct / union in initializer, RFE #901.
[sdcc.git] / sdcc / support / cpp / gcc / opts.cc
blob6e397f6535eda221ab909621b7ddc5091edb5054
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
10 version.
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 for more details.
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING3. If not see
19 <http://www.gnu.org/licenses/>. */
22 #include "config.h"
23 #include "system.h"
24 #include "intl.h"
25 #include "coretypes.h"
26 #include "opts.h"
27 #include "tm.h"
28 #include "flags.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"
36 #include "version.h"
37 #include "selftest.h"
39 #define untested() { fprintf (stderr, "@@#\n@@@:%s:%d:%s\n", __FILE__, __LINE__, __func__); }
41 // sdcc hack?
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
47 debug_info_type. */
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
55 debug_info_type. */
57 static uint32_t debug_type_masks[] =
59 NO_DEBUG, DBX_DEBUG, DWARF2_DEBUG, XCOFF_DEBUG, VMS_DEBUG,
60 CTF_DEBUG, BTF_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. */
71 enum debug_info_type
72 debug_set_to_format (uint32_t debug_info_set)
74 int idx = 0;
75 enum debug_info_type dinfo_type = DINFO_TYPE_NONE;
76 /* Find first set bit. */
77 if (debug_info_set)
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);
85 return dinfo_type;
88 /* Get the number of debug formats enabled for output. */
90 unsigned int
91 debug_set_count (uint32_t w_symbols)
93 unsigned int count = 0;
94 while (w_symbols)
96 ++ count;
97 w_symbols &= ~ (w_symbols & - w_symbols);
99 return count;
102 /* Get the names of the debug formats enabled for output. */
104 const char *
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]);
119 num_set_df--;
120 if (num_set_df)
121 strcat (df_set_names, " ");
122 else
123 break;
125 else if (!w_symbols)
127 /* No debug formats enabled. */
128 gcc_assert (i == DINFO_TYPE_NONE);
129 strcat (df_set_names, debug_type_names[i]);
130 break;
133 return df_set_names;
136 /* Return TRUE iff BTF debug info is enabled. */
138 bool
139 btf_debuginfo_p ()
141 return (write_symbols & BTF_DEBUG);
144 /* Return TRUE iff BTF with CO-RE debug info is enabled. */
146 bool
147 btf_with_core_debuginfo_p ()
149 return (write_symbols & BTF_WITH_CORE_DEBUG);
152 /* Return TRUE iff CTF debug info is enabled. */
154 bool
155 ctf_debuginfo_p ()
157 return (write_symbols & CTF_DEBUG);
160 /* Return TRUE iff dwarf2 debug info is enabled. */
162 bool
163 dwarf_debuginfo_p ()
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)
184 void
185 set_struct_debug_option (struct gcc_options *opts, location_t loc,
186 const char *spec)
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;
199 /* What usage? */
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))
209 gen = 0;
210 else if (MATCH (gen_lbl, spec))
211 ord = 0;
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;
222 else
223 error_at (loc,
224 "argument %qs to %<-femit-struct-debug-detailed%> "
225 "not recognized",
226 spec);
228 /* Effect the specification. */
229 if (usage == DINFO_USAGE_NUM_ENUMS)
231 if (ord)
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;
237 if (gen)
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;
244 else
246 if (ord)
247 opts->x_debug_struct_ordinary[usage] = files;
248 if (gen)
249 opts->x_debug_struct_generic[usage] = files;
252 if (*spec == ',')
253 set_struct_debug_option (opts, loc, spec+1);
254 else
256 /* No more -femit-struct-debug-detailed specifications.
257 Do final checks. */
258 if (*spec != '\0')
259 error_at (loc,
260 "argument %qs to %<-femit-struct-debug-detailed%> unknown",
261 spec);
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])
266 error_at (loc,
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".) */
278 void
279 strip_off_ending (char *name, int len)
281 int i;
282 for (i = 2; i < 5 && len > i; i++)
284 if (name[len - i] == '.')
286 name[len - i] = '\0';
287 break;
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;
298 const char *dot = 0;
299 const char *p = path;
300 char c = *p;
301 while (c)
303 if (IS_DIR_SEPARATOR (c))
305 base = p + 1;
306 dot = 0;
308 else if (c == '.')
309 dot = p;
310 c = *++p;
312 if (!dot)
313 dot = p;
314 *base_out = base;
315 return dot - base;
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,
327 location_t loc);
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,
332 int set);
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,
338 location_t loc,
339 diagnostic_context *dc);
341 /* Handle a back-end option; arguments and return value as for
342 handle_option. */
344 #if 0 // sdcpp
345 bool
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,
350 location_t loc,
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);
358 #endif // sdcpp
360 /* Add comma-separated strings to a char_p vector. */
362 static void
363 add_comma_separated_to_vector (void **pvec, const char *arg)
365 char *tmp;
366 char *r;
367 char *w;
368 char *token_start;
369 vec<char_p> *v = (vec<char_p> *) *pvec;
371 vec_check_alloc (v, 1);
373 /* We never free this string. */
374 tmp = xstrdup (arg);
376 r = tmp;
377 w = tmp;
378 token_start = tmp;
380 while (*r != '\0')
382 if (*r == ',')
384 *w++ = '\0';
385 ++r;
386 v->safe_push (token_start);
387 token_start = w;
389 if (*r == '\\' && r[1] == ',')
391 *w++ = ',';
392 r += 2;
394 else
395 *w++ = *r++;
398 *w = '\0';
399 if (*token_start != '\0')
400 v->safe_push (token_start);
402 *pvec = v;
405 /* Initialize opts_obstack. */
407 void
408 init_opts_obstack (void)
410 gcc_obstack_init (&opts_obstack);
413 /* Initialize OPTS and OPTS_SET before using them in parsing options. */
415 void
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;
424 if (opts_set)
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;
433 #if 0 // sdcpp
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);
443 #endif // sdcpp
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. */
451 #if 0 // sdcpp
452 static void
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,
459 location_t loc,
460 diagnostic_context *dc)
462 const struct cl_option *option = &cl_options[default_opt->opt_index];
463 bool enabled;
465 if (size)
466 gcc_assert (level == 2);
467 if (fast)
468 gcc_assert (level == 3);
469 if (debug)
470 gcc_assert (level == 1);
472 switch (default_opt->levels)
474 case OPT_LEVELS_ALL:
475 enabled = true;
476 break;
478 case OPT_LEVELS_0_ONLY:
479 enabled = (level == 0);
480 break;
482 case OPT_LEVELS_1_PLUS:
483 enabled = (level >= 1);
484 break;
486 case OPT_LEVELS_1_PLUS_SPEED_ONLY:
487 enabled = (level >= 1 && !size && !debug);
488 break;
490 case OPT_LEVELS_1_PLUS_NOT_DEBUG:
491 enabled = (level >= 1 && !debug);
492 break;
494 case OPT_LEVELS_2_PLUS:
495 enabled = (level >= 2);
496 break;
498 case OPT_LEVELS_2_PLUS_SPEED_ONLY:
499 enabled = (level >= 2 && !size && !debug);
500 break;
502 case OPT_LEVELS_3_PLUS:
503 enabled = (level >= 3);
504 break;
506 case OPT_LEVELS_3_PLUS_AND_SIZE:
507 enabled = (level >= 3 || size);
508 break;
510 case OPT_LEVELS_SIZE:
511 enabled = size;
512 break;
514 case OPT_LEVELS_FAST:
515 enabled = fast;
516 break;
518 case OPT_LEVELS_NONE:
519 default:
520 gcc_unreachable ();
523 if (enabled)
524 handle_generated_option (opts, opts_set, default_opt->opt_index,
525 default_opt->arg, default_opt->value,
526 lang_mask, DK_UNSPECIFIED, loc,
527 handlers, true, dc);
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,
534 handlers, true, dc);
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. */
542 static void
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,
549 location_t loc,
550 diagnostic_context *dc)
552 size_t i;
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);
559 #endif // sdcpp
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
564 in sync. */
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 },
600 #if DELAY_SLOTS
601 { OPT_LEVELS_1_PLUS_NOT_DEBUG, OPT_fdelayed_branch, NULL, 1 },
602 #endif
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 },
643 #endif
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 },
668 #endif
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 }
702 #if 0 //sdcpp
703 /* Default the options in OPTS and OPTS_SET based on the optimization
704 settings in DECODED_OPTIONS and DECODED_OPTIONS_COUNT. */
705 void
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,
710 location_t loc,
711 unsigned int lang_mask,
712 const struct cl_option_handlers *handlers,
713 diagnostic_context *dc)
715 unsigned int i;
716 int opt2;
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)
726 case OPT_O:
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;
734 else
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%>");
740 else
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;
750 break;
752 case OPT_Os:
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;
759 break;
761 case OPT_Oz:
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;
768 break;
770 case OPT_Ofast:
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;
776 break;
778 case OPT_Og:
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;
784 break;
786 case OPT_fopenacc:
787 if (opt->value)
788 openacc_mode = true;
789 break;
791 default:
792 /* Ignore other options in this prescan. */
793 break;
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);
805 if (openacc_mode)
806 SET_OPTION_IF_UNSET (opts, opts_set, flag_ipa_pta, true);
808 /* Track fields in field-sensitive alias analysis. */
809 if (opt2)
810 SET_OPTION_IF_UNSET (opts, opts_set, param_max_fields_for_field_sensitive,
811 100);
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);
829 #endif
831 /* Control IPA optimizations based on different live patching LEVEL. */
832 static void
833 control_options_for_live_patching (struct gcc_options *opts,
834 struct gcc_options *opts_set,
835 enum live_patching_level level,
836 location_t loc)
838 gcc_assert (level > LIVE_PATCHING_NONE);
840 switch (level)
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);
847 else
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);
853 else
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);
859 else
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);
865 else
866 opts->x_flag_ipa_cp = 0;
868 /* FALLTHROUGH. */
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);
876 else
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);
886 else
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);
892 else
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);
898 else
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);
904 else
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);
910 else
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);
916 else
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);
922 else
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);
928 else
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);
934 else
935 opts->x_flag_ipa_pure_const = 0;
937 if (opts_set->x_flag_ipa_modref && opts->x_flag_ipa_modref)
938 error_at (loc,
939 "%<-fipa-modref%> is incompatible with %qs",
940 LIVE_PATCHING_OPTION);
941 else
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);
951 else
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);
959 else
960 opts->x_flag_ipa_stack_alignment = 0;
961 break;
962 default:
963 gcc_unreachable ();
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. */
974 const char *
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
988 command line. */
989 if ((sanitizer_opts[i].flag & opts->x_flag_sanitize)
990 != sanitizer_opts[i].flag)
991 continue;
992 if ((sanitizer_opts[i].flag & flags) != flags)
993 continue;
994 return sanitizer_opts[i].name;
996 return NULL;
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
1006 set these flags. */
1007 static void
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);
1018 error_at (loc,
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
1026 combinations. */
1027 void
1028 finish_options (struct gcc_options *opts, struct gcc_options *opts_set,
1029 location_t loc)
1031 if (opts->x_dump_base_name
1032 && ! opts->x_dump_base_name_prefixed)
1034 const char *sep = opts->x_dump_base_name;
1036 for (; *sep; sep++)
1037 if (IS_DIR_SEPARATOR (*sep))
1038 break;
1040 if (*sep)
1041 /* If dump_base_path contains subdirectories, don't prepend
1042 anything. */;
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
1053 section-anchors. */
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 "
1058 "is disabled");
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 "
1062 "is disabled");
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"
1091 " is disabled");
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
1098 default value. */
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;
1105 else
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)
1144 #ifdef ENABLE_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
1149 errors later. */
1150 opts->x_flag_whole_program = 0;
1151 #else
1152 error_at (loc, "LTO support has not been enabled in this configuration");
1153 #endif
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 "
1161 "linker plugin");
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,"
1169 " disabling");
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)
1208 error_at (loc,
1209 "%<-fsanitize=pointer-compare%> must be combined with "
1210 "%<-fsanitize=address%> or %<-fsanitize=kernel-address%>");
1211 if (opts->x_flag_sanitize & SANITIZE_POINTER_SUBTRACT)
1212 error_at (loc,
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,
1222 SANITIZE_THREAD);
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
1252 enabled. */
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,
1256 true);
1258 /* Force -fstack-reuse=none in case -fsanitize-address-use-after-scope
1259 is enabled. */
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)
1264 error_at (loc,
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,
1290 loc);
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);
1319 if (flag_gtoggle)
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;
1330 else
1331 debug_info_level = DINFO_LEVEL_NONE;
1334 if (!OPTION_SET_P (debug_nonbind_markers_p))
1335 debug_nonbind_markers_p
1336 = (optimize
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))
1364 warning_at (loc, 0,
1365 "var-tracking-assignments changes selective scheduling");
1367 if (flag_syntax_only)
1369 write_symbols = NO_DEBUG;
1370 profile_flag = 0;
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,
1383 location_t loc)
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)
1399 inform (loc,
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
1407 optimization. */
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)
1415 inform (loc,
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)
1433 inform (loc,
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. */
1447 static void
1448 wrap_help (const char *help,
1449 const char *item,
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);
1461 if (room > columns)
1462 room = 0;
1463 len = remaining;
1465 if (room < len)
1467 unsigned int i;
1469 for (i = 0; help[i]; i++)
1471 if (i >= room && len != remaining)
1472 break;
1473 if (help[i] == ' ')
1474 len = i;
1475 else if ((help[i] == '-' || help[i] == '/')
1476 && help[i + 1] != ' '
1477 && i > 0 && ISALPHA (help[i - 1]))
1478 len = i + 1;
1482 printf (" %-*.*s %.*s\n", col_width, item_width, item, len, help);
1483 item_width = 0;
1484 while (help[len] == ' ')
1485 len++;
1486 help += len;
1487 remaining -= len;
1489 while (remaining);
1492 /* Data structure used to print list of valid option values. */
1494 class option_help_tuple
1496 public:
1497 option_help_tuple (int code, vec<const char *> values):
1498 m_code (code), m_values (values)
1501 /* Code of an option. */
1502 int m_code;
1504 /* List of possible values. */
1505 vec<const char *> m_values;
1508 /* Print help for a specific front-end, etc. */
1509 static void
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)
1517 unsigned int i;
1518 const char *help;
1519 bool found = false;
1520 bool displayed = false;
1521 char new_help[256];
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;
1534 unsigned int len;
1535 const char *opt;
1536 const char *tab;
1538 if (include_flags == 0
1539 || ((option->flags & include_flags) != include_flags))
1541 if ((option->flags & any_flags) == 0)
1542 continue;
1545 /* Skip unwanted switches. */
1546 if ((option->flags & exclude_flags) != 0)
1547 continue;
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)
1553 continue;
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)
1561 continue;
1563 found = true;
1564 /* Skip switches that have already been printed. */
1565 if (opts->x_help_printed[i])
1566 continue;
1568 opts->x_help_printed[i] = true;
1570 help = option->help;
1571 if (help == NULL)
1573 if (exclude_flags & CL_UNDOCUMENTED)
1574 continue;
1576 help = undocumented_msg;
1579 /* Get the translation. */
1580 help = _(help);
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);
1601 else
1602 snprintf (new_help, sizeof new_help,
1603 _("Same as %s%s."),
1604 target->opt_text, option->alias_arg);
1606 else
1607 snprintf (new_help, sizeof new_help,
1608 _("Same as %s."),
1609 target->opt_text);
1611 else
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);
1620 help = new_help;
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));
1630 else
1631 snprintf (new_help, sizeof new_help,
1632 "%s %s", help, _(use_diagnosed_msg));
1634 help = new_help;
1637 /* Find the gap between the name of the
1638 option and its descriptive text. */
1639 tab = strchr (help, '\t');
1640 if (tab)
1642 len = tab - help;
1643 opt = help;
1644 help = tab + 1;
1646 else
1648 opt = option->opt_text;
1649 len = strlen (opt);
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");
1660 else
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))
1683 if (n++)
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];
1705 int value;
1706 const char *arg = NULL;
1708 value = e->get (flag_var);
1709 enum_value_to_arg (e->values, &arg, value, lang_mask);
1710 if (arg == NULL)
1711 arg = _("[default]");
1712 snprintf (new_help + strlen (new_help),
1713 sizeof (new_help) - strlen (new_help),
1714 "%s", arg);
1716 else
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);
1722 else
1723 sprintf (new_help + strlen (new_help),
1724 "%i", * (int *) flag_var);
1727 else
1728 print_state = true;
1730 else
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);
1735 if (print_state)
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",
1747 target->opt_text,
1748 option->alias_arg ? option->alias_arg : "");
1750 else if (option->alias_target == OPT_SPECIAL_ignore)
1751 strcat (new_help, ("[ignored]"));
1752 else
1754 /* Print the state for an on/off option. */
1755 int ena = option_enabled (i, lang_mask, opts);
1756 if (ena > 0)
1757 strcat (new_help, _("[enabled]"));
1758 else if (ena == 0)
1759 strcat (new_help, _("[disabled]"));
1763 help = new_help;
1766 if (option->range_max != -1)
1768 char b[128];
1769 snprintf (b, sizeof (b), "<%d,%d>", option->range_min,
1770 option->range_max);
1771 opt = concat (opt, b, NULL);
1772 len += strlen (b);
1775 wrap_help (help, opt, len, columns);
1776 displayed = true;
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;
1781 else
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));
1790 if (! found)
1792 unsigned int langs = include_flags & CL_LANG_ALL;
1794 if (langs == 0)
1795 printf (_(" No options with the desired characteristics were found\n"));
1796 else
1798 unsigned int i;
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"));
1812 putchar ('\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)
1823 continue;
1824 if (cl_enums[i].help == NULL)
1825 continue;
1826 printf (" %s\n ", _(cl_enums[i].help));
1827 pos = 4;
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);
1835 pos += 1 + len;
1837 else
1839 if (pos > 4)
1841 printf ("\n ");
1842 pos = 4;
1844 printf ("%s", cl_enums[i].values[j].arg);
1845 pos += len;
1848 printf ("\n\n");
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 "),
1856 option->opt_text);
1857 for (unsigned j = 0; j < help_tuples[i].m_values.length (); j++)
1858 printf (" %s", help_tuples[i].m_values[j]);
1859 printf ("\n\n");
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. */
1868 static void
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 = "";
1878 size_t i;
1879 unsigned int flag;
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)
1900 case 0:
1901 case CL_DRIVER:
1902 break;
1904 case CL_TARGET:
1905 description = _("The following options are target specific");
1906 break;
1907 case CL_WARNING:
1908 description = _("The following options control compiler warning messages");
1909 break;
1910 case CL_OPTIMIZATION:
1911 description = _("The following options control optimizations");
1912 break;
1913 case CL_COMMON:
1914 description = _("The following options are language-independent");
1915 break;
1916 case CL_PARAMS:
1917 description = _("The following options control parameters");
1918 break;
1919 default:
1920 if (i >= cl_lang_count)
1921 break;
1922 if (exclude_flags & all_langs_mask)
1923 description = _("The following options are specific to just the language ");
1924 else
1925 description = _("The following options are supported by the language ");
1926 descrip_extra = lang_names [i];
1927 break;
1931 if (description == NULL)
1933 if (any_flags == 0)
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");
1941 else
1943 internal_error ("unrecognized %<include_flags 0x%x%> passed "
1944 "to %<print_specific_help%>",
1945 include_flags);
1946 return;
1949 else
1951 if (any_flags & all_langs_mask)
1952 description = _("The following options are language-related");
1953 else
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. */
1965 static void
1966 enable_fdo_optimizations (struct gcc_options *opts,
1967 struct gcc_options *opts_set,
1968 int value)
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,
1976 value);
1977 SET_OPTION_IF_UNSET (opts, opts_set, flag_inline_functions, value);
1978 SET_OPTION_IF_UNSET (opts, opts_set, flag_ipa_cp, value);
1979 if (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,
1994 value);
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),
2007 true),
2008 SANITIZER_OPT (kernel-address, (SANITIZE_ADDRESS | SANITIZE_KERNEL_ADDRESS),
2009 true),
2010 SANITIZER_OPT (kernel-hwaddress,
2011 (SANITIZE_HWADDRESS | SANITIZE_KERNEL_HWADDRESS),
2012 true),
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,
2036 true),
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) \
2051 { #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
2062 {NULL, 0U}
2065 /* A struct for describing a run of chars within a string. */
2067 class string_fragment
2069 public:
2070 string_fragment (const char *start, size_t len)
2071 : m_start (start), m_len (len) {}
2073 const char *m_start;
2074 size_t m_len;
2077 /* Specialization of edit_distance_traits for string_fragment,
2078 for use by get_closest_sanitizer_option. */
2080 template <>
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="). */
2101 static const char *
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
2112 && value)
2113 continue;
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
2119 && value)
2120 continue;
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. */
2131 unsigned int
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;
2137 while (*p != 0)
2139 size_t len, i;
2140 bool found = false;
2141 const char *comma = strchr (p, ',');
2143 if (comma == NULL)
2144 len = strlen (p);
2145 else
2146 len = comma - p;
2147 if (len == 0)
2149 p = comma + 1;
2150 continue;
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_)
2163 if (complain)
2164 error_at (loc, "%<-fsanitize=all%> option is not valid");
2166 else
2167 flags |= ~(SANITIZE_THREAD | SANITIZE_LEAK
2168 | SANITIZE_UNREACHABLE | SANITIZE_RETURN
2169 | SANITIZE_SHADOW_CALL_STACK);
2171 else if (value)
2173 /* Do not enable -fsanitize-recover=unreachable and
2174 -fsanitize-recover=return if -fsanitize-recover=undefined
2175 is selected. */
2176 if (code == OPT_fsanitize_recover_
2177 && sanitizer_opts[i].flag == SANITIZE_UNDEFINED)
2178 flags |= (SANITIZE_UNDEFINED
2179 & ~(SANITIZE_UNREACHABLE | SANITIZE_RETURN));
2180 else
2181 flags |= sanitizer_opts[i].flag;
2183 else
2184 flags &= ~sanitizer_opts[i].flag;
2185 found = true;
2186 break;
2189 if (! found && complain)
2191 const char *hint
2192 = get_closest_sanitizer_option (string_fragment (p, len),
2193 sanitizer_opts, code, value);
2195 const char *suffix;
2196 if (code == OPT_fsanitize_recover_)
2197 suffix = "-recover";
2198 else
2199 suffix = "";
2201 if (hint)
2202 error_at (loc,
2203 "unrecognized argument to %<-f%ssanitize%s=%> "
2204 "option: %q.*s; did you mean %qs?",
2205 value ? "" : "no-",
2206 suffix, (int) len, p, hint);
2207 else
2208 error_at (loc,
2209 "unrecognized argument to %<-f%ssanitize%s=%> option: "
2210 "%q.*s", value ? "" : "no-",
2211 suffix, (int) len, p);
2214 if (comma == NULL)
2215 break;
2216 p = comma + 1;
2218 return flags;
2221 /* Parse string values of no_sanitize attribute passed in VALUE.
2222 Values are separated with comma. */
2224 unsigned int
2225 parse_no_sanitize_attribute (char *value)
2227 unsigned int flags = 0;
2228 unsigned int i;
2229 char *q = strtok (value, ",");
2231 while (q != NULL)
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;
2239 break;
2242 if (sanitizer_opts[i].name == NULL)
2243 warning (OPT_Wattributes,
2244 "%qs attribute directive ignored", q);
2246 q = strtok (NULL, ",");
2249 return flags;
2252 /* Parse -fzero-call-used-regs suboptions from ARG, return the FLAGS. */
2254 unsigned int
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;
2264 break;
2267 if (!flags)
2268 error ("unrecognized argument to %<-fzero-call-used-regs=%>: %qs", arg);
2270 return flags;
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. */
2277 bool
2278 parse_and_check_align_values (const char *flag,
2279 const char *name,
2280 auto_vec<unsigned> &result_values,
2281 bool report_error,
2282 location_t loc)
2284 char *str = xstrdup (flag);
2285 for (char *p = strtok (str, ":"); p; p = strtok (NULL, ":"))
2287 char *end;
2288 int v = strtol (p, &end, 10);
2289 if (*end != '\0' || v < 0)
2291 if (report_error)
2292 error_at (loc, "invalid arguments for %<-falign-%s%> option: %qs",
2293 name, flag);
2295 return false;
2298 result_values.safe_push ((unsigned)v);
2301 free (str);
2303 /* Check that we have a correct number of values. */
2304 if (result_values.is_empty () || result_values.length () > 4)
2306 if (report_error)
2307 error_at (loc, "invalid number of arguments for %<-falign-%s%> "
2308 "option: %qs", name, flag);
2309 return false;
2312 for (unsigned i = 0; i < result_values.length (); i++)
2313 if (result_values[i] > MAX_CODE_ALIGN_VALUE)
2315 if (report_error)
2316 error_at (loc, "%<-falign-%s%> is not between 0 and %d",
2317 name, MAX_CODE_ALIGN_VALUE);
2318 return false;
2321 return true;
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. */
2328 static void
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)
2337 *opt_flag = 1;
2338 *opt_str = NULL;
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. */
2347 void
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;
2355 if (arg == NULL)
2356 return;
2358 char *patch_area_arg = xstrdup (arg);
2359 char *comma = strchr (patch_area_arg, ',');
2360 if (comma)
2362 *comma = '\0';
2363 *patch_area_size = integral_argument (patch_area_arg);
2364 *patch_area_start = integral_argument (comma + 1);
2366 else
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)
2374 if (report_error)
2375 error ("invalid arguments for %<-fpatchable-function-entry%>");
2377 free (patch_area_arg);
2380 /* Print help when OPT__help_ is set. */
2382 void
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)
2396 return;
2398 /* Walk along the argument string, parsing each word in turn.
2399 The format is:
2400 arg = [^]{word}[,{arg}]
2401 word = {optimizers|target|warnings|undocumented|
2402 params|common|<language>} */
2403 while (*a != 0)
2405 static const struct
2407 const char *string;
2408 unsigned int flag;
2410 specifics[] =
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 },
2420 { NULL, 0 }
2422 unsigned int *pflags;
2423 const char *comma;
2424 unsigned int lang_flag, specific_flag;
2425 unsigned int len;
2426 unsigned int i;
2428 if (*a == '^')
2430 ++a;
2431 if (*a == '\0')
2433 error ("missing argument to %qs", "--help=^");
2434 break;
2436 pflags = &exclude_flags;
2438 else
2439 pflags = &include_flags;
2441 comma = strchr (a, ',');
2442 if (comma == NULL)
2443 len = strlen (a);
2444 else
2445 len = comma - a;
2446 if (len == 0)
2448 a = comma + 1;
2449 continue;
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;
2457 break;
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;
2470 break;
2473 if (specific_flag != 0)
2475 if (lang_flag == 0)
2476 *pflags |= specific_flag;
2477 else
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
2483 a warning. */
2484 if (strncasecmp (a, "c", len) == 0)
2485 *pflags |= lang_flag;
2486 else
2487 warning (0,
2488 "%<--help%> argument %q.*s is ambiguous, "
2489 "please be more specific",
2490 len, a);
2493 else if (lang_flag != 0)
2494 *pflags |= lang_flag;
2495 else
2496 warning (0,
2497 "unrecognized argument to %<--help=%> option: %q.*s",
2498 len, a);
2500 if (comma == NULL)
2501 break;
2502 a = comma + 1;
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;
2512 if (include_flags)
2513 print_specific_help (include_flags, exclude_flags, 0, opts,
2514 lang_mask);
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. */
2522 bool
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,
2527 location_t loc,
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);
2539 switch (code)
2541 case OPT__help:
2543 unsigned int all_langs_mask = (1U << cl_lang_count) - 1;
2544 unsigned int undoc_mask;
2545 unsigned int i;
2547 if (lang_mask == CL_DRIVER)
2548 break;
2550 undoc_mask = ((opts->x_verbose_flag | opts->x_extra_warnings)
2552 : CL_UNDOCUMENTED);
2553 target_option_override_hook ();
2554 /* First display any single language specific options. */
2555 for (i = 0; i < cl_lang_count; i++)
2556 print_specific_help
2557 (1U << i, (all_langs_mask & (~ (1U << i))) | undoc_mask, 0, opts,
2558 lang_mask);
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)
2563 if (i != CL_DRIVER)
2564 print_specific_help (i, undoc_mask, 0, opts, lang_mask);
2565 opts->x_exit_after_options = true;
2566 break;
2569 case OPT__target_help:
2570 if (lang_mask == CL_DRIVER)
2571 break;
2573 target_option_override_hook ();
2574 print_specific_help (CL_TARGET, 0, 0, opts, lang_mask);
2575 opts->x_exit_after_options = true;
2576 break;
2578 case OPT__help_:
2580 help_option_arguments.safe_push (arg);
2581 opts->x_exit_after_options = true;
2582 break;
2585 case OPT__version:
2586 if (lang_mask == CL_DRIVER)
2587 break;
2589 opts->x_exit_after_options = true;
2590 break;
2592 case OPT__completion_:
2593 break;
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
2601 all features. */
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);
2621 break;
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);
2627 break;
2629 case OPT_fasan_shadow_offset_:
2630 /* Deferred. */
2631 break;
2633 case OPT_fsanitize_address_use_after_scope:
2634 opts->x_flag_sanitize_address_use_after_scope = value;
2635 break;
2637 case OPT_fsanitize_recover:
2638 if (value)
2639 opts->x_flag_sanitize_recover
2640 |= (SANITIZE_UNDEFINED | SANITIZE_UNDEFINED_NONDEFAULT)
2641 & ~(SANITIZE_UNREACHABLE | SANITIZE_RETURN);
2642 else
2643 opts->x_flag_sanitize_recover
2644 &= ~(SANITIZE_UNDEFINED | SANITIZE_UNDEFINED_NONDEFAULT);
2645 break;
2647 case OPT_O:
2648 case OPT_Os:
2649 case OPT_Ofast:
2650 case OPT_Og:
2651 case OPT_Oz:
2652 /* Currently handled in a prescan. */
2653 break;
2655 case OPT_Wattributes_:
2656 if (lang_mask == CL_DRIVER)
2657 break;
2659 if (value)
2661 error_at (loc, "arguments ignored for %<-Wattributes=%>; use "
2662 "%<-Wno-attributes=%> instead");
2663 break;
2665 else if (arg[strlen (arg) - 1] == ',')
2667 error_at (loc, "trailing %<,%> in arguments for "
2668 "%<-Wno-attributes=%>");
2669 break;
2672 add_comma_separated_to_vector (&opts->x_flag_ignored_attributes, arg);
2673 break;
2675 case OPT_Werror:
2676 dc->warning_as_error_requested = value;
2677 break;
2679 case OPT_Werror_:
2680 if (lang_mask == CL_DRIVER)
2681 break;
2683 enable_warning_as_error (arg, value, lang_mask, handlers,
2684 opts, opts_set, loc, dc);
2685 break;
2687 case OPT_Wfatal_errors:
2688 dc->fatal_errors = value;
2689 break;
2691 case OPT_Wstack_usage_:
2692 opts->x_flag_stack_usage_info = value != -1;
2693 break;
2695 case OPT_Wstrict_aliasing:
2696 set_Wstrict_aliasing (opts, value);
2697 break;
2699 case OPT_Wstrict_overflow:
2700 opts->x_warn_strict_overflow = (value
2701 ? (int) WARN_STRICT_OVERFLOW_CONDITIONAL
2702 : 0);
2703 break;
2705 case OPT_Wsystem_headers:
2706 dc->dc_warn_system_headers = value;
2707 break;
2709 case OPT_aux_info:
2710 opts->x_flag_gen_aux_info = 1;
2711 break;
2713 case OPT_d:
2714 decode_d_option (arg, opts, loc, dc);
2715 break;
2717 case OPT_fcall_used_:
2718 case OPT_fcall_saved_:
2719 /* Deferred. */
2720 break;
2722 case OPT_fdbg_cnt_:
2723 /* Deferred. */
2724 break;
2726 case OPT_fdebug_prefix_map_:
2727 case OPT_ffile_prefix_map_:
2728 case OPT_fprofile_prefix_map_:
2729 /* Deferred. */
2730 break;
2732 case OPT_fcallgraph_info:
2733 opts->x_flag_callgraph_info = CALLGRAPH_INFO_NAKED;
2734 break;
2736 case OPT_fcallgraph_info_:
2738 char *my_arg, *p;
2739 my_arg = xstrdup (arg);
2740 p = strtok (my_arg, ",");
2741 while (p)
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;
2750 else
2751 return 0;
2752 p = strtok (NULL, ",");
2754 free (my_arg);
2756 break;
2758 case OPT_fdiagnostics_show_location_:
2759 diagnostic_prefixing_rule (dc) = (diagnostic_prefixing_rule_t) value;
2760 break;
2762 case OPT_fdiagnostics_show_caret:
2763 dc->show_caret = value;
2764 break;
2766 case OPT_fdiagnostics_show_labels:
2767 dc->show_labels_p = value;
2768 break;
2770 case OPT_fdiagnostics_show_line_numbers:
2771 dc->show_line_numbers_p = value;
2772 break;
2774 case OPT_fdiagnostics_color_:
2775 diagnostic_color_init (dc, value);
2776 break;
2778 case OPT_fdiagnostics_urls_:
2779 diagnostic_urls_init (dc, value);
2780 break;
2782 case OPT_fdiagnostics_format_:
2783 diagnostic_output_format_init (dc,
2784 (enum diagnostics_output_format)value);
2785 break;
2787 case OPT_fdiagnostics_parseable_fixits:
2788 dc->extra_output_kind = (value
2789 ? EXTRA_DIAGNOSTIC_OUTPUT_fixits_v1
2790 : EXTRA_DIAGNOSTIC_OUTPUT_none);
2791 break;
2793 case OPT_fdiagnostics_column_unit_:
2794 dc->column_unit = (enum diagnostics_column_unit)value;
2795 break;
2797 case OPT_fdiagnostics_column_origin_:
2798 dc->column_origin = value;
2799 break;
2801 case OPT_fdiagnostics_escape_format_:
2802 dc->escape_format = (enum diagnostics_escape_format)value;
2803 break;
2805 case OPT_fdiagnostics_show_cwe:
2806 dc->show_cwe = value;
2807 break;
2809 case OPT_fdiagnostics_path_format_:
2810 dc->path_format = (enum diagnostic_path_format)value;
2811 break;
2813 case OPT_fdiagnostics_show_path_depths:
2814 dc->show_path_depths = value;
2815 break;
2817 case OPT_fdiagnostics_show_option:
2818 dc->show_option_requested = value;
2819 break;
2821 case OPT_fdiagnostics_minimum_margin_width_:
2822 dc->min_margin_width = value;
2823 break;
2825 case OPT_fdump_:
2826 /* Deferred. */
2827 break;
2829 case OPT_ffast_math:
2830 set_fast_math_flags (opts, value);
2831 break;
2833 case OPT_funsafe_math_optimizations:
2834 set_unsafe_math_optimizations_flags (opts, value);
2835 break;
2837 case OPT_ffixed_:
2838 /* Deferred. */
2839 break;
2841 case OPT_finline_limit_:
2842 SET_OPTION_IF_UNSET (opts, opts_set, param_max_inline_insns_single,
2843 value / 2);
2844 SET_OPTION_IF_UNSET (opts, opts_set, param_max_inline_insns_auto,
2845 value / 2);
2846 break;
2848 case OPT_finstrument_functions_exclude_function_list_:
2849 add_comma_separated_to_vector
2850 (&opts->x_flag_instrument_functions_exclude_functions, arg);
2851 break;
2853 case OPT_finstrument_functions_exclude_file_list_:
2854 add_comma_separated_to_vector
2855 (&opts->x_flag_instrument_functions_exclude_files, arg);
2856 break;
2858 case OPT_fmessage_length_:
2859 pp_set_line_maximum_length (dc->printer, value);
2860 diagnostic_set_caret_max_width (dc, value);
2861 break;
2863 case OPT_fopt_info:
2864 case OPT_fopt_info_:
2865 /* Deferred. */
2866 break;
2868 case OPT_foffload_options_:
2869 /* Deferred. */
2870 break;
2872 case OPT_foffload_abi_:
2873 #ifdef ACCEL_COMPILER
2874 /* Handled in the 'mkoffload's. */
2875 #else
2876 error_at (loc, "%<-foffload-abi%> option can be specified only for "
2877 "offload compiler");
2878 #endif
2879 break;
2881 case OPT_fpack_struct_:
2882 if (value <= 0 || (value & (value - 1)) || value > 16)
2883 error_at (loc,
2884 "structure alignment must be a small power of two, not %wu",
2885 value);
2886 else
2887 opts->x_initial_max_fld_align = value;
2888 break;
2890 case OPT_fplugin_:
2891 case OPT_fplugin_arg_:
2892 /* Deferred. */
2893 break;
2895 case OPT_fprofile_use_:
2896 opts->x_profile_data_prefix = xstrdup (arg);
2897 opts->x_flag_profile_use = true;
2898 value = true;
2899 /* No break here - do -fprofile-use processing. */
2900 /* FALLTHRU */
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,
2904 value);
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,
2909 false);
2910 break;
2912 case OPT_fauto_profile_:
2913 opts->x_auto_profile_file = xstrdup (arg);
2914 opts->x_flag_auto_profile = true;
2915 value = true;
2916 /* No break here - do -fauto-profile processing. */
2917 /* FALLTHRU */
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);
2921 break;
2923 case OPT_fprofile_generate_:
2924 opts->x_profile_data_prefix = xstrdup (arg);
2925 value = true;
2926 /* No break here - do -fprofile-generate processing. */
2927 /* FALLTHRU */
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);
2933 break;
2935 case OPT_fprofile_info_section:
2936 opts->x_profile_info_section = ".gcov_info";
2937 break;
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,
2943 &patch_area_start);
2945 break;
2947 case OPT_ftree_vectorize:
2948 /* Automatically sets -ftree-loop-vectorize and
2949 -ftree-slp-vectorize. Nothing more to do here. */
2950 break;
2951 case OPT_fzero_call_used_regs_:
2952 opts->x_flag_zero_call_used_regs
2953 = parse_zero_call_used_regs_options (arg);
2954 break;
2956 case OPT_fshow_column:
2957 dc->show_column = value;
2958 break;
2960 case OPT_frandom_seed:
2961 /* The real switch is -fno-random-seed. */
2962 if (value)
2963 return false;
2964 /* Deferred. */
2965 break;
2967 case OPT_frandom_seed_:
2968 /* Deferred. */
2969 break;
2971 case OPT_fsched_verbose_:
2972 #ifdef INSN_SCHEDULING
2973 /* Handled with Var in common.opt. */
2974 break;
2975 #else
2976 return false;
2977 #endif
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;
2983 break;
2985 case OPT_fsched_stalled_insns_dep_:
2986 opts->x_flag_sched_stalled_insns_dep = value;
2987 break;
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;
3004 else
3005 warning_at (loc, 0, "unknown stack check parameter %qs", arg);
3006 break;
3008 case OPT_fstack_limit:
3009 /* The real switch is -fno-stack-limit. */
3010 if (value)
3011 return false;
3012 /* Deferred. */
3013 break;
3015 case OPT_fstack_limit_register_:
3016 case OPT_fstack_limit_symbol_:
3017 /* Deferred. */
3018 break;
3020 case OPT_fstack_usage:
3021 opts->x_flag_stack_usage = value;
3022 opts->x_flag_stack_usage_info = value != 0;
3023 break;
3025 case OPT_g:
3026 set_debug_level (NO_DEBUG, DEFAULT_GDB_EXTENSIONS, arg, opts, opts_set,
3027 loc);
3028 break;
3030 case OPT_gbtf:
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,
3033 don't lower it. */
3034 if (opts->x_debug_info_level < DINFO_LEVEL_NORMAL)
3035 opts->x_debug_info_level = DINFO_LEVEL_NORMAL;
3036 break;
3038 case OPT_gctf:
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;
3046 break;
3048 case OPT_gdwarf:
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);
3054 break;
3056 else
3057 value = opts->x_dwarf_version;
3059 /* FALLTHRU */
3060 case OPT_gdwarf_:
3061 if (value < 2 || value > 5)
3062 error_at (loc, "dwarf version %wu is not supported", value);
3063 else
3064 opts->x_dwarf_version = value;
3065 set_debug_level (DWARF2_DEBUG, false, "", opts, opts_set, loc);
3066 break;
3068 case OPT_ggdb:
3069 set_debug_level (NO_DEBUG, 2, arg, opts, opts_set, loc);
3070 break;
3072 case OPT_gstabs:
3073 case OPT_gstabs_:
3074 set_debug_level (DBX_DEBUG, code == OPT_gstabs_, arg, opts, opts_set,
3075 loc);
3076 break;
3078 case OPT_gvms:
3079 set_debug_level (VMS_DEBUG, false, arg, opts, opts_set, loc);
3080 break;
3082 case OPT_gxcoff:
3083 case OPT_gxcoff_:
3084 set_debug_level (XCOFF_DEBUG, code == OPT_gxcoff_, arg, opts, opts_set,
3085 loc);
3086 break;
3088 case OPT_gz:
3089 case OPT_gz_:
3090 /* Handled completely via specs. */
3091 break;
3093 case OPT_pedantic_errors:
3094 dc->pedantic_errors = 1;
3095 control_warning_option (OPT_Wpedantic, DK_ERROR, NULL, value,
3096 loc, lang_mask,
3097 handlers, opts, opts_set,
3098 dc);
3099 break;
3101 case OPT_flto:
3102 opts->x_flag_lto = value ? "" : NULL;
3103 break;
3105 case OPT_flto_:
3106 if (strcmp (arg, "none") != 0
3107 && strcmp (arg, "jobserver") != 0
3108 && strcmp (arg, "auto") != 0
3109 && atoi (arg) == 0)
3110 error_at (loc,
3111 "unrecognized argument to %<-flto=%> option: %qs", arg);
3112 break;
3114 case OPT_w:
3115 dc->dc_inhibit_warnings = true;
3116 break;
3118 case OPT_fmax_errors_:
3119 dc->max_errors = value;
3120 break;
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.*/
3128 break;
3130 case OPT_fwrapv:
3131 if (value)
3132 opts->x_flag_trapv = 0;
3133 break;
3135 case OPT_ftrapv:
3136 if (value)
3137 opts->x_flag_wrapv = 0;
3138 break;
3140 case OPT_fstrict_overflow:
3141 opts->x_flag_wrapv = !value;
3142 opts->x_flag_wrapv_pointer = !value;
3143 if (!value)
3144 opts->x_flag_trapv = 0;
3145 break;
3147 case OPT_fipa_icf:
3148 opts->x_flag_ipa_icf_functions = value;
3149 opts->x_flag_ipa_icf_variables = value;
3150 break;
3152 case OPT_falign_loops_:
3153 check_alignment_argument (loc, arg, "loops",
3154 &opts->x_flag_align_loops,
3155 &opts->x_str_align_loops);
3156 break;
3158 case OPT_falign_jumps_:
3159 check_alignment_argument (loc, arg, "jumps",
3160 &opts->x_flag_align_jumps,
3161 &opts->x_str_align_jumps);
3162 break;
3164 case OPT_falign_labels_:
3165 check_alignment_argument (loc, arg, "labels",
3166 &opts->x_flag_align_labels,
3167 &opts->x_str_align_labels);
3168 break;
3170 case OPT_falign_functions_:
3171 check_alignment_argument (loc, arg, "functions",
3172 &opts->x_flag_align_functions,
3173 &opts->x_str_align_functions);
3174 break;
3176 case OPT_ftabstop_:
3177 /* It is documented that we silently ignore silly values. */
3178 if (value >= 1 && value <= 100)
3179 dc->tabstop = value;
3180 break;
3182 case OPT_freport_bug:
3183 dc->report_bug = value;
3184 break;
3186 default:
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));
3190 break;
3193 common_handle_option_auto (opts, opts_set, decoded, lang_mask, kind,
3194 loc, handlers, dc);
3195 return true;
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. */
3204 static void
3205 set_Wstrict_aliasing (struct gcc_options *opts, int onoff)
3207 gcc_assert (onoff == 0 || onoff == 1);
3208 if (onoff != 0)
3209 opts->x_warn_strict_aliasing = 3;
3210 else
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. */
3216 static void
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;
3228 if (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. */
3244 static void
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. */
3258 bool
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. */
3271 bool
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). */
3285 static void
3286 set_debug_level (uint32_t dinfo, int extended, const char *arg,
3287 struct gcc_options *opts, struct gcc_options *opts_set,
3288 location_t loc)
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;
3298 if (extended == 2)
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;
3303 else
3304 opts->x_write_symbols = DWARF2_DEBUG;
3305 #elif defined DBX_DEBUGGING_INFO
3306 opts->x_write_symbols = DBX_DEBUG;
3307 #endif
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;
3320 else
3322 /* Make and retain the choice if both CTF and DWARF debug info are to
3323 be generated. */
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;
3341 else
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. */
3362 if (*arg == '\0')
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;
3369 else
3371 int argval = integral_argument (arg);
3372 if (argval == -1)
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);
3376 else
3378 if (dinfo == CTF_DEBUG)
3379 opts->x_ctf_debug_info_level
3380 = (enum ctf_debug_info_levels) argval;
3381 else
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
3392 abort ().) */
3394 static void
3395 setup_core_dumping (diagnostic_context *dc)
3397 #ifdef SIGABRT
3398 signal (SIGABRT, SIG_DFL);
3399 #endif
3400 #if defined(HAVE_SETRLIMIT)
3402 struct rlimit rlim;
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");
3410 #endif
3411 diagnostic_abort_on_error (dc);
3414 /* Parse a -d<ARG> command line switch for OPTS, location LOC,
3415 diagnostic context DC. */
3417 static void
3418 decode_d_option (const char *arg, struct gcc_options *opts,
3419 location_t loc, diagnostic_context *dc)
3421 int c;
3423 while (*arg)
3424 switch (c = *arg++)
3426 case 'A':
3427 opts->x_flag_debug_asm = 1;
3428 break;
3429 case 'p':
3430 opts->x_flag_print_asm_name = 1;
3431 break;
3432 case 'P':
3433 opts->x_flag_dump_rtl_in_asm = 1;
3434 opts->x_flag_print_asm_name = 1;
3435 break;
3436 case 'x':
3437 opts->x_rtl_dump_and_exit = 1;
3438 break;
3439 case 'D': /* These are handled by the preprocessor. */
3440 case 'I':
3441 case 'M':
3442 case 'N':
3443 case 'U':
3444 break;
3445 case 'H':
3446 setup_core_dumping (dc);
3447 break;
3448 case 'a':
3449 opts->x_flag_dump_all_passed = true;
3450 break;
3452 default:
3453 warning_at (loc, 0, "unrecognized gcc debugging option: %c", c);
3454 break;
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=. */
3463 static void
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)
3470 char *new_option;
3471 int option_index;
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);
3481 if (hint)
3482 error_at (loc, "%<-W%serror=%s%>: no option %<-%s%>;"
3483 " did you mean %<-%s%>?", value ? "" : "no-",
3484 arg, new_option, hint);
3485 else
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);
3492 else
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,
3500 loc, lang_mask,
3501 handlers, opts, opts_set, dc);
3503 free (new_option);
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
3509 as -Werror. */
3511 char *
3512 option_name (diagnostic_context *context, int option_index,
3513 diagnostic_t orig_diag_kind, diagnostic_t diag_kind)
3515 if (option_index)
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,
3523 NULL);
3524 /* A warning with option. */
3525 else
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);
3533 else
3534 return NULL;
3537 /* Get the page within the documentation for this option. */
3539 static const char *
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";
3552 #ifdef CL_Fortran
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
3557 #ifdef CL_CXX
3558 && (cl_opt->flags & CL_CXX) == 0
3559 #endif
3561 return "gfortran/Error-and-Warning-Options.html";
3562 #endif
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). */
3570 char *
3571 get_option_url (diagnostic_context *, int option_index)
3573 if (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,
3587 NULL);
3588 else
3589 return NULL;
3592 /* Return a heap allocated producer with command line options. */
3594 char *
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;
3600 const char *p;
3601 size_t len = 0;
3603 for (unsigned i = 0; i < options_count; i++)
3604 switch (options[i].opt_index)
3606 case OPT_o:
3607 case OPT_d:
3608 case OPT_dumpbase:
3609 case OPT_dumpbase_ext:
3610 case OPT_dumpdir:
3611 case OPT_quiet:
3612 case OPT_version:
3613 case OPT_v:
3614 case OPT_w:
3615 case OPT_L:
3616 case OPT_D:
3617 case OPT_I:
3618 case OPT_U:
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:
3635 case OPT____:
3636 case OPT__sysroot_:
3637 case OPT_nostdinc:
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:
3647 case OPT_fchecking:
3648 case OPT_fchecking_:
3649 /* Ignore these. */
3650 continue;
3651 case OPT_flto_:
3653 const char *lto_canonical = "-flto";
3654 switches.safe_push (lto_canonical);
3655 len += strlen (lto_canonical) + 1;
3656 break;
3658 default:
3659 if (cl_options[options[i].opt_index].flags
3660 & CL_NO_DWARF_RECORD)
3661 continue;
3662 gcc_checking_assert (options[i].canonical_option[0][0] == '-');
3663 switch (options[i].canonical_option[0][1])
3665 case 'M':
3666 case 'i':
3667 case 'W':
3668 continue;
3669 case 'f':
3670 if (strncmp (options[i].canonical_option[0] + 2,
3671 "dump", 4) == 0)
3672 continue;
3673 break;
3674 default:
3675 break;
3677 switches.safe_push (options[i].orig_option_with_args_text);
3678 len += strlen (options[i].orig_option_with_args_text) + 1;
3679 break;
3682 options_string = XNEWVEC (char, len + 1);
3683 tail = options_string;
3685 unsigned i;
3686 FOR_EACH_VEC_ELT (switches, i, p)
3688 len = strlen (p);
3689 memcpy (tail, p, len);
3690 tail += len;
3691 if (i != switches.length () - 1)
3693 *tail = ' ';
3694 ++tail;
3698 *tail = '\0';
3699 return options_string;
3702 /* Return a heap allocated producer string including command line options. */
3704 char *
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, " ",
3710 cmdline, NULL);
3711 free (cmdline);
3712 return combined;
3715 #if CHECKING_P
3717 namespace selftest {
3719 /* Verify that get_option_html_page works as expected. */
3721 static void
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");
3727 #ifdef CL_Fortran
3728 ASSERT_STREQ (get_option_html_page (OPT_Wline_truncation),
3729 "gfortran/Error-and-Warning-Options.html");
3730 #endif
3733 /* Verify EnumSet and EnumBitSet requirements. */
3735 static void
3736 test_enum_sets ()
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));
3755 continue;
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)
3764 continue;
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);
3770 else
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;
3778 if (set == j)
3779 this_mask |= e->values[j].value;
3781 ASSERT_TRUE ((mask & this_mask) == 0);
3782 mask |= this_mask;
3787 /* Run all of the selftests within this file. */
3789 void
3790 opts_cc_tests ()
3792 test_get_option_html_page ();
3793 test_enum_sets ();
3796 } // namespace selftest
3798 #endif /* #if CHECKING_P */