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 : 107844 : btf_debuginfo_p ()
147 : : {
148 : 107844 : 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 : 433 : ctf_debuginfo_p ()
163 : : {
164 : 433 : return (write_symbols & CTF_DEBUG);
165 : : }
166 : :
167 : : /* Return TRUE iff CodeView debug info is enabled. */
168 : :
169 : : bool
170 : 439 : codeview_debuginfo_p ()
171 : : {
172 : 439 : return (write_symbols & CODEVIEW_DEBUG);
173 : : }
174 : :
175 : : /* Return TRUE iff dwarf2 debug info is enabled. */
176 : :
177 : : bool
178 : 45579794 : dwarf_debuginfo_p (struct gcc_options *opts)
179 : : {
180 : 45579794 : 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 : 4831918 : bool dwarf_based_debuginfo_p ()
187 : : {
188 : 4831918 : return ((write_symbols & CTF_DEBUG)
189 : 4830293 : || (write_symbols & BTF_DEBUG)
190 : 9661803 : || (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 : 1472 : strip_off_ending (char *name, int len)
301 : : {
302 : 1472 : int i;
303 : 1618 : for (i = 2; i < 5 && len > i; i++)
304 : : {
305 : 1618 : if (name[len - i] == '.')
306 : : {
307 : 1472 : name[len - i] = '\0';
308 : 1472 : break;
309 : : }
310 : : }
311 : 1472 : }
312 : :
313 : : /* Find the base name of a path, stripping off both directories and
314 : : a single final extension. */
315 : : int
316 : 289415 : base_of_path (const char *path, const char **base_out)
317 : : {
318 : 289415 : const char *base = path;
319 : 289415 : const char *dot = 0;
320 : 289415 : const char *p = path;
321 : 289415 : char c = *p;
322 : 22127069 : while (c)
323 : : {
324 : 21837654 : if (IS_DIR_SEPARATOR (c))
325 : : {
326 : 2477923 : base = p + 1;
327 : 2477923 : dot = 0;
328 : : }
329 : 19359731 : else if (c == '.')
330 : 503620 : dot = p;
331 : 21837654 : c = *++p;
332 : : }
333 : 289415 : if (!dot)
334 : 421 : dot = p;
335 : 289415 : *base_out = base;
336 : 289415 : 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 : 1276237 : 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 : 1276237 : gcc_assert (dc == global_dc);
375 : 1276237 : gcc_assert (static_cast<diagnostics::kind> (kind)
376 : : == diagnostics::kind::unspecified);
377 : 1276237 : 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 : 601036 : init_opts_obstack (void)
429 : : {
430 : 601036 : gcc_obstack_init (&opts_obstack);
431 : 601036 : }
432 : :
433 : : /* Initialize OPTS and OPTS_SET before using them in parsing options. */
434 : :
435 : : void
436 : 48074593 : 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 : 48074593 : gcc_assert (opts_obstack.chunk_size > 0);
441 : :
442 : 48074593 : *opts = global_options_init;
443 : :
444 : 48074593 : if (opts_set)
445 : 587738 : memset (opts_set, 0, sizeof (*opts_set));
446 : :
447 : : /* Initialize whether `char' is signed. */
448 : 48074593 : 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 : 48074593 : opts->x_target_flags = targetm_common.default_target_flags;
453 : :
454 : : /* Some targets have ABI-specified unwind tables. */
455 : 48074593 : opts->x_flag_unwind_tables = targetm_common.unwind_tables_default;
456 : :
457 : : /* Languages not explicitly specifying a default get fortran rules. */
458 : 48074593 : opts->x_flag_complex_method = 1;
459 : :
460 : : /* Some targets have other target-specific initialization. */
461 : 48074593 : targetm_common.option_init_struct (opts);
462 : 48074593 : }
463 : :
464 : : /* If indicated by the optimization level LEVEL (-Os if SIZE is set,
465 : : -Ofast if FAST is set, -Og if DEBUG is set), apply the option DEFAULT_OPT
466 : : to OPTS and OPTS_SET, diagnostic context DC, location LOC, with language
467 : : mask LANG_MASK and option handlers HANDLERS. */
468 : :
469 : : static void
470 : 75992640 : maybe_default_option (struct gcc_options *opts,
471 : : struct gcc_options *opts_set,
472 : : const struct default_options *default_opt,
473 : : int level, bool size, bool fast, bool debug,
474 : : unsigned int lang_mask,
475 : : const struct cl_option_handlers *handlers,
476 : : location_t loc,
477 : : diagnostics::context *dc)
478 : : {
479 : 75992640 : const struct cl_option *option = &cl_options[default_opt->opt_index];
480 : 75992640 : bool enabled;
481 : :
482 : 75992640 : if (size)
483 : 1836960 : gcc_assert (level == 2);
484 : 75992640 : if (fast)
485 : 74640 : gcc_assert (level == 3);
486 : 75992640 : if (debug)
487 : 91320 : gcc_assert (level == 1);
488 : :
489 : 75992640 : switch (default_opt->levels)
490 : : {
491 : : case OPT_LEVELS_ALL:
492 : : enabled = true;
493 : : break;
494 : :
495 : 0 : case OPT_LEVELS_0_ONLY:
496 : 0 : enabled = (level == 0);
497 : 0 : break;
498 : :
499 : 17731616 : case OPT_LEVELS_1_PLUS:
500 : 17731616 : enabled = (level >= 1);
501 : 17731616 : break;
502 : :
503 : 0 : case OPT_LEVELS_1_PLUS_SPEED_ONLY:
504 : 0 : enabled = (level >= 1 && !size && !debug);
505 : : break;
506 : :
507 : 9499080 : case OPT_LEVELS_1_PLUS_NOT_DEBUG:
508 : 9499080 : enabled = (level >= 1 && !debug);
509 : 9499080 : break;
510 : :
511 : 25964152 : case OPT_LEVELS_2_PLUS:
512 : 25964152 : enabled = (level >= 2);
513 : 25964152 : break;
514 : :
515 : 7599264 : case OPT_LEVELS_2_PLUS_SPEED_ONLY:
516 : 7599264 : enabled = (level >= 2 && !size && !debug);
517 : : break;
518 : :
519 : 11398896 : case OPT_LEVELS_3_PLUS:
520 : 11398896 : enabled = (level >= 3);
521 : 11398896 : break;
522 : :
523 : 0 : case OPT_LEVELS_3_PLUS_AND_SIZE:
524 : 0 : enabled = (level >= 3 || size);
525 : 0 : break;
526 : :
527 : : case OPT_LEVELS_SIZE:
528 : : enabled = size;
529 : : break;
530 : :
531 : 1899816 : case OPT_LEVELS_FAST:
532 : 1899816 : enabled = fast;
533 : 1899816 : break;
534 : :
535 : 0 : case OPT_LEVELS_NONE:
536 : 0 : default:
537 : 0 : gcc_unreachable ();
538 : : }
539 : :
540 : 66493560 : if (enabled)
541 : 50480226 : handle_generated_option (opts, opts_set, default_opt->opt_index,
542 : 50480226 : default_opt->arg, default_opt->value,
543 : : lang_mask,
544 : : static_cast<int> (diagnostics::kind::unspecified),
545 : : loc,
546 : : handlers, true, dc);
547 : 25512414 : else if (default_opt->arg == NULL
548 : 25512414 : && !option->cl_reject_negative
549 : 24303780 : && !(option->flags & CL_PARAMS))
550 : 21281550 : handle_generated_option (opts, opts_set, default_opt->opt_index,
551 : 21281550 : default_opt->arg, !default_opt->value,
552 : : lang_mask,
553 : : static_cast<int> (diagnostics::kind::unspecified),
554 : : loc,
555 : : handlers, true, dc);
556 : 75992640 : }
557 : :
558 : : /* As indicated by the optimization level LEVEL (-Os if SIZE is set,
559 : : -Ofast if FAST is set), apply the options in array DEFAULT_OPTS to
560 : : OPTS and OPTS_SET, diagnostic context DC, location LOC, with
561 : : language mask LANG_MASK and option handlers HANDLERS. */
562 : :
563 : : static void
564 : 1266544 : maybe_default_options (struct gcc_options *opts,
565 : : struct gcc_options *opts_set,
566 : : const struct default_options *default_opts,
567 : : int level, bool size, bool fast, bool debug,
568 : : unsigned int lang_mask,
569 : : const struct cl_option_handlers *handlers,
570 : : location_t loc,
571 : : diagnostics::context *dc)
572 : : {
573 : 1266544 : size_t i;
574 : :
575 : 77259184 : for (i = 0; default_opts[i].levels != OPT_LEVELS_NONE; i++)
576 : 75992640 : maybe_default_option (opts, opts_set, &default_opts[i],
577 : : level, size, fast, debug,
578 : : lang_mask, handlers, loc, dc);
579 : 1266544 : }
580 : :
581 : : /* Table of options enabled by default at different levels.
582 : : Please keep this list sorted by level and alphabetized within
583 : : each level; this makes it easier to keep the documentation
584 : : in sync. */
585 : :
586 : : static const struct default_options default_options_table[] =
587 : : {
588 : : /* -O1 and -Og optimizations. */
589 : : { OPT_LEVELS_1_PLUS, OPT_fcombine_stack_adjustments, NULL, 1 },
590 : : { OPT_LEVELS_1_PLUS, OPT_fcompare_elim, NULL, 1 },
591 : : { OPT_LEVELS_1_PLUS, OPT_fcprop_registers, NULL, 1 },
592 : : { OPT_LEVELS_1_PLUS, OPT_fdefer_pop, NULL, 1 },
593 : : { OPT_LEVELS_1_PLUS, OPT_fforward_propagate, NULL, 1 },
594 : : { OPT_LEVELS_1_PLUS, OPT_fguess_branch_probability, NULL, 1 },
595 : : { OPT_LEVELS_1_PLUS, OPT_fipa_profile, NULL, 1 },
596 : : { OPT_LEVELS_1_PLUS, OPT_fipa_pure_const, NULL, 1 },
597 : : { OPT_LEVELS_1_PLUS, OPT_fipa_reference, NULL, 1 },
598 : : { OPT_LEVELS_1_PLUS, OPT_fipa_reference_addressable, NULL, 1 },
599 : : { OPT_LEVELS_1_PLUS, OPT_fmerge_constants, NULL, 1 },
600 : : { OPT_LEVELS_1_PLUS, OPT_fomit_frame_pointer, NULL, 1 },
601 : : { OPT_LEVELS_1_PLUS, OPT_freorder_blocks, NULL, 1 },
602 : : { OPT_LEVELS_1_PLUS, OPT_fshrink_wrap, NULL, 1 },
603 : : { OPT_LEVELS_1_PLUS, OPT_fsplit_wide_types, NULL, 1 },
604 : : { OPT_LEVELS_1_PLUS, OPT_fthread_jumps, NULL, 1 },
605 : : { OPT_LEVELS_1_PLUS, OPT_ftree_builtin_call_dce, NULL, 1 },
606 : : { OPT_LEVELS_1_PLUS, OPT_ftree_ccp, NULL, 1 },
607 : : { OPT_LEVELS_1_PLUS, OPT_ftree_ch, NULL, 1 },
608 : : { OPT_LEVELS_1_PLUS, OPT_ftree_coalesce_vars, NULL, 1 },
609 : : { OPT_LEVELS_1_PLUS, OPT_ftree_copy_prop, NULL, 1 },
610 : : { OPT_LEVELS_1_PLUS, OPT_ftree_dce, NULL, 1 },
611 : : { OPT_LEVELS_1_PLUS, OPT_ftree_dominator_opts, NULL, 1 },
612 : : { OPT_LEVELS_1_PLUS, OPT_ftree_fre, NULL, 1 },
613 : : { OPT_LEVELS_1_PLUS, OPT_ftree_sink, NULL, 1 },
614 : : { OPT_LEVELS_1_PLUS, OPT_ftree_slsr, NULL, 1 },
615 : : { OPT_LEVELS_1_PLUS, OPT_ftree_ter, NULL, 1 },
616 : : { OPT_LEVELS_1_PLUS, OPT_fvar_tracking, NULL, 1 },
617 : :
618 : : /* -O1 (and not -Og) optimizations. */
619 : : { OPT_LEVELS_1_PLUS_NOT_DEBUG, OPT_fbit_tests, NULL, 1 },
620 : : { OPT_LEVELS_1_PLUS_NOT_DEBUG, OPT_fbranch_count_reg, NULL, 1 },
621 : : #if DELAY_SLOTS
622 : : { OPT_LEVELS_1_PLUS_NOT_DEBUG, OPT_fdelayed_branch, NULL, 1 },
623 : : #endif
624 : : { OPT_LEVELS_1_PLUS_NOT_DEBUG, OPT_fdse, NULL, 1 },
625 : : { OPT_LEVELS_1_PLUS_NOT_DEBUG, OPT_fif_conversion, NULL, 1 },
626 : : { OPT_LEVELS_1_PLUS_NOT_DEBUG, OPT_fif_conversion2, NULL, 1 },
627 : : { OPT_LEVELS_1_PLUS_NOT_DEBUG, OPT_finline_functions_called_once, NULL, 1 },
628 : : { OPT_LEVELS_1_PLUS_NOT_DEBUG, OPT_fjump_tables, NULL, 1 },
629 : : { OPT_LEVELS_1_PLUS_NOT_DEBUG, OPT_fmove_loop_invariants, NULL, 1 },
630 : : { OPT_LEVELS_1_PLUS_NOT_DEBUG, OPT_fmove_loop_stores, NULL, 1 },
631 : : { OPT_LEVELS_1_PLUS_NOT_DEBUG, OPT_fssa_phiopt, NULL, 1 },
632 : : { OPT_LEVELS_1_PLUS_NOT_DEBUG, OPT_fipa_modref, NULL, 1 },
633 : : { OPT_LEVELS_1_PLUS_NOT_DEBUG, OPT_ftree_bit_ccp, NULL, 1 },
634 : : { OPT_LEVELS_1_PLUS_NOT_DEBUG, OPT_ftree_dse, NULL, 1 },
635 : : { OPT_LEVELS_1_PLUS_NOT_DEBUG, OPT_ftree_pta, NULL, 1 },
636 : : { OPT_LEVELS_1_PLUS_NOT_DEBUG, OPT_ftree_sra, NULL, 1 },
637 : :
638 : : /* -O2 and -Os optimizations. */
639 : : { OPT_LEVELS_2_PLUS, OPT_fcaller_saves, NULL, 1 },
640 : : { OPT_LEVELS_2_PLUS, OPT_fcode_hoisting, NULL, 1 },
641 : : { OPT_LEVELS_2_PLUS, OPT_fcrossjumping, NULL, 1 },
642 : : { OPT_LEVELS_2_PLUS, OPT_fcse_follow_jumps, NULL, 1 },
643 : : { OPT_LEVELS_2_PLUS, OPT_fdep_fusion, NULL, 1 },
644 : : { OPT_LEVELS_2_PLUS, OPT_fdevirtualize, NULL, 1 },
645 : : { OPT_LEVELS_2_PLUS, OPT_fdevirtualize_speculatively, NULL, 1 },
646 : : { OPT_LEVELS_2_PLUS, OPT_fexpensive_optimizations, NULL, 1 },
647 : : { OPT_LEVELS_2_PLUS, OPT_fext_dce, NULL, 1 },
648 : : { OPT_LEVELS_2_PLUS, OPT_fgcse, NULL, 1 },
649 : : { OPT_LEVELS_2_PLUS, OPT_fhoist_adjacent_loads, NULL, 1 },
650 : : { OPT_LEVELS_2_PLUS, OPT_findirect_inlining, NULL, 1 },
651 : : { OPT_LEVELS_2_PLUS, OPT_finline_small_functions, NULL, 1 },
652 : : { OPT_LEVELS_2_PLUS, OPT_fipa_bit_cp, NULL, 1 },
653 : : { OPT_LEVELS_2_PLUS, OPT_fipa_cp, NULL, 1 },
654 : : { OPT_LEVELS_2_PLUS, OPT_fipa_icf, NULL, 1 },
655 : : { OPT_LEVELS_2_PLUS, OPT_fipa_ra, NULL, 1 },
656 : : { OPT_LEVELS_2_PLUS, OPT_fipa_sra, NULL, 1 },
657 : : { OPT_LEVELS_2_PLUS, OPT_fipa_vrp, NULL, 1 },
658 : : { OPT_LEVELS_2_PLUS, OPT_fisolate_erroneous_paths_dereference, NULL, 1 },
659 : : { OPT_LEVELS_2_PLUS, OPT_flra_remat, NULL, 1 },
660 : : { OPT_LEVELS_2_PLUS, OPT_foptimize_sibling_calls, NULL, 1 },
661 : : { OPT_LEVELS_2_PLUS, OPT_fpartial_inlining, NULL, 1 },
662 : : { OPT_LEVELS_2_PLUS, OPT_fpeephole2, NULL, 1 },
663 : : { OPT_LEVELS_2_PLUS, OPT_freorder_functions, NULL, 1 },
664 : : { OPT_LEVELS_2_PLUS, OPT_frerun_cse_after_loop, NULL, 1 },
665 : : #ifdef INSN_SCHEDULING
666 : : { OPT_LEVELS_2_PLUS, OPT_fschedule_insns2, NULL, 1 },
667 : : #endif
668 : : { OPT_LEVELS_2_PLUS, OPT_fstrict_aliasing, NULL, 1 },
669 : : { OPT_LEVELS_2_PLUS, OPT_fstore_merging, NULL, 1 },
670 : : { OPT_LEVELS_2_PLUS, OPT_ftree_pre, NULL, 1 },
671 : : { OPT_LEVELS_2_PLUS, OPT_ftree_switch_conversion, NULL, 1 },
672 : : { OPT_LEVELS_2_PLUS, OPT_ftree_tail_merge, NULL, 1 },
673 : : { OPT_LEVELS_2_PLUS, OPT_ftree_vrp, NULL, 1 },
674 : : { OPT_LEVELS_2_PLUS, OPT_fvect_cost_model_, NULL,
675 : : VECT_COST_MODEL_VERY_CHEAP },
676 : : { OPT_LEVELS_2_PLUS, OPT_finline_functions, NULL, 1 },
677 : : { OPT_LEVELS_2_PLUS, OPT_ftree_loop_distribute_patterns, NULL, 1 },
678 : : { OPT_LEVELS_2_PLUS, OPT_foptimize_crc, NULL, 1 },
679 : : { OPT_LEVELS_2_PLUS, OPT_flate_combine_instructions, NULL, 1 },
680 : :
681 : : /* -O2 and above optimizations, but not -Os or -Og. */
682 : : { OPT_LEVELS_2_PLUS_SPEED_ONLY, OPT_falign_functions, NULL, 1 },
683 : : { OPT_LEVELS_2_PLUS_SPEED_ONLY, OPT_falign_jumps, NULL, 1 },
684 : : { OPT_LEVELS_2_PLUS_SPEED_ONLY, OPT_falign_labels, NULL, 1 },
685 : : { OPT_LEVELS_2_PLUS_SPEED_ONLY, OPT_falign_loops, NULL, 1 },
686 : : { OPT_LEVELS_2_PLUS_SPEED_ONLY, OPT_foptimize_strlen, NULL, 1 },
687 : : { OPT_LEVELS_2_PLUS_SPEED_ONLY, OPT_freorder_blocks_algorithm_, NULL,
688 : : REORDER_BLOCKS_ALGORITHM_STC },
689 : : { OPT_LEVELS_2_PLUS_SPEED_ONLY, OPT_ftree_loop_vectorize, NULL, 1 },
690 : : { OPT_LEVELS_2_PLUS_SPEED_ONLY, OPT_ftree_slp_vectorize, NULL, 1 },
691 : : { OPT_LEVELS_2_PLUS_SPEED_ONLY, OPT_fopenmp_target_simd_clone_, NULL,
692 : : OMP_TARGET_SIMD_CLONE_NOHOST },
693 : : #ifdef INSN_SCHEDULING
694 : : /* Only run the pre-regalloc scheduling pass if optimizing for speed. */
695 : : { OPT_LEVELS_2_PLUS_SPEED_ONLY, OPT_fschedule_insns, NULL, 1 },
696 : : #endif
697 : :
698 : : /* -O3 and -Os optimizations. */
699 : :
700 : : /* -O3 optimizations. */
701 : : { OPT_LEVELS_3_PLUS, OPT_fgcse_after_reload, NULL, 1 },
702 : : { OPT_LEVELS_3_PLUS, OPT_fipa_cp_clone, NULL, 1 },
703 : : { OPT_LEVELS_3_PLUS, OPT_floop_interchange, NULL, 1 },
704 : : { OPT_LEVELS_3_PLUS, OPT_floop_unroll_and_jam, NULL, 1 },
705 : : { OPT_LEVELS_3_PLUS, OPT_fpeel_loops, NULL, 1 },
706 : : { OPT_LEVELS_3_PLUS, OPT_fpredictive_commoning, NULL, 1 },
707 : : { OPT_LEVELS_3_PLUS, OPT_fsplit_loops, NULL, 1 },
708 : : { OPT_LEVELS_3_PLUS, OPT_fsplit_paths, NULL, 1 },
709 : : { OPT_LEVELS_3_PLUS, OPT_ftree_loop_distribution, NULL, 1 },
710 : : { OPT_LEVELS_3_PLUS, OPT_ftree_partial_pre, NULL, 1 },
711 : : { OPT_LEVELS_3_PLUS, OPT_funswitch_loops, NULL, 1 },
712 : : { OPT_LEVELS_3_PLUS, OPT_fvect_cost_model_, NULL, VECT_COST_MODEL_DYNAMIC },
713 : : { OPT_LEVELS_3_PLUS, OPT_fversion_loops_for_strides, NULL, 1 },
714 : :
715 : : /* -O3 parameters. */
716 : : { OPT_LEVELS_3_PLUS, OPT__param_max_inline_insns_auto_, NULL, 30 },
717 : : { OPT_LEVELS_3_PLUS, OPT__param_early_inlining_insns_, NULL, 14 },
718 : : { OPT_LEVELS_3_PLUS, OPT__param_inline_heuristics_hint_percent_, NULL, 600 },
719 : : { OPT_LEVELS_3_PLUS, OPT__param_inline_min_speedup_, NULL, 15 },
720 : : { OPT_LEVELS_3_PLUS, OPT__param_max_inline_insns_single_, NULL, 200 },
721 : :
722 : : /* -Ofast adds optimizations to -O3. */
723 : : { OPT_LEVELS_FAST, OPT_ffast_math, NULL, 1 },
724 : : { OPT_LEVELS_FAST, OPT_fallow_store_data_races, NULL, 1 },
725 : : { OPT_LEVELS_FAST, OPT_fsemantic_interposition, NULL, 0 },
726 : :
727 : : { OPT_LEVELS_NONE, 0, NULL, 0 }
728 : : };
729 : :
730 : : /* Default the options in OPTS and OPTS_SET based on the optimization
731 : : settings in DECODED_OPTIONS and DECODED_OPTIONS_COUNT. */
732 : : void
733 : 633272 : default_options_optimization (struct gcc_options *opts,
734 : : struct gcc_options *opts_set,
735 : : struct cl_decoded_option *decoded_options,
736 : : unsigned int decoded_options_count,
737 : : location_t loc,
738 : : unsigned int lang_mask,
739 : : const struct cl_option_handlers *handlers,
740 : : diagnostics::context *dc)
741 : : {
742 : 633272 : unsigned int i;
743 : 633272 : int opt2;
744 : 633272 : bool openacc_mode = false;
745 : :
746 : : /* Scan to see what optimization level has been specified. That will
747 : : determine the default value of many flags. */
748 : 10724556 : for (i = 1; i < decoded_options_count; i++)
749 : : {
750 : 10091284 : struct cl_decoded_option *opt = &decoded_options[i];
751 : 10091284 : switch (opt->opt_index)
752 : : {
753 : 565524 : case OPT_O:
754 : 565524 : if (*opt->arg == '\0')
755 : : {
756 : 14249 : opts->x_optimize = 1;
757 : 14249 : opts->x_optimize_size = 0;
758 : 14249 : opts->x_optimize_fast = 0;
759 : 14249 : opts->x_optimize_debug = 0;
760 : : }
761 : : else
762 : : {
763 : 551275 : const int optimize_val = integral_argument (opt->arg);
764 : 551275 : if (optimize_val == -1)
765 : 0 : error_at (loc, "argument to %<-O%> should be a non-negative "
766 : : "integer, %<g%>, %<s%>, %<z%> or %<fast%>");
767 : : else
768 : : {
769 : 551275 : opts->x_optimize = optimize_val;
770 : 551275 : if ((unsigned int) opts->x_optimize > 255)
771 : 3 : opts->x_optimize = 255;
772 : 551275 : opts->x_optimize_size = 0;
773 : 551275 : opts->x_optimize_fast = 0;
774 : 551275 : opts->x_optimize_debug = 0;
775 : : }
776 : : }
777 : : break;
778 : :
779 : 15445 : case OPT_Os:
780 : 15445 : opts->x_optimize_size = 1;
781 : :
782 : : /* Optimizing for size forces optimize to be 2. */
783 : 15445 : opts->x_optimize = 2;
784 : 15445 : opts->x_optimize_fast = 0;
785 : 15445 : opts->x_optimize_debug = 0;
786 : 15445 : break;
787 : :
788 : 15 : case OPT_Oz:
789 : 15 : opts->x_optimize_size = 2;
790 : :
791 : : /* Optimizing for size forces optimize to be 2. */
792 : 15 : opts->x_optimize = 2;
793 : 15 : opts->x_optimize_fast = 0;
794 : 15 : opts->x_optimize_debug = 0;
795 : 15 : break;
796 : :
797 : 709 : case OPT_Ofast:
798 : : /* -Ofast only adds flags to -O3. */
799 : 709 : opts->x_optimize_size = 0;
800 : 709 : opts->x_optimize = 3;
801 : 709 : opts->x_optimize_fast = 1;
802 : 709 : opts->x_optimize_debug = 0;
803 : 709 : break;
804 : :
805 : 785 : case OPT_Og:
806 : : /* -Og selects optimization level 1. */
807 : 785 : opts->x_optimize_size = 0;
808 : 785 : opts->x_optimize = 1;
809 : 785 : opts->x_optimize_fast = 0;
810 : 785 : opts->x_optimize_debug = 1;
811 : 785 : break;
812 : :
813 : 25508 : case OPT_fopenacc:
814 : 25508 : if (opt->value)
815 : 10091284 : openacc_mode = true;
816 : : break;
817 : :
818 : : default:
819 : : /* Ignore other options in this prescan. */
820 : : break;
821 : : }
822 : : }
823 : :
824 : 633272 : maybe_default_options (opts, opts_set, default_options_table,
825 : 633272 : opts->x_optimize, opts->x_optimize_size,
826 : 633272 : opts->x_optimize_fast, opts->x_optimize_debug,
827 : : lang_mask, handlers, loc, dc);
828 : :
829 : : /* -O2 param settings. */
830 : 633272 : opt2 = (opts->x_optimize >= 2);
831 : :
832 : 633272 : if (openacc_mode)
833 : 3319 : SET_OPTION_IF_UNSET (opts, opts_set, flag_ipa_pta, true);
834 : :
835 : : /* Track fields in field-sensitive alias analysis. */
836 : 633272 : if (opt2)
837 : 489879 : SET_OPTION_IF_UNSET (opts, opts_set, param_max_fields_for_field_sensitive,
838 : : 100);
839 : :
840 : 633272 : if (opts->x_optimize_size)
841 : : /* We want to crossjump as much as possible. */
842 : 15308 : SET_OPTION_IF_UNSET (opts, opts_set, param_min_crossjump_insns, 1);
843 : :
844 : : /* Restrict the amount of work combine does at -Og while retaining
845 : : most of its useful transforms. */
846 : 633272 : if (opts->x_optimize_debug)
847 : 761 : SET_OPTION_IF_UNSET (opts, opts_set, param_max_combine_insns, 2);
848 : :
849 : : /* Allow default optimizations to be specified on a per-machine basis. */
850 : 633272 : maybe_default_options (opts, opts_set,
851 : : targetm_common.option_optimization_table,
852 : : opts->x_optimize, opts->x_optimize_size,
853 : 633272 : opts->x_optimize_fast, opts->x_optimize_debug,
854 : : lang_mask, handlers, loc, dc);
855 : 633272 : }
856 : :
857 : : /* Control IPA optimizations based on different live patching LEVEL. */
858 : : static void
859 : 20 : control_options_for_live_patching (struct gcc_options *opts,
860 : : struct gcc_options *opts_set,
861 : : enum live_patching_level level,
862 : : location_t loc)
863 : : {
864 : 20 : gcc_assert (level > LIVE_PATCHING_NONE);
865 : :
866 : 20 : switch (level)
867 : : {
868 : 3 : case LIVE_PATCHING_INLINE_ONLY_STATIC:
869 : : #define LIVE_PATCHING_OPTION "-flive-patching=inline-only-static"
870 : 3 : if (opts_set->x_flag_ipa_cp_clone && opts->x_flag_ipa_cp_clone)
871 : 0 : error_at (loc, "%qs is incompatible with %qs",
872 : : "-fipa-cp-clone", LIVE_PATCHING_OPTION);
873 : : else
874 : 3 : opts->x_flag_ipa_cp_clone = 0;
875 : :
876 : 3 : if (opts_set->x_flag_ipa_sra && opts->x_flag_ipa_sra)
877 : 0 : error_at (loc, "%qs is incompatible with %qs",
878 : : "-fipa-sra", LIVE_PATCHING_OPTION);
879 : : else
880 : 3 : opts->x_flag_ipa_sra = 0;
881 : :
882 : 3 : if (opts_set->x_flag_partial_inlining && opts->x_flag_partial_inlining)
883 : 0 : error_at (loc, "%qs is incompatible with %qs",
884 : : "-fpartial-inlining", LIVE_PATCHING_OPTION);
885 : : else
886 : 3 : opts->x_flag_partial_inlining = 0;
887 : :
888 : 3 : if (opts_set->x_flag_ipa_cp && opts->x_flag_ipa_cp)
889 : 0 : error_at (loc, "%qs is incompatible with %qs",
890 : : "-fipa-cp", LIVE_PATCHING_OPTION);
891 : : else
892 : 3 : opts->x_flag_ipa_cp = 0;
893 : :
894 : : /* FALLTHROUGH. */
895 : 20 : case LIVE_PATCHING_INLINE_CLONE:
896 : : #undef LIVE_PATCHING_OPTION
897 : : #define LIVE_PATCHING_OPTION "-flive-patching=inline-only-static|inline-clone"
898 : : /* live patching should disable whole-program optimization. */
899 : 20 : if (opts_set->x_flag_whole_program && opts->x_flag_whole_program)
900 : 1 : error_at (loc, "%qs is incompatible with %qs",
901 : : "-fwhole-program", LIVE_PATCHING_OPTION);
902 : : else
903 : 19 : opts->x_flag_whole_program = 0;
904 : :
905 : : /* visibility change should be excluded by !flag_whole_program
906 : : && !in_lto_p && !flag_ipa_cp_clone && !flag_ipa_sra
907 : : && !flag_partial_inlining. */
908 : :
909 : 20 : if (opts_set->x_flag_ipa_pta && opts->x_flag_ipa_pta)
910 : 0 : error_at (loc, "%qs is incompatible with %qs",
911 : : "-fipa-pta", LIVE_PATCHING_OPTION);
912 : : else
913 : 20 : opts->x_flag_ipa_pta = 0;
914 : :
915 : 20 : if (opts_set->x_flag_ipa_reference && opts->x_flag_ipa_reference)
916 : 0 : error_at (loc, "%qs is incompatible with %qs",
917 : : "-fipa-reference", LIVE_PATCHING_OPTION);
918 : : else
919 : 20 : opts->x_flag_ipa_reference = 0;
920 : :
921 : 20 : if (opts_set->x_flag_ipa_ra && opts->x_flag_ipa_ra)
922 : 0 : error_at (loc, "%qs is incompatible with %qs",
923 : : "-fipa-ra", LIVE_PATCHING_OPTION);
924 : : else
925 : 20 : opts->x_flag_ipa_ra = 0;
926 : :
927 : 20 : if (opts_set->x_flag_ipa_icf && opts->x_flag_ipa_icf)
928 : 0 : error_at (loc, "%qs is incompatible with %qs",
929 : : "-fipa-icf", LIVE_PATCHING_OPTION);
930 : : else
931 : 20 : opts->x_flag_ipa_icf = 0;
932 : :
933 : 20 : if (opts_set->x_flag_ipa_icf_functions && opts->x_flag_ipa_icf_functions)
934 : 0 : error_at (loc, "%qs is incompatible with %qs",
935 : : "-fipa-icf-functions", LIVE_PATCHING_OPTION);
936 : : else
937 : 20 : opts->x_flag_ipa_icf_functions = 0;
938 : :
939 : 20 : if (opts_set->x_flag_ipa_icf_variables && opts->x_flag_ipa_icf_variables)
940 : 0 : error_at (loc, "%qs is incompatible with %qs",
941 : : "-fipa-icf-variables", LIVE_PATCHING_OPTION);
942 : : else
943 : 20 : opts->x_flag_ipa_icf_variables = 0;
944 : :
945 : 20 : if (opts_set->x_flag_ipa_bit_cp && opts->x_flag_ipa_bit_cp)
946 : 0 : error_at (loc, "%qs is incompatible with %qs",
947 : : "-fipa-bit-cp", LIVE_PATCHING_OPTION);
948 : : else
949 : 20 : opts->x_flag_ipa_bit_cp = 0;
950 : :
951 : 20 : if (opts_set->x_flag_ipa_vrp && opts->x_flag_ipa_vrp)
952 : 0 : error_at (loc, "%qs is incompatible with %qs",
953 : : "-fipa-vrp", LIVE_PATCHING_OPTION);
954 : : else
955 : 20 : opts->x_flag_ipa_vrp = 0;
956 : :
957 : 20 : if (opts_set->x_flag_ipa_pure_const && opts->x_flag_ipa_pure_const)
958 : 0 : error_at (loc, "%qs is incompatible with %qs",
959 : : "-fipa-pure-const", LIVE_PATCHING_OPTION);
960 : : else
961 : 20 : opts->x_flag_ipa_pure_const = 0;
962 : :
963 : 20 : if (opts_set->x_flag_ipa_modref && opts->x_flag_ipa_modref)
964 : 0 : error_at (loc,
965 : : "%<-fipa-modref%> is incompatible with %qs",
966 : : LIVE_PATCHING_OPTION);
967 : : else
968 : 20 : opts->x_flag_ipa_modref = 0;
969 : :
970 : : /* FIXME: disable unreachable code removal. */
971 : :
972 : : /* discovery of functions/variables with no address taken. */
973 : 20 : if (opts_set->x_flag_ipa_reference_addressable
974 : 0 : && opts->x_flag_ipa_reference_addressable)
975 : 0 : error_at (loc, "%qs is incompatible with %qs",
976 : : "-fipa-reference-addressable", LIVE_PATCHING_OPTION);
977 : : else
978 : 20 : opts->x_flag_ipa_reference_addressable = 0;
979 : :
980 : : /* ipa stack alignment propagation. */
981 : 20 : if (opts_set->x_flag_ipa_stack_alignment
982 : 0 : && opts->x_flag_ipa_stack_alignment)
983 : 0 : error_at (loc, "%qs is incompatible with %qs",
984 : : "-fipa-stack-alignment", LIVE_PATCHING_OPTION);
985 : : else
986 : 20 : opts->x_flag_ipa_stack_alignment = 0;
987 : 20 : break;
988 : 0 : default:
989 : 0 : gcc_unreachable ();
990 : : }
991 : :
992 : : #undef LIVE_PATCHING_OPTION
993 : 20 : }
994 : :
995 : : /* --help option argument if set. */
996 : : vec<const char *> help_option_arguments;
997 : :
998 : : /* Return the string name describing a sanitizer argument which has been
999 : : provided on the command line and has set this particular flag. */
1000 : : const char *
1001 : 208 : find_sanitizer_argument (struct gcc_options *opts,
1002 : : sanitize_code_type flags)
1003 : : {
1004 : 706 : for (int i = 0; sanitizer_opts[i].name != NULL; ++i)
1005 : : {
1006 : : /* Need to find the sanitizer_opts element which:
1007 : : a) Could have set the flags requested.
1008 : : b) Has been set on the command line.
1009 : :
1010 : : Can have (a) without (b) if the flag requested is e.g.
1011 : : SANITIZE_ADDRESS, since both -fsanitize=address and
1012 : : -fsanitize=kernel-address set this flag.
1013 : :
1014 : : Can have (b) without (a) by requesting more than one sanitizer on the
1015 : : command line. */
1016 : 706 : if ((sanitizer_opts[i].flag & opts->x_flag_sanitize)
1017 : : != sanitizer_opts[i].flag)
1018 : 352 : continue;
1019 : 354 : if ((sanitizer_opts[i].flag & flags) != flags)
1020 : 146 : continue;
1021 : : return sanitizer_opts[i].name;
1022 : : }
1023 : : return NULL;
1024 : : }
1025 : :
1026 : :
1027 : : /* Report an error to the user about sanitizer options they have requested
1028 : : which have set conflicting flags.
1029 : :
1030 : : LEFT and RIGHT indicate sanitizer flags which conflict with each other, this
1031 : : function reports an error if both have been set in OPTS->x_flag_sanitize and
1032 : : ensures the error identifies the requested command line options that have
1033 : : set these flags. */
1034 : : static void
1035 : 3799632 : report_conflicting_sanitizer_options (struct gcc_options *opts, location_t loc,
1036 : : sanitize_code_type left,
1037 : : sanitize_code_type right)
1038 : : {
1039 : 3799632 : sanitize_code_type left_seen = (opts->x_flag_sanitize & left);
1040 : 3799632 : sanitize_code_type right_seen = (opts->x_flag_sanitize & right);
1041 : 3799632 : if (left_seen && right_seen)
1042 : : {
1043 : 104 : const char* left_arg = find_sanitizer_argument (opts, left_seen);
1044 : 104 : const char* right_arg = find_sanitizer_argument (opts, right_seen);
1045 : 104 : gcc_assert (left_arg && right_arg);
1046 : 104 : error_at (loc,
1047 : : "%<-fsanitize=%s%> is incompatible with %<-fsanitize=%s%>",
1048 : : left_arg, right_arg);
1049 : : }
1050 : 3799632 : }
1051 : :
1052 : : /* Validate from OPTS and OPTS_SET that when -fipa-reorder-for-locality is
1053 : : enabled no explicit -flto-partition is also passed as the locality cloning
1054 : : pass uses its own partitioning scheme. */
1055 : :
1056 : : static void
1057 : 633272 : validate_ipa_reorder_locality_lto_partition (struct gcc_options *opts,
1058 : : struct gcc_options *opts_set)
1059 : : {
1060 : 633272 : static bool validated_p = false;
1061 : :
1062 : 633272 : if (opts_set->x_flag_lto_partition)
1063 : : {
1064 : 15050 : if (opts->x_flag_ipa_reorder_for_locality && !validated_p)
1065 : 0 : error ("%<-fipa-reorder-for-locality%> is incompatible with"
1066 : : " an explicit %qs option", "-flto-partition");
1067 : : }
1068 : 633272 : validated_p = true;
1069 : 633272 : }
1070 : :
1071 : : /* After all options at LOC have been read into OPTS and OPTS_SET,
1072 : : finalize settings of those options and diagnose incompatible
1073 : : combinations. */
1074 : : void
1075 : 633272 : finish_options (struct gcc_options *opts, struct gcc_options *opts_set,
1076 : : location_t loc)
1077 : : {
1078 : 633272 : if (opts->x_dump_base_name
1079 : 630499 : && ! opts->x_dump_base_name_prefixed)
1080 : : {
1081 : : const char *sep = opts->x_dump_base_name;
1082 : :
1083 : 3856628 : for (; *sep; sep++)
1084 : 3592289 : if (IS_DIR_SEPARATOR (*sep))
1085 : : break;
1086 : :
1087 : 286529 : if (*sep)
1088 : : /* If dump_base_path contains subdirectories, don't prepend
1089 : : anything. */;
1090 : 264339 : else if (opts->x_dump_dir_name)
1091 : : /* We have a DUMP_DIR_NAME, prepend that. */
1092 : 105519 : opts->x_dump_base_name = opts_concat (opts->x_dump_dir_name,
1093 : : opts->x_dump_base_name, NULL);
1094 : :
1095 : : /* It is definitely prefixed now. */
1096 : 286529 : opts->x_dump_base_name_prefixed = true;
1097 : : }
1098 : :
1099 : : /* Handle related options for unit-at-a-time, toplevel-reorder, and
1100 : : section-anchors. */
1101 : 633272 : if (!opts->x_flag_unit_at_a_time)
1102 : : {
1103 : 4 : if (opts->x_flag_section_anchors && opts_set->x_flag_section_anchors)
1104 : 0 : error_at (loc, "section anchors must be disabled when unit-at-a-time "
1105 : : "is disabled");
1106 : 4 : opts->x_flag_section_anchors = 0;
1107 : 4 : if (opts->x_flag_toplevel_reorder == 1)
1108 : 0 : error_at (loc, "toplevel reorder must be disabled when unit-at-a-time "
1109 : : "is disabled");
1110 : 4 : opts->x_flag_toplevel_reorder = 0;
1111 : : }
1112 : :
1113 : : /* -fself-test depends on the state of the compiler prior to
1114 : : compiling anything. Ideally it should be run on an empty source
1115 : : file. However, in case we get run with actual source, assume
1116 : : -fsyntax-only which will inhibit any compiler initialization
1117 : : which may confuse the self tests. */
1118 : 633272 : if (opts->x_flag_self_test)
1119 : 5 : opts->x_flag_syntax_only = 1;
1120 : :
1121 : 633272 : if (opts->x_flag_tm && opts->x_flag_non_call_exceptions)
1122 : 3 : sorry ("transactional memory is not supported with non-call exceptions");
1123 : :
1124 : : /* Unless the user has asked for section anchors, we disable toplevel
1125 : : reordering at -O0 to disable transformations that might be surprising
1126 : : to end users and to get -fno-toplevel-reorder tested. */
1127 : 633272 : if (!opts->x_optimize
1128 : 114872 : && opts->x_flag_toplevel_reorder == 2
1129 : 114652 : && !(opts->x_flag_section_anchors && opts_set->x_flag_section_anchors))
1130 : : {
1131 : 114652 : opts->x_flag_toplevel_reorder = 0;
1132 : 114652 : opts->x_flag_section_anchors = 0;
1133 : : }
1134 : 633272 : if (!opts->x_flag_toplevel_reorder)
1135 : : {
1136 : 134372 : if (opts->x_flag_section_anchors && opts_set->x_flag_section_anchors)
1137 : 0 : error_at (loc, "section anchors must be disabled when toplevel reorder"
1138 : : " is disabled");
1139 : 134372 : opts->x_flag_section_anchors = 0;
1140 : : }
1141 : :
1142 : 633272 : if (opts->x_flag_hardened)
1143 : : {
1144 : 91 : if (!opts_set->x_flag_auto_var_init)
1145 : 87 : opts->x_flag_auto_var_init = AUTO_INIT_ZERO;
1146 : 4 : else if (opts->x_flag_auto_var_init != AUTO_INIT_ZERO)
1147 : 4 : warning_at (loc, OPT_Whardened,
1148 : : "%<-ftrivial-auto-var-init=zero%> is not enabled by "
1149 : : "%<-fhardened%> because it was specified on the command "
1150 : : "line");
1151 : : }
1152 : :
1153 : 633272 : if (!opts->x_flag_opts_finished)
1154 : : {
1155 : : /* We initialize opts->x_flag_pie to -1 so that targets can set a
1156 : : default value. */
1157 : 289302 : if (opts->x_flag_pie == -1)
1158 : : {
1159 : : /* We initialize opts->x_flag_pic to -1 so that we can tell if
1160 : : -fpic, -fPIC, -fno-pic or -fno-PIC is used. */
1161 : 267118 : if (opts->x_flag_pic == -1)
1162 : 257888 : opts->x_flag_pie = (opts->x_flag_hardened
1163 : 257888 : ? /*-fPIE*/ 2 : DEFAULT_FLAG_PIE);
1164 : : else
1165 : 9230 : opts->x_flag_pie = 0;
1166 : : }
1167 : : /* If -fPIE or -fpie is used, turn on PIC. */
1168 : 289302 : if (opts->x_flag_pie)
1169 : 265 : opts->x_flag_pic = opts->x_flag_pie;
1170 : 289037 : else if (opts->x_flag_pic == -1)
1171 : 279807 : opts->x_flag_pic = 0;
1172 : 289302 : if (opts->x_flag_pic && !opts->x_flag_pie)
1173 : 9060 : opts->x_flag_shlib = 1;
1174 : 289302 : opts->x_flag_opts_finished = true;
1175 : : }
1176 : :
1177 : : /* We initialize opts->x_flag_stack_protect to -1 so that targets
1178 : : can set a default value. With --enable-default-ssp or -fhardened
1179 : : the default is -fstack-protector-strong. */
1180 : 633272 : if (opts->x_flag_stack_protect == -1)
1181 : : {
1182 : : /* This should check FRAME_GROWS_DOWNWARD, but on some targets it's
1183 : : defined in such a way that it uses flag_stack_protect which can't
1184 : : be used here. Moreover, some targets like BPF don't support
1185 : : -fstack-protector at all but we don't know that here. So remember
1186 : : that flag_stack_protect was set at the behest of -fhardened. */
1187 : 288024 : if (opts->x_flag_hardened)
1188 : : {
1189 : 87 : opts->x_flag_stack_protect = SPCT_FLAG_STRONG;
1190 : 87 : flag_stack_protector_set_by_fhardened_p = true;
1191 : : }
1192 : : else
1193 : 287937 : opts->x_flag_stack_protect = DEFAULT_FLAG_SSP;
1194 : : }
1195 : 345248 : else if (opts->x_flag_hardened
1196 : 4 : && opts->x_flag_stack_protect != SPCT_FLAG_STRONG)
1197 : 4 : warning_at (UNKNOWN_LOCATION, OPT_Whardened,
1198 : : "%<-fstack-protector-strong%> is not enabled by "
1199 : : "%<-fhardened%> because it was specified on the command "
1200 : : "line");
1201 : :
1202 : 633272 : if (opts->x_optimize == 0)
1203 : : {
1204 : : /* Inlining does not work if not optimizing,
1205 : : so force it not to be done. */
1206 : 114872 : opts->x_warn_inline = 0;
1207 : 114872 : opts->x_flag_no_inline = 1;
1208 : : }
1209 : :
1210 : : /* At -O0 or -Og, turn __builtin_unreachable into a trap. */
1211 : 633272 : if (!opts->x_optimize || opts->x_optimize_debug)
1212 : 115633 : SET_OPTION_IF_UNSET (opts, opts_set, flag_unreachable_traps, true);
1213 : :
1214 : : /* Pipelining of outer loops is only possible when general pipelining
1215 : : capabilities are requested. */
1216 : 633272 : if (!opts->x_flag_sel_sched_pipelining)
1217 : 633220 : opts->x_flag_sel_sched_pipelining_outer_loops = 0;
1218 : :
1219 : 633272 : if (opts->x_flag_conserve_stack)
1220 : : {
1221 : 30 : SET_OPTION_IF_UNSET (opts, opts_set, param_large_stack_frame, 100);
1222 : 30 : SET_OPTION_IF_UNSET (opts, opts_set, param_stack_frame_growth, 40);
1223 : : }
1224 : :
1225 : 633272 : if (opts->x_flag_lto)
1226 : : {
1227 : : #ifdef ENABLE_LTO
1228 : 184301 : opts->x_flag_generate_lto = 1;
1229 : :
1230 : : /* When generating IL, do not operate in whole-program mode.
1231 : : Otherwise, symbols will be privatized too early, causing link
1232 : : errors later. */
1233 : 184301 : opts->x_flag_whole_program = 0;
1234 : : #else
1235 : : error_at (loc, "LTO support has not been enabled in this configuration");
1236 : : #endif
1237 : 184301 : if (!opts->x_flag_fat_lto_objects
1238 : 22241 : && (!HAVE_LTO_PLUGIN
1239 : 22241 : || (opts_set->x_flag_use_linker_plugin
1240 : 20306 : && !opts->x_flag_use_linker_plugin)))
1241 : : {
1242 : 8659 : if (opts_set->x_flag_fat_lto_objects)
1243 : 0 : error_at (loc, "%<-fno-fat-lto-objects%> are supported only with "
1244 : : "linker plugin");
1245 : 8659 : opts->x_flag_fat_lto_objects = 1;
1246 : : }
1247 : :
1248 : : /* -gsplit-dwarf isn't compatible with LTO, see PR88389. */
1249 : 184301 : if (opts->x_dwarf_split_debug_info)
1250 : : {
1251 : 1 : inform (loc, "%<-gsplit-dwarf%> is not supported with LTO,"
1252 : : " disabling");
1253 : 1 : opts->x_dwarf_split_debug_info = 0;
1254 : : }
1255 : : }
1256 : :
1257 : : /* We initialize opts->x_flag_split_stack to -1 so that targets can set a
1258 : : default value if they choose based on other options. */
1259 : 633272 : if (opts->x_flag_split_stack == -1)
1260 : 287614 : opts->x_flag_split_stack = 0;
1261 : 345658 : else if (opts->x_flag_split_stack)
1262 : : {
1263 : 1716 : if (!targetm_common.supports_split_stack (true, opts))
1264 : : {
1265 : 0 : error_at (loc, "%<-fsplit-stack%> is not supported by "
1266 : : "this compiler configuration");
1267 : 0 : opts->x_flag_split_stack = 0;
1268 : : }
1269 : : }
1270 : :
1271 : : /* If stack splitting is turned on, and the user did not explicitly
1272 : : request function partitioning, turn off partitioning, as it
1273 : : confuses the linker when trying to handle partitioned split-stack
1274 : : code that calls a non-split-stack functions. But if partitioning
1275 : : was turned on explicitly just hope for the best. */
1276 : 633272 : if (opts->x_flag_split_stack
1277 : 1716 : && opts->x_flag_reorder_blocks_and_partition)
1278 : 1280 : SET_OPTION_IF_UNSET (opts, opts_set, flag_reorder_blocks_and_partition, 0);
1279 : :
1280 : 633272 : if (opts->x_flag_reorder_blocks_and_partition)
1281 : 488642 : SET_OPTION_IF_UNSET (opts, opts_set, flag_reorder_functions, 1);
1282 : :
1283 : 633272 : validate_ipa_reorder_locality_lto_partition (opts, opts_set);
1284 : :
1285 : : /* The -gsplit-dwarf option requires -ggnu-pubnames. */
1286 : 633272 : if (opts->x_dwarf_split_debug_info)
1287 : 308 : opts->x_debug_generate_pub_sections = 2;
1288 : :
1289 : 633272 : if ((opts->x_flag_sanitize
1290 : 633272 : & (SANITIZE_USER_ADDRESS | SANITIZE_KERNEL_ADDRESS)) == 0)
1291 : : {
1292 : 630127 : if (opts->x_flag_sanitize & SANITIZE_POINTER_COMPARE)
1293 : 0 : error_at (loc,
1294 : : "%<-fsanitize=pointer-compare%> must be combined with "
1295 : : "%<-fsanitize=address%> or %<-fsanitize=kernel-address%>");
1296 : 630127 : if (opts->x_flag_sanitize & SANITIZE_POINTER_SUBTRACT)
1297 : 0 : error_at (loc,
1298 : : "%<-fsanitize=pointer-subtract%> must be combined with "
1299 : : "%<-fsanitize=address%> or %<-fsanitize=kernel-address%>");
1300 : : }
1301 : :
1302 : : /* Address sanitizers conflict with the thread sanitizer. */
1303 : 633272 : report_conflicting_sanitizer_options (opts, loc, SANITIZE_THREAD,
1304 : : SANITIZE_ADDRESS);
1305 : 633272 : report_conflicting_sanitizer_options (opts, loc, SANITIZE_THREAD,
1306 : : SANITIZE_HWADDRESS);
1307 : : /* The leak sanitizer conflicts with the thread sanitizer. */
1308 : 633272 : report_conflicting_sanitizer_options (opts, loc, SANITIZE_LEAK,
1309 : : SANITIZE_THREAD);
1310 : :
1311 : : /* No combination of HWASAN and ASAN work together. */
1312 : 633272 : report_conflicting_sanitizer_options (opts, loc,
1313 : : SANITIZE_HWADDRESS, SANITIZE_ADDRESS);
1314 : :
1315 : : /* The userspace and kernel address sanitizers conflict with each other. */
1316 : 633272 : report_conflicting_sanitizer_options (opts, loc, SANITIZE_USER_HWADDRESS,
1317 : : SANITIZE_KERNEL_HWADDRESS);
1318 : 633272 : report_conflicting_sanitizer_options (opts, loc, SANITIZE_USER_ADDRESS,
1319 : : SANITIZE_KERNEL_ADDRESS);
1320 : :
1321 : : /* Check error recovery for -fsanitize-recover option. */
1322 : 21531248 : for (int i = 0; sanitizer_opts[i].name != NULL; ++i)
1323 : 20897976 : if ((opts->x_flag_sanitize_recover & sanitizer_opts[i].flag)
1324 : 15194113 : && !sanitizer_opts[i].can_recover)
1325 : 40 : error_at (loc, "%<-fsanitize-recover=%s%> is not supported",
1326 : : sanitizer_opts[i].name);
1327 : :
1328 : : /* Check -fsanitize-trap option. */
1329 : 21531248 : for (int i = 0; sanitizer_opts[i].name != NULL; ++i)
1330 : 20897976 : if ((opts->x_flag_sanitize_trap & sanitizer_opts[i].flag)
1331 : 4357 : && !sanitizer_opts[i].can_trap
1332 : : /* Allow -fsanitize-trap=all or -fsanitize-trap=undefined
1333 : : to set flag_sanitize_trap & SANITIZE_VPTR bit which will
1334 : : effectively disable -fsanitize=vptr, just disallow
1335 : : explicit -fsanitize-trap=vptr. */
1336 : 183 : && sanitizer_opts[i].flag != SANITIZE_VPTR)
1337 : 0 : error_at (loc, "%<-fsanitize-trap=%s%> is not supported",
1338 : : sanitizer_opts[i].name);
1339 : :
1340 : : /* When instrumenting the pointers, we don't want to remove
1341 : : the null pointer checks. */
1342 : 633272 : if (opts->x_flag_sanitize & (SANITIZE_NULL | SANITIZE_NONNULL_ATTRIBUTE
1343 : : | SANITIZE_RETURNS_NONNULL_ATTRIBUTE))
1344 : 1690 : opts->x_flag_delete_null_pointer_checks = 0;
1345 : :
1346 : : /* Aggressive compiler optimizations may cause false negatives. */
1347 : 633272 : if (opts->x_flag_sanitize & ~(SANITIZE_LEAK | SANITIZE_UNREACHABLE))
1348 : 7657 : opts->x_flag_aggressive_loop_optimizations = 0;
1349 : :
1350 : : /* Enable -fsanitize-address-use-after-scope if either address sanitizer is
1351 : : enabled. */
1352 : 633272 : if (opts->x_flag_sanitize
1353 : 633272 : & (SANITIZE_USER_ADDRESS | SANITIZE_USER_HWADDRESS))
1354 : 3485 : SET_OPTION_IF_UNSET (opts, opts_set, flag_sanitize_address_use_after_scope,
1355 : : true);
1356 : :
1357 : : /* Force -fstack-reuse=none in case -fsanitize-address-use-after-scope
1358 : : is enabled. */
1359 : 633272 : if (opts->x_flag_sanitize_address_use_after_scope)
1360 : : {
1361 : 3451 : if (opts->x_flag_stack_reuse != SR_NONE
1362 : 3443 : && opts_set->x_flag_stack_reuse != SR_NONE)
1363 : 0 : error_at (loc,
1364 : : "%<-fsanitize-address-use-after-scope%> requires "
1365 : : "%<-fstack-reuse=none%> option");
1366 : :
1367 : 3451 : opts->x_flag_stack_reuse = SR_NONE;
1368 : : }
1369 : :
1370 : 633272 : if ((opts->x_flag_sanitize & SANITIZE_USER_ADDRESS) && opts->x_flag_tm)
1371 : 0 : sorry ("transactional memory is not supported with %<-fsanitize=address%>");
1372 : :
1373 : 633272 : if ((opts->x_flag_sanitize & SANITIZE_KERNEL_ADDRESS) && opts->x_flag_tm)
1374 : 0 : sorry ("transactional memory is not supported with "
1375 : : "%<-fsanitize=kernel-address%>");
1376 : :
1377 : : /* Currently live patching is not support for LTO. */
1378 : 633272 : if (opts->x_flag_live_patching == LIVE_PATCHING_INLINE_ONLY_STATIC && opts->x_flag_lto)
1379 : 1 : sorry ("live patching (with %qs) is not supported with LTO",
1380 : : "inline-only-static");
1381 : :
1382 : : /* Currently vtable verification is not supported for LTO */
1383 : 633272 : if (opts->x_flag_vtable_verify && opts->x_flag_lto)
1384 : 0 : sorry ("vtable verification is not supported with LTO");
1385 : :
1386 : : /* Control IPA optimizations based on different -flive-patching level. */
1387 : 633272 : if (opts->x_flag_live_patching)
1388 : 20 : control_options_for_live_patching (opts, opts_set,
1389 : : opts->x_flag_live_patching,
1390 : : loc);
1391 : :
1392 : : /* Allow cunroll to grow size accordingly. */
1393 : 633272 : if (!opts_set->x_flag_cunroll_grow_size)
1394 : 633272 : opts->x_flag_cunroll_grow_size
1395 : 1266544 : = (opts->x_flag_unroll_loops
1396 : 158579 : || opts->x_flag_peel_loops
1397 : 1266544 : || opts->x_optimize >= 3);
1398 : :
1399 : : /* Use -fvect-cost-model=cheap instead of -fvect-cost-mode=very-cheap
1400 : : by default with explicit -ftree-{loop,slp}-vectorize. */
1401 : 633272 : if (opts->x_optimize == 2
1402 : 461053 : && (opts_set->x_flag_tree_loop_vectorize
1403 : 460994 : || opts_set->x_flag_tree_vectorize))
1404 : 345616 : SET_OPTION_IF_UNSET (opts, opts_set, flag_vect_cost_model,
1405 : : VECT_COST_MODEL_CHEAP);
1406 : :
1407 : 633272 : if (opts->x_flag_gtoggle)
1408 : : {
1409 : : /* Make sure to process -gtoggle only once. */
1410 : 613 : opts->x_flag_gtoggle = false;
1411 : 613 : if (opts->x_debug_info_level == DINFO_LEVEL_NONE)
1412 : : {
1413 : 366 : opts->x_debug_info_level = DINFO_LEVEL_NORMAL;
1414 : :
1415 : 366 : if (opts->x_write_symbols == NO_DEBUG)
1416 : 366 : opts->x_write_symbols = PREFERRED_DEBUGGING_TYPE;
1417 : : }
1418 : : else
1419 : 247 : opts->x_debug_info_level = DINFO_LEVEL_NONE;
1420 : : }
1421 : :
1422 : : /* Also enable markers with -fauto-profile even when debug info is disabled,
1423 : : so we assign same discriminators and can read back the profile info. */
1424 : 633272 : if (!opts_set->x_debug_nonbind_markers_p)
1425 : 633240 : opts->x_debug_nonbind_markers_p
1426 : 633240 : = (opts->x_optimize
1427 : 518368 : && ((opts->x_debug_info_level >= DINFO_LEVEL_NORMAL
1428 : 51910 : && (dwarf_debuginfo_p (opts) || codeview_debuginfo_p ()))
1429 : 466467 : || opts->x_flag_auto_profile)
1430 : 1318381 : && !(opts->x_flag_selective_scheduling
1431 : 51901 : || opts->x_flag_selective_scheduling2));
1432 : :
1433 : : /* We know which debug output will be used so we can set flag_var_tracking
1434 : : and flag_var_tracking_uninit if the user has not specified them. */
1435 : 633272 : if (opts->x_debug_info_level < DINFO_LEVEL_NORMAL
1436 : 633272 : || (!dwarf_debuginfo_p (opts) && !codeview_debuginfo_p ())
1437 : : /* We have not yet initialized debug hooks so match that to check
1438 : : whether we're only doing DWARF2_LINENO_DEBUGGING_INFO. */
1439 : : #ifndef DWARF2_DEBUGGING_INFO
1440 : : || true
1441 : : #endif
1442 : : )
1443 : : {
1444 : 574516 : if ((opts_set->x_flag_var_tracking && opts->x_flag_var_tracking == 1)
1445 : 574500 : || (opts_set->x_flag_var_tracking_uninit
1446 : 0 : && opts->x_flag_var_tracking_uninit == 1))
1447 : : {
1448 : 16 : if (opts->x_debug_info_level < DINFO_LEVEL_NORMAL)
1449 : 15 : warning_at (UNKNOWN_LOCATION, 0,
1450 : : "variable tracking requested, but useless unless "
1451 : : "producing debug info");
1452 : : else
1453 : 1 : warning_at (UNKNOWN_LOCATION, 0,
1454 : : "variable tracking requested, but not supported "
1455 : : "by this debug format");
1456 : : }
1457 : 574516 : opts->x_flag_var_tracking = 0;
1458 : 574516 : opts->x_flag_var_tracking_uninit = 0;
1459 : 574516 : opts->x_flag_var_tracking_assignments = 0;
1460 : : }
1461 : :
1462 : : /* One could use EnabledBy, but it would lead to a circular dependency. */
1463 : 633272 : if (!opts_set->x_flag_var_tracking_uninit)
1464 : 633272 : opts->x_flag_var_tracking_uninit = opts->x_flag_var_tracking;
1465 : :
1466 : 633272 : if (!opts_set->x_flag_var_tracking_assignments)
1467 : 633198 : opts->x_flag_var_tracking_assignments
1468 : 1266396 : = (opts->x_flag_var_tracking
1469 : 1266396 : && !(opts->x_flag_selective_scheduling
1470 : 51897 : || opts->x_flag_selective_scheduling2));
1471 : :
1472 : 633272 : if (opts->x_flag_var_tracking_assignments_toggle)
1473 : 0 : opts->x_flag_var_tracking_assignments
1474 : 0 : = !opts->x_flag_var_tracking_assignments;
1475 : :
1476 : 633272 : if (opts->x_flag_var_tracking_assignments && !opts->x_flag_var_tracking)
1477 : 2 : opts->x_flag_var_tracking = opts->x_flag_var_tracking_assignments = -1;
1478 : :
1479 : 633272 : if (opts->x_flag_var_tracking_assignments
1480 : 51904 : && (opts->x_flag_selective_scheduling
1481 : 51904 : || opts->x_flag_selective_scheduling2))
1482 : 5 : warning_at (loc, 0,
1483 : : "var-tracking-assignments changes selective scheduling");
1484 : :
1485 : 633272 : if (opts->x_flag_syntax_only)
1486 : : {
1487 : 281 : opts->x_write_symbols = NO_DEBUG;
1488 : 281 : opts->x_profile_flag = 0;
1489 : : }
1490 : :
1491 : 633272 : if (opts->x_warn_strict_flex_arrays)
1492 : 13 : if (opts->x_flag_strict_flex_arrays == 0)
1493 : : {
1494 : 4 : opts->x_warn_strict_flex_arrays = 0;
1495 : 4 : warning_at (UNKNOWN_LOCATION, 0,
1496 : : "%<-Wstrict-flex-arrays%> is ignored when"
1497 : : " %<-fstrict-flex-arrays%> is not present");
1498 : : }
1499 : :
1500 : 633272 : diagnose_options (opts, opts_set, loc);
1501 : 633272 : }
1502 : :
1503 : : /* The function diagnoses incompatible combinations for provided options
1504 : : (OPTS and OPTS_SET) at a given LOCation. The function is called both
1505 : : when command line is parsed (after the target optimization hook) and
1506 : : when an optimize/target attribute (or pragma) is used. */
1507 : :
1508 : 922471 : void diagnose_options (gcc_options *opts, gcc_options *opts_set,
1509 : : location_t loc)
1510 : : {
1511 : : /* The optimization to partition hot and cold basic blocks into separate
1512 : : sections of the .o and executable files does not work (currently)
1513 : : with exception handling. This is because there is no support for
1514 : : generating unwind info. If opts->x_flag_exceptions is turned on
1515 : : we need to turn off the partitioning optimization. */
1516 : :
1517 : 922471 : enum unwind_info_type ui_except
1518 : 922471 : = targetm_common.except_unwind_info (opts);
1519 : :
1520 : 922471 : if (opts->x_flag_exceptions
1521 : 255443 : && opts->x_flag_reorder_blocks_and_partition
1522 : 87942 : && (ui_except == UI_SJLJ || ui_except >= UI_TARGET))
1523 : : {
1524 : 0 : if (opts_set->x_flag_reorder_blocks_and_partition)
1525 : 0 : inform (loc,
1526 : : "%<-freorder-blocks-and-partition%> does not work "
1527 : : "with exceptions on this architecture");
1528 : 0 : opts->x_flag_reorder_blocks_and_partition = 0;
1529 : 0 : opts->x_flag_reorder_blocks = 1;
1530 : : }
1531 : :
1532 : : /* If user requested unwind info, then turn off the partitioning
1533 : : optimization. */
1534 : :
1535 : 922471 : if (opts->x_flag_unwind_tables
1536 : 634124 : && !targetm_common.unwind_tables_default
1537 : 634124 : && opts->x_flag_reorder_blocks_and_partition
1538 : 486780 : && (ui_except == UI_SJLJ || ui_except >= UI_TARGET))
1539 : : {
1540 : 0 : if (opts_set->x_flag_reorder_blocks_and_partition)
1541 : 0 : inform (loc,
1542 : : "%<-freorder-blocks-and-partition%> does not support "
1543 : : "unwind info on this architecture");
1544 : 0 : opts->x_flag_reorder_blocks_and_partition = 0;
1545 : 0 : opts->x_flag_reorder_blocks = 1;
1546 : : }
1547 : :
1548 : : /* If the target requested unwind info, then turn off the partitioning
1549 : : optimization with a different message. Likewise, if the target does not
1550 : : support named sections. */
1551 : :
1552 : 922471 : if (opts->x_flag_reorder_blocks_and_partition
1553 : 631308 : && (!targetm_common.have_named_sections
1554 : 631308 : || (opts->x_flag_unwind_tables
1555 : 486780 : && targetm_common.unwind_tables_default
1556 : 0 : && (ui_except == UI_SJLJ || ui_except >= UI_TARGET))))
1557 : : {
1558 : 0 : if (opts_set->x_flag_reorder_blocks_and_partition)
1559 : 0 : inform (loc,
1560 : : "%<-freorder-blocks-and-partition%> does not work "
1561 : : "on this architecture");
1562 : 0 : opts->x_flag_reorder_blocks_and_partition = 0;
1563 : 0 : opts->x_flag_reorder_blocks = 1;
1564 : : }
1565 : :
1566 : :
1567 : 922471 : }
1568 : :
1569 : : #define LEFT_COLUMN 27
1570 : :
1571 : : /* Output ITEM, of length ITEM_WIDTH, in the left column,
1572 : : followed by word-wrapped HELP in a second column. */
1573 : : static void
1574 : 35247 : wrap_help (const char *help,
1575 : : const char *item,
1576 : : unsigned int item_width,
1577 : : unsigned int columns)
1578 : : {
1579 : 35247 : unsigned int col_width = LEFT_COLUMN;
1580 : 35247 : unsigned int remaining, room, len;
1581 : :
1582 : 35247 : remaining = strlen (help);
1583 : :
1584 : 60332 : do
1585 : : {
1586 : 60332 : room = columns - 3 - MAX (col_width, item_width);
1587 : 60332 : if (room > columns)
1588 : 0 : room = 0;
1589 : 60332 : len = remaining;
1590 : :
1591 : 60332 : if (room < len)
1592 : : {
1593 : : unsigned int i;
1594 : :
1595 : 1124226 : for (i = 0; help[i]; i++)
1596 : : {
1597 : 1124226 : if (i >= room && len != remaining)
1598 : : break;
1599 : 1099141 : if (help[i] == ' ')
1600 : : len = i;
1601 : 933707 : else if ((help[i] == '-' || help[i] == '/')
1602 : 3832 : && help[i + 1] != ' '
1603 : 3832 : && i > 0 && ISALPHA (help[i - 1]))
1604 : 1099141 : len = i + 1;
1605 : : }
1606 : : }
1607 : :
1608 : 60332 : printf (" %-*.*s %.*s\n", col_width, item_width, item, len, help);
1609 : 60332 : item_width = 0;
1610 : 145347 : while (help[len] == ' ')
1611 : 24683 : len++;
1612 : 60332 : help += len;
1613 : 60332 : remaining -= len;
1614 : : }
1615 : 60332 : while (remaining);
1616 : 35247 : }
1617 : :
1618 : : /* Data structure used to print list of valid option values. */
1619 : :
1620 : : class option_help_tuple
1621 : : {
1622 : : public:
1623 : 14 : option_help_tuple (int code, vec<const char *> values):
1624 : 14 : m_code (code), m_values (values)
1625 : : {}
1626 : :
1627 : : /* Code of an option. */
1628 : : int m_code;
1629 : :
1630 : : /* List of possible values. */
1631 : : vec<const char *> m_values;
1632 : : };
1633 : :
1634 : : /* Print help for a specific front-end, etc. */
1635 : : static void
1636 : 156 : print_filtered_help (unsigned int include_flags,
1637 : : unsigned int exclude_flags,
1638 : : unsigned int any_flags,
1639 : : unsigned int columns,
1640 : : struct gcc_options *opts,
1641 : : unsigned int lang_mask)
1642 : : {
1643 : 156 : unsigned int i;
1644 : 156 : const char *help;
1645 : 156 : bool found = false;
1646 : 156 : bool displayed = false;
1647 : 156 : char new_help[256];
1648 : :
1649 : 156 : if (!opts->x_help_printed)
1650 : 94 : opts->x_help_printed = XCNEWVAR (char, cl_options_count);
1651 : :
1652 : 156 : if (!opts->x_help_enum_printed)
1653 : 94 : opts->x_help_enum_printed = XCNEWVAR (char, cl_enums_count);
1654 : :
1655 : 156 : auto_vec<option_help_tuple> help_tuples;
1656 : :
1657 : 384696 : for (i = 0; i < cl_options_count; i++)
1658 : : {
1659 : 384540 : const struct cl_option *option = cl_options + i;
1660 : 384540 : unsigned int len;
1661 : 384540 : const char *opt;
1662 : 384540 : const char *tab;
1663 : :
1664 : 384540 : if (include_flags == 0
1665 : 377145 : || ((option->flags & include_flags) != include_flags))
1666 : : {
1667 : 337292 : if ((option->flags & any_flags) == 0)
1668 : 334169 : continue;
1669 : : }
1670 : :
1671 : : /* Skip unwanted switches. */
1672 : 50371 : if ((option->flags & exclude_flags) != 0)
1673 : 9750 : continue;
1674 : :
1675 : : /* The driver currently prints its own help text. */
1676 : 40621 : if ((option->flags & CL_DRIVER) != 0
1677 : 825 : && (option->flags & (((1U << cl_lang_count) - 1)
1678 : 731 : | CL_COMMON | CL_TARGET)) == 0)
1679 : 94 : continue;
1680 : :
1681 : : /* If an option contains a language specification,
1682 : : exclude it from common unless all languages are present. */
1683 : 40527 : if ((include_flags & CL_COMMON)
1684 : 4776 : && !(option->flags & CL_DRIVER)
1685 : 4386 : && (option->flags & CL_LANG_ALL)
1686 : 145 : && (option->flags & CL_LANG_ALL) != CL_LANG_ALL)
1687 : 145 : continue;
1688 : :
1689 : 40382 : found = true;
1690 : : /* Skip switches that have already been printed. */
1691 : 40382 : if (opts->x_help_printed[i])
1692 : 5125 : continue;
1693 : :
1694 : 35257 : opts->x_help_printed[i] = true;
1695 : :
1696 : 35257 : help = option->help;
1697 : 35257 : if (help == NULL)
1698 : : {
1699 : 1385 : if (exclude_flags & CL_UNDOCUMENTED)
1700 : 10 : continue;
1701 : :
1702 : : help = undocumented_msg;
1703 : : }
1704 : :
1705 : : /* Get the translation. */
1706 : 35247 : help = _(help);
1707 : :
1708 : 35247 : if (option->alias_target < N_OPTS
1709 : 1398 : && cl_options [option->alias_target].help)
1710 : : {
1711 : 1368 : const struct cl_option *target = cl_options + option->alias_target;
1712 : 1368 : if (option->help == NULL)
1713 : : {
1714 : : /* The option is undocumented but is an alias for an option that
1715 : : is documented. If the option has alias arguments, then its
1716 : : purpose is to provide certain arguments to the other option, so
1717 : : inform the reader of this. Otherwise, point the reader to the
1718 : : other option in preference to the former. */
1719 : :
1720 : 803 : if (option->alias_arg)
1721 : : {
1722 : 130 : if (option->neg_alias_arg)
1723 : 110 : snprintf (new_help, sizeof new_help,
1724 : 110 : _("Same as %s%s (or, in negated form, %s%s)."),
1725 : : target->opt_text, option->alias_arg,
1726 : 110 : target->opt_text, option->neg_alias_arg);
1727 : : else
1728 : 20 : snprintf (new_help, sizeof new_help,
1729 : 20 : _("Same as %s%s."),
1730 : 20 : target->opt_text, option->alias_arg);
1731 : : }
1732 : : else
1733 : 673 : snprintf (new_help, sizeof new_help,
1734 : 673 : _("Same as %s."),
1735 : 673 : target->opt_text);
1736 : : }
1737 : : else
1738 : : {
1739 : : /* For documented options with aliases, mention the aliased
1740 : : option's name for reference. */
1741 : 565 : snprintf (new_help, sizeof new_help,
1742 : 565 : _("%s Same as %s."),
1743 : 565 : help, cl_options [option->alias_target].opt_text);
1744 : : }
1745 : :
1746 : : help = new_help;
1747 : : }
1748 : :
1749 : 35247 : if (option->warn_message)
1750 : : {
1751 : : /* Mention that the use of the option will trigger a warning. */
1752 : 49 : if (help == new_help)
1753 : 42 : snprintf (new_help + strlen (new_help),
1754 : 42 : sizeof new_help - strlen (new_help),
1755 : : " %s", _(use_diagnosed_msg));
1756 : : else
1757 : 7 : snprintf (new_help, sizeof new_help,
1758 : : "%s %s", help, _(use_diagnosed_msg));
1759 : :
1760 : : help = new_help;
1761 : : }
1762 : :
1763 : : /* Find the gap between the name of the
1764 : : option and its descriptive text. */
1765 : 35247 : tab = strchr (help, '\t');
1766 : 35247 : if (tab)
1767 : : {
1768 : 1619 : len = tab - help;
1769 : 1619 : opt = help;
1770 : 1619 : help = tab + 1;
1771 : : }
1772 : : else
1773 : : {
1774 : 33628 : opt = option->opt_text;
1775 : 33628 : len = strlen (opt);
1776 : : }
1777 : :
1778 : : /* With the -Q option enabled we change the descriptive text associated
1779 : : with an option to be an indication of its current setting. */
1780 : 35247 : if (!opts->x_quiet_flag)
1781 : : {
1782 : 2510 : void *flag_var = option_flag_var (i, opts);
1783 : :
1784 : 2510 : if (len < (LEFT_COLUMN + 2))
1785 : 2226 : strcpy (new_help, "\t\t");
1786 : : else
1787 : 284 : strcpy (new_help, "\t");
1788 : :
1789 : : /* Set to print whether the option is enabled or disabled,
1790 : : or, if it's an alias for another option, the name of
1791 : : the aliased option. */
1792 : 2510 : bool print_state = false;
1793 : :
1794 : 2510 : if (flag_var != NULL
1795 : 2288 : && option->var_type != CLVC_DEFER)
1796 : : {
1797 : : /* If OPTION is only available for a specific subset
1798 : : of languages other than this one, mention them. */
1799 : 2288 : bool avail_for_lang = true;
1800 : 2288 : if (unsigned langset = option->flags & CL_LANG_ALL)
1801 : : {
1802 : 1308 : if (!(langset & lang_mask))
1803 : : {
1804 : 480 : avail_for_lang = false;
1805 : 480 : strcat (new_help, _("[available in "));
1806 : 7680 : for (unsigned i = 0, n = 0; (1U << i) < CL_LANG_ALL; ++i)
1807 : 7200 : if (langset & (1U << i))
1808 : : {
1809 : 830 : if (n++)
1810 : 350 : strcat (new_help, ", ");
1811 : 830 : strcat (new_help, lang_names[i]);
1812 : : }
1813 : 480 : strcat (new_help, "]");
1814 : : }
1815 : : }
1816 : 480 : if (!avail_for_lang)
1817 : : ; /* Print nothing else if the option is not available
1818 : : in the current language. */
1819 : 1808 : else if (option->flags & CL_JOINED)
1820 : : {
1821 : 157 : if (option->var_type == CLVC_STRING)
1822 : : {
1823 : 10 : if (* (const char **) flag_var != NULL)
1824 : 8 : snprintf (new_help + strlen (new_help),
1825 : 8 : sizeof (new_help) - strlen (new_help),
1826 : : "%s", * (const char **) flag_var);
1827 : : }
1828 : 147 : else if (option->var_type == CLVC_ENUM)
1829 : : {
1830 : 47 : const struct cl_enum *e = &cl_enums[option->var_enum];
1831 : 47 : int value;
1832 : 47 : const char *arg = NULL;
1833 : :
1834 : 47 : value = e->get (flag_var);
1835 : 47 : enum_value_to_arg (e->values, &arg, value, lang_mask);
1836 : 47 : if (arg == NULL)
1837 : 8 : arg = _("[default]");
1838 : 47 : snprintf (new_help + strlen (new_help),
1839 : 47 : sizeof (new_help) - strlen (new_help),
1840 : : "%s", arg);
1841 : : }
1842 : : else
1843 : : {
1844 : 100 : if (option->cl_host_wide_int)
1845 : 24 : sprintf (new_help + strlen (new_help),
1846 : 24 : _("%llu bytes"), (unsigned long long)
1847 : : *(unsigned HOST_WIDE_INT *) flag_var);
1848 : : else
1849 : 76 : sprintf (new_help + strlen (new_help),
1850 : : "%i", * (int *) flag_var);
1851 : : }
1852 : : }
1853 : : else
1854 : : print_state = true;
1855 : : }
1856 : : else
1857 : : /* When there is no argument, print the option state only
1858 : : if the option takes no argument. */
1859 : 222 : print_state = !(option->flags & CL_JOINED);
1860 : :
1861 : 857 : if (print_state)
1862 : : {
1863 : 1855 : if (option->alias_target < N_OPTS
1864 : : && option->alias_target != OPT_SPECIAL_warn_removed
1865 : : && option->alias_target != OPT_SPECIAL_ignore
1866 : : && option->alias_target != OPT_SPECIAL_input_file
1867 : : && option->alias_target != OPT_SPECIAL_program_name
1868 : : && option->alias_target != OPT_SPECIAL_unknown)
1869 : : {
1870 : 162 : const struct cl_option *target
1871 : 162 : = &cl_options[option->alias_target];
1872 : 324 : sprintf (new_help + strlen (new_help), "%s%s",
1873 : 162 : target->opt_text,
1874 : 162 : option->alias_arg ? option->alias_arg : "");
1875 : : }
1876 : 1693 : else if (option->alias_target == OPT_SPECIAL_ignore)
1877 : 16 : strcat (new_help, ("[ignored]"));
1878 : : else
1879 : : {
1880 : : /* Print the state for an on/off option. */
1881 : 1677 : int ena = option_enabled (i, lang_mask, opts);
1882 : 1677 : if (ena > 0)
1883 : 769 : strcat (new_help, _("[enabled]"));
1884 : 908 : else if (ena == 0)
1885 : 803 : strcat (new_help, _("[disabled]"));
1886 : : }
1887 : : }
1888 : :
1889 : : help = new_help;
1890 : : }
1891 : :
1892 : 35247 : if (option->range_max != -1 && tab == NULL)
1893 : : {
1894 : 7479 : char b[128];
1895 : 7479 : snprintf (b, sizeof (b), "<%d,%d>", option->range_min,
1896 : : option->range_max);
1897 : 7479 : opt = concat (opt, b, NULL);
1898 : 7479 : len += strlen (b);
1899 : : }
1900 : :
1901 : 35247 : wrap_help (help, opt, len, columns);
1902 : 35247 : displayed = true;
1903 : :
1904 : 35247 : if (option->var_type == CLVC_ENUM
1905 : 981 : && opts->x_help_enum_printed[option->var_enum] != 2)
1906 : 981 : opts->x_help_enum_printed[option->var_enum] = 1;
1907 : : else
1908 : : {
1909 : 34266 : vec<const char *> option_values
1910 : 34266 : = targetm_common.get_valid_option_values (i, NULL);
1911 : 34280 : if (!option_values.is_empty ())
1912 : 14 : help_tuples.safe_push (option_help_tuple (i, option_values));
1913 : : }
1914 : : }
1915 : :
1916 : 156 : if (! found)
1917 : : {
1918 : 9 : unsigned int langs = include_flags & CL_LANG_ALL;
1919 : :
1920 : 9 : if (langs == 0)
1921 : 0 : printf (_(" No options with the desired characteristics were found\n"));
1922 : : else
1923 : : {
1924 : : unsigned int i;
1925 : :
1926 : : /* PR 31349: Tell the user how to see all of the
1927 : : options supported by a specific front end. */
1928 : 144 : for (i = 0; (1U << i) < CL_LANG_ALL; i ++)
1929 : 135 : if ((1U << i) & langs)
1930 : 9 : printf (_(" None found. Use --help=%s to show *all* the options supported by the %s front-end.\n"),
1931 : 9 : lang_names[i], lang_names[i]);
1932 : : }
1933 : :
1934 : : }
1935 : 147 : else if (! displayed)
1936 : 0 : printf (_(" All options with the desired characteristics have already been displayed\n"));
1937 : :
1938 : 156 : putchar ('\n');
1939 : :
1940 : : /* Print details of enumerated option arguments, if those
1941 : : enumerations have help text headings provided. If no help text
1942 : : is provided, presume that the possible values are listed in the
1943 : : help text for the relevant options. */
1944 : 12792 : for (i = 0; i < cl_enums_count; i++)
1945 : : {
1946 : 12636 : unsigned int j, pos;
1947 : :
1948 : 12636 : if (opts->x_help_enum_printed[i] != 1)
1949 : 10954 : continue;
1950 : 1682 : if (cl_enums[i].help == NULL)
1951 : 1584 : continue;
1952 : 98 : printf (" %s\n ", _(cl_enums[i].help));
1953 : 98 : pos = 4;
1954 : 455 : for (j = 0; cl_enums[i].values[j].arg != NULL; j++)
1955 : : {
1956 : 357 : unsigned int len = strlen (cl_enums[i].values[j].arg);
1957 : :
1958 : 357 : if (pos > 4 && pos + 1 + len <= columns)
1959 : : {
1960 : 258 : printf (" %s", cl_enums[i].values[j].arg);
1961 : 258 : pos += 1 + len;
1962 : : }
1963 : : else
1964 : : {
1965 : 1 : if (pos > 4)
1966 : : {
1967 : 1 : printf ("\n ");
1968 : 1 : pos = 4;
1969 : : }
1970 : 99 : printf ("%s", cl_enums[i].values[j].arg);
1971 : 99 : pos += len;
1972 : : }
1973 : : }
1974 : 98 : printf ("\n\n");
1975 : 98 : opts->x_help_enum_printed[i] = 2;
1976 : : }
1977 : :
1978 : 170 : for (unsigned i = 0; i < help_tuples.length (); i++)
1979 : : {
1980 : 14 : const struct cl_option *option = cl_options + help_tuples[i].m_code;
1981 : 14 : printf (_(" Known valid arguments for %s option:\n "),
1982 : 14 : option->opt_text);
1983 : 1232 : for (unsigned j = 0; j < help_tuples[i].m_values.length (); j++)
1984 : 1218 : printf (" %s", help_tuples[i].m_values[j]);
1985 : 14 : printf ("\n\n");
1986 : : }
1987 : 156 : }
1988 : :
1989 : : /* Display help for a specified type of option.
1990 : : The options must have ALL of the INCLUDE_FLAGS set
1991 : : ANY of the flags in the ANY_FLAGS set
1992 : : and NONE of the EXCLUDE_FLAGS set. The current option state is in
1993 : : OPTS; LANG_MASK is used for interpreting enumerated option state. */
1994 : : static void
1995 : 156 : print_specific_help (unsigned int include_flags,
1996 : : unsigned int exclude_flags,
1997 : : unsigned int any_flags,
1998 : : struct gcc_options *opts,
1999 : : unsigned int lang_mask)
2000 : : {
2001 : 156 : unsigned int all_langs_mask = (1U << cl_lang_count) - 1;
2002 : 156 : const char * description = NULL;
2003 : 156 : const char * descrip_extra = "";
2004 : 156 : size_t i;
2005 : 156 : unsigned int flag;
2006 : :
2007 : : /* Sanity check: Make sure that we do not have more
2008 : : languages than we have bits available to enumerate them. */
2009 : 156 : gcc_assert ((1U << cl_lang_count) <= CL_MIN_OPTION_CLASS);
2010 : :
2011 : : /* If we have not done so already, obtain
2012 : : the desired maximum width of the output. */
2013 : 156 : if (opts->x_help_columns == 0)
2014 : : {
2015 : 94 : opts->x_help_columns = get_terminal_width ();
2016 : 94 : if (opts->x_help_columns == INT_MAX)
2017 : : /* Use a reasonable default. */
2018 : 56 : opts->x_help_columns = 80;
2019 : : }
2020 : :
2021 : : /* Decide upon the title for the options that we are going to display. */
2022 : 3588 : for (i = 0, flag = 1; flag <= CL_MAX_OPTION_CLASS; flag <<= 1, i ++)
2023 : : {
2024 : 3432 : switch (flag & include_flags)
2025 : : {
2026 : : case 0:
2027 : : case CL_DRIVER:
2028 : : break;
2029 : :
2030 : 7 : case CL_TARGET:
2031 : 7 : description = _("The following options are target specific");
2032 : 7 : break;
2033 : 11 : case CL_WARNING:
2034 : 11 : description = _("The following options control compiler warning messages");
2035 : 11 : break;
2036 : 10 : case CL_OPTIMIZATION:
2037 : 10 : description = _("The following options control optimizations");
2038 : 10 : break;
2039 : 5 : case CL_COMMON:
2040 : 5 : description = _("The following options are language-independent");
2041 : 5 : break;
2042 : 62 : case CL_PARAMS:
2043 : 62 : description = _("The following options control parameters");
2044 : 62 : break;
2045 : 53 : default:
2046 : 53 : if (i >= cl_lang_count)
2047 : : break;
2048 : 53 : if (exclude_flags & all_langs_mask)
2049 : 45 : description = _("The following options are specific to just the language ");
2050 : : else
2051 : 8 : description = _("The following options are supported by the language ");
2052 : 53 : descrip_extra = lang_names [i];
2053 : 53 : break;
2054 : : }
2055 : : }
2056 : :
2057 : 156 : if (description == NULL)
2058 : : {
2059 : 9 : if (any_flags == 0)
2060 : : {
2061 : 6 : if (include_flags & CL_UNDOCUMENTED)
2062 : 2 : description = _("The following options are not documented");
2063 : 4 : else if (include_flags & CL_SEPARATE)
2064 : 2 : description = _("The following options take separate arguments");
2065 : 2 : else if (include_flags & CL_JOINED)
2066 : 2 : description = _("The following options take joined arguments");
2067 : : else
2068 : : {
2069 : 0 : internal_error ("unrecognized %<include_flags 0x%x%> passed "
2070 : : "to %<print_specific_help%>",
2071 : : include_flags);
2072 : : return;
2073 : : }
2074 : : }
2075 : : else
2076 : : {
2077 : 3 : if (any_flags & all_langs_mask)
2078 : 3 : description = _("The following options are language-related");
2079 : : else
2080 : 0 : description = _("The following options are language-independent");
2081 : : }
2082 : : }
2083 : :
2084 : 156 : printf ("%s%s:\n", description, descrip_extra);
2085 : 156 : print_filtered_help (include_flags, exclude_flags, any_flags,
2086 : : opts->x_help_columns, opts, lang_mask);
2087 : : }
2088 : :
2089 : : /* Enable FDO-related flags. */
2090 : :
2091 : : static void
2092 : 152 : enable_fdo_optimizations (struct gcc_options *opts,
2093 : : struct gcc_options *opts_set,
2094 : : int value, bool autofdo)
2095 : : {
2096 : 152 : if (!autofdo)
2097 : : {
2098 : 152 : SET_OPTION_IF_UNSET (opts, opts_set, flag_branch_probabilities, value);
2099 : 152 : SET_OPTION_IF_UNSET (opts, opts_set, flag_profile_values, value);
2100 : : }
2101 : 152 : SET_OPTION_IF_UNSET (opts, opts_set, flag_value_profile_transformations,
2102 : : value);
2103 : :
2104 : : /* Enable IPA optimizatins that makes effective use of profile data. */
2105 : 152 : SET_OPTION_IF_UNSET (opts, opts_set, flag_inline_functions, value);
2106 : 152 : SET_OPTION_IF_UNSET (opts, opts_set, flag_ipa_cp, value);
2107 : 152 : if (value)
2108 : : {
2109 : 152 : SET_OPTION_IF_UNSET (opts, opts_set, flag_ipa_cp_clone, 1);
2110 : 152 : SET_OPTION_IF_UNSET (opts, opts_set, flag_ipa_bit_cp, 1);
2111 : : }
2112 : :
2113 : 152 : SET_OPTION_IF_UNSET (opts, opts_set, flag_gcse_after_reload, value);
2114 : 152 : SET_OPTION_IF_UNSET (opts, opts_set, flag_tracer, value);
2115 : :
2116 : : /* Loop optimizations uses profile feedback to determine their profitability
2117 : : and thus it makes sense to enable them by default even at -O2.
2118 : : Auto-profile, in its current form, is not very good on determining
2119 : : iteration counts and thus only real profile feedback is used. */
2120 : 152 : if (!autofdo)
2121 : : {
2122 : 152 : SET_OPTION_IF_UNSET (opts, opts_set, flag_unroll_loops, value);
2123 : 152 : SET_OPTION_IF_UNSET (opts, opts_set, flag_peel_loops, value);
2124 : 152 : SET_OPTION_IF_UNSET (opts, opts_set, flag_predictive_commoning, value);
2125 : 152 : SET_OPTION_IF_UNSET (opts, opts_set, flag_split_loops, value);
2126 : 152 : SET_OPTION_IF_UNSET (opts, opts_set, flag_unswitch_loops, value);
2127 : 152 : SET_OPTION_IF_UNSET (opts, opts_set, flag_tree_loop_vectorize, value);
2128 : 152 : SET_OPTION_IF_UNSET (opts, opts_set, flag_tree_slp_vectorize, value);
2129 : 152 : SET_OPTION_IF_UNSET (opts, opts_set, flag_version_loops_for_strides, value);
2130 : 152 : SET_OPTION_IF_UNSET (opts, opts_set, flag_vect_cost_model,
2131 : : VECT_COST_MODEL_DYNAMIC);
2132 : 152 : SET_OPTION_IF_UNSET (opts, opts_set, flag_tree_loop_distribute_patterns,
2133 : : value);
2134 : 152 : SET_OPTION_IF_UNSET (opts, opts_set, flag_loop_interchange, value);
2135 : 152 : SET_OPTION_IF_UNSET (opts, opts_set, flag_unroll_jam, value);
2136 : 152 : SET_OPTION_IF_UNSET (opts, opts_set, flag_tree_loop_distribution, value);
2137 : 152 : SET_OPTION_IF_UNSET (opts, opts_set, flag_optimize_crc, value);
2138 : : }
2139 : 152 : }
2140 : :
2141 : : /* -f{,no-}sanitize{,-recover}= suboptions. */
2142 : : const struct sanitizer_opts_s sanitizer_opts[] =
2143 : : {
2144 : : #define SANITIZER_OPT(name, flags, recover, trap) \
2145 : : { #name, flags, sizeof #name - 1, recover, trap }
2146 : : SANITIZER_OPT (address, (SANITIZE_ADDRESS | SANITIZE_USER_ADDRESS), true,
2147 : : false),
2148 : : SANITIZER_OPT (hwaddress, (SANITIZE_HWADDRESS | SANITIZE_USER_HWADDRESS),
2149 : : true, false),
2150 : : SANITIZER_OPT (kernel-address, (SANITIZE_ADDRESS | SANITIZE_KERNEL_ADDRESS),
2151 : : true, false),
2152 : : SANITIZER_OPT (kernel-hwaddress,
2153 : : (SANITIZE_HWADDRESS | SANITIZE_KERNEL_HWADDRESS),
2154 : : true, false),
2155 : : SANITIZER_OPT (pointer-compare, SANITIZE_POINTER_COMPARE, true, false),
2156 : : SANITIZER_OPT (pointer-subtract, SANITIZE_POINTER_SUBTRACT, true, false),
2157 : : SANITIZER_OPT (thread, SANITIZE_THREAD, false, false),
2158 : : SANITIZER_OPT (leak, SANITIZE_LEAK, false, false),
2159 : : SANITIZER_OPT (shift, SANITIZE_SHIFT, true, true),
2160 : : SANITIZER_OPT (shift-base, SANITIZE_SHIFT_BASE, true, true),
2161 : : SANITIZER_OPT (shift-exponent, SANITIZE_SHIFT_EXPONENT, true, true),
2162 : : SANITIZER_OPT (integer-divide-by-zero, SANITIZE_DIVIDE, true, true),
2163 : : SANITIZER_OPT (undefined, SANITIZE_UNDEFINED, true, true),
2164 : : SANITIZER_OPT (unreachable, SANITIZE_UNREACHABLE, false, true),
2165 : : SANITIZER_OPT (vla-bound, SANITIZE_VLA, true, true),
2166 : : SANITIZER_OPT (return, SANITIZE_RETURN, false, true),
2167 : : SANITIZER_OPT (null, SANITIZE_NULL, true, true),
2168 : : SANITIZER_OPT (signed-integer-overflow, SANITIZE_SI_OVERFLOW, true, true),
2169 : : SANITIZER_OPT (bool, SANITIZE_BOOL, true, true),
2170 : : SANITIZER_OPT (enum, SANITIZE_ENUM, true, true),
2171 : : SANITIZER_OPT (float-divide-by-zero, SANITIZE_FLOAT_DIVIDE, true, true),
2172 : : SANITIZER_OPT (float-cast-overflow, SANITIZE_FLOAT_CAST, true, true),
2173 : : SANITIZER_OPT (bounds, SANITIZE_BOUNDS, true, true),
2174 : : SANITIZER_OPT (bounds-strict, SANITIZE_BOUNDS | SANITIZE_BOUNDS_STRICT, true,
2175 : : true),
2176 : : SANITIZER_OPT (alignment, SANITIZE_ALIGNMENT, true, true),
2177 : : SANITIZER_OPT (nonnull-attribute, SANITIZE_NONNULL_ATTRIBUTE, true, true),
2178 : : SANITIZER_OPT (returns-nonnull-attribute, SANITIZE_RETURNS_NONNULL_ATTRIBUTE,
2179 : : true, true),
2180 : : SANITIZER_OPT (object-size, SANITIZE_OBJECT_SIZE, true, true),
2181 : : SANITIZER_OPT (vptr, SANITIZE_VPTR, true, false),
2182 : : SANITIZER_OPT (pointer-overflow, SANITIZE_POINTER_OVERFLOW, true, true),
2183 : : SANITIZER_OPT (builtin, SANITIZE_BUILTIN, true, true),
2184 : : SANITIZER_OPT (shadow-call-stack, SANITIZE_SHADOW_CALL_STACK, false, false),
2185 : : SANITIZER_OPT (all, ~sanitize_code_type (0), true, true),
2186 : : #undef SANITIZER_OPT
2187 : : { NULL, sanitize_code_type (0), 0UL, false, false }
2188 : : };
2189 : :
2190 : : /* -fzero-call-used-regs= suboptions. */
2191 : : const struct zero_call_used_regs_opts_s zero_call_used_regs_opts[] =
2192 : : {
2193 : : #define ZERO_CALL_USED_REGS_OPT(name, flags) \
2194 : : { #name, flags }
2195 : : ZERO_CALL_USED_REGS_OPT (skip, zero_regs_flags::SKIP),
2196 : : ZERO_CALL_USED_REGS_OPT (used-gpr-arg, zero_regs_flags::USED_GPR_ARG),
2197 : : ZERO_CALL_USED_REGS_OPT (used-gpr, zero_regs_flags::USED_GPR),
2198 : : ZERO_CALL_USED_REGS_OPT (used-arg, zero_regs_flags::USED_ARG),
2199 : : ZERO_CALL_USED_REGS_OPT (used, zero_regs_flags::USED),
2200 : : ZERO_CALL_USED_REGS_OPT (all-gpr-arg, zero_regs_flags::ALL_GPR_ARG),
2201 : : ZERO_CALL_USED_REGS_OPT (all-gpr, zero_regs_flags::ALL_GPR),
2202 : : ZERO_CALL_USED_REGS_OPT (all-arg, zero_regs_flags::ALL_ARG),
2203 : : ZERO_CALL_USED_REGS_OPT (all, zero_regs_flags::ALL),
2204 : : ZERO_CALL_USED_REGS_OPT (leafy-gpr-arg, zero_regs_flags::LEAFY_GPR_ARG),
2205 : : ZERO_CALL_USED_REGS_OPT (leafy-gpr, zero_regs_flags::LEAFY_GPR),
2206 : : ZERO_CALL_USED_REGS_OPT (leafy-arg, zero_regs_flags::LEAFY_ARG),
2207 : : ZERO_CALL_USED_REGS_OPT (leafy, zero_regs_flags::LEAFY),
2208 : : #undef ZERO_CALL_USED_REGS_OPT
2209 : : {NULL, 0U}
2210 : : };
2211 : :
2212 : : /* A struct for describing a run of chars within a string. */
2213 : :
2214 : : class string_fragment
2215 : : {
2216 : : public:
2217 : 6 : string_fragment (const char *start, size_t len)
2218 : 6 : : m_start (start), m_len (len) {}
2219 : :
2220 : : const char *m_start;
2221 : : size_t m_len;
2222 : : };
2223 : :
2224 : : /* Specialization of edit_distance_traits for string_fragment,
2225 : : for use by get_closest_sanitizer_option. */
2226 : :
2227 : : template <>
2228 : : struct edit_distance_traits<const string_fragment &>
2229 : : {
2230 : 6 : static size_t get_length (const string_fragment &fragment)
2231 : : {
2232 : 6 : return fragment.m_len;
2233 : : }
2234 : :
2235 : 6 : static const char *get_string (const string_fragment &fragment)
2236 : : {
2237 : 6 : return fragment.m_start;
2238 : : }
2239 : : };
2240 : :
2241 : : /* Given ARG, an unrecognized sanitizer option, return the best
2242 : : matching sanitizer option, or NULL if there isn't one.
2243 : : OPTS is array of candidate sanitizer options.
2244 : : CODE is OPT_fsanitize_, OPT_fsanitize_recover_ or OPT_fsanitize_trap_.
2245 : : VALUE is non-zero for the regular form of the option, zero
2246 : : for the "no-" form (e.g. "-fno-sanitize-recover="). */
2247 : :
2248 : : static const char *
2249 : 6 : get_closest_sanitizer_option (const string_fragment &arg,
2250 : : const struct sanitizer_opts_s *opts,
2251 : : enum opt_code code, int value)
2252 : : {
2253 : 6 : best_match <const string_fragment &, const char*> bm (arg);
2254 : 204 : for (int i = 0; opts[i].name != NULL; ++i)
2255 : : {
2256 : : /* -fsanitize=all is not valid, so don't offer it. */
2257 : 198 : if (code == OPT_fsanitize_
2258 : 165 : && opts[i].flag == ~sanitize_code_type (0)
2259 : 5 : && value)
2260 : 4 : continue;
2261 : :
2262 : : /* For -fsanitize-recover= (and not -fno-sanitize-recover=),
2263 : : don't offer the non-recoverable options. */
2264 : 194 : if (code == OPT_fsanitize_recover_
2265 : 33 : && !opts[i].can_recover
2266 : 5 : && value)
2267 : 5 : continue;
2268 : :
2269 : : /* For -fsanitize-trap= (and not -fno-sanitize-trap=),
2270 : : don't offer the non-trapping options. */
2271 : 189 : if (code == OPT_fsanitize_trap_
2272 : 0 : && !opts[i].can_trap
2273 : 0 : && value)
2274 : 0 : continue;
2275 : :
2276 : 189 : bm.consider (opts[i].name);
2277 : : }
2278 : 6 : return bm.get_best_meaningful_candidate ();
2279 : : }
2280 : :
2281 : : /* Parse comma separated sanitizer suboptions from P for option SCODE,
2282 : : adjust previous FLAGS and return new ones. If COMPLAIN is false,
2283 : : don't issue diagnostics. */
2284 : :
2285 : : sanitize_code_type
2286 : 19442 : parse_sanitizer_options (const char *p, location_t loc, int scode,
2287 : : sanitize_code_type flags, int value, bool complain)
2288 : : {
2289 : 19442 : enum opt_code code = (enum opt_code) scode;
2290 : :
2291 : 20375 : while (*p != 0)
2292 : : {
2293 : 20375 : size_t len, i;
2294 : 20375 : bool found = false;
2295 : 20375 : const char *comma = strchr (p, ',');
2296 : :
2297 : 20375 : if (comma == NULL)
2298 : 19442 : len = strlen (p);
2299 : : else
2300 : 933 : len = comma - p;
2301 : 20375 : if (len == 0)
2302 : : {
2303 : 0 : p = comma + 1;
2304 : 0 : continue;
2305 : : }
2306 : :
2307 : : /* Check to see if the string matches an option class name. */
2308 : 184658 : for (i = 0; sanitizer_opts[i].name != NULL; ++i)
2309 : 184652 : if (len == sanitizer_opts[i].len
2310 : 29309 : && memcmp (p, sanitizer_opts[i].name, len) == 0)
2311 : : {
2312 : : /* Handle both -fsanitize and -fno-sanitize cases. */
2313 : 20369 : if (value && sanitizer_opts[i].flag == ~sanitize_code_type (0))
2314 : : {
2315 : 42 : if (code == OPT_fsanitize_)
2316 : : {
2317 : 3 : if (complain)
2318 : 3 : error_at (loc, "%<-fsanitize=all%> option is not valid");
2319 : : }
2320 : 39 : else if (code == OPT_fsanitize_recover_)
2321 : 13 : flags |= ~(SANITIZE_THREAD | SANITIZE_LEAK
2322 : : | SANITIZE_UNREACHABLE | SANITIZE_RETURN
2323 : : | SANITIZE_SHADOW_CALL_STACK);
2324 : : else /* if (code == OPT_fsanitize_trap_) */
2325 : 26 : flags |= (SANITIZE_UNDEFINED
2326 : : | SANITIZE_UNDEFINED_NONDEFAULT);
2327 : : }
2328 : 19047 : else if (value)
2329 : : {
2330 : : /* Do not enable -fsanitize-recover=unreachable and
2331 : : -fsanitize-recover=return if -fsanitize-recover=undefined
2332 : : is selected. */
2333 : 19047 : if (code == OPT_fsanitize_recover_
2334 : 404 : && sanitizer_opts[i].flag == SANITIZE_UNDEFINED)
2335 : 40 : flags |= (SANITIZE_UNDEFINED
2336 : : & ~(SANITIZE_UNREACHABLE | SANITIZE_RETURN));
2337 : 19007 : else if (code == OPT_fsanitize_trap_
2338 : 176 : && sanitizer_opts[i].flag == SANITIZE_VPTR)
2339 : 0 : error_at (loc, "%<-fsanitize-trap=%s%> is not supported",
2340 : : sanitizer_opts[i].name);
2341 : : else
2342 : 19007 : flags |= sanitizer_opts[i].flag;
2343 : : }
2344 : : else
2345 : : {
2346 : 1280 : flags &= ~sanitizer_opts[i].flag;
2347 : : /* Don't always clear SANITIZE_ADDRESS if it was previously
2348 : : set: -fsanitize=address -fno-sanitize=kernel-address should
2349 : : leave SANITIZE_ADDRESS set. */
2350 : 1280 : if (flags & (SANITIZE_KERNEL_ADDRESS | SANITIZE_USER_ADDRESS))
2351 : 754 : flags |= SANITIZE_ADDRESS;
2352 : : }
2353 : : found = true;
2354 : : break;
2355 : : }
2356 : :
2357 : 20375 : if (! found && complain)
2358 : : {
2359 : 6 : const char *hint
2360 : 6 : = get_closest_sanitizer_option (string_fragment (p, len),
2361 : : sanitizer_opts, code, value);
2362 : :
2363 : 6 : const char *suffix;
2364 : 6 : if (code == OPT_fsanitize_recover_)
2365 : : suffix = "-recover";
2366 : 5 : else if (code == OPT_fsanitize_trap_)
2367 : : suffix = "-trap";
2368 : : else
2369 : 5 : suffix = "";
2370 : :
2371 : 6 : if (hint)
2372 : 4 : error_at (loc,
2373 : : "unrecognized argument to %<-f%ssanitize%s=%> "
2374 : : "option: %q.*s; did you mean %qs?",
2375 : : value ? "" : "no-",
2376 : : suffix, (int) len, p, hint);
2377 : : else
2378 : 3 : error_at (loc,
2379 : : "unrecognized argument to %<-f%ssanitize%s=%> option: "
2380 : : "%q.*s", value ? "" : "no-",
2381 : : suffix, (int) len, p);
2382 : : }
2383 : :
2384 : 20375 : if (comma == NULL)
2385 : : break;
2386 : 933 : p = comma + 1;
2387 : : }
2388 : 19442 : return flags;
2389 : : }
2390 : :
2391 : : /* Parse string values of no_sanitize attribute passed in VALUE.
2392 : : Values are separated with comma. */
2393 : :
2394 : : sanitize_code_type
2395 : 281 : parse_no_sanitize_attribute (char *value)
2396 : : {
2397 : 281 : sanitize_code_type flags = 0;
2398 : 281 : unsigned int i;
2399 : 281 : char *q = strtok (value, ",");
2400 : :
2401 : 1072 : while (q != NULL)
2402 : : {
2403 : 6128 : for (i = 0; sanitizer_opts[i].name != NULL; ++i)
2404 : 6108 : if (strcmp (sanitizer_opts[i].name, q) == 0)
2405 : : {
2406 : 490 : flags |= sanitizer_opts[i].flag;
2407 : 490 : if (sanitizer_opts[i].flag == SANITIZE_UNDEFINED)
2408 : 57 : flags |= SANITIZE_UNDEFINED_NONDEFAULT;
2409 : : break;
2410 : : }
2411 : :
2412 : 510 : if (sanitizer_opts[i].name == NULL)
2413 : 20 : warning (OPT_Wattributes,
2414 : : "%qs attribute directive ignored", q);
2415 : :
2416 : 510 : q = strtok (NULL, ",");
2417 : : }
2418 : :
2419 : 281 : return flags;
2420 : : }
2421 : :
2422 : : /* Parse -fzero-call-used-regs suboptions from ARG, return the FLAGS. */
2423 : :
2424 : : unsigned int
2425 : 77 : parse_zero_call_used_regs_options (const char *arg)
2426 : : {
2427 : 77 : unsigned int flags = 0;
2428 : :
2429 : : /* Check to see if the string matches a sub-option name. */
2430 : 459 : for (unsigned int i = 0; zero_call_used_regs_opts[i].name != NULL; ++i)
2431 : 459 : if (strcmp (arg, zero_call_used_regs_opts[i].name) == 0)
2432 : : {
2433 : 77 : flags = zero_call_used_regs_opts[i].flag;
2434 : 77 : break;
2435 : : }
2436 : :
2437 : 77 : if (!flags)
2438 : 0 : error ("unrecognized argument to %<-fzero-call-used-regs=%>: %qs", arg);
2439 : :
2440 : 77 : return flags;
2441 : : }
2442 : :
2443 : : /* Parse -falign-NAME format for a FLAG value. Return individual
2444 : : parsed integer values into RESULT_VALUES array. If REPORT_ERROR is
2445 : : set, print error message at LOC location. */
2446 : :
2447 : : bool
2448 : 358492 : parse_and_check_align_values (const char *flag,
2449 : : const char *name,
2450 : : auto_vec<unsigned> &result_values,
2451 : : bool report_error,
2452 : : location_t loc)
2453 : : {
2454 : 358492 : char *str = xstrdup (flag);
2455 : 1194954 : for (char *p = strtok (str, ":"); p; p = strtok (NULL, ":"))
2456 : : {
2457 : 836462 : char *end;
2458 : 836462 : int v = strtol (p, &end, 10);
2459 : 836462 : if (*end != '\0' || v < 0)
2460 : : {
2461 : 0 : if (report_error)
2462 : 0 : error_at (loc, "invalid arguments for %<-falign-%s%> option: %qs",
2463 : : name, flag);
2464 : :
2465 : 0 : return false;
2466 : : }
2467 : :
2468 : 836462 : result_values.safe_push ((unsigned)v);
2469 : : }
2470 : :
2471 : 358492 : free (str);
2472 : :
2473 : : /* Check that we have a correct number of values. */
2474 : 716984 : if (result_values.is_empty () || result_values.length () > 4)
2475 : : {
2476 : 0 : if (report_error)
2477 : 0 : error_at (loc, "invalid number of arguments for %<-falign-%s%> "
2478 : : "option: %qs", name, flag);
2479 : 0 : return false;
2480 : : }
2481 : :
2482 : 1194953 : for (unsigned i = 0; i < result_values.length (); i++)
2483 : 836462 : if (result_values[i] > MAX_CODE_ALIGN_VALUE)
2484 : : {
2485 : 1 : if (report_error)
2486 : 1 : error_at (loc, "%<-falign-%s%> is not between 0 and %d",
2487 : : name, MAX_CODE_ALIGN_VALUE);
2488 : 1 : return false;
2489 : : }
2490 : :
2491 : : return true;
2492 : : }
2493 : :
2494 : : /* Check that alignment value FLAG for -falign-NAME is valid at a given
2495 : : location LOC. OPT_STR points to the stored -falign-NAME=argument and
2496 : : OPT_FLAG points to the associated -falign-NAME on/off flag. */
2497 : :
2498 : : static void
2499 : 20 : check_alignment_argument (location_t loc, const char *flag, const char *name,
2500 : : int *opt_flag, const char **opt_str)
2501 : : {
2502 : 20 : auto_vec<unsigned> align_result;
2503 : 20 : parse_and_check_align_values (flag, name, align_result, true, loc);
2504 : :
2505 : 40 : if (align_result.length() >= 1 && align_result[0] == 0)
2506 : : {
2507 : 0 : *opt_flag = 1;
2508 : 0 : *opt_str = NULL;
2509 : : }
2510 : 20 : }
2511 : :
2512 : : /* Parse argument of -fpatchable-function-entry option ARG and store
2513 : : corresponding values to PATCH_AREA_SIZE and PATCH_AREA_START.
2514 : : If REPORT_ERROR is set to true, generate error for a problematic
2515 : : option arguments. */
2516 : :
2517 : : void
2518 : 1762114 : parse_and_check_patch_area (const char *arg, bool report_error,
2519 : : HOST_WIDE_INT *patch_area_size,
2520 : : HOST_WIDE_INT *patch_area_start)
2521 : : {
2522 : 1762114 : *patch_area_size = 0;
2523 : 1762114 : *patch_area_start = 0;
2524 : :
2525 : 1762114 : if (arg == NULL)
2526 : : return;
2527 : :
2528 : 115 : char *patch_area_arg = xstrdup (arg);
2529 : 115 : char *comma = strchr (patch_area_arg, ',');
2530 : 115 : if (comma)
2531 : : {
2532 : 52 : *comma = '\0';
2533 : 52 : *patch_area_size = integral_argument (patch_area_arg);
2534 : 52 : *patch_area_start = integral_argument (comma + 1);
2535 : : }
2536 : : else
2537 : 63 : *patch_area_size = integral_argument (patch_area_arg);
2538 : :
2539 : 115 : if (*patch_area_size < 0
2540 : 115 : || *patch_area_size > USHRT_MAX
2541 : 107 : || *patch_area_start < 0
2542 : 107 : || *patch_area_start > USHRT_MAX
2543 : 99 : || *patch_area_size < *patch_area_start)
2544 : 16 : if (report_error)
2545 : 8 : error ("invalid arguments for %<-fpatchable-function-entry%>");
2546 : :
2547 : 115 : free (patch_area_arg);
2548 : : }
2549 : :
2550 : : /* Print options enabled by -fhardened. Keep this in sync with the manual! */
2551 : :
2552 : : static void
2553 : 1 : print_help_hardened ()
2554 : : {
2555 : 1 : printf ("%s\n", "The following options are enabled by -fhardened:");
2556 : : /* Unfortunately, I can't seem to use targetm.fortify_source_default_level
2557 : : here. */
2558 : 1 : printf (" %s\n", "-D_FORTIFY_SOURCE=3 (or =2 for glibc < 2.35)");
2559 : 1 : printf (" %s\n", "-D_GLIBCXX_ASSERTIONS");
2560 : 1 : printf (" %s\n", "-ftrivial-auto-var-init=zero");
2561 : : #ifdef HAVE_LD_PIE
2562 : 1 : printf (" %s %s\n", "-fPIE", "-pie");
2563 : : #endif
2564 : 1 : if (HAVE_LD_NOW_SUPPORT)
2565 : 1 : printf (" %s\n", "-Wl,-z,now");
2566 : 1 : if (HAVE_LD_RELRO_SUPPORT)
2567 : 1 : printf (" %s\n", "-Wl,-z,relro");
2568 : 1 : printf (" %s\n", "-fstack-protector-strong");
2569 : 1 : printf (" %s\n", "-fstack-clash-protection");
2570 : 1 : printf (" %s\n", "-fcf-protection=full");
2571 : 1 : putchar ('\n');
2572 : 1 : }
2573 : :
2574 : : /* Print help when OPT__help_ is set. */
2575 : :
2576 : : void
2577 : 97 : print_help (struct gcc_options *opts, unsigned int lang_mask,
2578 : : const char *help_option_argument)
2579 : : {
2580 : 97 : const char *a = help_option_argument;
2581 : 97 : unsigned int include_flags = 0;
2582 : : /* Note - by default we include undocumented options when listing
2583 : : specific classes. If you only want to see documented options
2584 : : then add ",^undocumented" to the --help= option. E.g.:
2585 : :
2586 : : --help=target,^undocumented */
2587 : 97 : unsigned int exclude_flags = 0;
2588 : :
2589 : 97 : if (lang_mask == CL_DRIVER)
2590 : 0 : return;
2591 : :
2592 : : /* Walk along the argument string, parsing each word in turn.
2593 : : The format is:
2594 : : arg = [^]{word}[,{arg}]
2595 : : word = {optimizers|target|warnings|undocumented|
2596 : : params|common|<language>} */
2597 : 107 : while (*a != 0)
2598 : : {
2599 : 107 : static const struct
2600 : : {
2601 : : const char *string;
2602 : : unsigned int flag;
2603 : : }
2604 : : specifics[] =
2605 : : {
2606 : : { "optimizers", CL_OPTIMIZATION },
2607 : : { "target", CL_TARGET },
2608 : : { "warnings", CL_WARNING },
2609 : : { "undocumented", CL_UNDOCUMENTED },
2610 : : { "params", CL_PARAMS },
2611 : : { "joined", CL_JOINED },
2612 : : { "separate", CL_SEPARATE },
2613 : : { "common", CL_COMMON },
2614 : : { NULL, 0 }
2615 : : };
2616 : 107 : unsigned int *pflags;
2617 : 107 : const char *comma;
2618 : 107 : unsigned int lang_flag, specific_flag;
2619 : 107 : unsigned int len;
2620 : 107 : unsigned int i;
2621 : :
2622 : 107 : if (*a == '^')
2623 : : {
2624 : 8 : ++a;
2625 : 8 : if (*a == '\0')
2626 : : {
2627 : 1 : error ("missing argument to %qs", "--help=^");
2628 : 1 : break;
2629 : : }
2630 : : pflags = &exclude_flags;
2631 : : }
2632 : : else
2633 : : pflags = &include_flags;
2634 : :
2635 : 106 : comma = strchr (a, ',');
2636 : 106 : if (comma == NULL)
2637 : 96 : len = strlen (a);
2638 : : else
2639 : 10 : len = comma - a;
2640 : 106 : if (len == 0)
2641 : : {
2642 : 0 : a = comma + 1;
2643 : 0 : continue;
2644 : : }
2645 : :
2646 : : /* Check to see if the string matches an option class name. */
2647 : 525 : for (i = 0, specific_flag = 0; specifics[i].string != NULL; i++)
2648 : 518 : if (strncasecmp (a, specifics[i].string, len) == 0)
2649 : : {
2650 : 99 : specific_flag = specifics[i].flag;
2651 : 99 : break;
2652 : : }
2653 : :
2654 : : /* Check to see if the string matches a language name.
2655 : : Note - we rely upon the alpha-sorted nature of the entries in
2656 : : the lang_names array, specifically that shorter names appear
2657 : : before their longer variants. (i.e. C before C++). That way
2658 : : when we are attempting to match --help=c for example we will
2659 : : match with C first and not C++. */
2660 : 1611 : for (i = 0, lang_flag = 0; i < cl_lang_count; i++)
2661 : 1513 : if (strncasecmp (a, lang_names[i], len) == 0)
2662 : : {
2663 : 8 : lang_flag = 1U << i;
2664 : 8 : break;
2665 : : }
2666 : :
2667 : 106 : if (specific_flag != 0)
2668 : : {
2669 : 99 : if (lang_flag == 0)
2670 : 97 : *pflags |= specific_flag;
2671 : : else
2672 : : {
2673 : : /* The option's argument matches both the start of a
2674 : : language name and the start of an option class name.
2675 : : We have a special case for when the user has
2676 : : specified "--help=c", but otherwise we have to issue
2677 : : a warning. */
2678 : 2 : if (strncasecmp (a, "c", len) == 0)
2679 : 2 : *pflags |= lang_flag;
2680 : : else
2681 : 0 : warning (0,
2682 : : "%<--help%> argument %q.*s is ambiguous, "
2683 : : "please be more specific",
2684 : : len, a);
2685 : : }
2686 : : }
2687 : 7 : else if (lang_flag != 0)
2688 : 6 : *pflags |= lang_flag;
2689 : 1 : else if (strncasecmp (a, "hardened", len) == 0)
2690 : 1 : print_help_hardened ();
2691 : : else
2692 : 0 : warning (0,
2693 : : "unrecognized argument to %<--help=%> option: %q.*s",
2694 : : len, a);
2695 : :
2696 : 106 : if (comma == NULL)
2697 : : break;
2698 : 10 : a = comma + 1;
2699 : : }
2700 : :
2701 : : /* We started using PerFunction/Optimization for parameters and
2702 : : a warning. We should exclude these from optimization options. */
2703 : 97 : if (include_flags & CL_OPTIMIZATION)
2704 : 7 : exclude_flags |= CL_WARNING;
2705 : 97 : if (!(include_flags & CL_PARAMS))
2706 : 38 : exclude_flags |= CL_PARAMS;
2707 : :
2708 : 97 : if (include_flags)
2709 : 93 : print_specific_help (include_flags, exclude_flags, 0, opts,
2710 : : lang_mask);
2711 : : }
2712 : :
2713 : : /* Handle target- and language-independent options. Return zero to
2714 : : generate an "unknown option" message. Only options that need
2715 : : extra handling need to be listed here; if you simply want
2716 : : DECODED->value assigned to a variable, it happens automatically. */
2717 : :
2718 : : bool
2719 : 81899367 : common_handle_option (struct gcc_options *opts,
2720 : : struct gcc_options *opts_set,
2721 : : const struct cl_decoded_option *decoded,
2722 : : unsigned int lang_mask, int kind ATTRIBUTE_UNUSED,
2723 : : location_t loc,
2724 : : const struct cl_option_handlers *handlers,
2725 : : diagnostics::context *dc,
2726 : : void (*target_option_override_hook) (void))
2727 : : {
2728 : 81899367 : size_t scode = decoded->opt_index;
2729 : 81899367 : const char *arg = decoded->arg;
2730 : 81899367 : HOST_WIDE_INT value = decoded->value;
2731 : 81899367 : enum opt_code code = (enum opt_code) scode;
2732 : :
2733 : 81899367 : gcc_assert (decoded->canonical_option_num_elements <= 2);
2734 : :
2735 : 81899367 : switch (code)
2736 : : {
2737 : 7 : case OPT__help:
2738 : 7 : {
2739 : 7 : unsigned int all_langs_mask = (1U << cl_lang_count) - 1;
2740 : 7 : unsigned int undoc_mask;
2741 : 7 : unsigned int i;
2742 : :
2743 : 7 : if (lang_mask == CL_DRIVER)
2744 : : break;
2745 : :
2746 : 0 : undoc_mask = ((opts->x_verbose_flag | opts->x_extra_warnings)
2747 : 3 : ? 0
2748 : : : CL_UNDOCUMENTED);
2749 : 3 : target_option_override_hook ();
2750 : : /* First display any single language specific options. */
2751 : 51 : for (i = 0; i < cl_lang_count; i++)
2752 : 45 : print_specific_help
2753 : 45 : (1U << i, (all_langs_mask & (~ (1U << i))) | undoc_mask, 0, opts,
2754 : : lang_mask);
2755 : : /* Next display any multi language specific options. */
2756 : 3 : print_specific_help (0, undoc_mask, all_langs_mask, opts, lang_mask);
2757 : : /* Then display any remaining, non-language options. */
2758 : 24 : for (i = CL_MIN_OPTION_CLASS; i <= CL_MAX_OPTION_CLASS; i <<= 1)
2759 : 18 : if (i != CL_DRIVER)
2760 : 15 : print_specific_help (i, undoc_mask, 0, opts, lang_mask);
2761 : 3 : opts->x_exit_after_options = true;
2762 : 3 : break;
2763 : : }
2764 : :
2765 : 0 : case OPT__target_help:
2766 : 0 : if (lang_mask == CL_DRIVER)
2767 : : break;
2768 : :
2769 : 0 : target_option_override_hook ();
2770 : 0 : print_specific_help (CL_TARGET, 0, 0, opts, lang_mask);
2771 : 0 : opts->x_exit_after_options = true;
2772 : 0 : break;
2773 : :
2774 : 194 : case OPT__help_:
2775 : 194 : {
2776 : 194 : help_option_arguments.safe_push (arg);
2777 : 194 : opts->x_exit_after_options = true;
2778 : 194 : break;
2779 : : }
2780 : :
2781 : 78 : case OPT__version:
2782 : 78 : if (lang_mask == CL_DRIVER)
2783 : : break;
2784 : :
2785 : 0 : opts->x_exit_after_options = true;
2786 : 0 : break;
2787 : :
2788 : : case OPT__completion_:
2789 : : break;
2790 : :
2791 : 18170 : case OPT_fsanitize_:
2792 : 18170 : opts_set->x_flag_sanitize = true;
2793 : 18170 : opts->x_flag_sanitize
2794 : 18170 : = parse_sanitizer_options (arg, loc, code,
2795 : : opts->x_flag_sanitize, value, true);
2796 : :
2797 : : /* Kernel ASan implies normal ASan but does not yet support
2798 : : all features. */
2799 : 18170 : if (opts->x_flag_sanitize & SANITIZE_KERNEL_ADDRESS)
2800 : : {
2801 : 366 : SET_OPTION_IF_UNSET (opts, opts_set,
2802 : : param_asan_instrumentation_with_call_threshold,
2803 : : 0);
2804 : 366 : SET_OPTION_IF_UNSET (opts, opts_set, param_asan_globals, 0);
2805 : 366 : SET_OPTION_IF_UNSET (opts, opts_set, param_asan_stack, 0);
2806 : 366 : SET_OPTION_IF_UNSET (opts, opts_set, param_asan_protect_allocas, 0);
2807 : 366 : SET_OPTION_IF_UNSET (opts, opts_set, param_asan_use_after_return, 0);
2808 : : }
2809 : 18170 : if (opts->x_flag_sanitize & SANITIZE_KERNEL_HWADDRESS)
2810 : : {
2811 : 56 : SET_OPTION_IF_UNSET (opts, opts_set,
2812 : : param_hwasan_instrument_stack, 0);
2813 : 56 : SET_OPTION_IF_UNSET (opts, opts_set,
2814 : : param_hwasan_random_frame_tag, 0);
2815 : 56 : SET_OPTION_IF_UNSET (opts, opts_set,
2816 : : param_hwasan_instrument_allocas, 0);
2817 : : }
2818 : : break;
2819 : :
2820 : 1070 : case OPT_fsanitize_recover_:
2821 : 1070 : opts->x_flag_sanitize_recover
2822 : 1070 : = parse_sanitizer_options (arg, loc, code,
2823 : : opts->x_flag_sanitize_recover, value, true);
2824 : 1070 : break;
2825 : :
2826 : 202 : case OPT_fsanitize_trap_:
2827 : 202 : opts->x_flag_sanitize_trap
2828 : 202 : = parse_sanitizer_options (arg, loc, code,
2829 : : opts->x_flag_sanitize_trap, value, true);
2830 : 202 : break;
2831 : :
2832 : : case OPT_fasan_shadow_offset_:
2833 : : /* Deferred. */
2834 : : break;
2835 : :
2836 : 68 : case OPT_fsanitize_address_use_after_scope:
2837 : 68 : opts->x_flag_sanitize_address_use_after_scope = value;
2838 : 68 : break;
2839 : :
2840 : 6 : case OPT_fsanitize_recover:
2841 : 6 : if (value)
2842 : 0 : opts->x_flag_sanitize_recover
2843 : 0 : |= (SANITIZE_UNDEFINED | SANITIZE_UNDEFINED_NONDEFAULT)
2844 : : & ~(SANITIZE_UNREACHABLE | SANITIZE_RETURN);
2845 : : else
2846 : 6 : opts->x_flag_sanitize_recover
2847 : 6 : &= ~(SANITIZE_UNDEFINED | SANITIZE_UNDEFINED_NONDEFAULT);
2848 : : break;
2849 : :
2850 : 236 : case OPT_fsanitize_trap:
2851 : 236 : if (value)
2852 : 236 : opts->x_flag_sanitize_trap
2853 : 236 : |= (SANITIZE_UNDEFINED | SANITIZE_UNDEFINED_NONDEFAULT);
2854 : : else
2855 : 0 : opts->x_flag_sanitize_trap
2856 : 0 : &= ~(SANITIZE_UNDEFINED | SANITIZE_UNDEFINED_NONDEFAULT);
2857 : : break;
2858 : :
2859 : : case OPT_O:
2860 : : case OPT_Os:
2861 : : case OPT_Ofast:
2862 : : case OPT_Og:
2863 : : case OPT_Oz:
2864 : : /* Currently handled in a prescan. */
2865 : : break;
2866 : :
2867 : 100 : case OPT_Wattributes_:
2868 : 100 : if (lang_mask == CL_DRIVER)
2869 : : break;
2870 : :
2871 : 100 : if (value)
2872 : : {
2873 : 0 : error_at (loc, "arguments ignored for %<-Wattributes=%>; use "
2874 : : "%<-Wno-attributes=%> instead");
2875 : 0 : break;
2876 : : }
2877 : 100 : else if (arg[strlen (arg) - 1] == ',')
2878 : : {
2879 : 0 : error_at (loc, "trailing %<,%> in arguments for "
2880 : : "%<-Wno-attributes=%>");
2881 : 0 : break;
2882 : : }
2883 : :
2884 : 100 : add_comma_separated_to_vector (&opts->x_flag_ignored_attributes, arg);
2885 : 100 : break;
2886 : :
2887 : 4403 : case OPT_Werror:
2888 : 4403 : dc->set_warning_as_error_requested (value);
2889 : 4403 : break;
2890 : :
2891 : 7046 : case OPT_Werror_:
2892 : 7046 : if (lang_mask == CL_DRIVER)
2893 : : break;
2894 : :
2895 : 7046 : enable_warning_as_error (arg, value, lang_mask, handlers,
2896 : : opts, opts_set, loc, dc);
2897 : 7046 : break;
2898 : :
2899 : 8 : case OPT_Wfatal_errors:
2900 : 8 : dc->set_fatal_errors (value);
2901 : 8 : break;
2902 : :
2903 : 12 : case OPT_Wstack_usage_:
2904 : 12 : opts->x_flag_stack_usage_info = value != -1;
2905 : 12 : break;
2906 : :
2907 : 57 : case OPT_Wstrict_aliasing:
2908 : 57 : set_Wstrict_aliasing (opts, value);
2909 : 57 : break;
2910 : :
2911 : 15 : case OPT_Wstrict_overflow:
2912 : 30 : opts->x_warn_strict_overflow = (value
2913 : 15 : ? (int) WARN_STRICT_OVERFLOW_CONDITIONAL
2914 : : : 0);
2915 : 15 : break;
2916 : :
2917 : 37 : case OPT_Wsystem_headers:
2918 : 37 : dc->m_warn_system_headers = value;
2919 : 37 : break;
2920 : :
2921 : 0 : case OPT_aux_info:
2922 : 0 : opts->x_flag_gen_aux_info = 1;
2923 : 0 : break;
2924 : :
2925 : 1646 : case OPT_d:
2926 : 1646 : decode_d_option (arg, opts, loc, dc);
2927 : 1646 : break;
2928 : :
2929 : : case OPT_fcall_used_:
2930 : : case OPT_fcall_saved_:
2931 : : /* Deferred. */
2932 : : break;
2933 : :
2934 : : case OPT_fdbg_cnt_:
2935 : : /* Deferred. */
2936 : : break;
2937 : :
2938 : : case OPT_fdebug_prefix_map_:
2939 : : case OPT_ffile_prefix_map_:
2940 : : case OPT_fprofile_prefix_map_:
2941 : : /* Deferred. */
2942 : : break;
2943 : :
2944 : 0 : case OPT_fcanon_prefix_map:
2945 : 0 : flag_canon_prefix_map = value;
2946 : 0 : break;
2947 : :
2948 : 1 : case OPT_fcallgraph_info:
2949 : 1 : opts->x_flag_callgraph_info = CALLGRAPH_INFO_NAKED;
2950 : 1 : break;
2951 : :
2952 : 0 : case OPT_fcallgraph_info_:
2953 : 0 : {
2954 : 0 : char *my_arg, *p;
2955 : 0 : my_arg = xstrdup (arg);
2956 : 0 : p = strtok (my_arg, ",");
2957 : 0 : while (p)
2958 : : {
2959 : 0 : if (strcmp (p, "su") == 0)
2960 : : {
2961 : 0 : opts->x_flag_callgraph_info |= CALLGRAPH_INFO_STACK_USAGE;
2962 : 0 : opts->x_flag_stack_usage_info = true;
2963 : : }
2964 : 0 : else if (strcmp (p, "da") == 0)
2965 : 0 : opts->x_flag_callgraph_info |= CALLGRAPH_INFO_DYNAMIC_ALLOC;
2966 : : else
2967 : : return 0;
2968 : 0 : p = strtok (NULL, ",");
2969 : : }
2970 : 0 : free (my_arg);
2971 : : }
2972 : 0 : break;
2973 : :
2974 : 422 : case OPT_fdiagnostics_show_location_:
2975 : 422 : dc->set_prefixing_rule ((diagnostic_prefixing_rule_t) value);
2976 : 422 : break;
2977 : :
2978 : 270064 : case OPT_fdiagnostics_show_caret:
2979 : 270064 : dc->get_source_printing_options ().enabled = value;
2980 : 270064 : break;
2981 : :
2982 : 270064 : case OPT_fdiagnostics_show_event_links:
2983 : 270064 : dc->get_source_printing_options ().show_event_links_p = value;
2984 : 270064 : break;
2985 : :
2986 : 1 : case OPT_fdiagnostics_show_labels:
2987 : 1 : dc->get_source_printing_options ().show_labels_p = value;
2988 : 1 : break;
2989 : :
2990 : 270064 : case OPT_fdiagnostics_show_line_numbers:
2991 : 270064 : dc->get_source_printing_options ().show_line_numbers_p = value;
2992 : 270064 : break;
2993 : :
2994 : 538411 : case OPT_fdiagnostics_color_:
2995 : 538411 : diagnostic_color_init (dc, value);
2996 : 538411 : break;
2997 : :
2998 : 532434 : case OPT_fdiagnostics_urls_:
2999 : 532434 : diagnostic_urls_init (dc, value);
3000 : 532434 : break;
3001 : :
3002 : 90 : case OPT_fdiagnostics_format_:
3003 : 90 : {
3004 : 90 : const char *basename = (opts->x_dump_base_name ? opts->x_dump_base_name
3005 : : : opts->x_main_input_basename);
3006 : 90 : gcc_assert (dc);
3007 : 90 : diagnostics::output_format_init (*dc,
3008 : : opts->x_main_input_filename, basename,
3009 : : (enum diagnostics_output_format)value,
3010 : 90 : opts->x_flag_diagnostics_json_formatting);
3011 : 90 : break;
3012 : : }
3013 : :
3014 : 33 : case OPT_fdiagnostics_add_output_:
3015 : 33 : handle_OPT_fdiagnostics_add_output_ (*opts, *dc, arg, loc);
3016 : 33 : break;
3017 : :
3018 : 14 : case OPT_fdiagnostics_set_output_:
3019 : 14 : handle_OPT_fdiagnostics_set_output_ (*opts, *dc, arg, loc);
3020 : 14 : break;
3021 : :
3022 : 594225 : case OPT_fdiagnostics_text_art_charset_:
3023 : 594225 : dc->set_text_art_charset ((enum diagnostic_text_art_charset)value);
3024 : 594225 : break;
3025 : :
3026 : 4 : case OPT_fdiagnostics_parseable_fixits:
3027 : 4 : dc->set_extra_output_kind (value
3028 : : ? EXTRA_DIAGNOSTIC_OUTPUT_fixits_v1
3029 : : : EXTRA_DIAGNOSTIC_OUTPUT_none);
3030 : 4 : break;
3031 : :
3032 : 28 : case OPT_fdiagnostics_column_unit_:
3033 : 28 : dc->get_column_options ().m_column_unit
3034 : 28 : = (enum diagnostics_column_unit)value;
3035 : 28 : break;
3036 : :
3037 : 12 : case OPT_fdiagnostics_column_origin_:
3038 : 12 : dc->get_column_options ().m_column_origin = value;
3039 : 12 : break;
3040 : :
3041 : 4 : case OPT_fdiagnostics_escape_format_:
3042 : 4 : dc->set_escape_format ((enum diagnostics_escape_format)value);
3043 : 4 : break;
3044 : :
3045 : 5 : case OPT_fdiagnostics_show_highlight_colors:
3046 : 5 : dc->set_show_highlight_colors (value);
3047 : 5 : break;
3048 : :
3049 : 0 : case OPT_fdiagnostics_show_cwe:
3050 : 0 : dc->set_show_cwe (value);
3051 : 0 : break;
3052 : :
3053 : 0 : case OPT_fdiagnostics_show_rules:
3054 : 0 : dc->set_show_rules (value);
3055 : 0 : break;
3056 : :
3057 : 300594 : case OPT_fdiagnostics_path_format_:
3058 : 300594 : dc->set_path_format ((enum diagnostic_path_format)value);
3059 : 300594 : break;
3060 : :
3061 : 76 : case OPT_fdiagnostics_show_path_depths:
3062 : 76 : dc->set_show_path_depths (value);
3063 : 76 : break;
3064 : :
3065 : 54 : case OPT_fdiagnostics_show_option:
3066 : 54 : dc->set_show_option_requested (value);
3067 : 54 : break;
3068 : :
3069 : 270064 : case OPT_fdiagnostics_show_nesting:
3070 : 270064 : dc->set_show_nesting (value);
3071 : 270064 : break;
3072 : :
3073 : 0 : case OPT_fdiagnostics_show_nesting_locations:
3074 : 0 : dc->set_show_nesting_locations (value);
3075 : 0 : break;
3076 : :
3077 : 0 : case OPT_fdiagnostics_show_nesting_levels:
3078 : 0 : dc->set_show_nesting_levels (value);
3079 : 0 : break;
3080 : :
3081 : 1 : case OPT_fdiagnostics_minimum_margin_width_:
3082 : 1 : dc->get_source_printing_options ().min_margin_width = value;
3083 : 1 : break;
3084 : :
3085 : : case OPT_fdump_:
3086 : : /* Deferred. */
3087 : : break;
3088 : :
3089 : 634692 : case OPT_ffast_math:
3090 : 634692 : set_fast_math_flags (opts, value);
3091 : 634692 : break;
3092 : :
3093 : 366 : case OPT_funsafe_math_optimizations:
3094 : 366 : set_unsafe_math_optimizations_flags (opts, value);
3095 : 366 : break;
3096 : :
3097 : : case OPT_ffixed_:
3098 : : /* Deferred. */
3099 : : break;
3100 : :
3101 : 9 : case OPT_finline_limit_:
3102 : 9 : SET_OPTION_IF_UNSET (opts, opts_set, param_max_inline_insns_single,
3103 : : value / 2);
3104 : 9 : SET_OPTION_IF_UNSET (opts, opts_set, param_max_inline_insns_auto,
3105 : : value / 2);
3106 : : break;
3107 : :
3108 : 1 : case OPT_finstrument_functions_exclude_function_list_:
3109 : 1 : add_comma_separated_to_vector
3110 : 1 : (&opts->x_flag_instrument_functions_exclude_functions, arg);
3111 : 1 : break;
3112 : :
3113 : 1 : case OPT_finstrument_functions_exclude_file_list_:
3114 : 1 : add_comma_separated_to_vector
3115 : 1 : (&opts->x_flag_instrument_functions_exclude_files, arg);
3116 : 1 : break;
3117 : :
3118 : 103163 : case OPT_fmessage_length_:
3119 : 103163 : pp_set_line_maximum_length (dc->get_reference_printer (), value);
3120 : 103163 : dc->set_caret_max_width (value);
3121 : 103163 : break;
3122 : :
3123 : : case OPT_fopt_info:
3124 : : case OPT_fopt_info_:
3125 : : /* Deferred. */
3126 : : break;
3127 : :
3128 : : case OPT_foffload_options_:
3129 : : /* Deferred. */
3130 : : break;
3131 : :
3132 : 0 : case OPT_foffload_abi_:
3133 : 0 : case OPT_foffload_abi_host_opts_:
3134 : : #ifdef ACCEL_COMPILER
3135 : : /* Handled in the 'mkoffload's. */
3136 : : #else
3137 : 0 : error_at (loc,
3138 : : "%qs option can be specified only for offload compiler",
3139 : : (code == OPT_foffload_abi_) ? "-foffload-abi"
3140 : : : "-foffload-abi-host-opts");
3141 : : #endif
3142 : 0 : break;
3143 : :
3144 : 1 : case OPT_fpack_struct_:
3145 : 1 : if (value <= 0 || (value & (value - 1)) || value > 16)
3146 : 0 : error_at (loc,
3147 : : "structure alignment must be a small power of two, not %wu",
3148 : : value);
3149 : : else
3150 : 1 : opts->x_initial_max_fld_align = value;
3151 : : break;
3152 : :
3153 : : case OPT_fplugin_:
3154 : : case OPT_fplugin_arg_:
3155 : : /* Deferred. */
3156 : : break;
3157 : :
3158 : 0 : case OPT_fprofile_use_:
3159 : 0 : opts->x_profile_data_prefix = xstrdup (arg);
3160 : 0 : opts->x_flag_profile_use = true;
3161 : 0 : value = true;
3162 : : /* No break here - do -fprofile-use processing. */
3163 : : /* FALLTHRU */
3164 : 152 : case OPT_fprofile_use:
3165 : 152 : enable_fdo_optimizations (opts, opts_set, value, false);
3166 : 152 : SET_OPTION_IF_UNSET (opts, opts_set, flag_profile_reorder_functions,
3167 : : value);
3168 : : /* Indirect call profiling should do all useful transformations
3169 : : speculative devirtualization does. */
3170 : 152 : if (opts->x_flag_value_profile_transformations)
3171 : 152 : SET_OPTION_IF_UNSET (opts, opts_set, flag_devirtualize_speculatively,
3172 : : false);
3173 : : break;
3174 : :
3175 : 0 : case OPT_fauto_profile_:
3176 : 0 : opts->x_auto_profile_file = xstrdup (arg);
3177 : 0 : opts->x_flag_auto_profile = true;
3178 : 0 : value = true;
3179 : : /* No break here - do -fauto-profile processing. */
3180 : : /* FALLTHRU */
3181 : 0 : case OPT_fauto_profile:
3182 : 0 : enable_fdo_optimizations (opts, opts_set, value, true);
3183 : 0 : SET_OPTION_IF_UNSET (opts, opts_set, flag_profile_correction, value);
3184 : : break;
3185 : :
3186 : 2 : case OPT_fprofile_generate_:
3187 : 2 : opts->x_profile_data_prefix = xstrdup (arg);
3188 : 2 : value = true;
3189 : : /* No break here - do -fprofile-generate processing. */
3190 : : /* FALLTHRU */
3191 : 253 : case OPT_fprofile_generate:
3192 : 253 : SET_OPTION_IF_UNSET (opts, opts_set, profile_arc_flag, value);
3193 : 253 : SET_OPTION_IF_UNSET (opts, opts_set, flag_profile_values, value);
3194 : 253 : SET_OPTION_IF_UNSET (opts, opts_set, flag_inline_functions, value);
3195 : 253 : SET_OPTION_IF_UNSET (opts, opts_set, flag_ipa_bit_cp, value);
3196 : : break;
3197 : :
3198 : 2 : case OPT_fprofile_info_section:
3199 : 2 : opts->x_profile_info_section = ".gcov_info";
3200 : 2 : break;
3201 : :
3202 : 36 : case OPT_fpatchable_function_entry_:
3203 : 36 : {
3204 : 36 : HOST_WIDE_INT patch_area_size, patch_area_start;
3205 : 36 : parse_and_check_patch_area (arg, true, &patch_area_size,
3206 : : &patch_area_start);
3207 : : }
3208 : 36 : break;
3209 : :
3210 : : case OPT_ftree_vectorize:
3211 : : /* Automatically sets -ftree-loop-vectorize and
3212 : : -ftree-slp-vectorize. Nothing more to do here. */
3213 : : break;
3214 : 77 : case OPT_fzero_call_used_regs_:
3215 : 77 : opts->x_flag_zero_call_used_regs
3216 : 77 : = parse_zero_call_used_regs_options (arg);
3217 : 77 : break;
3218 : :
3219 : 13326 : case OPT_fshow_column:
3220 : 13326 : dc->m_show_column = value;
3221 : 13326 : break;
3222 : :
3223 : 0 : case OPT_frandom_seed:
3224 : : /* The real switch is -fno-random-seed. */
3225 : 0 : if (value)
3226 : : return false;
3227 : : /* Deferred. */
3228 : : break;
3229 : :
3230 : : case OPT_frandom_seed_:
3231 : : /* Deferred. */
3232 : : break;
3233 : :
3234 : : case OPT_fsched_verbose_:
3235 : : #ifdef INSN_SCHEDULING
3236 : : /* Handled with Var in common.opt. */
3237 : : break;
3238 : : #else
3239 : : return false;
3240 : : #endif
3241 : :
3242 : 1 : case OPT_fsched_stalled_insns_:
3243 : 1 : opts->x_flag_sched_stalled_insns = value;
3244 : 1 : if (opts->x_flag_sched_stalled_insns == 0)
3245 : 1 : opts->x_flag_sched_stalled_insns = -1;
3246 : : break;
3247 : :
3248 : 0 : case OPT_fsched_stalled_insns_dep_:
3249 : 0 : opts->x_flag_sched_stalled_insns_dep = value;
3250 : 0 : break;
3251 : :
3252 : 67 : case OPT_fstack_check_:
3253 : 67 : if (!strcmp (arg, "no"))
3254 : 0 : opts->x_flag_stack_check = NO_STACK_CHECK;
3255 : 67 : else if (!strcmp (arg, "generic"))
3256 : : /* This is the old stack checking method. */
3257 : 34 : opts->x_flag_stack_check = STACK_CHECK_BUILTIN
3258 : : ? FULL_BUILTIN_STACK_CHECK
3259 : : : GENERIC_STACK_CHECK;
3260 : 33 : else if (!strcmp (arg, "specific"))
3261 : : /* This is the new stack checking method. */
3262 : 33 : opts->x_flag_stack_check = STACK_CHECK_BUILTIN
3263 : : ? FULL_BUILTIN_STACK_CHECK
3264 : : : STACK_CHECK_STATIC_BUILTIN
3265 : : ? STATIC_BUILTIN_STACK_CHECK
3266 : : : GENERIC_STACK_CHECK;
3267 : : else
3268 : 0 : warning_at (loc, 0, "unknown stack check parameter %qs", arg);
3269 : : break;
3270 : :
3271 : 1 : case OPT_fstack_limit:
3272 : : /* The real switch is -fno-stack-limit. */
3273 : 1 : if (value)
3274 : : return false;
3275 : : /* Deferred. */
3276 : : break;
3277 : :
3278 : : case OPT_fstack_limit_register_:
3279 : : case OPT_fstack_limit_symbol_:
3280 : : /* Deferred. */
3281 : : break;
3282 : :
3283 : 558 : case OPT_fstack_usage:
3284 : 558 : opts->x_flag_stack_usage = value;
3285 : 558 : opts->x_flag_stack_usage_info = value != 0;
3286 : 558 : break;
3287 : :
3288 : 128313 : case OPT_g:
3289 : 128313 : set_debug_level (NO_DEBUG, DEFAULT_GDB_EXTENSIONS, arg, opts, opts_set,
3290 : : loc);
3291 : 128313 : break;
3292 : :
3293 : 0 : case OPT_gcodeview:
3294 : 0 : set_debug_level (CODEVIEW_DEBUG, false, arg, opts, opts_set, loc);
3295 : 0 : if (opts->x_debug_info_level < DINFO_LEVEL_NORMAL)
3296 : 0 : opts->x_debug_info_level = DINFO_LEVEL_NORMAL;
3297 : : break;
3298 : :
3299 : 216 : case OPT_gbtf:
3300 : 216 : set_debug_level (BTF_DEBUG, false, arg, opts, opts_set, loc);
3301 : : /* set the debug level to level 2, but if already at level 3,
3302 : : don't lower it. */
3303 : 216 : if (opts->x_debug_info_level < DINFO_LEVEL_NORMAL)
3304 : 216 : opts->x_debug_info_level = DINFO_LEVEL_NORMAL;
3305 : : break;
3306 : :
3307 : 691 : case OPT_gctf:
3308 : 691 : set_debug_level (CTF_DEBUG, false, arg, opts, opts_set, loc);
3309 : : /* CTF generation feeds off DWARF dies. For optimal CTF, switch debug
3310 : : info level to 2. If off or at level 1, set it to level 2, but if
3311 : : already at level 3, don't lower it. */
3312 : 691 : if (opts->x_debug_info_level < DINFO_LEVEL_NORMAL
3313 : 685 : && opts->x_ctf_debug_info_level > CTFINFO_LEVEL_NONE)
3314 : 683 : opts->x_debug_info_level = DINFO_LEVEL_NORMAL;
3315 : : break;
3316 : :
3317 : 305 : case OPT_gdwarf:
3318 : 305 : if (arg && strlen (arg) != 0)
3319 : : {
3320 : 0 : error_at (loc, "%<-gdwarf%s%> is ambiguous; "
3321 : : "use %<-gdwarf-%s%> for DWARF version "
3322 : : "or %<-gdwarf%> %<-g%s%> for debug level", arg, arg, arg);
3323 : 0 : break;
3324 : : }
3325 : : else
3326 : 305 : value = opts->x_dwarf_version;
3327 : :
3328 : : /* FALLTHRU */
3329 : 4859 : case OPT_gdwarf_:
3330 : 4859 : if (value < 2 || value > 5)
3331 : 0 : error_at (loc, "dwarf version %wu is not supported", value);
3332 : : else
3333 : 4859 : opts->x_dwarf_version = value;
3334 : 4859 : set_debug_level (DWARF2_DEBUG, false, "", opts, opts_set, loc);
3335 : 4859 : break;
3336 : :
3337 : 20 : case OPT_ggdb:
3338 : 20 : set_debug_level (NO_DEBUG, 2, arg, opts, opts_set, loc);
3339 : 20 : break;
3340 : :
3341 : 0 : case OPT_gvms:
3342 : 0 : set_debug_level (VMS_DEBUG, false, arg, opts, opts_set, loc);
3343 : 0 : break;
3344 : :
3345 : : case OPT_gz:
3346 : : case OPT_gz_:
3347 : : /* Handled completely via specs. */
3348 : : break;
3349 : :
3350 : 63741 : case OPT_pedantic_errors:
3351 : 63741 : dc->m_pedantic_errors = 1;
3352 : 63741 : control_warning_option (OPT_Wpedantic,
3353 : : static_cast<int> (diagnostics::kind::error),
3354 : : NULL, value,
3355 : : loc, lang_mask,
3356 : : handlers, opts, opts_set,
3357 : : dc);
3358 : 63741 : break;
3359 : :
3360 : 25394 : case OPT_flto:
3361 : 25394 : opts->x_flag_lto = value ? "" : NULL;
3362 : 25394 : break;
3363 : :
3364 : 13 : case OPT_flto_:
3365 : 13 : if (strcmp (arg, "none") != 0
3366 : 13 : && strcmp (arg, "jobserver") != 0
3367 : 13 : && strcmp (arg, "auto") != 0
3368 : 1 : && atoi (arg) == 0)
3369 : 1 : error_at (loc,
3370 : : "unrecognized argument to %<-flto=%> option: %qs", arg);
3371 : : break;
3372 : :
3373 : 43686 : case OPT_w:
3374 : 43686 : dc->m_inhibit_warnings = true;
3375 : 43686 : break;
3376 : :
3377 : 44 : case OPT_fmax_errors_:
3378 : 44 : dc->set_max_errors (value);
3379 : 44 : break;
3380 : :
3381 : : case OPT_fuse_ld_bfd:
3382 : : case OPT_fuse_ld_gold:
3383 : : case OPT_fuse_ld_lld:
3384 : : case OPT_fuse_ld_mold:
3385 : : case OPT_fuse_ld_wild:
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 : 481 : case OPT_fwrapv:
3391 : 481 : if (value)
3392 : 475 : 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 : 633746 : case OPT_fipa_icf:
3408 : 633746 : opts->x_flag_ipa_icf_functions = value;
3409 : 633746 : opts->x_flag_ipa_icf_variables = value;
3410 : 633746 : 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 : 75850989 : default:
3451 : : /* If the flag was handled in a standard way, assume the lack of
3452 : : processing here is intentional. */
3453 : 75850989 : gcc_assert (option_flag_var (scode, opts));
3454 : : break;
3455 : : }
3456 : :
3457 : 81899366 : common_handle_option_auto (opts, opts_set, decoded, lang_mask, kind,
3458 : : loc, handlers, dc);
3459 : 81899366 : 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 : 634692 : set_fast_math_flags (struct gcc_options *opts, int set)
3482 : : {
3483 : 634692 : if (!opts->frontend_set_flag_unsafe_math_optimizations)
3484 : : {
3485 : 634692 : opts->x_flag_unsafe_math_optimizations = set;
3486 : 634692 : set_unsafe_math_optimizations_flags (opts, set);
3487 : : }
3488 : 634692 : if (!opts->frontend_set_flag_finite_math_only)
3489 : 634692 : opts->x_flag_finite_math_only = set;
3490 : 634692 : if (!opts->frontend_set_flag_errno_math)
3491 : 583777 : opts->x_flag_errno_math = !set;
3492 : 634692 : if (set)
3493 : : {
3494 : 1985 : if (opts->frontend_set_flag_excess_precision == EXCESS_PRECISION_DEFAULT)
3495 : 1985 : opts->x_flag_excess_precision
3496 : 1985 : = set ? EXCESS_PRECISION_FAST : EXCESS_PRECISION_DEFAULT;
3497 : 1985 : if (!opts->frontend_set_flag_signaling_nans)
3498 : 1985 : opts->x_flag_signaling_nans = 0;
3499 : 1985 : if (!opts->frontend_set_flag_rounding_math)
3500 : 1985 : opts->x_flag_rounding_math = 0;
3501 : 1985 : if (!opts->frontend_set_flag_complex_method)
3502 : 1985 : opts->x_flag_complex_method = 0;
3503 : : }
3504 : 634692 : }
3505 : :
3506 : : /* When -funsafe-math-optimizations is set the following
3507 : : flags are set as well. */
3508 : : static void
3509 : 635058 : set_unsafe_math_optimizations_flags (struct gcc_options *opts, int set)
3510 : : {
3511 : 635058 : if (!opts->frontend_set_flag_trapping_math)
3512 : 635058 : opts->x_flag_trapping_math = !set;
3513 : 635058 : if (!opts->frontend_set_flag_signed_zeros)
3514 : 635058 : opts->x_flag_signed_zeros = !set;
3515 : 635058 : if (!opts->frontend_set_flag_associative_math)
3516 : 603768 : opts->x_flag_associative_math = set;
3517 : 635058 : if (!opts->frontend_set_flag_reciprocal_math)
3518 : 635058 : opts->x_flag_reciprocal_math = set;
3519 : 635058 : }
3520 : :
3521 : : /* Return true iff flags in OPTS are set as if -ffast-math. */
3522 : : bool
3523 : 47237650 : fast_math_flags_set_p (const struct gcc_options *opts)
3524 : : {
3525 : 47237650 : return (!opts->x_flag_trapping_math
3526 : 947780 : && opts->x_flag_unsafe_math_optimizations
3527 : 940592 : && opts->x_flag_finite_math_only
3528 : 940528 : && !opts->x_flag_signed_zeros
3529 : 940514 : && !opts->x_flag_errno_math
3530 : 48178160 : && 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 : 134099 : 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 : 134099 : if (dinfo == NO_DEBUG)
3555 : : {
3556 : 128333 : if (opts->x_write_symbols == NO_DEBUG)
3557 : : {
3558 : 111915 : opts->x_write_symbols = PREFERRED_DEBUGGING_TYPE;
3559 : :
3560 : 111915 : if (extended == 2)
3561 : : {
3562 : : #if defined DWARF2_DEBUGGING_INFO || defined DWARF2_LINENO_DEBUGGING_INFO
3563 : 111915 : if (opts->x_write_symbols & CTF_DEBUG)
3564 : : opts->x_write_symbols |= DWARF2_DEBUG;
3565 : : else
3566 : 111915 : opts->x_write_symbols = DWARF2_DEBUG;
3567 : : #endif
3568 : : }
3569 : :
3570 : 111915 : if (opts->x_write_symbols == NO_DEBUG)
3571 : : warning_at (loc, 0, "target system does not support debug output");
3572 : : }
3573 : 16418 : else if ((opts->x_write_symbols & CTF_DEBUG)
3574 : 16384 : || (opts->x_write_symbols & BTF_DEBUG)
3575 : 16384 : || (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 : 5766 : if (((dinfo == DWARF2_DEBUG) || (dinfo == CTF_DEBUG))
3586 : 5550 : && ((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 : 5644 : else if (((dinfo == DWARF2_DEBUG) || (dinfo == BTF_DEBUG))
3595 : 4959 : && ((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 : 5644 : 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 : 5644 : opts->x_write_symbols = dinfo;
3614 : 5644 : opts_set->x_write_symbols = dinfo;
3615 : : }
3616 : : }
3617 : :
3618 : 134099 : 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 : 133883 : if (*arg == '\0')
3624 : : {
3625 : 128500 : if (dinfo == CTF_DEBUG)
3626 : 689 : opts->x_ctf_debug_info_level = CTFINFO_LEVEL_NORMAL;
3627 : 127811 : else if (opts->x_debug_info_level < DINFO_LEVEL_NORMAL)
3628 : 113891 : opts->x_debug_info_level = DINFO_LEVEL_NORMAL;
3629 : : }
3630 : : else
3631 : : {
3632 : 5383 : int argval = integral_argument (arg);
3633 : 5383 : if (argval == -1)
3634 : 0 : error_at (loc, "unrecognized debug output level %qs", arg);
3635 : 5383 : else if (argval > 3)
3636 : 0 : error_at (loc, "debug output level %qs is too high", arg);
3637 : : else
3638 : : {
3639 : 5383 : if (dinfo == CTF_DEBUG)
3640 : 2 : opts->x_ctf_debug_info_level
3641 : 2 : = (enum ctf_debug_info_levels) argval;
3642 : : else
3643 : 5381 : opts->x_debug_info_level = (enum debug_info_levels) argval;
3644 : : }
3645 : : }
3646 : : }
3647 : 216 : else if (*arg != '\0')
3648 : 0 : error_at (loc, "unrecognized btf debug output level %qs", arg);
3649 : 134099 : }
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 : 1646 : decode_d_option (const char *arg, struct gcc_options *opts,
3680 : : location_t loc, diagnostics::context *dc)
3681 : : {
3682 : 1646 : int c;
3683 : :
3684 : 3292 : while (*arg)
3685 : 1646 : switch (c = *arg++)
3686 : : {
3687 : 699 : case 'A':
3688 : 699 : opts->x_flag_debug_asm = 1;
3689 : 699 : 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 : 1646 : }
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 : 7046 : 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 : 7046 : char *new_option;
3732 : 7046 : int option_index;
3733 : :
3734 : 7046 : new_option = XNEWVEC (char, strlen (arg) + 2);
3735 : 7046 : new_option[0] = 'W';
3736 : 7046 : strcpy (new_option + 1, arg);
3737 : 7046 : option_index = find_opt (new_option, lang_mask);
3738 : 7046 : 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 : 7044 : 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 : 1106 : const enum diagnostics::kind kind = (value
3756 : 7039 : ? diagnostics::kind::error
3757 : : : diagnostics::kind::warning);
3758 : 7039 : const char *arg = NULL;
3759 : :
3760 : 7039 : if (cl_options[option_index].flags & CL_JOINED)
3761 : 17 : arg = new_option + cl_options[option_index].opt_len;
3762 : 7039 : control_warning_option (option_index, (int) kind, arg, value,
3763 : : loc, lang_mask,
3764 : : handlers, opts, opts_set, dc);
3765 : : }
3766 : 7046 : free (new_option);
3767 : 7046 : }
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 : 1540213 : 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 : 1540213 : if (option_id.m_idx)
3781 : : {
3782 : : /* A warning classified as an error. */
3783 : 93325 : if ((orig_diag_kind == diagnostics::kind::warning
3784 : 93325 : || orig_diag_kind == diagnostics::kind::pedwarn)
3785 : 78548 : && diag_kind == diagnostics::kind::error)
3786 : 211 : return concat (cl_options[OPT_Werror_].opt_text,
3787 : : /* Skip over "-W". */
3788 : 211 : cl_options[option_id.m_idx].opt_text + 2,
3789 : 211 : NULL);
3790 : : /* A warning with option. */
3791 : : else
3792 : 93114 : return xstrdup (cl_options[option_id.m_idx].opt_text);
3793 : : }
3794 : : /* A warning without option classified as an error. */
3795 : 1446888 : else if ((orig_diag_kind == diagnostics::kind::warning
3796 : 1446888 : || orig_diag_kind == diagnostics::kind::pedwarn
3797 : 1416768 : || diag_kind == diagnostics::kind::warning)
3798 : 1446888 : && 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 : 12173 : get_option_html_page (int option_index)
3808 : : {
3809 : 12173 : const cl_option *cl_opt = &cl_options[option_index];
3810 : :
3811 : : #ifdef CL_Fortran
3812 : 12173 : 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 : 89 : && (cl_opt->flags & CL_C) == 0
3816 : : #ifdef CL_CXX
3817 : 80 : && (cl_opt->flags & CL_CXX) == 0
3818 : : #endif
3819 : : )
3820 : 80 : 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 : 26459 : get_option_url_suffix (int option_index, unsigned lang_mask)
3830 : : {
3831 : 26459 : if (const char *url = get_opt_url_suffix (option_index, lang_mask))
3832 : :
3833 : 14286 : 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 : 12173 : if (const char *html_page = get_option_html_page (option_index))
3838 : 80 : 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 : 80 : cl_options[option_index].opt_text,
3845 : 80 : NULL));
3846 : :
3847 : 12093 : 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 : 122 : gcc_diagnostic_option_id_manager::
3855 : : make_option_url (diagnostics::option_id option_id) const
3856 : : {
3857 : 122 : if (option_id.m_idx)
3858 : : {
3859 : 122 : label_text url_suffix = get_option_url_suffix (option_id.m_idx,
3860 : 122 : m_lang_mask);
3861 : 122 : if (url_suffix.get ())
3862 : 122 : return concat (DOCUMENTATION_ROOT_URL, url_suffix.get (), nullptr);
3863 : 122 : }
3864 : :
3865 : : return nullptr;
3866 : : }
3867 : :
3868 : : /* Return a heap allocated producer with command line options. */
3869 : :
3870 : : char *
3871 : 53423 : gen_command_line_string (cl_decoded_option *options,
3872 : : unsigned int options_count)
3873 : : {
3874 : 53423 : auto_vec<const char *> switches;
3875 : 53423 : char *options_string, *tail;
3876 : 53423 : const char *p;
3877 : 53423 : size_t len = 0;
3878 : :
3879 : 1854057 : for (unsigned i = 0; i < options_count; i++)
3880 : 1800634 : switch (options[i].opt_index)
3881 : : {
3882 : 809851 : case OPT_o:
3883 : 809851 : case OPT_d:
3884 : 809851 : case OPT_dumpbase:
3885 : 809851 : case OPT_dumpbase_ext:
3886 : 809851 : case OPT_dumpdir:
3887 : 809851 : case OPT_quiet:
3888 : 809851 : case OPT_version:
3889 : 809851 : case OPT_v:
3890 : 809851 : case OPT_w:
3891 : 809851 : case OPT_L:
3892 : 809851 : case OPT_I:
3893 : 809851 : case OPT_SPECIAL_unknown:
3894 : 809851 : case OPT_SPECIAL_ignore:
3895 : 809851 : case OPT_SPECIAL_warn_removed:
3896 : 809851 : case OPT_SPECIAL_program_name:
3897 : 809851 : case OPT_SPECIAL_input_file:
3898 : 809851 : case OPT_grecord_gcc_switches:
3899 : 809851 : case OPT_frecord_gcc_switches:
3900 : 809851 : case OPT__output_pch:
3901 : 809851 : case OPT_fdiagnostics_show_highlight_colors:
3902 : 809851 : case OPT_fdiagnostics_show_location_:
3903 : 809851 : case OPT_fdiagnostics_show_option:
3904 : 809851 : case OPT_fdiagnostics_show_caret:
3905 : 809851 : case OPT_fdiagnostics_show_event_links:
3906 : 809851 : case OPT_fdiagnostics_show_labels:
3907 : 809851 : case OPT_fdiagnostics_show_line_numbers:
3908 : 809851 : case OPT_fdiagnostics_color_:
3909 : 809851 : case OPT_fdiagnostics_format_:
3910 : 809851 : case OPT_fdiagnostics_show_nesting:
3911 : 809851 : case OPT_fdiagnostics_show_nesting_locations:
3912 : 809851 : case OPT_fdiagnostics_show_nesting_levels:
3913 : 809851 : case OPT_fverbose_asm:
3914 : 809851 : case OPT____:
3915 : 809851 : case OPT__sysroot_:
3916 : 809851 : case OPT_nostdinc:
3917 : 809851 : case OPT_nostdinc__:
3918 : 809851 : case OPT_fpreprocessed:
3919 : 809851 : case OPT_fltrans_output_list_:
3920 : 809851 : case OPT_fresolution_:
3921 : 809851 : case OPT_fdebug_prefix_map_:
3922 : 809851 : case OPT_fmacro_prefix_map_:
3923 : 809851 : case OPT_ffile_prefix_map_:
3924 : 809851 : case OPT_fprofile_prefix_map_:
3925 : 809851 : case OPT_fcanon_prefix_map:
3926 : 809851 : case OPT_fcompare_debug:
3927 : 809851 : case OPT_fchecking:
3928 : 809851 : case OPT_fchecking_:
3929 : : /* Ignore these. */
3930 : 809851 : continue;
3931 : 68336 : case OPT_D:
3932 : 68336 : case OPT_U:
3933 : 68336 : if (startswith (options[i].arg, "_FORTIFY_SOURCE")
3934 : 68336 : && (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 : 68336 : 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 : 922447 : default:
3951 : 923217 : if (cl_options[options[i].opt_index].flags
3952 : 922447 : & CL_NO_DWARF_RECORD)
3953 : 770 : continue;
3954 : 921677 : gcc_checking_assert (options[i].canonical_option[0][0] == '-');
3955 : 921677 : switch (options[i].canonical_option[0][1])
3956 : : {
3957 : 276336 : case 'M':
3958 : 276336 : case 'i':
3959 : 276336 : case 'W':
3960 : 276336 : continue;
3961 : 364764 : case 'f':
3962 : 364764 : if (strncmp (options[i].canonical_option[0] + 2,
3963 : : "dump", 4) == 0)
3964 : 1763 : continue;
3965 : : break;
3966 : : default:
3967 : : break;
3968 : : }
3969 : 643578 : switches.safe_push (options[i].orig_option_with_args_text);
3970 : 643578 : len += strlen (options[i].orig_option_with_args_text) + 1;
3971 : 643578 : break;
3972 : 878187 : }
3973 : :
3974 : 53423 : options_string = XNEWVEC (char, len + 1);
3975 : 53423 : tail = options_string;
3976 : :
3977 : 53423 : unsigned i;
3978 : 750424 : FOR_EACH_VEC_ELT (switches, i, p)
3979 : : {
3980 : 643578 : len = strlen (p);
3981 : 643578 : memcpy (tail, p, len);
3982 : 643578 : tail += len;
3983 : 643578 : if (i != switches.length () - 1)
3984 : : {
3985 : 590155 : *tail = ' ';
3986 : 590155 : ++tail;
3987 : : }
3988 : : }
3989 : :
3990 : 53423 : *tail = '\0';
3991 : 53423 : return options_string;
3992 : 53423 : }
3993 : :
3994 : : /* Return a heap allocated producer string including command line options. */
3995 : :
3996 : : char *
3997 : 53412 : gen_producer_string (const char *language_string, cl_decoded_option *options,
3998 : : unsigned int options_count)
3999 : : {
4000 : 53412 : char *cmdline = gen_command_line_string (options, options_count);
4001 : 53412 : char *combined = concat (language_string, " ", version_string, " ",
4002 : : cmdline, NULL);
4003 : 53412 : free (cmdline);
4004 : 53412 : 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 : 9864 : for (unsigned i = 0; i < cl_options_count; ++i)
4049 : 9860 : 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 */
|