]>
Commit | Line | Data |
---|---|---|
2772ef3e | 1 | /* Command line option handling. |
a5544970 | 2 | Copyright (C) 2002-2019 Free Software Foundation, Inc. |
2772ef3e NB |
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 | |
9dcd6f09 | 9 | Software Foundation; either version 3, or (at your option) any later |
2772ef3e NB |
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 | |
9dcd6f09 NC |
18 | along with GCC; see the file COPYING3. If not see |
19 | <http://www.gnu.org/licenses/>. */ | |
2772ef3e NB |
20 | |
21 | #include "config.h" | |
22 | #include "system.h" | |
cf03fd63 | 23 | #include "intl.h" |
2772ef3e | 24 | #include "coretypes.h" |
7d5a5747 | 25 | #include "opts.h" |
903f5c23 | 26 | #include "tm.h" |
d7b42618 | 27 | #include "flags.h" |
903caebf | 28 | #include "params.h" |
de32c0cb | 29 | #include "diagnostic.h" |
5f0f4a3b | 30 | #include "opts-diagnostic.h" |
88a00ef7 | 31 | #include "insn-attr-common.h" |
677f3fa8 | 32 | #include "common/common-target.h" |
19ff0049 | 33 | #include "spellcheck.h" |
5bcc5a3b | 34 | #include "opt-suggestions.h" |
fa5baeed | 35 | #include "diagnostic-color.h" |
2772ef3e | 36 | |
65d4f2cd MLI |
37 | static void set_Wstrict_aliasing (struct gcc_options *opts, int onoff); |
38 | ||
a7d0d30f JM |
39 | /* Indexed by enum debug_info_type. */ |
40 | const char *const debug_type_names[] = | |
41 | { | |
180295ed | 42 | "none", "stabs", "dwarf-2", "xcoff", "vms" |
a7d0d30f JM |
43 | }; |
44 | ||
39ef6592 LC |
45 | /* Parse the -femit-struct-debug-detailed option value |
46 | and set the flag variables. */ | |
47 | ||
48 | #define MATCH( prefix, string ) \ | |
49 | ((strncmp (prefix, string, sizeof prefix - 1) == 0) \ | |
50 | ? ((string += sizeof prefix - 1), 1) : 0) | |
51 | ||
52 | void | |
299404a1 JM |
53 | set_struct_debug_option (struct gcc_options *opts, location_t loc, |
54 | const char *spec) | |
39ef6592 LC |
55 | { |
56 | /* various labels for comparison */ | |
0576d21f JM |
57 | static const char dfn_lbl[] = "dfn:", dir_lbl[] = "dir:", ind_lbl[] = "ind:"; |
58 | static const char ord_lbl[] = "ord:", gen_lbl[] = "gen:"; | |
59 | static const char none_lbl[] = "none", any_lbl[] = "any"; | |
60 | static const char base_lbl[] = "base", sys_lbl[] = "sys"; | |
39ef6592 LC |
61 | |
62 | enum debug_struct_file files = DINFO_STRUCT_FILE_ANY; | |
63 | /* Default is to apply to as much as possible. */ | |
64 | enum debug_info_usage usage = DINFO_USAGE_NUM_ENUMS; | |
65 | int ord = 1, gen = 1; | |
66 | ||
67 | /* What usage? */ | |
68 | if (MATCH (dfn_lbl, spec)) | |
69 | usage = DINFO_USAGE_DFN; | |
70 | else if (MATCH (dir_lbl, spec)) | |
71 | usage = DINFO_USAGE_DIR_USE; | |
72 | else if (MATCH (ind_lbl, spec)) | |
73 | usage = DINFO_USAGE_IND_USE; | |
74 | ||
75 | /* Generics or not? */ | |
76 | if (MATCH (ord_lbl, spec)) | |
77 | gen = 0; | |
78 | else if (MATCH (gen_lbl, spec)) | |
79 | ord = 0; | |
80 | ||
81 | /* What allowable environment? */ | |
82 | if (MATCH (none_lbl, spec)) | |
83 | files = DINFO_STRUCT_FILE_NONE; | |
84 | else if (MATCH (any_lbl, spec)) | |
85 | files = DINFO_STRUCT_FILE_ANY; | |
86 | else if (MATCH (sys_lbl, spec)) | |
87 | files = DINFO_STRUCT_FILE_SYS; | |
88 | else if (MATCH (base_lbl, spec)) | |
89 | files = DINFO_STRUCT_FILE_BASE; | |
90 | else | |
299404a1 JM |
91 | error_at (loc, |
92 | "argument %qs to %<-femit-struct-debug-detailed%> " | |
93 | "not recognized", | |
94 | spec); | |
39ef6592 LC |
95 | |
96 | /* Effect the specification. */ | |
97 | if (usage == DINFO_USAGE_NUM_ENUMS) | |
98 | { | |
99 | if (ord) | |
100 | { | |
69ccdddb JM |
101 | opts->x_debug_struct_ordinary[DINFO_USAGE_DFN] = files; |
102 | opts->x_debug_struct_ordinary[DINFO_USAGE_DIR_USE] = files; | |
103 | opts->x_debug_struct_ordinary[DINFO_USAGE_IND_USE] = files; | |
39ef6592 LC |
104 | } |
105 | if (gen) | |
106 | { | |
69ccdddb JM |
107 | opts->x_debug_struct_generic[DINFO_USAGE_DFN] = files; |
108 | opts->x_debug_struct_generic[DINFO_USAGE_DIR_USE] = files; | |
109 | opts->x_debug_struct_generic[DINFO_USAGE_IND_USE] = files; | |
39ef6592 LC |
110 | } |
111 | } | |
112 | else | |
113 | { | |
114 | if (ord) | |
69ccdddb | 115 | opts->x_debug_struct_ordinary[usage] = files; |
39ef6592 | 116 | if (gen) |
69ccdddb | 117 | opts->x_debug_struct_generic[usage] = files; |
39ef6592 LC |
118 | } |
119 | ||
120 | if (*spec == ',') | |
299404a1 | 121 | set_struct_debug_option (opts, loc, spec+1); |
39ef6592 LC |
122 | else |
123 | { | |
124 | /* No more -femit-struct-debug-detailed specifications. | |
125 | Do final checks. */ | |
126 | if (*spec != '\0') | |
299404a1 JM |
127 | error_at (loc, |
128 | "argument %qs to %<-femit-struct-debug-detailed%> unknown", | |
129 | spec); | |
69ccdddb JM |
130 | if (opts->x_debug_struct_ordinary[DINFO_USAGE_DIR_USE] |
131 | < opts->x_debug_struct_ordinary[DINFO_USAGE_IND_USE] | |
132 | || opts->x_debug_struct_generic[DINFO_USAGE_DIR_USE] | |
133 | < opts->x_debug_struct_generic[DINFO_USAGE_IND_USE]) | |
299404a1 JM |
134 | error_at (loc, |
135 | "%<-femit-struct-debug-detailed=dir:...%> must allow " | |
136 | "at least as much as " | |
137 | "%<-femit-struct-debug-detailed=ind:...%>"); | |
39ef6592 LC |
138 | } |
139 | } | |
140 | ||
c98cd5bf JM |
141 | /* Strip off a legitimate source ending from the input string NAME of |
142 | length LEN. Rather than having to know the names used by all of | |
143 | our front ends, we strip off an ending of a period followed by | |
ed5cd5bc | 144 | up to fource characters. (C++ uses ".cpp".) */ |
c98cd5bf JM |
145 | |
146 | void | |
147 | strip_off_ending (char *name, int len) | |
148 | { | |
149 | int i; | |
ed5cd5bc | 150 | for (i = 2; i < 5 && len > i; i++) |
c98cd5bf JM |
151 | { |
152 | if (name[len - i] == '.') | |
153 | { | |
154 | name[len - i] = '\0'; | |
155 | break; | |
156 | } | |
157 | } | |
158 | } | |
159 | ||
39ef6592 LC |
160 | /* Find the base name of a path, stripping off both directories and |
161 | a single final extension. */ | |
69ccdddb | 162 | int |
39ef6592 LC |
163 | base_of_path (const char *path, const char **base_out) |
164 | { | |
165 | const char *base = path; | |
166 | const char *dot = 0; | |
167 | const char *p = path; | |
168 | char c = *p; | |
169 | while (c) | |
170 | { | |
c3284718 | 171 | if (IS_DIR_SEPARATOR (c)) |
39ef6592 LC |
172 | { |
173 | base = p + 1; | |
174 | dot = 0; | |
175 | } | |
176 | else if (c == '.') | |
177 | dot = p; | |
178 | c = *++p; | |
179 | } | |
180 | if (!dot) | |
181 | dot = p; | |
182 | *base_out = base; | |
183 | return dot - base; | |
184 | } | |
185 | ||
2cc98056 | 186 | /* What to print when a switch has no documentation. */ |
a7b2e184 MS |
187 | static const char undocumented_msg[] = N_("This option lacks documentation."); |
188 | static const char use_diagnosed_msg[] = N_("Uses of this option are diagnosed."); | |
2cc98056 | 189 | |
8d5a7d1f | 190 | typedef char *char_p; /* For DEF_VEC_P. */ |
8d5a7d1f | 191 | |
48476d13 | 192 | static void handle_param (struct gcc_options *opts, |
299404a1 JM |
193 | struct gcc_options *opts_set, location_t loc, |
194 | const char *carg); | |
df38ffef | 195 | static void set_debug_level (enum debug_info_type type, int extended, |
0576d21f | 196 | const char *arg, struct gcc_options *opts, |
299404a1 JM |
197 | struct gcc_options *opts_set, |
198 | location_t loc); | |
d5478783 | 199 | static void set_fast_math_flags (struct gcc_options *opts, int set); |
299404a1 JM |
200 | static void decode_d_option (const char *arg, struct gcc_options *opts, |
201 | location_t loc, diagnostic_context *dc); | |
d5478783 JM |
202 | static void set_unsafe_math_optimizations_flags (struct gcc_options *opts, |
203 | int set); | |
a4d8c676 JM |
204 | static void enable_warning_as_error (const char *arg, int value, |
205 | unsigned int lang_mask, | |
206 | const struct cl_option_handlers *handlers, | |
c5fa0890 JM |
207 | struct gcc_options *opts, |
208 | struct gcc_options *opts_set, | |
a4d8c676 JM |
209 | location_t loc, |
210 | diagnostic_context *dc); | |
2772ef3e | 211 | |
5f20c657 JM |
212 | /* Handle a back-end option; arguments and return value as for |
213 | handle_option. */ | |
2772ef3e | 214 | |
c98cd5bf | 215 | bool |
46625112 | 216 | target_handle_option (struct gcc_options *opts, |
d4d24ba4 | 217 | struct gcc_options *opts_set, |
46625112 | 218 | const struct cl_decoded_option *decoded, |
481e1176 | 219 | unsigned int lang_mask ATTRIBUTE_UNUSED, int kind, |
96e45421 | 220 | location_t loc, |
d5478783 | 221 | const struct cl_option_handlers *handlers ATTRIBUTE_UNUSED, |
130fcab0 | 222 | diagnostic_context *dc, void (*) (void)) |
5f20c657 | 223 | { |
d5478783 | 224 | gcc_assert (dc == global_dc); |
5f20c657 | 225 | gcc_assert (kind == DK_UNSPECIFIED); |
677f3fa8 | 226 | return targetm_common.handle_option (opts, opts_set, decoded, loc); |
2772ef3e | 227 | } |
d7b42618 | 228 | |
1ebc7e68 | 229 | /* Add comma-separated strings to a char_p vector. */ |
8d5a7d1f ILT |
230 | |
231 | static void | |
6a1f6c9c | 232 | add_comma_separated_to_vector (void **pvec, const char *arg) |
8d5a7d1f ILT |
233 | { |
234 | char *tmp; | |
235 | char *r; | |
236 | char *w; | |
237 | char *token_start; | |
9771b263 DN |
238 | vec<char_p> *v = (vec<char_p> *) *pvec; |
239 | ||
240 | vec_check_alloc (v, 1); | |
8d5a7d1f ILT |
241 | |
242 | /* We never free this string. */ | |
243 | tmp = xstrdup (arg); | |
244 | ||
245 | r = tmp; | |
246 | w = tmp; | |
247 | token_start = tmp; | |
248 | ||
249 | while (*r != '\0') | |
250 | { | |
251 | if (*r == ',') | |
252 | { | |
253 | *w++ = '\0'; | |
254 | ++r; | |
9771b263 | 255 | v->safe_push (token_start); |
8d5a7d1f ILT |
256 | token_start = w; |
257 | } | |
258 | if (*r == '\\' && r[1] == ',') | |
259 | { | |
260 | *w++ = ','; | |
261 | r += 2; | |
262 | } | |
263 | else | |
264 | *w++ = *r++; | |
265 | } | |
efab3e3a OB |
266 | |
267 | *w = '\0'; | |
8d5a7d1f | 268 | if (*token_start != '\0') |
9771b263 | 269 | v->safe_push (token_start); |
8d5a7d1f | 270 | |
9771b263 | 271 | *pvec = v; |
8d5a7d1f ILT |
272 | } |
273 | ||
d6874f56 | 274 | /* Initialize opts_obstack. */ |
de5672fc ML |
275 | |
276 | void | |
277 | init_opts_obstack (void) | |
278 | { | |
d6874f56 | 279 | gcc_obstack_init (&opts_obstack); |
de5672fc ML |
280 | } |
281 | ||
a75bfaa6 JM |
282 | /* Initialize OPTS and OPTS_SET before using them in parsing options. */ |
283 | ||
284 | void | |
285 | init_options_struct (struct gcc_options *opts, struct gcc_options *opts_set) | |
286 | { | |
48476d13 JM |
287 | size_t num_params = get_num_compiler_params (); |
288 | ||
d6874f56 DM |
289 | /* Ensure that opts_obstack has already been initialized by the time |
290 | that we initialize any gcc_options instances (PR jit/68446). */ | |
291 | gcc_assert (opts_obstack.chunk_size > 0); | |
dc357798 | 292 | |
a75bfaa6 | 293 | *opts = global_options_init; |
bf7b5747 ST |
294 | |
295 | if (opts_set) | |
296 | memset (opts_set, 0, sizeof (*opts_set)); | |
a75bfaa6 | 297 | |
48476d13 | 298 | opts->x_param_values = XNEWVEC (int, num_params); |
bf7b5747 ST |
299 | |
300 | if (opts_set) | |
301 | opts_set->x_param_values = XCNEWVEC (int, num_params); | |
302 | ||
48476d13 JM |
303 | init_param_values (opts->x_param_values); |
304 | ||
a75bfaa6 JM |
305 | /* Initialize whether `char' is signed. */ |
306 | opts->x_flag_signed_char = DEFAULT_SIGNED_CHAR; | |
307 | /* Set this to a special "uninitialized" value. The actual default | |
308 | is set after target options have been processed. */ | |
309 | opts->x_flag_short_enums = 2; | |
310 | ||
677f3fa8 | 311 | /* Initialize target_flags before default_options_optimization |
a75bfaa6 | 312 | so the latter can modify it. */ |
677f3fa8 | 313 | opts->x_target_flags = targetm_common.default_target_flags; |
a75bfaa6 JM |
314 | |
315 | /* Some targets have ABI-specified unwind tables. */ | |
677f3fa8 | 316 | opts->x_flag_unwind_tables = targetm_common.unwind_tables_default; |
7e4aae92 JM |
317 | |
318 | /* Some targets have other target-specific initialization. */ | |
677f3fa8 | 319 | targetm_common.option_init_struct (opts); |
a75bfaa6 JM |
320 | } |
321 | ||
0ef443cf DM |
322 | /* Release any allocations owned by OPTS. */ |
323 | ||
324 | void | |
325 | finalize_options_struct (struct gcc_options *opts) | |
326 | { | |
327 | XDELETEVEC (opts->x_param_values); | |
328 | } | |
329 | ||
3020190e | 330 | /* If indicated by the optimization level LEVEL (-Os if SIZE is set, |
bf7a7185 RG |
331 | -Ofast if FAST is set, -Og if DEBUG is set), apply the option DEFAULT_OPT |
332 | to OPTS and OPTS_SET, diagnostic context DC, location LOC, with language | |
333 | mask LANG_MASK and option handlers HANDLERS. */ | |
3020190e JM |
334 | |
335 | static void | |
336 | maybe_default_option (struct gcc_options *opts, | |
337 | struct gcc_options *opts_set, | |
338 | const struct default_options *default_opt, | |
bf7a7185 | 339 | int level, bool size, bool fast, bool debug, |
3020190e JM |
340 | unsigned int lang_mask, |
341 | const struct cl_option_handlers *handlers, | |
a4d8c676 | 342 | location_t loc, |
3020190e JM |
343 | diagnostic_context *dc) |
344 | { | |
345 | const struct cl_option *option = &cl_options[default_opt->opt_index]; | |
346 | bool enabled; | |
347 | ||
348 | if (size) | |
349 | gcc_assert (level == 2); | |
350 | if (fast) | |
351 | gcc_assert (level == 3); | |
bf7a7185 RG |
352 | if (debug) |
353 | gcc_assert (level == 1); | |
3020190e JM |
354 | |
355 | switch (default_opt->levels) | |
356 | { | |
357 | case OPT_LEVELS_ALL: | |
358 | enabled = true; | |
359 | break; | |
360 | ||
361 | case OPT_LEVELS_0_ONLY: | |
362 | enabled = (level == 0); | |
363 | break; | |
364 | ||
365 | case OPT_LEVELS_1_PLUS: | |
366 | enabled = (level >= 1); | |
367 | break; | |
368 | ||
369 | case OPT_LEVELS_1_PLUS_SPEED_ONLY: | |
bf7a7185 RG |
370 | enabled = (level >= 1 && !size && !debug); |
371 | break; | |
372 | ||
373 | case OPT_LEVELS_1_PLUS_NOT_DEBUG: | |
374 | enabled = (level >= 1 && !debug); | |
3020190e JM |
375 | break; |
376 | ||
377 | case OPT_LEVELS_2_PLUS: | |
378 | enabled = (level >= 2); | |
379 | break; | |
380 | ||
381 | case OPT_LEVELS_2_PLUS_SPEED_ONLY: | |
bf7a7185 | 382 | enabled = (level >= 2 && !size && !debug); |
3020190e JM |
383 | break; |
384 | ||
385 | case OPT_LEVELS_3_PLUS: | |
386 | enabled = (level >= 3); | |
387 | break; | |
388 | ||
389 | case OPT_LEVELS_3_PLUS_AND_SIZE: | |
390 | enabled = (level >= 3 || size); | |
391 | break; | |
392 | ||
393 | case OPT_LEVELS_SIZE: | |
394 | enabled = size; | |
395 | break; | |
396 | ||
397 | case OPT_LEVELS_FAST: | |
398 | enabled = fast; | |
399 | break; | |
400 | ||
401 | case OPT_LEVELS_NONE: | |
402 | default: | |
403 | gcc_unreachable (); | |
404 | } | |
405 | ||
406 | if (enabled) | |
407 | handle_generated_option (opts, opts_set, default_opt->opt_index, | |
408 | default_opt->arg, default_opt->value, | |
a4d8c676 | 409 | lang_mask, DK_UNSPECIFIED, loc, |
b9822443 | 410 | handlers, true, dc); |
3020190e | 411 | else if (default_opt->arg == NULL |
300d83d9 | 412 | && !option->cl_reject_negative) |
3020190e JM |
413 | handle_generated_option (opts, opts_set, default_opt->opt_index, |
414 | default_opt->arg, !default_opt->value, | |
a4d8c676 | 415 | lang_mask, DK_UNSPECIFIED, loc, |
b9822443 | 416 | handlers, true, dc); |
3020190e JM |
417 | } |
418 | ||
419 | /* As indicated by the optimization level LEVEL (-Os if SIZE is set, | |
420 | -Ofast if FAST is set), apply the options in array DEFAULT_OPTS to | |
a4d8c676 JM |
421 | OPTS and OPTS_SET, diagnostic context DC, location LOC, with |
422 | language mask LANG_MASK and option handlers HANDLERS. */ | |
3020190e JM |
423 | |
424 | static void | |
425 | maybe_default_options (struct gcc_options *opts, | |
426 | struct gcc_options *opts_set, | |
427 | const struct default_options *default_opts, | |
bf7a7185 | 428 | int level, bool size, bool fast, bool debug, |
3020190e JM |
429 | unsigned int lang_mask, |
430 | const struct cl_option_handlers *handlers, | |
a4d8c676 | 431 | location_t loc, |
3020190e JM |
432 | diagnostic_context *dc) |
433 | { | |
434 | size_t i; | |
435 | ||
436 | for (i = 0; default_opts[i].levels != OPT_LEVELS_NONE; i++) | |
437 | maybe_default_option (opts, opts_set, &default_opts[i], | |
bf7a7185 RG |
438 | level, size, fast, debug, |
439 | lang_mask, handlers, loc, dc); | |
3020190e JM |
440 | } |
441 | ||
ded7b411 SL |
442 | /* Table of options enabled by default at different levels. |
443 | Please keep this list sorted by level and alphabetized within | |
444 | each level; this makes it easier to keep the documentation | |
445 | in sync. */ | |
3020190e JM |
446 | |
447 | static const struct default_options default_options_table[] = | |
448 | { | |
ded7b411 SL |
449 | /* -O1 and -Og optimizations. */ |
450 | { OPT_LEVELS_1_PLUS, OPT_fcombine_stack_adjustments, NULL, 1 }, | |
451 | { OPT_LEVELS_1_PLUS, OPT_fcompare_elim, NULL, 1 }, | |
3020190e | 452 | { OPT_LEVELS_1_PLUS, OPT_fcprop_registers, NULL, 1 }, |
ded7b411 | 453 | { OPT_LEVELS_1_PLUS, OPT_fdefer_pop, NULL, 1 }, |
3020190e | 454 | { OPT_LEVELS_1_PLUS, OPT_fforward_propagate, NULL, 1 }, |
ded7b411 SL |
455 | { OPT_LEVELS_1_PLUS, OPT_fguess_branch_probability, NULL, 1 }, |
456 | { OPT_LEVELS_1_PLUS, OPT_fipa_profile, NULL, 1 }, | |
3020190e JM |
457 | { OPT_LEVELS_1_PLUS, OPT_fipa_pure_const, NULL, 1 }, |
458 | { OPT_LEVELS_1_PLUS, OPT_fipa_reference, NULL, 1 }, | |
2e14744f | 459 | { OPT_LEVELS_1_PLUS, OPT_fipa_reference_addressable, NULL, 1 }, |
3020190e | 460 | { OPT_LEVELS_1_PLUS, OPT_fmerge_constants, NULL, 1 }, |
ded7b411 | 461 | { OPT_LEVELS_1_PLUS, OPT_fomit_frame_pointer, NULL, 1 }, |
59faab7c | 462 | { OPT_LEVELS_1_PLUS, OPT_freorder_blocks, NULL, 1 }, |
484db665 | 463 | { OPT_LEVELS_1_PLUS, OPT_fshrink_wrap, NULL, 1 }, |
3020190e | 464 | { OPT_LEVELS_1_PLUS, OPT_fsplit_wide_types, NULL, 1 }, |
ded7b411 | 465 | { OPT_LEVELS_1_PLUS, OPT_ftree_builtin_call_dce, NULL, 1 }, |
3020190e | 466 | { OPT_LEVELS_1_PLUS, OPT_ftree_ccp, NULL, 1 }, |
ded7b411 | 467 | { OPT_LEVELS_1_PLUS, OPT_ftree_ch, NULL, 1 }, |
1f9ceff1 | 468 | { OPT_LEVELS_1_PLUS, OPT_ftree_coalesce_vars, NULL, 1 }, |
ded7b411 | 469 | { OPT_LEVELS_1_PLUS, OPT_ftree_copy_prop, NULL, 1 }, |
3020190e JM |
470 | { OPT_LEVELS_1_PLUS, OPT_ftree_dce, NULL, 1 }, |
471 | { OPT_LEVELS_1_PLUS, OPT_ftree_dominator_opts, NULL, 1 }, | |
3020190e | 472 | { OPT_LEVELS_1_PLUS, OPT_ftree_fre, NULL, 1 }, |
3020190e | 473 | { OPT_LEVELS_1_PLUS, OPT_ftree_sink, NULL, 1 }, |
75cfe445 | 474 | { OPT_LEVELS_1_PLUS, OPT_ftree_slsr, NULL, 1 }, |
ded7b411 SL |
475 | { OPT_LEVELS_1_PLUS, OPT_ftree_ter, NULL, 1 }, |
476 | ||
477 | /* -O1 (and not -Og) optimizations. */ | |
14379e66 | 478 | { OPT_LEVELS_1_PLUS_NOT_DEBUG, OPT_fbranch_count_reg, NULL, 1 }, |
ded7b411 SL |
479 | #if DELAY_SLOTS |
480 | { OPT_LEVELS_1_PLUS_NOT_DEBUG, OPT_fdelayed_branch, NULL, 1 }, | |
481 | #endif | |
c0fe6bce | 482 | { OPT_LEVELS_1_PLUS_NOT_DEBUG, OPT_fdse, NULL, 1 }, |
ded7b411 SL |
483 | { OPT_LEVELS_1_PLUS_NOT_DEBUG, OPT_fif_conversion, NULL, 1 }, |
484 | { OPT_LEVELS_1_PLUS_NOT_DEBUG, OPT_fif_conversion2, NULL, 1 }, | |
485 | { OPT_LEVELS_1_PLUS_NOT_DEBUG, OPT_finline_functions_called_once, NULL, 1 }, | |
14379e66 | 486 | { OPT_LEVELS_1_PLUS_NOT_DEBUG, OPT_fmove_loop_invariants, NULL, 1 }, |
68f6df73 | 487 | { OPT_LEVELS_1_PLUS_NOT_DEBUG, OPT_fssa_phiopt, NULL, 1 }, |
ded7b411 | 488 | { OPT_LEVELS_1_PLUS_NOT_DEBUG, OPT_ftree_bit_ccp, NULL, 1 }, |
c0fe6bce | 489 | { OPT_LEVELS_1_PLUS_NOT_DEBUG, OPT_ftree_dse, NULL, 1 }, |
ded7b411 | 490 | { OPT_LEVELS_1_PLUS_NOT_DEBUG, OPT_ftree_pta, NULL, 1 }, |
c0fe6bce | 491 | { OPT_LEVELS_1_PLUS_NOT_DEBUG, OPT_ftree_sra, NULL, 1 }, |
3020190e | 492 | |
ded7b411 SL |
493 | /* -O2 and -Os optimizations. */ |
494 | { OPT_LEVELS_2_PLUS, OPT_fcaller_saves, NULL, 1 }, | |
495 | { OPT_LEVELS_2_PLUS, OPT_fcode_hoisting, NULL, 1 }, | |
3020190e | 496 | { OPT_LEVELS_2_PLUS, OPT_fcrossjumping, NULL, 1 }, |
3020190e | 497 | { OPT_LEVELS_2_PLUS, OPT_fcse_follow_jumps, NULL, 1 }, |
ded7b411 SL |
498 | { OPT_LEVELS_2_PLUS, OPT_fdevirtualize, NULL, 1 }, |
499 | { OPT_LEVELS_2_PLUS, OPT_fdevirtualize_speculatively, NULL, 1 }, | |
3020190e | 500 | { OPT_LEVELS_2_PLUS, OPT_fexpensive_optimizations, NULL, 1 }, |
c29c92c7 | 501 | { OPT_LEVELS_2_PLUS, OPT_ffinite_loops, NULL, 1 }, |
ded7b411 SL |
502 | { OPT_LEVELS_2_PLUS, OPT_fgcse, NULL, 1 }, |
503 | { OPT_LEVELS_2_PLUS, OPT_fhoist_adjacent_loads, NULL, 1 }, | |
504 | { OPT_LEVELS_2_PLUS, OPT_findirect_inlining, NULL, 1 }, | |
505 | { OPT_LEVELS_2_PLUS, OPT_finline_small_functions, NULL, 1 }, | |
506 | { OPT_LEVELS_2_PLUS, OPT_fipa_bit_cp, NULL, 1 }, | |
507 | { OPT_LEVELS_2_PLUS, OPT_fipa_cp, NULL, 1 }, | |
508 | { OPT_LEVELS_2_PLUS, OPT_fipa_icf, NULL, 1 }, | |
509 | { OPT_LEVELS_2_PLUS, OPT_fipa_ra, NULL, 1 }, | |
510 | { OPT_LEVELS_2_PLUS, OPT_fipa_sra, NULL, 1 }, | |
511 | { OPT_LEVELS_2_PLUS, OPT_fipa_vrp, NULL, 1 }, | |
512 | { OPT_LEVELS_2_PLUS, OPT_fisolate_erroneous_paths_dereference, NULL, 1 }, | |
513 | { OPT_LEVELS_2_PLUS, OPT_flra_remat, NULL, 1 }, | |
514 | { OPT_LEVELS_2_PLUS, OPT_foptimize_sibling_calls, NULL, 1 }, | |
515 | { OPT_LEVELS_2_PLUS, OPT_fpartial_inlining, NULL, 1 }, | |
3020190e | 516 | { OPT_LEVELS_2_PLUS, OPT_fpeephole2, NULL, 1 }, |
ded7b411 SL |
517 | { OPT_LEVELS_2_PLUS, OPT_freorder_functions, NULL, 1 }, |
518 | { OPT_LEVELS_2_PLUS, OPT_frerun_cse_after_loop, NULL, 1 }, | |
3020190e | 519 | #ifdef INSN_SCHEDULING |
3020190e JM |
520 | { OPT_LEVELS_2_PLUS, OPT_fschedule_insns2, NULL, 1 }, |
521 | #endif | |
3020190e | 522 | { OPT_LEVELS_2_PLUS, OPT_fstrict_aliasing, NULL, 1 }, |
ded7b411 SL |
523 | { OPT_LEVELS_2_PLUS, OPT_fstore_merging, NULL, 1 }, |
524 | { OPT_LEVELS_2_PLUS, OPT_fthread_jumps, NULL, 1 }, | |
3020190e JM |
525 | { OPT_LEVELS_2_PLUS, OPT_ftree_pre, NULL, 1 }, |
526 | { OPT_LEVELS_2_PLUS, OPT_ftree_switch_conversion, NULL, 1 }, | |
c9e93168 | 527 | { OPT_LEVELS_2_PLUS, OPT_ftree_tail_merge, NULL, 1 }, |
ded7b411 | 528 | { OPT_LEVELS_2_PLUS, OPT_ftree_vrp, NULL, 1 }, |
d6d11272 | 529 | { OPT_LEVELS_2_PLUS, OPT_fvect_cost_model_, NULL, VECT_COST_MODEL_CHEAP }, |
562d1e95 | 530 | { OPT_LEVELS_2_PLUS, OPT_finline_functions, NULL, 1 }, |
ded7b411 SL |
531 | |
532 | /* -O2 and -Os optimizations. */ | |
533 | { OPT_LEVELS_2_PLUS_SPEED_ONLY, OPT_falign_functions, NULL, 1 }, | |
534 | { OPT_LEVELS_2_PLUS_SPEED_ONLY, OPT_falign_jumps, NULL, 1 }, | |
535 | { OPT_LEVELS_2_PLUS_SPEED_ONLY, OPT_falign_labels, NULL, 1 }, | |
536 | { OPT_LEVELS_2_PLUS_SPEED_ONLY, OPT_falign_loops, NULL, 1 }, | |
d8878031 | 537 | { OPT_LEVELS_2_PLUS_SPEED_ONLY, OPT_foptimize_strlen, NULL, 1 }, |
ded7b411 SL |
538 | { OPT_LEVELS_2_PLUS_SPEED_ONLY, OPT_freorder_blocks_algorithm_, NULL, |
539 | REORDER_BLOCKS_ALGORITHM_STC }, | |
540 | #ifdef INSN_SCHEDULING | |
541 | /* Only run the pre-regalloc scheduling pass if optimizing for speed. */ | |
542 | { OPT_LEVELS_2_PLUS_SPEED_ONLY, OPT_fschedule_insns, NULL, 1 }, | |
543 | #endif | |
3020190e | 544 | |
ded7b411 | 545 | /* -O3 and -Os optimizations. */ |
ded7b411 SL |
546 | |
547 | /* -O3 optimizations. */ | |
3020190e | 548 | { OPT_LEVELS_3_PLUS, OPT_fgcse_after_reload, NULL, 1 }, |
ded7b411 SL |
549 | { OPT_LEVELS_3_PLUS, OPT_fipa_cp_clone, NULL, 1 }, |
550 | { OPT_LEVELS_3_PLUS, OPT_floop_interchange, NULL, 1 }, | |
551 | { OPT_LEVELS_3_PLUS, OPT_floop_unroll_and_jam, NULL, 1 }, | |
552 | { OPT_LEVELS_3_PLUS, OPT_fpeel_loops, NULL, 1 }, | |
553 | { OPT_LEVELS_3_PLUS, OPT_fpredictive_commoning, NULL, 1 }, | |
554 | { OPT_LEVELS_3_PLUS, OPT_fsplit_loops, NULL, 1 }, | |
555 | { OPT_LEVELS_3_PLUS, OPT_fsplit_paths, NULL, 1 }, | |
5879ab5f | 556 | { OPT_LEVELS_2_PLUS, OPT_ftree_loop_distribute_patterns, NULL, 1 }, |
ded7b411 | 557 | { OPT_LEVELS_3_PLUS, OPT_ftree_loop_distribution, NULL, 1 }, |
ea0f3e87 | 558 | { OPT_LEVELS_3_PLUS, OPT_ftree_loop_vectorize, NULL, 1 }, |
ded7b411 | 559 | { OPT_LEVELS_3_PLUS, OPT_ftree_partial_pre, NULL, 1 }, |
ea0f3e87 | 560 | { OPT_LEVELS_3_PLUS, OPT_ftree_slp_vectorize, NULL, 1 }, |
ded7b411 | 561 | { OPT_LEVELS_3_PLUS, OPT_funswitch_loops, NULL, 1 }, |
d6d11272 | 562 | { OPT_LEVELS_3_PLUS, OPT_fvect_cost_model_, NULL, VECT_COST_MODEL_DYNAMIC }, |
13e08dc9 | 563 | { OPT_LEVELS_3_PLUS, OPT_fversion_loops_for_strides, NULL, 1 }, |
3020190e JM |
564 | |
565 | /* -Ofast adds optimizations to -O3. */ | |
566 | { OPT_LEVELS_FAST, OPT_ffast_math, NULL, 1 }, | |
e622a32d | 567 | { OPT_LEVELS_FAST, OPT_fallow_store_data_races, NULL, 1 }, |
3020190e JM |
568 | |
569 | { OPT_LEVELS_NONE, 0, NULL, 0 } | |
570 | }; | |
571 | ||
a75bfaa6 JM |
572 | /* Default the options in OPTS and OPTS_SET based on the optimization |
573 | settings in DECODED_OPTIONS and DECODED_OPTIONS_COUNT. */ | |
c98cd5bf | 574 | void |
a75bfaa6 JM |
575 | default_options_optimization (struct gcc_options *opts, |
576 | struct gcc_options *opts_set, | |
577 | struct cl_decoded_option *decoded_options, | |
3020190e | 578 | unsigned int decoded_options_count, |
a4d8c676 | 579 | location_t loc, |
3020190e JM |
580 | unsigned int lang_mask, |
581 | const struct cl_option_handlers *handlers, | |
582 | diagnostic_context *dc) | |
a75bfaa6 JM |
583 | { |
584 | unsigned int i; | |
ab442df7 | 585 | int opt2; |
597a8ab9 | 586 | bool openacc_mode = false; |
9756310a NB |
587 | |
588 | /* Scan to see what optimization level has been specified. That will | |
589 | determine the default value of many flags. */ | |
a75bfaa6 | 590 | for (i = 1; i < decoded_options_count; i++) |
9756310a | 591 | { |
a75bfaa6 | 592 | struct cl_decoded_option *opt = &decoded_options[i]; |
6e2f1956 | 593 | switch (opt->opt_index) |
9756310a | 594 | { |
6e2f1956 JM |
595 | case OPT_O: |
596 | if (*opt->arg == '\0') | |
be6d3f0e | 597 | { |
3020190e JM |
598 | opts->x_optimize = 1; |
599 | opts->x_optimize_size = 0; | |
0a8134ca | 600 | opts->x_optimize_fast = 0; |
bf7a7185 | 601 | opts->x_optimize_debug = 0; |
9756310a NB |
602 | } |
603 | else | |
604 | { | |
6e2f1956 JM |
605 | const int optimize_val = integral_argument (opt->arg); |
606 | if (optimize_val == -1) | |
33879b9f MP |
607 | error_at (loc, "argument to %<-O%> should be a non-negative " |
608 | "integer, %<g%>, %<s%> or %<fast%>"); | |
6e2f1956 | 609 | else |
9756310a | 610 | { |
3020190e JM |
611 | opts->x_optimize = optimize_val; |
612 | if ((unsigned int) opts->x_optimize > 255) | |
613 | opts->x_optimize = 255; | |
614 | opts->x_optimize_size = 0; | |
0a8134ca | 615 | opts->x_optimize_fast = 0; |
bf7a7185 | 616 | opts->x_optimize_debug = 0; |
9756310a NB |
617 | } |
618 | } | |
6e2f1956 JM |
619 | break; |
620 | ||
621 | case OPT_Os: | |
3020190e | 622 | opts->x_optimize_size = 1; |
6e2f1956 JM |
623 | |
624 | /* Optimizing for size forces optimize to be 2. */ | |
3020190e | 625 | opts->x_optimize = 2; |
0a8134ca | 626 | opts->x_optimize_fast = 0; |
bf7a7185 | 627 | opts->x_optimize_debug = 0; |
6e2f1956 JM |
628 | break; |
629 | ||
630 | case OPT_Ofast: | |
631 | /* -Ofast only adds flags to -O3. */ | |
3020190e JM |
632 | opts->x_optimize_size = 0; |
633 | opts->x_optimize = 3; | |
0a8134ca | 634 | opts->x_optimize_fast = 1; |
bf7a7185 RG |
635 | opts->x_optimize_debug = 0; |
636 | break; | |
637 | ||
638 | case OPT_Og: | |
639 | /* -Og selects optimization level 1. */ | |
640 | opts->x_optimize_size = 0; | |
641 | opts->x_optimize = 1; | |
642 | opts->x_optimize_fast = 0; | |
643 | opts->x_optimize_debug = 1; | |
6e2f1956 JM |
644 | break; |
645 | ||
597a8ab9 TV |
646 | case OPT_fopenacc: |
647 | if (opt->value) | |
648 | openacc_mode = true; | |
649 | break; | |
650 | ||
6e2f1956 JM |
651 | default: |
652 | /* Ignore other options in this prescan. */ | |
653 | break; | |
9756310a NB |
654 | } |
655 | } | |
b8698a0f | 656 | |
3020190e JM |
657 | maybe_default_options (opts, opts_set, default_options_table, |
658 | opts->x_optimize, opts->x_optimize_size, | |
bf7a7185 RG |
659 | opts->x_optimize_fast, opts->x_optimize_debug, |
660 | lang_mask, handlers, loc, dc); | |
3020190e JM |
661 | |
662 | /* -O2 param settings. */ | |
663 | opt2 = (opts->x_optimize >= 2); | |
116cb604 | 664 | |
597a8ab9 TV |
665 | if (openacc_mode |
666 | && !opts_set->x_flag_ipa_pta) | |
667 | opts->x_flag_ipa_pta = true; | |
668 | ||
ab442df7 | 669 | /* Track fields in field-sensitive alias analysis. */ |
028d4092 ML |
670 | if (opt2) |
671 | SET_OPTION_IF_UNSET (opts, opts_set, param_max_fields_for_field_sensitive, | |
672 | 100); | |
e9e0aa2c | 673 | |
3020190e JM |
674 | if (opts->x_optimize_size) |
675 | /* We want to crossjump as much as possible. */ | |
028d4092 | 676 | SET_OPTION_IF_UNSET (opts, opts_set, param_min_crossjump_insns, 1); |
f736cb3e | 677 | |
b30e733a RB |
678 | /* Restrict the amount of work combine does at -Og while retaining |
679 | most of its useful transforms. */ | |
680 | if (opts->x_optimize_debug) | |
028d4092 | 681 | SET_OPTION_IF_UNSET (opts, opts_set, param_max_combine_insns, 2); |
b30e733a | 682 | |
a75bfaa6 | 683 | /* Allow default optimizations to be specified on a per-machine basis. */ |
3020190e | 684 | maybe_default_options (opts, opts_set, |
677f3fa8 | 685 | targetm_common.option_optimization_table, |
3020190e | 686 | opts->x_optimize, opts->x_optimize_size, |
bf7a7185 RG |
687 | opts->x_optimize_fast, opts->x_optimize_debug, |
688 | lang_mask, handlers, loc, dc); | |
a75bfaa6 JM |
689 | } |
690 | ||
6fd6a2ff QZ |
691 | /* Control IPA optimizations based on different live patching LEVEL. */ |
692 | static void | |
693 | control_options_for_live_patching (struct gcc_options *opts, | |
694 | struct gcc_options *opts_set, | |
695 | enum live_patching_level level, | |
696 | location_t loc) | |
697 | { | |
698 | gcc_assert (level > LIVE_PATCHING_NONE); | |
699 | ||
700 | switch (level) | |
701 | { | |
702 | case LIVE_PATCHING_INLINE_ONLY_STATIC: | |
703 | if (opts_set->x_flag_ipa_cp_clone && opts->x_flag_ipa_cp_clone) | |
704 | error_at (loc, | |
705 | "%<-fipa-cp-clone%> is incompatible with " | |
706 | "%<-flive-patching=inline-only-static%>"); | |
707 | else | |
708 | opts->x_flag_ipa_cp_clone = 0; | |
709 | ||
710 | if (opts_set->x_flag_ipa_sra && opts->x_flag_ipa_sra) | |
711 | error_at (loc, | |
712 | "%<-fipa-sra%> is incompatible with " | |
713 | "%<-flive-patching=inline-only-static%>"); | |
714 | else | |
715 | opts->x_flag_ipa_sra = 0; | |
716 | ||
717 | if (opts_set->x_flag_partial_inlining && opts->x_flag_partial_inlining) | |
718 | error_at (loc, | |
719 | "%<-fpartial-inlining%> is incompatible with " | |
720 | "%<-flive-patching=inline-only-static%>"); | |
721 | else | |
722 | opts->x_flag_partial_inlining = 0; | |
723 | ||
724 | if (opts_set->x_flag_ipa_cp && opts->x_flag_ipa_cp) | |
725 | error_at (loc, | |
726 | "%<-fipa-cp%> is incompatible with " | |
727 | "%<-flive-patching=inline-only-static%>"); | |
728 | else | |
729 | opts->x_flag_ipa_cp = 0; | |
730 | ||
731 | /* FALLTHROUGH. */ | |
732 | case LIVE_PATCHING_INLINE_CLONE: | |
733 | /* live patching should disable whole-program optimization. */ | |
734 | if (opts_set->x_flag_whole_program && opts->x_flag_whole_program) | |
735 | error_at (loc, | |
736 | "%<-fwhole-program%> is incompatible with " | |
737 | "%<-flive-patching=inline-only-static|inline-clone%>"); | |
738 | else | |
739 | opts->x_flag_whole_program = 0; | |
740 | ||
741 | /* visibility change should be excluded by !flag_whole_program | |
742 | && !in_lto_p && !flag_ipa_cp_clone && !flag_ipa_sra | |
743 | && !flag_partial_inlining. */ | |
744 | ||
745 | if (opts_set->x_flag_ipa_pta && opts->x_flag_ipa_pta) | |
746 | error_at (loc, | |
747 | "%<-fipa-pta%> is incompatible with " | |
748 | "%<-flive-patching=inline-only-static|inline-clone%>"); | |
749 | else | |
750 | opts->x_flag_ipa_pta = 0; | |
751 | ||
752 | if (opts_set->x_flag_ipa_reference && opts->x_flag_ipa_reference) | |
753 | error_at (loc, | |
754 | "%<-fipa-reference%> is incompatible with " | |
755 | "%<-flive-patching=inline-only-static|inline-clone%>"); | |
756 | else | |
757 | opts->x_flag_ipa_reference = 0; | |
758 | ||
759 | if (opts_set->x_flag_ipa_ra && opts->x_flag_ipa_ra) | |
760 | error_at (loc, | |
761 | "%<-fipa-ra%> is incompatible with " | |
762 | "%<-flive-patching=inline-only-static|inline-clone%>"); | |
763 | else | |
764 | opts->x_flag_ipa_ra = 0; | |
765 | ||
766 | if (opts_set->x_flag_ipa_icf && opts->x_flag_ipa_icf) | |
767 | error_at (loc, | |
768 | "%<-fipa-icf%> is incompatible with " | |
769 | "%<-flive-patching=inline-only-static|inline-clone%>"); | |
770 | else | |
771 | opts->x_flag_ipa_icf = 0; | |
772 | ||
773 | if (opts_set->x_flag_ipa_icf_functions && opts->x_flag_ipa_icf_functions) | |
774 | error_at (loc, | |
775 | "%<-fipa-icf-functions%> is incompatible with " | |
776 | "%<-flive-patching=inline-only-static|inline-clone%>"); | |
777 | else | |
778 | opts->x_flag_ipa_icf_functions = 0; | |
779 | ||
780 | if (opts_set->x_flag_ipa_icf_variables && opts->x_flag_ipa_icf_variables) | |
781 | error_at (loc, | |
782 | "%<-fipa-icf-variables%> is incompatible with " | |
783 | "%<-flive-patching=inline-only-static|inline-clone%>"); | |
784 | else | |
785 | opts->x_flag_ipa_icf_variables = 0; | |
786 | ||
787 | if (opts_set->x_flag_ipa_bit_cp && opts->x_flag_ipa_bit_cp) | |
788 | error_at (loc, | |
789 | "%<-fipa-bit-cp%> is incompatible with " | |
790 | "%<-flive-patching=inline-only-static|inline-clone%>"); | |
791 | else | |
792 | opts->x_flag_ipa_bit_cp = 0; | |
793 | ||
794 | if (opts_set->x_flag_ipa_vrp && opts->x_flag_ipa_vrp) | |
795 | error_at (loc, | |
796 | "%<-fipa-vrp%> is incompatible with " | |
797 | "%<-flive-patching=inline-only-static|inline-clone%>"); | |
798 | else | |
799 | opts->x_flag_ipa_vrp = 0; | |
800 | ||
801 | if (opts_set->x_flag_ipa_pure_const && opts->x_flag_ipa_pure_const) | |
802 | error_at (loc, | |
803 | "%<-fipa-pure-const%> is incompatible with " | |
804 | "%<-flive-patching=inline-only-static|inline-clone%>"); | |
805 | else | |
806 | opts->x_flag_ipa_pure_const = 0; | |
807 | ||
808 | /* FIXME: disable unreachable code removal. */ | |
809 | ||
810 | /* discovery of functions/variables with no address taken. */ | |
811 | if (opts_set->x_flag_ipa_reference_addressable | |
812 | && opts->x_flag_ipa_reference_addressable) | |
813 | error_at (loc, | |
814 | "%<-fipa-reference-addressable%> is incompatible with " | |
815 | "%<-flive-patching=inline-only-static|inline-clone%>"); | |
816 | else | |
817 | opts->x_flag_ipa_reference_addressable = 0; | |
818 | ||
819 | /* ipa stack alignment propagation. */ | |
820 | if (opts_set->x_flag_ipa_stack_alignment | |
821 | && opts->x_flag_ipa_stack_alignment) | |
822 | error_at (loc, | |
823 | "%<-fipa-stack-alignment%> is incompatible with " | |
824 | "%<-flive-patching=inline-only-static|inline-clone%>"); | |
825 | else | |
826 | opts->x_flag_ipa_stack_alignment = 0; | |
827 | break; | |
828 | default: | |
829 | gcc_unreachable (); | |
830 | } | |
831 | } | |
832 | ||
2dcfc872 | 833 | /* --help option argument if set. */ |
bc405869 | 834 | vec<const char *> help_option_arguments; |
2dcfc872 | 835 | |
2dcfc872 | 836 | |
299404a1 JM |
837 | /* After all options at LOC have been read into OPTS and OPTS_SET, |
838 | finalize settings of those options and diagnose incompatible | |
a75bfaa6 | 839 | combinations. */ |
c98cd5bf | 840 | void |
299404a1 | 841 | finish_options (struct gcc_options *opts, struct gcc_options *opts_set, |
f66409e0 | 842 | location_t loc) |
a75bfaa6 | 843 | { |
a75bfaa6 JM |
844 | enum unwind_info_type ui_except; |
845 | ||
91035653 | 846 | if (opts->x_dump_base_name |
91035653 | 847 | && ! opts->x_dump_base_name_prefixed) |
e71da632 | 848 | { |
f35629b7 NS |
849 | const char *sep = opts->x_dump_base_name; |
850 | ||
851 | for (; *sep; sep++) | |
852 | if (IS_DIR_SEPARATOR (*sep)) | |
853 | break; | |
854 | ||
855 | if (*sep) | |
856 | /* If dump_base_path contains subdirectories, don't prepend | |
857 | anything. */; | |
858 | else if (opts->x_dump_dir_name) | |
859 | /* We have a DUMP_DIR_NAME, prepend that. */ | |
dc357798 JJ |
860 | opts->x_dump_base_name = opts_concat (opts->x_dump_dir_name, |
861 | opts->x_dump_base_name, NULL); | |
dd3b31fb L |
862 | else if (opts->x_aux_base_name |
863 | && strcmp (opts->x_aux_base_name, HOST_BIT_BUCKET) != 0) | |
f35629b7 NS |
864 | /* AUX_BASE_NAME is set and is not the bit bucket. If it |
865 | contains a directory component, prepend those directories. | |
866 | Typically this places things in the same directory as the | |
867 | object file. */ | |
e71da632 | 868 | { |
d7fb0a6d L |
869 | const char *aux_base; |
870 | ||
d5478783 JM |
871 | base_of_path (opts->x_aux_base_name, &aux_base); |
872 | if (opts->x_aux_base_name != aux_base) | |
d7fb0a6d | 873 | { |
d5478783 | 874 | int dir_len = aux_base - opts->x_aux_base_name; |
dc357798 JJ |
875 | char *new_dump_base_name |
876 | = XOBNEWVEC (&opts_obstack, char, | |
877 | strlen (opts->x_dump_base_name) + dir_len + 1); | |
d7fb0a6d | 878 | |
d5478783 JM |
879 | /* Copy directory component from OPTS->X_AUX_BASE_NAME. */ |
880 | memcpy (new_dump_base_name, opts->x_aux_base_name, dir_len); | |
881 | /* Append existing OPTS->X_DUMP_BASE_NAME. */ | |
882 | strcpy (new_dump_base_name + dir_len, opts->x_dump_base_name); | |
883 | opts->x_dump_base_name = new_dump_base_name; | |
d7fb0a6d | 884 | } |
e71da632 | 885 | } |
f35629b7 NS |
886 | |
887 | /* It is definitely prefixed now. */ | |
888 | opts->x_dump_base_name_prefixed = true; | |
e71da632 MH |
889 | } |
890 | ||
93a4f5e0 JJ |
891 | /* Handle related options for unit-at-a-time, toplevel-reorder, and |
892 | section-anchors. */ | |
d5478783 | 893 | if (!opts->x_flag_unit_at_a_time) |
57b08d04 | 894 | { |
d5478783 | 895 | if (opts->x_flag_section_anchors && opts_set->x_flag_section_anchors) |
299404a1 JM |
896 | error_at (loc, "section anchors must be disabled when unit-at-a-time " |
897 | "is disabled"); | |
d5478783 JM |
898 | opts->x_flag_section_anchors = 0; |
899 | if (opts->x_flag_toplevel_reorder == 1) | |
299404a1 JM |
900 | error_at (loc, "toplevel reorder must be disabled when unit-at-a-time " |
901 | "is disabled"); | |
d5478783 | 902 | opts->x_flag_toplevel_reorder = 0; |
57b08d04 | 903 | } |
7ea6b6cf | 904 | |
3615816d AH |
905 | /* -fself-test depends on the state of the compiler prior to |
906 | compiling anything. Ideally it should be run on an empty source | |
907 | file. However, in case we get run with actual source, assume | |
908 | -fsyntax-only which will inhibit any compiler initialization | |
909 | which may confuse the self tests. */ | |
910 | if (opts->x_flag_self_test) | |
911 | opts->x_flag_syntax_only = 1; | |
912 | ||
ee777b71 AH |
913 | if (opts->x_flag_tm && opts->x_flag_non_call_exceptions) |
914 | sorry ("transactional memory is not supported with non-call exceptions"); | |
915 | ||
5ffebee7 JJ |
916 | /* Unless the user has asked for section anchors, we disable toplevel |
917 | reordering at -O0 to disable transformations that might be surprising | |
918 | to end users and to get -fno-toplevel-reorder tested. */ | |
299404a1 | 919 | if (!opts->x_optimize |
d5478783 JM |
920 | && opts->x_flag_toplevel_reorder == 2 |
921 | && !(opts->x_flag_section_anchors && opts_set->x_flag_section_anchors)) | |
93a4f5e0 | 922 | { |
d5478783 JM |
923 | opts->x_flag_toplevel_reorder = 0; |
924 | opts->x_flag_section_anchors = 0; | |
93a4f5e0 | 925 | } |
d5478783 | 926 | if (!opts->x_flag_toplevel_reorder) |
57b08d04 | 927 | { |
d5478783 | 928 | if (opts->x_flag_section_anchors && opts_set->x_flag_section_anchors) |
299404a1 JM |
929 | error_at (loc, "section anchors must be disabled when toplevel reorder" |
930 | " is disabled"); | |
d5478783 | 931 | opts->x_flag_section_anchors = 0; |
57b08d04 ST |
932 | } |
933 | ||
299404a1 | 934 | if (!opts->x_flag_opts_finished) |
ab442df7 | 935 | { |
428b3812 L |
936 | /* We initialize opts->x_flag_pie to -1 so that targets can set a |
937 | default value. */ | |
938 | if (opts->x_flag_pie == -1) | |
939 | { | |
b57e6e18 L |
940 | /* We initialize opts->x_flag_pic to -1 so that we can tell if |
941 | -fpic, -fPIC, -fno-pic or -fno-PIC is used. */ | |
942 | if (opts->x_flag_pic == -1) | |
428b3812 L |
943 | opts->x_flag_pie = DEFAULT_FLAG_PIE; |
944 | else | |
945 | opts->x_flag_pie = 0; | |
946 | } | |
b57e6e18 | 947 | /* If -fPIE or -fpie is used, turn on PIC. */ |
d5478783 JM |
948 | if (opts->x_flag_pie) |
949 | opts->x_flag_pic = opts->x_flag_pie; | |
b57e6e18 L |
950 | else if (opts->x_flag_pic == -1) |
951 | opts->x_flag_pic = 0; | |
d5478783 JM |
952 | if (opts->x_flag_pic && !opts->x_flag_pie) |
953 | opts->x_flag_shlib = 1; | |
b294a75e | 954 | opts->x_flag_opts_finished = true; |
ab442df7 | 955 | } |
9756310a | 956 | |
e0f6cba0 MG |
957 | /* We initialize opts->x_flag_stack_protect to -1 so that targets |
958 | can set a default value. */ | |
959 | if (opts->x_flag_stack_protect == -1) | |
960 | opts->x_flag_stack_protect = DEFAULT_FLAG_SSP; | |
961 | ||
299404a1 | 962 | if (opts->x_optimize == 0) |
9756310a NB |
963 | { |
964 | /* Inlining does not work if not optimizing, | |
965 | so force it not to be done. */ | |
d5478783 JM |
966 | opts->x_warn_inline = 0; |
967 | opts->x_flag_no_inline = 1; | |
9756310a NB |
968 | } |
969 | ||
750054a2 CT |
970 | /* The optimization to partition hot and cold basic blocks into separate |
971 | sections of the .o and executable files does not work (currently) | |
e395963f | 972 | with exception handling. This is because there is no support for |
d5478783 JM |
973 | generating unwind info. If opts->x_flag_exceptions is turned on |
974 | we need to turn off the partitioning optimization. */ | |
750054a2 | 975 | |
677f3fa8 | 976 | ui_except = targetm_common.except_unwind_info (opts); |
f0a0390e | 977 | |
d5478783 JM |
978 | if (opts->x_flag_exceptions |
979 | && opts->x_flag_reorder_blocks_and_partition | |
bf1431e3 | 980 | && (ui_except == UI_SJLJ || ui_except >= UI_TARGET)) |
750054a2 | 981 | { |
32ad0f03 TJ |
982 | if (opts_set->x_flag_reorder_blocks_and_partition) |
983 | inform (loc, | |
4f4b35a0 ML |
984 | "%<-freorder-blocks-and-partition%> does not work " |
985 | "with exceptions on this architecture"); | |
d5478783 JM |
986 | opts->x_flag_reorder_blocks_and_partition = 0; |
987 | opts->x_flag_reorder_blocks = 1; | |
750054a2 | 988 | } |
c7466dee | 989 | |
e395963f JW |
990 | /* If user requested unwind info, then turn off the partitioning |
991 | optimization. */ | |
992 | ||
d5478783 | 993 | if (opts->x_flag_unwind_tables |
677f3fa8 | 994 | && !targetm_common.unwind_tables_default |
d5478783 | 995 | && opts->x_flag_reorder_blocks_and_partition |
bf1431e3 | 996 | && (ui_except == UI_SJLJ || ui_except >= UI_TARGET)) |
e395963f | 997 | { |
32ad0f03 TJ |
998 | if (opts_set->x_flag_reorder_blocks_and_partition) |
999 | inform (loc, | |
4f4b35a0 ML |
1000 | "%<-freorder-blocks-and-partition%> does not support " |
1001 | "unwind info on this architecture"); | |
d5478783 JM |
1002 | opts->x_flag_reorder_blocks_and_partition = 0; |
1003 | opts->x_flag_reorder_blocks = 1; | |
e395963f JW |
1004 | } |
1005 | ||
1006 | /* If the target requested unwind info, then turn off the partitioning | |
1007 | optimization with a different message. Likewise, if the target does not | |
1008 | support named sections. */ | |
1009 | ||
d5478783 | 1010 | if (opts->x_flag_reorder_blocks_and_partition |
677f3fa8 | 1011 | && (!targetm_common.have_named_sections |
d5478783 | 1012 | || (opts->x_flag_unwind_tables |
677f3fa8 | 1013 | && targetm_common.unwind_tables_default |
bf1431e3 | 1014 | && (ui_except == UI_SJLJ || ui_except >= UI_TARGET)))) |
c7466dee | 1015 | { |
32ad0f03 TJ |
1016 | if (opts_set->x_flag_reorder_blocks_and_partition) |
1017 | inform (loc, | |
4f4b35a0 ML |
1018 | "%<-freorder-blocks-and-partition%> does not work " |
1019 | "on this architecture"); | |
d5478783 JM |
1020 | opts->x_flag_reorder_blocks_and_partition = 0; |
1021 | opts->x_flag_reorder_blocks = 1; | |
c7466dee | 1022 | } |
ab442df7 | 1023 | |
940c4160 | 1024 | |
e855c69d AB |
1025 | /* Pipelining of outer loops is only possible when general pipelining |
1026 | capabilities are requested. */ | |
d5478783 JM |
1027 | if (!opts->x_flag_sel_sched_pipelining) |
1028 | opts->x_flag_sel_sched_pipelining_outer_loops = 0; | |
e855c69d | 1029 | |
d5478783 | 1030 | if (opts->x_flag_conserve_stack) |
6a78eaa3 | 1031 | { |
028d4092 ML |
1032 | SET_OPTION_IF_UNSET (opts, opts_set, param_large_stack_frame, 100); |
1033 | SET_OPTION_IF_UNSET (opts, opts_set, param_stack_frame_growth, 40); | |
6a78eaa3 JH |
1034 | } |
1035 | ||
014d92e1 | 1036 | if (opts->x_flag_lto) |
e3b8749b RG |
1037 | { |
1038 | #ifdef ENABLE_LTO | |
d5478783 | 1039 | opts->x_flag_generate_lto = 1; |
e3b8749b RG |
1040 | |
1041 | /* When generating IL, do not operate in whole-program mode. | |
1042 | Otherwise, symbols will be privatized too early, causing link | |
1043 | errors later. */ | |
d5478783 | 1044 | opts->x_flag_whole_program = 0; |
e3b8749b | 1045 | #else |
299404a1 | 1046 | error_at (loc, "LTO support has not been enabled in this configuration"); |
e3b8749b | 1047 | #endif |
063d671d JH |
1048 | if (!opts->x_flag_fat_lto_objects |
1049 | && (!HAVE_LTO_PLUGIN | |
1050 | || (opts_set->x_flag_use_linker_plugin | |
1051 | && !opts->x_flag_use_linker_plugin))) | |
e9f67e62 JH |
1052 | { |
1053 | if (opts_set->x_flag_fat_lto_objects) | |
4f4b35a0 ML |
1054 | error_at (loc, "%<-fno-fat-lto-objects%> are supported only with " |
1055 | "linker plugin"); | |
e9f67e62 JH |
1056 | opts->x_flag_fat_lto_objects = 1; |
1057 | } | |
22fdf6af RB |
1058 | |
1059 | /* -gsplit-dwarf isn't compatible with LTO, see PR88389. */ | |
1060 | if (opts->x_dwarf_split_debug_info) | |
1061 | { | |
1062 | inform (loc, "%<-gsplit-dwarf%> is not supported with LTO," | |
1063 | " disabling"); | |
1064 | opts->x_dwarf_split_debug_info = 0; | |
1065 | } | |
e9f67e62 | 1066 | } |
e3b8749b | 1067 | |
d5478783 | 1068 | /* We initialize opts->x_flag_split_stack to -1 so that targets can set a |
7458026b | 1069 | default value if they choose based on other options. */ |
d5478783 JM |
1070 | if (opts->x_flag_split_stack == -1) |
1071 | opts->x_flag_split_stack = 0; | |
1072 | else if (opts->x_flag_split_stack) | |
7458026b | 1073 | { |
677f3fa8 | 1074 | if (!targetm_common.supports_split_stack (true, opts)) |
7458026b | 1075 | { |
299404a1 JM |
1076 | error_at (loc, "%<-fsplit-stack%> is not supported by " |
1077 | "this compiler configuration"); | |
d5478783 | 1078 | opts->x_flag_split_stack = 0; |
7458026b ILT |
1079 | } |
1080 | } | |
bfe068c3 | 1081 | |
227b76c3 JH |
1082 | /* If stack splitting is turned on, and the user did not explicitly |
1083 | request function partitioning, turn off partitioning, as it | |
1084 | confuses the linker when trying to handle partitioned split-stack | |
1085 | code that calls a non-split-stack functions. But if partitioning | |
1086 | was turned on explicitly just hope for the best. */ | |
1087 | if (opts->x_flag_split_stack | |
1088 | && opts->x_flag_reorder_blocks_and_partition | |
1089 | && !opts_set->x_flag_reorder_blocks_and_partition) | |
1090 | opts->x_flag_reorder_blocks_and_partition = 0; | |
1091 | ||
1092 | if (opts->x_flag_reorder_blocks_and_partition | |
1093 | && !opts_set->x_flag_reorder_functions) | |
1094 | opts->x_flag_reorder_functions = 1; | |
1095 | ||
bd5c3baa | 1096 | /* The -gsplit-dwarf option requires -ggnu-pubnames. */ |
99ea153e | 1097 | if (opts->x_dwarf_split_debug_info) |
bd5c3baa | 1098 | opts->x_debug_generate_pub_sections = 2; |
fec4842d | 1099 | |
05abad4c ML |
1100 | if ((opts->x_flag_sanitize |
1101 | & (SANITIZE_USER_ADDRESS | SANITIZE_KERNEL_ADDRESS)) == 0) | |
1102 | { | |
1103 | if (opts->x_flag_sanitize & SANITIZE_POINTER_COMPARE) | |
1104 | error_at (loc, | |
1105 | "%<-fsanitize=pointer-compare%> must be combined with " | |
1106 | "%<-fsanitize=address%> or %<-fsanitize=kernel-address%>"); | |
1107 | if (opts->x_flag_sanitize & SANITIZE_POINTER_SUBTRACT) | |
1108 | error_at (loc, | |
1109 | "%<-fsanitize=pointer-subtract%> must be combined with " | |
1110 | "%<-fsanitize=address%> or %<-fsanitize=kernel-address%>"); | |
1111 | } | |
1112 | ||
fed4de37 | 1113 | /* Userspace and kernel ASan conflict with each other. */ |
d95a2703 JJ |
1114 | if ((opts->x_flag_sanitize & SANITIZE_USER_ADDRESS) |
1115 | && (opts->x_flag_sanitize & SANITIZE_KERNEL_ADDRESS)) | |
fec4842d | 1116 | error_at (loc, |
6d28654e ML |
1117 | "%<-fsanitize=address%> is incompatible with " |
1118 | "%<-fsanitize=kernel-address%>"); | |
fec4842d | 1119 | |
fed4de37 | 1120 | /* And with TSan. */ |
d95a2703 JJ |
1121 | if ((opts->x_flag_sanitize & SANITIZE_ADDRESS) |
1122 | && (opts->x_flag_sanitize & SANITIZE_THREAD)) | |
fec4842d | 1123 | error_at (loc, |
6d28654e ML |
1124 | "%<-fsanitize=address%> and %<-fsanitize=kernel-address%> " |
1125 | "are incompatible with %<-fsanitize=thread%>"); | |
d95a2703 | 1126 | |
5cc6c41c ML |
1127 | if ((opts->x_flag_sanitize & SANITIZE_LEAK) |
1128 | && (opts->x_flag_sanitize & SANITIZE_THREAD)) | |
1129 | error_at (loc, | |
6d28654e | 1130 | "%<-fsanitize=leak%> is incompatible with %<-fsanitize=thread%>"); |
d95a2703 | 1131 | |
5cc6c41c ML |
1132 | /* Check error recovery for -fsanitize-recover option. */ |
1133 | for (int i = 0; sanitizer_opts[i].name != NULL; ++i) | |
1134 | if ((opts->x_flag_sanitize_recover & sanitizer_opts[i].flag) | |
1135 | && !sanitizer_opts[i].can_recover) | |
6d28654e | 1136 | error_at (loc, "%<-fsanitize-recover=%s%> is not supported", |
5cc6c41c | 1137 | sanitizer_opts[i].name); |
9ca0032c MZ |
1138 | |
1139 | /* When instrumenting the pointers, we don't want to remove | |
1140 | the null pointer checks. */ | |
1141 | if (opts->x_flag_sanitize & (SANITIZE_NULL | SANITIZE_NONNULL_ATTRIBUTE | |
1142 | | SANITIZE_RETURNS_NONNULL_ATTRIBUTE)) | |
1143 | opts->x_flag_delete_null_pointer_checks = 0; | |
1144 | ||
1145 | /* Aggressive compiler optimizations may cause false negatives. */ | |
866c72a8 | 1146 | if (opts->x_flag_sanitize & ~(SANITIZE_LEAK | SANITIZE_UNREACHABLE)) |
2bf54d93 | 1147 | opts->x_flag_aggressive_loop_optimizations = 0; |
6dc4a604 ML |
1148 | |
1149 | /* Enable -fsanitize-address-use-after-scope if address sanitizer is | |
1150 | enabled. */ | |
04bfa1e4 | 1151 | if ((opts->x_flag_sanitize & SANITIZE_USER_ADDRESS) |
6dc4a604 ML |
1152 | && !opts_set->x_flag_sanitize_address_use_after_scope) |
1153 | opts->x_flag_sanitize_address_use_after_scope = true; | |
1154 | ||
1155 | /* Force -fstack-reuse=none in case -fsanitize-address-use-after-scope | |
1156 | is enabled. */ | |
1157 | if (opts->x_flag_sanitize_address_use_after_scope) | |
1158 | { | |
1159 | if (opts->x_flag_stack_reuse != SR_NONE | |
1160 | && opts_set->x_flag_stack_reuse != SR_NONE) | |
1161 | error_at (loc, | |
6d28654e ML |
1162 | "%<-fsanitize-address-use-after-scope%> requires " |
1163 | "%<-fstack-reuse=none%> option"); | |
6dc4a604 ML |
1164 | |
1165 | opts->x_flag_stack_reuse = SR_NONE; | |
1166 | } | |
26c5b549 ML |
1167 | |
1168 | if ((opts->x_flag_sanitize & SANITIZE_USER_ADDRESS) && opts->x_flag_tm) | |
1169 | sorry ("transactional memory is not supported with %<-fsanitize=address%>"); | |
1170 | ||
1171 | if ((opts->x_flag_sanitize & SANITIZE_KERNEL_ADDRESS) && opts->x_flag_tm) | |
1172 | sorry ("transactional memory is not supported with " | |
1173 | "%<-fsanitize=kernel-address%>"); | |
6fd6a2ff QZ |
1174 | |
1175 | /* Currently live patching is not support for LTO. */ | |
1176 | if (opts->x_flag_live_patching && opts->x_flag_lto) | |
1177 | sorry ("live patching is not supported with LTO"); | |
1178 | ||
9eb730b8 CT |
1179 | /* Currently vtable verification is not supported for LTO */ |
1180 | if (opts->x_flag_vtable_verify && opts->x_flag_lto) | |
1181 | sorry ("vtable verification is not supported with LTO"); | |
1182 | ||
6fd6a2ff QZ |
1183 | /* Control IPA optimizations based on different -flive-patching level. */ |
1184 | if (opts->x_flag_live_patching) | |
1185 | { | |
1186 | control_options_for_live_patching (opts, opts_set, | |
1187 | opts->x_flag_live_patching, | |
1188 | loc); | |
1189 | } | |
9756310a NB |
1190 | } |
1191 | ||
c662432e NC |
1192 | #define LEFT_COLUMN 27 |
1193 | ||
1194 | /* Output ITEM, of length ITEM_WIDTH, in the left column, | |
1195 | followed by word-wrapped HELP in a second column. */ | |
1196 | static void | |
1197 | wrap_help (const char *help, | |
1198 | const char *item, | |
1199 | unsigned int item_width, | |
1200 | unsigned int columns) | |
1201 | { | |
1202 | unsigned int col_width = LEFT_COLUMN; | |
1203 | unsigned int remaining, room, len; | |
1204 | ||
1205 | remaining = strlen (help); | |
1206 | ||
1207 | do | |
1208 | { | |
1209 | room = columns - 3 - MAX (col_width, item_width); | |
1210 | if (room > columns) | |
1211 | room = 0; | |
1212 | len = remaining; | |
1213 | ||
1214 | if (room < len) | |
1215 | { | |
1216 | unsigned int i; | |
1217 | ||
1218 | for (i = 0; help[i]; i++) | |
1219 | { | |
1220 | if (i >= room && len != remaining) | |
1221 | break; | |
1222 | if (help[i] == ' ') | |
1223 | len = i; | |
1224 | else if ((help[i] == '-' || help[i] == '/') | |
1225 | && help[i + 1] != ' ' | |
1226 | && i > 0 && ISALPHA (help[i - 1])) | |
1227 | len = i + 1; | |
1228 | } | |
1229 | } | |
1230 | ||
c3284718 | 1231 | printf (" %-*.*s %.*s\n", col_width, item_width, item, len, help); |
c662432e NC |
1232 | item_width = 0; |
1233 | while (help[len] == ' ') | |
1234 | len++; | |
1235 | help += len; | |
1236 | remaining -= len; | |
1237 | } | |
1238 | while (remaining); | |
1239 | } | |
1240 | ||
c98c2430 ML |
1241 | /* Data structure used to print list of valid option values. */ |
1242 | ||
6c1dae73 | 1243 | class option_help_tuple |
c98c2430 | 1244 | { |
6c1dae73 | 1245 | public: |
c98c2430 ML |
1246 | option_help_tuple (int code, vec<const char *> values): |
1247 | m_code (code), m_values (values) | |
1248 | {} | |
1249 | ||
1250 | /* Code of an option. */ | |
1251 | int m_code; | |
1252 | ||
1253 | /* List of possible values. */ | |
1254 | vec<const char *> m_values; | |
1255 | }; | |
1256 | ||
c662432e NC |
1257 | /* Print help for a specific front-end, etc. */ |
1258 | static void | |
1259 | print_filtered_help (unsigned int include_flags, | |
1260 | unsigned int exclude_flags, | |
1261 | unsigned int any_flags, | |
0576d21f | 1262 | unsigned int columns, |
e6d4b984 JM |
1263 | struct gcc_options *opts, |
1264 | unsigned int lang_mask) | |
c662432e NC |
1265 | { |
1266 | unsigned int i; | |
1267 | const char *help; | |
c662432e NC |
1268 | bool found = false; |
1269 | bool displayed = false; | |
a7b2e184 | 1270 | char new_help[256]; |
c662432e | 1271 | |
299404a1 JM |
1272 | if (!opts->x_help_printed) |
1273 | opts->x_help_printed = XCNEWVAR (char, cl_options_count); | |
c662432e | 1274 | |
e6d4b984 JM |
1275 | if (!opts->x_help_enum_printed) |
1276 | opts->x_help_enum_printed = XCNEWVAR (char, cl_enums_count); | |
1277 | ||
c98c2430 ML |
1278 | auto_vec<option_help_tuple> help_tuples; |
1279 | ||
c662432e NC |
1280 | for (i = 0; i < cl_options_count; i++) |
1281 | { | |
c662432e NC |
1282 | const struct cl_option *option = cl_options + i; |
1283 | unsigned int len; | |
1284 | const char *opt; | |
1285 | const char *tab; | |
1286 | ||
1287 | if (include_flags == 0 | |
1288 | || ((option->flags & include_flags) != include_flags)) | |
1289 | { | |
1290 | if ((option->flags & any_flags) == 0) | |
1291 | continue; | |
1292 | } | |
1293 | ||
1294 | /* Skip unwanted switches. */ | |
1295 | if ((option->flags & exclude_flags) != 0) | |
1296 | continue; | |
1297 | ||
603349bf JM |
1298 | /* The driver currently prints its own help text. */ |
1299 | if ((option->flags & CL_DRIVER) != 0 | |
1300 | && (option->flags & (((1U << cl_lang_count) - 1) | |
1301 | | CL_COMMON | CL_TARGET)) == 0) | |
1302 | continue; | |
1303 | ||
c662432e NC |
1304 | found = true; |
1305 | /* Skip switches that have already been printed. */ | |
299404a1 | 1306 | if (opts->x_help_printed[i]) |
c662432e NC |
1307 | continue; |
1308 | ||
299404a1 | 1309 | opts->x_help_printed[i] = true; |
c662432e NC |
1310 | |
1311 | help = option->help; | |
1312 | if (help == NULL) | |
1313 | { | |
1314 | if (exclude_flags & CL_UNDOCUMENTED) | |
1315 | continue; | |
a7b2e184 | 1316 | |
c662432e NC |
1317 | help = undocumented_msg; |
1318 | } | |
1319 | ||
a7b2e184 MS |
1320 | if (option->alias_target < N_OPTS |
1321 | && cl_options [option->alias_target].help) | |
1322 | { | |
1323 | if (help == undocumented_msg) | |
1324 | { | |
1325 | /* For undocumented options that are aliases for other options | |
1326 | that are documented, point the reader to the other option in | |
1327 | preference of the former. */ | |
1328 | snprintf (new_help, sizeof new_help, | |
1329 | _("Same as %s. Use the latter option instead."), | |
1330 | cl_options [option->alias_target].opt_text); | |
1331 | } | |
1332 | else | |
1333 | { | |
1334 | /* For documented options with aliases, mention the aliased | |
1335 | option's name for reference. */ | |
1336 | snprintf (new_help, sizeof new_help, | |
1337 | _("%s Same as %s."), | |
1338 | help, cl_options [option->alias_target].opt_text); | |
1339 | } | |
1340 | ||
1341 | help = new_help; | |
1342 | } | |
1343 | ||
1344 | if (option->warn_message) | |
1345 | { | |
1346 | /* Mention that the use of the option will trigger a warning. */ | |
1347 | if (help == new_help) | |
1348 | snprintf (new_help + strlen (new_help), | |
1349 | sizeof new_help - strlen (new_help), | |
1350 | " %s", _(use_diagnosed_msg)); | |
1351 | else | |
1352 | snprintf (new_help, sizeof new_help, | |
1353 | "%s %s", help, _(use_diagnosed_msg)); | |
1354 | ||
1355 | help = new_help; | |
1356 | } | |
1357 | ||
c662432e NC |
1358 | /* Get the translation. */ |
1359 | help = _(help); | |
1360 | ||
1361 | /* Find the gap between the name of the | |
1362 | option and its descriptive text. */ | |
1363 | tab = strchr (help, '\t'); | |
1364 | if (tab) | |
1365 | { | |
1366 | len = tab - help; | |
1367 | opt = help; | |
1368 | help = tab + 1; | |
1369 | } | |
1370 | else | |
1371 | { | |
1372 | opt = option->opt_text; | |
1373 | len = strlen (opt); | |
1374 | } | |
1375 | ||
1376 | /* With the -Q option enabled we change the descriptive text associated | |
1377 | with an option to be an indication of its current setting. */ | |
a7d0d30f | 1378 | if (!opts->x_quiet_flag) |
c662432e | 1379 | { |
0576d21f | 1380 | void *flag_var = option_flag_var (i, opts); |
46625112 | 1381 | |
c662432e NC |
1382 | if (len < (LEFT_COLUMN + 2)) |
1383 | strcpy (new_help, "\t\t"); | |
1384 | else | |
1385 | strcpy (new_help, "\t"); | |
1386 | ||
fa5baeed MS |
1387 | /* Set to print whether the option is enabled or disabled, |
1388 | or, if it's an alias for another option, the name of | |
1389 | the aliased option. */ | |
1390 | bool print_state = false; | |
1391 | ||
21bf1558 JM |
1392 | if (flag_var != NULL |
1393 | && option->var_type != CLVC_DEFER) | |
c662432e | 1394 | { |
fa5baeed MS |
1395 | /* If OPTION is only available for a specific subset |
1396 | of languages other than this one, mention them. */ | |
1397 | bool avail_for_lang = true; | |
1398 | if (unsigned langset = option->flags & CL_LANG_ALL) | |
1399 | { | |
1400 | if (!(langset & lang_mask)) | |
1401 | { | |
1402 | avail_for_lang = false; | |
1403 | strcat (new_help, _("[available in ")); | |
1404 | for (unsigned i = 0, n = 0; (1U << i) < CL_LANG_ALL; ++i) | |
1405 | if (langset & (1U << i)) | |
1406 | { | |
1407 | if (n++) | |
1408 | strcat (new_help, ", "); | |
1409 | strcat (new_help, lang_names[i]); | |
1410 | } | |
1411 | strcat (new_help, "]"); | |
1412 | } | |
1413 | } | |
1414 | if (!avail_for_lang) | |
1415 | ; /* Print nothing else if the option is not available | |
1416 | in the current language. */ | |
1417 | else if (option->flags & CL_JOINED) | |
c662432e NC |
1418 | { |
1419 | if (option->var_type == CLVC_STRING) | |
1420 | { | |
46625112 | 1421 | if (* (const char **) flag_var != NULL) |
c662432e NC |
1422 | snprintf (new_help + strlen (new_help), |
1423 | sizeof (new_help) - strlen (new_help), | |
81018dcf | 1424 | "%s", * (const char **) flag_var); |
c662432e | 1425 | } |
e6d4b984 JM |
1426 | else if (option->var_type == CLVC_ENUM) |
1427 | { | |
1428 | const struct cl_enum *e = &cl_enums[option->var_enum]; | |
1429 | int value; | |
1430 | const char *arg = NULL; | |
1431 | ||
1432 | value = e->get (flag_var); | |
1433 | enum_value_to_arg (e->values, &arg, value, lang_mask); | |
1434 | if (arg == NULL) | |
1435 | arg = _("[default]"); | |
1436 | snprintf (new_help + strlen (new_help), | |
1437 | sizeof (new_help) - strlen (new_help), | |
81018dcf | 1438 | "%s", arg); |
e6d4b984 | 1439 | } |
c662432e | 1440 | else |
fa5baeed MS |
1441 | { |
1442 | if (option->cl_host_wide_int) | |
1443 | sprintf (new_help + strlen (new_help), | |
1444 | _("%llu bytes"), (unsigned long long) | |
1445 | *(unsigned HOST_WIDE_INT *) flag_var); | |
1446 | else | |
1447 | sprintf (new_help + strlen (new_help), | |
1448 | "%i", * (int *) flag_var); | |
1449 | } | |
1450 | } | |
1451 | else | |
1452 | print_state = true; | |
1453 | } | |
1454 | else | |
1455 | /* When there is no argument, print the option state only | |
1456 | if the option takes no argument. */ | |
1457 | print_state = !(option->flags & CL_JOINED); | |
1458 | ||
1459 | if (print_state) | |
1460 | { | |
1461 | if (option->alias_target < N_OPTS | |
68a57628 | 1462 | && option->alias_target != OPT_SPECIAL_warn_removed |
fa5baeed MS |
1463 | && option->alias_target != OPT_SPECIAL_ignore |
1464 | && option->alias_target != OPT_SPECIAL_input_file | |
1465 | && option->alias_target != OPT_SPECIAL_program_name | |
1466 | && option->alias_target != OPT_SPECIAL_unknown) | |
1467 | { | |
1468 | const struct cl_option *target | |
1469 | = &cl_options[option->alias_target]; | |
1470 | sprintf (new_help + strlen (new_help), "%s%s", | |
1471 | target->opt_text, | |
1472 | option->alias_arg ? option->alias_arg : ""); | |
c662432e | 1473 | } |
fa5baeed MS |
1474 | else if (option->alias_target == OPT_SPECIAL_ignore) |
1475 | strcat (new_help, ("[ignored]")); | |
c662432e | 1476 | else |
fa5baeed MS |
1477 | { |
1478 | /* Print the state for an on/off option. */ | |
1479 | int ena = option_enabled (i, lang_mask, opts); | |
1480 | if (ena > 0) | |
1481 | strcat (new_help, _("[enabled]")); | |
1482 | else if (ena == 0) | |
1483 | strcat (new_help, _("[disabled]")); | |
1484 | } | |
c662432e NC |
1485 | } |
1486 | ||
1487 | help = new_help; | |
1488 | } | |
1489 | ||
63010089 ML |
1490 | if (option->range_max != -1) |
1491 | { | |
1492 | char b[128]; | |
1493 | snprintf (b, sizeof (b), "<%d,%d>", option->range_min, | |
1494 | option->range_max); | |
1495 | opt = concat (opt, b, NULL); | |
1496 | len += strlen (b); | |
1497 | } | |
1498 | ||
c662432e NC |
1499 | wrap_help (help, opt, len, columns); |
1500 | displayed = true; | |
e6d4b984 JM |
1501 | |
1502 | if (option->var_type == CLVC_ENUM | |
1503 | && opts->x_help_enum_printed[option->var_enum] != 2) | |
1504 | opts->x_help_enum_printed[option->var_enum] = 1; | |
c98c2430 ML |
1505 | else |
1506 | { | |
1507 | vec<const char *> option_values | |
1508 | = targetm_common.get_valid_option_values (i, NULL); | |
1509 | if (!option_values.is_empty ()) | |
1510 | help_tuples.safe_push (option_help_tuple (i, option_values)); | |
1511 | } | |
c662432e NC |
1512 | } |
1513 | ||
1514 | if (! found) | |
b3eaaf1a NC |
1515 | { |
1516 | unsigned int langs = include_flags & CL_LANG_ALL; | |
1517 | ||
1518 | if (langs == 0) | |
1519 | printf (_(" No options with the desired characteristics were found\n")); | |
1520 | else | |
1521 | { | |
1522 | unsigned int i; | |
1523 | ||
1524 | /* PR 31349: Tell the user how to see all of the | |
1525 | options supported by a specific front end. */ | |
1526 | for (i = 0; (1U << i) < CL_LANG_ALL; i ++) | |
1527 | if ((1U << i) & langs) | |
a7b2e184 | 1528 | printf (_(" None found. Use --help=%s to show *all* the options supported by the %s front-end.\n"), |
b3eaaf1a NC |
1529 | lang_names[i], lang_names[i]); |
1530 | } | |
b8698a0f | 1531 | |
b3eaaf1a | 1532 | } |
c662432e NC |
1533 | else if (! displayed) |
1534 | printf (_(" All options with the desired characteristics have already been displayed\n")); | |
1535 | ||
1536 | putchar ('\n'); | |
e6d4b984 JM |
1537 | |
1538 | /* Print details of enumerated option arguments, if those | |
1539 | enumerations have help text headings provided. If no help text | |
1540 | is provided, presume that the possible values are listed in the | |
1541 | help text for the relevant options. */ | |
1542 | for (i = 0; i < cl_enums_count; i++) | |
1543 | { | |
1544 | unsigned int j, pos; | |
1545 | ||
1546 | if (opts->x_help_enum_printed[i] != 1) | |
1547 | continue; | |
1548 | if (cl_enums[i].help == NULL) | |
1549 | continue; | |
1550 | printf (" %s\n ", _(cl_enums[i].help)); | |
1551 | pos = 4; | |
1552 | for (j = 0; cl_enums[i].values[j].arg != NULL; j++) | |
1553 | { | |
1554 | unsigned int len = strlen (cl_enums[i].values[j].arg); | |
1555 | ||
1556 | if (pos > 4 && pos + 1 + len <= columns) | |
1557 | { | |
1558 | printf (" %s", cl_enums[i].values[j].arg); | |
1559 | pos += 1 + len; | |
1560 | } | |
1561 | else | |
1562 | { | |
1563 | if (pos > 4) | |
1564 | { | |
1565 | printf ("\n "); | |
1566 | pos = 4; | |
1567 | } | |
1568 | printf ("%s", cl_enums[i].values[j].arg); | |
1569 | pos += len; | |
1570 | } | |
1571 | } | |
1572 | printf ("\n\n"); | |
1573 | opts->x_help_enum_printed[i] = 2; | |
1574 | } | |
c98c2430 ML |
1575 | |
1576 | for (unsigned i = 0; i < help_tuples.length (); i++) | |
1577 | { | |
1578 | const struct cl_option *option = cl_options + help_tuples[i].m_code; | |
3f58b66d ML |
1579 | printf (_(" Known valid arguments for %s option:\n "), |
1580 | option->opt_text); | |
c98c2430 ML |
1581 | for (unsigned j = 0; j < help_tuples[i].m_values.length (); j++) |
1582 | printf (" %s", help_tuples[i].m_values[j]); | |
1583 | printf ("\n\n"); | |
1584 | } | |
c662432e NC |
1585 | } |
1586 | ||
1587 | /* Display help for a specified type of option. | |
1588 | The options must have ALL of the INCLUDE_FLAGS set | |
1589 | ANY of the flags in the ANY_FLAGS set | |
0576d21f | 1590 | and NONE of the EXCLUDE_FLAGS set. The current option state is in |
e6d4b984 | 1591 | OPTS; LANG_MASK is used for interpreting enumerated option state. */ |
c662432e NC |
1592 | static void |
1593 | print_specific_help (unsigned int include_flags, | |
1594 | unsigned int exclude_flags, | |
0576d21f | 1595 | unsigned int any_flags, |
e6d4b984 JM |
1596 | struct gcc_options *opts, |
1597 | unsigned int lang_mask) | |
c662432e NC |
1598 | { |
1599 | unsigned int all_langs_mask = (1U << cl_lang_count) - 1; | |
1600 | const char * description = NULL; | |
1601 | const char * descrip_extra = ""; | |
1602 | size_t i; | |
1603 | unsigned int flag; | |
c662432e NC |
1604 | |
1605 | /* Sanity check: Make sure that we do not have more | |
1606 | languages than we have bits available to enumerate them. */ | |
58265ea6 | 1607 | gcc_assert ((1U << cl_lang_count) <= CL_MIN_OPTION_CLASS); |
c662432e NC |
1608 | |
1609 | /* If we have not done so already, obtain | |
1610 | the desired maximum width of the output. */ | |
299404a1 | 1611 | if (opts->x_help_columns == 0) |
c662432e | 1612 | { |
c9db45aa TB |
1613 | opts->x_help_columns = get_terminal_width (); |
1614 | if (opts->x_help_columns == INT_MAX) | |
c662432e | 1615 | /* Use a reasonable default. */ |
299404a1 | 1616 | opts->x_help_columns = 80; |
c662432e NC |
1617 | } |
1618 | ||
1619 | /* Decide upon the title for the options that we are going to display. */ | |
1620 | for (i = 0, flag = 1; flag <= CL_MAX_OPTION_CLASS; flag <<= 1, i ++) | |
1621 | { | |
1622 | switch (flag & include_flags) | |
1623 | { | |
1624 | case 0: | |
603349bf | 1625 | case CL_DRIVER: |
c662432e NC |
1626 | break; |
1627 | ||
1628 | case CL_TARGET: | |
1629 | description = _("The following options are target specific"); | |
1630 | break; | |
1631 | case CL_WARNING: | |
1632 | description = _("The following options control compiler warning messages"); | |
1633 | break; | |
1634 | case CL_OPTIMIZATION: | |
1635 | description = _("The following options control optimizations"); | |
1636 | break; | |
1637 | case CL_COMMON: | |
1638 | description = _("The following options are language-independent"); | |
1639 | break; | |
1640 | case CL_PARAMS: | |
76c26af9 | 1641 | description = _("The following options control parameters"); |
c662432e NC |
1642 | break; |
1643 | default: | |
1644 | if (i >= cl_lang_count) | |
1645 | break; | |
0631b69f | 1646 | if (exclude_flags & all_langs_mask) |
c01c261d | 1647 | description = _("The following options are specific to just the language "); |
c662432e | 1648 | else |
b5456e04 | 1649 | description = _("The following options are supported by the language "); |
b3eaaf1a | 1650 | descrip_extra = lang_names [i]; |
c662432e NC |
1651 | break; |
1652 | } | |
1653 | } | |
1654 | ||
1655 | if (description == NULL) | |
1656 | { | |
1657 | if (any_flags == 0) | |
1658 | { | |
0631b69f | 1659 | if (include_flags & CL_UNDOCUMENTED) |
c662432e | 1660 | description = _("The following options are not documented"); |
0631b69f RW |
1661 | else if (include_flags & CL_SEPARATE) |
1662 | description = _("The following options take separate arguments"); | |
1663 | else if (include_flags & CL_JOINED) | |
1664 | description = _("The following options take joined arguments"); | |
c662432e NC |
1665 | else |
1666 | { | |
a9c697b8 MS |
1667 | internal_error ("unrecognized %<include_flags 0x%x%> passed " |
1668 | "to %<print_specific_help%>", | |
c662432e NC |
1669 | include_flags); |
1670 | return; | |
1671 | } | |
1672 | } | |
1673 | else | |
1674 | { | |
1675 | if (any_flags & all_langs_mask) | |
1676 | description = _("The following options are language-related"); | |
1677 | else | |
1678 | description = _("The following options are language-independent"); | |
1679 | } | |
1680 | } | |
1681 | ||
1682 | printf ("%s%s:\n", description, descrip_extra); | |
299404a1 | 1683 | print_filtered_help (include_flags, exclude_flags, any_flags, |
e6d4b984 | 1684 | opts->x_help_columns, opts, lang_mask); |
c662432e NC |
1685 | } |
1686 | ||
be3c16c4 DC |
1687 | /* Enable FDO-related flags. */ |
1688 | ||
1689 | static void | |
1690 | enable_fdo_optimizations (struct gcc_options *opts, | |
1691 | struct gcc_options *opts_set, | |
1692 | int value) | |
1693 | { | |
1694 | if (!opts_set->x_flag_branch_probabilities) | |
1695 | opts->x_flag_branch_probabilities = value; | |
1696 | if (!opts_set->x_flag_profile_values) | |
1697 | opts->x_flag_profile_values = value; | |
1698 | if (!opts_set->x_flag_unroll_loops) | |
1699 | opts->x_flag_unroll_loops = value; | |
1700 | if (!opts_set->x_flag_peel_loops) | |
1701 | opts->x_flag_peel_loops = value; | |
1702 | if (!opts_set->x_flag_tracer) | |
1703 | opts->x_flag_tracer = value; | |
1704 | if (!opts_set->x_flag_value_profile_transformations) | |
1705 | opts->x_flag_value_profile_transformations = value; | |
1706 | if (!opts_set->x_flag_inline_functions) | |
1707 | opts->x_flag_inline_functions = value; | |
1708 | if (!opts_set->x_flag_ipa_cp) | |
1709 | opts->x_flag_ipa_cp = value; | |
1710 | if (!opts_set->x_flag_ipa_cp_clone | |
1711 | && value && opts->x_flag_ipa_cp) | |
1712 | opts->x_flag_ipa_cp_clone = value; | |
209ca542 PK |
1713 | if (!opts_set->x_flag_ipa_bit_cp |
1714 | && value && opts->x_flag_ipa_cp) | |
1715 | opts->x_flag_ipa_bit_cp = value; | |
be3c16c4 DC |
1716 | if (!opts_set->x_flag_predictive_commoning) |
1717 | opts->x_flag_predictive_commoning = value; | |
28df8730 MM |
1718 | if (!opts_set->x_flag_split_loops) |
1719 | opts->x_flag_split_loops = value; | |
be3c16c4 DC |
1720 | if (!opts_set->x_flag_unswitch_loops) |
1721 | opts->x_flag_unswitch_loops = value; | |
1722 | if (!opts_set->x_flag_gcse_after_reload) | |
1723 | opts->x_flag_gcse_after_reload = value; | |
26d476cd | 1724 | if (!opts_set->x_flag_tree_loop_vectorize) |
be3c16c4 | 1725 | opts->x_flag_tree_loop_vectorize = value; |
26d476cd | 1726 | if (!opts_set->x_flag_tree_slp_vectorize) |
be3c16c4 | 1727 | opts->x_flag_tree_slp_vectorize = value; |
a9a32e56 JH |
1728 | if (!opts_set->x_flag_version_loops_for_strides) |
1729 | opts->x_flag_version_loops_for_strides = value; | |
be3c16c4 DC |
1730 | if (!opts_set->x_flag_vect_cost_model) |
1731 | opts->x_flag_vect_cost_model = VECT_COST_MODEL_DYNAMIC; | |
1732 | if (!opts_set->x_flag_tree_loop_distribute_patterns) | |
1733 | opts->x_flag_tree_loop_distribute_patterns = value; | |
a9a32e56 JH |
1734 | if (!opts_set->x_flag_loop_interchange) |
1735 | opts->x_flag_loop_interchange = value; | |
1736 | if (!opts_set->x_flag_unroll_jam) | |
1737 | opts->x_flag_unroll_jam = value; | |
1738 | if (!opts_set->x_flag_tree_loop_distribution) | |
1739 | opts->x_flag_tree_loop_distribution = value; | |
be3c16c4 DC |
1740 | } |
1741 | ||
b1b46af0 | 1742 | /* -f{,no-}sanitize{,-recover}= suboptions. */ |
61789eed | 1743 | const struct sanitizer_opts_s sanitizer_opts[] = |
b1b46af0 | 1744 | { |
5cc6c41c ML |
1745 | #define SANITIZER_OPT(name, flags, recover) \ |
1746 | { #name, flags, sizeof #name - 1, recover } | |
6dc4a604 ML |
1747 | SANITIZER_OPT (address, (SANITIZE_ADDRESS | SANITIZE_USER_ADDRESS), true), |
1748 | SANITIZER_OPT (kernel-address, (SANITIZE_ADDRESS | SANITIZE_KERNEL_ADDRESS), | |
5cc6c41c | 1749 | true), |
05abad4c ML |
1750 | SANITIZER_OPT (pointer-compare, SANITIZE_POINTER_COMPARE, true), |
1751 | SANITIZER_OPT (pointer-subtract, SANITIZE_POINTER_SUBTRACT, true), | |
5cc6c41c ML |
1752 | SANITIZER_OPT (thread, SANITIZE_THREAD, false), |
1753 | SANITIZER_OPT (leak, SANITIZE_LEAK, false), | |
1754 | SANITIZER_OPT (shift, SANITIZE_SHIFT, true), | |
2e955d50 JJ |
1755 | SANITIZER_OPT (shift-base, SANITIZE_SHIFT_BASE, true), |
1756 | SANITIZER_OPT (shift-exponent, SANITIZE_SHIFT_EXPONENT, true), | |
5cc6c41c ML |
1757 | SANITIZER_OPT (integer-divide-by-zero, SANITIZE_DIVIDE, true), |
1758 | SANITIZER_OPT (undefined, SANITIZE_UNDEFINED, true), | |
1759 | SANITIZER_OPT (unreachable, SANITIZE_UNREACHABLE, false), | |
1760 | SANITIZER_OPT (vla-bound, SANITIZE_VLA, true), | |
1761 | SANITIZER_OPT (return, SANITIZE_RETURN, false), | |
1762 | SANITIZER_OPT (null, SANITIZE_NULL, true), | |
1763 | SANITIZER_OPT (signed-integer-overflow, SANITIZE_SI_OVERFLOW, true), | |
1764 | SANITIZER_OPT (bool, SANITIZE_BOOL, true), | |
1765 | SANITIZER_OPT (enum, SANITIZE_ENUM, true), | |
1766 | SANITIZER_OPT (float-divide-by-zero, SANITIZE_FLOAT_DIVIDE, true), | |
1767 | SANITIZER_OPT (float-cast-overflow, SANITIZE_FLOAT_CAST, true), | |
1768 | SANITIZER_OPT (bounds, SANITIZE_BOUNDS, true), | |
1769 | SANITIZER_OPT (bounds-strict, SANITIZE_BOUNDS | SANITIZE_BOUNDS_STRICT, true), | |
1770 | SANITIZER_OPT (alignment, SANITIZE_ALIGNMENT, true), | |
1771 | SANITIZER_OPT (nonnull-attribute, SANITIZE_NONNULL_ATTRIBUTE, true), | |
1772 | SANITIZER_OPT (returns-nonnull-attribute, SANITIZE_RETURNS_NONNULL_ATTRIBUTE, | |
1773 | true), | |
1774 | SANITIZER_OPT (object-size, SANITIZE_OBJECT_SIZE, true), | |
1775 | SANITIZER_OPT (vptr, SANITIZE_VPTR, true), | |
c9b39a49 | 1776 | SANITIZER_OPT (pointer-overflow, SANITIZE_POINTER_OVERFLOW, true), |
07d7c611 | 1777 | SANITIZER_OPT (builtin, SANITIZE_BUILTIN, true), |
5cc6c41c | 1778 | SANITIZER_OPT (all, ~0U, true), |
b1b46af0 | 1779 | #undef SANITIZER_OPT |
5cc6c41c | 1780 | { NULL, 0U, 0UL, false } |
b1b46af0 JJ |
1781 | }; |
1782 | ||
f6e50a7d WW |
1783 | /* -f{,no-}sanitize-coverage= suboptions. */ |
1784 | const struct sanitizer_opts_s coverage_sanitizer_opts[] = | |
1785 | { | |
1786 | #define COVERAGE_SANITIZER_OPT(name, flags) \ | |
1787 | { #name, flags, sizeof #name - 1, true } | |
1788 | COVERAGE_SANITIZER_OPT (trace-pc, SANITIZE_COV_TRACE_PC), | |
1789 | COVERAGE_SANITIZER_OPT (trace-cmp, SANITIZE_COV_TRACE_CMP), | |
1790 | #undef COVERAGE_SANITIZER_OPT | |
1791 | { NULL, 0U, 0UL, false } | |
1792 | }; | |
1793 | ||
19ff0049 DM |
1794 | /* A struct for describing a run of chars within a string. */ |
1795 | ||
6c1dae73 | 1796 | class string_fragment |
19ff0049 | 1797 | { |
6c1dae73 | 1798 | public: |
19ff0049 DM |
1799 | string_fragment (const char *start, size_t len) |
1800 | : m_start (start), m_len (len) {} | |
1801 | ||
1802 | const char *m_start; | |
1803 | size_t m_len; | |
1804 | }; | |
1805 | ||
1806 | /* Specialization of edit_distance_traits for string_fragment, | |
1807 | for use by get_closest_sanitizer_option. */ | |
1808 | ||
1809 | template <> | |
1810 | struct edit_distance_traits<const string_fragment &> | |
1811 | { | |
1812 | static size_t get_length (const string_fragment &fragment) | |
1813 | { | |
1814 | return fragment.m_len; | |
1815 | } | |
1816 | ||
1817 | static const char *get_string (const string_fragment &fragment) | |
1818 | { | |
1819 | return fragment.m_start; | |
1820 | } | |
1821 | }; | |
1822 | ||
1823 | /* Given ARG, an unrecognized sanitizer option, return the best | |
1824 | matching sanitizer option, or NULL if there isn't one. | |
f6e50a7d WW |
1825 | OPTS is array of candidate sanitizer options. |
1826 | CODE is OPT_fsanitize_, OPT_fsanitize_recover_ or | |
1827 | OPT_fsanitize_coverage_. | |
19ff0049 DM |
1828 | VALUE is non-zero for the regular form of the option, zero |
1829 | for the "no-" form (e.g. "-fno-sanitize-recover="). */ | |
1830 | ||
1831 | static const char * | |
1832 | get_closest_sanitizer_option (const string_fragment &arg, | |
f6e50a7d | 1833 | const struct sanitizer_opts_s *opts, |
19ff0049 DM |
1834 | enum opt_code code, int value) |
1835 | { | |
1836 | best_match <const string_fragment &, const char*> bm (arg); | |
f6e50a7d | 1837 | for (int i = 0; opts[i].name != NULL; ++i) |
19ff0049 DM |
1838 | { |
1839 | /* -fsanitize=all is not valid, so don't offer it. */ | |
f6e50a7d WW |
1840 | if (code == OPT_fsanitize_ |
1841 | && opts[i].flag == ~0U | |
19ff0049 DM |
1842 | && value) |
1843 | continue; | |
1844 | ||
1845 | /* For -fsanitize-recover= (and not -fno-sanitize-recover=), | |
1846 | don't offer the non-recoverable options. */ | |
f6e50a7d WW |
1847 | if (code == OPT_fsanitize_recover_ |
1848 | && !opts[i].can_recover | |
19ff0049 DM |
1849 | && value) |
1850 | continue; | |
1851 | ||
f6e50a7d | 1852 | bm.consider (opts[i].name); |
19ff0049 DM |
1853 | } |
1854 | return bm.get_best_meaningful_candidate (); | |
1855 | } | |
1856 | ||
b1b46af0 JJ |
1857 | /* Parse comma separated sanitizer suboptions from P for option SCODE, |
1858 | adjust previous FLAGS and return new ones. If COMPLAIN is false, | |
1859 | don't issue diagnostics. */ | |
1860 | ||
1861 | unsigned int | |
1862 | parse_sanitizer_options (const char *p, location_t loc, int scode, | |
1863 | unsigned int flags, int value, bool complain) | |
1864 | { | |
1865 | enum opt_code code = (enum opt_code) scode; | |
f6e50a7d WW |
1866 | |
1867 | const struct sanitizer_opts_s *opts; | |
1868 | if (code == OPT_fsanitize_coverage_) | |
1869 | opts = coverage_sanitizer_opts; | |
1870 | else | |
1871 | opts = sanitizer_opts; | |
1872 | ||
b1b46af0 JJ |
1873 | while (*p != 0) |
1874 | { | |
1875 | size_t len, i; | |
1876 | bool found = false; | |
1877 | const char *comma = strchr (p, ','); | |
1878 | ||
1879 | if (comma == NULL) | |
1880 | len = strlen (p); | |
1881 | else | |
1882 | len = comma - p; | |
1883 | if (len == 0) | |
1884 | { | |
1885 | p = comma + 1; | |
1886 | continue; | |
1887 | } | |
1888 | ||
1889 | /* Check to see if the string matches an option class name. */ | |
f6e50a7d WW |
1890 | for (i = 0; opts[i].name != NULL; ++i) |
1891 | if (len == opts[i].len && memcmp (p, opts[i].name, len) == 0) | |
b1b46af0 JJ |
1892 | { |
1893 | /* Handle both -fsanitize and -fno-sanitize cases. */ | |
f6e50a7d | 1894 | if (value && opts[i].flag == ~0U) |
b1b46af0 JJ |
1895 | { |
1896 | if (code == OPT_fsanitize_) | |
1897 | { | |
1898 | if (complain) | |
6d28654e | 1899 | error_at (loc, "%<-fsanitize=all%> option is not valid"); |
b1b46af0 JJ |
1900 | } |
1901 | else | |
5cc6c41c ML |
1902 | flags |= ~(SANITIZE_THREAD | SANITIZE_LEAK |
1903 | | SANITIZE_UNREACHABLE | SANITIZE_RETURN); | |
b1b46af0 JJ |
1904 | } |
1905 | else if (value) | |
5cc6c41c ML |
1906 | { |
1907 | /* Do not enable -fsanitize-recover=unreachable and | |
1908 | -fsanitize-recover=return if -fsanitize-recover=undefined | |
1909 | is selected. */ | |
c944c6a2 | 1910 | if (code == OPT_fsanitize_recover_ |
f6e50a7d | 1911 | && opts[i].flag == SANITIZE_UNDEFINED) |
5cc6c41c ML |
1912 | flags |= (SANITIZE_UNDEFINED |
1913 | & ~(SANITIZE_UNREACHABLE | SANITIZE_RETURN)); | |
1914 | else | |
f6e50a7d | 1915 | flags |= opts[i].flag; |
5cc6c41c | 1916 | } |
b1b46af0 | 1917 | else |
f6e50a7d | 1918 | flags &= ~opts[i].flag; |
b1b46af0 JJ |
1919 | found = true; |
1920 | break; | |
1921 | } | |
1922 | ||
1923 | if (! found && complain) | |
19ff0049 DM |
1924 | { |
1925 | const char *hint | |
1926 | = get_closest_sanitizer_option (string_fragment (p, len), | |
f6e50a7d WW |
1927 | opts, code, value); |
1928 | ||
1929 | const char *suffix; | |
1930 | if (code == OPT_fsanitize_recover_) | |
1931 | suffix = "-recover"; | |
1932 | else if (code == OPT_fsanitize_coverage_) | |
1933 | suffix = "-coverage"; | |
1934 | else | |
1935 | suffix = ""; | |
19ff0049 DM |
1936 | |
1937 | if (hint) | |
1938 | error_at (loc, | |
a3f9f006 ML |
1939 | "unrecognized argument to %<-f%ssanitize%s=%> " |
1940 | "option: %q.*s; did you mean %qs?", | |
19ff0049 | 1941 | value ? "" : "no-", |
f6e50a7d | 1942 | suffix, (int) len, p, hint); |
19ff0049 DM |
1943 | else |
1944 | error_at (loc, | |
a3f9f006 ML |
1945 | "unrecognized argument to %<-f%ssanitize%s=%> option: " |
1946 | "%q.*s", value ? "" : "no-", | |
f6e50a7d | 1947 | suffix, (int) len, p); |
19ff0049 | 1948 | } |
b1b46af0 JJ |
1949 | |
1950 | if (comma == NULL) | |
1951 | break; | |
1952 | p = comma + 1; | |
1953 | } | |
1954 | return flags; | |
1955 | } | |
1956 | ||
45b2222a | 1957 | /* Parse string values of no_sanitize attribute passed in VALUE. |
3a266bcd | 1958 | Values are separated with comma. */ |
45b2222a ML |
1959 | |
1960 | unsigned int | |
3a266bcd | 1961 | parse_no_sanitize_attribute (char *value) |
45b2222a ML |
1962 | { |
1963 | unsigned int flags = 0; | |
1964 | unsigned int i; | |
1965 | char *q = strtok (value, ","); | |
1966 | ||
1967 | while (q != NULL) | |
1968 | { | |
1969 | for (i = 0; sanitizer_opts[i].name != NULL; ++i) | |
1970 | if (strcmp (sanitizer_opts[i].name, q) == 0) | |
1971 | { | |
1972 | flags |= sanitizer_opts[i].flag; | |
1973 | if (sanitizer_opts[i].flag == SANITIZE_UNDEFINED) | |
1974 | flags |= SANITIZE_UNDEFINED_NONDEFAULT; | |
1975 | break; | |
1976 | } | |
1977 | ||
1978 | if (sanitizer_opts[i].name == NULL) | |
3a266bcd | 1979 | warning (OPT_Wattributes, |
a9c697b8 | 1980 | "%qs attribute directive ignored", q); |
45b2222a ML |
1981 | |
1982 | q = strtok (NULL, ","); | |
1983 | } | |
1984 | ||
1985 | return flags; | |
1986 | } | |
1987 | ||
c518c102 ML |
1988 | /* Parse -falign-NAME format for a FLAG value. Return individual |
1989 | parsed integer values into RESULT_VALUES array. If REPORT_ERROR is | |
1990 | set, print error message at LOC location. */ | |
1991 | ||
1992 | bool | |
1993 | parse_and_check_align_values (const char *flag, | |
1994 | const char *name, | |
1995 | auto_vec<unsigned> &result_values, | |
1996 | bool report_error, | |
1997 | location_t loc) | |
1998 | { | |
1999 | char *str = xstrdup (flag); | |
2000 | for (char *p = strtok (str, ":"); p; p = strtok (NULL, ":")) | |
2001 | { | |
2002 | char *end; | |
2003 | int v = strtol (p, &end, 10); | |
2004 | if (*end != '\0' || v < 0) | |
2005 | { | |
2006 | if (report_error) | |
2007 | error_at (loc, "invalid arguments for %<-falign-%s%> option: %qs", | |
2008 | name, flag); | |
2009 | ||
2010 | return false; | |
2011 | } | |
2012 | ||
2013 | result_values.safe_push ((unsigned)v); | |
2014 | } | |
2015 | ||
2016 | free (str); | |
2017 | ||
2018 | /* Check that we have a correct number of values. */ | |
49f3f450 | 2019 | if (result_values.is_empty () || result_values.length () > 4) |
c518c102 ML |
2020 | { |
2021 | if (report_error) | |
2022 | error_at (loc, "invalid number of arguments for %<-falign-%s%> " | |
2023 | "option: %qs", name, flag); | |
2024 | return false; | |
2025 | } | |
2026 | ||
c518c102 ML |
2027 | for (unsigned i = 0; i < result_values.length (); i++) |
2028 | if (result_values[i] > MAX_CODE_ALIGN_VALUE) | |
2029 | { | |
2030 | if (report_error) | |
2031 | error_at (loc, "%<-falign-%s%> is not between 0 and %d", | |
2032 | name, MAX_CODE_ALIGN_VALUE); | |
2033 | return false; | |
2034 | } | |
2035 | ||
2036 | return true; | |
2037 | } | |
2038 | ||
2039 | /* Check that alignment value FLAG for -falign-NAME is valid at a given | |
2040 | location LOC. */ | |
2041 | ||
2042 | static void | |
2043 | check_alignment_argument (location_t loc, const char *flag, const char *name) | |
2044 | { | |
2045 | auto_vec<unsigned> align_result; | |
2046 | parse_and_check_align_values (flag, name, align_result, true, loc); | |
2047 | } | |
2048 | ||
2dcfc872 ML |
2049 | /* Print help when OPT__help_ is set. */ |
2050 | ||
f66409e0 | 2051 | void |
bc405869 ML |
2052 | print_help (struct gcc_options *opts, unsigned int lang_mask, |
2053 | const char *help_option_argument) | |
2dcfc872 ML |
2054 | { |
2055 | const char *a = help_option_argument; | |
2056 | unsigned int include_flags = 0; | |
2057 | /* Note - by default we include undocumented options when listing | |
2058 | specific classes. If you only want to see documented options | |
2059 | then add ",^undocumented" to the --help= option. E.g.: | |
2060 | ||
2061 | --help=target,^undocumented */ | |
2062 | unsigned int exclude_flags = 0; | |
2063 | ||
2064 | if (lang_mask == CL_DRIVER) | |
2065 | return; | |
2066 | ||
2067 | /* Walk along the argument string, parsing each word in turn. | |
2068 | The format is: | |
2069 | arg = [^]{word}[,{arg}] | |
2070 | word = {optimizers|target|warnings|undocumented| | |
2071 | params|common|<language>} */ | |
2072 | while (*a != 0) | |
2073 | { | |
2074 | static const struct | |
2075 | { | |
2076 | const char *string; | |
2077 | unsigned int flag; | |
2078 | } | |
2079 | specifics[] = | |
2080 | { | |
2081 | { "optimizers", CL_OPTIMIZATION }, | |
2082 | { "target", CL_TARGET }, | |
2083 | { "warnings", CL_WARNING }, | |
2084 | { "undocumented", CL_UNDOCUMENTED }, | |
2085 | { "params", CL_PARAMS }, | |
2086 | { "joined", CL_JOINED }, | |
2087 | { "separate", CL_SEPARATE }, | |
2088 | { "common", CL_COMMON }, | |
2089 | { NULL, 0 } | |
2090 | }; | |
2091 | unsigned int *pflags; | |
2092 | const char *comma; | |
2093 | unsigned int lang_flag, specific_flag; | |
2094 | unsigned int len; | |
2095 | unsigned int i; | |
2096 | ||
2097 | if (*a == '^') | |
2098 | { | |
2099 | ++a; | |
2100 | if (*a == '\0') | |
2101 | { | |
2102 | error ("missing argument to %qs", "--help=^"); | |
2103 | break; | |
2104 | } | |
2105 | pflags = &exclude_flags; | |
2106 | } | |
2107 | else | |
2108 | pflags = &include_flags; | |
2109 | ||
2110 | comma = strchr (a, ','); | |
2111 | if (comma == NULL) | |
2112 | len = strlen (a); | |
2113 | else | |
2114 | len = comma - a; | |
2115 | if (len == 0) | |
2116 | { | |
2117 | a = comma + 1; | |
2118 | continue; | |
2119 | } | |
2120 | ||
2121 | /* Check to see if the string matches an option class name. */ | |
2122 | for (i = 0, specific_flag = 0; specifics[i].string != NULL; i++) | |
2123 | if (strncasecmp (a, specifics[i].string, len) == 0) | |
2124 | { | |
2125 | specific_flag = specifics[i].flag; | |
2126 | break; | |
2127 | } | |
2128 | ||
2129 | /* Check to see if the string matches a language name. | |
2130 | Note - we rely upon the alpha-sorted nature of the entries in | |
2131 | the lang_names array, specifically that shorter names appear | |
2132 | before their longer variants. (i.e. C before C++). That way | |
2133 | when we are attempting to match --help=c for example we will | |
2134 | match with C first and not C++. */ | |
2135 | for (i = 0, lang_flag = 0; i < cl_lang_count; i++) | |
2136 | if (strncasecmp (a, lang_names[i], len) == 0) | |
2137 | { | |
2138 | lang_flag = 1U << i; | |
2139 | break; | |
2140 | } | |
2141 | ||
2142 | if (specific_flag != 0) | |
2143 | { | |
2144 | if (lang_flag == 0) | |
2145 | *pflags |= specific_flag; | |
2146 | else | |
2147 | { | |
2148 | /* The option's argument matches both the start of a | |
2149 | language name and the start of an option class name. | |
2150 | We have a special case for when the user has | |
2151 | specified "--help=c", but otherwise we have to issue | |
2152 | a warning. */ | |
2153 | if (strncasecmp (a, "c", len) == 0) | |
2154 | *pflags |= lang_flag; | |
2155 | else | |
2156 | warning (0, | |
a9c697b8 | 2157 | "%<--help%> argument %q.*s is ambiguous, " |
2dcfc872 ML |
2158 | "please be more specific", |
2159 | len, a); | |
2160 | } | |
2161 | } | |
2162 | else if (lang_flag != 0) | |
2163 | *pflags |= lang_flag; | |
2164 | else | |
2165 | warning (0, | |
a9c697b8 | 2166 | "unrecognized argument to %<--help=%> option: %q.*s", |
2dcfc872 ML |
2167 | len, a); |
2168 | ||
2169 | if (comma == NULL) | |
2170 | break; | |
2171 | a = comma + 1; | |
2172 | } | |
2173 | ||
2174 | if (include_flags) | |
2175 | print_specific_help (include_flags, exclude_flags, 0, opts, | |
2176 | lang_mask); | |
2177 | } | |
2178 | ||
d7b42618 | 2179 | /* Handle target- and language-independent options. Return zero to |
50431bc4 ZD |
2180 | generate an "unknown option" message. Only options that need |
2181 | extra handling need to be listed here; if you simply want | |
481e1176 | 2182 | DECODED->value assigned to a variable, it happens automatically. */ |
50431bc4 | 2183 | |
c98cd5bf | 2184 | bool |
46625112 | 2185 | common_handle_option (struct gcc_options *opts, |
d4d24ba4 | 2186 | struct gcc_options *opts_set, |
46625112 | 2187 | const struct cl_decoded_option *decoded, |
5f20c657 | 2188 | unsigned int lang_mask, int kind ATTRIBUTE_UNUSED, |
a4d8c676 | 2189 | location_t loc, |
d5478783 | 2190 | const struct cl_option_handlers *handlers, |
130fcab0 ML |
2191 | diagnostic_context *dc, |
2192 | void (*target_option_override_hook) (void)) | |
d7b42618 | 2193 | { |
481e1176 JM |
2194 | size_t scode = decoded->opt_index; |
2195 | const char *arg = decoded->arg; | |
00abf86c | 2196 | HOST_WIDE_INT value = decoded->value; |
d7b42618 NB |
2197 | enum opt_code code = (enum opt_code) scode; |
2198 | ||
481e1176 JM |
2199 | gcc_assert (decoded->canonical_option_num_elements <= 2); |
2200 | ||
d7b42618 NB |
2201 | switch (code) |
2202 | { | |
c662432e NC |
2203 | case OPT__help: |
2204 | { | |
2205 | unsigned int all_langs_mask = (1U << cl_lang_count) - 1; | |
2206 | unsigned int undoc_mask; | |
2207 | unsigned int i; | |
2208 | ||
a7d0d30f | 2209 | if (lang_mask == CL_DRIVER) |
6f3d1a5e | 2210 | break; |
a7d0d30f | 2211 | |
d5478783 JM |
2212 | undoc_mask = ((opts->x_verbose_flag | opts->x_extra_warnings) |
2213 | ? 0 | |
2214 | : CL_UNDOCUMENTED); | |
130fcab0 | 2215 | target_option_override_hook (); |
c662432e NC |
2216 | /* First display any single language specific options. */ |
2217 | for (i = 0; i < cl_lang_count; i++) | |
2218 | print_specific_help | |
e6d4b984 JM |
2219 | (1U << i, (all_langs_mask & (~ (1U << i))) | undoc_mask, 0, opts, |
2220 | lang_mask); | |
c662432e | 2221 | /* Next display any multi language specific options. */ |
e6d4b984 | 2222 | print_specific_help (0, undoc_mask, all_langs_mask, opts, lang_mask); |
c662432e NC |
2223 | /* Then display any remaining, non-language options. */ |
2224 | for (i = CL_MIN_OPTION_CLASS; i <= CL_MAX_OPTION_CLASS; i <<= 1) | |
603349bf | 2225 | if (i != CL_DRIVER) |
e6d4b984 | 2226 | print_specific_help (i, undoc_mask, 0, opts, lang_mask); |
0576d21f | 2227 | opts->x_exit_after_options = true; |
c662432e NC |
2228 | break; |
2229 | } | |
2230 | ||
d185d268 | 2231 | case OPT__target_help: |
a7d0d30f JM |
2232 | if (lang_mask == CL_DRIVER) |
2233 | break; | |
2234 | ||
130fcab0 | 2235 | target_option_override_hook (); |
e6d4b984 | 2236 | print_specific_help (CL_TARGET, CL_UNDOCUMENTED, 0, opts, lang_mask); |
0576d21f | 2237 | opts->x_exit_after_options = true; |
d185d268 NB |
2238 | break; |
2239 | ||
c662432e NC |
2240 | case OPT__help_: |
2241 | { | |
bc405869 | 2242 | help_option_arguments.safe_push (arg); |
0576d21f | 2243 | opts->x_exit_after_options = true; |
c662432e NC |
2244 | break; |
2245 | } | |
2246 | ||
d185d268 | 2247 | case OPT__version: |
a7d0d30f JM |
2248 | if (lang_mask == CL_DRIVER) |
2249 | break; | |
2250 | ||
0576d21f | 2251 | opts->x_exit_after_options = true; |
d185d268 NB |
2252 | break; |
2253 | ||
d86c7648 ML |
2254 | case OPT__completion_: |
2255 | break; | |
2256 | ||
de5a5fa1 | 2257 | case OPT_fsanitize_: |
b1b46af0 JJ |
2258 | opts->x_flag_sanitize |
2259 | = parse_sanitizer_options (arg, loc, code, | |
2260 | opts->x_flag_sanitize, value, true); | |
de5a5fa1 | 2261 | |
b1b46af0 JJ |
2262 | /* Kernel ASan implies normal ASan but does not yet support |
2263 | all features. */ | |
2264 | if (opts->x_flag_sanitize & SANITIZE_KERNEL_ADDRESS) | |
2265 | { | |
028d4092 ML |
2266 | SET_OPTION_IF_UNSET (opts, opts_set, |
2267 | param_asan_instrumentation_with_call_threshold, | |
2268 | 0); | |
2269 | SET_OPTION_IF_UNSET (opts, opts_set, param_asan_globals, 0); | |
2270 | SET_OPTION_IF_UNSET (opts, opts_set, param_asan_stack, 0); | |
2271 | SET_OPTION_IF_UNSET (opts, opts_set, param_asan_protect_allocas, 0); | |
2272 | SET_OPTION_IF_UNSET (opts, opts_set, param_asan_use_after_return, 0); | |
b1b46af0 JJ |
2273 | } |
2274 | break; | |
fec4842d | 2275 | |
b1b46af0 JJ |
2276 | case OPT_fsanitize_recover_: |
2277 | opts->x_flag_sanitize_recover | |
2278 | = parse_sanitizer_options (arg, loc, code, | |
2279 | opts->x_flag_sanitize_recover, value, true); | |
2280 | break; | |
de5a5fa1 | 2281 | |
fd960af2 YG |
2282 | case OPT_fasan_shadow_offset_: |
2283 | /* Deferred. */ | |
2284 | break; | |
2285 | ||
6dc4a604 ML |
2286 | case OPT_fsanitize_address_use_after_scope: |
2287 | opts->x_flag_sanitize_address_use_after_scope = value; | |
2288 | break; | |
2289 | ||
d95a2703 JJ |
2290 | case OPT_fsanitize_recover: |
2291 | if (value) | |
2292 | opts->x_flag_sanitize_recover | |
45b2222a | 2293 | |= (SANITIZE_UNDEFINED | SANITIZE_UNDEFINED_NONDEFAULT) |
5cc6c41c | 2294 | & ~(SANITIZE_UNREACHABLE | SANITIZE_RETURN); |
d95a2703 JJ |
2295 | else |
2296 | opts->x_flag_sanitize_recover | |
45b2222a | 2297 | &= ~(SANITIZE_UNDEFINED | SANITIZE_UNDEFINED_NONDEFAULT); |
d95a2703 JJ |
2298 | break; |
2299 | ||
f6e50a7d WW |
2300 | case OPT_fsanitize_coverage_: |
2301 | opts->x_flag_sanitize_coverage | |
2302 | = parse_sanitizer_options (arg, loc, code, | |
2303 | opts->x_flag_sanitize_coverage, value, true); | |
2304 | break; | |
2305 | ||
903caebf NB |
2306 | case OPT_O: |
2307 | case OPT_Os: | |
c3a02647 | 2308 | case OPT_Ofast: |
bf7a7185 | 2309 | case OPT_Og: |
903caebf NB |
2310 | /* Currently handled in a prescan. */ |
2311 | break; | |
2312 | ||
aee15221 RG |
2313 | case OPT_Werror: |
2314 | dc->warning_as_error_requested = value; | |
2315 | break; | |
2316 | ||
79cf5994 | 2317 | case OPT_Werror_: |
a7d0d30f JM |
2318 | if (lang_mask == CL_DRIVER) |
2319 | break; | |
2320 | ||
c5fa0890 JM |
2321 | enable_warning_as_error (arg, value, lang_mask, handlers, |
2322 | opts, opts_set, loc, dc); | |
79cf5994 DD |
2323 | break; |
2324 | ||
5f0f4a3b | 2325 | case OPT_Wfatal_errors: |
d5478783 | 2326 | dc->fatal_errors = value; |
5f0f4a3b JM |
2327 | break; |
2328 | ||
a11e0df4 | 2329 | case OPT_Wstack_usage_: |
a11e0df4 EB |
2330 | opts->x_flag_stack_usage_info = value != -1; |
2331 | break; | |
2332 | ||
e01cc6dc | 2333 | case OPT_Wstrict_aliasing: |
d5478783 | 2334 | set_Wstrict_aliasing (opts, value); |
e01cc6dc NB |
2335 | break; |
2336 | ||
6ac01510 | 2337 | case OPT_Wstrict_overflow: |
d5478783 JM |
2338 | opts->x_warn_strict_overflow = (value |
2339 | ? (int) WARN_STRICT_OVERFLOW_CONDITIONAL | |
2340 | : 0); | |
6ac01510 ILT |
2341 | break; |
2342 | ||
5f0f4a3b | 2343 | case OPT_Wsystem_headers: |
d5478783 | 2344 | dc->dc_warn_system_headers = value; |
903caebf NB |
2345 | break; |
2346 | ||
d185d268 | 2347 | case OPT_aux_info: |
d5478783 | 2348 | opts->x_flag_gen_aux_info = 1; |
d185d268 NB |
2349 | break; |
2350 | ||
2351 | case OPT_auxbase_strip: | |
2352 | { | |
2353 | char *tmp = xstrdup (arg); | |
2354 | strip_off_ending (tmp, strlen (tmp)); | |
2355 | if (tmp[0]) | |
d5478783 | 2356 | opts->x_aux_base_name = tmp; |
fc429b48 TB |
2357 | else |
2358 | free (tmp); | |
d185d268 NB |
2359 | } |
2360 | break; | |
2361 | ||
2362 | case OPT_d: | |
299404a1 | 2363 | decode_d_option (arg, opts, loc, dc); |
d185d268 NB |
2364 | break; |
2365 | ||
058de654 | 2366 | case OPT_fcall_used_: |
058de654 | 2367 | case OPT_fcall_saved_: |
21bf1558 | 2368 | /* Deferred. */ |
058de654 | 2369 | break; |
6fb5fa3c DB |
2370 | |
2371 | case OPT_fdbg_cnt_: | |
68d070ac ML |
2372 | /* Deferred. */ |
2373 | break; | |
2374 | ||
0a090f42 | 2375 | case OPT_fdbg_cnt_list: |
299404a1 | 2376 | /* Deferred. */ |
68d070ac | 2377 | opts->x_exit_after_options = true; |
0a090f42 | 2378 | break; |
058de654 | 2379 | |
c8aea42c | 2380 | case OPT_fdebug_prefix_map_: |
7365279f | 2381 | case OPT_ffile_prefix_map_: |
299404a1 | 2382 | /* Deferred. */ |
c8aea42c PB |
2383 | break; |
2384 | ||
3cf3da88 EB |
2385 | case OPT_fcallgraph_info: |
2386 | opts->x_flag_callgraph_info = CALLGRAPH_INFO_NAKED; | |
2387 | break; | |
2388 | ||
2389 | case OPT_fcallgraph_info_: | |
2390 | { | |
2391 | char *my_arg, *p; | |
2392 | my_arg = xstrdup (arg); | |
2393 | p = strtok (my_arg, ","); | |
2394 | while (p) | |
2395 | { | |
2396 | if (strcmp (p, "su") == 0) | |
2397 | { | |
2398 | opts->x_flag_callgraph_info |= CALLGRAPH_INFO_STACK_USAGE; | |
2399 | opts->x_flag_stack_usage_info = true; | |
2400 | } | |
2401 | else if (strcmp (p, "da") == 0) | |
2402 | opts->x_flag_callgraph_info |= CALLGRAPH_INFO_DYNAMIC_ALLOC; | |
2403 | else | |
2404 | return 0; | |
2405 | p = strtok (NULL, ","); | |
2406 | } | |
2407 | free (my_arg); | |
2408 | } | |
2409 | break; | |
2410 | ||
de32c0cb | 2411 | case OPT_fdiagnostics_show_location_: |
e6d4b984 | 2412 | diagnostic_prefixing_rule (dc) = (diagnostic_prefixing_rule_t) value; |
de32c0cb | 2413 | break; |
9fec0042 MLI |
2414 | |
2415 | case OPT_fdiagnostics_show_caret: | |
2416 | dc->show_caret = value; | |
2417 | break; | |
de32c0cb | 2418 | |
96e6ae57 DM |
2419 | case OPT_fdiagnostics_show_labels: |
2420 | dc->show_labels_p = value; | |
2421 | break; | |
2422 | ||
56b61d7f DM |
2423 | case OPT_fdiagnostics_show_line_numbers: |
2424 | dc->show_line_numbers_p = value; | |
2425 | break; | |
2426 | ||
4b84d650 | 2427 | case OPT_fdiagnostics_color_: |
97aa8bb6 | 2428 | diagnostic_color_init (dc, value); |
4b84d650 JJ |
2429 | break; |
2430 | ||
d2608235 DM |
2431 | case OPT_fdiagnostics_urls_: |
2432 | diagnostic_urls_init (dc, value); | |
2433 | break; | |
2434 | ||
478dd60d DM |
2435 | case OPT_fdiagnostics_format_: |
2436 | diagnostic_output_format_init (dc, | |
2437 | (enum diagnostics_output_format)value); | |
2438 | break; | |
2439 | ||
a93eac6a DM |
2440 | case OPT_fdiagnostics_parseable_fixits: |
2441 | dc->parseable_fixits_p = value; | |
2442 | break; | |
2443 | ||
2098fe9e | 2444 | case OPT_fdiagnostics_show_option: |
d5478783 | 2445 | dc->show_option_requested = value; |
2098fe9e DD |
2446 | break; |
2447 | ||
0141ab44 DM |
2448 | case OPT_fdiagnostics_minimum_margin_width_: |
2449 | dc->min_margin_width = value; | |
2450 | break; | |
2451 | ||
6de9cd9a | 2452 | case OPT_fdump_: |
21bf1558 | 2453 | /* Deferred. */ |
6de9cd9a DN |
2454 | break; |
2455 | ||
058de654 | 2456 | case OPT_ffast_math: |
d5478783 | 2457 | set_fast_math_flags (opts, value); |
058de654 NB |
2458 | break; |
2459 | ||
a1a82611 | 2460 | case OPT_funsafe_math_optimizations: |
d5478783 | 2461 | set_unsafe_math_optimizations_flags (opts, value); |
a1a82611 RE |
2462 | break; |
2463 | ||
058de654 | 2464 | case OPT_ffixed_: |
21bf1558 | 2465 | /* Deferred. */ |
058de654 NB |
2466 | break; |
2467 | ||
d302c9d6 | 2468 | case OPT_finline_limit_: |
48476d13 JM |
2469 | set_param_value ("max-inline-insns-single", value / 2, |
2470 | opts->x_param_values, opts_set->x_param_values); | |
2471 | set_param_value ("max-inline-insns-auto", value / 2, | |
2472 | opts->x_param_values, opts_set->x_param_values); | |
d302c9d6 NB |
2473 | break; |
2474 | ||
8d5a7d1f | 2475 | case OPT_finstrument_functions_exclude_function_list_: |
1ebc7e68 | 2476 | add_comma_separated_to_vector |
6a1f6c9c | 2477 | (&opts->x_flag_instrument_functions_exclude_functions, arg); |
8d5a7d1f ILT |
2478 | break; |
2479 | ||
2480 | case OPT_finstrument_functions_exclude_file_list_: | |
1ebc7e68 | 2481 | add_comma_separated_to_vector |
6a1f6c9c | 2482 | (&opts->x_flag_instrument_functions_exclude_files, arg); |
8d5a7d1f ILT |
2483 | break; |
2484 | ||
de32c0cb | 2485 | case OPT_fmessage_length_: |
d5478783 | 2486 | pp_set_line_maximum_length (dc->printer, value); |
9fec0042 | 2487 | diagnostic_set_caret_max_width (dc, value); |
de32c0cb NB |
2488 | break; |
2489 | ||
78c60e3d SS |
2490 | case OPT_fopt_info: |
2491 | case OPT_fopt_info_: | |
2492 | /* Deferred. */ | |
2493 | break; | |
2494 | ||
c713ddc0 | 2495 | case OPT_foffload_: |
b2b40051 MJ |
2496 | { |
2497 | const char *p = arg; | |
2498 | opts->x_flag_disable_hsa = true; | |
2499 | while (*p != 0) | |
2500 | { | |
2501 | const char *comma = strchr (p, ','); | |
2502 | ||
2503 | if ((strncmp (p, "disable", 7) == 0) | |
2504 | && (p[7] == ',' || p[7] == '\0')) | |
2505 | { | |
2506 | opts->x_flag_disable_hsa = true; | |
2507 | break; | |
2508 | } | |
2509 | ||
2510 | if ((strncmp (p, "hsa", 3) == 0) | |
2511 | && (p[3] == ',' || p[3] == '\0')) | |
2512 | { | |
2513 | #ifdef ENABLE_HSA | |
2514 | opts->x_flag_disable_hsa = false; | |
2515 | #else | |
2516 | sorry ("HSA has not been enabled during configuration"); | |
2517 | #endif | |
2518 | } | |
2519 | if (!comma) | |
2520 | break; | |
2521 | p = comma + 1; | |
2522 | } | |
2523 | break; | |
2524 | } | |
c713ddc0 BS |
2525 | |
2526 | #ifndef ACCEL_COMPILER | |
2527 | case OPT_foffload_abi_: | |
4f4b35a0 | 2528 | error_at (loc, "%<-foffload-abi%> option can be specified only for " |
c713ddc0 BS |
2529 | "offload compiler"); |
2530 | break; | |
2531 | #endif | |
2532 | ||
467cecf3 JB |
2533 | case OPT_fpack_struct_: |
2534 | if (value <= 0 || (value & (value - 1)) || value > 16) | |
299404a1 | 2535 | error_at (loc, |
00abf86c | 2536 | "structure alignment must be a small power of two, not %wu", |
299404a1 | 2537 | value); |
467cecf3 | 2538 | else |
299404a1 | 2539 | opts->x_initial_max_fld_align = value; |
467cecf3 JB |
2540 | break; |
2541 | ||
68a607d8 | 2542 | case OPT_fplugin_: |
68a607d8 | 2543 | case OPT_fplugin_arg_: |
21bf1558 | 2544 | /* Deferred. */ |
68a607d8 DN |
2545 | break; |
2546 | ||
2f908293 | 2547 | case OPT_fprofile_use_: |
0576d21f | 2548 | opts->x_profile_data_prefix = xstrdup (arg); |
d5478783 | 2549 | opts->x_flag_profile_use = true; |
2f908293 SP |
2550 | value = true; |
2551 | /* No break here - do -fprofile-use processing. */ | |
191816a3 | 2552 | /* FALLTHRU */ |
a8a5f53a | 2553 | case OPT_fprofile_use: |
be3c16c4 | 2554 | enable_fdo_optimizations (opts, opts_set, value); |
9cec31f4 | 2555 | if (!opts_set->x_flag_profile_reorder_functions) |
be3c16c4 DC |
2556 | opts->x_flag_profile_reorder_functions = value; |
2557 | /* Indirect call profiling should do all useful transformations | |
2558 | speculative devirtualization does. */ | |
bbc9396b JH |
2559 | if (!opts_set->x_flag_devirtualize_speculatively |
2560 | && opts->x_flag_value_profile_transformations) | |
2561 | opts->x_flag_devirtualize_speculatively = false; | |
a8a5f53a JH |
2562 | break; |
2563 | ||
be3c16c4 DC |
2564 | case OPT_fauto_profile_: |
2565 | opts->x_auto_profile_file = xstrdup (arg); | |
2566 | opts->x_flag_auto_profile = true; | |
2567 | value = true; | |
2568 | /* No break here - do -fauto-profile processing. */ | |
191816a3 | 2569 | /* FALLTHRU */ |
be3c16c4 DC |
2570 | case OPT_fauto_profile: |
2571 | enable_fdo_optimizations (opts, opts_set, value); | |
2572 | if (!opts_set->x_flag_profile_correction) | |
2573 | opts->x_flag_profile_correction = value; | |
028d4092 ML |
2574 | SET_OPTION_IF_UNSET (opts, opts_set, |
2575 | param_early_inliner_max_iterations, 10); | |
be3c16c4 DC |
2576 | break; |
2577 | ||
2f908293 | 2578 | case OPT_fprofile_generate_: |
0576d21f | 2579 | opts->x_profile_data_prefix = xstrdup (arg); |
2f908293 SP |
2580 | value = true; |
2581 | /* No break here - do -fprofile-generate processing. */ | |
191816a3 | 2582 | /* FALLTHRU */ |
a8a5f53a | 2583 | case OPT_fprofile_generate: |
d4d24ba4 | 2584 | if (!opts_set->x_profile_arc_flag) |
d5478783 | 2585 | opts->x_profile_arc_flag = value; |
d4d24ba4 | 2586 | if (!opts_set->x_flag_profile_values) |
d5478783 | 2587 | opts->x_flag_profile_values = value; |
d4d24ba4 | 2588 | if (!opts_set->x_flag_inline_functions) |
d5478783 | 2589 | opts->x_flag_inline_functions = value; |
37731134 ML |
2590 | if (!opts_set->x_flag_ipa_bit_cp) |
2591 | opts->x_flag_ipa_bit_cp = value; | |
b0223c3e JH |
2592 | /* FIXME: Instrumentation we insert makes ipa-reference bitmaps |
2593 | quadratic. Disable the pass until better memory representation | |
2594 | is done. */ | |
1c58fe29 | 2595 | if (!opts_set->x_flag_ipa_reference) |
b0223c3e | 2596 | opts->x_flag_ipa_reference = false; |
a8a5f53a JH |
2597 | break; |
2598 | ||
417ca011 TD |
2599 | case OPT_fpatchable_function_entry_: |
2600 | { | |
2601 | char *patch_area_arg = xstrdup (arg); | |
2602 | char *comma = strchr (patch_area_arg, ','); | |
2603 | if (comma) | |
2604 | { | |
2605 | *comma = '\0'; | |
2606 | function_entry_patch_area_size = | |
2607 | integral_argument (patch_area_arg); | |
2608 | function_entry_patch_area_start = | |
2609 | integral_argument (comma + 1); | |
2610 | } | |
2611 | else | |
2612 | { | |
2613 | function_entry_patch_area_size = | |
2614 | integral_argument (patch_area_arg); | |
2615 | function_entry_patch_area_start = 0; | |
2616 | } | |
2617 | if (function_entry_patch_area_size < 0 | |
2618 | || function_entry_patch_area_start < 0 | |
2619 | || function_entry_patch_area_size | |
2620 | < function_entry_patch_area_start) | |
2621 | error ("invalid arguments for %<-fpatchable_function_entry%>"); | |
2622 | free (patch_area_arg); | |
2623 | } | |
2624 | break; | |
2625 | ||
ea0f3e87 | 2626 | case OPT_ftree_vectorize: |
26d476cd JG |
2627 | /* Automatically sets -ftree-loop-vectorize and |
2628 | -ftree-slp-vectorize. Nothing more to do here. */ | |
ea0f3e87 | 2629 | break; |
5f0f4a3b | 2630 | case OPT_fshow_column: |
d5478783 | 2631 | dc->show_column = value; |
5f0f4a3b JM |
2632 | break; |
2633 | ||
de32c0cb NB |
2634 | case OPT_frandom_seed: |
2635 | /* The real switch is -fno-random-seed. */ | |
2636 | if (value) | |
5f20c657 | 2637 | return false; |
299404a1 | 2638 | /* Deferred. */ |
de32c0cb NB |
2639 | break; |
2640 | ||
2641 | case OPT_frandom_seed_: | |
299404a1 | 2642 | /* Deferred. */ |
de32c0cb NB |
2643 | break; |
2644 | ||
de32c0cb NB |
2645 | case OPT_fsched_verbose_: |
2646 | #ifdef INSN_SCHEDULING | |
299404a1 | 2647 | /* Handled with Var in common.opt. */ |
de32c0cb NB |
2648 | break; |
2649 | #else | |
5f20c657 | 2650 | return false; |
de32c0cb NB |
2651 | #endif |
2652 | ||
569fa502 | 2653 | case OPT_fsched_stalled_insns_: |
d5478783 JM |
2654 | opts->x_flag_sched_stalled_insns = value; |
2655 | if (opts->x_flag_sched_stalled_insns == 0) | |
2656 | opts->x_flag_sched_stalled_insns = -1; | |
569fa502 DN |
2657 | break; |
2658 | ||
569fa502 | 2659 | case OPT_fsched_stalled_insns_dep_: |
d5478783 | 2660 | opts->x_flag_sched_stalled_insns_dep = value; |
569fa502 | 2661 | break; |
6ff3a151 | 2662 | |
b38f3813 EB |
2663 | case OPT_fstack_check_: |
2664 | if (!strcmp (arg, "no")) | |
5e471ea6 | 2665 | opts->x_flag_stack_check = NO_STACK_CHECK; |
b38f3813 EB |
2666 | else if (!strcmp (arg, "generic")) |
2667 | /* This is the old stack checking method. */ | |
5e471ea6 | 2668 | opts->x_flag_stack_check = STACK_CHECK_BUILTIN |
b38f3813 EB |
2669 | ? FULL_BUILTIN_STACK_CHECK |
2670 | : GENERIC_STACK_CHECK; | |
2671 | else if (!strcmp (arg, "specific")) | |
2672 | /* This is the new stack checking method. */ | |
5e471ea6 | 2673 | opts->x_flag_stack_check = STACK_CHECK_BUILTIN |
b38f3813 EB |
2674 | ? FULL_BUILTIN_STACK_CHECK |
2675 | : STACK_CHECK_STATIC_BUILTIN | |
2676 | ? STATIC_BUILTIN_STACK_CHECK | |
2677 | : GENERIC_STACK_CHECK; | |
2678 | else | |
778e02fd | 2679 | warning_at (loc, 0, "unknown stack check parameter %qs", arg); |
b38f3813 EB |
2680 | break; |
2681 | ||
de32c0cb NB |
2682 | case OPT_fstack_limit: |
2683 | /* The real switch is -fno-stack-limit. */ | |
2684 | if (value) | |
5f20c657 | 2685 | return false; |
21bf1558 | 2686 | /* Deferred. */ |
de32c0cb NB |
2687 | break; |
2688 | ||
058de654 | 2689 | case OPT_fstack_limit_register_: |
058de654 | 2690 | case OPT_fstack_limit_symbol_: |
21bf1558 | 2691 | /* Deferred. */ |
058de654 NB |
2692 | break; |
2693 | ||
a11e0df4 EB |
2694 | case OPT_fstack_usage: |
2695 | opts->x_flag_stack_usage = value; | |
2696 | opts->x_flag_stack_usage_info = value != 0; | |
2697 | break; | |
2698 | ||
e01cc6dc | 2699 | case OPT_g: |
bc91b0e0 CC |
2700 | set_debug_level (NO_DEBUG, DEFAULT_GDB_EXTENSIONS, arg, opts, opts_set, |
2701 | loc); | |
df38ffef NB |
2702 | break; |
2703 | ||
6782438d | 2704 | case OPT_gdwarf: |
f0defe58 | 2705 | if (arg && strlen (arg) != 0) |
6782438d | 2706 | { |
a3f9f006 ML |
2707 | error_at (loc, "%<-gdwarf%s%> is ambiguous; " |
2708 | "use %<-gdwarf-%s%> for DWARF version " | |
2709 | "or %<-gdwarf%> %<-g%s%> for debug level", arg, arg, arg); | |
6782438d SKS |
2710 | break; |
2711 | } | |
2712 | else | |
f0defe58 SKS |
2713 | value = opts->x_dwarf_version; |
2714 | ||
2715 | /* FALLTHRU */ | |
53b2323e | 2716 | case OPT_gdwarf_: |
5d45c9c0 | 2717 | if (value < 2 || value > 5) |
00abf86c | 2718 | error_at (loc, "dwarf version %wu is not supported", value); |
53b2323e | 2719 | else |
a7d0d30f | 2720 | opts->x_dwarf_version = value; |
299404a1 | 2721 | set_debug_level (DWARF2_DEBUG, false, "", opts, opts_set, loc); |
df38ffef NB |
2722 | break; |
2723 | ||
99ea153e SA |
2724 | case OPT_gsplit_dwarf: |
2725 | set_debug_level (NO_DEBUG, DEFAULT_GDB_EXTENSIONS, "", opts, opts_set, | |
2726 | loc); | |
2727 | break; | |
2728 | ||
df38ffef | 2729 | case OPT_ggdb: |
299404a1 | 2730 | set_debug_level (NO_DEBUG, 2, arg, opts, opts_set, loc); |
df38ffef NB |
2731 | break; |
2732 | ||
2733 | case OPT_gstabs: | |
2734 | case OPT_gstabs_: | |
299404a1 JM |
2735 | set_debug_level (DBX_DEBUG, code == OPT_gstabs_, arg, opts, opts_set, |
2736 | loc); | |
df38ffef NB |
2737 | break; |
2738 | ||
2739 | case OPT_gvms: | |
299404a1 | 2740 | set_debug_level (VMS_DEBUG, false, arg, opts, opts_set, loc); |
df38ffef NB |
2741 | break; |
2742 | ||
2743 | case OPT_gxcoff: | |
2744 | case OPT_gxcoff_: | |
299404a1 JM |
2745 | set_debug_level (XCOFF_DEBUG, code == OPT_gxcoff_, arg, opts, opts_set, |
2746 | loc); | |
e01cc6dc NB |
2747 | break; |
2748 | ||
29d7cbd1 RO |
2749 | case OPT_gz: |
2750 | case OPT_gz_: | |
2751 | /* Handled completely via specs. */ | |
2752 | break; | |
2753 | ||
d185d268 | 2754 | case OPT_pedantic_errors: |
d5478783 | 2755 | dc->pedantic_errors = 1; |
63bbf46d | 2756 | control_warning_option (OPT_Wpedantic, DK_ERROR, NULL, value, |
9b095bf1 MLI |
2757 | loc, lang_mask, |
2758 | handlers, opts, opts_set, | |
2759 | dc); | |
c04b6b38 RG |
2760 | break; |
2761 | ||
014d92e1 | 2762 | case OPT_flto: |
595c8dfa | 2763 | opts->x_flag_lto = value ? "" : NULL; |
e10909ce AK |
2764 | break; |
2765 | ||
40077d15 ML |
2766 | case OPT_flto_: |
2767 | if (strcmp (arg, "none") != 0 | |
2768 | && strcmp (arg, "jobserver") != 0 | |
279dc7a3 | 2769 | && strcmp (arg, "auto") != 0 |
40077d15 ML |
2770 | && atoi (arg) == 0) |
2771 | error_at (loc, | |
2772 | "unrecognized argument to %<-flto=%> option: %qs", arg); | |
2773 | break; | |
2774 | ||
5f0f4a3b | 2775 | case OPT_w: |
d5478783 | 2776 | dc->dc_inhibit_warnings = true; |
5f0f4a3b JM |
2777 | break; |
2778 | ||
3a789837 NF |
2779 | case OPT_fmax_errors_: |
2780 | dc->max_errors = value; | |
2781 | break; | |
2782 | ||
b352afba NC |
2783 | case OPT_fuse_ld_bfd: |
2784 | case OPT_fuse_ld_gold: | |
d69ac8b7 | 2785 | case OPT_fuse_ld_lld: |
da18ea94 RAE |
2786 | case OPT_fuse_linker_plugin: |
2787 | /* No-op. Used by the driver and passed to us because it starts with f.*/ | |
2788 | break; | |
2789 | ||
955f5a07 JJ |
2790 | case OPT_fwrapv: |
2791 | if (value) | |
2792 | opts->x_flag_trapv = 0; | |
2793 | break; | |
2794 | ||
2795 | case OPT_ftrapv: | |
2796 | if (value) | |
2797 | opts->x_flag_wrapv = 0; | |
2798 | break; | |
2799 | ||
3fccbb9e JJ |
2800 | case OPT_fstrict_overflow: |
2801 | opts->x_flag_wrapv = !value; | |
2802 | opts->x_flag_wrapv_pointer = !value; | |
2803 | if (!value) | |
2804 | opts->x_flag_trapv = 0; | |
2805 | break; | |
2806 | ||
b84d4347 | 2807 | case OPT_fipa_icf: |
9d4ded75 ML |
2808 | opts->x_flag_ipa_icf_functions = value; |
2809 | opts->x_flag_ipa_icf_variables = value; | |
b84d4347 ML |
2810 | break; |
2811 | ||
c518c102 ML |
2812 | case OPT_falign_loops_: |
2813 | check_alignment_argument (loc, arg, "loops"); | |
2814 | break; | |
2815 | ||
2816 | case OPT_falign_jumps_: | |
2817 | check_alignment_argument (loc, arg, "jumps"); | |
2818 | break; | |
2819 | ||
2820 | case OPT_falign_labels_: | |
2821 | check_alignment_argument (loc, arg, "labels"); | |
2822 | break; | |
2823 | ||
2824 | case OPT_falign_functions_: | |
2825 | check_alignment_argument (loc, arg, "functions"); | |
2826 | break; | |
2827 | ||
50431bc4 ZD |
2828 | default: |
2829 | /* If the flag was handled in a standard way, assume the lack of | |
2830 | processing here is intentional. */ | |
46625112 | 2831 | gcc_assert (option_flag_var (scode, opts)); |
0e61db61 | 2832 | break; |
d7b42618 NB |
2833 | } |
2834 | ||
7d5a5747 MLI |
2835 | common_handle_option_auto (opts, opts_set, decoded, lang_mask, kind, |
2836 | loc, handlers, dc); | |
5f20c657 | 2837 | return true; |
d7b42618 | 2838 | } |
903caebf NB |
2839 | |
2840 | /* Handle --param NAME=VALUE. */ | |
2841 | static void | |
48476d13 | 2842 | handle_param (struct gcc_options *opts, struct gcc_options *opts_set, |
299404a1 | 2843 | location_t loc, const char *carg) |
903caebf NB |
2844 | { |
2845 | char *equal, *arg; | |
2846 | int value; | |
2847 | ||
2848 | arg = xstrdup (carg); | |
2849 | equal = strchr (arg, '='); | |
2850 | if (!equal) | |
a9c697b8 MS |
2851 | error_at (loc, "%s: %qs arguments should be of the form NAME=VALUE", |
2852 | arg, "--param"); | |
903caebf NB |
2853 | else |
2854 | { | |
d78182cc TV |
2855 | *equal = '\0'; |
2856 | ||
2857 | enum compiler_param index; | |
2858 | if (!find_param (arg, &index)) | |
f4452176 DM |
2859 | { |
2860 | const char *suggestion = find_param_fuzzy (arg); | |
2861 | if (suggestion) | |
a9c697b8 MS |
2862 | error_at (loc, "invalid %qs name %qs; did you mean %qs?", |
2863 | "--param", arg, suggestion); | |
f4452176 | 2864 | else |
a9c697b8 | 2865 | error_at (loc, "invalid %qs name %qs", "--param", arg); |
f4452176 | 2866 | } |
903caebf NB |
2867 | else |
2868 | { | |
d78182cc TV |
2869 | if (!param_string_value_p (index, equal + 1, &value)) |
2870 | value = integral_argument (equal + 1); | |
2871 | ||
2872 | if (value == -1) | |
a9c697b8 | 2873 | error_at (loc, "invalid %qs value %qs", "--param", equal + 1); |
d78182cc TV |
2874 | else |
2875 | set_param_value (arg, value, | |
2876 | opts->x_param_values, opts_set->x_param_values); | |
903caebf NB |
2877 | } |
2878 | } | |
2879 | ||
2880 | free (arg); | |
2881 | } | |
2882 | ||
d5478783 | 2883 | /* Used to set the level of strict aliasing warnings in OPTS, |
79bedddc SR |
2884 | when no level is specified (i.e., when -Wstrict-aliasing, and not |
2885 | -Wstrict-aliasing=level was given). | |
2886 | ONOFF is assumed to take value 1 when -Wstrict-aliasing is specified, | |
2887 | and 0 otherwise. After calling this function, wstrict_aliasing will be | |
2888 | set to the default value of -Wstrict_aliasing=level, currently 3. */ | |
65d4f2cd | 2889 | static void |
d5478783 | 2890 | set_Wstrict_aliasing (struct gcc_options *opts, int onoff) |
79bedddc SR |
2891 | { |
2892 | gcc_assert (onoff == 0 || onoff == 1); | |
2893 | if (onoff != 0) | |
d5478783 | 2894 | opts->x_warn_strict_aliasing = 3; |
621b5ed6 | 2895 | else |
d5478783 | 2896 | opts->x_warn_strict_aliasing = 0; |
79bedddc SR |
2897 | } |
2898 | ||
058de654 NB |
2899 | /* The following routines are useful in setting all the flags that |
2900 | -ffast-math and -fno-fast-math imply. */ | |
7bb3487f | 2901 | static void |
d5478783 | 2902 | set_fast_math_flags (struct gcc_options *opts, int set) |
058de654 | 2903 | { |
5e46b0c6 ILT |
2904 | if (!opts->frontend_set_flag_unsafe_math_optimizations) |
2905 | { | |
2906 | opts->x_flag_unsafe_math_optimizations = set; | |
2907 | set_unsafe_math_optimizations_flags (opts, set); | |
2908 | } | |
2909 | if (!opts->frontend_set_flag_finite_math_only) | |
2910 | opts->x_flag_finite_math_only = set; | |
2911 | if (!opts->frontend_set_flag_errno_math) | |
2912 | opts->x_flag_errno_math = !set; | |
058de654 | 2913 | if (set) |
039c3d42 | 2914 | { |
df375b03 JJ |
2915 | if (opts->frontend_set_flag_excess_precision == EXCESS_PRECISION_DEFAULT) |
2916 | opts->x_flag_excess_precision | |
314e1b47 | 2917 | = set ? EXCESS_PRECISION_FAST : EXCESS_PRECISION_DEFAULT; |
5e46b0c6 ILT |
2918 | if (!opts->frontend_set_flag_signaling_nans) |
2919 | opts->x_flag_signaling_nans = 0; | |
2920 | if (!opts->frontend_set_flag_rounding_math) | |
2921 | opts->x_flag_rounding_math = 0; | |
2922 | if (!opts->frontend_set_flag_cx_limited_range) | |
2923 | opts->x_flag_cx_limited_range = 1; | |
039c3d42 | 2924 | } |
058de654 NB |
2925 | } |
2926 | ||
b8698a0f L |
2927 | /* When -funsafe-math-optimizations is set the following |
2928 | flags are set as well. */ | |
7bb3487f | 2929 | static void |
d5478783 | 2930 | set_unsafe_math_optimizations_flags (struct gcc_options *opts, int set) |
a1a82611 | 2931 | { |
5e46b0c6 ILT |
2932 | if (!opts->frontend_set_flag_trapping_math) |
2933 | opts->x_flag_trapping_math = !set; | |
2934 | if (!opts->frontend_set_flag_signed_zeros) | |
2935 | opts->x_flag_signed_zeros = !set; | |
2936 | if (!opts->frontend_set_flag_associative_math) | |
2937 | opts->x_flag_associative_math = set; | |
2938 | if (!opts->frontend_set_flag_reciprocal_math) | |
2939 | opts->x_flag_reciprocal_math = set; | |
a1a82611 RE |
2940 | } |
2941 | ||
0576d21f | 2942 | /* Return true iff flags in OPTS are set as if -ffast-math. */ |
058de654 | 2943 | bool |
0576d21f | 2944 | fast_math_flags_set_p (const struct gcc_options *opts) |
058de654 | 2945 | { |
0576d21f JM |
2946 | return (!opts->x_flag_trapping_math |
2947 | && opts->x_flag_unsafe_math_optimizations | |
2948 | && opts->x_flag_finite_math_only | |
2949 | && !opts->x_flag_signed_zeros | |
314e1b47 | 2950 | && !opts->x_flag_errno_math |
df375b03 | 2951 | && opts->x_flag_excess_precision == EXCESS_PRECISION_FAST); |
058de654 | 2952 | } |
cf03fd63 | 2953 | |
ab442df7 MM |
2954 | /* Return true iff flags are set as if -ffast-math but using the flags stored |
2955 | in the struct cl_optimization structure. */ | |
2956 | bool | |
2957 | fast_math_flags_struct_set_p (struct cl_optimization *opt) | |
2958 | { | |
e3339d0f JM |
2959 | return (!opt->x_flag_trapping_math |
2960 | && opt->x_flag_unsafe_math_optimizations | |
2961 | && opt->x_flag_finite_math_only | |
2962 | && !opt->x_flag_signed_zeros | |
2963 | && !opt->x_flag_errno_math); | |
ab442df7 MM |
2964 | } |
2965 | ||
0576d21f JM |
2966 | /* Handle a debug output -g switch for options OPTS |
2967 | (OPTS_SET->x_write_symbols storing whether a debug type was passed | |
299404a1 JM |
2968 | explicitly), location LOC. EXTENDED is true or false to support |
2969 | extended output (2 is special and means "-ggdb" was given). */ | |
df38ffef | 2970 | static void |
0576d21f | 2971 | set_debug_level (enum debug_info_type type, int extended, const char *arg, |
299404a1 JM |
2972 | struct gcc_options *opts, struct gcc_options *opts_set, |
2973 | location_t loc) | |
df38ffef | 2974 | { |
0576d21f | 2975 | opts->x_use_gnu_debug_info_extensions = extended; |
df38ffef NB |
2976 | |
2977 | if (type == NO_DEBUG) | |
2978 | { | |
0576d21f | 2979 | if (opts->x_write_symbols == NO_DEBUG) |
df38ffef | 2980 | { |
0576d21f | 2981 | opts->x_write_symbols = PREFERRED_DEBUGGING_TYPE; |
df38ffef NB |
2982 | |
2983 | if (extended == 2) | |
2984 | { | |
c9665100 | 2985 | #if defined DWARF2_DEBUGGING_INFO || defined DWARF2_LINENO_DEBUGGING_INFO |
0576d21f | 2986 | opts->x_write_symbols = DWARF2_DEBUG; |
df38ffef | 2987 | #elif defined DBX_DEBUGGING_INFO |
0576d21f | 2988 | opts->x_write_symbols = DBX_DEBUG; |
df38ffef NB |
2989 | #endif |
2990 | } | |
2991 | ||
0576d21f | 2992 | if (opts->x_write_symbols == NO_DEBUG) |
299404a1 | 2993 | warning_at (loc, 0, "target system does not support debug output"); |
df38ffef NB |
2994 | } |
2995 | } | |
2996 | else | |
2997 | { | |
2998 | /* Does it conflict with an already selected type? */ | |
0576d21f JM |
2999 | if (opts_set->x_write_symbols != NO_DEBUG |
3000 | && opts->x_write_symbols != NO_DEBUG | |
3001 | && type != opts->x_write_symbols) | |
778e02fd | 3002 | error_at (loc, "debug format %qs conflicts with prior selection", |
299404a1 | 3003 | debug_type_names[type]); |
0576d21f JM |
3004 | opts->x_write_symbols = type; |
3005 | opts_set->x_write_symbols = type; | |
df38ffef NB |
3006 | } |
3007 | ||
bc91b0e0 CC |
3008 | /* A debug flag without a level defaults to level 2. |
3009 | If off or at level 1, set it to level 2, but if already | |
3010 | at level 3, don't lower it. */ | |
df38ffef NB |
3011 | if (*arg == '\0') |
3012 | { | |
bc91b0e0 | 3013 | if (opts->x_debug_info_level < DINFO_LEVEL_NORMAL) |
0576d21f | 3014 | opts->x_debug_info_level = DINFO_LEVEL_NORMAL; |
df38ffef NB |
3015 | } |
3016 | else | |
3017 | { | |
32e8bb8e ILT |
3018 | int argval = integral_argument (arg); |
3019 | if (argval == -1) | |
bd2c6270 | 3020 | error_at (loc, "unrecognized debug output level %qs", arg); |
32e8bb8e | 3021 | else if (argval > 3) |
778e02fd | 3022 | error_at (loc, "debug output level %qs is too high", arg); |
32e8bb8e | 3023 | else |
0576d21f | 3024 | opts->x_debug_info_level = (enum debug_info_levels) argval; |
df38ffef NB |
3025 | } |
3026 | } | |
3027 | ||
299404a1 JM |
3028 | /* Arrange to dump core on error for diagnostic context DC. (The |
3029 | regular error message is still printed first, except in the case of | |
3030 | abort ().) */ | |
75685792 | 3031 | |
c98cd5bf | 3032 | static void |
299404a1 | 3033 | setup_core_dumping (diagnostic_context *dc) |
75685792 | 3034 | { |
c98cd5bf JM |
3035 | #ifdef SIGABRT |
3036 | signal (SIGABRT, SIG_DFL); | |
3037 | #endif | |
3038 | #if defined(HAVE_SETRLIMIT) | |
3039 | { | |
3040 | struct rlimit rlim; | |
3041 | if (getrlimit (RLIMIT_CORE, &rlim) != 0) | |
40fecdd6 | 3042 | fatal_error (input_location, "getting core file size maximum limit: %m"); |
c98cd5bf JM |
3043 | rlim.rlim_cur = rlim.rlim_max; |
3044 | if (setrlimit (RLIMIT_CORE, &rlim) != 0) | |
40fecdd6 JM |
3045 | fatal_error (input_location, |
3046 | "setting core file size limit to maximum: %m"); | |
c98cd5bf JM |
3047 | } |
3048 | #endif | |
299404a1 | 3049 | diagnostic_abort_on_error (dc); |
75685792 | 3050 | } |
5c60a017 | 3051 | |
299404a1 JM |
3052 | /* Parse a -d<ARG> command line switch for OPTS, location LOC, |
3053 | diagnostic context DC. */ | |
5c60a017 | 3054 | |
c98cd5bf | 3055 | static void |
299404a1 JM |
3056 | decode_d_option (const char *arg, struct gcc_options *opts, |
3057 | location_t loc, diagnostic_context *dc) | |
5c60a017 | 3058 | { |
c98cd5bf | 3059 | int c; |
5c60a017 | 3060 | |
c98cd5bf JM |
3061 | while (*arg) |
3062 | switch (c = *arg++) | |
3063 | { | |
3064 | case 'A': | |
299404a1 | 3065 | opts->x_flag_debug_asm = 1; |
c98cd5bf JM |
3066 | break; |
3067 | case 'p': | |
299404a1 | 3068 | opts->x_flag_print_asm_name = 1; |
c98cd5bf JM |
3069 | break; |
3070 | case 'P': | |
299404a1 JM |
3071 | opts->x_flag_dump_rtl_in_asm = 1; |
3072 | opts->x_flag_print_asm_name = 1; | |
c98cd5bf | 3073 | break; |
c98cd5bf | 3074 | case 'x': |
299404a1 | 3075 | opts->x_rtl_dump_and_exit = 1; |
c98cd5bf JM |
3076 | break; |
3077 | case 'D': /* These are handled by the preprocessor. */ | |
3078 | case 'I': | |
3079 | case 'M': | |
3080 | case 'N': | |
3081 | case 'U': | |
3082 | break; | |
3083 | case 'H': | |
299404a1 | 3084 | setup_core_dumping (dc); |
c98cd5bf JM |
3085 | break; |
3086 | case 'a': | |
299404a1 | 3087 | opts->x_flag_dump_all_passed = true; |
c98cd5bf | 3088 | break; |
21bf1558 | 3089 | |
c98cd5bf | 3090 | default: |
299404a1 | 3091 | warning_at (loc, 0, "unrecognized gcc debugging option: %c", c); |
c98cd5bf JM |
3092 | break; |
3093 | } | |
5c60a017 | 3094 | } |
dc90f45b | 3095 | |
1ebe4b4f | 3096 | /* Enable (or disable if VALUE is 0) a warning option ARG (language |
c5fa0890 JM |
3097 | mask LANG_MASK, option handlers HANDLERS) as an error for option |
3098 | structures OPTS and OPTS_SET, diagnostic context DC (possibly | |
3099 | NULL), location LOC. This is used by -Werror=. */ | |
dc90f45b | 3100 | |
a4d8c676 | 3101 | static void |
5f20c657 | 3102 | enable_warning_as_error (const char *arg, int value, unsigned int lang_mask, |
1ebe4b4f | 3103 | const struct cl_option_handlers *handlers, |
c5fa0890 JM |
3104 | struct gcc_options *opts, |
3105 | struct gcc_options *opts_set, | |
a4d8c676 | 3106 | location_t loc, diagnostic_context *dc) |
dc90f45b MLI |
3107 | { |
3108 | char *new_option; | |
3109 | int option_index; | |
3110 | ||
3111 | new_option = XNEWVEC (char, strlen (arg) + 2); | |
3112 | new_option[0] = 'W'; | |
3113 | strcpy (new_option + 1, arg); | |
3114 | option_index = find_opt (new_option, lang_mask); | |
6e2f1956 | 3115 | if (option_index == OPT_SPECIAL_unknown) |
5bcc5a3b ML |
3116 | { |
3117 | option_proposer op; | |
3118 | const char *hint = op.suggest_option (new_option); | |
3119 | if (hint) | |
3120 | error_at (loc, "%<-W%serror=%s%>: no option %<-%s%>;" | |
3121 | " did you mean %<-%s%>?", value ? "" : "no-", | |
3122 | arg, new_option, hint); | |
3123 | else | |
3124 | error_at (loc, "%<-W%serror=%s%>: no option %<-%s%>", | |
3125 | value ? "" : "no-", arg, new_option); | |
3126 | } | |
35632122 | 3127 | else if (!(cl_options[option_index].flags & CL_WARNING)) |
5bcc5a3b ML |
3128 | error_at (loc, "%<-Werror=%s%>: %<-%s%> is not an option that " |
3129 | "controls warnings", arg, new_option); | |
dc90f45b MLI |
3130 | else |
3131 | { | |
87cf0651 | 3132 | const diagnostic_t kind = value ? DK_ERROR : DK_WARNING; |
63bbf46d | 3133 | const char *arg = NULL; |
87cf0651 | 3134 | |
63bbf46d JJ |
3135 | if (cl_options[option_index].flags & CL_JOINED) |
3136 | arg = new_option + cl_options[option_index].opt_len; | |
3137 | control_warning_option (option_index, (int) kind, arg, value, | |
c5fa0890 JM |
3138 | loc, lang_mask, |
3139 | handlers, opts, opts_set, dc); | |
dc90f45b MLI |
3140 | } |
3141 | free (new_option); | |
3142 | } | |
5f0f4a3b JM |
3143 | |
3144 | /* Return malloced memory for the name of the option OPTION_INDEX | |
3145 | which enabled a diagnostic (context CONTEXT), originally of type | |
3146 | ORIG_DIAG_KIND but possibly converted to DIAG_KIND by options such | |
3147 | as -Werror. */ | |
3148 | ||
3149 | char * | |
3150 | option_name (diagnostic_context *context, int option_index, | |
3151 | diagnostic_t orig_diag_kind, diagnostic_t diag_kind) | |
3152 | { | |
3153 | if (option_index) | |
3154 | { | |
3155 | /* A warning classified as an error. */ | |
3156 | if ((orig_diag_kind == DK_WARNING || orig_diag_kind == DK_PEDWARN) | |
3157 | && diag_kind == DK_ERROR) | |
3158 | return concat (cl_options[OPT_Werror_].opt_text, | |
3159 | /* Skip over "-W". */ | |
3160 | cl_options[option_index].opt_text + 2, | |
3161 | NULL); | |
3162 | /* A warning with option. */ | |
3163 | else | |
3164 | return xstrdup (cl_options[option_index].opt_text); | |
3165 | } | |
3166 | /* A warning without option classified as an error. */ | |
9f8da907 RS |
3167 | else if ((orig_diag_kind == DK_WARNING || orig_diag_kind == DK_PEDWARN |
3168 | || diag_kind == DK_WARNING) | |
3169 | && context->warning_as_error_requested) | |
3170 | return xstrdup (cl_options[OPT_Werror].opt_text); | |
5f0f4a3b JM |
3171 | else |
3172 | return NULL; | |
3173 | } | |
b4c7ca2e DM |
3174 | |
3175 | /* Return malloced memory for a URL describing the option OPTION_INDEX | |
3176 | which enabled a diagnostic (context CONTEXT). */ | |
3177 | ||
3178 | char * | |
3179 | get_option_url (diagnostic_context *, int option_index) | |
3180 | { | |
3181 | if (option_index) | |
3182 | /* DOCUMENTATION_ROOT_URL should be supplied via -D by the Makefile | |
3183 | (see --with-documentation-root-url). | |
3184 | ||
3185 | Expect an anchor of the form "index-Wfoo" e.g. | |
3186 | <a name="index-Wformat"></a>, and thus an id within | |
3187 | the URL of "#index-Wformat". */ | |
3188 | return concat (DOCUMENTATION_ROOT_URL, | |
3189 | "Warning-Options.html", | |
3190 | "#index", cl_options[option_index].opt_text, | |
3191 | NULL); | |
3192 | else | |
3193 | return NULL; | |
3194 | } |