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