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