LCOV - code coverage report
Current view: top level - gcc - opts.cc (source / functions) Coverage Total Hit
Test: gcc.info Lines: 88.1 % 1821 1604
Test Date: 2026-11-14 16:39:50 Functions: 98.3 % 58 57
Legend: Lines:     hit not hit

            Line data    Source code
       1              : /* Command line option handling.
       2              :    Copyright (C) 2002-2026 Free Software Foundation, Inc.
       3              :    Contributed by Neil Booth.
       4              : 
       5              : This file is part of GCC.
       6              : 
       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.
      11              : 
      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.
      16              : 
      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/>.  */
      20              : 
      21              : #define INCLUDE_LIST
      22              : #define INCLUDE_VECTOR
      23              : #include "config.h"
      24              : #include "system.h"
      25              : #include "intl.h"
      26              : #include "coretypes.h"
      27              : #include "opts.h"
      28              : #include "tm.h"
      29              : #include "flags.h"
      30              : #include "diagnostic.h"
      31              : #include "opts-diagnostic.h"
      32              : #include "insn-attr-common.h"
      33              : #include "common/common-target.h"
      34              : #include "spellcheck.h"
      35              : #include "opt-suggestions.h"
      36              : #include "diagnostics/color.h"
      37              : #include "diagnostics/sink.h"
      38              : #include "version.h"
      39              : #include "selftest.h"
      40              : #include "file-prefix-map.h"
      41              : 
      42              : /* In this file all option sets are explicit.  */
      43              : #undef OPTION_SET_P
      44              : 
      45              : /* Set by -fcanon-prefix-map.  */
      46              : bool flag_canon_prefix_map;
      47              : 
      48              : /* Set by finish_options when flag_stack_protector was set only because of
      49              :    -fhardened.  Yuck.  */
      50              : bool flag_stack_protector_set_by_fhardened_p;
      51              : 
      52              : static void set_Wstrict_aliasing (struct gcc_options *opts, int onoff);
      53              : 
      54              : /* Names of fundamental debug info formats indexed by enum
      55              :    debug_info_type.  */
      56              : 
      57              : const char *const debug_type_names[] =
      58              : {
      59              :   "none", "dwarf-2", "vms", "ctf", "btf", "codeview"
      60              : };
      61              : 
      62              : /* Bitmasks of fundamental debug info formats indexed by enum
      63              :    debug_info_type.  */
      64              : 
      65              : static uint32_t debug_type_masks[] =
      66              : {
      67              :   NO_DEBUG, DWARF2_DEBUG, VMS_DEBUG,
      68              :   CTF_DEBUG, BTF_DEBUG, CODEVIEW_DEBUG
      69              : };
      70              : 
      71              : /* Names of the set of debug formats requested by user.  Updated and accessed
      72              :    via debug_set_names.  */
      73              : 
      74              : static char df_set_names[sizeof "none dwarf-2 vms ctf btf codeview"];
      75              : 
      76              : /* Get enum debug_info_type of the specified debug format, for error messages.
      77              :    Can be used only for individual debug format types.  */
      78              : 
      79              : enum debug_info_type
      80            0 : debug_set_to_format (uint32_t debug_info_set)
      81              : {
      82            0 :   int idx = 0;
      83            0 :   enum debug_info_type dinfo_type = DINFO_TYPE_NONE;
      84              :   /* Find first set bit.  */
      85            0 :   if (debug_info_set)
      86            0 :     idx = exact_log2 (debug_info_set & - debug_info_set);
      87              :   /* Check that only one bit is set, if at all.  This function is meant to be
      88              :      used only for vanilla debug_info_set bitmask values, i.e. for individual
      89              :      debug format types upto DINFO_TYPE_MAX.  */
      90            0 :   gcc_assert ((debug_info_set & (debug_info_set - 1)) == 0);
      91            0 :   dinfo_type = (enum debug_info_type)idx;
      92            0 :   gcc_assert (dinfo_type <= DINFO_TYPE_MAX);
      93            0 :   return dinfo_type;
      94              : }
      95              : 
      96              : /* Get the number of debug formats enabled for output.  */
      97              : 
      98              : unsigned int
      99           12 : debug_set_count (uint32_t w_symbols)
     100              : {
     101           12 :   unsigned int count = 0;
     102           18 :   while (w_symbols)
     103              :     {
     104            6 :       ++ count;
     105            6 :       w_symbols &= ~ (w_symbols & - w_symbols);
     106              :     }
     107           12 :   return count;
     108              : }
     109              : 
     110              : /* Get the names of the debug formats enabled for output.  */
     111              : 
     112              : const char *
     113           12 : debug_set_names (uint32_t w_symbols)
     114              : {
     115           12 :   uint32_t df_mask = 0;
     116              :   /* Reset the string to be returned.  */
     117           12 :   memset (df_set_names, 0, sizeof (df_set_names));
     118              :   /* Get the popcount.  */
     119           12 :   int num_set_df = debug_set_count (w_symbols);
     120              :   /* Iterate over the debug formats.  Add name string for those enabled.  */
     121           18 :   for (int i = DINFO_TYPE_NONE; i <= DINFO_TYPE_MAX; i++)
     122              :     {
     123           18 :       df_mask = debug_type_masks[i];
     124           18 :       if (w_symbols & df_mask)
     125              :         {
     126            6 :           strcat (df_set_names, debug_type_names[i]);
     127            6 :           num_set_df--;
     128            6 :           if (num_set_df)
     129            0 :             strcat (df_set_names, " ");
     130              :           else
     131              :             break;
     132              :         }
     133           12 :       else if (!w_symbols)
     134              :         {
     135              :           /* No debug formats enabled.  */
     136            6 :           gcc_assert (i == DINFO_TYPE_NONE);
     137            6 :           strcat (df_set_names, debug_type_names[i]);
     138            6 :           break;
     139              :         }
     140              :     }
     141           12 :   return df_set_names;
     142              : }
     143              : 
     144              : /* Return TRUE iff BTF debug info is enabled.  */
     145              : 
     146              : bool
     147       107646 : btf_debuginfo_p ()
     148              : {
     149       107646 :   return (write_symbols & BTF_DEBUG);
     150              : }
     151              : 
     152              : /* Return TRUE iff BTF with CO-RE debug info is enabled.  */
     153              : 
     154              : bool
     155          182 : btf_with_core_debuginfo_p ()
     156              : {
     157          182 :   return (write_symbols & BTF_WITH_CORE_DEBUG);
     158              : }
     159              : 
     160              : /* Return TRUE iff CTF debug info is enabled.  */
     161              : 
     162              : bool
     163          315 : ctf_debuginfo_p ()
     164              : {
     165          315 :   return (write_symbols & CTF_DEBUG);
     166              : }
     167              : 
     168              : /* Return TRUE iff CodeView debug info is enabled.  */
     169              : 
     170              : bool
     171          321 : codeview_debuginfo_p ()
     172              : {
     173          321 :   return (write_symbols & CODEVIEW_DEBUG);
     174              : }
     175              : 
     176              : /* Return TRUE iff dwarf2 debug info is enabled.  */
     177              : 
     178              : bool
     179     46342095 : dwarf_debuginfo_p (struct gcc_options *opts)
     180              : {
     181     46342095 :   return (opts->x_write_symbols & DWARF2_DEBUG);
     182              : }
     183              : 
     184              : /* Return true iff the debug info format is to be generated based on DWARF
     185              :    DIEs (like CTF and BTF debug info formats).  */
     186              : 
     187      5076570 : bool dwarf_based_debuginfo_p ()
     188              : {
     189      5076570 :   return ((write_symbols & CTF_DEBUG)
     190      5075395 :           || (write_symbols & BTF_DEBUG)
     191     10151697 :           || (write_symbols & CODEVIEW_DEBUG));
     192              : }
     193              : 
     194              : /* All flag uses below need to explicitly reference the option sets
     195              :    to operate on.  */
     196              : #define global_options DO_NOT_USE
     197              : #define global_options_set DO_NOT_USE
     198              : 
     199              : /* Parse the -femit-struct-debug-detailed option value
     200              :    and set the flag variables. */
     201              : 
     202              : #define MATCH( prefix, string ) \
     203              :   ((strncmp (prefix, string, sizeof prefix - 1) == 0) \
     204              :    ? ((string += sizeof prefix - 1), 1) : 0)
     205              : 
     206              : void
     207           42 : set_struct_debug_option (struct gcc_options *opts, location_t loc,
     208              :                          const char *spec)
     209              : {
     210              :   /* various labels for comparison */
     211           58 :   static const char dfn_lbl[] = "dfn:", dir_lbl[] = "dir:", ind_lbl[] = "ind:";
     212           58 :   static const char ord_lbl[] = "ord:", gen_lbl[] = "gen:";
     213           58 :   static const char none_lbl[] = "none", any_lbl[] = "any";
     214           58 :   static const char base_lbl[] = "base", sys_lbl[] = "sys";
     215              : 
     216           58 :   enum debug_struct_file files = DINFO_STRUCT_FILE_ANY;
     217              :   /* Default is to apply to as much as possible. */
     218           58 :   enum debug_info_usage usage = DINFO_USAGE_NUM_ENUMS;
     219           58 :   int ord = 1, gen = 1;
     220              : 
     221              :   /* What usage? */
     222           58 :   if (MATCH (dfn_lbl, spec))
     223              :     usage = DINFO_USAGE_DFN;
     224           58 :   else if (MATCH (dir_lbl, spec))
     225              :     usage = DINFO_USAGE_DIR_USE;
     226           42 :   else if (MATCH (ind_lbl, spec))
     227            8 :     usage = DINFO_USAGE_IND_USE;
     228              : 
     229              :   /* Generics or not? */
     230           58 :   if (MATCH (ord_lbl, spec))
     231              :     gen = 0;
     232           50 :   else if (MATCH (gen_lbl, spec))
     233            8 :     ord = 0;
     234              : 
     235              :   /* What allowable environment? */
     236           58 :   if (MATCH (none_lbl, spec))
     237              :     files = DINFO_STRUCT_FILE_NONE;
     238           54 :   else if (MATCH (any_lbl, spec))
     239              :     files = DINFO_STRUCT_FILE_ANY;
     240           42 :   else if (MATCH (sys_lbl, spec))
     241              :     files = DINFO_STRUCT_FILE_SYS;
     242           30 :   else if (MATCH (base_lbl, spec))
     243              :     files = DINFO_STRUCT_FILE_BASE;
     244              :   else
     245            0 :     error_at (loc,
     246              :               "argument %qs to %<-femit-struct-debug-detailed%> "
     247              :               "not recognized",
     248              :               spec);
     249              : 
     250              :   /* Effect the specification. */
     251           58 :   if (usage == DINFO_USAGE_NUM_ENUMS)
     252              :     {
     253           34 :       if (ord)
     254              :         {
     255           34 :           opts->x_debug_struct_ordinary[DINFO_USAGE_DFN] = files;
     256           34 :           opts->x_debug_struct_ordinary[DINFO_USAGE_DIR_USE] = files;
     257           34 :           opts->x_debug_struct_ordinary[DINFO_USAGE_IND_USE] = files;
     258              :         }
     259           34 :       if (gen)
     260              :         {
     261           34 :           opts->x_debug_struct_generic[DINFO_USAGE_DFN] = files;
     262           34 :           opts->x_debug_struct_generic[DINFO_USAGE_DIR_USE] = files;
     263           34 :           opts->x_debug_struct_generic[DINFO_USAGE_IND_USE] = files;
     264              :         }
     265              :     }
     266              :   else
     267              :     {
     268           24 :       if (ord)
     269           16 :         opts->x_debug_struct_ordinary[usage] = files;
     270           24 :       if (gen)
     271           16 :         opts->x_debug_struct_generic[usage] = files;
     272              :     }
     273              : 
     274           58 :   if (*spec == ',')
     275           16 :     set_struct_debug_option (opts, loc, spec+1);
     276              :   else
     277              :     {
     278              :       /* No more -femit-struct-debug-detailed specifications.
     279              :          Do final checks. */
     280           42 :       if (*spec != '\0')
     281            0 :         error_at (loc,
     282              :                   "argument %qs to %<-femit-struct-debug-detailed%> unknown",
     283              :                   spec);
     284           42 :       if (opts->x_debug_struct_ordinary[DINFO_USAGE_DIR_USE]
     285           42 :                 < opts->x_debug_struct_ordinary[DINFO_USAGE_IND_USE]
     286           42 :           || opts->x_debug_struct_generic[DINFO_USAGE_DIR_USE]
     287           42 :                 < opts->x_debug_struct_generic[DINFO_USAGE_IND_USE])
     288            0 :         error_at (loc,
     289              :                   "%<-femit-struct-debug-detailed=dir:...%> must allow "
     290              :                   "at least as much as "
     291              :                   "%<-femit-struct-debug-detailed=ind:...%>");
     292              :     }
     293           42 : }
     294              : 
     295              : /* Strip off a legitimate source ending from the input string NAME of
     296              :    length LEN.  Rather than having to know the names used by all of
     297              :    our front ends, we strip off an ending of a period followed by
     298              :    up to fource characters.  (C++ uses ".cpp".)  */
     299              : 
     300              : void
     301         1528 : strip_off_ending (char *name, int len)
     302              : {
     303         1528 :   int i;
     304         1690 :   for (i = 2; i < 5 && len > i; i++)
     305              :     {
     306         1690 :       if (name[len - i] == '.')
     307              :         {
     308         1528 :           name[len - i] = '\0';
     309         1528 :           break;
     310              :         }
     311              :     }
     312         1528 : }
     313              : 
     314              : /* Find the base name of a path, stripping off both directories and
     315              :    a single final extension. */
     316              : int
     317       297293 : base_of_path (const char *path, const char **base_out)
     318              : {
     319       297293 :   const char *base = path;
     320       297293 :   const char *dot = 0;
     321       297293 :   const char *p = path;
     322       297293 :   char c = *p;
     323     23113571 :   while (c)
     324              :     {
     325     22816278 :       if (IS_DIR_SEPARATOR (c))
     326              :         {
     327      2597935 :           base = p + 1;
     328      2597935 :           dot = 0;
     329              :         }
     330     20218343 :       else if (c == '.')
     331       521308 :         dot = p;
     332     22816278 :       c = *++p;
     333              :     }
     334       297293 :   if (!dot)
     335          421 :     dot = p;
     336       297293 :   *base_out = base;
     337       297293 :   return dot - base;
     338              : }
     339              : 
     340              : /* What to print when a switch has no documentation.  */
     341              : static const char undocumented_msg[] = N_("This option lacks documentation.");
     342              : static const char use_diagnosed_msg[] = N_("Uses of this option are diagnosed.");
     343              : 
     344              : typedef char *char_p; /* For DEF_VEC_P.  */
     345              : 
     346              : static void set_debug_level (uint32_t dinfo, int extended,
     347              :                              const char *arg, struct gcc_options *opts,
     348              :                              struct gcc_options *opts_set,
     349              :                              location_t loc);
     350              : static void set_fast_math_flags (struct gcc_options *opts, int set);
     351              : static void decode_d_option (const char *arg, struct gcc_options *opts,
     352              :                              location_t loc, diagnostics::context *dc);
     353              : static void set_unsafe_math_optimizations_flags (struct gcc_options *opts,
     354              :                                                  int set);
     355              : static void enable_warning_as_error (const char *arg, int value,
     356              :                                      unsigned int lang_mask,
     357              :                                      const struct cl_option_handlers *handlers,
     358              :                                      struct gcc_options *opts,
     359              :                                      struct gcc_options *opts_set,
     360              :                                      location_t loc,
     361              :                                      diagnostics::context *dc);
     362              : 
     363              : /* Handle a back-end option; arguments and return value as for
     364              :    handle_option.  */
     365              : 
     366              : bool
     367      1304937 : target_handle_option (struct gcc_options *opts,
     368              :                       struct gcc_options *opts_set,
     369              :                       const struct cl_decoded_option *decoded,
     370              :                       unsigned int lang_mask ATTRIBUTE_UNUSED, int kind,
     371              :                       location_t loc,
     372              :                       const struct cl_option_handlers *handlers ATTRIBUTE_UNUSED,
     373              :                       diagnostics::context *dc, void (*) (void))
     374              : {
     375      1304937 :   gcc_assert (dc == global_dc);
     376      1304937 :   gcc_assert (static_cast<diagnostics::kind> (kind)
     377              :               == diagnostics::kind::unspecified);
     378      1304937 :   return targetm_common.handle_option (opts, opts_set, decoded, loc);
     379              : }
     380              : 
     381              : /* Add comma-separated strings to a char_p vector.  */
     382              : 
     383              : static void
     384          102 : add_comma_separated_to_vector (void **pvec, const char *arg)
     385              : {
     386          102 :   char *tmp;
     387          102 :   char *r;
     388          102 :   char *w;
     389          102 :   char *token_start;
     390          102 :   vec<char_p> *v = (vec<char_p> *) *pvec;
     391              : 
     392          102 :   vec_check_alloc (v, 1);
     393              : 
     394              :   /* We never free this string.  */
     395          102 :   tmp = xstrdup (arg);
     396              : 
     397          102 :   r = tmp;
     398          102 :   w = tmp;
     399          102 :   token_start = tmp;
     400              : 
     401         1227 :   while (*r != '\0')
     402              :     {
     403         1125 :       if (*r == ',')
     404              :         {
     405           20 :           *w++ = '\0';
     406           20 :           ++r;
     407           20 :           v->safe_push (token_start);
     408           20 :           token_start = w;
     409              :         }
     410         1125 :       if (*r == '\\' && r[1] == ',')
     411              :         {
     412            0 :           *w++ = ',';
     413            0 :           r += 2;
     414              :         }
     415              :       else
     416         1125 :         *w++ = *r++;
     417              :     }
     418              : 
     419          102 :   *w = '\0';
     420          102 :   if (*token_start != '\0')
     421          102 :     v->safe_push (token_start);
     422              : 
     423          102 :   *pvec = v;
     424          102 : }
     425              : 
     426              : /* Initialize opts_obstack.  */
     427              : 
     428              : void
     429       617149 : init_opts_obstack (void)
     430              : {
     431       617149 :   gcc_obstack_init (&opts_obstack);
     432       617149 : }
     433              : 
     434              : /* Initialize OPTS and OPTS_SET before using them in parsing options.  */
     435              : 
     436              : void
     437     50730829 : init_options_struct (struct gcc_options *opts, struct gcc_options *opts_set)
     438              : {
     439              :   /* Ensure that opts_obstack has already been initialized by the time
     440              :      that we initialize any gcc_options instances (PR jit/68446).  */
     441     50730829 :   gcc_assert (opts_obstack.chunk_size > 0);
     442              : 
     443     50730829 :   *opts = global_options_init;
     444              : 
     445     50730829 :   if (opts_set)
     446       604235 :     memset (opts_set, 0, sizeof (*opts_set));
     447              : 
     448              :   /* Initialize whether `char' is signed.  */
     449     50730829 :   opts->x_flag_signed_char = DEFAULT_SIGNED_CHAR;
     450              : 
     451              :   /* Initialize target_flags before default_options_optimization
     452              :      so the latter can modify it.  */
     453     50730829 :   opts->x_target_flags = targetm_common.default_target_flags;
     454              : 
     455              :   /* Some targets have ABI-specified unwind tables.  */
     456     50730829 :   opts->x_flag_unwind_tables = targetm_common.unwind_tables_default;
     457              : 
     458              :   /* Languages not explicitly specifying a default get fortran rules.  */
     459     50730829 :   opts->x_flag_complex_method = 1;
     460              : 
     461              :   /* Some targets have other target-specific initialization.  */
     462     50730829 :   targetm_common.option_init_struct (opts);
     463     50730829 : }
     464              : 
     465              : /* If indicated by the optimization level LEVEL (-Os if SIZE is set,
     466              :    -Ofast if FAST is set, -Og if DEBUG is set), apply the option DEFAULT_OPT
     467              :    to OPTS and OPTS_SET, diagnostic context DC, location LOC, with language
     468              :    mask LANG_MASK and option handlers HANDLERS.  */
     469              : 
     470              : static void
     471     78014266 : maybe_default_option (struct gcc_options *opts,
     472              :                       struct gcc_options *opts_set,
     473              :                       const struct default_options *default_opt,
     474              :                       int level, bool size, bool fast, bool debug,
     475              :                       unsigned int lang_mask,
     476              :                       const struct cl_option_handlers *handlers,
     477              :                       location_t loc,
     478              :                       diagnostics::context *dc)
     479              : {
     480     78014266 :   const struct cl_option *option = &cl_options[default_opt->opt_index];
     481     78014266 :   bool enabled;
     482              : 
     483     78014266 :   if (size)
     484      1932007 :     gcc_assert (level == 2);
     485     78014266 :   if (fast)
     486        78166 :     gcc_assert (level == 3);
     487     78014266 :   if (debug)
     488        84458 :     gcc_assert (level == 1);
     489              : 
     490     78014266 :   switch (default_opt->levels)
     491              :     {
     492              :     case OPT_LEVELS_ALL:
     493              :       enabled = true;
     494              :       break;
     495              : 
     496            0 :     case OPT_LEVELS_0_ONLY:
     497            0 :       enabled = (level == 0);
     498            0 :       break;
     499              : 
     500     19342380 :     case OPT_LEVELS_1_PLUS:
     501     19342380 :       enabled = (level >= 1);
     502     19342380 :       break;
     503              : 
     504            0 :     case OPT_LEVELS_1_PLUS_SPEED_ONLY:
     505            0 :       enabled = (level >= 1 && !size && !debug);
     506              :       break;
     507              : 
     508      8381698 :     case OPT_LEVELS_1_PLUS_NOT_DEBUG:
     509      8381698 :       enabled = (level >= 1 && !debug);
     510      8381698 :       break;
     511              : 
     512     27079332 :     case OPT_LEVELS_2_PLUS:
     513     27079332 :       enabled = (level >= 2);
     514     27079332 :       break;
     515              : 
     516      8381698 :     case OPT_LEVELS_2_PLUS_SPEED_ONLY:
     517      8381698 :       enabled = (level >= 2 && !size && !debug);
     518              :       break;
     519              : 
     520     10960682 :     case OPT_LEVELS_3_PLUS:
     521     10960682 :       enabled = (level >= 3);
     522     10960682 :       break;
     523              : 
     524            0 :     case OPT_LEVELS_3_PLUS_AND_SIZE:
     525            0 :       enabled = (level >= 3 || size);
     526            0 :       break;
     527              : 
     528              :     case OPT_LEVELS_SIZE:
     529              :       enabled = size;
     530              :       break;
     531              : 
     532      1934238 :     case OPT_LEVELS_FAST:
     533      1934238 :       enabled = fast;
     534      1934238 :       break;
     535              : 
     536            0 :     case OPT_LEVELS_NONE:
     537            0 :     default:
     538            0 :       gcc_unreachable ();
     539              :     }
     540              : 
     541     67698330 :   if (enabled)
     542     52439401 :     handle_generated_option (opts, opts_set, default_opt->opt_index,
     543     52439401 :                              default_opt->arg, default_opt->value,
     544              :                              lang_mask,
     545              :                              static_cast<int> (diagnostics::kind::unspecified),
     546              :                              loc,
     547              :                              handlers, true, dc);
     548     25574865 :   else if (default_opt->arg == NULL
     549     25574865 :            && !option->cl_reject_negative
     550     24346822 :            && !(option->flags & CL_PARAMS))
     551     21274497 :     handle_generated_option (opts, opts_set, default_opt->opt_index,
     552     21274497 :                              default_opt->arg, !default_opt->value,
     553              :                              lang_mask,
     554              :                              static_cast<int> (diagnostics::kind::unspecified),
     555              :                              loc,
     556              :                              handlers, true, dc);
     557     78014266 : }
     558              : 
     559              : /* As indicated by the optimization level LEVEL (-Os if SIZE is set,
     560              :    -Ofast if FAST is set), apply the options in array DEFAULT_OPTS to
     561              :    OPTS and OPTS_SET, diagnostic context DC, location LOC, with
     562              :    language mask LANG_MASK and option handlers HANDLERS.  */
     563              : 
     564              : static void
     565      1289492 : maybe_default_options (struct gcc_options *opts,
     566              :                        struct gcc_options *opts_set,
     567              :                        const struct default_options *default_opts,
     568              :                        int level, bool size, bool fast, bool debug,
     569              :                        unsigned int lang_mask,
     570              :                        const struct cl_option_handlers *handlers,
     571              :                        location_t loc,
     572              :                        diagnostics::context *dc)
     573              : {
     574      1289492 :   size_t i;
     575              : 
     576     79303758 :   for (i = 0; default_opts[i].levels != OPT_LEVELS_NONE; i++)
     577     78014266 :     maybe_default_option (opts, opts_set, &default_opts[i],
     578              :                           level, size, fast, debug,
     579              :                           lang_mask, handlers, loc, dc);
     580      1289492 : }
     581              : 
     582              : /* Table of options enabled by default at different levels.
     583              :    Please keep this list sorted by level and alphabetized within
     584              :    each level; this makes it easier to keep the documentation
     585              :    in sync.  */
     586              : 
     587              : static const struct default_options default_options_table[] =
     588              :   {
     589              :     /* -O1 and -Og optimizations.  */
     590              :     { OPT_LEVELS_1_PLUS, OPT_fbit_tests, NULL, 1 },
     591              :     { OPT_LEVELS_1_PLUS, OPT_fcombine_stack_adjustments, NULL, 1 },
     592              :     { OPT_LEVELS_1_PLUS, OPT_fcompare_elim, NULL, 1 },
     593              :     { OPT_LEVELS_1_PLUS, OPT_fcprop_registers, NULL, 1 },
     594              :     { OPT_LEVELS_1_PLUS, OPT_fdefer_pop, NULL, 1 },
     595              :     { OPT_LEVELS_1_PLUS, OPT_fforward_propagate, NULL, 1 },
     596              :     { OPT_LEVELS_1_PLUS, OPT_fguess_branch_probability, NULL, 1 },
     597              :     { OPT_LEVELS_1_PLUS, OPT_fipa_profile, NULL, 1 },
     598              :     { OPT_LEVELS_1_PLUS, OPT_fipa_pure_const, NULL, 1 },
     599              :     { OPT_LEVELS_1_PLUS, OPT_fipa_reference, NULL, 1 },
     600              :     { OPT_LEVELS_1_PLUS, OPT_fipa_reference_addressable, NULL, 1 },
     601              :     { OPT_LEVELS_1_PLUS, OPT_fjump_tables, NULL, 1 },
     602              :     { OPT_LEVELS_1_PLUS, OPT_fmerge_constants, NULL, 1 },
     603              :     { OPT_LEVELS_1_PLUS, OPT_fomit_frame_pointer, NULL, 1 },
     604              :     { OPT_LEVELS_1_PLUS, OPT_freorder_blocks, NULL, 1 },
     605              :     { OPT_LEVELS_1_PLUS, OPT_fshrink_wrap, NULL, 1 },
     606              :     { OPT_LEVELS_1_PLUS, OPT_fsplit_wide_types, NULL, 1 },
     607              :     { OPT_LEVELS_1_PLUS, OPT_fthread_jumps, NULL, 1 },
     608              :     { OPT_LEVELS_1_PLUS, OPT_ftree_builtin_call_dce, NULL, 1 },
     609              :     { OPT_LEVELS_1_PLUS, OPT_ftree_ccp, NULL, 1 },
     610              :     { OPT_LEVELS_1_PLUS, OPT_ftree_ch, NULL, 1 },
     611              :     { OPT_LEVELS_1_PLUS, OPT_ftree_coalesce_vars, NULL, 1 },
     612              :     { OPT_LEVELS_1_PLUS, OPT_ftree_copy_prop, NULL, 1 },
     613              :     { OPT_LEVELS_1_PLUS, OPT_ftree_dce, NULL, 1 },
     614              :     { OPT_LEVELS_1_PLUS, OPT_ftree_dominator_opts, NULL, 1 },
     615              :     { OPT_LEVELS_1_PLUS, OPT_ftree_fre, NULL, 1 },
     616              :     { OPT_LEVELS_1_PLUS, OPT_ftree_sink, NULL, 1 },
     617              :     { OPT_LEVELS_1_PLUS, OPT_ftree_slsr, NULL, 1 },
     618              :     { OPT_LEVELS_1_PLUS, OPT_ftree_ter, NULL, 1 },
     619              :     { OPT_LEVELS_1_PLUS, OPT_fvar_tracking, NULL, 1 },
     620              : 
     621              :     /* -O1 (and not -Og) optimizations.  */
     622              :     { OPT_LEVELS_1_PLUS_NOT_DEBUG, OPT_fbranch_count_reg, NULL, 1 },
     623              : #if DELAY_SLOTS
     624              :     { OPT_LEVELS_1_PLUS_NOT_DEBUG, OPT_fdelayed_branch, NULL, 1 },
     625              : #endif
     626              :     { OPT_LEVELS_1_PLUS_NOT_DEBUG, OPT_fdse, NULL, 1 },
     627              :     { OPT_LEVELS_1_PLUS_NOT_DEBUG, OPT_fif_conversion, NULL, 1 },
     628              :     { OPT_LEVELS_1_PLUS_NOT_DEBUG, OPT_fif_conversion2, NULL, 1 },
     629              :     { OPT_LEVELS_1_PLUS_NOT_DEBUG, OPT_finline_functions_called_once, NULL, 1 },
     630              :     { OPT_LEVELS_1_PLUS_NOT_DEBUG, OPT_fmove_loop_invariants, NULL, 1 },
     631              :     { OPT_LEVELS_1_PLUS_NOT_DEBUG, OPT_fmove_loop_stores, NULL, 1 },
     632              :     { OPT_LEVELS_1_PLUS_NOT_DEBUG, OPT_fssa_phiopt, NULL, 1 },
     633              :     { OPT_LEVELS_1_PLUS_NOT_DEBUG, OPT_fipa_modref, NULL, 1 },
     634              :     { OPT_LEVELS_1_PLUS_NOT_DEBUG, OPT_ftree_bit_ccp, NULL, 1 },
     635              :     { OPT_LEVELS_1_PLUS_NOT_DEBUG, OPT_ftree_dse, NULL, 1 },
     636              :     { OPT_LEVELS_1_PLUS_NOT_DEBUG, OPT_ftree_pta, NULL, 1 },
     637              :     { OPT_LEVELS_1_PLUS_NOT_DEBUG, OPT_ftree_sra, NULL, 1 },
     638              : 
     639              :     /* -O2 and -Os optimizations.  */
     640              :     { OPT_LEVELS_2_PLUS, OPT_fcaller_saves, NULL, 1 },
     641              :     { OPT_LEVELS_2_PLUS, OPT_fcode_hoisting, NULL, 1 },
     642              :     { OPT_LEVELS_2_PLUS, OPT_fcrossjumping, NULL, 1 },
     643              :     { OPT_LEVELS_2_PLUS, OPT_fcse_follow_jumps, NULL, 1 },
     644              :     { OPT_LEVELS_2_PLUS, OPT_fdep_fusion, NULL, 1 },
     645              :     { OPT_LEVELS_2_PLUS, OPT_fdevirtualize, NULL, 1 },
     646              :     { OPT_LEVELS_2_PLUS, OPT_fdevirtualize_speculatively, NULL, 1 },
     647              :     { OPT_LEVELS_2_PLUS, OPT_fexpensive_optimizations, NULL, 1 },
     648              :     { OPT_LEVELS_2_PLUS, OPT_fext_dce, NULL, 1 },
     649              :     { OPT_LEVELS_2_PLUS, OPT_fgcse, NULL, 1 },
     650              :     { OPT_LEVELS_2_PLUS, OPT_fhoist_adjacent_loads, NULL, 1 },
     651              :     { OPT_LEVELS_2_PLUS, OPT_findirect_inlining, NULL, 1 },
     652              :     { OPT_LEVELS_2_PLUS, OPT_finline_small_functions, NULL, 1 },
     653              :     { OPT_LEVELS_2_PLUS, OPT_fipa_bit_cp, NULL, 1 },
     654              :     { OPT_LEVELS_2_PLUS, OPT_fipa_cp, NULL, 1 },
     655              :     { OPT_LEVELS_2_PLUS, OPT_fipa_icf, NULL, 1 },
     656              :     { OPT_LEVELS_2_PLUS, OPT_fipa_ra, NULL, 1 },
     657              :     { OPT_LEVELS_2_PLUS, OPT_fipa_sra, NULL, 1 },
     658              :     { OPT_LEVELS_2_PLUS, OPT_fipa_vrp, NULL, 1 },
     659              :     { OPT_LEVELS_2_PLUS, OPT_fisolate_erroneous_paths_dereference, NULL, 1 },
     660              :     { OPT_LEVELS_2_PLUS, OPT_flra_remat, NULL, 1 },
     661              :     { OPT_LEVELS_2_PLUS, OPT_foptimize_sibling_calls, NULL, 1 },
     662              :     { OPT_LEVELS_2_PLUS, OPT_fpartial_inlining, NULL, 1 },
     663              :     { OPT_LEVELS_2_PLUS, OPT_fpeephole2, NULL, 1 },
     664              :     { OPT_LEVELS_2_PLUS, OPT_freorder_functions, NULL, 1 },
     665              :     { OPT_LEVELS_2_PLUS, OPT_frerun_cse_after_loop, NULL, 1 },
     666              :     { OPT_LEVELS_2_PLUS, OPT_fspeculatively_call_stored_functions, NULL, 1 },
     667              : #ifdef INSN_SCHEDULING
     668              :     { OPT_LEVELS_2_PLUS, OPT_fschedule_insns2, NULL, 1 },
     669              : #endif
     670              :     { OPT_LEVELS_2_PLUS, OPT_fstrict_aliasing, NULL, 1 },
     671              :     { OPT_LEVELS_2_PLUS, OPT_fstore_merging, NULL, 1 },
     672              :     { OPT_LEVELS_2_PLUS, OPT_ftree_pre, NULL, 1 },
     673              :     { OPT_LEVELS_2_PLUS, OPT_ftree_switch_conversion, NULL, 1 },
     674              :     { OPT_LEVELS_2_PLUS, OPT_ftree_tail_merge, NULL, 1 },
     675              :     { OPT_LEVELS_2_PLUS, OPT_ftree_vrp, NULL, 1 },
     676              :     { OPT_LEVELS_2_PLUS, OPT_fvect_cost_model_, NULL,
     677              :       VECT_COST_MODEL_VERY_CHEAP },
     678              :     { OPT_LEVELS_2_PLUS, OPT_finline_functions, NULL, 1 },
     679              :     { OPT_LEVELS_2_PLUS, OPT_ftree_loop_distribute_patterns, NULL, 1 },
     680              :     { OPT_LEVELS_2_PLUS, OPT_foptimize_crc, NULL, 1 },
     681              :     { OPT_LEVELS_2_PLUS, OPT_flate_combine_instructions, NULL, 1 },
     682              : 
     683              :     /* -O2 and above optimizations, but not -Os or -Og.  */
     684              :     { OPT_LEVELS_2_PLUS_SPEED_ONLY, OPT_falign_functions, NULL, 1 },
     685              :     { OPT_LEVELS_2_PLUS_SPEED_ONLY, OPT_falign_jumps, NULL, 1 },
     686              :     { OPT_LEVELS_2_PLUS_SPEED_ONLY, OPT_falign_labels, NULL, 1 },
     687              :     { OPT_LEVELS_2_PLUS_SPEED_ONLY, OPT_falign_loops, NULL, 1 },
     688              :     { OPT_LEVELS_2_PLUS_SPEED_ONLY, OPT_fduplicate_switch_dispatch, NULL, 1 },
     689              :     { OPT_LEVELS_2_PLUS_SPEED_ONLY, OPT_foptimize_strlen, NULL, 1 },
     690              :     { OPT_LEVELS_2_PLUS_SPEED_ONLY, OPT_freorder_blocks_algorithm_, NULL,
     691              :       REORDER_BLOCKS_ALGORITHM_STC },
     692              :     { OPT_LEVELS_2_PLUS_SPEED_ONLY, OPT_ftree_loop_vectorize, NULL, 1 },
     693              :     { OPT_LEVELS_2_PLUS_SPEED_ONLY, OPT_ftree_slp_vectorize, NULL, 1 },
     694              :     { OPT_LEVELS_2_PLUS_SPEED_ONLY, OPT_fopenmp_target_simd_clone_, NULL,
     695              :       OMP_TARGET_SIMD_CLONE_NOHOST },
     696              : #ifdef INSN_SCHEDULING
     697              :   /* Only run the pre-regalloc scheduling pass if optimizing for speed.  */
     698              :     { OPT_LEVELS_2_PLUS_SPEED_ONLY, OPT_fschedule_insns, NULL, 1 },
     699              : #endif
     700              : 
     701              :     /* -O3 and -Os optimizations.  */
     702              : 
     703              :     /* -O3 optimizations.  */
     704              :     { OPT_LEVELS_3_PLUS, OPT_fgcse_after_reload, NULL, 1 },
     705              :     { OPT_LEVELS_3_PLUS, OPT_fipa_cp_clone, NULL, 1 },
     706              :     { OPT_LEVELS_3_PLUS, OPT_floop_interchange, NULL, 1 },
     707              :     { OPT_LEVELS_3_PLUS, OPT_floop_unroll_and_jam, NULL, 1 },
     708              :     { OPT_LEVELS_3_PLUS, OPT_fpeel_loops, NULL, 1 },
     709              :     { OPT_LEVELS_3_PLUS, OPT_fpredictive_commoning, NULL, 1 },
     710              :     { OPT_LEVELS_3_PLUS, OPT_fsplit_loops, NULL, 1 },
     711              :     { OPT_LEVELS_3_PLUS, OPT_ftree_loop_distribution, NULL, 1 },
     712              :     { OPT_LEVELS_3_PLUS, OPT_ftree_partial_pre, NULL, 1 },
     713              :     { OPT_LEVELS_3_PLUS, OPT_funswitch_loops, NULL, 1 },
     714              :     { OPT_LEVELS_3_PLUS, OPT_fvect_cost_model_, NULL, VECT_COST_MODEL_DYNAMIC },
     715              :     { OPT_LEVELS_3_PLUS, OPT_fversion_loops_for_strides, NULL, 1 },
     716              : 
     717              :     /* -O3 parameters.  */
     718              :     { OPT_LEVELS_3_PLUS, OPT__param_max_inline_insns_auto_, NULL, 30 },
     719              :     { OPT_LEVELS_3_PLUS, OPT__param_early_inlining_insns_, NULL, 14 },
     720              :     { OPT_LEVELS_3_PLUS, OPT__param_inline_heuristics_hint_percent_, NULL, 600 },
     721              :     { OPT_LEVELS_3_PLUS, OPT__param_inline_min_speedup_, NULL, 15 },
     722              :     { OPT_LEVELS_3_PLUS, OPT__param_max_inline_insns_single_, NULL, 200 },
     723              : 
     724              :     /* -Ofast adds optimizations to -O3.  */
     725              :     { OPT_LEVELS_FAST, OPT_ffast_math, NULL, 1 },
     726              :     { OPT_LEVELS_FAST, OPT_fallow_store_data_races, NULL, 1 },
     727              :     { OPT_LEVELS_FAST, OPT_fsemantic_interposition, NULL, 0 },
     728              : 
     729              :     { OPT_LEVELS_NONE, 0, NULL, 0 }
     730              :   };
     731              : 
     732              : /* Default the options in OPTS and OPTS_SET based on the optimization
     733              :    settings in DECODED_OPTIONS and DECODED_OPTIONS_COUNT.  */
     734              : void
     735       644746 : default_options_optimization (struct gcc_options *opts,
     736              :                               struct gcc_options *opts_set,
     737              :                               struct cl_decoded_option *decoded_options,
     738              :                               unsigned int decoded_options_count,
     739              :                               location_t loc,
     740              :                               unsigned int lang_mask,
     741              :                               const struct cl_option_handlers *handlers,
     742              :                               diagnostics::context *dc)
     743              : {
     744       644746 :   unsigned int i;
     745       644746 :   int opt2;
     746       644746 :   bool openacc_mode = false;
     747              : 
     748              :   /* Scan to see what optimization level has been specified.  That will
     749              :      determine the default value of many flags.  */
     750     11032330 :   for (i = 1; i < decoded_options_count; i++)
     751              :     {
     752     10387584 :       struct cl_decoded_option *opt = &decoded_options[i];
     753     10387584 :       switch (opt->opt_index)
     754              :         {
     755       578240 :         case OPT_O:
     756       578240 :           if (*opt->arg == '\0')
     757              :             {
     758        14641 :               opts->x_optimize = 1;
     759        14641 :               opts->x_optimize_size = 0;
     760        14641 :               opts->x_optimize_fast = 0;
     761        14641 :               opts->x_optimize_debug = 0;
     762              :             }
     763              :           else
     764              :             {
     765       563599 :               const int optimize_val = integral_argument (opt->arg);
     766       563599 :               if (optimize_val == -1)
     767            0 :                 error_at (loc, "argument to %<-O%> should be a non-negative "
     768              :                                "integer, %<g%>, %<s%>, %<z%> or %<fast%>");
     769              :               else
     770              :                 {
     771       563599 :                   opts->x_optimize = optimize_val;
     772       563599 :                   if ((unsigned int) opts->x_optimize > 255)
     773            3 :                     opts->x_optimize = 255;
     774       563599 :                   opts->x_optimize_size = 0;
     775       563599 :                   opts->x_optimize_fast = 0;
     776       563599 :                   opts->x_optimize_debug = 0;
     777              :                 }
     778              :             }
     779              :           break;
     780              : 
     781        16121 :         case OPT_Os:
     782        16121 :           opts->x_optimize_size = 1;
     783              : 
     784              :           /* Optimizing for size forces optimize to be 2.  */
     785        16121 :           opts->x_optimize = 2;
     786        16121 :           opts->x_optimize_fast = 0;
     787        16121 :           opts->x_optimize_debug = 0;
     788        16121 :           break;
     789              : 
     790           21 :         case OPT_Oz:
     791           21 :           opts->x_optimize_size = 2;
     792              : 
     793              :           /* Optimizing for size forces optimize to be 2.  */
     794           21 :           opts->x_optimize = 2;
     795           21 :           opts->x_optimize_fast = 0;
     796           21 :           opts->x_optimize_debug = 0;
     797           21 :           break;
     798              : 
     799          733 :         case OPT_Ofast:
     800              :           /* -Ofast only adds flags to -O3.  */
     801          733 :           opts->x_optimize_size = 0;
     802          733 :           opts->x_optimize = 3;
     803          733 :           opts->x_optimize_fast = 1;
     804          733 :           opts->x_optimize_debug = 0;
     805          733 :           break;
     806              : 
     807          722 :         case OPT_Og:
     808              :           /* -Og selects optimization level 1.  */
     809          722 :           opts->x_optimize_size = 0;
     810          722 :           opts->x_optimize = 1;
     811          722 :           opts->x_optimize_fast = 0;
     812          722 :           opts->x_optimize_debug = 1;
     813          722 :           break;
     814              : 
     815        24475 :         case OPT_fopenacc:
     816        24475 :           if (opt->value)
     817     10387584 :             openacc_mode = true;
     818              :           break;
     819              : 
     820              :         default:
     821              :           /* Ignore other options in this prescan.  */
     822              :           break;
     823              :         }
     824              :     }
     825              : 
     826       644746 :   maybe_default_options (opts, opts_set, default_options_table,
     827       644746 :                          opts->x_optimize, opts->x_optimize_size,
     828       644746 :                          opts->x_optimize_fast, opts->x_optimize_debug,
     829              :                          lang_mask, handlers, loc, dc);
     830              : 
     831              :   /* -O2 param settings.  */
     832       644746 :   opt2 = (opts->x_optimize >= 2);
     833              : 
     834       644746 :   if (openacc_mode)
     835         3339 :     SET_OPTION_IF_UNSET (opts, opts_set, flag_ipa_pta, true);
     836              : 
     837              :   /* Track fields in field-sensitive alias analysis.  */
     838       644746 :   if (opt2)
     839       499335 :     SET_OPTION_IF_UNSET (opts, opts_set, param_max_fields_for_field_sensitive,
     840              :                          100);
     841              : 
     842       644746 :   if (opts->x_optimize_size)
     843              :     /* We want to crossjump as much as possible.  */
     844        15967 :     SET_OPTION_IF_UNSET (opts, opts_set, param_min_crossjump_insns, 1);
     845              : 
     846              :   /* Restrict the amount of work combine does at -Og while retaining
     847              :      most of its useful transforms.  */
     848       644746 :   if (opts->x_optimize_debug)
     849          698 :     SET_OPTION_IF_UNSET (opts, opts_set, param_max_combine_insns, 2);
     850              : 
     851              :   /* Allow default optimizations to be specified on a per-machine basis.  */
     852       644746 :   maybe_default_options (opts, opts_set,
     853              :                          targetm_common.option_optimization_table,
     854              :                          opts->x_optimize, opts->x_optimize_size,
     855       644746 :                          opts->x_optimize_fast, opts->x_optimize_debug,
     856              :                          lang_mask, handlers, loc, dc);
     857       644746 : }
     858              : 
     859              : /* Control IPA optimizations based on different live patching LEVEL.  */
     860              : static void
     861           20 : control_options_for_live_patching (struct gcc_options *opts,
     862              :                                    struct gcc_options *opts_set,
     863              :                                    enum live_patching_level level,
     864              :                                    location_t loc)
     865              : {
     866           20 :   gcc_assert (level > LIVE_PATCHING_NONE);
     867              : 
     868           20 :   switch (level)
     869              :     {
     870            3 :     case LIVE_PATCHING_INLINE_ONLY_STATIC:
     871              : #define LIVE_PATCHING_OPTION "-flive-patching=inline-only-static"
     872            3 :       if (opts_set->x_flag_ipa_cp_clone && opts->x_flag_ipa_cp_clone)
     873            0 :         error_at (loc, "%qs is incompatible with %qs",
     874              :                   "-fipa-cp-clone", LIVE_PATCHING_OPTION);
     875              :       else
     876            3 :         opts->x_flag_ipa_cp_clone = 0;
     877              : 
     878            3 :       if (opts_set->x_flag_ipa_sra && opts->x_flag_ipa_sra)
     879            0 :         error_at (loc, "%qs is incompatible with %qs",
     880              :                   "-fipa-sra", LIVE_PATCHING_OPTION);
     881              :       else
     882            3 :         opts->x_flag_ipa_sra = 0;
     883              : 
     884            3 :       if (opts_set->x_flag_partial_inlining && opts->x_flag_partial_inlining)
     885            0 :         error_at (loc, "%qs is incompatible with %qs",
     886              :                   "-fpartial-inlining", LIVE_PATCHING_OPTION);
     887              :       else
     888            3 :         opts->x_flag_partial_inlining = 0;
     889              : 
     890            3 :       if (opts_set->x_flag_ipa_cp && opts->x_flag_ipa_cp)
     891            0 :         error_at (loc, "%qs is incompatible with %qs",
     892              :                   "-fipa-cp", LIVE_PATCHING_OPTION);
     893              :       else
     894            3 :         opts->x_flag_ipa_cp = 0;
     895              : 
     896              :       /* FALLTHROUGH.  */
     897           20 :     case LIVE_PATCHING_INLINE_CLONE:
     898              : #undef LIVE_PATCHING_OPTION
     899              : #define LIVE_PATCHING_OPTION "-flive-patching=inline-only-static|inline-clone"
     900              :       /* live patching should disable whole-program optimization.  */
     901           20 :       if (opts_set->x_flag_whole_program && opts->x_flag_whole_program)
     902            1 :         error_at (loc, "%qs is incompatible with %qs",
     903              :                   "-fwhole-program", LIVE_PATCHING_OPTION);
     904              :       else
     905           19 :         opts->x_flag_whole_program = 0;
     906              : 
     907              :       /* visibility change should be excluded by !flag_whole_program
     908              :          && !in_lto_p && !flag_ipa_cp_clone && !flag_ipa_sra
     909              :          && !flag_partial_inlining.  */
     910              : 
     911           20 :       if (opts_set->x_flag_ipa_pta && opts->x_flag_ipa_pta)
     912            0 :         error_at (loc, "%qs is incompatible with %qs",
     913              :                   "-fipa-pta", LIVE_PATCHING_OPTION);
     914              :       else
     915           20 :         opts->x_flag_ipa_pta = 0;
     916              : 
     917           20 :       if (opts_set->x_flag_ipa_reference && opts->x_flag_ipa_reference)
     918            0 :         error_at (loc, "%qs is incompatible with %qs",
     919              :                   "-fipa-reference", LIVE_PATCHING_OPTION);
     920              :       else
     921           20 :         opts->x_flag_ipa_reference = 0;
     922              : 
     923           20 :       if (opts_set->x_flag_ipa_ra && opts->x_flag_ipa_ra)
     924            0 :         error_at (loc, "%qs is incompatible with %qs",
     925              :                   "-fipa-ra", LIVE_PATCHING_OPTION);
     926              :       else
     927           20 :         opts->x_flag_ipa_ra = 0;
     928              : 
     929           20 :       if (opts_set->x_flag_ipa_icf && opts->x_flag_ipa_icf)
     930            0 :         error_at (loc, "%qs is incompatible with %qs",
     931              :                   "-fipa-icf", LIVE_PATCHING_OPTION);
     932              :       else
     933           20 :         opts->x_flag_ipa_icf = 0;
     934              : 
     935           20 :       if (opts_set->x_flag_ipa_icf_functions && opts->x_flag_ipa_icf_functions)
     936            0 :         error_at (loc, "%qs is incompatible with %qs",
     937              :                   "-fipa-icf-functions", LIVE_PATCHING_OPTION);
     938              :       else
     939           20 :         opts->x_flag_ipa_icf_functions = 0;
     940              : 
     941           20 :       if (opts_set->x_flag_ipa_icf_variables && opts->x_flag_ipa_icf_variables)
     942            0 :         error_at (loc, "%qs is incompatible with %qs",
     943              :                   "-fipa-icf-variables", LIVE_PATCHING_OPTION);
     944              :       else
     945           20 :         opts->x_flag_ipa_icf_variables = 0;
     946              : 
     947           20 :       if (opts_set->x_flag_ipa_bit_cp && opts->x_flag_ipa_bit_cp)
     948            0 :         error_at (loc, "%qs is incompatible with %qs",
     949              :                   "-fipa-bit-cp", LIVE_PATCHING_OPTION);
     950              :       else
     951           20 :         opts->x_flag_ipa_bit_cp = 0;
     952              : 
     953           20 :       if (opts_set->x_flag_ipa_vrp && opts->x_flag_ipa_vrp)
     954            0 :         error_at (loc, "%qs is incompatible with %qs",
     955              :                   "-fipa-vrp", LIVE_PATCHING_OPTION);
     956              :       else
     957           20 :         opts->x_flag_ipa_vrp = 0;
     958              : 
     959           20 :       if (opts_set->x_flag_ipa_pure_const && opts->x_flag_ipa_pure_const)
     960            0 :         error_at (loc, "%qs is incompatible with %qs",
     961              :                   "-fipa-pure-const", LIVE_PATCHING_OPTION);
     962              :       else
     963           20 :         opts->x_flag_ipa_pure_const = 0;
     964              : 
     965           20 :       if (opts_set->x_flag_ipa_modref && opts->x_flag_ipa_modref)
     966            0 :         error_at (loc,
     967              :                   "%<-fipa-modref%> is incompatible with %qs",
     968              :                   LIVE_PATCHING_OPTION);
     969              :       else
     970           20 :         opts->x_flag_ipa_modref = 0;
     971              : 
     972              :       /* FIXME: disable unreachable code removal.  */
     973              : 
     974              :       /* discovery of functions/variables with no address taken.  */
     975           20 :       if (opts_set->x_flag_ipa_reference_addressable
     976            0 :           && opts->x_flag_ipa_reference_addressable)
     977            0 :         error_at (loc, "%qs is incompatible with %qs",
     978              :                   "-fipa-reference-addressable", LIVE_PATCHING_OPTION);
     979              :       else
     980           20 :         opts->x_flag_ipa_reference_addressable = 0;
     981              : 
     982              :       /* ipa stack alignment propagation.  */
     983           20 :       if (opts_set->x_flag_ipa_stack_alignment
     984            0 :           && opts->x_flag_ipa_stack_alignment)
     985            0 :         error_at (loc, "%qs is incompatible with %qs",
     986              :                   "-fipa-stack-alignment", LIVE_PATCHING_OPTION);
     987              :       else
     988           20 :         opts->x_flag_ipa_stack_alignment = 0;
     989           20 :       break;
     990            0 :     default:
     991            0 :       gcc_unreachable ();
     992              :     }
     993              : 
     994              : #undef LIVE_PATCHING_OPTION
     995           20 : }
     996              : 
     997              : /* --help option argument if set.  */
     998              : vec<const char *> help_option_arguments;
     999              : 
    1000              : /* Return the string name describing a sanitizer argument which has been
    1001              :    provided on the command line and has set this particular flag.  */
    1002              : const char *
    1003          208 : find_sanitizer_argument (struct gcc_options *opts,
    1004              :                          sanitize_code_type flags)
    1005              : {
    1006          706 :   for (int i = 0; sanitizer_opts[i].name != NULL; ++i)
    1007              :     {
    1008              :       /* Need to find the sanitizer_opts element which:
    1009              :          a) Could have set the flags requested.
    1010              :          b) Has been set on the command line.
    1011              : 
    1012              :          Can have (a) without (b) if the flag requested is e.g.
    1013              :          SANITIZE_ADDRESS, since both -fsanitize=address and
    1014              :          -fsanitize=kernel-address set this flag.
    1015              : 
    1016              :          Can have (b) without (a) by requesting more than one sanitizer on the
    1017              :          command line.  */
    1018          706 :       if ((sanitizer_opts[i].flag & opts->x_flag_sanitize)
    1019              :           != sanitizer_opts[i].flag)
    1020          352 :         continue;
    1021          354 :       if ((sanitizer_opts[i].flag & flags) != flags)
    1022          146 :         continue;
    1023              :       return sanitizer_opts[i].name;
    1024              :     }
    1025              :   return NULL;
    1026              : }
    1027              : 
    1028              : 
    1029              : /* Report an error to the user about sanitizer options they have requested
    1030              :    which have set conflicting flags.
    1031              : 
    1032              :    LEFT and RIGHT indicate sanitizer flags which conflict with each other, this
    1033              :    function reports an error if both have been set in OPTS->x_flag_sanitize and
    1034              :    ensures the error identifies the requested command line options that have
    1035              :    set these flags.  */
    1036              : static void
    1037      5157968 : report_conflicting_sanitizer_options (struct gcc_options *opts, location_t loc,
    1038              :                                       sanitize_code_type left,
    1039              :                                       sanitize_code_type right)
    1040              : {
    1041      5157968 :   sanitize_code_type left_seen = (opts->x_flag_sanitize & left);
    1042      5157968 :   sanitize_code_type right_seen = (opts->x_flag_sanitize & right);
    1043      5157968 :   if (left_seen && right_seen)
    1044              :     {
    1045          104 :       const char* left_arg = find_sanitizer_argument (opts, left_seen);
    1046          104 :       const char* right_arg = find_sanitizer_argument (opts, right_seen);
    1047          104 :       gcc_assert (left_arg && right_arg);
    1048          104 :       error_at (loc,
    1049              :                 "%<-fsanitize=%s%> is incompatible with %<-fsanitize=%s%>",
    1050              :                 left_arg, right_arg);
    1051              :     }
    1052      5157968 : }
    1053              : 
    1054              : /* Validate from OPTS and OPTS_SET that when -fipa-reorder-for-locality is
    1055              :    enabled no explicit -flto-partition is also passed as the locality cloning
    1056              :    pass uses its own partitioning scheme.  */
    1057              : 
    1058              : static void
    1059       644746 : validate_ipa_reorder_locality_lto_partition (struct gcc_options *opts,
    1060              :                                              struct gcc_options *opts_set)
    1061              : {
    1062       644746 :   static bool validated_p = false;
    1063              : 
    1064       644746 :   if (opts_set->x_flag_lto_partition)
    1065              :     {
    1066        15946 :       if (opts->x_flag_ipa_reorder_for_locality && !validated_p)
    1067            0 :         error ("%<-fipa-reorder-for-locality%> is incompatible with"
    1068              :                " an explicit %qs option", "-flto-partition");
    1069              :     }
    1070       644746 :   validated_p = true;
    1071       644746 : }
    1072              : 
    1073              : /* If OPTS.x_dump_base_name doesn't contain any directory separators
    1074              :    and has not had OPTS.x_dump_dir_name prepended to it, generate
    1075              :    a new string in opts_obstack that has the dump_dir_name prepended to
    1076              :    the dump_base_name.  */
    1077              : 
    1078              : const char *
    1079       294462 : maybe_prepend_dump_dir_name (const gcc_options &opts)
    1080              : {
    1081       294462 :   const char *sep = opts.x_dump_base_name;
    1082              : 
    1083      4004755 :   for (; *sep; sep++)
    1084      3731412 :     if (IS_DIR_SEPARATOR (*sep))
    1085              :       break;
    1086              : 
    1087       294462 :   if (*sep)
    1088              :     {
    1089              :       /* If dump_base_name contains subdirectories, don't prepend
    1090              :          anything.  */
    1091              :       return nullptr;
    1092              :     }
    1093              : 
    1094       273343 :   if (opts.x_dump_dir_name)
    1095              :     {
    1096              :       /* We have a DUMP_DIR_NAME, prepend that.  */
    1097       110011 :       return opts_concat (opts.x_dump_dir_name,
    1098       110011 :                           opts.x_dump_base_name, NULL);
    1099              :     }
    1100              : 
    1101              :   return nullptr;
    1102              : }
    1103              : 
    1104              : /* After all options at LOC have been read into OPTS and OPTS_SET,
    1105              :    finalize settings of those options and diagnose incompatible
    1106              :    combinations.  */
    1107              : void
    1108       644746 : finish_options (struct gcc_options *opts, struct gcc_options *opts_set,
    1109              :                 location_t loc)
    1110              : {
    1111       644746 :   if (opts->x_dump_base_name
    1112       641909 :       && ! opts->x_dump_base_name_prefixed)
    1113              :     {
    1114       588686 :       if (const char *prepended_dump_base_name
    1115       294343 :           = maybe_prepend_dump_dir_name (*opts))
    1116       110011 :         opts->x_dump_base_name = prepended_dump_base_name;
    1117              : 
    1118              :       /* It is definitely prefixed now.  */
    1119       294343 :       opts->x_dump_base_name_prefixed = true;
    1120              :     }
    1121              : 
    1122              :   /* Handle related options for unit-at-a-time, toplevel-reorder, and
    1123              :      section-anchors.  */
    1124       644746 :   if (!opts->x_flag_unit_at_a_time)
    1125              :     {
    1126            5 :       if (opts->x_flag_section_anchors && opts_set->x_flag_section_anchors)
    1127            0 :         error_at (loc, "section anchors must be disabled when unit-at-a-time "
    1128              :                   "is disabled");
    1129            5 :       opts->x_flag_section_anchors = 0;
    1130            5 :       if (opts->x_flag_toplevel_reorder == 1)
    1131            0 :         error_at (loc, "toplevel reorder must be disabled when unit-at-a-time "
    1132              :                   "is disabled");
    1133            5 :       opts->x_flag_toplevel_reorder = 0;
    1134              :     }
    1135              : 
    1136              :   /* -fself-test depends on the state of the compiler prior to
    1137              :      compiling anything.  Ideally it should be run on an empty source
    1138              :      file.  However, in case we get run with actual source, assume
    1139              :      -fsyntax-only which will inhibit any compiler initialization
    1140              :      which may confuse the self tests.  */
    1141       644746 :   if (opts->x_flag_self_test)
    1142            5 :     opts->x_flag_syntax_only = 1;
    1143              : 
    1144       644746 :   if (opts->x_flag_tm && opts->x_flag_non_call_exceptions)
    1145            3 :     sorry ("transactional memory is not supported with non-call exceptions");
    1146              : 
    1147              :   /* Unless the user has asked for section anchors, we disable toplevel
    1148              :      reordering at -O0 to disable transformations that might be surprising
    1149              :      to end users and to get -fno-toplevel-reorder tested.  */
    1150       644746 :   if (!opts->x_optimize
    1151       115870 :       && opts->x_flag_toplevel_reorder == 2
    1152       115636 :       && !(opts->x_flag_section_anchors && opts_set->x_flag_section_anchors))
    1153              :     {
    1154       115636 :       opts->x_flag_toplevel_reorder = 0;
    1155       115636 :       opts->x_flag_section_anchors = 0;
    1156              :     }
    1157       644746 :   if (!opts->x_flag_toplevel_reorder)
    1158              :     {
    1159       135445 :       if (opts->x_flag_section_anchors && opts_set->x_flag_section_anchors)
    1160            0 :         error_at (loc, "section anchors must be disabled when toplevel reorder"
    1161              :                   " is disabled");
    1162       135445 :       opts->x_flag_section_anchors = 0;
    1163              :     }
    1164              : 
    1165       644746 :   if (opts->x_flag_hardened)
    1166              :     {
    1167           92 :       if (!opts_set->x_flag_auto_var_init)
    1168           88 :         opts->x_flag_auto_var_init
    1169           88 :           = auto_init_type (opts->x_flag_auto_var_init | AUTO_INIT_ZERO);
    1170            4 :       else if ((opts->x_flag_auto_var_init & ~AUTO_INIT_CXX26)
    1171              :                != AUTO_INIT_ZERO)
    1172            4 :         warning_at (loc, OPT_Whardened,
    1173              :                     "%<-ftrivial-auto-var-init=zero%> is not enabled by "
    1174              :                     "%<-fhardened%> because it was specified on the command "
    1175              :                     "line");
    1176              :     }
    1177              : 
    1178       644746 :   if (!opts->x_flag_opts_finished)
    1179              :     {
    1180              :       /* We initialize opts->x_flag_pie to -1 so that targets can set a
    1181              :          default value.  */
    1182       297180 :       if (opts->x_flag_pie == -1)
    1183              :         {
    1184              :           /* We initialize opts->x_flag_pic to -1 so that we can tell if
    1185              :              -fpic, -fPIC, -fno-pic or -fno-PIC is used.  */
    1186       257743 :           if (opts->x_flag_pic == -1)
    1187       248378 :             opts->x_flag_pie = (opts->x_flag_hardened
    1188       248378 :                                 ? /*-fPIE*/ 2 : DEFAULT_FLAG_PIE);
    1189              :           else
    1190         9365 :             opts->x_flag_pie = 0;
    1191              :         }
    1192              :       /* If -fPIE or -fpie is used, turn on PIC.  */
    1193       297180 :       if (opts->x_flag_pie)
    1194        18519 :         opts->x_flag_pic = opts->x_flag_pie;
    1195       278661 :       else if (opts->x_flag_pic == -1)
    1196       269296 :         opts->x_flag_pic = 0;
    1197       297180 :       if (opts->x_flag_pic && !opts->x_flag_pie)
    1198         9147 :         opts->x_flag_shlib = 1;
    1199       297180 :       opts->x_flag_opts_finished = true;
    1200              :     }
    1201              : 
    1202              :   /* We initialize opts->x_flag_stack_protect to -1 so that targets
    1203              :      can set a default value.  With --enable-default-ssp or -fhardened
    1204              :      the default is -fstack-protector-strong.  */
    1205       644746 :   if (opts->x_flag_stack_protect == -1)
    1206              :     {
    1207              :       /* This should check FRAME_GROWS_DOWNWARD, but on some targets it's
    1208              :          defined in such a way that it uses flag_stack_protect which can't
    1209              :          be used here.  Moreover, some targets like BPF don't support
    1210              :          -fstack-protector at all but we don't know that here.  So remember
    1211              :          that flag_stack_protect was set at the behest of -fhardened.  */
    1212       295861 :       if (opts->x_flag_hardened)
    1213              :         {
    1214           88 :           opts->x_flag_stack_protect = SPCT_FLAG_STRONG;
    1215           88 :           flag_stack_protector_set_by_fhardened_p = true;
    1216              :         }
    1217              :       else
    1218       295773 :         opts->x_flag_stack_protect = DEFAULT_FLAG_SSP;
    1219              :     }
    1220       348885 :   else if (opts->x_flag_hardened
    1221            4 :            && opts->x_flag_stack_protect != SPCT_FLAG_STRONG)
    1222            4 :     warning_at (UNKNOWN_LOCATION, OPT_Whardened,
    1223              :                 "%<-fstack-protector-strong%> is not enabled by "
    1224              :                 "%<-fhardened%> because it was specified on the command "
    1225              :                 "line");
    1226              : 
    1227       644746 :   if (opts->x_optimize == 0)
    1228              :     {
    1229              :       /* Inlining does not work if not optimizing,
    1230              :          so force it not to be done.  */
    1231       115870 :       opts->x_warn_inline = 0;
    1232       115870 :       opts->x_flag_no_inline = 1;
    1233              :     }
    1234              : 
    1235              :   /* At -O0 or -Og, turn __builtin_unreachable into a trap.  */
    1236       644746 :   if (!opts->x_optimize || opts->x_optimize_debug)
    1237       116568 :     SET_OPTION_IF_UNSET (opts, opts_set, flag_unreachable_traps, true);
    1238              : 
    1239              :   /* Pipelining of outer loops is only possible when general pipelining
    1240              :      capabilities are requested.  */
    1241       644746 :   if (!opts->x_flag_sel_sched_pipelining)
    1242       644694 :     opts->x_flag_sel_sched_pipelining_outer_loops = 0;
    1243              : 
    1244       644746 :   if (opts->x_flag_conserve_stack)
    1245              :     {
    1246           30 :       SET_OPTION_IF_UNSET (opts, opts_set, param_large_stack_frame, 100);
    1247           30 :       SET_OPTION_IF_UNSET (opts, opts_set, param_stack_frame_growth, 40);
    1248              :     }
    1249              : 
    1250       644746 :   if (opts->x_flag_lto)
    1251              :     {
    1252              : #ifdef ENABLE_LTO
    1253       185686 :       opts->x_flag_generate_lto = 1;
    1254              : 
    1255              :       /* When generating IL, do not operate in whole-program mode.
    1256              :          Otherwise, symbols will be privatized too early, causing link
    1257              :          errors later.  */
    1258       185686 :       opts->x_flag_whole_program = 0;
    1259              : #else
    1260              :       error_at (loc, "LTO support has not been enabled in this configuration");
    1261              : #endif
    1262       185686 :       if (!opts->x_flag_fat_lto_objects
    1263        21648 :           && (!HAVE_LTO_PLUGIN
    1264        21648 :               || (opts_set->x_flag_use_linker_plugin
    1265        20083 :                   && !opts->x_flag_use_linker_plugin)))
    1266              :         {
    1267         9105 :           if (opts_set->x_flag_fat_lto_objects)
    1268            0 :             error_at (loc, "%<-fno-fat-lto-objects%> are supported only with "
    1269              :                       "linker plugin");
    1270         9105 :           opts->x_flag_fat_lto_objects = 1;
    1271              :         }
    1272              : 
    1273              :       /* -gsplit-dwarf isn't compatible with LTO, see PR88389.  */
    1274       185686 :       if (opts->x_dwarf_split_debug_info)
    1275              :         {
    1276            1 :           inform (loc, "%<-gsplit-dwarf%> is not supported with LTO,"
    1277              :                   " disabling");
    1278            1 :           opts->x_dwarf_split_debug_info = 0;
    1279              :         }
    1280              :     }
    1281              : 
    1282              :   /* We initialize opts->x_flag_split_stack to -1 so that targets can set a
    1283              :      default value if they choose based on other options.  */
    1284       644746 :   if (opts->x_flag_split_stack == -1)
    1285       295491 :     opts->x_flag_split_stack = 0;
    1286       349255 :   else if (opts->x_flag_split_stack)
    1287              :     {
    1288         1717 :       if (!targetm_common.supports_split_stack (true, opts))
    1289              :         {
    1290            0 :           error_at (loc, "%<-fsplit-stack%> is not supported by "
    1291              :                     "this compiler configuration");
    1292            0 :           opts->x_flag_split_stack = 0;
    1293              :         }
    1294              :     }
    1295              : 
    1296              :   /* If stack splitting is turned on, and the user did not explicitly
    1297              :      request function partitioning, turn off partitioning, as it
    1298              :      confuses the linker when trying to handle partitioned split-stack
    1299              :      code that calls a non-split-stack functions.  But if partitioning
    1300              :      was turned on explicitly just hope for the best.  */
    1301       644746 :   if (opts->x_flag_split_stack
    1302         1717 :       && opts->x_flag_reorder_blocks_and_partition)
    1303         1280 :     SET_OPTION_IF_UNSET (opts, opts_set, flag_reorder_blocks_and_partition, 0);
    1304              : 
    1305       644746 :   if (opts->x_flag_reorder_blocks_and_partition)
    1306       498094 :     SET_OPTION_IF_UNSET (opts, opts_set, flag_reorder_functions, 1);
    1307              : 
    1308       644746 :   validate_ipa_reorder_locality_lto_partition (opts, opts_set);
    1309              : 
    1310              :   /* The -gsplit-dwarf option requires -ggnu-pubnames.  */
    1311       644746 :   if (opts->x_dwarf_split_debug_info)
    1312          311 :     opts->x_debug_generate_pub_sections = 2;
    1313              : 
    1314       644746 :   if ((opts->x_flag_sanitize
    1315       644746 :        & (SANITIZE_USER_ADDRESS | SANITIZE_KERNEL_ADDRESS)) == 0)
    1316              :     {
    1317       641615 :       if (opts->x_flag_sanitize & SANITIZE_POINTER_COMPARE)
    1318            0 :         error_at (loc,
    1319              :                   "%<-fsanitize=pointer-compare%> must be combined with "
    1320              :                   "%<-fsanitize=address%> or %<-fsanitize=kernel-address%>");
    1321       641615 :       if (opts->x_flag_sanitize & SANITIZE_POINTER_SUBTRACT)
    1322            0 :         error_at (loc,
    1323              :                   "%<-fsanitize=pointer-subtract%> must be combined with "
    1324              :                   "%<-fsanitize=address%> or %<-fsanitize=kernel-address%>");
    1325              :     }
    1326              : 
    1327              :   /* Address sanitizers conflict with the thread sanitizer.  */
    1328       644746 :   report_conflicting_sanitizer_options (opts, loc, SANITIZE_THREAD,
    1329              :                                         SANITIZE_ADDRESS);
    1330       644746 :   report_conflicting_sanitizer_options (opts, loc, SANITIZE_THREAD,
    1331              :                                         SANITIZE_HWADDRESS);
    1332              :   /* The leak sanitizer conflicts with the thread sanitizer.  */
    1333       644746 :   report_conflicting_sanitizer_options (opts, loc, SANITIZE_LEAK,
    1334              :                                         SANITIZE_THREAD);
    1335              : 
    1336              :   /* No combination of HWASAN and ASAN work together.  */
    1337       644746 :   report_conflicting_sanitizer_options (opts, loc,
    1338              :                                         SANITIZE_HWADDRESS, SANITIZE_ADDRESS);
    1339              : 
    1340              :   /* The userspace and kernel address sanitizers conflict with each other.  */
    1341       644746 :   report_conflicting_sanitizer_options (opts, loc, SANITIZE_USER_HWADDRESS,
    1342              :                                         SANITIZE_KERNEL_HWADDRESS);
    1343       644746 :   report_conflicting_sanitizer_options (opts, loc, SANITIZE_USER_ADDRESS,
    1344              :                                         SANITIZE_KERNEL_ADDRESS);
    1345              : 
    1346              :   /* Sanitizers using Memory-Tagging Extension conflict with HWASAN and
    1347              :      ASAN.  */
    1348       644746 :   report_conflicting_sanitizer_options (opts, loc, SANITIZE_MEMTAG,
    1349              :                                         SANITIZE_HWADDRESS);
    1350       644746 :   report_conflicting_sanitizer_options (opts, loc, SANITIZE_MEMTAG,
    1351              :                                         SANITIZE_ADDRESS);
    1352              : 
    1353              :   /* Memtag sanitizer implies HWASAN but with tags always generated by
    1354              :      the hardware randomly.  */
    1355       644746 :   if ((opts->x_flag_sanitize & SANITIZE_MEMTAG_STACK)
    1356            0 :       && opts->x_param_hwasan_random_frame_tag == 0)
    1357              :     {
    1358            0 :        warning_at (loc, OPT_fsanitize_,
    1359              :                    "%<--param hwasan-random-frame-tag=0%> is ignored when "
    1360              :                    "%<-fsanitize=memtag-stack%> is present");
    1361            0 :        opts->x_param_hwasan_random_frame_tag = 1;
    1362              :     }
    1363              : 
    1364              :   /* Check error recovery for -fsanitize-recover option.  */
    1365     22566110 :   for (int i = 0; sanitizer_opts[i].name != NULL; ++i)
    1366     21921364 :     if ((opts->x_flag_sanitize_recover & sanitizer_opts[i].flag)
    1367     15469489 :         && !sanitizer_opts[i].can_recover)
    1368           40 :       error_at (loc, "%<-fsanitize-recover=%s%> is not supported",
    1369              :                 sanitizer_opts[i].name);
    1370              : 
    1371              :   /* Check -fsanitize-trap option.  */
    1372     22566110 :   for (int i = 0; sanitizer_opts[i].name != NULL; ++i)
    1373     21921364 :     if ((opts->x_flag_sanitize_trap & sanitizer_opts[i].flag)
    1374         4381 :         && !sanitizer_opts[i].can_trap
    1375              :         /* Allow -fsanitize-trap=all or -fsanitize-trap=undefined
    1376              :            to set flag_sanitize_trap & SANITIZE_VPTR bit which will
    1377              :            effectively disable -fsanitize=vptr, just disallow
    1378              :            explicit -fsanitize-trap=vptr.  */
    1379          184 :         && sanitizer_opts[i].flag != SANITIZE_VPTR)
    1380            0 :       error_at (loc, "%<-fsanitize-trap=%s%> is not supported",
    1381              :                 sanitizer_opts[i].name);
    1382              : 
    1383              :   /* When instrumenting the pointers, we don't want to remove
    1384              :      the null pointer checks.  */
    1385       644746 :   if (opts->x_flag_sanitize & (SANITIZE_NULL | SANITIZE_NONNULL_ATTRIBUTE
    1386              :                                 | SANITIZE_RETURNS_NONNULL_ATTRIBUTE))
    1387         1689 :     opts->x_flag_delete_null_pointer_checks = 0;
    1388              : 
    1389              :   /* Aggressive compiler optimizations may cause false negatives.  */
    1390       644746 :   if (opts->x_flag_sanitize & ~(SANITIZE_LEAK | SANITIZE_UNREACHABLE))
    1391         7577 :     opts->x_flag_aggressive_loop_optimizations = 0;
    1392              : 
    1393              :   /* Enable -fsanitize-address-use-after-scope if either address sanitizer is
    1394              :      enabled.  */
    1395       644746 :   if (opts->x_flag_sanitize
    1396       644746 :       & (SANITIZE_USER_ADDRESS | SANITIZE_USER_HWADDRESS))
    1397         3341 :     SET_OPTION_IF_UNSET (opts, opts_set, flag_sanitize_address_use_after_scope,
    1398              :                          true);
    1399              : 
    1400              :   /* Force -fstack-reuse=none in case -fsanitize-address-use-after-scope
    1401              :      is enabled.  */
    1402       644746 :   if (opts->x_flag_sanitize_address_use_after_scope)
    1403              :     {
    1404         3307 :       if (opts->x_flag_stack_reuse != SR_NONE
    1405         3257 :           && opts_set->x_flag_stack_reuse != SR_NONE)
    1406            0 :         error_at (loc,
    1407              :                   "%<-fsanitize-address-use-after-scope%> requires "
    1408              :                   "%<-fstack-reuse=none%> option");
    1409              : 
    1410         3307 :       opts->x_flag_stack_reuse = SR_NONE;
    1411              :     }
    1412              : 
    1413       644746 :   if ((opts->x_flag_sanitize & SANITIZE_USER_ADDRESS) && opts->x_flag_tm)
    1414            0 :     sorry ("transactional memory is not supported with %<-fsanitize=address%>");
    1415              : 
    1416       644746 :   if ((opts->x_flag_sanitize & SANITIZE_KERNEL_ADDRESS) && opts->x_flag_tm)
    1417            0 :     sorry ("transactional memory is not supported with "
    1418              :            "%<-fsanitize=kernel-address%>");
    1419              : 
    1420              :   /* Currently live patching is not support for LTO.  */
    1421       644746 :   if (opts->x_flag_live_patching == LIVE_PATCHING_INLINE_ONLY_STATIC && opts->x_flag_lto)
    1422            1 :     sorry ("live patching (with %qs) is not supported with LTO",
    1423              :            "inline-only-static");
    1424              : 
    1425              :   /* Currently vtable verification is not supported for LTO */
    1426       644746 :   if (opts->x_flag_vtable_verify && opts->x_flag_lto)
    1427            0 :     sorry ("vtable verification is not supported with LTO");
    1428              : 
    1429              :   /* Control IPA optimizations based on different -flive-patching level.  */
    1430       644746 :   if (opts->x_flag_live_patching)
    1431           20 :     control_options_for_live_patching (opts, opts_set,
    1432              :                                        opts->x_flag_live_patching,
    1433              :                                        loc);
    1434              : 
    1435              :   /* Allow cunroll to grow size accordingly.  */
    1436       644746 :   if (!opts_set->x_flag_cunroll_grow_size)
    1437       644746 :     opts->x_flag_cunroll_grow_size
    1438      1289492 :       = (opts->x_flag_unroll_loops
    1439       161236 :          || opts->x_flag_peel_loops
    1440      1289492 :          || opts->x_optimize >= 3);
    1441              : 
    1442              :   /* Use -fvect-cost-model=cheap instead of -fvect-cost-mode=very-cheap
    1443              :      by default with explicit -ftree-{loop,slp}-vectorize.  */
    1444       644746 :   if (opts->x_optimize == 2
    1445       469054 :       && (opts_set->x_flag_tree_loop_vectorize
    1446       468993 :           || opts_set->x_flag_tree_vectorize))
    1447       349674 :     SET_OPTION_IF_UNSET (opts, opts_set, flag_vect_cost_model,
    1448              :                          VECT_COST_MODEL_CHEAP);
    1449              : 
    1450       644746 :   if (opts->x_flag_gtoggle)
    1451              :     {
    1452              :       /* Make sure to process -gtoggle only once.  */
    1453          633 :       opts->x_flag_gtoggle = false;
    1454          633 :       if (opts->x_debug_info_level == DINFO_LEVEL_NONE)
    1455              :         {
    1456          383 :           opts->x_debug_info_level = DINFO_LEVEL_NORMAL;
    1457              : 
    1458          383 :           if (opts->x_write_symbols == NO_DEBUG)
    1459          383 :             opts->x_write_symbols = PREFERRED_DEBUGGING_TYPE;
    1460              :         }
    1461              :       else
    1462          250 :         opts->x_debug_info_level = DINFO_LEVEL_NONE;
    1463              :     }
    1464              : 
    1465              :   /* Also enable markers with -fauto-profile even when debug info is disabled,
    1466              :      so we assign same discriminators and can read back the profile info.  */
    1467       644746 :   if (!opts_set->x_debug_nonbind_markers_p)
    1468       644714 :     opts->x_debug_nonbind_markers_p
    1469       644714 :       = (opts->x_optimize
    1470       528844 :          && ((opts->x_debug_info_level >= DINFO_LEVEL_NORMAL
    1471        52214 :               && (dwarf_debuginfo_p (opts) || codeview_debuginfo_p ()))
    1472       476639 :              || opts->x_flag_auto_profile)
    1473      1341633 :          && !(opts->x_flag_selective_scheduling
    1474        52205 :               || opts->x_flag_selective_scheduling2));
    1475              : 
    1476              :   /* We know which debug output will be used so we can set flag_var_tracking
    1477              :      and flag_var_tracking_uninit if the user has not specified them.  */
    1478       644746 :   if (opts->x_debug_info_level < DINFO_LEVEL_NORMAL
    1479       644746 :       || (!dwarf_debuginfo_p (opts) && !codeview_debuginfo_p ())
    1480              :       /* We have not yet initialized debug hooks so match that to check
    1481              :          whether we're only doing DWARF2_LINENO_DEBUGGING_INFO.  */
    1482              : #ifndef DWARF2_DEBUGGING_INFO
    1483              :       || true
    1484              : #endif
    1485              :      )
    1486              :     {
    1487       586052 :       if ((opts_set->x_flag_var_tracking && opts->x_flag_var_tracking == 1)
    1488       586036 :           || (opts_set->x_flag_var_tracking_uninit
    1489            0 :               && opts->x_flag_var_tracking_uninit == 1))
    1490              :         {
    1491           16 :           if (opts->x_debug_info_level < DINFO_LEVEL_NORMAL)
    1492           15 :             warning_at (UNKNOWN_LOCATION, 0,
    1493              :                         "variable tracking requested, but useless unless "
    1494              :                         "producing debug info");
    1495              :           else
    1496            1 :             warning_at (UNKNOWN_LOCATION, 0,
    1497              :                         "variable tracking requested, but not supported "
    1498              :                         "by this debug format");
    1499              :         }
    1500       586052 :       opts->x_flag_var_tracking = 0;
    1501       586052 :       opts->x_flag_var_tracking_uninit = 0;
    1502       586052 :       opts->x_flag_var_tracking_assignments = 0;
    1503              :     }
    1504              : 
    1505       644746 :   if (opts_set->x_flag_var_tracking_uninit && opts->x_flag_var_tracking_uninit)
    1506            0 :     opts->x_flag_var_tracking = 1;
    1507              : 
    1508       644746 :   if (!opts_set->x_flag_var_tracking_assignments)
    1509       644672 :     opts->x_flag_var_tracking_assignments
    1510      1289344 :       = (opts->x_flag_var_tracking
    1511      1289344 :          && !(opts->x_flag_selective_scheduling
    1512        52201 :               || opts->x_flag_selective_scheduling2));
    1513              : 
    1514       644746 :   if (opts->x_flag_var_tracking_assignments_toggle)
    1515            0 :     opts->x_flag_var_tracking_assignments
    1516            0 :       = !opts->x_flag_var_tracking_assignments;
    1517              : 
    1518       644746 :   if (opts->x_flag_var_tracking_assignments && !opts->x_flag_var_tracking)
    1519            2 :     opts->x_flag_var_tracking = opts->x_flag_var_tracking_assignments = -1;
    1520              : 
    1521       644746 :   if (opts->x_flag_var_tracking_assignments
    1522        52208 :       && (opts->x_flag_selective_scheduling
    1523        52208 :           || opts->x_flag_selective_scheduling2))
    1524            5 :     warning_at (loc, 0,
    1525              :                 "var-tracking-assignments changes selective scheduling");
    1526              : 
    1527       644746 :   if (opts->x_flag_syntax_only)
    1528              :     {
    1529          284 :       opts->x_write_symbols = NO_DEBUG;
    1530          284 :       opts->x_profile_flag = 0;
    1531              :     }
    1532              : 
    1533       644746 :   if (opts->x_warn_strict_flex_arrays)
    1534           13 :     if (opts->x_flag_strict_flex_arrays == 0)
    1535              :       {
    1536            4 :         opts->x_warn_strict_flex_arrays = 0;
    1537            4 :         warning_at (UNKNOWN_LOCATION, 0,
    1538              :                     "%<-Wstrict-flex-arrays%> is ignored when"
    1539              :                     " %<-fstrict-flex-arrays%> is not present");
    1540              :       }
    1541              : 
    1542       644746 :   if (opts->x_flag_openmp_ompt && !opts->x_flag_openmp)
    1543            8 :     error_at (loc, "%<-fopenmp-ompt%> requires %<-fopenmp%>");
    1544              : 
    1545       644746 :   diagnose_options (opts, opts_set, loc);
    1546       644746 : }
    1547              : 
    1548              : /* The function diagnoses incompatible combinations for provided options
    1549              :    (OPTS and OPTS_SET) at a given LOCation.  The function is called both
    1550              :    when command line is parsed (after the target optimization hook) and
    1551              :    when an optimize/target attribute (or pragma) is used.  */
    1552              : 
    1553       941845 : void diagnose_options (gcc_options *opts, gcc_options *opts_set,
    1554              :                        location_t loc)
    1555              : {
    1556              :   /* The optimization to partition hot and cold basic blocks into separate
    1557              :      sections of the .o and executable files does not work (currently)
    1558              :      with exception handling.  This is because there is no support for
    1559              :      generating unwind info.  If opts->x_flag_exceptions is turned on
    1560              :      we need to turn off the partitioning optimization.  */
    1561              : 
    1562       941845 :   enum unwind_info_type ui_except
    1563       941845 :     = targetm_common.except_unwind_info (opts);
    1564              : 
    1565       941845 :   if (opts->x_flag_exceptions
    1566       267589 :       && opts->x_flag_reorder_blocks_and_partition
    1567        89056 :       && (ui_except == UI_SJLJ || ui_except >= UI_TARGET))
    1568              :     {
    1569            0 :       if (opts_set->x_flag_reorder_blocks_and_partition)
    1570            0 :         inform (loc,
    1571              :                 "%<-freorder-blocks-and-partition%> does not work "
    1572              :                 "with exceptions on this architecture");
    1573            0 :       opts->x_flag_reorder_blocks_and_partition = 0;
    1574            0 :       opts->x_flag_reorder_blocks = 1;
    1575              :     }
    1576              : 
    1577              :   /* If user requested unwind info, then turn off the partitioning
    1578              :      optimization.  */
    1579              : 
    1580       941845 :   if (opts->x_flag_unwind_tables
    1581       645619 :       && !targetm_common.unwind_tables_default
    1582       645619 :       && opts->x_flag_reorder_blocks_and_partition
    1583       496229 :       && (ui_except == UI_SJLJ || ui_except >= UI_TARGET))
    1584              :     {
    1585            0 :       if (opts_set->x_flag_reorder_blocks_and_partition)
    1586            0 :         inform (loc,
    1587              :                 "%<-freorder-blocks-and-partition%> does not support "
    1588              :                 "unwind info on this architecture");
    1589            0 :       opts->x_flag_reorder_blocks_and_partition = 0;
    1590            0 :       opts->x_flag_reorder_blocks = 1;
    1591              :     }
    1592              : 
    1593              :   /* If the target requested unwind info, then turn off the partitioning
    1594              :      optimization with a different message.  Likewise, if the target does not
    1595              :      support named sections.  */
    1596              : 
    1597       941845 :   if (opts->x_flag_reorder_blocks_and_partition
    1598       646800 :       && (!targetm_common.have_named_sections
    1599       646800 :           || (opts->x_flag_unwind_tables
    1600       496229 :               && targetm_common.unwind_tables_default
    1601            0 :               && (ui_except == UI_SJLJ || ui_except >= UI_TARGET))))
    1602              :     {
    1603            0 :       if (opts_set->x_flag_reorder_blocks_and_partition)
    1604            0 :         inform (loc,
    1605              :                 "%<-freorder-blocks-and-partition%> does not work "
    1606              :                 "on this architecture");
    1607            0 :       opts->x_flag_reorder_blocks_and_partition = 0;
    1608            0 :       opts->x_flag_reorder_blocks = 1;
    1609              :     }
    1610              : 
    1611              : 
    1612       941845 : }
    1613              : 
    1614              : #define LEFT_COLUMN     27
    1615              : 
    1616              : /* Output ITEM, of length ITEM_WIDTH, in the left column,
    1617              :    followed by word-wrapped HELP in a second column.  */
    1618              : static void
    1619        29440 : wrap_help (const char *help,
    1620              :            const char *item,
    1621              :            unsigned int item_width,
    1622              :            unsigned int columns)
    1623              : {
    1624        29440 :   unsigned int col_width = LEFT_COLUMN;
    1625        29440 :   unsigned int remaining, room, len;
    1626              : 
    1627        29440 :   remaining = strlen (help);
    1628              : 
    1629        42718 :   do
    1630              :     {
    1631        42718 :       room = columns - 3 - MAX (col_width, item_width);
    1632        42718 :       if (room > columns)
    1633            0 :         room = 0;
    1634        42718 :       len = remaining;
    1635              : 
    1636        42718 :       if (room < len)
    1637              :         {
    1638              :           unsigned int i;
    1639              : 
    1640       595973 :           for (i = 0; help[i]; i++)
    1641              :             {
    1642       595973 :               if (i >= room && len != remaining)
    1643              :                 break;
    1644       582695 :               if (help[i] == ' ')
    1645              :                 len = i;
    1646       495497 :               else if ((help[i] == '-' || help[i] == '/')
    1647         2070 :                        && help[i + 1] != ' '
    1648         2070 :                        && i > 0 && ISALPHA (help[i - 1]))
    1649       582695 :                 len = i + 1;
    1650              :             }
    1651              :         }
    1652              : 
    1653        42718 :       printf ("  %-*.*s %.*s\n", col_width, item_width, item, len, help);
    1654        42718 :       item_width = 0;
    1655        98481 :       while (help[len] == ' ')
    1656        13045 :         len++;
    1657        42718 :       help += len;
    1658        42718 :       remaining -= len;
    1659              :     }
    1660        42718 :   while (remaining);
    1661        29440 : }
    1662              : 
    1663              : /* Data structure used to print list of valid option values.  */
    1664              : 
    1665              : class option_help_tuple
    1666              : {
    1667              : public:
    1668           14 :   option_help_tuple (int code, vec<const char *> values):
    1669           14 :     m_code (code), m_values (values)
    1670              :   {}
    1671              : 
    1672              :   /* Code of an option.  */
    1673              :   int m_code;
    1674              : 
    1675              :   /* List of possible values.  */
    1676              :   vec<const char *> m_values;
    1677              : };
    1678              : 
    1679              : /* Print help for a specific front-end, etc.  */
    1680              : static void
    1681          137 : print_filtered_help (unsigned int include_flags,
    1682              :                      unsigned int exclude_flags,
    1683              :                      unsigned int any_flags,
    1684              :                      unsigned int columns,
    1685              :                      struct gcc_options *opts,
    1686              :                      unsigned int lang_mask)
    1687              : {
    1688          137 :   unsigned int i;
    1689          137 :   const char *help;
    1690          137 :   bool found = false;
    1691          137 :   bool displayed = false;
    1692          137 :   char new_help[256];
    1693              : 
    1694          137 :   if (!opts->x_help_printed)
    1695           72 :     opts->x_help_printed = XCNEWVAR (char, cl_options_count);
    1696              : 
    1697          137 :   if (!opts->x_help_enum_printed)
    1698           72 :     opts->x_help_enum_printed = XCNEWVAR (char, cl_enums_count);
    1699              : 
    1700          137 :   auto_vec<option_help_tuple> help_tuples;
    1701              : 
    1702       356200 :   for (i = 0; i < cl_options_count; i++)
    1703              :     {
    1704       356063 :       const struct cl_option *option = cl_options + i;
    1705       356063 :       unsigned int len;
    1706       356063 :       const char *opt;
    1707       356063 :       const char *tab;
    1708              : 
    1709       356063 :       if (include_flags == 0
    1710       348266 :           || ((option->flags & include_flags) != include_flags))
    1711              :         {
    1712       314125 :           if ((option->flags & any_flags) == 0)
    1713       310705 :             continue;
    1714              :         }
    1715              : 
    1716              :       /* Skip unwanted switches.  */
    1717        45358 :       if ((option->flags & exclude_flags) != 0)
    1718         9956 :         continue;
    1719              : 
    1720              :       /* The driver currently prints its own help text.  */
    1721        35402 :       if ((option->flags & CL_DRIVER) != 0
    1722          861 :           && (option->flags & (((1U << cl_lang_count) - 1)
    1723          767 :                                | CL_COMMON | CL_TARGET)) == 0)
    1724           94 :         continue;
    1725              : 
    1726              :       /* If an option contains a language specification,
    1727              :          exclude it from common unless all languages are present.  */
    1728        35308 :       if ((include_flags & CL_COMMON)
    1729         4871 :           && !(option->flags & CL_DRIVER)
    1730         4481 :           && (option->flags & CL_LANG_ALL)
    1731          140 :           && (option->flags & CL_LANG_ALL) != CL_LANG_ALL)
    1732          140 :         continue;
    1733              : 
    1734        35168 :       found = true;
    1735              :       /* Skip switches that have already been printed.  */
    1736        35168 :       if (opts->x_help_printed[i])
    1737         5717 :         continue;
    1738              : 
    1739        29451 :       opts->x_help_printed[i] = true;
    1740              : 
    1741        29451 :       help = option->help;
    1742        29451 :       if (help == NULL)
    1743              :         {
    1744         1574 :           if (exclude_flags & CL_UNDOCUMENTED)
    1745           11 :             continue;
    1746              : 
    1747              :           help = undocumented_msg;
    1748              :         }
    1749              : 
    1750              :       /* Get the translation.  */
    1751        29440 :       help = _(help);
    1752              : 
    1753        29440 :       if (option->alias_target < N_OPTS
    1754         1603 :           && cl_options [option->alias_target].help)
    1755              :         {
    1756         1570 :           const struct cl_option *target = cl_options + option->alias_target;
    1757         1570 :           if (option->help == NULL)
    1758              :             {
    1759              :               /* The option is undocumented but is an alias for an option that
    1760              :                  is documented.  If the option has alias arguments, then its
    1761              :                  purpose is to provide certain arguments to the other option, so
    1762              :                  inform the reader of this.  Otherwise, point the reader to the
    1763              :                  other option in preference to the former.  */
    1764              : 
    1765          928 :               if (option->alias_arg)
    1766              :                 {
    1767          154 :                   if (option->neg_alias_arg)
    1768          127 :                     snprintf (new_help, sizeof new_help,
    1769          127 :                               _("Same as %s%s (or, in negated form, %s%s)."),
    1770              :                               target->opt_text, option->alias_arg,
    1771          127 :                               target->opt_text, option->neg_alias_arg);
    1772              :                   else
    1773           27 :                     snprintf (new_help, sizeof new_help,
    1774           27 :                               _("Same as %s%s."),
    1775           27 :                               target->opt_text, option->alias_arg);
    1776              :                 }
    1777              :               else
    1778          774 :                 snprintf (new_help, sizeof new_help,
    1779          774 :                           _("Same as %s."),
    1780          774 :                           target->opt_text);
    1781              :             }
    1782              :           else
    1783              :             {
    1784              :               /* For documented options with aliases, mention the aliased
    1785              :                  option's name for reference.  */
    1786          642 :               snprintf (new_help, sizeof new_help,
    1787          642 :                         _("%s  Same as %s."),
    1788          642 :                         help, cl_options [option->alias_target].opt_text);
    1789              :             }
    1790              : 
    1791              :           help = new_help;
    1792              :         }
    1793              : 
    1794        29440 :       if (option->warn_message)
    1795              :         {
    1796              :           /* Mention that the use of the option will trigger a warning.  */
    1797           50 :           if (help == new_help)
    1798           43 :             snprintf (new_help + strlen (new_help),
    1799           43 :                       sizeof new_help - strlen (new_help),
    1800              :                       "  %s", _(use_diagnosed_msg));
    1801              :           else
    1802            7 :             snprintf (new_help, sizeof new_help,
    1803              :                       "%s  %s", help, _(use_diagnosed_msg));
    1804              : 
    1805              :           help = new_help;
    1806              :         }
    1807              : 
    1808              :       /* Find the gap between the name of the
    1809              :          option and its descriptive text.  */
    1810        29440 :       tab = strchr (help, '\t');
    1811        29440 :       if (tab)
    1812              :         {
    1813         1652 :           len = tab - help;
    1814         1652 :           opt = help;
    1815         1652 :           help = tab + 1;
    1816              :         }
    1817              :       else
    1818              :         {
    1819        27788 :           opt = option->opt_text;
    1820        27788 :           len = strlen (opt);
    1821              :         }
    1822              : 
    1823              :       /* With the -Q option enabled we change the descriptive text associated
    1824              :          with an option to be an indication of its current setting.  */
    1825        29440 :       if (!opts->x_quiet_flag)
    1826              :         {
    1827         2858 :           void *flag_var = option_flag_var (i, opts);
    1828              : 
    1829         2858 :           if (len < (LEFT_COLUMN + 2))
    1830         2554 :             strcpy (new_help, "\t\t");
    1831              :           else
    1832          304 :             strcpy (new_help, "\t");
    1833              : 
    1834              :           /* Set to print whether the option is enabled or disabled,
    1835              :              or, if it's an alias for another option, the name of
    1836              :              the aliased option.  */
    1837         2858 :           bool print_state = false;
    1838              : 
    1839         2858 :           if (flag_var != NULL
    1840         2604 :               && option->var_type != CLVC_DEFER)
    1841              :             {
    1842              :               /* If OPTION is only available for a specific subset
    1843              :                  of languages other than this one, mention them.  */
    1844         2604 :               bool avail_for_lang = true;
    1845         2604 :               if (unsigned langset = option->flags & CL_LANG_ALL)
    1846              :                 {
    1847         1604 :                   if (!(langset & lang_mask))
    1848              :                     {
    1849          770 :                       avail_for_lang = false;
    1850          770 :                       strcat (new_help, _("[available in "));
    1851        13090 :                       for (unsigned i = 0, n = 0; (1U << i) < CL_LANG_ALL; ++i)
    1852        12320 :                         if (langset & (1U << i))
    1853              :                           {
    1854         1126 :                             if (n++)
    1855          356 :                               strcat (new_help, ", ");
    1856         1126 :                             strcat (new_help, lang_names[i]);
    1857              :                           }
    1858          770 :                       strcat (new_help, "]");
    1859              :                     }
    1860              :                 }
    1861          770 :               if (!avail_for_lang)
    1862              :                 ; /* Print nothing else if the option is not available
    1863              :                      in the current language.  */
    1864         1834 :               else if (option->flags & CL_JOINED)
    1865              :                 {
    1866          159 :                   if (option->var_type == CLVC_STRING)
    1867              :                     {
    1868           10 :                       if (* (const char **) flag_var != NULL)
    1869            8 :                         snprintf (new_help + strlen (new_help),
    1870            8 :                                   sizeof (new_help) - strlen (new_help),
    1871              :                                   "%s", * (const char **) flag_var);
    1872              :                     }
    1873          149 :                   else if (option->var_type == CLVC_ENUM)
    1874              :                     {
    1875           53 :                       const struct cl_enum *e = &cl_enums[option->var_enum];
    1876           53 :                       int value;
    1877           53 :                       const char *arg = NULL;
    1878              : 
    1879           53 :                       value = e->get (flag_var);
    1880           53 :                       enum_value_to_arg (e->values, &arg, value, lang_mask);
    1881           53 :                       if (arg == NULL)
    1882           10 :                         arg = _("[default]");
    1883           53 :                       snprintf (new_help + strlen (new_help),
    1884           53 :                                 sizeof (new_help) - strlen (new_help),
    1885              :                                 "%s", arg);
    1886              :                     }
    1887              :                   else
    1888              :                     {
    1889           96 :                       if (option->cl_host_wide_int)
    1890           24 :                         sprintf (new_help + strlen (new_help),
    1891           24 :                                  _("%llu bytes"), (unsigned long long)
    1892              :                                  *(unsigned HOST_WIDE_INT *) flag_var);
    1893              :                       else
    1894           72 :                         sprintf (new_help + strlen (new_help),
    1895              :                                  "%i", * (int *) flag_var);
    1896              :                     }
    1897              :                 }
    1898              :               else
    1899              :                 print_state = true;
    1900              :             }
    1901              :           else
    1902              :             /* When there is no argument, print the option state only
    1903              :                if the option takes no argument.  */
    1904          254 :             print_state = !(option->flags & CL_JOINED);
    1905              : 
    1906         1181 :           if (print_state)
    1907              :             {
    1908         1903 :               if (option->alias_target < N_OPTS
    1909              :                   && option->alias_target != OPT_SPECIAL_warn_removed
    1910              :                   && option->alias_target != OPT_SPECIAL_ignore
    1911              :                   && option->alias_target != OPT_SPECIAL_input_file
    1912              :                   && option->alias_target != OPT_SPECIAL_program_name
    1913              :                   && option->alias_target != OPT_SPECIAL_unknown)
    1914              :                 {
    1915          166 :                   const struct cl_option *target
    1916          166 :                     = &cl_options[option->alias_target];
    1917          332 :                   sprintf (new_help + strlen (new_help), "%s%s",
    1918          166 :                            target->opt_text,
    1919          166 :                            option->alias_arg ? option->alias_arg : "");
    1920              :                 }
    1921         1737 :               else if (option->alias_target == OPT_SPECIAL_ignore)
    1922           20 :                 strcat (new_help, ("[ignored]"));
    1923              :               else
    1924              :                 {
    1925              :                   /* Print the state for an on/off option.  */
    1926         1717 :                   int ena = option_enabled (i, lang_mask, opts);
    1927         1717 :                   if (ena > 0)
    1928          794 :                     strcat (new_help, _("[enabled]"));
    1929          923 :                   else if (ena == 0)
    1930          824 :                     strcat (new_help, _("[disabled]"));
    1931              :                 }
    1932              :             }
    1933              : 
    1934              :           help = new_help;
    1935              :         }
    1936              : 
    1937        29440 :       if (option->range_max != -1 && tab == NULL)
    1938              :         {
    1939         4614 :           char b[128];
    1940         4614 :           snprintf (b, sizeof (b), "<%d,%d>", option->range_min,
    1941              :                     option->range_max);
    1942         4614 :           opt = concat (opt, b, NULL);
    1943         4614 :           len += strlen (b);
    1944              :         }
    1945              : 
    1946        29440 :       wrap_help (help, opt, len, columns);
    1947        29440 :       displayed = true;
    1948              : 
    1949        29440 :       if (option->var_type == CLVC_ENUM
    1950          923 :           && opts->x_help_enum_printed[option->var_enum] != 2)
    1951          923 :         opts->x_help_enum_printed[option->var_enum] = 1;
    1952              :       else
    1953              :         {
    1954        28517 :           vec<const char *> option_values
    1955        28517 :             = targetm_common.get_valid_option_values (i, NULL);
    1956        28531 :           if (!option_values.is_empty ())
    1957           14 :             help_tuples.safe_push (option_help_tuple (i, option_values));
    1958              :         }
    1959              :     }
    1960              : 
    1961          137 :   if (! found)
    1962              :     {
    1963            9 :       unsigned int langs = include_flags & CL_LANG_ALL;
    1964              : 
    1965            9 :       if (langs == 0)
    1966            0 :         printf (_(" No options with the desired characteristics were found\n"));
    1967              :       else
    1968              :         {
    1969              :           unsigned int i;
    1970              : 
    1971              :           /* PR 31349: Tell the user how to see all of the
    1972              :              options supported by a specific front end.  */
    1973          153 :           for (i = 0; (1U << i) < CL_LANG_ALL; i ++)
    1974          144 :             if ((1U << i) & langs)
    1975            9 :               printf (_(" None found.  Use --help=%s to show *all* the options supported by the %s front-end.\n"),
    1976            9 :                       lang_names[i], lang_names[i]);
    1977              :         }
    1978              : 
    1979              :     }
    1980          128 :   else if (! displayed)
    1981            0 :     printf (_(" All options with the desired characteristics have already been displayed\n"));
    1982              : 
    1983          137 :   putchar ('\n');
    1984              : 
    1985              :   /* Print details of enumerated option arguments, if those
    1986              :      enumerations have help text headings provided.  If no help text
    1987              :      is provided, presume that the possible values are listed in the
    1988              :      help text for the relevant options.  */
    1989        12193 :   for (i = 0; i < cl_enums_count; i++)
    1990              :     {
    1991        11919 :       unsigned int j, pos;
    1992              : 
    1993        11919 :       if (opts->x_help_enum_printed[i] != 1)
    1994        10142 :         continue;
    1995         1777 :       if (cl_enums[i].help == NULL)
    1996         1679 :         continue;
    1997           98 :       printf ("  %s\n    ", _(cl_enums[i].help));
    1998           98 :       pos = 4;
    1999          560 :       for (j = 0; cl_enums[i].values[j].arg != NULL; j++)
    2000              :         {
    2001          364 :           unsigned int len = strlen (cl_enums[i].values[j].arg);
    2002              : 
    2003          364 :           if (pos > 4 && pos + 1 + len <= columns)
    2004              :             {
    2005          265 :               printf (" %s", cl_enums[i].values[j].arg);
    2006          265 :               pos += 1 + len;
    2007              :             }
    2008              :           else
    2009              :             {
    2010            1 :               if (pos > 4)
    2011              :                 {
    2012            1 :                   printf ("\n    ");
    2013            1 :                   pos = 4;
    2014              :                 }
    2015           99 :               printf ("%s", cl_enums[i].values[j].arg);
    2016           99 :               pos += len;
    2017              :             }
    2018              :         }
    2019           98 :       printf ("\n\n");
    2020           98 :       opts->x_help_enum_printed[i] = 2;
    2021              :     }
    2022              : 
    2023          151 :   for (unsigned i = 0; i < help_tuples.length (); i++)
    2024              :     {
    2025           14 :       const struct cl_option *option = cl_options + help_tuples[i].m_code;
    2026           14 :       printf (_("  Known valid arguments for %s option:\n   "),
    2027           14 :               option->opt_text);
    2028         1316 :       for (unsigned j = 0; j < help_tuples[i].m_values.length (); j++)
    2029         1288 :         printf (" %s", help_tuples[i].m_values[j]);
    2030           14 :       printf ("\n\n");
    2031              :     }
    2032          137 : }
    2033              : 
    2034              : /* Display help for a specified type of option.
    2035              :    The options must have ALL of the INCLUDE_FLAGS set
    2036              :    ANY of the flags in the ANY_FLAGS set
    2037              :    and NONE of the EXCLUDE_FLAGS set.  The current option state is in
    2038              :    OPTS; LANG_MASK is used for interpreting enumerated option state.  */
    2039              : static void
    2040          137 : print_specific_help (unsigned int include_flags,
    2041              :                      unsigned int exclude_flags,
    2042              :                      unsigned int any_flags,
    2043              :                      struct gcc_options *opts,
    2044              :                      unsigned int lang_mask)
    2045              : {
    2046          137 :   unsigned int all_langs_mask = (1U << cl_lang_count) - 1;
    2047          137 :   const char * description = NULL;
    2048          137 :   const char * descrip_extra = "";
    2049          137 :   size_t i;
    2050          137 :   unsigned int flag;
    2051              : 
    2052              :   /* Sanity check: Make sure that we do not have more
    2053              :      languages than we have bits available to enumerate them.  */
    2054          137 :   gcc_assert ((1U << cl_lang_count) <= CL_MIN_OPTION_CLASS);
    2055              : 
    2056              :   /* If we have not done so already, obtain
    2057              :      the desired maximum width of the output.  */
    2058          137 :   if (opts->x_help_columns == 0)
    2059              :     {
    2060           72 :       opts->x_help_columns = get_terminal_width ();
    2061           72 :       if (opts->x_help_columns == INT_MAX)
    2062              :         /* Use a reasonable default.  */
    2063           28 :         opts->x_help_columns = 80;
    2064              :     }
    2065              : 
    2066              :   /* Decide upon the title for the options that we are going to display.  */
    2067         3151 :   for (i = 0, flag = 1; flag <= CL_MAX_OPTION_CLASS; flag <<= 1, i ++)
    2068              :     {
    2069         3014 :       switch (flag & include_flags)
    2070              :         {
    2071              :         case 0:
    2072              :         case CL_DRIVER:
    2073              :           break;
    2074              : 
    2075            7 :         case CL_TARGET:
    2076            7 :           description = _("The following options are target specific");
    2077            7 :           break;
    2078           11 :         case CL_WARNING:
    2079           11 :           description = _("The following options control compiler warning messages");
    2080           11 :           break;
    2081           10 :         case CL_OPTIMIZATION:
    2082           10 :           description = _("The following options control optimizations");
    2083           10 :           break;
    2084            5 :         case CL_COMMON:
    2085            5 :           description = _("The following options are language-independent");
    2086            5 :           break;
    2087           34 :         case CL_PARAMS:
    2088           34 :           description = _("The following options control parameters");
    2089           34 :           break;
    2090           62 :         default:
    2091           62 :           if (i >= cl_lang_count)
    2092              :             break;
    2093           62 :           if (exclude_flags & all_langs_mask)
    2094           48 :             description = _("The following options are specific to just the language ");
    2095              :           else
    2096           14 :             description = _("The following options are supported by the language ");
    2097           62 :           descrip_extra = lang_names [i];
    2098           62 :           break;
    2099              :         }
    2100              :     }
    2101              : 
    2102          137 :   if (description == NULL)
    2103              :     {
    2104            9 :       if (any_flags == 0)
    2105              :         {
    2106            6 :           if (include_flags & CL_UNDOCUMENTED)
    2107            2 :             description = _("The following options are not documented");
    2108            4 :           else if (include_flags & CL_SEPARATE)
    2109            2 :             description = _("The following options take separate arguments");
    2110            2 :           else if (include_flags & CL_JOINED)
    2111            2 :             description = _("The following options take joined arguments");
    2112              :           else
    2113              :             {
    2114            0 :               internal_error ("unrecognized %<include_flags 0x%x%> passed "
    2115              :                               "to %<print_specific_help%>",
    2116              :                               include_flags);
    2117              :               return;
    2118              :             }
    2119              :         }
    2120              :       else
    2121              :         {
    2122            3 :           if (any_flags & all_langs_mask)
    2123            3 :             description = _("The following options are language-related");
    2124              :           else
    2125            0 :             description = _("The following options are language-independent");
    2126              :         }
    2127              :     }
    2128              : 
    2129          137 :   printf ("%s%s:\n", description, descrip_extra);
    2130          137 :   print_filtered_help (include_flags, exclude_flags, any_flags,
    2131              :                        opts->x_help_columns, opts, lang_mask);
    2132              : }
    2133              : 
    2134              : /* Enable FDO-related flags.  */
    2135              : 
    2136              : static void
    2137          157 : enable_fdo_optimizations (struct gcc_options *opts,
    2138              :                           struct gcc_options *opts_set,
    2139              :                           int value, bool autofdo)
    2140              : {
    2141          157 :   if (!autofdo)
    2142              :     {
    2143          157 :       SET_OPTION_IF_UNSET (opts, opts_set, flag_branch_probabilities, value);
    2144          157 :       SET_OPTION_IF_UNSET (opts, opts_set, flag_profile_values, value);
    2145              :     }
    2146          157 :   SET_OPTION_IF_UNSET (opts, opts_set, flag_value_profile_transformations,
    2147              :                        value);
    2148              : 
    2149              :   /* Enable IPA optimizatins that makes effective use of profile data.  */
    2150          157 :   SET_OPTION_IF_UNSET (opts, opts_set, flag_inline_functions, value);
    2151          157 :   SET_OPTION_IF_UNSET (opts, opts_set, flag_ipa_cp, value);
    2152          157 :   if (value)
    2153              :     {
    2154          157 :       SET_OPTION_IF_UNSET (opts, opts_set, flag_ipa_cp_clone, 1);
    2155          157 :       SET_OPTION_IF_UNSET (opts, opts_set, flag_ipa_bit_cp, 1);
    2156              :     }
    2157              : 
    2158          157 :   SET_OPTION_IF_UNSET (opts, opts_set, flag_gcse_after_reload, value);
    2159          157 :   SET_OPTION_IF_UNSET (opts, opts_set, flag_tracer, value);
    2160              : 
    2161              :   /* Loop optimizations uses profile feedback to determine their profitability
    2162              :      and thus it makes sense to enable them by default even at -O2.
    2163              :      Auto-profile, in its current form, is not very good on determining
    2164              :      iteration counts and thus only real profile feedback is used.  */
    2165          157 :   if (!autofdo)
    2166              :     {
    2167          157 :       SET_OPTION_IF_UNSET (opts, opts_set, flag_unroll_loops, value);
    2168          157 :       SET_OPTION_IF_UNSET (opts, opts_set, flag_peel_loops, value);
    2169          157 :       SET_OPTION_IF_UNSET (opts, opts_set, flag_predictive_commoning, value);
    2170          157 :       SET_OPTION_IF_UNSET (opts, opts_set, flag_split_loops, value);
    2171          157 :       SET_OPTION_IF_UNSET (opts, opts_set, flag_unswitch_loops, value);
    2172          157 :       SET_OPTION_IF_UNSET (opts, opts_set, flag_tree_loop_vectorize, value);
    2173          157 :       SET_OPTION_IF_UNSET (opts, opts_set, flag_tree_slp_vectorize, value);
    2174          157 :       SET_OPTION_IF_UNSET (opts, opts_set, flag_version_loops_for_strides, value);
    2175          157 :       SET_OPTION_IF_UNSET (opts, opts_set, flag_vect_cost_model,
    2176              :                            VECT_COST_MODEL_DYNAMIC);
    2177          157 :       SET_OPTION_IF_UNSET (opts, opts_set, flag_tree_loop_distribute_patterns,
    2178              :                            value);
    2179          157 :       SET_OPTION_IF_UNSET (opts, opts_set, flag_loop_interchange, value);
    2180          157 :       SET_OPTION_IF_UNSET (opts, opts_set, flag_unroll_jam, value);
    2181          157 :       SET_OPTION_IF_UNSET (opts, opts_set, flag_tree_loop_distribution, value);
    2182          157 :       SET_OPTION_IF_UNSET (opts, opts_set, flag_optimize_crc, value);
    2183              :     }
    2184          157 : }
    2185              : 
    2186              : /* -f{,no-}sanitize{,-recover}= suboptions.  */
    2187              : const struct sanitizer_opts_s sanitizer_opts[] =
    2188              : {
    2189              : #define SANITIZER_OPT(name, flags, recover, trap) \
    2190              :     { #name, flags, sizeof #name - 1, recover, trap }
    2191              :   SANITIZER_OPT (address, (SANITIZE_ADDRESS | SANITIZE_USER_ADDRESS), true,
    2192              :                  false),
    2193              :   SANITIZER_OPT (hwaddress, (SANITIZE_HWADDRESS | SANITIZE_USER_HWADDRESS),
    2194              :                  true, false),
    2195              :   SANITIZER_OPT (kernel-address, (SANITIZE_ADDRESS | SANITIZE_KERNEL_ADDRESS),
    2196              :                  true, false),
    2197              :   SANITIZER_OPT (kernel-hwaddress,
    2198              :                  (SANITIZE_HWADDRESS | SANITIZE_KERNEL_HWADDRESS),
    2199              :                  true, false),
    2200              :   SANITIZER_OPT (pointer-compare, SANITIZE_POINTER_COMPARE, true, false),
    2201              :   SANITIZER_OPT (pointer-subtract, SANITIZE_POINTER_SUBTRACT, true, false),
    2202              :   SANITIZER_OPT (thread, SANITIZE_THREAD, false, false),
    2203              :   SANITIZER_OPT (leak, SANITIZE_LEAK, false, false),
    2204              :   SANITIZER_OPT (shift, SANITIZE_SHIFT, true, true),
    2205              :   SANITIZER_OPT (shift-base, SANITIZE_SHIFT_BASE, true, true),
    2206              :   SANITIZER_OPT (shift-exponent, SANITIZE_SHIFT_EXPONENT, true, true),
    2207              :   SANITIZER_OPT (integer-divide-by-zero, SANITIZE_DIVIDE, true, true),
    2208              :   SANITIZER_OPT (undefined, SANITIZE_UNDEFINED, true, true),
    2209              :   SANITIZER_OPT (unreachable, SANITIZE_UNREACHABLE, false, true),
    2210              :   SANITIZER_OPT (vla-bound, SANITIZE_VLA, true, true),
    2211              :   SANITIZER_OPT (return, SANITIZE_RETURN, false, true),
    2212              :   SANITIZER_OPT (null, SANITIZE_NULL, true, true),
    2213              :   SANITIZER_OPT (signed-integer-overflow, SANITIZE_SI_OVERFLOW, true, true),
    2214              :   SANITIZER_OPT (bool, SANITIZE_BOOL, true, true),
    2215              :   SANITIZER_OPT (enum, SANITIZE_ENUM, true, true),
    2216              :   SANITIZER_OPT (float-divide-by-zero, SANITIZE_FLOAT_DIVIDE, true, true),
    2217              :   SANITIZER_OPT (float-cast-overflow, SANITIZE_FLOAT_CAST, true, true),
    2218              :   SANITIZER_OPT (bounds, SANITIZE_BOUNDS, true, true),
    2219              :   SANITIZER_OPT (bounds-strict, SANITIZE_BOUNDS | SANITIZE_BOUNDS_STRICT, true,
    2220              :                  true),
    2221              :   SANITIZER_OPT (alignment, SANITIZE_ALIGNMENT, true, true),
    2222              :   SANITIZER_OPT (nonnull-attribute, SANITIZE_NONNULL_ATTRIBUTE, true, true),
    2223              :   SANITIZER_OPT (returns-nonnull-attribute, SANITIZE_RETURNS_NONNULL_ATTRIBUTE,
    2224              :                  true, true),
    2225              :   SANITIZER_OPT (object-size, SANITIZE_OBJECT_SIZE, true, true),
    2226              :   SANITIZER_OPT (vptr, SANITIZE_VPTR, true, false),
    2227              :   SANITIZER_OPT (pointer-overflow, SANITIZE_POINTER_OVERFLOW, true, true),
    2228              :   SANITIZER_OPT (builtin, SANITIZE_BUILTIN, true, true),
    2229              :   SANITIZER_OPT (shadow-call-stack, SANITIZE_SHADOW_CALL_STACK, false, false),
    2230              :   SANITIZER_OPT (memtag-stack, SANITIZE_MEMTAG_STACK, false, false),
    2231              :   SANITIZER_OPT (all, ~sanitize_code_type (0), true, true),
    2232              : #undef SANITIZER_OPT
    2233              :   { NULL, sanitize_code_type (0), 0UL, false, false }
    2234              : };
    2235              : 
    2236              : /* -fzero-call-used-regs= suboptions.  */
    2237              : const struct zero_call_used_regs_opts_s zero_call_used_regs_opts[] =
    2238              : {
    2239              : #define ZERO_CALL_USED_REGS_OPT(name, flags) \
    2240              :     { #name, flags }
    2241              :   ZERO_CALL_USED_REGS_OPT (skip, zero_regs_flags::SKIP),
    2242              :   ZERO_CALL_USED_REGS_OPT (used-gpr-arg, zero_regs_flags::USED_GPR_ARG),
    2243              :   ZERO_CALL_USED_REGS_OPT (used-gpr, zero_regs_flags::USED_GPR),
    2244              :   ZERO_CALL_USED_REGS_OPT (used-arg, zero_regs_flags::USED_ARG),
    2245              :   ZERO_CALL_USED_REGS_OPT (used, zero_regs_flags::USED),
    2246              :   ZERO_CALL_USED_REGS_OPT (all-gpr-arg, zero_regs_flags::ALL_GPR_ARG),
    2247              :   ZERO_CALL_USED_REGS_OPT (all-gpr, zero_regs_flags::ALL_GPR),
    2248              :   ZERO_CALL_USED_REGS_OPT (all-arg, zero_regs_flags::ALL_ARG),
    2249              :   ZERO_CALL_USED_REGS_OPT (all, zero_regs_flags::ALL),
    2250              :   ZERO_CALL_USED_REGS_OPT (leafy-gpr-arg, zero_regs_flags::LEAFY_GPR_ARG),
    2251              :   ZERO_CALL_USED_REGS_OPT (leafy-gpr, zero_regs_flags::LEAFY_GPR),
    2252              :   ZERO_CALL_USED_REGS_OPT (leafy-arg, zero_regs_flags::LEAFY_ARG),
    2253              :   ZERO_CALL_USED_REGS_OPT (leafy, zero_regs_flags::LEAFY),
    2254              : #undef ZERO_CALL_USED_REGS_OPT
    2255              :   {NULL, 0U}
    2256              : };
    2257              : 
    2258              : /* A struct for describing a run of chars within a string.  */
    2259              : 
    2260              : class string_fragment
    2261              : {
    2262              : public:
    2263            6 :   string_fragment (const char *start, size_t len)
    2264            6 :   : m_start (start), m_len (len) {}
    2265              : 
    2266              :   const char *m_start;
    2267              :   size_t m_len;
    2268              : };
    2269              : 
    2270              : /* Specialization of edit_distance_traits for string_fragment,
    2271              :    for use by get_closest_sanitizer_option.  */
    2272              : 
    2273              : template <>
    2274              : struct edit_distance_traits<const string_fragment &>
    2275              : {
    2276            6 :   static size_t get_length (const string_fragment &fragment)
    2277              :   {
    2278            6 :     return fragment.m_len;
    2279              :   }
    2280              : 
    2281            6 :   static const char *get_string (const string_fragment &fragment)
    2282              :   {
    2283            6 :     return fragment.m_start;
    2284              :   }
    2285              : };
    2286              : 
    2287              : /* Given ARG, an unrecognized sanitizer option, return the best
    2288              :    matching sanitizer option, or NULL if there isn't one.
    2289              :    OPTS is array of candidate sanitizer options.
    2290              :    CODE is OPT_fsanitize_, OPT_fsanitize_recover_ or OPT_fsanitize_trap_.
    2291              :    VALUE is non-zero for the regular form of the option, zero
    2292              :    for the "no-" form (e.g. "-fno-sanitize-recover=").  */
    2293              : 
    2294              : static const char *
    2295            6 : get_closest_sanitizer_option (const string_fragment &arg,
    2296              :                               const struct sanitizer_opts_s *opts,
    2297              :                               enum opt_code code, int value)
    2298              : {
    2299            6 :   best_match <const string_fragment &, const char*> bm (arg);
    2300          210 :   for (int i = 0; opts[i].name != NULL; ++i)
    2301              :     {
    2302              :       /* -fsanitize=all is not valid, so don't offer it.  */
    2303          204 :       if (code == OPT_fsanitize_
    2304          170 :           && opts[i].flag == ~sanitize_code_type (0)
    2305            5 :           && value)
    2306            4 :         continue;
    2307              : 
    2308              :       /* For -fsanitize-recover= (and not -fno-sanitize-recover=),
    2309              :          don't offer the non-recoverable options.  */
    2310          200 :       if (code == OPT_fsanitize_recover_
    2311           34 :           && !opts[i].can_recover
    2312            6 :           && value)
    2313            6 :         continue;
    2314              : 
    2315              :       /* For -fsanitize-trap= (and not -fno-sanitize-trap=),
    2316              :          don't offer the non-trapping options.  */
    2317          194 :       if (code == OPT_fsanitize_trap_
    2318            0 :           && !opts[i].can_trap
    2319            0 :           && value)
    2320            0 :         continue;
    2321              : 
    2322          194 :       bm.consider (opts[i].name);
    2323              :     }
    2324            6 :   return bm.get_best_meaningful_candidate ();
    2325              : }
    2326              : 
    2327              : /* Parse comma separated sanitizer suboptions from P for option SCODE,
    2328              :    adjust previous FLAGS and return new ones.  If COMPLAIN is false,
    2329              :    don't issue diagnostics.  */
    2330              : 
    2331              : sanitize_code_type
    2332        19328 : parse_sanitizer_options (const char *p, location_t loc, int scode,
    2333              :                          sanitize_code_type flags, int value, bool complain)
    2334              : {
    2335        19328 :   enum opt_code code = (enum opt_code) scode;
    2336              : 
    2337        20263 :   while (*p != 0)
    2338              :     {
    2339        20263 :       size_t len, i;
    2340        20263 :       bool found = false;
    2341        20263 :       const char *comma = strchr (p, ',');
    2342              : 
    2343        20263 :       if (comma == NULL)
    2344        19328 :         len = strlen (p);
    2345              :       else
    2346          935 :         len = comma - p;
    2347        20263 :       if (len == 0)
    2348              :         {
    2349            0 :           p = comma + 1;
    2350            0 :           continue;
    2351              :         }
    2352              : 
    2353              :       /* Check to see if the string matches an option class name.  */
    2354       188721 :       for (i = 0; sanitizer_opts[i].name != NULL; ++i)
    2355       188715 :         if (len == sanitizer_opts[i].len
    2356        29557 :             && memcmp (p, sanitizer_opts[i].name, len) == 0)
    2357              :           {
    2358              :             /* Handle both -fsanitize and -fno-sanitize cases.  */
    2359        20257 :             if (value && sanitizer_opts[i].flag == ~sanitize_code_type (0))
    2360              :               {
    2361           42 :                 if (code == OPT_fsanitize_)
    2362              :                   {
    2363            3 :                     if (complain)
    2364            3 :                       error_at (loc, "%<-fsanitize=all%> option is not valid");
    2365              :                   }
    2366           39 :                 else if (code == OPT_fsanitize_recover_)
    2367           13 :                   flags |= ~(SANITIZE_THREAD | SANITIZE_LEAK
    2368              :                              | SANITIZE_UNREACHABLE | SANITIZE_RETURN
    2369              :                              | SANITIZE_SHADOW_CALL_STACK
    2370              :                              | SANITIZE_MEMTAG_STACK);
    2371              :                 else /* if (code == OPT_fsanitize_trap_) */
    2372           26 :                   flags |= (SANITIZE_UNDEFINED
    2373              :                             | SANITIZE_UNDEFINED_NONDEFAULT);
    2374              :               }
    2375        18935 :             else if (value)
    2376              :               {
    2377              :                 /* Do not enable -fsanitize-recover=unreachable and
    2378              :                    -fsanitize-recover=return if -fsanitize-recover=undefined
    2379              :                    is selected.  */
    2380        18935 :                 if (code == OPT_fsanitize_recover_
    2381          404 :                     && sanitizer_opts[i].flag == SANITIZE_UNDEFINED)
    2382           40 :                   flags |= (SANITIZE_UNDEFINED
    2383              :                             & ~(SANITIZE_UNREACHABLE | SANITIZE_RETURN));
    2384        18895 :                 else if (code == OPT_fsanitize_trap_
    2385          176 :                          && sanitizer_opts[i].flag == SANITIZE_VPTR)
    2386            0 :                   error_at (loc, "%<-fsanitize-trap=%s%> is not supported",
    2387              :                             sanitizer_opts[i].name);
    2388              :                 else
    2389        18895 :                   flags |= sanitizer_opts[i].flag;
    2390              :               }
    2391              :             else
    2392              :               {
    2393         1280 :                 flags &= ~sanitizer_opts[i].flag;
    2394              :                 /* Don't always clear SANITIZE_ADDRESS if it was previously
    2395              :                    set: -fsanitize=address -fno-sanitize=kernel-address should
    2396              :                    leave SANITIZE_ADDRESS set.  */
    2397         1280 :                 if (flags & (SANITIZE_KERNEL_ADDRESS | SANITIZE_USER_ADDRESS))
    2398          754 :                   flags |= SANITIZE_ADDRESS;
    2399              :               }
    2400              :             found = true;
    2401              :             break;
    2402              :           }
    2403              : 
    2404        20263 :       if (! found && complain)
    2405              :         {
    2406            6 :           const char *hint
    2407            6 :             = get_closest_sanitizer_option (string_fragment (p, len),
    2408              :                                             sanitizer_opts, code, value);
    2409              : 
    2410            6 :           const char *suffix;
    2411            6 :           if (code == OPT_fsanitize_recover_)
    2412              :             suffix = "-recover";
    2413            5 :           else if (code == OPT_fsanitize_trap_)
    2414              :             suffix = "-trap";
    2415              :           else
    2416            5 :             suffix = "";
    2417              : 
    2418            6 :           if (hint)
    2419            4 :             error_at (loc,
    2420              :                       "unrecognized argument to %<-f%ssanitize%s=%> "
    2421              :                       "option: %q.*s; did you mean %qs?",
    2422              :                       value ? "" : "no-",
    2423              :                       suffix, (int) len, p, hint);
    2424              :           else
    2425            3 :             error_at (loc,
    2426              :                       "unrecognized argument to %<-f%ssanitize%s=%> option: "
    2427              :                       "%q.*s", value ? "" : "no-",
    2428              :                       suffix, (int) len, p);
    2429              :         }
    2430              : 
    2431        20263 :       if (comma == NULL)
    2432              :         break;
    2433          935 :       p = comma + 1;
    2434              :     }
    2435        19328 :   return flags;
    2436              : }
    2437              : 
    2438              : /* Parse string values of no_sanitize attribute passed in VALUE.
    2439              :    Values are separated with comma.  */
    2440              : 
    2441              : sanitize_code_type
    2442          280 : parse_no_sanitize_attribute (char *value)
    2443              : {
    2444          280 :   sanitize_code_type flags = 0;
    2445          280 :   unsigned int i;
    2446          280 :   char *q = strtok (value, ",");
    2447              : 
    2448         1070 :   while (q != NULL)
    2449              :     {
    2450         6155 :       for (i = 0; sanitizer_opts[i].name != NULL; ++i)
    2451         6135 :         if (strcmp (sanitizer_opts[i].name, q) == 0)
    2452              :           {
    2453          490 :             flags |= sanitizer_opts[i].flag;
    2454          490 :             if (sanitizer_opts[i].flag == SANITIZE_UNDEFINED)
    2455           57 :               flags |= SANITIZE_UNDEFINED_NONDEFAULT;
    2456              :             break;
    2457              :           }
    2458              : 
    2459          510 :       if (sanitizer_opts[i].name == NULL)
    2460           20 :         warning (OPT_Wattributes,
    2461              :                  "%qs attribute directive ignored", q);
    2462              : 
    2463          510 :       q = strtok (NULL, ",");
    2464              :     }
    2465              : 
    2466          280 :   return flags;
    2467              : }
    2468              : 
    2469              : /* Parse -fzero-call-used-regs suboptions from ARG, return the FLAGS.  */
    2470              : 
    2471              : unsigned int
    2472           78 : parse_zero_call_used_regs_options (const char *arg)
    2473              : {
    2474           78 :   unsigned int flags = 0;
    2475              : 
    2476              :   /* Check to see if the string matches a sub-option name.  */
    2477          468 :   for (unsigned int i = 0; zero_call_used_regs_opts[i].name != NULL; ++i)
    2478          468 :     if (strcmp (arg, zero_call_used_regs_opts[i].name) == 0)
    2479              :       {
    2480           78 :         flags = zero_call_used_regs_opts[i].flag;
    2481           78 :         break;
    2482              :       }
    2483              : 
    2484           78 :   if (!flags)
    2485            0 :     error ("unrecognized argument to %<-fzero-call-used-regs=%>: %qs", arg);
    2486              : 
    2487           78 :   return flags;
    2488              : }
    2489              : 
    2490              : /* Parse -falign-NAME format for a FLAG value.  Return individual
    2491              :    parsed integer values into RESULT_VALUES array.  If REPORT_ERROR is
    2492              :    set, print error message at LOC location.  */
    2493              : 
    2494              : bool
    2495       373181 : parse_and_check_align_values (const char *flag,
    2496              :                               const char *name,
    2497              :                               auto_vec<unsigned> &result_values,
    2498              :                               bool report_error,
    2499              :                               location_t loc)
    2500              : {
    2501       373181 :   char *str = xstrdup (flag);
    2502      1243900 :   for (char *p = strtok (str, ":"); p; p = strtok (NULL, ":"))
    2503              :     {
    2504       870719 :       char *end;
    2505       870719 :       int v = strtol (p, &end, 10);
    2506       870719 :       if (*end != '\0' || v < 0)
    2507              :         {
    2508            0 :           if (report_error)
    2509            0 :             error_at (loc, "invalid arguments for %<-falign-%s%> option: %qs",
    2510              :                       name, flag);
    2511              : 
    2512            0 :           return false;
    2513              :         }
    2514              : 
    2515       870719 :       result_values.safe_push ((unsigned)v);
    2516              :     }
    2517              : 
    2518       373181 :   free (str);
    2519              : 
    2520              :   /* Check that we have a correct number of values.  */
    2521       746362 :   if (result_values.is_empty () || result_values.length () > 4)
    2522              :     {
    2523            0 :       if (report_error)
    2524            0 :         error_at (loc, "invalid number of arguments for %<-falign-%s%> "
    2525              :                   "option: %qs", name, flag);
    2526              :       return false;
    2527              :     }
    2528              : 
    2529      1243899 :   for (unsigned i = 0; i < result_values.length (); i++)
    2530       870719 :     if (result_values[i] > MAX_CODE_ALIGN_VALUE)
    2531              :       {
    2532            1 :         if (report_error)
    2533            1 :           error_at (loc, "%<-falign-%s%> is not between 0 and %d",
    2534              :                     name, MAX_CODE_ALIGN_VALUE);
    2535              :         return false;
    2536              :       }
    2537              : 
    2538              :   return true;
    2539              : }
    2540              : 
    2541              : /* Check that alignment value FLAG for -falign-NAME is valid at a given
    2542              :    location LOC. OPT_STR points to the stored -falign-NAME=argument and
    2543              :    OPT_FLAG points to the associated -falign-NAME on/off flag.  */
    2544              : 
    2545              : static void
    2546           20 : check_alignment_argument (location_t loc, const char *flag, const char *name,
    2547              :                           int *opt_flag, const char **opt_str)
    2548              : {
    2549           20 :   auto_vec<unsigned> align_result;
    2550           20 :   parse_and_check_align_values (flag, name, align_result, true, loc);
    2551              : 
    2552           40 :   if (align_result.length() >= 1 && align_result[0] == 0)
    2553              :     {
    2554            0 :       *opt_flag = 1;
    2555            0 :       *opt_str = NULL;
    2556              :     }
    2557           20 : }
    2558              : 
    2559              : /* Parse argument of -fpatchable-function-entry option ARG and store
    2560              :    corresponding values to PATCH_AREA_SIZE and PATCH_AREA_START.
    2561              :    If REPORT_ERROR is set to true, generate error for a problematic
    2562              :    option arguments.  */
    2563              : 
    2564              : void
    2565      1815041 : parse_and_check_patch_area (const char *arg, bool report_error,
    2566              :                             HOST_WIDE_INT *patch_area_size,
    2567              :                             HOST_WIDE_INT *patch_area_start)
    2568              : {
    2569      1815041 :   *patch_area_size = 0;
    2570      1815041 :   *patch_area_start = 0;
    2571              : 
    2572      1815041 :   if (arg == NULL)
    2573              :     return;
    2574              : 
    2575          115 :   char *patch_area_arg = xstrdup (arg);
    2576          115 :   char *comma = strchr (patch_area_arg, ',');
    2577          115 :   if (comma)
    2578              :     {
    2579           52 :       *comma = '\0';
    2580           52 :       *patch_area_size = integral_argument (patch_area_arg);
    2581           52 :       *patch_area_start = integral_argument (comma + 1);
    2582              :     }
    2583              :   else
    2584           63 :     *patch_area_size = integral_argument (patch_area_arg);
    2585              : 
    2586          115 :   if (*patch_area_size < 0
    2587          115 :       || *patch_area_size > USHRT_MAX
    2588          107 :       || *patch_area_start < 0
    2589          107 :       || *patch_area_start > USHRT_MAX
    2590           99 :       || *patch_area_size < *patch_area_start)
    2591           16 :     if (report_error)
    2592            8 :       error ("invalid arguments for %<-fpatchable-function-entry%>");
    2593              : 
    2594          115 :   free (patch_area_arg);
    2595              : }
    2596              : 
    2597              : /* Print options enabled by -fhardened.  Keep this in sync with the manual!  */
    2598              : 
    2599              : static void
    2600            1 : print_help_hardened ()
    2601              : {
    2602            1 :   printf ("%s\n", "The following options are enabled by -fhardened:");
    2603              :   /* Unfortunately, I can't seem to use targetm.fortify_source_default_level
    2604              :      here.  */
    2605            1 :   printf ("  %s\n", "-D_FORTIFY_SOURCE=3 (or =2 for glibc < 2.35)");
    2606            1 :   printf ("  %s\n", "-D_GLIBCXX_ASSERTIONS");
    2607            1 :   printf ("  %s\n", "-ftrivial-auto-var-init=zero");
    2608              : #ifdef HAVE_LD_PIE
    2609            1 :   printf ("  %s  %s\n", "-fPIE", "-pie");
    2610              : #endif
    2611            1 :   if (HAVE_LD_NOW_SUPPORT)
    2612            1 :     printf ("  %s\n", "-Wl,-z,now");
    2613            1 :   if (HAVE_LD_RELRO_SUPPORT)
    2614            1 :     printf ("  %s\n", "-Wl,-z,relro");
    2615            1 :   printf ("  %s\n", "-fstack-protector-strong");
    2616            1 :   printf ("  %s\n", "-fstack-clash-protection");
    2617            1 :   printf ("  %s\n", "-fcf-protection=full");
    2618            1 :   putchar ('\n');
    2619            1 : }
    2620              : 
    2621              : /* Print help when OPT__help_ is set.  */
    2622              : 
    2623              : void
    2624           75 : print_help (struct gcc_options *opts, unsigned int lang_mask,
    2625              :             const char *help_option_argument)
    2626              : {
    2627           75 :   const char *a = help_option_argument;
    2628           75 :   unsigned int include_flags = 0;
    2629              :   /* Note - by default we include undocumented options when listing
    2630              :      specific classes.  If you only want to see documented options
    2631              :      then add ",^undocumented" to the --help= option.  E.g.:
    2632              : 
    2633              :      --help=target,^undocumented  */
    2634           75 :   unsigned int exclude_flags = 0;
    2635              : 
    2636           75 :   if (lang_mask == CL_DRIVER)
    2637            0 :     return;
    2638              : 
    2639              :   /* Walk along the argument string, parsing each word in turn.
    2640              :      The format is:
    2641              :      arg = [^]{word}[,{arg}]
    2642              :      word = {optimizers|target|warnings|undocumented|
    2643              :      params|common|<language>}  */
    2644           85 :   while (*a != 0)
    2645              :     {
    2646           85 :       static const struct
    2647              :         {
    2648              :           const char *string;
    2649              :           unsigned int flag;
    2650              :         }
    2651              :       specifics[] =
    2652              :         {
    2653              :             { "optimizers", CL_OPTIMIZATION },
    2654              :             { "target", CL_TARGET },
    2655              :             { "warnings", CL_WARNING },
    2656              :             { "undocumented", CL_UNDOCUMENTED },
    2657              :             { "params", CL_PARAMS },
    2658              :             { "joined", CL_JOINED },
    2659              :             { "separate", CL_SEPARATE },
    2660              :             { "common", CL_COMMON },
    2661              :             { NULL, 0 }
    2662              :         };
    2663           85 :       unsigned int *pflags;
    2664           85 :       const char *comma;
    2665           85 :       unsigned int lang_flag, specific_flag;
    2666           85 :       unsigned int len;
    2667           85 :       unsigned int i;
    2668              : 
    2669           85 :       if (*a == '^')
    2670              :         {
    2671            8 :           ++a;
    2672            8 :           if (*a == '\0')
    2673              :             {
    2674            1 :               error ("missing argument to %qs", "--help=^");
    2675            1 :               break;
    2676              :             }
    2677            7 :           pflags = &exclude_flags;
    2678              :         }
    2679              :       else
    2680           77 :         pflags = &include_flags;
    2681              : 
    2682           84 :       comma = strchr (a, ',');
    2683           84 :       if (comma == NULL)
    2684           74 :         len = strlen (a);
    2685              :       else
    2686           10 :         len = comma - a;
    2687           84 :       if (len == 0)
    2688              :         {
    2689            0 :           a = comma + 1;
    2690            0 :           continue;
    2691              :         }
    2692              : 
    2693              :       /* Check to see if the string matches an option class name.  */
    2694          439 :       for (i = 0, specific_flag = 0; specifics[i].string != NULL; i++)
    2695          426 :         if (strncasecmp (a, specifics[i].string, len) == 0)
    2696              :           {
    2697           71 :             specific_flag = specifics[i].flag;
    2698           71 :             break;
    2699              :           }
    2700              : 
    2701              :       /* Check to see if the string matches a language name.
    2702              :          Note - we rely upon the alpha-sorted nature of the entries in
    2703              :          the lang_names array, specifically that shorter names appear
    2704              :          before their longer variants.  (i.e. C before C++).  That way
    2705              :          when we are attempting to match --help=c for example we will
    2706              :          match with C first and not C++.  */
    2707         1309 :       for (i = 0, lang_flag = 0; i < cl_lang_count; i++)
    2708         1239 :         if (strncasecmp (a, lang_names[i], len) == 0)
    2709              :           {
    2710           14 :             lang_flag = 1U << i;
    2711           14 :             break;
    2712              :           }
    2713              : 
    2714           84 :       if (specific_flag != 0)
    2715              :         {
    2716           71 :           if (lang_flag == 0)
    2717           69 :             *pflags |= specific_flag;
    2718              :           else
    2719              :             {
    2720              :               /* The option's argument matches both the start of a
    2721              :                  language name and the start of an option class name.
    2722              :                  We have a special case for when the user has
    2723              :                  specified "--help=c", but otherwise we have to issue
    2724              :                  a warning.  */
    2725            2 :               if (strncasecmp (a, "c", len) == 0)
    2726            2 :                 *pflags |= lang_flag;
    2727              :               else
    2728            0 :                 warning (0,
    2729              :                          "%<--help%> argument %q.*s is ambiguous, "
    2730              :                          "please be more specific",
    2731              :                          len, a);
    2732              :             }
    2733              :         }
    2734           13 :       else if (lang_flag != 0)
    2735           12 :         *pflags |= lang_flag;
    2736            1 :       else if (strncasecmp (a, "hardened", len) == 0)
    2737            1 :         print_help_hardened ();
    2738              :       else
    2739            0 :         warning (0,
    2740              :                  "unrecognized argument to %<--help=%> option: %q.*s",
    2741              :                  len, a);
    2742              : 
    2743           84 :       if (comma == NULL)
    2744              :         break;
    2745           10 :       a = comma + 1;
    2746              :     }
    2747              : 
    2748              :   /* We started using PerFunction/Optimization for parameters and
    2749              :      a warning.  We should exclude these from optimization options.  */
    2750           75 :   if (include_flags & CL_OPTIMIZATION)
    2751            7 :     exclude_flags |= CL_WARNING;
    2752           75 :   if (!(include_flags & CL_PARAMS))
    2753           44 :     exclude_flags |= CL_PARAMS;
    2754              : 
    2755           75 :   if (include_flags)
    2756           71 :     print_specific_help (include_flags, exclude_flags, 0, opts,
    2757              :                          lang_mask);
    2758              : }
    2759              : 
    2760              : /* Handle target- and language-independent options.  Return zero to
    2761              :    generate an "unknown option" message.  Only options that need
    2762              :    extra handling need to be listed here; if you simply want
    2763              :    DECODED->value assigned to a variable, it happens automatically.  */
    2764              : 
    2765              : bool
    2766     84080329 : common_handle_option (struct gcc_options *opts,
    2767              :                       struct gcc_options *opts_set,
    2768              :                       const struct cl_decoded_option *decoded,
    2769              :                       unsigned int lang_mask, int kind ATTRIBUTE_UNUSED,
    2770              :                       location_t loc,
    2771              :                       const struct cl_option_handlers *handlers,
    2772              :                       diagnostics::context *dc,
    2773              :                       void (*target_option_override_hook) (void))
    2774              : {
    2775     84080329 :   size_t scode = decoded->opt_index;
    2776     84080329 :   const char *arg = decoded->arg;
    2777     84080329 :   HOST_WIDE_INT value = decoded->value;
    2778     84080329 :   enum opt_code code = (enum opt_code) scode;
    2779              : 
    2780     84080329 :   gcc_assert (decoded->canonical_option_num_elements <= 2);
    2781              : 
    2782     84080329 :   switch (code)
    2783              :     {
    2784            7 :     case OPT__help:
    2785            7 :       {
    2786            7 :         unsigned int all_langs_mask = (1U << cl_lang_count) - 1;
    2787            7 :         unsigned int undoc_mask;
    2788            7 :         unsigned int i;
    2789              : 
    2790            7 :         if (lang_mask == CL_DRIVER)
    2791              :           break;
    2792              : 
    2793            0 :         undoc_mask = ((opts->x_verbose_flag | opts->x_extra_warnings)
    2794            3 :                       ? 0
    2795              :                       : CL_UNDOCUMENTED);
    2796            3 :         target_option_override_hook ();
    2797              :         /* First display any single language specific options.  */
    2798           54 :         for (i = 0; i < cl_lang_count; i++)
    2799           48 :           print_specific_help
    2800           48 :             (1U << i, (all_langs_mask & (~ (1U << i))) | undoc_mask, 0, opts,
    2801              :              lang_mask);
    2802              :         /* Next display any multi language specific options.  */
    2803            3 :         print_specific_help (0, undoc_mask, all_langs_mask, opts, lang_mask);
    2804              :         /* Then display any remaining, non-language options.  */
    2805           24 :         for (i = CL_MIN_OPTION_CLASS; i <= CL_MAX_OPTION_CLASS; i <<= 1)
    2806           18 :           if (i != CL_DRIVER)
    2807           15 :             print_specific_help (i, undoc_mask, 0, opts, lang_mask);
    2808            3 :         opts->x_exit_after_options = true;
    2809            3 :         break;
    2810              :       }
    2811              : 
    2812            0 :     case OPT__target_help:
    2813            0 :       if (lang_mask == CL_DRIVER)
    2814              :         break;
    2815              : 
    2816            0 :       target_option_override_hook ();
    2817            0 :       print_specific_help (CL_TARGET, 0, 0, opts, lang_mask);
    2818            0 :       opts->x_exit_after_options = true;
    2819            0 :       break;
    2820              : 
    2821          150 :     case OPT__help_:
    2822          150 :       {
    2823          150 :         help_option_arguments.safe_push (arg);
    2824          150 :         opts->x_exit_after_options = true;
    2825          150 :         break;
    2826              :       }
    2827              : 
    2828           78 :     case OPT__version:
    2829           78 :       if (lang_mask == CL_DRIVER)
    2830              :         break;
    2831              : 
    2832            0 :       opts->x_exit_after_options = true;
    2833            0 :       break;
    2834              : 
    2835              :     case OPT__completion_:
    2836              :       break;
    2837              : 
    2838        18056 :     case OPT_fsanitize_:
    2839        18056 :       opts_set->x_flag_sanitize = true;
    2840        18056 :       opts->x_flag_sanitize
    2841        18056 :         = parse_sanitizer_options (arg, loc, code,
    2842              :                                    opts->x_flag_sanitize, value, true);
    2843              : 
    2844              :       /* Kernel ASan implies normal ASan but does not yet support
    2845              :          all features.  */
    2846        18056 :       if (opts->x_flag_sanitize & SANITIZE_KERNEL_ADDRESS)
    2847              :         {
    2848          372 :           SET_OPTION_IF_UNSET (opts, opts_set,
    2849              :                                param_asan_instrumentation_with_call_threshold,
    2850              :                                0);
    2851          372 :           SET_OPTION_IF_UNSET (opts, opts_set, param_asan_globals, 0);
    2852          372 :           SET_OPTION_IF_UNSET (opts, opts_set, param_asan_stack, 0);
    2853          372 :           SET_OPTION_IF_UNSET (opts, opts_set, param_asan_protect_allocas, 0);
    2854          372 :           SET_OPTION_IF_UNSET (opts, opts_set, param_asan_use_after_return, 0);
    2855              :         }
    2856        18056 :       if (opts->x_flag_sanitize & SANITIZE_KERNEL_HWADDRESS)
    2857              :         {
    2858           56 :           SET_OPTION_IF_UNSET (opts, opts_set,
    2859              :                                param_hwasan_instrument_stack, 0);
    2860           56 :           SET_OPTION_IF_UNSET (opts, opts_set,
    2861              :                                param_hwasan_random_frame_tag, 0);
    2862           56 :           SET_OPTION_IF_UNSET (opts, opts_set,
    2863              :                                param_hwasan_instrument_allocas, 0);
    2864              :         }
    2865              :       break;
    2866              : 
    2867         1070 :     case OPT_fsanitize_recover_:
    2868         1070 :       opts->x_flag_sanitize_recover
    2869         1070 :         = parse_sanitizer_options (arg, loc, code,
    2870              :                                    opts->x_flag_sanitize_recover, value, true);
    2871         1070 :       break;
    2872              : 
    2873          202 :     case OPT_fsanitize_trap_:
    2874          202 :       opts->x_flag_sanitize_trap
    2875          202 :         = parse_sanitizer_options (arg, loc, code,
    2876              :                                    opts->x_flag_sanitize_trap, value, true);
    2877          202 :       break;
    2878              : 
    2879              :     case OPT_fasan_shadow_offset_:
    2880              :       /* Deferred.  */
    2881              :       break;
    2882              : 
    2883           68 :     case OPT_fsanitize_address_use_after_scope:
    2884           68 :       opts->x_flag_sanitize_address_use_after_scope = value;
    2885           68 :       break;
    2886              : 
    2887            6 :     case OPT_fsanitize_recover:
    2888            6 :       if (value)
    2889            0 :         opts->x_flag_sanitize_recover
    2890            0 :           |= (SANITIZE_UNDEFINED | SANITIZE_UNDEFINED_NONDEFAULT)
    2891              :              & ~(SANITIZE_UNREACHABLE | SANITIZE_RETURN);
    2892              :       else
    2893            6 :         opts->x_flag_sanitize_recover
    2894            6 :           &= ~(SANITIZE_UNDEFINED | SANITIZE_UNDEFINED_NONDEFAULT);
    2895              :       break;
    2896              : 
    2897          238 :     case OPT_fsanitize_trap:
    2898          238 :       if (value)
    2899          238 :         opts->x_flag_sanitize_trap
    2900          238 :           |= (SANITIZE_UNDEFINED | SANITIZE_UNDEFINED_NONDEFAULT);
    2901              :       else
    2902            0 :         opts->x_flag_sanitize_trap
    2903            0 :           &= ~(SANITIZE_UNDEFINED | SANITIZE_UNDEFINED_NONDEFAULT);
    2904              :       break;
    2905              : 
    2906              :     case OPT_O:
    2907              :     case OPT_Os:
    2908              :     case OPT_Ofast:
    2909              :     case OPT_Og:
    2910              :     case OPT_Oz:
    2911              :       /* Currently handled in a prescan.  */
    2912              :       break;
    2913              : 
    2914          100 :     case OPT_Wattributes_:
    2915          100 :       if (lang_mask == CL_DRIVER)
    2916              :         break;
    2917              : 
    2918          100 :       if (value)
    2919              :         {
    2920            0 :           error_at (loc, "arguments ignored for %<-Wattributes=%>; use "
    2921              :                     "%<-Wno-attributes=%> instead");
    2922            0 :           break;
    2923              :         }
    2924          100 :       else if (arg[strlen (arg) - 1] == ',')
    2925              :         {
    2926            0 :           error_at (loc, "trailing %<,%> in arguments for "
    2927              :                     "%<-Wno-attributes=%>");
    2928            0 :           break;
    2929              :         }
    2930              : 
    2931          100 :       add_comma_separated_to_vector (&opts->x_flag_ignored_attributes, arg);
    2932          100 :       break;
    2933              : 
    2934         4382 :     case OPT_Werror:
    2935         4382 :       dc->set_warning_as_error_requested (value);
    2936         4382 :       break;
    2937              : 
    2938         7069 :     case OPT_Werror_:
    2939         7069 :       if (lang_mask == CL_DRIVER)
    2940              :         break;
    2941              : 
    2942         7069 :       enable_warning_as_error (arg, value, lang_mask, handlers,
    2943              :                                opts, opts_set, loc, dc);
    2944         7069 :       break;
    2945              : 
    2946            8 :     case OPT_Wfatal_errors:
    2947            8 :       dc->set_fatal_errors (value);
    2948            8 :       break;
    2949              : 
    2950           12 :     case OPT_Wstack_usage_:
    2951           12 :       opts->x_flag_stack_usage_info = value != -1;
    2952           12 :       break;
    2953              : 
    2954           57 :     case OPT_Wstrict_aliasing:
    2955           57 :       set_Wstrict_aliasing (opts, value);
    2956           57 :       break;
    2957              : 
    2958           37 :     case OPT_Wsystem_headers:
    2959           37 :       dc->m_warn_system_headers = value;
    2960           37 :       break;
    2961              : 
    2962            0 :     case OPT_aux_info:
    2963            0 :       opts->x_flag_gen_aux_info = 1;
    2964            0 :       break;
    2965              : 
    2966         1648 :     case OPT_d:
    2967         1648 :       decode_d_option (arg, opts, loc, dc);
    2968         1648 :       break;
    2969              : 
    2970              :     case OPT_fcall_used_:
    2971              :     case OPT_fcall_saved_:
    2972              :       /* Deferred.  */
    2973              :       break;
    2974              : 
    2975              :     case OPT_fdbg_cnt_:
    2976              :       /* Deferred.  */
    2977              :       break;
    2978              : 
    2979              :     case OPT_fdebug_prefix_map_:
    2980              :     case OPT_ffile_prefix_map_:
    2981              :     case OPT_fprofile_prefix_map_:
    2982              :       /* Deferred.  */
    2983              :       break;
    2984              : 
    2985            0 :     case OPT_fcanon_prefix_map:
    2986            0 :       flag_canon_prefix_map = value;
    2987            0 :       break;
    2988              : 
    2989            1 :     case OPT_fcallgraph_info:
    2990            1 :       opts->x_flag_callgraph_info = CALLGRAPH_INFO_NAKED;
    2991            1 :       break;
    2992              : 
    2993            0 :     case OPT_fcallgraph_info_:
    2994            0 :       {
    2995            0 :         char *my_arg, *p;
    2996            0 :         my_arg = xstrdup (arg);
    2997            0 :         p = strtok (my_arg, ",");
    2998            0 :         while (p)
    2999              :           {
    3000            0 :             if (strcmp (p, "su") == 0)
    3001              :               {
    3002            0 :                 opts->x_flag_callgraph_info |= CALLGRAPH_INFO_STACK_USAGE;
    3003            0 :                 opts->x_flag_stack_usage_info = true;
    3004              :               }
    3005            0 :             else if (strcmp (p, "da") == 0)
    3006            0 :               opts->x_flag_callgraph_info |= CALLGRAPH_INFO_DYNAMIC_ALLOC;
    3007              :             else
    3008              :               return 0;
    3009            0 :             p = strtok (NULL, ",");
    3010              :           }
    3011            0 :         free (my_arg);
    3012              :       }
    3013            0 :       break;
    3014              : 
    3015          432 :     case OPT_fdiagnostics_show_location_:
    3016          432 :       dc->set_prefixing_rule ((diagnostic_prefixing_rule_t) value);
    3017          432 :       break;
    3018              : 
    3019       277774 :     case OPT_fdiagnostics_show_caret:
    3020       277774 :       dc->get_source_printing_options ().enabled = value;
    3021       277774 :       break;
    3022              : 
    3023       277774 :     case OPT_fdiagnostics_show_event_links:
    3024       277774 :       dc->get_source_printing_options ().show_event_links_p = value;
    3025       277774 :       break;
    3026              : 
    3027            1 :     case OPT_fdiagnostics_show_labels:
    3028            1 :       dc->get_source_printing_options ().show_labels_p = value;
    3029            1 :       break;
    3030              : 
    3031       277774 :     case OPT_fdiagnostics_show_line_numbers:
    3032       277774 :       dc->get_source_printing_options ().show_line_numbers_p = value;
    3033       277774 :       break;
    3034              : 
    3035       557686 :     case OPT_fdiagnostics_color_:
    3036       557686 :       diagnostic_color_init (dc, value);
    3037       557686 :       break;
    3038              : 
    3039       548011 :     case OPT_fdiagnostics_urls_:
    3040       548011 :       diagnostic_urls_init (dc, value);
    3041       548011 :       break;
    3042              : 
    3043           90 :     case OPT_fdiagnostics_format_:
    3044           90 :         {
    3045           90 :           const char *basename = get_diagnostic_file_output_basename (*opts);
    3046           90 :           gcc_assert (dc);
    3047           90 :           diagnostics::output_format_init (*dc,
    3048              :                                            opts->x_main_input_filename, basename,
    3049              :                                            (enum diagnostics_output_format)value,
    3050           90 :                                            opts->x_flag_diagnostics_json_formatting);
    3051           90 :           break;
    3052              :         }
    3053              : 
    3054           37 :     case OPT_fdiagnostics_add_output_:
    3055           37 :       handle_OPT_fdiagnostics_add_output_ (*opts, *dc, arg, loc);
    3056           37 :       break;
    3057              : 
    3058           14 :     case OPT_fdiagnostics_set_output_:
    3059           14 :       handle_OPT_fdiagnostics_set_output_ (*opts, *dc, arg, loc);
    3060           14 :       break;
    3061              : 
    3062       611337 :     case OPT_fdiagnostics_text_art_charset_:
    3063       611337 :       dc->set_text_art_charset ((enum diagnostic_text_art_charset)value);
    3064       611337 :       break;
    3065              : 
    3066            4 :     case OPT_fdiagnostics_parseable_fixits:
    3067            4 :       dc->set_extra_output_kind (value
    3068              :                                  ? EXTRA_DIAGNOSTIC_OUTPUT_fixits_v1
    3069              :                                  : EXTRA_DIAGNOSTIC_OUTPUT_none);
    3070            4 :       break;
    3071              : 
    3072           28 :     case OPT_fdiagnostics_column_unit_:
    3073           28 :       dc->get_column_options ().m_column_unit
    3074           28 :         = (enum diagnostics_column_unit)value;
    3075           28 :       break;
    3076              : 
    3077           12 :     case OPT_fdiagnostics_column_origin_:
    3078           12 :       dc->get_column_options ().m_column_origin = value;
    3079           12 :       break;
    3080              : 
    3081            4 :     case OPT_fdiagnostics_escape_format_:
    3082            4 :       dc->set_escape_format ((enum diagnostics_escape_format)value);
    3083            4 :       break;
    3084              : 
    3085            5 :     case OPT_fdiagnostics_show_highlight_colors:
    3086            5 :       dc->set_show_highlight_colors (value);
    3087            5 :       break;
    3088              : 
    3089            0 :     case OPT_fdiagnostics_show_cwe:
    3090            0 :       dc->set_show_cwe (value);
    3091            0 :       break;
    3092              : 
    3093            0 :     case OPT_fdiagnostics_show_rules:
    3094            0 :       dc->set_show_rules (value);
    3095            0 :       break;
    3096              : 
    3097       309096 :     case OPT_fdiagnostics_path_format_:
    3098       309096 :       dc->set_path_format ((enum diagnostic_path_format)value);
    3099       309096 :       break;
    3100              : 
    3101           76 :     case OPT_fdiagnostics_show_path_depths:
    3102           76 :       dc->set_show_path_depths (value);
    3103           76 :       break;
    3104              : 
    3105           54 :     case OPT_fdiagnostics_show_option:
    3106           54 :       dc->set_show_option_requested (value);
    3107           54 :       break;
    3108              : 
    3109       277774 :     case OPT_fdiagnostics_show_nesting:
    3110       277774 :       dc->set_show_nesting (value);
    3111       277774 :       break;
    3112              : 
    3113            0 :     case OPT_fdiagnostics_show_nesting_locations:
    3114            0 :       dc->set_show_nesting_locations (value);
    3115            0 :       break;
    3116              : 
    3117            0 :     case OPT_fdiagnostics_show_nesting_levels:
    3118            0 :       dc->set_show_nesting_levels (value);
    3119            0 :       break;
    3120              : 
    3121            1 :     case OPT_fdiagnostics_minimum_margin_width_:
    3122            1 :       dc->get_source_printing_options ().min_margin_width = value;
    3123            1 :       break;
    3124              : 
    3125              :     case OPT_fdump_:
    3126              :       /* Deferred.  */
    3127              :       break;
    3128              : 
    3129       646221 :     case OPT_ffast_math:
    3130       646221 :       set_fast_math_flags (opts, value);
    3131       646221 :       break;
    3132              : 
    3133          380 :     case OPT_funsafe_math_optimizations:
    3134          380 :       set_unsafe_math_optimizations_flags (opts, value);
    3135          380 :       break;
    3136              : 
    3137              :     case OPT_ffixed_:
    3138              :       /* Deferred.  */
    3139              :       break;
    3140              : 
    3141            9 :     case OPT_finline_limit_:
    3142            9 :       SET_OPTION_IF_UNSET (opts, opts_set, param_max_inline_insns_single,
    3143              :                            value / 2);
    3144            9 :       SET_OPTION_IF_UNSET (opts, opts_set, param_max_inline_insns_auto,
    3145              :                            value / 2);
    3146              :       break;
    3147              : 
    3148            1 :     case OPT_finstrument_functions_exclude_function_list_:
    3149            1 :       add_comma_separated_to_vector
    3150            1 :         (&opts->x_flag_instrument_functions_exclude_functions, arg);
    3151            1 :       break;
    3152              : 
    3153            1 :     case OPT_finstrument_functions_exclude_file_list_:
    3154            1 :       add_comma_separated_to_vector
    3155            1 :         (&opts->x_flag_instrument_functions_exclude_files, arg);
    3156            1 :       break;
    3157              : 
    3158       107990 :     case OPT_fmessage_length_:
    3159       107990 :       pp_set_line_maximum_length (dc->get_reference_printer (), value);
    3160       107990 :       dc->set_caret_max_width (value);
    3161       107990 :       break;
    3162              : 
    3163              :     case OPT_fopt_info:
    3164              :     case OPT_fopt_info_:
    3165              :       /* Deferred.  */
    3166              :       break;
    3167              : 
    3168              :     case OPT_foffload_options_:
    3169              :       /* Deferred.  */
    3170              :       break;
    3171              : 
    3172            0 :     case OPT_foffload_abi_:
    3173            0 :     case OPT_foffload_abi_host_opts_:
    3174              : #ifdef ACCEL_COMPILER
    3175              :       /* Handled in the 'mkoffload's.  */
    3176              : #else
    3177            0 :       error_at (loc,
    3178              :                 "%qs option can be specified only for offload compiler",
    3179              :                 (code == OPT_foffload_abi_) ? "-foffload-abi"
    3180              :                                             : "-foffload-abi-host-opts");
    3181              : #endif
    3182            0 :       break;
    3183              : 
    3184            1 :     case OPT_fpack_struct_:
    3185            1 :       if (value <= 0 || (value & (value - 1)) || value > 16)
    3186            0 :         error_at (loc,
    3187              :                   "structure alignment must be a small power of two, not %wu",
    3188              :                   value);
    3189              :       else
    3190            1 :         opts->x_initial_max_fld_align = value;
    3191              :       break;
    3192              : 
    3193              :     case OPT_fplugin_:
    3194              :     case OPT_fplugin_arg_:
    3195              :       /* Deferred.  */
    3196              :       break;
    3197              : 
    3198            0 :     case OPT_fprofile_use_:
    3199            0 :       opts->x_profile_data_prefix = xstrdup (arg);
    3200            0 :       opts->x_flag_profile_use = true;
    3201            0 :       value = true;
    3202              :       /* No break here - do -fprofile-use processing. */
    3203              :       /* FALLTHRU */
    3204          157 :     case OPT_fprofile_use:
    3205          157 :       enable_fdo_optimizations (opts, opts_set, value, false);
    3206          157 :       SET_OPTION_IF_UNSET (opts, opts_set, flag_profile_reorder_functions,
    3207              :                            value);
    3208              :         /* Indirect call profiling should do all useful transformations
    3209              :            speculative devirtualization does.  */
    3210          157 :       if (opts->x_flag_value_profile_transformations)
    3211              :         {
    3212          157 :           SET_OPTION_IF_UNSET (opts, opts_set, flag_devirtualize_speculatively,
    3213              :                                false);
    3214          157 :           SET_OPTION_IF_UNSET (opts, opts_set,
    3215              :                                flag_speculatively_call_stored_functions, false);
    3216              :         }
    3217              :       break;
    3218              : 
    3219            0 :     case OPT_fauto_profile_:
    3220            0 :       opts->x_auto_profile_file = xstrdup (arg);
    3221            0 :       opts->x_flag_auto_profile = true;
    3222            0 :       value = true;
    3223              :       /* No break here - do -fauto-profile processing. */
    3224              :       /* FALLTHRU */
    3225            0 :     case OPT_fauto_profile:
    3226            0 :       enable_fdo_optimizations (opts, opts_set, value, true);
    3227            0 :       SET_OPTION_IF_UNSET (opts, opts_set, flag_profile_correction, value);
    3228              :       break;
    3229              : 
    3230            2 :     case OPT_fprofile_generate_:
    3231            2 :       opts->x_profile_data_prefix = xstrdup (arg);
    3232            2 :       value = true;
    3233              :       /* No break here - do -fprofile-generate processing. */
    3234              :       /* FALLTHRU */
    3235          263 :     case OPT_fprofile_generate:
    3236          263 :       SET_OPTION_IF_UNSET (opts, opts_set, profile_arc_flag, value);
    3237          263 :       SET_OPTION_IF_UNSET (opts, opts_set, flag_profile_values, value);
    3238          263 :       SET_OPTION_IF_UNSET (opts, opts_set, flag_inline_functions, value);
    3239          263 :       SET_OPTION_IF_UNSET (opts, opts_set, flag_ipa_bit_cp, value);
    3240              :       break;
    3241              : 
    3242            2 :     case OPT_fprofile_info_section:
    3243            2 :       opts->x_profile_info_section = ".gcov_info";
    3244            2 :       break;
    3245              : 
    3246           36 :     case OPT_fpatchable_function_entry_:
    3247           36 :       {
    3248           36 :         HOST_WIDE_INT patch_area_size, patch_area_start;
    3249           36 :         parse_and_check_patch_area (arg, true, &patch_area_size,
    3250              :                                     &patch_area_start);
    3251              :       }
    3252           36 :       break;
    3253              : 
    3254              :     case OPT_ftree_vectorize:
    3255              :       /* Automatically sets -ftree-loop-vectorize and
    3256              :          -ftree-slp-vectorize.  Nothing more to do here.  */
    3257              :       break;
    3258           78 :     case OPT_fzero_call_used_regs_:
    3259           78 :       opts->x_flag_zero_call_used_regs
    3260           78 :         = parse_zero_call_used_regs_options (arg);
    3261           78 :       break;
    3262              : 
    3263        12810 :     case OPT_fshow_column:
    3264        12810 :       dc->m_show_column = value;
    3265        12810 :       break;
    3266              : 
    3267            0 :     case OPT_frandom_seed:
    3268              :       /* The real switch is -fno-random-seed.  */
    3269            0 :       if (value)
    3270              :         return false;
    3271              :       /* Deferred.  */
    3272              :       break;
    3273              : 
    3274              :     case OPT_frandom_seed_:
    3275              :       /* Deferred.  */
    3276              :       break;
    3277              : 
    3278              :     case OPT_fsched_verbose_:
    3279              : #ifdef INSN_SCHEDULING
    3280              :       /* Handled with Var in common.opt.  */
    3281              :       break;
    3282              : #else
    3283              :       return false;
    3284              : #endif
    3285              : 
    3286            1 :     case OPT_fsched_stalled_insns_:
    3287            1 :       opts->x_flag_sched_stalled_insns = value;
    3288            1 :       if (opts->x_flag_sched_stalled_insns == 0)
    3289            1 :         opts->x_flag_sched_stalled_insns = -1;
    3290              :       break;
    3291              : 
    3292            0 :     case OPT_fsched_stalled_insns_dep_:
    3293            0 :       opts->x_flag_sched_stalled_insns_dep = value;
    3294            0 :       break;
    3295              : 
    3296           69 :     case OPT_fstack_check_:
    3297           69 :       if (!strcmp (arg, "no"))
    3298            0 :         opts->x_flag_stack_check = NO_STACK_CHECK;
    3299           69 :       else if (!strcmp (arg, "generic"))
    3300              :         /* This is the old stack checking method.  */
    3301           36 :         opts->x_flag_stack_check = STACK_CHECK_BUILTIN
    3302              :                            ? FULL_BUILTIN_STACK_CHECK
    3303              :                            : GENERIC_STACK_CHECK;
    3304           33 :       else if (!strcmp (arg, "specific"))
    3305              :         /* This is the new stack checking method.  */
    3306           33 :         opts->x_flag_stack_check = STACK_CHECK_BUILTIN
    3307              :                            ? FULL_BUILTIN_STACK_CHECK
    3308              :                            : STACK_CHECK_STATIC_BUILTIN
    3309              :                              ? STATIC_BUILTIN_STACK_CHECK
    3310              :                              : GENERIC_STACK_CHECK;
    3311              :       else
    3312            0 :         warning_at (loc, 0, "unknown stack check parameter %qs", arg);
    3313              :       break;
    3314              : 
    3315            1 :     case OPT_fstack_limit:
    3316              :       /* The real switch is -fno-stack-limit.  */
    3317            1 :       if (value)
    3318              :         return false;
    3319              :       /* Deferred.  */
    3320              :       break;
    3321              : 
    3322              :     case OPT_fstack_limit_register_:
    3323              :     case OPT_fstack_limit_symbol_:
    3324              :       /* Deferred.  */
    3325              :       break;
    3326              : 
    3327          558 :     case OPT_fstack_usage:
    3328          558 :       opts->x_flag_stack_usage = value;
    3329          558 :       opts->x_flag_stack_usage_info = value != 0;
    3330          558 :       break;
    3331              : 
    3332       128060 :     case OPT_g:
    3333       128060 :       set_debug_level (NO_DEBUG, DEFAULT_GDB_EXTENSIONS, arg, opts, opts_set,
    3334              :                        loc);
    3335       128060 :       break;
    3336              : 
    3337            0 :     case OPT_gcodeview:
    3338            0 :       set_debug_level (CODEVIEW_DEBUG, false, arg, opts, opts_set, loc);
    3339            0 :       if (opts->x_debug_info_level < DINFO_LEVEL_NORMAL)
    3340            0 :         opts->x_debug_info_level = DINFO_LEVEL_NORMAL;
    3341              :       break;
    3342              : 
    3343          160 :     case OPT_gbtf:
    3344          160 :       set_debug_level (BTF_DEBUG, false, arg, opts, opts_set, loc);
    3345              :       /* set the debug level to level 2, but if already at level 3,
    3346              :          don't lower it.  */
    3347          160 :       if (opts->x_debug_info_level < DINFO_LEVEL_NORMAL)
    3348          160 :         opts->x_debug_info_level = DINFO_LEVEL_NORMAL;
    3349              :       break;
    3350              : 
    3351          511 :     case OPT_gctf:
    3352          511 :       set_debug_level (CTF_DEBUG, false, arg, opts, opts_set, loc);
    3353              :       /* CTF generation feeds off DWARF dies.  For optimal CTF, switch debug
    3354              :          info level to 2.  If off or at level 1, set it to level 2, but if
    3355              :          already at level 3, don't lower it.  */
    3356          511 :       if (opts->x_debug_info_level < DINFO_LEVEL_NORMAL
    3357          505 :           && opts->x_ctf_debug_info_level > CTFINFO_LEVEL_NONE)
    3358          503 :         opts->x_debug_info_level = DINFO_LEVEL_NORMAL;
    3359              :       break;
    3360              : 
    3361          253 :     case OPT_gdwarf:
    3362          253 :       if (arg && strlen (arg) != 0)
    3363              :         {
    3364            0 :           error_at (loc, "%<-gdwarf%s%> is ambiguous; "
    3365              :                     "use %<-gdwarf-%s%> for DWARF version "
    3366              :                     "or %<-gdwarf%> %<-g%s%> for debug level", arg, arg, arg);
    3367            0 :           break;
    3368              :         }
    3369              :       else
    3370          253 :         value = opts->x_dwarf_version;
    3371              : 
    3372              :       /* FALLTHRU */
    3373         4747 :     case OPT_gdwarf_:
    3374         4747 :       if (value < 2 || value > 5)
    3375            0 :         error_at (loc, "dwarf version %wu is not supported", value);
    3376              :       else
    3377         4747 :         opts->x_dwarf_version = value;
    3378         4747 :       set_debug_level (DWARF2_DEBUG, false, "", opts, opts_set, loc);
    3379         4747 :       break;
    3380              : 
    3381           20 :     case OPT_ggdb:
    3382           20 :       set_debug_level (NO_DEBUG, 2, arg, opts, opts_set, loc);
    3383           20 :       break;
    3384              : 
    3385            0 :     case OPT_gvms:
    3386            0 :       set_debug_level (VMS_DEBUG, false, arg, opts, opts_set, loc);
    3387            0 :       break;
    3388              : 
    3389              :     case OPT_gz:
    3390              :     case OPT_gz_:
    3391              :       /* Handled completely via specs.  */
    3392              :       break;
    3393              : 
    3394        68049 :     case OPT_pedantic_errors:
    3395        68049 :       dc->m_pedantic_errors = 1;
    3396        68049 :       control_warning_option (OPT_Wpedantic,
    3397              :                               static_cast<int> (diagnostics::kind::error),
    3398              :                               NULL, value,
    3399              :                               loc, lang_mask,
    3400              :                               handlers, opts, opts_set,
    3401              :                               dc);
    3402        68049 :       break;
    3403              : 
    3404        25118 :     case OPT_flto:
    3405        25118 :       opts->x_flag_lto = value ? "" : NULL;
    3406        25118 :       break;
    3407              : 
    3408           17 :     case OPT_flto_:
    3409           17 :       if (strcmp (arg, "none") != 0
    3410           17 :           && strcmp (arg, "jobserver") != 0
    3411           17 :           && strcmp (arg, "auto") != 0
    3412            5 :           && atoi (arg) == 0)
    3413            1 :         error_at (loc,
    3414              :                   "unrecognized argument to %<-flto=%> option: %qs", arg);
    3415              :       break;
    3416              : 
    3417        44358 :     case OPT_w:
    3418        44358 :       dc->m_inhibit_warnings = true;
    3419        44358 :       break;
    3420              : 
    3421           44 :     case OPT_fmax_errors_:
    3422           44 :       dc->set_max_errors (value);
    3423           44 :       break;
    3424              : 
    3425              :     case OPT_fuse_ld_bfd:
    3426              :     case OPT_fuse_ld_gold:
    3427              :     case OPT_fuse_ld_lld:
    3428              :     case OPT_fuse_ld_mold:
    3429              :     case OPT_fuse_ld_wild:
    3430              :     case OPT_fuse_linker_plugin:
    3431              :       /* No-op. Used by the driver and passed to us because it starts with f.*/
    3432              :       break;
    3433              : 
    3434          555 :     case OPT_fwrapv:
    3435          555 :       if (value)
    3436          549 :         opts->x_flag_trapv = 0;
    3437              :       break;
    3438              : 
    3439          140 :     case OPT_ftrapv:
    3440          140 :       if (value)
    3441          140 :         opts->x_flag_wrapv = 0;
    3442              :       break;
    3443              : 
    3444          194 :     case OPT_fstrict_overflow:
    3445          194 :       opts->x_flag_wrapv = !value;
    3446          194 :       opts->x_flag_wrapv_pointer = !value;
    3447          194 :       if (!value)
    3448           64 :         opts->x_flag_trapv = 0;
    3449              :       break;
    3450              : 
    3451       645240 :     case OPT_fipa_icf:
    3452       645240 :       opts->x_flag_ipa_icf_functions = value;
    3453       645240 :       opts->x_flag_ipa_icf_variables = value;
    3454       645240 :       break;
    3455              : 
    3456            2 :     case OPT_falign_loops_:
    3457            2 :       check_alignment_argument (loc, arg, "loops",
    3458              :                                 &opts->x_flag_align_loops,
    3459              :                                 &opts->x_str_align_loops);
    3460            2 :       break;
    3461              : 
    3462            2 :     case OPT_falign_jumps_:
    3463            2 :       check_alignment_argument (loc, arg, "jumps",
    3464              :                                 &opts->x_flag_align_jumps,
    3465              :                                 &opts->x_str_align_jumps);
    3466            2 :       break;
    3467              : 
    3468            3 :     case OPT_falign_labels_:
    3469            3 :       check_alignment_argument (loc, arg, "labels",
    3470              :                                 &opts->x_flag_align_labels,
    3471              :                                 &opts->x_str_align_labels);
    3472            3 :       break;
    3473              : 
    3474           13 :     case OPT_falign_functions_:
    3475           13 :       check_alignment_argument (loc, arg, "functions",
    3476              :                                 &opts->x_flag_align_functions,
    3477              :                                 &opts->x_str_align_functions);
    3478           13 :       break;
    3479              : 
    3480           12 :     case OPT_ftabstop_:
    3481              :       /* It is documented that we silently ignore silly values.  */
    3482           12 :       if (value >= 1 && value <= 100)
    3483            8 :         dc->get_column_options ().m_tabstop = value;
    3484              :       break;
    3485              : 
    3486           16 :     case OPT_freport_bug:
    3487           16 :       dc->set_report_bug (value);
    3488           16 :       break;
    3489              : 
    3490            0 :     case OPT_fmultiflags:
    3491            0 :       gcc_checking_assert (lang_mask == CL_DRIVER);
    3492              :       break;
    3493              : 
    3494     77887546 :     default:
    3495              :       /* If the flag was handled in a standard way, assume the lack of
    3496              :          processing here is intentional.  */
    3497     77887546 :       gcc_assert (option_flag_var (scode, opts));
    3498              :       break;
    3499              :     }
    3500              : 
    3501     84080328 :   common_handle_option_auto (opts, opts_set, decoded, lang_mask, kind,
    3502              :                              loc, handlers, dc);
    3503     84080328 :   return true;
    3504              : }
    3505              : 
    3506              : /* Used to set the level of strict aliasing warnings in OPTS,
    3507              :    when no level is specified (i.e., when -Wstrict-aliasing, and not
    3508              :    -Wstrict-aliasing=level was given).
    3509              :    ONOFF is assumed to take value 1 when -Wstrict-aliasing is specified,
    3510              :    and 0 otherwise.  After calling this function, wstrict_aliasing will be
    3511              :    set to the default value of -Wstrict_aliasing=level, currently 3.  */
    3512              : static void
    3513           57 : set_Wstrict_aliasing (struct gcc_options *opts, int onoff)
    3514              : {
    3515           57 :   gcc_assert (onoff == 0 || onoff == 1);
    3516           57 :   if (onoff != 0)
    3517              :     opts->x_warn_strict_aliasing = 3;
    3518              :   else
    3519            1 :     opts->x_warn_strict_aliasing = 0;
    3520           57 : }
    3521              : 
    3522              : /* The following routines are useful in setting all the flags that
    3523              :    -ffast-math and -fno-fast-math imply.  */
    3524              : static void
    3525       646221 : set_fast_math_flags (struct gcc_options *opts, int set)
    3526              : {
    3527       646221 :   if (!opts->frontend_set_flag_unsafe_math_optimizations)
    3528              :     {
    3529       646221 :       opts->x_flag_unsafe_math_optimizations = set;
    3530       646221 :       set_unsafe_math_optimizations_flags (opts, set);
    3531              :     }
    3532       646221 :   if (!opts->frontend_set_flag_finite_math_only)
    3533       646221 :     opts->x_flag_finite_math_only = set;
    3534       646221 :   if (!opts->frontend_set_flag_errno_math)
    3535       592742 :     opts->x_flag_errno_math = !set;
    3536       646221 :   if (set)
    3537              :     {
    3538         2064 :       if (opts->frontend_set_flag_excess_precision == EXCESS_PRECISION_DEFAULT)
    3539         2064 :         opts->x_flag_excess_precision
    3540         2064 :           = set ? EXCESS_PRECISION_FAST : EXCESS_PRECISION_DEFAULT;
    3541         2064 :       if (!opts->frontend_set_flag_signaling_nans)
    3542         2064 :         opts->x_flag_signaling_nans = 0;
    3543         2064 :       if (!opts->frontend_set_flag_rounding_math)
    3544         2064 :         opts->x_flag_rounding_math = 0;
    3545         2064 :       if (!opts->frontend_set_flag_complex_method)
    3546         2064 :         opts->x_flag_complex_method = 0;
    3547              :     }
    3548       646221 : }
    3549              : 
    3550              : /* When -funsafe-math-optimizations is set the following
    3551              :    flags are set as well.  */
    3552              : static void
    3553       646601 : set_unsafe_math_optimizations_flags (struct gcc_options *opts, int set)
    3554              : {
    3555       646601 :   if (!opts->frontend_set_flag_trapping_math)
    3556       646601 :     opts->x_flag_trapping_math = !set;
    3557       646601 :   if (!opts->frontend_set_flag_signed_zeros)
    3558       646601 :     opts->x_flag_signed_zeros = !set;
    3559       646601 :   if (!opts->frontend_set_flag_associative_math)
    3560       613565 :     opts->x_flag_associative_math = set;
    3561       646601 :   if (!opts->frontend_set_flag_reciprocal_math)
    3562       646601 :     opts->x_flag_reciprocal_math = set;
    3563       646601 : }
    3564              : 
    3565              : /* Return true iff flags in OPTS are set as if -ffast-math.  */
    3566              : bool
    3567     49871561 : fast_math_flags_set_p (const struct gcc_options *opts)
    3568              : {
    3569     49871561 :   return (!opts->x_flag_trapping_math
    3570      1002855 :           && opts->x_flag_unsafe_math_optimizations
    3571       994660 :           && opts->x_flag_finite_math_only
    3572       994588 :           && !opts->x_flag_signed_zeros
    3573       994574 :           && !opts->x_flag_errno_math
    3574     50866131 :           && opts->x_flag_excess_precision == EXCESS_PRECISION_FAST);
    3575              : }
    3576              : 
    3577              : /* Return true iff flags are set as if -ffast-math but using the flags stored
    3578              :    in the struct cl_optimization structure.  */
    3579              : bool
    3580         1276 : fast_math_flags_struct_set_p (struct cl_optimization *opt)
    3581              : {
    3582         1276 :   return (!opt->x_flag_trapping_math
    3583           43 :           && opt->x_flag_unsafe_math_optimizations
    3584           23 :           && opt->x_flag_finite_math_only
    3585           19 :           && !opt->x_flag_signed_zeros
    3586         1295 :           && !opt->x_flag_errno_math);
    3587              : }
    3588              : 
    3589              : /* Handle a debug output -g switch for options OPTS
    3590              :    (OPTS_SET->x_write_symbols storing whether a debug format was passed
    3591              :    explicitly), location LOC.  EXTENDED is true or false to support
    3592              :    extended output (2 is special and means "-ggdb" was given).  */
    3593              : static void
    3594       133498 : set_debug_level (uint32_t dinfo, int extended, const char *arg,
    3595              :                  struct gcc_options *opts, struct gcc_options *opts_set,
    3596              :                  location_t loc)
    3597              : {
    3598       133498 :   if (dinfo == NO_DEBUG)
    3599              :     {
    3600       128080 :       if (opts->x_write_symbols == NO_DEBUG)
    3601              :         {
    3602       111875 :           opts->x_write_symbols = PREFERRED_DEBUGGING_TYPE;
    3603              : 
    3604       111875 :           if (extended == 2)
    3605              :             {
    3606              : #if defined DWARF2_DEBUGGING_INFO || defined DWARF2_LINENO_DEBUGGING_INFO
    3607       111875 :               if (opts->x_write_symbols & CTF_DEBUG)
    3608              :                 opts->x_write_symbols |= DWARF2_DEBUG;
    3609              :               else
    3610       111875 :                 opts->x_write_symbols = DWARF2_DEBUG;
    3611              : #endif
    3612              :             }
    3613              : 
    3614       111875 :           if (opts->x_write_symbols == NO_DEBUG)
    3615              :             warning_at (loc, 0, "target system does not support debug output");
    3616              :         }
    3617        16205 :       else if ((opts->x_write_symbols & CTF_DEBUG)
    3618        16171 :                || (opts->x_write_symbols & BTF_DEBUG)
    3619        16171 :                || (opts->x_write_symbols & CODEVIEW_DEBUG))
    3620              :         {
    3621           34 :           opts->x_write_symbols |= DWARF2_DEBUG;
    3622           34 :           opts_set->x_write_symbols |= DWARF2_DEBUG;
    3623              :         }
    3624              :     }
    3625              :   else
    3626              :     {
    3627              :       /* Make and retain the choice if both CTF and DWARF debug info are to
    3628              :          be generated.  */
    3629         5418 :       if (((dinfo == DWARF2_DEBUG) || (dinfo == CTF_DEBUG))
    3630         5258 :           && ((opts->x_write_symbols == (DWARF2_DEBUG|CTF_DEBUG))
    3631              :               || (opts->x_write_symbols == DWARF2_DEBUG)
    3632              :               || (opts->x_write_symbols == CTF_DEBUG)))
    3633              :         {
    3634          124 :           opts->x_write_symbols |= dinfo;
    3635          124 :           opts_set->x_write_symbols |= dinfo;
    3636              :         }
    3637              :       /* However, CTF and BTF are not allowed together at this time.  */
    3638         5294 :       else if (((dinfo == DWARF2_DEBUG) || (dinfo == BTF_DEBUG))
    3639         4789 :                && ((opts->x_write_symbols == (DWARF2_DEBUG|BTF_DEBUG))
    3640              :                    || (opts->x_write_symbols == DWARF2_DEBUG)
    3641              :                    || (opts->x_write_symbols == BTF_DEBUG)))
    3642              :         {
    3643            0 :           opts->x_write_symbols |= dinfo;
    3644            0 :           opts_set->x_write_symbols |= dinfo;
    3645              :         }
    3646              :       else
    3647              :         {
    3648              :           /* Does it conflict with an already selected debug format?  */
    3649         5294 :           if (opts_set->x_write_symbols != NO_DEBUG
    3650            0 :               && opts->x_write_symbols != NO_DEBUG
    3651            0 :               && dinfo != opts->x_write_symbols)
    3652              :             {
    3653            0 :               gcc_assert (debug_set_count (dinfo) <= 1);
    3654            0 :               error_at (loc, "debug format %qs conflicts with prior selection",
    3655            0 :                         debug_type_names[debug_set_to_format (dinfo)]);
    3656              :             }
    3657         5294 :           opts->x_write_symbols = dinfo;
    3658         5294 :           opts_set->x_write_symbols = dinfo;
    3659              :         }
    3660              :     }
    3661              : 
    3662       133498 :   if (dinfo != BTF_DEBUG)
    3663              :     {
    3664              :       /* A debug flag without a level defaults to level 2.
    3665              :          If off or at level 1, set it to level 2, but if already
    3666              :          at level 3, don't lower it.  */
    3667       133338 :       if (*arg == '\0')
    3668              :         {
    3669       127901 :           if (dinfo == CTF_DEBUG)
    3670          509 :             opts->x_ctf_debug_info_level = CTFINFO_LEVEL_NORMAL;
    3671       127392 :           else if (opts->x_debug_info_level < DINFO_LEVEL_NORMAL)
    3672       113711 :             opts->x_debug_info_level = DINFO_LEVEL_NORMAL;
    3673              :         }
    3674              :       else
    3675              :         {
    3676         5437 :           int argval = integral_argument (arg);
    3677         5437 :           if (argval == -1)
    3678            0 :             error_at (loc, "unrecognized debug output level %qs", arg);
    3679         5437 :           else if (argval > 3)
    3680            0 :             error_at (loc, "debug output level %qs is too high", arg);
    3681              :           else
    3682              :             {
    3683         5437 :               if (dinfo == CTF_DEBUG)
    3684            2 :                 opts->x_ctf_debug_info_level
    3685            2 :                   = (enum ctf_debug_info_levels) argval;
    3686              :               else
    3687         5435 :                 opts->x_debug_info_level = (enum debug_info_levels) argval;
    3688              :             }
    3689              :         }
    3690              :     }
    3691          160 :   else if (*arg != '\0')
    3692            0 :     error_at (loc, "unrecognized btf debug output level %qs", arg);
    3693       133498 : }
    3694              : 
    3695              : /* Arrange to dump core on error for diagnostic context DC.  (The
    3696              :    regular error message is still printed first, except in the case of
    3697              :    abort ().)  */
    3698              : 
    3699              : static void
    3700           13 : setup_core_dumping (diagnostics::context *dc)
    3701              : {
    3702              : #ifdef SIGABRT
    3703           13 :   signal (SIGABRT, SIG_DFL);
    3704              : #endif
    3705              : #if defined(HAVE_SETRLIMIT)
    3706           13 :   {
    3707           13 :     struct rlimit rlim;
    3708           13 :     if (getrlimit (RLIMIT_CORE, &rlim) != 0)
    3709            0 :       fatal_error (input_location, "getting core file size maximum limit: %m");
    3710           13 :     rlim.rlim_cur = rlim.rlim_max;
    3711           13 :     if (setrlimit (RLIMIT_CORE, &rlim) != 0)
    3712            0 :       fatal_error (input_location,
    3713              :                    "setting core file size limit to maximum: %m");
    3714              :   }
    3715              : #endif
    3716           13 :   dc->set_abort_on_error (true);
    3717           13 : }
    3718              : 
    3719              : /* Parse a -d<ARG> command line switch for OPTS, location LOC,
    3720              :    diagnostic context DC.  */
    3721              : 
    3722              : static void
    3723         1648 : decode_d_option (const char *arg, struct gcc_options *opts,
    3724              :                  location_t loc, diagnostics::context *dc)
    3725              : {
    3726         1648 :   int c;
    3727              : 
    3728         3296 :   while (*arg)
    3729         1648 :     switch (c = *arg++)
    3730              :       {
    3731          704 :       case 'A':
    3732          704 :         opts->x_flag_debug_asm = 1;
    3733          704 :         break;
    3734          123 :       case 'p':
    3735          123 :         opts->x_flag_print_asm_name = 1;
    3736          123 :         break;
    3737            5 :       case 'P':
    3738            5 :         opts->x_flag_dump_rtl_in_asm = 1;
    3739            5 :         opts->x_flag_print_asm_name = 1;
    3740            5 :         break;
    3741           10 :       case 'x':
    3742           10 :         opts->x_rtl_dump_and_exit = 1;
    3743           10 :         break;
    3744              :       case 'D': /* These are handled by the preprocessor.  */
    3745              :       case 'I':
    3746              :       case 'M':
    3747              :       case 'N':
    3748              :       case 'U':
    3749              :         break;
    3750           13 :       case 'H':
    3751           13 :         setup_core_dumping (dc);
    3752           13 :         break;
    3753            4 :       case 'a':
    3754            4 :         opts->x_flag_dump_all_passed = true;
    3755            4 :         break;
    3756              : 
    3757            0 :       default:
    3758            0 :           warning_at (loc, 0, "unrecognized gcc debugging option: %c", c);
    3759            0 :         break;
    3760              :       }
    3761         1648 : }
    3762              : 
    3763              : /* Enable (or disable if VALUE is 0) a warning option ARG (language
    3764              :    mask LANG_MASK, option handlers HANDLERS) as an error for option
    3765              :    structures OPTS and OPTS_SET, diagnostic context DC (possibly
    3766              :    NULL), location LOC.  This is used by -Werror=.  */
    3767              : 
    3768              : static void
    3769         7069 : enable_warning_as_error (const char *arg, int value, unsigned int lang_mask,
    3770              :                          const struct cl_option_handlers *handlers,
    3771              :                          struct gcc_options *opts,
    3772              :                          struct gcc_options *opts_set,
    3773              :                          location_t loc, diagnostics::context *dc)
    3774              : {
    3775         7069 :   char *new_option;
    3776         7069 :   int option_index;
    3777              : 
    3778         7069 :   new_option = XNEWVEC (char, strlen (arg) + 2);
    3779         7069 :   new_option[0] = 'W';
    3780         7069 :   strcpy (new_option + 1, arg);
    3781         7069 :   option_index = find_opt (new_option, lang_mask);
    3782         7069 :   if (option_index == OPT_SPECIAL_unknown)
    3783              :     {
    3784            2 :       option_proposer op;
    3785            2 :       const char *hint = op.suggest_option (new_option);
    3786            2 :       if (hint)
    3787            3 :         error_at (loc, "%<-W%serror=%s%>: no option %<-%s%>;"
    3788              :                   " did you mean %<-%s%>?", value ? "" : "no-",
    3789              :                   arg, new_option, hint);
    3790              :       else
    3791            0 :         error_at (loc, "%<-W%serror=%s%>: no option %<-%s%>",
    3792              :                   value ? "" : "no-", arg, new_option);
    3793            2 :     }
    3794         7067 :   else if (!(cl_options[option_index].flags & CL_WARNING))
    3795            4 :     error_at (loc, "%<-Werror=%s%>: %<-%s%> is not an option that "
    3796              :               "controls warnings", arg, new_option);
    3797              :   else
    3798              :     {
    3799         1114 :       const enum diagnostics::kind kind = (value
    3800         7063 :                                            ? diagnostics::kind::error
    3801              :                                            : diagnostics::kind::warning);
    3802         7063 :       const char *arg = NULL;
    3803              : 
    3804         7063 :       if (cl_options[option_index].flags & CL_JOINED)
    3805           17 :         arg = new_option + cl_options[option_index].opt_len;
    3806         7063 :       control_warning_option (option_index, (int) kind, arg, value,
    3807              :                               loc, lang_mask,
    3808              :                               handlers, opts, opts_set, dc);
    3809              :     }
    3810         7069 :   free (new_option);
    3811         7069 : }
    3812              : 
    3813              : /* Return the name of the option OPTION_INDEX which enabled a diagnostic,
    3814              :    originally of type ORIG_DIAG_KIND but possibly converted to DIAG_KIND by
    3815              :    options such as -Werror.   Can return null if OPTION_ID is zero.  */
    3816              : 
    3817              : label_text
    3818      1652700 : compiler_diagnostic_option_id_manager::
    3819              : get_option_name (diagnostics::option_id option_id,
    3820              :                  enum diagnostics::kind orig_diag_kind,
    3821              :                  enum diagnostics::kind diag_kind) const
    3822              : {
    3823      1652700 :   if (option_id.m_idx)
    3824              :     {
    3825              :       /* A warning classified as an error.  */
    3826        96478 :       if ((orig_diag_kind == diagnostics::kind::warning
    3827        96478 :            || orig_diag_kind == diagnostics::kind::pedwarn)
    3828        80844 :           && diag_kind == diagnostics::kind::error)
    3829          224 :         return label_text::take
    3830          224 :           (concat (cl_options[OPT_Werror_].opt_text,
    3831              :                    /* Skip over "-W".  */
    3832          224 :                    cl_options[option_id.m_idx].opt_text + 2,
    3833          224 :                    NULL));
    3834              :       /* A warning with option.  */
    3835              :       else
    3836        96254 :         return label_text::take
    3837        96254 :           (xstrdup (cl_options[option_id.m_idx].opt_text));
    3838              :     }
    3839              :   /* A warning without option classified as an error.  */
    3840      1556222 :   else if ((orig_diag_kind == diagnostics::kind::warning
    3841      1556222 :             || orig_diag_kind == diagnostics::kind::pedwarn
    3842      1524659 :             || diag_kind == diagnostics::kind::warning)
    3843      1556222 :            && m_context.warning_as_error_requested_p ())
    3844          102 :     return label_text::borrow (cl_options[OPT_Werror].opt_text);
    3845              :   else
    3846      1556120 :     return label_text ();
    3847              : }
    3848              : 
    3849              : /* Get the page within the documentation for this option.  */
    3850              : 
    3851              : static const char *
    3852        12582 : get_option_html_page (int option_index)
    3853              : {
    3854        12582 :   const cl_option *cl_opt = &cl_options[option_index];
    3855              : 
    3856              : #ifdef CL_Fortran
    3857        12582 :   if ((cl_opt->flags & CL_Fortran) != 0
    3858              :       /* If it is option common to both C/C++ and Fortran, it is documented
    3859              :          in gcc/ rather than gfortran/ docs.  */
    3860           90 :       && (cl_opt->flags & CL_C) == 0
    3861              : #ifdef CL_CXX
    3862           80 :       && (cl_opt->flags & CL_CXX) == 0
    3863              : #endif
    3864              :      )
    3865           80 :     return "gfortran/Error-and-Warning-Options.html";
    3866              : #endif
    3867              : 
    3868              :   return nullptr;
    3869              : }
    3870              : 
    3871              : /* Get the url within the documentation for this option, or NULL.  */
    3872              : 
    3873              : label_text
    3874        27075 : get_option_url_suffix (int option_index, unsigned lang_mask)
    3875              : {
    3876        27075 :   if (const char *url = get_opt_url_suffix (option_index, lang_mask))
    3877              : 
    3878        14493 :     return label_text::borrow (url);
    3879              : 
    3880              :   /* Fallback code for some options that aren't handled byt opt_url_suffixes
    3881              :      e.g. links below "gfortran/".  */
    3882        12582 :   if (const char *html_page = get_option_html_page (option_index))
    3883           80 :     return label_text::take
    3884              :       (concat (html_page,
    3885              :                /* Expect an anchor of the form "index-Wfoo" e.g.
    3886              :                   <a name="index-Wformat"></a>, and thus an id within
    3887              :                   the page of "#index-Wformat".  */
    3888              :                "#index",
    3889           80 :                cl_options[option_index].opt_text,
    3890           80 :                NULL));
    3891              : 
    3892        12502 :   return label_text ();
    3893              : }
    3894              : 
    3895              : /* Return a URL describing the option OPTION_INDEX which enabled
    3896              :    a diagnostic, or null.  */
    3897              : 
    3898              : label_text
    3899          124 : gcc_diagnostic_option_id_manager::
    3900              : get_option_url (diagnostics::option_id option_id) const
    3901              : {
    3902          124 :   if (option_id.m_idx)
    3903              :     {
    3904          124 :       label_text url_suffix = get_option_url_suffix (option_id.m_idx,
    3905          124 :                                                      m_lang_mask);
    3906          124 :       if (url_suffix.get ())
    3907          124 :         return label_text::take
    3908          124 :           (concat (DOCUMENTATION_ROOT_URL, url_suffix.get (), nullptr));
    3909          124 :     }
    3910              : 
    3911            0 :   return label_text ();
    3912              : }
    3913              : 
    3914              : /* Return a heap allocated producer with command line options.  */
    3915              : 
    3916              : char *
    3917        53353 : gen_command_line_string (cl_decoded_option *options,
    3918              :                          unsigned int options_count)
    3919              : {
    3920        53353 :   auto_vec<const char *> switches;
    3921        53353 :   char *options_string, *tail;
    3922        53353 :   const char *p;
    3923        53353 :   size_t len = 0;
    3924              : 
    3925      1851762 :   for (unsigned i = 0; i < options_count; i++)
    3926      1798409 :     switch (options[i].opt_index)
    3927              :       {
    3928       807153 :       case OPT_o:
    3929       807153 :       case OPT_d:
    3930       807153 :       case OPT_dumpbase:
    3931       807153 :       case OPT_dumpbase_ext:
    3932       807153 :       case OPT_dumpdir:
    3933       807153 :       case OPT_quiet:
    3934       807153 :       case OPT_version:
    3935       807153 :       case OPT_v:
    3936       807153 :       case OPT_w:
    3937       807153 :       case OPT_L:
    3938       807153 :       case OPT_I:
    3939       807153 :       case OPT_SPECIAL_unknown:
    3940       807153 :       case OPT_SPECIAL_ignore:
    3941       807153 :       case OPT_SPECIAL_warn_removed:
    3942       807153 :       case OPT_SPECIAL_program_name:
    3943       807153 :       case OPT_SPECIAL_input_file:
    3944       807153 :       case OPT_grecord_gcc_switches:
    3945       807153 :       case OPT_frecord_gcc_switches:
    3946       807153 :       case OPT__output_pch:
    3947       807153 :       case OPT_fdiagnostics_show_highlight_colors:
    3948       807153 :       case OPT_fdiagnostics_show_location_:
    3949       807153 :       case OPT_fdiagnostics_show_option:
    3950       807153 :       case OPT_fdiagnostics_show_caret:
    3951       807153 :       case OPT_fdiagnostics_show_event_links:
    3952       807153 :       case OPT_fdiagnostics_show_labels:
    3953       807153 :       case OPT_fdiagnostics_show_line_numbers:
    3954       807153 :       case OPT_fdiagnostics_color_:
    3955       807153 :       case OPT_fdiagnostics_format_:
    3956       807153 :       case OPT_fdiagnostics_show_nesting:
    3957       807153 :       case OPT_fdiagnostics_show_nesting_locations:
    3958       807153 :       case OPT_fdiagnostics_show_nesting_levels:
    3959       807153 :       case OPT_fverbose_asm:
    3960       807153 :       case OPT____:
    3961       807153 :       case OPT__sysroot_:
    3962       807153 :       case OPT_nostdinc:
    3963       807153 :       case OPT_nostdinc__:
    3964       807153 :       case OPT_fpreprocessed:
    3965       807153 :       case OPT_fltrans_output_list_:
    3966       807153 :       case OPT_fltrans_linemap_file_:
    3967       807153 :       case OPT_fresolution_:
    3968       807153 :       case OPT_fdebug_prefix_map_:
    3969       807153 :       case OPT_fmacro_prefix_map_:
    3970       807153 :       case OPT_ffile_prefix_map_:
    3971       807153 :       case OPT_fprofile_prefix_map_:
    3972       807153 :       case OPT_fcanon_prefix_map:
    3973       807153 :       case OPT_fcompare_debug:
    3974       807153 :       case OPT_fchecking:
    3975       807153 :       case OPT_fchecking_:
    3976              :         /* Ignore these.  */
    3977       807153 :         continue;
    3978        67113 :       case OPT_D:
    3979        67113 :       case OPT_U:
    3980        67113 :         if (startswith (options[i].arg, "_FORTIFY_SOURCE")
    3981        67113 :             && (options[i].arg[sizeof ("_FORTIFY_SOURCE") - 1] == '\0'
    3982            0 :                 || (options[i].opt_index == OPT_D
    3983            0 :                     && options[i].arg[sizeof ("_FORTIFY_SOURCE") - 1] == '=')))
    3984              :           {
    3985            0 :             switches.safe_push (options[i].orig_option_with_args_text);
    3986            0 :             len += strlen (options[i].orig_option_with_args_text) + 1;
    3987              :           }
    3988              :         /* Otherwise ignore these. */
    3989        67113 :         continue;
    3990            0 :       case OPT_flto_:
    3991            0 :         {
    3992            0 :           const char *lto_canonical = "-flto";
    3993            0 :           switches.safe_push (lto_canonical);
    3994            0 :           len += strlen (lto_canonical) + 1;
    3995            0 :           break;
    3996              :         }
    3997       924143 :       default:
    3998       924924 :         if (cl_options[options[i].opt_index].flags
    3999       924143 :             & CL_NO_DWARF_RECORD)
    4000          781 :           continue;
    4001       923362 :         gcc_checking_assert (options[i].canonical_option[0][0] == '-');
    4002       923362 :         switch (options[i].canonical_option[0][1])
    4003              :           {
    4004       274048 :           case 'M':
    4005       274048 :           case 'i':
    4006       274048 :           case 'W':
    4007       274048 :             continue;
    4008       369205 :           case 'f':
    4009       369205 :             if (strncmp (options[i].canonical_option[0] + 2,
    4010              :                          "dump", 4) == 0)
    4011         1824 :               continue;
    4012              :             break;
    4013              :           default:
    4014              :             break;
    4015              :           }
    4016       647490 :         switches.safe_push (options[i].orig_option_with_args_text);
    4017       647490 :         len += strlen (options[i].orig_option_with_args_text) + 1;
    4018       647490 :         break;
    4019       874266 :       }
    4020              : 
    4021        53353 :   options_string = XNEWVEC (char, len + 1);
    4022        53353 :   tail = options_string;
    4023              : 
    4024        53353 :   unsigned i;
    4025       754196 :   FOR_EACH_VEC_ELT (switches, i, p)
    4026              :     {
    4027       647490 :       len = strlen (p);
    4028       647490 :       memcpy (tail, p, len);
    4029       647490 :       tail += len;
    4030       647490 :       if (i != switches.length () - 1)
    4031              :         {
    4032       594137 :           *tail = ' ';
    4033       594137 :           ++tail;
    4034              :         }
    4035              :     }
    4036              : 
    4037        53353 :   *tail = '\0';
    4038        53353 :   return options_string;
    4039        53353 : }
    4040              : 
    4041              : /* Return a heap allocated producer string including command line options.  */
    4042              : 
    4043              : char *
    4044        53342 : gen_producer_string (const char *language_string, cl_decoded_option *options,
    4045              :                      unsigned int options_count)
    4046              : {
    4047        53342 :   char *cmdline = gen_command_line_string (options, options_count);
    4048        53342 :   char *combined = concat (language_string, " ", version_string, " ",
    4049              :                            cmdline, NULL);
    4050        53342 :   free (cmdline);
    4051        53342 :   return combined;
    4052              : }
    4053              : 
    4054              : #if CHECKING_P
    4055              : 
    4056              : namespace selftest {
    4057              : 
    4058              : /* Verify that get_option_url_suffix works as expected.  */
    4059              : 
    4060              : static void
    4061            4 : test_get_option_url_suffix ()
    4062              : {
    4063            4 :   ASSERT_STREQ (get_option_url_suffix (OPT_Wcpp, 0).get (),
    4064              :                 "gcc/Warning-Options.html#index-Wcpp");
    4065            4 :   ASSERT_STREQ (get_option_url_suffix (OPT_Wanalyzer_double_free, 0).get (),
    4066              :                 "gcc/Static-Analyzer-Options.html#index-Wanalyzer-double-free");
    4067              : 
    4068              :   /* Test of a D-specific option.  */
    4069              : #ifdef CL_D
    4070            4 :   ASSERT_EQ (get_option_url_suffix (OPT_fbounds_check_, 0).get (), nullptr);
    4071            4 :   ASSERT_STREQ (get_option_url_suffix (OPT_fbounds_check_, CL_D).get (),
    4072              :                 "gdc/Runtime-Options.html#index-fbounds-check");
    4073              : 
    4074              :   /* Test of a D-specific override to an option URL.  */
    4075              :   /* Generic URL.  */
    4076            4 :   ASSERT_STREQ (get_option_url_suffix (OPT_fmax_errors_, 0).get (),
    4077              :                 "gcc/Warning-Options.html#index-fmax-errors");
    4078              :   /* D-specific URL.  */
    4079            4 :   ASSERT_STREQ (get_option_url_suffix (OPT_fmax_errors_, CL_D).get (),
    4080              :                 "gdc/Warnings.html#index-fmax-errors");
    4081              : #endif
    4082              : 
    4083              : #ifdef CL_Fortran
    4084            4 :   ASSERT_STREQ
    4085              :     (get_option_url_suffix (OPT_Wline_truncation, CL_Fortran).get (),
    4086              :      "gfortran/Error-and-Warning-Options.html#index-Wline-truncation");
    4087              : #endif
    4088            4 : }
    4089              : 
    4090              : /* Verify EnumSet and EnumBitSet requirements.  */
    4091              : 
    4092              : static void
    4093            4 : test_enum_sets ()
    4094              : {
    4095        10400 :   for (unsigned i = 0; i < cl_options_count; ++i)
    4096        10396 :     if (cl_options[i].var_type == CLVC_ENUM
    4097          368 :         && cl_options[i].var_value != CLEV_NORMAL)
    4098              :       {
    4099           32 :         const struct cl_enum *e = &cl_enums[cl_options[i].var_enum];
    4100           32 :         unsigned HOST_WIDE_INT used_sets = 0;
    4101           32 :         unsigned HOST_WIDE_INT mask = 0;
    4102           32 :         unsigned highest_set = 0;
    4103          180 :         for (unsigned j = 0; e->values[j].arg; ++j)
    4104              :           {
    4105          148 :             unsigned set = e->values[j].flags >> CL_ENUM_SET_SHIFT;
    4106          148 :             if (cl_options[i].var_value == CLEV_BITSET)
    4107              :               {
    4108              :                 /* For EnumBitSet Set shouldn't be used and Value should
    4109              :                    be a power of two.  */
    4110           28 :                 ASSERT_TRUE (set == 0);
    4111           56 :                 ASSERT_TRUE (pow2p_hwi (e->values[j].value));
    4112           28 :                 continue;
    4113           28 :               }
    4114              :             /* Test that enumerators referenced in EnumSet have all
    4115              :                Set(n) on them within the valid range.  */
    4116          120 :             ASSERT_TRUE (set >= 1 && set <= HOST_BITS_PER_WIDE_INT);
    4117          120 :             highest_set = MAX (set, highest_set);
    4118          120 :             used_sets |= HOST_WIDE_INT_1U << (set - 1);
    4119              :           }
    4120           32 :         if (cl_options[i].var_value == CLEV_BITSET)
    4121            8 :           continue;
    4122              :         /* If there is just one set, no point to using EnumSet.  */
    4123           24 :         ASSERT_TRUE (highest_set >= 2);
    4124              :         /* Test that there are no gaps in between the sets.  */
    4125           24 :         if (highest_set == HOST_BITS_PER_WIDE_INT)
    4126            0 :           ASSERT_TRUE (used_sets == HOST_WIDE_INT_M1U);
    4127              :         else
    4128           24 :           ASSERT_TRUE (used_sets == (HOST_WIDE_INT_1U << highest_set) - 1);
    4129          112 :         for (unsigned int j = 1; j <= highest_set; ++j)
    4130              :           {
    4131              :             unsigned HOST_WIDE_INT this_mask = 0;
    4132          616 :             for (unsigned k = 0; e->values[k].arg; ++k)
    4133              :               {
    4134          528 :                 unsigned set = e->values[j].flags >> CL_ENUM_SET_SHIFT;
    4135          528 :                 if (set == j)
    4136          128 :                   this_mask |= e->values[j].value;
    4137              :               }
    4138           88 :             ASSERT_TRUE ((mask & this_mask) == 0);
    4139           88 :             mask |= this_mask;
    4140              :           }
    4141              :       }
    4142            4 : }
    4143              : 
    4144              : /* Run all of the selftests within this file.  */
    4145              : 
    4146              : void
    4147            4 : opts_cc_tests ()
    4148              : {
    4149            4 :   test_get_option_url_suffix ();
    4150            4 :   test_enum_sets ();
    4151            4 : }
    4152              : 
    4153              : } // namespace selftest
    4154              : 
    4155              : #endif /* #if CHECKING_P */
        

Generated by: LCOV version 2.5.0-beta

LCOV profile is generated on x86_64 machine using following configure options: configure --disable-bootstrap --enable-coverage=opt --enable-languages=c,c++,fortran,go,jit,lto,rust,m2 --enable-host-shared. GCC test suite is run with the built compiler.