]>
Commit | Line | Data |
---|---|---|
2772ef3e | 1 | /* Command line option handling. |
818ab71a | 2 | Copyright (C) 2002-2016 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" |
2772ef3e | 33 | |
65d4f2cd MLI |
34 | static void set_Wstrict_aliasing (struct gcc_options *opts, int onoff); |
35 | ||
a7d0d30f JM |
36 | /* Indexed by enum debug_info_type. */ |
37 | const char *const debug_type_names[] = | |
38 | { | |
39 | "none", "stabs", "coff", "dwarf-2", "xcoff", "vms" | |
40 | }; | |
41 | ||
39ef6592 LC |
42 | /* Parse the -femit-struct-debug-detailed option value |
43 | and set the flag variables. */ | |
44 | ||
45 | #define MATCH( prefix, string ) \ | |
46 | ((strncmp (prefix, string, sizeof prefix - 1) == 0) \ | |
47 | ? ((string += sizeof prefix - 1), 1) : 0) | |
48 | ||
49 | void | |
299404a1 JM |
50 | set_struct_debug_option (struct gcc_options *opts, location_t loc, |
51 | const char *spec) | |
39ef6592 LC |
52 | { |
53 | /* various labels for comparison */ | |
0576d21f JM |
54 | static const char dfn_lbl[] = "dfn:", dir_lbl[] = "dir:", ind_lbl[] = "ind:"; |
55 | static const char ord_lbl[] = "ord:", gen_lbl[] = "gen:"; | |
56 | static const char none_lbl[] = "none", any_lbl[] = "any"; | |
57 | static const char base_lbl[] = "base", sys_lbl[] = "sys"; | |
39ef6592 LC |
58 | |
59 | enum debug_struct_file files = DINFO_STRUCT_FILE_ANY; | |
60 | /* Default is to apply to as much as possible. */ | |
61 | enum debug_info_usage usage = DINFO_USAGE_NUM_ENUMS; | |
62 | int ord = 1, gen = 1; | |
63 | ||
64 | /* What usage? */ | |
65 | if (MATCH (dfn_lbl, spec)) | |
66 | usage = DINFO_USAGE_DFN; | |
67 | else if (MATCH (dir_lbl, spec)) | |
68 | usage = DINFO_USAGE_DIR_USE; | |
69 | else if (MATCH (ind_lbl, spec)) | |
70 | usage = DINFO_USAGE_IND_USE; | |
71 | ||
72 | /* Generics or not? */ | |
73 | if (MATCH (ord_lbl, spec)) | |
74 | gen = 0; | |
75 | else if (MATCH (gen_lbl, spec)) | |
76 | ord = 0; | |
77 | ||
78 | /* What allowable environment? */ | |
79 | if (MATCH (none_lbl, spec)) | |
80 | files = DINFO_STRUCT_FILE_NONE; | |
81 | else if (MATCH (any_lbl, spec)) | |
82 | files = DINFO_STRUCT_FILE_ANY; | |
83 | else if (MATCH (sys_lbl, spec)) | |
84 | files = DINFO_STRUCT_FILE_SYS; | |
85 | else if (MATCH (base_lbl, spec)) | |
86 | files = DINFO_STRUCT_FILE_BASE; | |
87 | else | |
299404a1 JM |
88 | error_at (loc, |
89 | "argument %qs to %<-femit-struct-debug-detailed%> " | |
90 | "not recognized", | |
91 | spec); | |
39ef6592 LC |
92 | |
93 | /* Effect the specification. */ | |
94 | if (usage == DINFO_USAGE_NUM_ENUMS) | |
95 | { | |
96 | if (ord) | |
97 | { | |
69ccdddb JM |
98 | opts->x_debug_struct_ordinary[DINFO_USAGE_DFN] = files; |
99 | opts->x_debug_struct_ordinary[DINFO_USAGE_DIR_USE] = files; | |
100 | opts->x_debug_struct_ordinary[DINFO_USAGE_IND_USE] = files; | |
39ef6592 LC |
101 | } |
102 | if (gen) | |
103 | { | |
69ccdddb JM |
104 | opts->x_debug_struct_generic[DINFO_USAGE_DFN] = files; |
105 | opts->x_debug_struct_generic[DINFO_USAGE_DIR_USE] = files; | |
106 | opts->x_debug_struct_generic[DINFO_USAGE_IND_USE] = files; | |
39ef6592 LC |
107 | } |
108 | } | |
109 | else | |
110 | { | |
111 | if (ord) | |
69ccdddb | 112 | opts->x_debug_struct_ordinary[usage] = files; |
39ef6592 | 113 | if (gen) |
69ccdddb | 114 | opts->x_debug_struct_generic[usage] = files; |
39ef6592 LC |
115 | } |
116 | ||
117 | if (*spec == ',') | |
299404a1 | 118 | set_struct_debug_option (opts, loc, spec+1); |
39ef6592 LC |
119 | else |
120 | { | |
121 | /* No more -femit-struct-debug-detailed specifications. | |
122 | Do final checks. */ | |
123 | if (*spec != '\0') | |
299404a1 JM |
124 | error_at (loc, |
125 | "argument %qs to %<-femit-struct-debug-detailed%> unknown", | |
126 | spec); | |
69ccdddb JM |
127 | if (opts->x_debug_struct_ordinary[DINFO_USAGE_DIR_USE] |
128 | < opts->x_debug_struct_ordinary[DINFO_USAGE_IND_USE] | |
129 | || opts->x_debug_struct_generic[DINFO_USAGE_DIR_USE] | |
130 | < opts->x_debug_struct_generic[DINFO_USAGE_IND_USE]) | |
299404a1 JM |
131 | error_at (loc, |
132 | "%<-femit-struct-debug-detailed=dir:...%> must allow " | |
133 | "at least as much as " | |
134 | "%<-femit-struct-debug-detailed=ind:...%>"); | |
39ef6592 LC |
135 | } |
136 | } | |
137 | ||
c98cd5bf JM |
138 | /* Strip off a legitimate source ending from the input string NAME of |
139 | length LEN. Rather than having to know the names used by all of | |
140 | our front ends, we strip off an ending of a period followed by | |
141 | up to five characters. (Java uses ".class".) */ | |
142 | ||
143 | void | |
144 | strip_off_ending (char *name, int len) | |
145 | { | |
146 | int i; | |
147 | for (i = 2; i < 6 && len > i; i++) | |
148 | { | |
149 | if (name[len - i] == '.') | |
150 | { | |
151 | name[len - i] = '\0'; | |
152 | break; | |
153 | } | |
154 | } | |
155 | } | |
156 | ||
39ef6592 LC |
157 | /* Find the base name of a path, stripping off both directories and |
158 | a single final extension. */ | |
69ccdddb | 159 | int |
39ef6592 LC |
160 | base_of_path (const char *path, const char **base_out) |
161 | { | |
162 | const char *base = path; | |
163 | const char *dot = 0; | |
164 | const char *p = path; | |
165 | char c = *p; | |
166 | while (c) | |
167 | { | |
c3284718 | 168 | if (IS_DIR_SEPARATOR (c)) |
39ef6592 LC |
169 | { |
170 | base = p + 1; | |
171 | dot = 0; | |
172 | } | |
173 | else if (c == '.') | |
174 | dot = p; | |
175 | c = *++p; | |
176 | } | |
177 | if (!dot) | |
178 | dot = p; | |
179 | *base_out = base; | |
180 | return dot - base; | |
181 | } | |
182 | ||
2cc98056 | 183 | /* What to print when a switch has no documentation. */ |
a7b2e184 MS |
184 | static const char undocumented_msg[] = N_("This option lacks documentation."); |
185 | static const char use_diagnosed_msg[] = N_("Uses of this option are diagnosed."); | |
2cc98056 | 186 | |
8d5a7d1f | 187 | typedef char *char_p; /* For DEF_VEC_P. */ |
8d5a7d1f | 188 | |
48476d13 | 189 | static void handle_param (struct gcc_options *opts, |
299404a1 JM |
190 | struct gcc_options *opts_set, location_t loc, |
191 | const char *carg); | |
df38ffef | 192 | static void set_debug_level (enum debug_info_type type, int extended, |
0576d21f | 193 | const char *arg, struct gcc_options *opts, |
299404a1 JM |
194 | struct gcc_options *opts_set, |
195 | location_t loc); | |
d5478783 | 196 | static void set_fast_math_flags (struct gcc_options *opts, int set); |
299404a1 JM |
197 | static void decode_d_option (const char *arg, struct gcc_options *opts, |
198 | location_t loc, diagnostic_context *dc); | |
d5478783 JM |
199 | static void set_unsafe_math_optimizations_flags (struct gcc_options *opts, |
200 | int set); | |
a4d8c676 JM |
201 | static void enable_warning_as_error (const char *arg, int value, |
202 | unsigned int lang_mask, | |
203 | const struct cl_option_handlers *handlers, | |
c5fa0890 JM |
204 | struct gcc_options *opts, |
205 | struct gcc_options *opts_set, | |
a4d8c676 JM |
206 | location_t loc, |
207 | diagnostic_context *dc); | |
2772ef3e | 208 | |
5f20c657 JM |
209 | /* Handle a back-end option; arguments and return value as for |
210 | handle_option. */ | |
2772ef3e | 211 | |
c98cd5bf | 212 | bool |
46625112 | 213 | target_handle_option (struct gcc_options *opts, |
d4d24ba4 | 214 | struct gcc_options *opts_set, |
46625112 | 215 | const struct cl_decoded_option *decoded, |
481e1176 | 216 | unsigned int lang_mask ATTRIBUTE_UNUSED, int kind, |
96e45421 | 217 | location_t loc, |
d5478783 JM |
218 | const struct cl_option_handlers *handlers ATTRIBUTE_UNUSED, |
219 | diagnostic_context *dc) | |
5f20c657 | 220 | { |
d5478783 | 221 | gcc_assert (dc == global_dc); |
5f20c657 | 222 | gcc_assert (kind == DK_UNSPECIFIED); |
677f3fa8 | 223 | return targetm_common.handle_option (opts, opts_set, decoded, loc); |
2772ef3e | 224 | } |
d7b42618 | 225 | |
1ebc7e68 | 226 | /* Add comma-separated strings to a char_p vector. */ |
8d5a7d1f ILT |
227 | |
228 | static void | |
6a1f6c9c | 229 | add_comma_separated_to_vector (void **pvec, const char *arg) |
8d5a7d1f ILT |
230 | { |
231 | char *tmp; | |
232 | char *r; | |
233 | char *w; | |
234 | char *token_start; | |
9771b263 DN |
235 | vec<char_p> *v = (vec<char_p> *) *pvec; |
236 | ||
237 | vec_check_alloc (v, 1); | |
8d5a7d1f ILT |
238 | |
239 | /* We never free this string. */ | |
240 | tmp = xstrdup (arg); | |
241 | ||
242 | r = tmp; | |
243 | w = tmp; | |
244 | token_start = tmp; | |
245 | ||
246 | while (*r != '\0') | |
247 | { | |
248 | if (*r == ',') | |
249 | { | |
250 | *w++ = '\0'; | |
251 | ++r; | |
9771b263 | 252 | v->safe_push (token_start); |
8d5a7d1f ILT |
253 | token_start = w; |
254 | } | |
255 | if (*r == '\\' && r[1] == ',') | |
256 | { | |
257 | *w++ = ','; | |
258 | r += 2; | |
259 | } | |
260 | else | |
261 | *w++ = *r++; | |
262 | } | |
263 | if (*token_start != '\0') | |
9771b263 | 264 | v->safe_push (token_start); |
8d5a7d1f | 265 | |
9771b263 | 266 | *pvec = v; |
8d5a7d1f ILT |
267 | } |
268 | ||
d6874f56 | 269 | /* Initialize opts_obstack. */ |
de5672fc ML |
270 | |
271 | void | |
272 | init_opts_obstack (void) | |
273 | { | |
d6874f56 | 274 | gcc_obstack_init (&opts_obstack); |
de5672fc ML |
275 | } |
276 | ||
a75bfaa6 JM |
277 | /* Initialize OPTS and OPTS_SET before using them in parsing options. */ |
278 | ||
279 | void | |
280 | init_options_struct (struct gcc_options *opts, struct gcc_options *opts_set) | |
281 | { | |
48476d13 JM |
282 | size_t num_params = get_num_compiler_params (); |
283 | ||
d6874f56 DM |
284 | /* Ensure that opts_obstack has already been initialized by the time |
285 | that we initialize any gcc_options instances (PR jit/68446). */ | |
286 | gcc_assert (opts_obstack.chunk_size > 0); | |
dc357798 | 287 | |
a75bfaa6 | 288 | *opts = global_options_init; |
bf7b5747 ST |
289 | |
290 | if (opts_set) | |
291 | memset (opts_set, 0, sizeof (*opts_set)); | |
a75bfaa6 | 292 | |
48476d13 | 293 | opts->x_param_values = XNEWVEC (int, num_params); |
bf7b5747 ST |
294 | |
295 | if (opts_set) | |
296 | opts_set->x_param_values = XCNEWVEC (int, num_params); | |
297 | ||
48476d13 JM |
298 | init_param_values (opts->x_param_values); |
299 | ||
a75bfaa6 JM |
300 | /* Initialize whether `char' is signed. */ |
301 | opts->x_flag_signed_char = DEFAULT_SIGNED_CHAR; | |
302 | /* Set this to a special "uninitialized" value. The actual default | |
303 | is set after target options have been processed. */ | |
304 | opts->x_flag_short_enums = 2; | |
305 | ||
677f3fa8 | 306 | /* Initialize target_flags before default_options_optimization |
a75bfaa6 | 307 | so the latter can modify it. */ |
677f3fa8 | 308 | opts->x_target_flags = targetm_common.default_target_flags; |
a75bfaa6 JM |
309 | |
310 | /* Some targets have ABI-specified unwind tables. */ | |
677f3fa8 | 311 | opts->x_flag_unwind_tables = targetm_common.unwind_tables_default; |
7e4aae92 JM |
312 | |
313 | /* Some targets have other target-specific initialization. */ | |
677f3fa8 | 314 | targetm_common.option_init_struct (opts); |
a75bfaa6 JM |
315 | } |
316 | ||
0ef443cf DM |
317 | /* Release any allocations owned by OPTS. */ |
318 | ||
319 | void | |
320 | finalize_options_struct (struct gcc_options *opts) | |
321 | { | |
322 | XDELETEVEC (opts->x_param_values); | |
323 | } | |
324 | ||
3020190e | 325 | /* If indicated by the optimization level LEVEL (-Os if SIZE is set, |
bf7a7185 RG |
326 | -Ofast if FAST is set, -Og if DEBUG is set), apply the option DEFAULT_OPT |
327 | to OPTS and OPTS_SET, diagnostic context DC, location LOC, with language | |
328 | mask LANG_MASK and option handlers HANDLERS. */ | |
3020190e JM |
329 | |
330 | static void | |
331 | maybe_default_option (struct gcc_options *opts, | |
332 | struct gcc_options *opts_set, | |
333 | const struct default_options *default_opt, | |
bf7a7185 | 334 | int level, bool size, bool fast, bool debug, |
3020190e JM |
335 | unsigned int lang_mask, |
336 | const struct cl_option_handlers *handlers, | |
a4d8c676 | 337 | location_t loc, |
3020190e JM |
338 | diagnostic_context *dc) |
339 | { | |
340 | const struct cl_option *option = &cl_options[default_opt->opt_index]; | |
341 | bool enabled; | |
342 | ||
343 | if (size) | |
344 | gcc_assert (level == 2); | |
345 | if (fast) | |
346 | gcc_assert (level == 3); | |
bf7a7185 RG |
347 | if (debug) |
348 | gcc_assert (level == 1); | |
3020190e JM |
349 | |
350 | switch (default_opt->levels) | |
351 | { | |
352 | case OPT_LEVELS_ALL: | |
353 | enabled = true; | |
354 | break; | |
355 | ||
356 | case OPT_LEVELS_0_ONLY: | |
357 | enabled = (level == 0); | |
358 | break; | |
359 | ||
360 | case OPT_LEVELS_1_PLUS: | |
361 | enabled = (level >= 1); | |
362 | break; | |
363 | ||
364 | case OPT_LEVELS_1_PLUS_SPEED_ONLY: | |
bf7a7185 RG |
365 | enabled = (level >= 1 && !size && !debug); |
366 | break; | |
367 | ||
368 | case OPT_LEVELS_1_PLUS_NOT_DEBUG: | |
369 | enabled = (level >= 1 && !debug); | |
3020190e JM |
370 | break; |
371 | ||
372 | case OPT_LEVELS_2_PLUS: | |
373 | enabled = (level >= 2); | |
374 | break; | |
375 | ||
376 | case OPT_LEVELS_2_PLUS_SPEED_ONLY: | |
bf7a7185 | 377 | enabled = (level >= 2 && !size && !debug); |
3020190e JM |
378 | break; |
379 | ||
380 | case OPT_LEVELS_3_PLUS: | |
381 | enabled = (level >= 3); | |
382 | break; | |
383 | ||
384 | case OPT_LEVELS_3_PLUS_AND_SIZE: | |
385 | enabled = (level >= 3 || size); | |
386 | break; | |
387 | ||
388 | case OPT_LEVELS_SIZE: | |
389 | enabled = size; | |
390 | break; | |
391 | ||
392 | case OPT_LEVELS_FAST: | |
393 | enabled = fast; | |
394 | break; | |
395 | ||
396 | case OPT_LEVELS_NONE: | |
397 | default: | |
398 | gcc_unreachable (); | |
399 | } | |
400 | ||
401 | if (enabled) | |
402 | handle_generated_option (opts, opts_set, default_opt->opt_index, | |
403 | default_opt->arg, default_opt->value, | |
a4d8c676 JM |
404 | lang_mask, DK_UNSPECIFIED, loc, |
405 | handlers, dc); | |
3020190e | 406 | else if (default_opt->arg == NULL |
300d83d9 | 407 | && !option->cl_reject_negative) |
3020190e JM |
408 | handle_generated_option (opts, opts_set, default_opt->opt_index, |
409 | default_opt->arg, !default_opt->value, | |
a4d8c676 JM |
410 | lang_mask, DK_UNSPECIFIED, loc, |
411 | handlers, dc); | |
3020190e JM |
412 | } |
413 | ||
414 | /* As indicated by the optimization level LEVEL (-Os if SIZE is set, | |
415 | -Ofast if FAST is set), apply the options in array DEFAULT_OPTS to | |
a4d8c676 JM |
416 | OPTS and OPTS_SET, diagnostic context DC, location LOC, with |
417 | language mask LANG_MASK and option handlers HANDLERS. */ | |
3020190e JM |
418 | |
419 | static void | |
420 | maybe_default_options (struct gcc_options *opts, | |
421 | struct gcc_options *opts_set, | |
422 | const struct default_options *default_opts, | |
bf7a7185 | 423 | int level, bool size, bool fast, bool debug, |
3020190e JM |
424 | unsigned int lang_mask, |
425 | const struct cl_option_handlers *handlers, | |
a4d8c676 | 426 | location_t loc, |
3020190e JM |
427 | diagnostic_context *dc) |
428 | { | |
429 | size_t i; | |
430 | ||
431 | for (i = 0; default_opts[i].levels != OPT_LEVELS_NONE; i++) | |
432 | maybe_default_option (opts, opts_set, &default_opts[i], | |
bf7a7185 RG |
433 | level, size, fast, debug, |
434 | lang_mask, handlers, loc, dc); | |
3020190e JM |
435 | } |
436 | ||
437 | /* Table of options enabled by default at different levels. */ | |
438 | ||
439 | static const struct default_options default_options_table[] = | |
440 | { | |
441 | /* -O1 optimizations. */ | |
442 | { OPT_LEVELS_1_PLUS, OPT_fdefer_pop, NULL, 1 }, | |
e90bedf5 | 443 | #if DELAY_SLOTS |
3020190e JM |
444 | { OPT_LEVELS_1_PLUS, OPT_fdelayed_branch, NULL, 1 }, |
445 | #endif | |
446 | { OPT_LEVELS_1_PLUS, OPT_fguess_branch_probability, NULL, 1 }, | |
447 | { OPT_LEVELS_1_PLUS, OPT_fcprop_registers, NULL, 1 }, | |
448 | { OPT_LEVELS_1_PLUS, OPT_fforward_propagate, NULL, 1 }, | |
eeee2277 JY |
449 | { OPT_LEVELS_1_PLUS_NOT_DEBUG, OPT_fif_conversion, NULL, 1 }, |
450 | { OPT_LEVELS_1_PLUS_NOT_DEBUG, OPT_fif_conversion2, NULL, 1 }, | |
3020190e JM |
451 | { OPT_LEVELS_1_PLUS, OPT_fipa_pure_const, NULL, 1 }, |
452 | { OPT_LEVELS_1_PLUS, OPT_fipa_reference, NULL, 1 }, | |
453 | { OPT_LEVELS_1_PLUS, OPT_fipa_profile, NULL, 1 }, | |
454 | { OPT_LEVELS_1_PLUS, OPT_fmerge_constants, NULL, 1 }, | |
59faab7c | 455 | { OPT_LEVELS_1_PLUS, OPT_freorder_blocks, NULL, 1 }, |
484db665 | 456 | { OPT_LEVELS_1_PLUS, OPT_fshrink_wrap, NULL, 1 }, |
3020190e JM |
457 | { OPT_LEVELS_1_PLUS, OPT_fsplit_wide_types, NULL, 1 }, |
458 | { OPT_LEVELS_1_PLUS, OPT_ftree_ccp, NULL, 1 }, | |
78d22941 | 459 | { OPT_LEVELS_1_PLUS_NOT_DEBUG, OPT_ftree_bit_ccp, NULL, 1 }, |
1f9ceff1 | 460 | { OPT_LEVELS_1_PLUS, OPT_ftree_coalesce_vars, NULL, 1 }, |
3020190e JM |
461 | { OPT_LEVELS_1_PLUS, OPT_ftree_dce, NULL, 1 }, |
462 | { OPT_LEVELS_1_PLUS, OPT_ftree_dominator_opts, NULL, 1 }, | |
463 | { OPT_LEVELS_1_PLUS, OPT_ftree_dse, NULL, 1 }, | |
464 | { OPT_LEVELS_1_PLUS, OPT_ftree_ter, NULL, 1 }, | |
bf7a7185 | 465 | { OPT_LEVELS_1_PLUS_NOT_DEBUG, OPT_ftree_sra, NULL, 1 }, |
3020190e JM |
466 | { OPT_LEVELS_1_PLUS, OPT_ftree_fre, NULL, 1 }, |
467 | { OPT_LEVELS_1_PLUS, OPT_ftree_copy_prop, NULL, 1 }, | |
468 | { OPT_LEVELS_1_PLUS, OPT_ftree_sink, NULL, 1 }, | |
469 | { OPT_LEVELS_1_PLUS, OPT_ftree_ch, NULL, 1 }, | |
470 | { OPT_LEVELS_1_PLUS, OPT_fcombine_stack_adjustments, NULL, 1 }, | |
e692f276 | 471 | { OPT_LEVELS_1_PLUS, OPT_fcompare_elim, NULL, 1 }, |
75cfe445 | 472 | { OPT_LEVELS_1_PLUS, OPT_ftree_slsr, NULL, 1 }, |
14379e66 RB |
473 | { OPT_LEVELS_1_PLUS_NOT_DEBUG, OPT_fbranch_count_reg, NULL, 1 }, |
474 | { OPT_LEVELS_1_PLUS_NOT_DEBUG, OPT_fmove_loop_invariants, NULL, 1 }, | |
475 | { OPT_LEVELS_1_PLUS_NOT_DEBUG, OPT_ftree_pta, NULL, 1 }, | |
68f6df73 | 476 | { OPT_LEVELS_1_PLUS_NOT_DEBUG, OPT_fssa_phiopt, NULL, 1 }, |
883cabde | 477 | { OPT_LEVELS_1_PLUS, OPT_ftree_builtin_call_dce, NULL, 1 }, |
3020190e JM |
478 | |
479 | /* -O2 optimizations. */ | |
480 | { OPT_LEVELS_2_PLUS, OPT_finline_small_functions, NULL, 1 }, | |
481 | { OPT_LEVELS_2_PLUS, OPT_findirect_inlining, NULL, 1 }, | |
482 | { OPT_LEVELS_2_PLUS, OPT_fpartial_inlining, NULL, 1 }, | |
483 | { OPT_LEVELS_2_PLUS, OPT_fthread_jumps, NULL, 1 }, | |
484 | { OPT_LEVELS_2_PLUS, OPT_fcrossjumping, NULL, 1 }, | |
485 | { OPT_LEVELS_2_PLUS, OPT_foptimize_sibling_calls, NULL, 1 }, | |
486 | { OPT_LEVELS_2_PLUS, OPT_fcse_follow_jumps, NULL, 1 }, | |
487 | { OPT_LEVELS_2_PLUS, OPT_fgcse, NULL, 1 }, | |
488 | { OPT_LEVELS_2_PLUS, OPT_fexpensive_optimizations, NULL, 1 }, | |
489 | { OPT_LEVELS_2_PLUS, OPT_frerun_cse_after_loop, NULL, 1 }, | |
490 | { OPT_LEVELS_2_PLUS, OPT_fcaller_saves, NULL, 1 }, | |
491 | { OPT_LEVELS_2_PLUS, OPT_fpeephole2, NULL, 1 }, | |
492 | #ifdef INSN_SCHEDULING | |
493 | /* Only run the pre-regalloc scheduling pass if optimizing for speed. */ | |
494 | { OPT_LEVELS_2_PLUS_SPEED_ONLY, OPT_fschedule_insns, NULL, 1 }, | |
495 | { OPT_LEVELS_2_PLUS, OPT_fschedule_insns2, NULL, 1 }, | |
496 | #endif | |
3020190e JM |
497 | { OPT_LEVELS_2_PLUS, OPT_fstrict_aliasing, NULL, 1 }, |
498 | { OPT_LEVELS_2_PLUS, OPT_fstrict_overflow, NULL, 1 }, | |
59faab7c SB |
499 | { OPT_LEVELS_2_PLUS_SPEED_ONLY, OPT_freorder_blocks_algorithm_, NULL, |
500 | REORDER_BLOCKS_ALGORITHM_STC }, | |
3020190e JM |
501 | { OPT_LEVELS_2_PLUS, OPT_freorder_functions, NULL, 1 }, |
502 | { OPT_LEVELS_2_PLUS, OPT_ftree_vrp, NULL, 1 }, | |
3020190e JM |
503 | { OPT_LEVELS_2_PLUS, OPT_ftree_pre, NULL, 1 }, |
504 | { OPT_LEVELS_2_PLUS, OPT_ftree_switch_conversion, NULL, 1 }, | |
505 | { OPT_LEVELS_2_PLUS, OPT_fipa_cp, NULL, 1 }, | |
3c99176a | 506 | { OPT_LEVELS_2_PLUS, OPT_fipa_cp_alignment, NULL, 1 }, |
05842ff5 | 507 | { OPT_LEVELS_2_PLUS, OPT_fdevirtualize, NULL, 1 }, |
bbc9396b | 508 | { OPT_LEVELS_2_PLUS, OPT_fdevirtualize_speculatively, NULL, 1 }, |
3020190e JM |
509 | { OPT_LEVELS_2_PLUS, OPT_fipa_sra, NULL, 1 }, |
510 | { OPT_LEVELS_2_PLUS, OPT_falign_loops, NULL, 1 }, | |
511 | { OPT_LEVELS_2_PLUS, OPT_falign_jumps, NULL, 1 }, | |
512 | { OPT_LEVELS_2_PLUS, OPT_falign_labels, NULL, 1 }, | |
513 | { OPT_LEVELS_2_PLUS, OPT_falign_functions, NULL, 1 }, | |
c9e93168 | 514 | { OPT_LEVELS_2_PLUS, OPT_ftree_tail_merge, NULL, 1 }, |
d6d11272 | 515 | { OPT_LEVELS_2_PLUS, OPT_fvect_cost_model_, NULL, VECT_COST_MODEL_CHEAP }, |
d8878031 | 516 | { OPT_LEVELS_2_PLUS_SPEED_ONLY, OPT_foptimize_strlen, NULL, 1 }, |
372a6eb8 | 517 | { OPT_LEVELS_2_PLUS, OPT_fhoist_adjacent_loads, NULL, 1 }, |
b84d4347 | 518 | { OPT_LEVELS_2_PLUS, OPT_fipa_icf, NULL, 1 }, |
ae93744d | 519 | { OPT_LEVELS_2_PLUS, OPT_fisolate_erroneous_paths_dereference, NULL, 1 }, |
1e288103 | 520 | { OPT_LEVELS_2_PLUS, OPT_fipa_ra, NULL, 1 }, |
d9cf932c | 521 | { OPT_LEVELS_2_PLUS, OPT_flra_remat, NULL, 1 }, |
3020190e JM |
522 | |
523 | /* -O3 optimizations. */ | |
524 | { OPT_LEVELS_3_PLUS, OPT_ftree_loop_distribute_patterns, NULL, 1 }, | |
525 | { OPT_LEVELS_3_PLUS, OPT_fpredictive_commoning, NULL, 1 }, | |
72ca20f9 | 526 | { OPT_LEVELS_3_PLUS, OPT_fsplit_paths, NULL, 1 }, |
3020190e JM |
527 | /* Inlining of functions reducing size is a good idea with -Os |
528 | regardless of them being declared inline. */ | |
529 | { OPT_LEVELS_3_PLUS_AND_SIZE, OPT_finline_functions, NULL, 1 }, | |
bf7a7185 | 530 | { OPT_LEVELS_1_PLUS_NOT_DEBUG, OPT_finline_functions_called_once, NULL, 1 }, |
3020190e JM |
531 | { OPT_LEVELS_3_PLUS, OPT_funswitch_loops, NULL, 1 }, |
532 | { OPT_LEVELS_3_PLUS, OPT_fgcse_after_reload, NULL, 1 }, | |
ea0f3e87 XDL |
533 | { OPT_LEVELS_3_PLUS, OPT_ftree_loop_vectorize, NULL, 1 }, |
534 | { OPT_LEVELS_3_PLUS, OPT_ftree_slp_vectorize, NULL, 1 }, | |
d6d11272 | 535 | { OPT_LEVELS_3_PLUS, OPT_fvect_cost_model_, NULL, VECT_COST_MODEL_DYNAMIC }, |
3020190e | 536 | { OPT_LEVELS_3_PLUS, OPT_fipa_cp_clone, NULL, 1 }, |
fa06ad0d | 537 | { OPT_LEVELS_3_PLUS, OPT_ftree_partial_pre, NULL, 1 }, |
3020190e JM |
538 | |
539 | /* -Ofast adds optimizations to -O3. */ | |
540 | { OPT_LEVELS_FAST, OPT_ffast_math, NULL, 1 }, | |
541 | ||
542 | { OPT_LEVELS_NONE, 0, NULL, 0 } | |
543 | }; | |
544 | ||
a75bfaa6 JM |
545 | /* Default the options in OPTS and OPTS_SET based on the optimization |
546 | settings in DECODED_OPTIONS and DECODED_OPTIONS_COUNT. */ | |
c98cd5bf | 547 | void |
a75bfaa6 JM |
548 | default_options_optimization (struct gcc_options *opts, |
549 | struct gcc_options *opts_set, | |
550 | struct cl_decoded_option *decoded_options, | |
3020190e | 551 | unsigned int decoded_options_count, |
a4d8c676 | 552 | location_t loc, |
3020190e JM |
553 | unsigned int lang_mask, |
554 | const struct cl_option_handlers *handlers, | |
555 | diagnostic_context *dc) | |
a75bfaa6 JM |
556 | { |
557 | unsigned int i; | |
ab442df7 | 558 | int opt2; |
597a8ab9 | 559 | bool openacc_mode = false; |
9756310a NB |
560 | |
561 | /* Scan to see what optimization level has been specified. That will | |
562 | determine the default value of many flags. */ | |
a75bfaa6 | 563 | for (i = 1; i < decoded_options_count; i++) |
9756310a | 564 | { |
a75bfaa6 | 565 | struct cl_decoded_option *opt = &decoded_options[i]; |
6e2f1956 | 566 | switch (opt->opt_index) |
9756310a | 567 | { |
6e2f1956 JM |
568 | case OPT_O: |
569 | if (*opt->arg == '\0') | |
be6d3f0e | 570 | { |
3020190e JM |
571 | opts->x_optimize = 1; |
572 | opts->x_optimize_size = 0; | |
0a8134ca | 573 | opts->x_optimize_fast = 0; |
bf7a7185 | 574 | opts->x_optimize_debug = 0; |
9756310a NB |
575 | } |
576 | else | |
577 | { | |
6e2f1956 JM |
578 | const int optimize_val = integral_argument (opt->arg); |
579 | if (optimize_val == -1) | |
33879b9f MP |
580 | error_at (loc, "argument to %<-O%> should be a non-negative " |
581 | "integer, %<g%>, %<s%> or %<fast%>"); | |
6e2f1956 | 582 | else |
9756310a | 583 | { |
3020190e JM |
584 | opts->x_optimize = optimize_val; |
585 | if ((unsigned int) opts->x_optimize > 255) | |
586 | opts->x_optimize = 255; | |
587 | opts->x_optimize_size = 0; | |
0a8134ca | 588 | opts->x_optimize_fast = 0; |
bf7a7185 | 589 | opts->x_optimize_debug = 0; |
9756310a NB |
590 | } |
591 | } | |
6e2f1956 JM |
592 | break; |
593 | ||
594 | case OPT_Os: | |
3020190e | 595 | opts->x_optimize_size = 1; |
6e2f1956 JM |
596 | |
597 | /* Optimizing for size forces optimize to be 2. */ | |
3020190e | 598 | opts->x_optimize = 2; |
0a8134ca | 599 | opts->x_optimize_fast = 0; |
bf7a7185 | 600 | opts->x_optimize_debug = 0; |
6e2f1956 JM |
601 | break; |
602 | ||
603 | case OPT_Ofast: | |
604 | /* -Ofast only adds flags to -O3. */ | |
3020190e JM |
605 | opts->x_optimize_size = 0; |
606 | opts->x_optimize = 3; | |
0a8134ca | 607 | opts->x_optimize_fast = 1; |
bf7a7185 RG |
608 | opts->x_optimize_debug = 0; |
609 | break; | |
610 | ||
611 | case OPT_Og: | |
612 | /* -Og selects optimization level 1. */ | |
613 | opts->x_optimize_size = 0; | |
614 | opts->x_optimize = 1; | |
615 | opts->x_optimize_fast = 0; | |
616 | opts->x_optimize_debug = 1; | |
6e2f1956 JM |
617 | break; |
618 | ||
597a8ab9 TV |
619 | case OPT_fopenacc: |
620 | if (opt->value) | |
621 | openacc_mode = true; | |
622 | break; | |
623 | ||
6e2f1956 JM |
624 | default: |
625 | /* Ignore other options in this prescan. */ | |
626 | break; | |
9756310a NB |
627 | } |
628 | } | |
b8698a0f | 629 | |
3020190e JM |
630 | maybe_default_options (opts, opts_set, default_options_table, |
631 | opts->x_optimize, opts->x_optimize_size, | |
bf7a7185 RG |
632 | opts->x_optimize_fast, opts->x_optimize_debug, |
633 | lang_mask, handlers, loc, dc); | |
3020190e JM |
634 | |
635 | /* -O2 param settings. */ | |
636 | opt2 = (opts->x_optimize >= 2); | |
116cb604 | 637 | |
597a8ab9 TV |
638 | if (openacc_mode |
639 | && !opts_set->x_flag_ipa_pta) | |
640 | opts->x_flag_ipa_pta = true; | |
641 | ||
ab442df7 | 642 | /* Track fields in field-sensitive alias analysis. */ |
48476d13 JM |
643 | maybe_set_param_value |
644 | (PARAM_MAX_FIELDS_FOR_FIELD_SENSITIVE, | |
645 | opt2 ? 100 : default_param_value (PARAM_MAX_FIELDS_FOR_FIELD_SENSITIVE), | |
646 | opts->x_param_values, opts_set->x_param_values); | |
e9e0aa2c | 647 | |
b1fb9f56 | 648 | /* For -O1 only do loop invariant motion for very small loops. */ |
48476d13 JM |
649 | maybe_set_param_value |
650 | (PARAM_LOOP_INVARIANT_MAX_BBS_IN_LOOP, | |
651 | opt2 ? default_param_value (PARAM_LOOP_INVARIANT_MAX_BBS_IN_LOOP) : 1000, | |
652 | opts->x_param_values, opts_set->x_param_values); | |
b1fb9f56 | 653 | |
680a5a7c MJ |
654 | /* At -Ofast, allow store motion to introduce potential race conditions. */ |
655 | maybe_set_param_value | |
656 | (PARAM_ALLOW_STORE_DATA_RACES, | |
657 | opts->x_optimize_fast ? 1 | |
658 | : default_param_value (PARAM_ALLOW_STORE_DATA_RACES), | |
659 | opts->x_param_values, opts_set->x_param_values); | |
660 | ||
3020190e JM |
661 | if (opts->x_optimize_size) |
662 | /* We want to crossjump as much as possible. */ | |
663 | maybe_set_param_value (PARAM_MIN_CROSSJUMP_INSNS, 1, | |
664 | opts->x_param_values, opts_set->x_param_values); | |
ab442df7 | 665 | else |
128dc8e2 | 666 | maybe_set_param_value (PARAM_MIN_CROSSJUMP_INSNS, |
48476d13 JM |
667 | default_param_value (PARAM_MIN_CROSSJUMP_INSNS), |
668 | opts->x_param_values, opts_set->x_param_values); | |
f736cb3e | 669 | |
b30e733a RB |
670 | /* Restrict the amount of work combine does at -Og while retaining |
671 | most of its useful transforms. */ | |
672 | if (opts->x_optimize_debug) | |
673 | maybe_set_param_value (PARAM_MAX_COMBINE_INSNS, 2, | |
674 | opts->x_param_values, opts_set->x_param_values); | |
675 | ||
a75bfaa6 | 676 | /* Allow default optimizations to be specified on a per-machine basis. */ |
3020190e | 677 | maybe_default_options (opts, opts_set, |
677f3fa8 | 678 | targetm_common.option_optimization_table, |
3020190e | 679 | opts->x_optimize, opts->x_optimize_size, |
bf7a7185 RG |
680 | opts->x_optimize_fast, opts->x_optimize_debug, |
681 | lang_mask, handlers, loc, dc); | |
a75bfaa6 JM |
682 | } |
683 | ||
299404a1 JM |
684 | /* After all options at LOC have been read into OPTS and OPTS_SET, |
685 | finalize settings of those options and diagnose incompatible | |
a75bfaa6 | 686 | combinations. */ |
c98cd5bf | 687 | void |
299404a1 JM |
688 | finish_options (struct gcc_options *opts, struct gcc_options *opts_set, |
689 | location_t loc) | |
a75bfaa6 | 690 | { |
a75bfaa6 JM |
691 | enum unwind_info_type ui_except; |
692 | ||
91035653 JJ |
693 | if (opts->x_dump_base_name |
694 | && ! IS_ABSOLUTE_PATH (opts->x_dump_base_name) | |
695 | && ! opts->x_dump_base_name_prefixed) | |
e71da632 | 696 | { |
d5478783 JM |
697 | /* First try to make OPTS->X_DUMP_BASE_NAME relative to the |
698 | OPTS->X_DUMP_DIR_NAME directory. Then try to make | |
699 | OPTS->X_DUMP_BASE_NAME relative to the OPTS->X_AUX_BASE_NAME | |
700 | directory, typically the directory to contain the object | |
701 | file. */ | |
702 | if (opts->x_dump_dir_name) | |
dc357798 JJ |
703 | opts->x_dump_base_name = opts_concat (opts->x_dump_dir_name, |
704 | opts->x_dump_base_name, NULL); | |
dd3b31fb L |
705 | else if (opts->x_aux_base_name |
706 | && strcmp (opts->x_aux_base_name, HOST_BIT_BUCKET) != 0) | |
e71da632 | 707 | { |
d7fb0a6d L |
708 | const char *aux_base; |
709 | ||
d5478783 JM |
710 | base_of_path (opts->x_aux_base_name, &aux_base); |
711 | if (opts->x_aux_base_name != aux_base) | |
d7fb0a6d | 712 | { |
d5478783 | 713 | int dir_len = aux_base - opts->x_aux_base_name; |
dc357798 JJ |
714 | char *new_dump_base_name |
715 | = XOBNEWVEC (&opts_obstack, char, | |
716 | strlen (opts->x_dump_base_name) + dir_len + 1); | |
d7fb0a6d | 717 | |
d5478783 JM |
718 | /* Copy directory component from OPTS->X_AUX_BASE_NAME. */ |
719 | memcpy (new_dump_base_name, opts->x_aux_base_name, dir_len); | |
720 | /* Append existing OPTS->X_DUMP_BASE_NAME. */ | |
721 | strcpy (new_dump_base_name + dir_len, opts->x_dump_base_name); | |
722 | opts->x_dump_base_name = new_dump_base_name; | |
d7fb0a6d | 723 | } |
e71da632 | 724 | } |
91035653 | 725 | opts->x_dump_base_name_prefixed = true; |
e71da632 MH |
726 | } |
727 | ||
93a4f5e0 JJ |
728 | /* Handle related options for unit-at-a-time, toplevel-reorder, and |
729 | section-anchors. */ | |
d5478783 | 730 | if (!opts->x_flag_unit_at_a_time) |
57b08d04 | 731 | { |
d5478783 | 732 | if (opts->x_flag_section_anchors && opts_set->x_flag_section_anchors) |
299404a1 JM |
733 | error_at (loc, "section anchors must be disabled when unit-at-a-time " |
734 | "is disabled"); | |
d5478783 JM |
735 | opts->x_flag_section_anchors = 0; |
736 | if (opts->x_flag_toplevel_reorder == 1) | |
299404a1 JM |
737 | error_at (loc, "toplevel reorder must be disabled when unit-at-a-time " |
738 | "is disabled"); | |
d5478783 | 739 | opts->x_flag_toplevel_reorder = 0; |
57b08d04 | 740 | } |
7ea6b6cf | 741 | |
ee777b71 AH |
742 | if (opts->x_flag_tm && opts->x_flag_non_call_exceptions) |
743 | sorry ("transactional memory is not supported with non-call exceptions"); | |
744 | ||
5ffebee7 JJ |
745 | /* Unless the user has asked for section anchors, we disable toplevel |
746 | reordering at -O0 to disable transformations that might be surprising | |
747 | to end users and to get -fno-toplevel-reorder tested. */ | |
299404a1 | 748 | if (!opts->x_optimize |
d5478783 JM |
749 | && opts->x_flag_toplevel_reorder == 2 |
750 | && !(opts->x_flag_section_anchors && opts_set->x_flag_section_anchors)) | |
93a4f5e0 | 751 | { |
d5478783 JM |
752 | opts->x_flag_toplevel_reorder = 0; |
753 | opts->x_flag_section_anchors = 0; | |
93a4f5e0 | 754 | } |
d5478783 | 755 | if (!opts->x_flag_toplevel_reorder) |
57b08d04 | 756 | { |
d5478783 | 757 | if (opts->x_flag_section_anchors && opts_set->x_flag_section_anchors) |
299404a1 JM |
758 | error_at (loc, "section anchors must be disabled when toplevel reorder" |
759 | " is disabled"); | |
d5478783 | 760 | opts->x_flag_section_anchors = 0; |
57b08d04 ST |
761 | } |
762 | ||
299404a1 | 763 | if (!opts->x_flag_opts_finished) |
ab442df7 | 764 | { |
428b3812 L |
765 | /* We initialize opts->x_flag_pie to -1 so that targets can set a |
766 | default value. */ | |
767 | if (opts->x_flag_pie == -1) | |
768 | { | |
769 | if (opts->x_flag_pic == 0) | |
770 | opts->x_flag_pie = DEFAULT_FLAG_PIE; | |
771 | else | |
772 | opts->x_flag_pie = 0; | |
773 | } | |
d5478783 JM |
774 | if (opts->x_flag_pie) |
775 | opts->x_flag_pic = opts->x_flag_pie; | |
776 | if (opts->x_flag_pic && !opts->x_flag_pie) | |
777 | opts->x_flag_shlib = 1; | |
b294a75e | 778 | opts->x_flag_opts_finished = true; |
ab442df7 | 779 | } |
9756310a | 780 | |
e0f6cba0 MG |
781 | /* We initialize opts->x_flag_stack_protect to -1 so that targets |
782 | can set a default value. */ | |
783 | if (opts->x_flag_stack_protect == -1) | |
784 | opts->x_flag_stack_protect = DEFAULT_FLAG_SSP; | |
785 | ||
299404a1 | 786 | if (opts->x_optimize == 0) |
9756310a NB |
787 | { |
788 | /* Inlining does not work if not optimizing, | |
789 | so force it not to be done. */ | |
d5478783 JM |
790 | opts->x_warn_inline = 0; |
791 | opts->x_flag_no_inline = 1; | |
9756310a NB |
792 | } |
793 | ||
750054a2 CT |
794 | /* The optimization to partition hot and cold basic blocks into separate |
795 | sections of the .o and executable files does not work (currently) | |
e395963f | 796 | with exception handling. This is because there is no support for |
d5478783 JM |
797 | generating unwind info. If opts->x_flag_exceptions is turned on |
798 | we need to turn off the partitioning optimization. */ | |
750054a2 | 799 | |
677f3fa8 | 800 | ui_except = targetm_common.except_unwind_info (opts); |
f0a0390e | 801 | |
d5478783 JM |
802 | if (opts->x_flag_exceptions |
803 | && opts->x_flag_reorder_blocks_and_partition | |
bf1431e3 | 804 | && (ui_except == UI_SJLJ || ui_except >= UI_TARGET)) |
750054a2 | 805 | { |
32ad0f03 TJ |
806 | if (opts_set->x_flag_reorder_blocks_and_partition) |
807 | inform (loc, | |
808 | "-freorder-blocks-and-partition does not work " | |
809 | "with exceptions on this architecture"); | |
d5478783 JM |
810 | opts->x_flag_reorder_blocks_and_partition = 0; |
811 | opts->x_flag_reorder_blocks = 1; | |
750054a2 | 812 | } |
c7466dee | 813 | |
e395963f JW |
814 | /* If user requested unwind info, then turn off the partitioning |
815 | optimization. */ | |
816 | ||
d5478783 | 817 | if (opts->x_flag_unwind_tables |
677f3fa8 | 818 | && !targetm_common.unwind_tables_default |
d5478783 | 819 | && opts->x_flag_reorder_blocks_and_partition |
bf1431e3 | 820 | && (ui_except == UI_SJLJ || ui_except >= UI_TARGET)) |
e395963f | 821 | { |
32ad0f03 TJ |
822 | if (opts_set->x_flag_reorder_blocks_and_partition) |
823 | inform (loc, | |
824 | "-freorder-blocks-and-partition does not support " | |
825 | "unwind info on this architecture"); | |
d5478783 JM |
826 | opts->x_flag_reorder_blocks_and_partition = 0; |
827 | opts->x_flag_reorder_blocks = 1; | |
e395963f JW |
828 | } |
829 | ||
830 | /* If the target requested unwind info, then turn off the partitioning | |
831 | optimization with a different message. Likewise, if the target does not | |
832 | support named sections. */ | |
833 | ||
d5478783 | 834 | if (opts->x_flag_reorder_blocks_and_partition |
677f3fa8 | 835 | && (!targetm_common.have_named_sections |
d5478783 | 836 | || (opts->x_flag_unwind_tables |
677f3fa8 | 837 | && targetm_common.unwind_tables_default |
bf1431e3 | 838 | && (ui_except == UI_SJLJ || ui_except >= UI_TARGET)))) |
c7466dee | 839 | { |
32ad0f03 TJ |
840 | if (opts_set->x_flag_reorder_blocks_and_partition) |
841 | inform (loc, | |
842 | "-freorder-blocks-and-partition does not work " | |
843 | "on this architecture"); | |
d5478783 JM |
844 | opts->x_flag_reorder_blocks_and_partition = 0; |
845 | opts->x_flag_reorder_blocks = 1; | |
c7466dee | 846 | } |
ab442df7 | 847 | |
66971048 TJ |
848 | /* Disable -freorder-blocks-and-partition when -fprofile-use is not in |
849 | effect. Function splitting was not actually being performed in that case, | |
850 | as probably_never_executed_bb_p does not distinguish any basic blocks as | |
851 | being cold vs hot when there is no profile data. Leaving it enabled, | |
852 | however, causes the assembly code generator to create (empty) cold | |
853 | sections and labels, leading to unnecessary size overhead. */ | |
854 | if (opts->x_flag_reorder_blocks_and_partition | |
855 | && !opts_set->x_flag_profile_use) | |
856 | opts->x_flag_reorder_blocks_and_partition = 0; | |
857 | ||
940c4160 IS |
858 | if (opts->x_flag_reorder_blocks_and_partition |
859 | && !opts_set->x_flag_reorder_functions) | |
860 | opts->x_flag_reorder_functions = 1; | |
861 | ||
e855c69d AB |
862 | /* Pipelining of outer loops is only possible when general pipelining |
863 | capabilities are requested. */ | |
d5478783 JM |
864 | if (!opts->x_flag_sel_sched_pipelining) |
865 | opts->x_flag_sel_sched_pipelining_outer_loops = 0; | |
e855c69d | 866 | |
d5478783 | 867 | if (opts->x_flag_conserve_stack) |
6a78eaa3 | 868 | { |
48476d13 JM |
869 | maybe_set_param_value (PARAM_LARGE_STACK_FRAME, 100, |
870 | opts->x_param_values, opts_set->x_param_values); | |
871 | maybe_set_param_value (PARAM_STACK_FRAME_GROWTH, 40, | |
872 | opts->x_param_values, opts_set->x_param_values); | |
6a78eaa3 JH |
873 | } |
874 | ||
014d92e1 | 875 | if (opts->x_flag_lto) |
e3b8749b RG |
876 | { |
877 | #ifdef ENABLE_LTO | |
d5478783 | 878 | opts->x_flag_generate_lto = 1; |
e3b8749b RG |
879 | |
880 | /* When generating IL, do not operate in whole-program mode. | |
881 | Otherwise, symbols will be privatized too early, causing link | |
882 | errors later. */ | |
d5478783 | 883 | opts->x_flag_whole_program = 0; |
e3b8749b | 884 | #else |
299404a1 | 885 | error_at (loc, "LTO support has not been enabled in this configuration"); |
e3b8749b | 886 | #endif |
063d671d JH |
887 | if (!opts->x_flag_fat_lto_objects |
888 | && (!HAVE_LTO_PLUGIN | |
889 | || (opts_set->x_flag_use_linker_plugin | |
890 | && !opts->x_flag_use_linker_plugin))) | |
e9f67e62 JH |
891 | { |
892 | if (opts_set->x_flag_fat_lto_objects) | |
063d671d | 893 | error_at (loc, "-fno-fat-lto-objects are supported only with linker plugin"); |
e9f67e62 JH |
894 | opts->x_flag_fat_lto_objects = 1; |
895 | } | |
896 | } | |
e3b8749b | 897 | |
d5478783 | 898 | /* We initialize opts->x_flag_split_stack to -1 so that targets can set a |
7458026b | 899 | default value if they choose based on other options. */ |
d5478783 JM |
900 | if (opts->x_flag_split_stack == -1) |
901 | opts->x_flag_split_stack = 0; | |
902 | else if (opts->x_flag_split_stack) | |
7458026b | 903 | { |
677f3fa8 | 904 | if (!targetm_common.supports_split_stack (true, opts)) |
7458026b | 905 | { |
299404a1 JM |
906 | error_at (loc, "%<-fsplit-stack%> is not supported by " |
907 | "this compiler configuration"); | |
d5478783 | 908 | opts->x_flag_split_stack = 0; |
7458026b ILT |
909 | } |
910 | } | |
bfe068c3 | 911 | |
d6d11272 XDL |
912 | /* Tune vectorization related parametees according to cost model. */ |
913 | if (opts->x_flag_vect_cost_model == VECT_COST_MODEL_CHEAP) | |
914 | { | |
915 | maybe_set_param_value (PARAM_VECT_MAX_VERSION_FOR_ALIAS_CHECKS, | |
916 | 6, opts->x_param_values, opts_set->x_param_values); | |
917 | maybe_set_param_value (PARAM_VECT_MAX_VERSION_FOR_ALIGNMENT_CHECKS, | |
918 | 0, opts->x_param_values, opts_set->x_param_values); | |
919 | maybe_set_param_value (PARAM_VECT_MAX_PEELING_FOR_ALIGNMENT, | |
920 | 0, opts->x_param_values, opts_set->x_param_values); | |
921 | } | |
922 | ||
bfe068c3 IR |
923 | /* Set PARAM_MAX_STORES_TO_SINK to 0 if either vectorization or if-conversion |
924 | is disabled. */ | |
ea0f3e87 XDL |
925 | if ((!opts->x_flag_tree_loop_vectorize && !opts->x_flag_tree_slp_vectorize) |
926 | || !opts->x_flag_tree_loop_if_convert) | |
bfe068c3 IR |
927 | maybe_set_param_value (PARAM_MAX_STORES_TO_SINK, 0, |
928 | opts->x_param_values, opts_set->x_param_values); | |
e9f8dcf9 | 929 | |
bd5c3baa | 930 | /* The -gsplit-dwarf option requires -ggnu-pubnames. */ |
99ea153e | 931 | if (opts->x_dwarf_split_debug_info) |
bd5c3baa | 932 | opts->x_debug_generate_pub_sections = 2; |
fec4842d | 933 | |
fed4de37 | 934 | /* Userspace and kernel ASan conflict with each other. */ |
fec4842d | 935 | |
d95a2703 JJ |
936 | if ((opts->x_flag_sanitize & SANITIZE_USER_ADDRESS) |
937 | && (opts->x_flag_sanitize & SANITIZE_KERNEL_ADDRESS)) | |
fec4842d | 938 | error_at (loc, |
d95a2703 JJ |
939 | "-fsanitize=address is incompatible with " |
940 | "-fsanitize=kernel-address"); | |
fec4842d | 941 | |
fed4de37 YG |
942 | /* And with TSan. */ |
943 | ||
d95a2703 JJ |
944 | if ((opts->x_flag_sanitize & SANITIZE_ADDRESS) |
945 | && (opts->x_flag_sanitize & SANITIZE_THREAD)) | |
fec4842d | 946 | error_at (loc, |
d95a2703 JJ |
947 | "-fsanitize=address and -fsanitize=kernel-address " |
948 | "are incompatible with -fsanitize=thread"); | |
949 | ||
b59e2a49 | 950 | /* Error recovery is not allowed for LSan and TSan. */ |
d95a2703 JJ |
951 | |
952 | if (opts->x_flag_sanitize_recover & SANITIZE_THREAD) | |
953 | error_at (loc, "-fsanitize-recover=thread is not supported"); | |
954 | ||
955 | if (opts->x_flag_sanitize_recover & SANITIZE_LEAK) | |
956 | error_at (loc, "-fsanitize-recover=leak is not supported"); | |
9ca0032c MZ |
957 | |
958 | /* When instrumenting the pointers, we don't want to remove | |
959 | the null pointer checks. */ | |
960 | if (opts->x_flag_sanitize & (SANITIZE_NULL | SANITIZE_NONNULL_ATTRIBUTE | |
961 | | SANITIZE_RETURNS_NONNULL_ATTRIBUTE)) | |
962 | opts->x_flag_delete_null_pointer_checks = 0; | |
963 | ||
964 | /* Aggressive compiler optimizations may cause false negatives. */ | |
965 | if (opts->x_flag_sanitize) | |
966 | { | |
967 | opts->x_flag_aggressive_loop_optimizations = 0; | |
968 | opts->x_flag_strict_overflow = 0; | |
969 | } | |
9756310a NB |
970 | } |
971 | ||
c662432e NC |
972 | #define LEFT_COLUMN 27 |
973 | ||
974 | /* Output ITEM, of length ITEM_WIDTH, in the left column, | |
975 | followed by word-wrapped HELP in a second column. */ | |
976 | static void | |
977 | wrap_help (const char *help, | |
978 | const char *item, | |
979 | unsigned int item_width, | |
980 | unsigned int columns) | |
981 | { | |
982 | unsigned int col_width = LEFT_COLUMN; | |
983 | unsigned int remaining, room, len; | |
984 | ||
985 | remaining = strlen (help); | |
986 | ||
987 | do | |
988 | { | |
989 | room = columns - 3 - MAX (col_width, item_width); | |
990 | if (room > columns) | |
991 | room = 0; | |
992 | len = remaining; | |
993 | ||
994 | if (room < len) | |
995 | { | |
996 | unsigned int i; | |
997 | ||
998 | for (i = 0; help[i]; i++) | |
999 | { | |
1000 | if (i >= room && len != remaining) | |
1001 | break; | |
1002 | if (help[i] == ' ') | |
1003 | len = i; | |
1004 | else if ((help[i] == '-' || help[i] == '/') | |
1005 | && help[i + 1] != ' ' | |
1006 | && i > 0 && ISALPHA (help[i - 1])) | |
1007 | len = i + 1; | |
1008 | } | |
1009 | } | |
1010 | ||
c3284718 | 1011 | printf (" %-*.*s %.*s\n", col_width, item_width, item, len, help); |
c662432e NC |
1012 | item_width = 0; |
1013 | while (help[len] == ' ') | |
1014 | len++; | |
1015 | help += len; | |
1016 | remaining -= len; | |
1017 | } | |
1018 | while (remaining); | |
1019 | } | |
1020 | ||
1021 | /* Print help for a specific front-end, etc. */ | |
1022 | static void | |
1023 | print_filtered_help (unsigned int include_flags, | |
1024 | unsigned int exclude_flags, | |
1025 | unsigned int any_flags, | |
0576d21f | 1026 | unsigned int columns, |
e6d4b984 JM |
1027 | struct gcc_options *opts, |
1028 | unsigned int lang_mask) | |
c662432e NC |
1029 | { |
1030 | unsigned int i; | |
1031 | const char *help; | |
c662432e NC |
1032 | bool found = false; |
1033 | bool displayed = false; | |
a7b2e184 | 1034 | char new_help[256]; |
c662432e NC |
1035 | |
1036 | if (include_flags == CL_PARAMS) | |
1037 | { | |
1038 | for (i = 0; i < LAST_PARAM; i++) | |
1039 | { | |
1040 | const char *param = compiler_params[i].option; | |
1041 | ||
1042 | help = compiler_params[i].help; | |
1043 | if (help == NULL || *help == '\0') | |
1044 | { | |
1045 | if (exclude_flags & CL_UNDOCUMENTED) | |
1046 | continue; | |
1047 | help = undocumented_msg; | |
1048 | } | |
1049 | ||
1050 | /* Get the translation. */ | |
1051 | help = _(help); | |
1052 | ||
ff5101bf AK |
1053 | if (!opts->x_quiet_flag) |
1054 | { | |
1055 | snprintf (new_help, sizeof (new_help), | |
1056 | _("default %d minimum %d maximum %d"), | |
1057 | compiler_params[i].default_value, | |
1058 | compiler_params[i].min_value, | |
1059 | compiler_params[i].max_value); | |
1060 | help = new_help; | |
1061 | } | |
c662432e NC |
1062 | wrap_help (help, param, strlen (param), columns); |
1063 | } | |
1064 | putchar ('\n'); | |
1065 | return; | |
1066 | } | |
1067 | ||
299404a1 JM |
1068 | if (!opts->x_help_printed) |
1069 | opts->x_help_printed = XCNEWVAR (char, cl_options_count); | |
c662432e | 1070 | |
e6d4b984 JM |
1071 | if (!opts->x_help_enum_printed) |
1072 | opts->x_help_enum_printed = XCNEWVAR (char, cl_enums_count); | |
1073 | ||
c662432e NC |
1074 | for (i = 0; i < cl_options_count; i++) |
1075 | { | |
c662432e NC |
1076 | const struct cl_option *option = cl_options + i; |
1077 | unsigned int len; | |
1078 | const char *opt; | |
1079 | const char *tab; | |
1080 | ||
1081 | if (include_flags == 0 | |
1082 | || ((option->flags & include_flags) != include_flags)) | |
1083 | { | |
1084 | if ((option->flags & any_flags) == 0) | |
1085 | continue; | |
1086 | } | |
1087 | ||
1088 | /* Skip unwanted switches. */ | |
1089 | if ((option->flags & exclude_flags) != 0) | |
1090 | continue; | |
1091 | ||
603349bf JM |
1092 | /* The driver currently prints its own help text. */ |
1093 | if ((option->flags & CL_DRIVER) != 0 | |
1094 | && (option->flags & (((1U << cl_lang_count) - 1) | |
1095 | | CL_COMMON | CL_TARGET)) == 0) | |
1096 | continue; | |
1097 | ||
c662432e NC |
1098 | found = true; |
1099 | /* Skip switches that have already been printed. */ | |
299404a1 | 1100 | if (opts->x_help_printed[i]) |
c662432e NC |
1101 | continue; |
1102 | ||
299404a1 | 1103 | opts->x_help_printed[i] = true; |
c662432e NC |
1104 | |
1105 | help = option->help; | |
1106 | if (help == NULL) | |
1107 | { | |
1108 | if (exclude_flags & CL_UNDOCUMENTED) | |
1109 | continue; | |
a7b2e184 | 1110 | |
c662432e NC |
1111 | help = undocumented_msg; |
1112 | } | |
1113 | ||
a7b2e184 MS |
1114 | if (option->alias_target < N_OPTS |
1115 | && cl_options [option->alias_target].help) | |
1116 | { | |
1117 | if (help == undocumented_msg) | |
1118 | { | |
1119 | /* For undocumented options that are aliases for other options | |
1120 | that are documented, point the reader to the other option in | |
1121 | preference of the former. */ | |
1122 | snprintf (new_help, sizeof new_help, | |
1123 | _("Same as %s. Use the latter option instead."), | |
1124 | cl_options [option->alias_target].opt_text); | |
1125 | } | |
1126 | else | |
1127 | { | |
1128 | /* For documented options with aliases, mention the aliased | |
1129 | option's name for reference. */ | |
1130 | snprintf (new_help, sizeof new_help, | |
1131 | _("%s Same as %s."), | |
1132 | help, cl_options [option->alias_target].opt_text); | |
1133 | } | |
1134 | ||
1135 | help = new_help; | |
1136 | } | |
1137 | ||
1138 | if (option->warn_message) | |
1139 | { | |
1140 | /* Mention that the use of the option will trigger a warning. */ | |
1141 | if (help == new_help) | |
1142 | snprintf (new_help + strlen (new_help), | |
1143 | sizeof new_help - strlen (new_help), | |
1144 | " %s", _(use_diagnosed_msg)); | |
1145 | else | |
1146 | snprintf (new_help, sizeof new_help, | |
1147 | "%s %s", help, _(use_diagnosed_msg)); | |
1148 | ||
1149 | help = new_help; | |
1150 | } | |
1151 | ||
c662432e NC |
1152 | /* Get the translation. */ |
1153 | help = _(help); | |
1154 | ||
1155 | /* Find the gap between the name of the | |
1156 | option and its descriptive text. */ | |
1157 | tab = strchr (help, '\t'); | |
1158 | if (tab) | |
1159 | { | |
1160 | len = tab - help; | |
1161 | opt = help; | |
1162 | help = tab + 1; | |
1163 | } | |
1164 | else | |
1165 | { | |
1166 | opt = option->opt_text; | |
1167 | len = strlen (opt); | |
1168 | } | |
1169 | ||
1170 | /* With the -Q option enabled we change the descriptive text associated | |
1171 | with an option to be an indication of its current setting. */ | |
a7d0d30f | 1172 | if (!opts->x_quiet_flag) |
c662432e | 1173 | { |
0576d21f | 1174 | void *flag_var = option_flag_var (i, opts); |
46625112 | 1175 | |
c662432e NC |
1176 | if (len < (LEFT_COLUMN + 2)) |
1177 | strcpy (new_help, "\t\t"); | |
1178 | else | |
1179 | strcpy (new_help, "\t"); | |
1180 | ||
21bf1558 JM |
1181 | if (flag_var != NULL |
1182 | && option->var_type != CLVC_DEFER) | |
c662432e NC |
1183 | { |
1184 | if (option->flags & CL_JOINED) | |
1185 | { | |
1186 | if (option->var_type == CLVC_STRING) | |
1187 | { | |
46625112 | 1188 | if (* (const char **) flag_var != NULL) |
c662432e NC |
1189 | snprintf (new_help + strlen (new_help), |
1190 | sizeof (new_help) - strlen (new_help), | |
81018dcf | 1191 | "%s", * (const char **) flag_var); |
c662432e | 1192 | } |
e6d4b984 JM |
1193 | else if (option->var_type == CLVC_ENUM) |
1194 | { | |
1195 | const struct cl_enum *e = &cl_enums[option->var_enum]; | |
1196 | int value; | |
1197 | const char *arg = NULL; | |
1198 | ||
1199 | value = e->get (flag_var); | |
1200 | enum_value_to_arg (e->values, &arg, value, lang_mask); | |
1201 | if (arg == NULL) | |
1202 | arg = _("[default]"); | |
1203 | snprintf (new_help + strlen (new_help), | |
1204 | sizeof (new_help) - strlen (new_help), | |
81018dcf | 1205 | "%s", arg); |
e6d4b984 | 1206 | } |
c662432e NC |
1207 | else |
1208 | sprintf (new_help + strlen (new_help), | |
46625112 | 1209 | "%#x", * (int *) flag_var); |
c662432e NC |
1210 | } |
1211 | else | |
0576d21f | 1212 | strcat (new_help, option_enabled (i, opts) |
c662432e NC |
1213 | ? _("[enabled]") : _("[disabled]")); |
1214 | } | |
1215 | ||
1216 | help = new_help; | |
1217 | } | |
1218 | ||
1219 | wrap_help (help, opt, len, columns); | |
1220 | displayed = true; | |
e6d4b984 JM |
1221 | |
1222 | if (option->var_type == CLVC_ENUM | |
1223 | && opts->x_help_enum_printed[option->var_enum] != 2) | |
1224 | opts->x_help_enum_printed[option->var_enum] = 1; | |
c662432e NC |
1225 | } |
1226 | ||
1227 | if (! found) | |
b3eaaf1a NC |
1228 | { |
1229 | unsigned int langs = include_flags & CL_LANG_ALL; | |
1230 | ||
1231 | if (langs == 0) | |
1232 | printf (_(" No options with the desired characteristics were found\n")); | |
1233 | else | |
1234 | { | |
1235 | unsigned int i; | |
1236 | ||
1237 | /* PR 31349: Tell the user how to see all of the | |
1238 | options supported by a specific front end. */ | |
1239 | for (i = 0; (1U << i) < CL_LANG_ALL; i ++) | |
1240 | if ((1U << i) & langs) | |
a7b2e184 | 1241 | printf (_(" None found. Use --help=%s to show *all* the options supported by the %s front-end.\n"), |
b3eaaf1a NC |
1242 | lang_names[i], lang_names[i]); |
1243 | } | |
b8698a0f | 1244 | |
b3eaaf1a | 1245 | } |
c662432e NC |
1246 | else if (! displayed) |
1247 | printf (_(" All options with the desired characteristics have already been displayed\n")); | |
1248 | ||
1249 | putchar ('\n'); | |
e6d4b984 JM |
1250 | |
1251 | /* Print details of enumerated option arguments, if those | |
1252 | enumerations have help text headings provided. If no help text | |
1253 | is provided, presume that the possible values are listed in the | |
1254 | help text for the relevant options. */ | |
1255 | for (i = 0; i < cl_enums_count; i++) | |
1256 | { | |
1257 | unsigned int j, pos; | |
1258 | ||
1259 | if (opts->x_help_enum_printed[i] != 1) | |
1260 | continue; | |
1261 | if (cl_enums[i].help == NULL) | |
1262 | continue; | |
1263 | printf (" %s\n ", _(cl_enums[i].help)); | |
1264 | pos = 4; | |
1265 | for (j = 0; cl_enums[i].values[j].arg != NULL; j++) | |
1266 | { | |
1267 | unsigned int len = strlen (cl_enums[i].values[j].arg); | |
1268 | ||
1269 | if (pos > 4 && pos + 1 + len <= columns) | |
1270 | { | |
1271 | printf (" %s", cl_enums[i].values[j].arg); | |
1272 | pos += 1 + len; | |
1273 | } | |
1274 | else | |
1275 | { | |
1276 | if (pos > 4) | |
1277 | { | |
1278 | printf ("\n "); | |
1279 | pos = 4; | |
1280 | } | |
1281 | printf ("%s", cl_enums[i].values[j].arg); | |
1282 | pos += len; | |
1283 | } | |
1284 | } | |
1285 | printf ("\n\n"); | |
1286 | opts->x_help_enum_printed[i] = 2; | |
1287 | } | |
c662432e NC |
1288 | } |
1289 | ||
1290 | /* Display help for a specified type of option. | |
1291 | The options must have ALL of the INCLUDE_FLAGS set | |
1292 | ANY of the flags in the ANY_FLAGS set | |
0576d21f | 1293 | and NONE of the EXCLUDE_FLAGS set. The current option state is in |
e6d4b984 | 1294 | OPTS; LANG_MASK is used for interpreting enumerated option state. */ |
c662432e NC |
1295 | static void |
1296 | print_specific_help (unsigned int include_flags, | |
1297 | unsigned int exclude_flags, | |
0576d21f | 1298 | unsigned int any_flags, |
e6d4b984 JM |
1299 | struct gcc_options *opts, |
1300 | unsigned int lang_mask) | |
c662432e NC |
1301 | { |
1302 | unsigned int all_langs_mask = (1U << cl_lang_count) - 1; | |
1303 | const char * description = NULL; | |
1304 | const char * descrip_extra = ""; | |
1305 | size_t i; | |
1306 | unsigned int flag; | |
c662432e NC |
1307 | |
1308 | /* Sanity check: Make sure that we do not have more | |
1309 | languages than we have bits available to enumerate them. */ | |
58265ea6 | 1310 | gcc_assert ((1U << cl_lang_count) <= CL_MIN_OPTION_CLASS); |
c662432e NC |
1311 | |
1312 | /* If we have not done so already, obtain | |
1313 | the desired maximum width of the output. */ | |
299404a1 | 1314 | if (opts->x_help_columns == 0) |
c662432e | 1315 | { |
c9db45aa TB |
1316 | opts->x_help_columns = get_terminal_width (); |
1317 | if (opts->x_help_columns == INT_MAX) | |
c662432e | 1318 | /* Use a reasonable default. */ |
299404a1 | 1319 | opts->x_help_columns = 80; |
c662432e NC |
1320 | } |
1321 | ||
1322 | /* Decide upon the title for the options that we are going to display. */ | |
1323 | for (i = 0, flag = 1; flag <= CL_MAX_OPTION_CLASS; flag <<= 1, i ++) | |
1324 | { | |
1325 | switch (flag & include_flags) | |
1326 | { | |
1327 | case 0: | |
603349bf | 1328 | case CL_DRIVER: |
c662432e NC |
1329 | break; |
1330 | ||
1331 | case CL_TARGET: | |
1332 | description = _("The following options are target specific"); | |
1333 | break; | |
1334 | case CL_WARNING: | |
1335 | description = _("The following options control compiler warning messages"); | |
1336 | break; | |
1337 | case CL_OPTIMIZATION: | |
1338 | description = _("The following options control optimizations"); | |
1339 | break; | |
1340 | case CL_COMMON: | |
1341 | description = _("The following options are language-independent"); | |
1342 | break; | |
1343 | case CL_PARAMS: | |
1344 | description = _("The --param option recognizes the following as parameters"); | |
1345 | break; | |
1346 | default: | |
1347 | if (i >= cl_lang_count) | |
1348 | break; | |
0631b69f | 1349 | if (exclude_flags & all_langs_mask) |
c01c261d | 1350 | description = _("The following options are specific to just the language "); |
c662432e | 1351 | else |
b5456e04 | 1352 | description = _("The following options are supported by the language "); |
b3eaaf1a | 1353 | descrip_extra = lang_names [i]; |
c662432e NC |
1354 | break; |
1355 | } | |
1356 | } | |
1357 | ||
1358 | if (description == NULL) | |
1359 | { | |
1360 | if (any_flags == 0) | |
1361 | { | |
0631b69f | 1362 | if (include_flags & CL_UNDOCUMENTED) |
c662432e | 1363 | description = _("The following options are not documented"); |
0631b69f RW |
1364 | else if (include_flags & CL_SEPARATE) |
1365 | description = _("The following options take separate arguments"); | |
1366 | else if (include_flags & CL_JOINED) | |
1367 | description = _("The following options take joined arguments"); | |
c662432e NC |
1368 | else |
1369 | { | |
1370 | internal_error ("unrecognized include_flags 0x%x passed to print_specific_help", | |
1371 | include_flags); | |
1372 | return; | |
1373 | } | |
1374 | } | |
1375 | else | |
1376 | { | |
1377 | if (any_flags & all_langs_mask) | |
1378 | description = _("The following options are language-related"); | |
1379 | else | |
1380 | description = _("The following options are language-independent"); | |
1381 | } | |
1382 | } | |
1383 | ||
1384 | printf ("%s%s:\n", description, descrip_extra); | |
299404a1 | 1385 | print_filtered_help (include_flags, exclude_flags, any_flags, |
e6d4b984 | 1386 | opts->x_help_columns, opts, lang_mask); |
c662432e NC |
1387 | } |
1388 | ||
be3c16c4 DC |
1389 | /* Enable FDO-related flags. */ |
1390 | ||
1391 | static void | |
1392 | enable_fdo_optimizations (struct gcc_options *opts, | |
1393 | struct gcc_options *opts_set, | |
1394 | int value) | |
1395 | { | |
1396 | if (!opts_set->x_flag_branch_probabilities) | |
1397 | opts->x_flag_branch_probabilities = value; | |
1398 | if (!opts_set->x_flag_profile_values) | |
1399 | opts->x_flag_profile_values = value; | |
1400 | if (!opts_set->x_flag_unroll_loops) | |
1401 | opts->x_flag_unroll_loops = value; | |
1402 | if (!opts_set->x_flag_peel_loops) | |
1403 | opts->x_flag_peel_loops = value; | |
1404 | if (!opts_set->x_flag_tracer) | |
1405 | opts->x_flag_tracer = value; | |
1406 | if (!opts_set->x_flag_value_profile_transformations) | |
1407 | opts->x_flag_value_profile_transformations = value; | |
1408 | if (!opts_set->x_flag_inline_functions) | |
1409 | opts->x_flag_inline_functions = value; | |
1410 | if (!opts_set->x_flag_ipa_cp) | |
1411 | opts->x_flag_ipa_cp = value; | |
1412 | if (!opts_set->x_flag_ipa_cp_clone | |
1413 | && value && opts->x_flag_ipa_cp) | |
1414 | opts->x_flag_ipa_cp_clone = value; | |
3c99176a L |
1415 | if (!opts_set->x_flag_ipa_cp_alignment |
1416 | && value && opts->x_flag_ipa_cp) | |
1417 | opts->x_flag_ipa_cp_alignment = value; | |
be3c16c4 DC |
1418 | if (!opts_set->x_flag_predictive_commoning) |
1419 | opts->x_flag_predictive_commoning = value; | |
1420 | if (!opts_set->x_flag_unswitch_loops) | |
1421 | opts->x_flag_unswitch_loops = value; | |
1422 | if (!opts_set->x_flag_gcse_after_reload) | |
1423 | opts->x_flag_gcse_after_reload = value; | |
1424 | if (!opts_set->x_flag_tree_loop_vectorize | |
1425 | && !opts_set->x_flag_tree_vectorize) | |
1426 | opts->x_flag_tree_loop_vectorize = value; | |
1427 | if (!opts_set->x_flag_tree_slp_vectorize | |
1428 | && !opts_set->x_flag_tree_vectorize) | |
1429 | opts->x_flag_tree_slp_vectorize = value; | |
1430 | if (!opts_set->x_flag_vect_cost_model) | |
1431 | opts->x_flag_vect_cost_model = VECT_COST_MODEL_DYNAMIC; | |
1432 | if (!opts_set->x_flag_tree_loop_distribute_patterns) | |
1433 | opts->x_flag_tree_loop_distribute_patterns = value; | |
1434 | } | |
1435 | ||
b1b46af0 | 1436 | /* -f{,no-}sanitize{,-recover}= suboptions. */ |
61789eed | 1437 | const struct sanitizer_opts_s sanitizer_opts[] = |
b1b46af0 JJ |
1438 | { |
1439 | #define SANITIZER_OPT(name, flags) { #name, flags, sizeof #name - 1 } | |
1440 | SANITIZER_OPT (address, SANITIZE_ADDRESS | SANITIZE_USER_ADDRESS), | |
1441 | SANITIZER_OPT (kernel-address, SANITIZE_ADDRESS | SANITIZE_KERNEL_ADDRESS), | |
1442 | SANITIZER_OPT (thread, SANITIZE_THREAD), | |
1443 | SANITIZER_OPT (leak, SANITIZE_LEAK), | |
1444 | SANITIZER_OPT (shift, SANITIZE_SHIFT), | |
1445 | SANITIZER_OPT (integer-divide-by-zero, SANITIZE_DIVIDE), | |
1446 | SANITIZER_OPT (undefined, SANITIZE_UNDEFINED), | |
1447 | SANITIZER_OPT (unreachable, SANITIZE_UNREACHABLE), | |
1448 | SANITIZER_OPT (vla-bound, SANITIZE_VLA), | |
1449 | SANITIZER_OPT (return, SANITIZE_RETURN), | |
1450 | SANITIZER_OPT (null, SANITIZE_NULL), | |
1451 | SANITIZER_OPT (signed-integer-overflow, SANITIZE_SI_OVERFLOW), | |
1452 | SANITIZER_OPT (bool, SANITIZE_BOOL), | |
1453 | SANITIZER_OPT (enum, SANITIZE_ENUM), | |
1454 | SANITIZER_OPT (float-divide-by-zero, SANITIZE_FLOAT_DIVIDE), | |
1455 | SANITIZER_OPT (float-cast-overflow, SANITIZE_FLOAT_CAST), | |
1456 | SANITIZER_OPT (bounds, SANITIZE_BOUNDS), | |
1457 | SANITIZER_OPT (bounds-strict, SANITIZE_BOUNDS | SANITIZE_BOUNDS_STRICT), | |
1458 | SANITIZER_OPT (alignment, SANITIZE_ALIGNMENT), | |
1459 | SANITIZER_OPT (nonnull-attribute, SANITIZE_NONNULL_ATTRIBUTE), | |
1460 | SANITIZER_OPT (returns-nonnull-attribute, SANITIZE_RETURNS_NONNULL_ATTRIBUTE), | |
1461 | SANITIZER_OPT (object-size, SANITIZE_OBJECT_SIZE), | |
1462 | SANITIZER_OPT (vptr, SANITIZE_VPTR), | |
1463 | SANITIZER_OPT (all, ~0), | |
1464 | #undef SANITIZER_OPT | |
1465 | { NULL, 0, 0 } | |
1466 | }; | |
1467 | ||
1468 | /* Parse comma separated sanitizer suboptions from P for option SCODE, | |
1469 | adjust previous FLAGS and return new ones. If COMPLAIN is false, | |
1470 | don't issue diagnostics. */ | |
1471 | ||
1472 | unsigned int | |
1473 | parse_sanitizer_options (const char *p, location_t loc, int scode, | |
1474 | unsigned int flags, int value, bool complain) | |
1475 | { | |
1476 | enum opt_code code = (enum opt_code) scode; | |
1477 | while (*p != 0) | |
1478 | { | |
1479 | size_t len, i; | |
1480 | bool found = false; | |
1481 | const char *comma = strchr (p, ','); | |
1482 | ||
1483 | if (comma == NULL) | |
1484 | len = strlen (p); | |
1485 | else | |
1486 | len = comma - p; | |
1487 | if (len == 0) | |
1488 | { | |
1489 | p = comma + 1; | |
1490 | continue; | |
1491 | } | |
1492 | ||
1493 | /* Check to see if the string matches an option class name. */ | |
1494 | for (i = 0; sanitizer_opts[i].name != NULL; ++i) | |
1495 | if (len == sanitizer_opts[i].len | |
1496 | && memcmp (p, sanitizer_opts[i].name, len) == 0) | |
1497 | { | |
1498 | /* Handle both -fsanitize and -fno-sanitize cases. */ | |
1499 | if (value && sanitizer_opts[i].flag == ~0U) | |
1500 | { | |
1501 | if (code == OPT_fsanitize_) | |
1502 | { | |
1503 | if (complain) | |
1504 | error_at (loc, "-fsanitize=all option is not valid"); | |
1505 | } | |
1506 | else | |
1507 | flags |= ~(SANITIZE_USER_ADDRESS | SANITIZE_THREAD | |
1508 | | SANITIZE_LEAK); | |
1509 | } | |
1510 | else if (value) | |
1511 | flags |= sanitizer_opts[i].flag; | |
1512 | else | |
1513 | flags &= ~sanitizer_opts[i].flag; | |
1514 | found = true; | |
1515 | break; | |
1516 | } | |
1517 | ||
1518 | if (! found && complain) | |
1519 | error_at (loc, "unrecognized argument to -fsanitize%s= option: %q.*s", | |
1520 | code == OPT_fsanitize_ ? "" : "-recover", (int) len, p); | |
1521 | ||
1522 | if (comma == NULL) | |
1523 | break; | |
1524 | p = comma + 1; | |
1525 | } | |
1526 | return flags; | |
1527 | } | |
1528 | ||
d7b42618 | 1529 | /* Handle target- and language-independent options. Return zero to |
50431bc4 ZD |
1530 | generate an "unknown option" message. Only options that need |
1531 | extra handling need to be listed here; if you simply want | |
481e1176 | 1532 | DECODED->value assigned to a variable, it happens automatically. */ |
50431bc4 | 1533 | |
c98cd5bf | 1534 | bool |
46625112 | 1535 | common_handle_option (struct gcc_options *opts, |
d4d24ba4 | 1536 | struct gcc_options *opts_set, |
46625112 | 1537 | const struct cl_decoded_option *decoded, |
5f20c657 | 1538 | unsigned int lang_mask, int kind ATTRIBUTE_UNUSED, |
a4d8c676 | 1539 | location_t loc, |
d5478783 JM |
1540 | const struct cl_option_handlers *handlers, |
1541 | diagnostic_context *dc) | |
d7b42618 | 1542 | { |
481e1176 JM |
1543 | size_t scode = decoded->opt_index; |
1544 | const char *arg = decoded->arg; | |
1545 | int value = decoded->value; | |
d7b42618 NB |
1546 | enum opt_code code = (enum opt_code) scode; |
1547 | ||
481e1176 JM |
1548 | gcc_assert (decoded->canonical_option_num_elements <= 2); |
1549 | ||
d7b42618 NB |
1550 | switch (code) |
1551 | { | |
903caebf | 1552 | case OPT__param: |
299404a1 | 1553 | handle_param (opts, opts_set, loc, arg); |
903caebf NB |
1554 | break; |
1555 | ||
c662432e NC |
1556 | case OPT__help: |
1557 | { | |
1558 | unsigned int all_langs_mask = (1U << cl_lang_count) - 1; | |
1559 | unsigned int undoc_mask; | |
1560 | unsigned int i; | |
1561 | ||
a7d0d30f | 1562 | if (lang_mask == CL_DRIVER) |
6f3d1a5e | 1563 | break; |
a7d0d30f | 1564 | |
d5478783 JM |
1565 | undoc_mask = ((opts->x_verbose_flag | opts->x_extra_warnings) |
1566 | ? 0 | |
1567 | : CL_UNDOCUMENTED); | |
c662432e NC |
1568 | /* First display any single language specific options. */ |
1569 | for (i = 0; i < cl_lang_count; i++) | |
1570 | print_specific_help | |
e6d4b984 JM |
1571 | (1U << i, (all_langs_mask & (~ (1U << i))) | undoc_mask, 0, opts, |
1572 | lang_mask); | |
c662432e | 1573 | /* Next display any multi language specific options. */ |
e6d4b984 | 1574 | print_specific_help (0, undoc_mask, all_langs_mask, opts, lang_mask); |
c662432e NC |
1575 | /* Then display any remaining, non-language options. */ |
1576 | for (i = CL_MIN_OPTION_CLASS; i <= CL_MAX_OPTION_CLASS; i <<= 1) | |
603349bf | 1577 | if (i != CL_DRIVER) |
e6d4b984 | 1578 | print_specific_help (i, undoc_mask, 0, opts, lang_mask); |
0576d21f | 1579 | opts->x_exit_after_options = true; |
c662432e NC |
1580 | break; |
1581 | } | |
1582 | ||
d185d268 | 1583 | case OPT__target_help: |
a7d0d30f JM |
1584 | if (lang_mask == CL_DRIVER) |
1585 | break; | |
1586 | ||
e6d4b984 | 1587 | print_specific_help (CL_TARGET, CL_UNDOCUMENTED, 0, opts, lang_mask); |
0576d21f | 1588 | opts->x_exit_after_options = true; |
d185d268 NB |
1589 | break; |
1590 | ||
c662432e NC |
1591 | case OPT__help_: |
1592 | { | |
1593 | const char * a = arg; | |
1594 | unsigned int include_flags = 0; | |
1595 | /* Note - by default we include undocumented options when listing | |
1596 | specific classes. If you only want to see documented options | |
fa10beec | 1597 | then add ",^undocumented" to the --help= option. E.g.: |
c662432e NC |
1598 | |
1599 | --help=target,^undocumented */ | |
1600 | unsigned int exclude_flags = 0; | |
1601 | ||
a7d0d30f JM |
1602 | if (lang_mask == CL_DRIVER) |
1603 | break; | |
1604 | ||
c662432e NC |
1605 | /* Walk along the argument string, parsing each word in turn. |
1606 | The format is: | |
1607 | arg = [^]{word}[,{arg}] | |
b5456e04 BM |
1608 | word = {optimizers|target|warnings|undocumented| |
1609 | params|common|<language>} */ | |
c662432e NC |
1610 | while (* a != 0) |
1611 | { | |
0576d21f | 1612 | static const struct |
c662432e NC |
1613 | { |
1614 | const char * string; | |
1615 | unsigned int flag; | |
1616 | } | |
1617 | specifics[] = | |
1618 | { | |
1619 | { "optimizers", CL_OPTIMIZATION }, | |
1620 | { "target", CL_TARGET }, | |
1621 | { "warnings", CL_WARNING }, | |
1622 | { "undocumented", CL_UNDOCUMENTED }, | |
1623 | { "params", CL_PARAMS }, | |
66811228 RW |
1624 | { "joined", CL_JOINED }, |
1625 | { "separate", CL_SEPARATE }, | |
b5456e04 | 1626 | { "common", CL_COMMON }, |
c662432e NC |
1627 | { NULL, 0 } |
1628 | }; | |
1629 | unsigned int * pflags; | |
86373e7e | 1630 | const char * comma; |
b3eaaf1a | 1631 | unsigned int lang_flag, specific_flag; |
c662432e NC |
1632 | unsigned int len; |
1633 | unsigned int i; | |
1634 | ||
1635 | if (* a == '^') | |
1636 | { | |
1637 | ++ a; | |
1638 | pflags = & exclude_flags; | |
1639 | } | |
1640 | else | |
1641 | pflags = & include_flags; | |
1642 | ||
1643 | comma = strchr (a, ','); | |
1644 | if (comma == NULL) | |
1645 | len = strlen (a); | |
1646 | else | |
1647 | len = comma - a; | |
0631b69f RW |
1648 | if (len == 0) |
1649 | { | |
1650 | a = comma + 1; | |
1651 | continue; | |
1652 | } | |
c662432e | 1653 | |
b3eaaf1a NC |
1654 | /* Check to see if the string matches an option class name. */ |
1655 | for (i = 0, specific_flag = 0; specifics[i].string != NULL; i++) | |
c662432e NC |
1656 | if (strncasecmp (a, specifics[i].string, len) == 0) |
1657 | { | |
b3eaaf1a NC |
1658 | specific_flag = specifics[i].flag; |
1659 | break; | |
1660 | } | |
0631b69f | 1661 | |
b3eaaf1a NC |
1662 | /* Check to see if the string matches a language name. |
1663 | Note - we rely upon the alpha-sorted nature of the entries in | |
1664 | the lang_names array, specifically that shorter names appear | |
fa10beec | 1665 | before their longer variants. (i.e. C before C++). That way |
b3eaaf1a NC |
1666 | when we are attempting to match --help=c for example we will |
1667 | match with C first and not C++. */ | |
1668 | for (i = 0, lang_flag = 0; i < cl_lang_count; i++) | |
1669 | if (strncasecmp (a, lang_names[i], len) == 0) | |
1670 | { | |
1671 | lang_flag = 1U << i; | |
c662432e NC |
1672 | break; |
1673 | } | |
1674 | ||
b3eaaf1a | 1675 | if (specific_flag != 0) |
c662432e | 1676 | { |
b3eaaf1a NC |
1677 | if (lang_flag == 0) |
1678 | * pflags |= specific_flag; | |
1679 | else | |
1680 | { | |
1681 | /* The option's argument matches both the start of a | |
1682 | language name and the start of an option class name. | |
1683 | We have a special case for when the user has | |
1684 | specified "--help=c", but otherwise we have to issue | |
1685 | a warning. */ | |
1686 | if (strncasecmp (a, "c", len) == 0) | |
1687 | * pflags |= lang_flag; | |
1688 | else | |
299404a1 JM |
1689 | warning_at (loc, 0, |
1690 | "--help argument %q.*s is ambiguous, " | |
1691 | "please be more specific", | |
1692 | len, a); | |
b3eaaf1a | 1693 | } |
c662432e | 1694 | } |
b3eaaf1a NC |
1695 | else if (lang_flag != 0) |
1696 | * pflags |= lang_flag; | |
1697 | else | |
299404a1 JM |
1698 | warning_at (loc, 0, |
1699 | "unrecognized argument to --help= option: %q.*s", | |
1700 | len, a); | |
c662432e NC |
1701 | |
1702 | if (comma == NULL) | |
1703 | break; | |
1704 | a = comma + 1; | |
1705 | } | |
1706 | ||
1707 | if (include_flags) | |
e6d4b984 JM |
1708 | print_specific_help (include_flags, exclude_flags, 0, opts, |
1709 | lang_mask); | |
0576d21f | 1710 | opts->x_exit_after_options = true; |
c662432e NC |
1711 | break; |
1712 | } | |
1713 | ||
d185d268 | 1714 | case OPT__version: |
a7d0d30f JM |
1715 | if (lang_mask == CL_DRIVER) |
1716 | break; | |
1717 | ||
0576d21f | 1718 | opts->x_exit_after_options = true; |
d185d268 NB |
1719 | break; |
1720 | ||
de5a5fa1 | 1721 | case OPT_fsanitize_: |
b1b46af0 JJ |
1722 | opts->x_flag_sanitize |
1723 | = parse_sanitizer_options (arg, loc, code, | |
1724 | opts->x_flag_sanitize, value, true); | |
de5a5fa1 | 1725 | |
b1b46af0 JJ |
1726 | /* Kernel ASan implies normal ASan but does not yet support |
1727 | all features. */ | |
1728 | if (opts->x_flag_sanitize & SANITIZE_KERNEL_ADDRESS) | |
1729 | { | |
1730 | maybe_set_param_value (PARAM_ASAN_INSTRUMENTATION_WITH_CALL_THRESHOLD, | |
1731 | 0, opts->x_param_values, | |
1732 | opts_set->x_param_values); | |
1733 | maybe_set_param_value (PARAM_ASAN_GLOBALS, 0, opts->x_param_values, | |
1734 | opts_set->x_param_values); | |
1735 | maybe_set_param_value (PARAM_ASAN_STACK, 0, opts->x_param_values, | |
1736 | opts_set->x_param_values); | |
1737 | maybe_set_param_value (PARAM_ASAN_USE_AFTER_RETURN, 0, | |
1738 | opts->x_param_values, | |
1739 | opts_set->x_param_values); | |
1740 | } | |
1741 | break; | |
fec4842d | 1742 | |
b1b46af0 JJ |
1743 | case OPT_fsanitize_recover_: |
1744 | opts->x_flag_sanitize_recover | |
1745 | = parse_sanitizer_options (arg, loc, code, | |
1746 | opts->x_flag_sanitize_recover, value, true); | |
1747 | break; | |
de5a5fa1 | 1748 | |
fd960af2 YG |
1749 | case OPT_fasan_shadow_offset_: |
1750 | /* Deferred. */ | |
1751 | break; | |
1752 | ||
d95a2703 JJ |
1753 | case OPT_fsanitize_recover: |
1754 | if (value) | |
1755 | opts->x_flag_sanitize_recover | |
1756 | |= SANITIZE_UNDEFINED | SANITIZE_NONDEFAULT; | |
1757 | else | |
1758 | opts->x_flag_sanitize_recover | |
1759 | &= ~(SANITIZE_UNDEFINED | SANITIZE_NONDEFAULT); | |
1760 | break; | |
1761 | ||
903caebf NB |
1762 | case OPT_O: |
1763 | case OPT_Os: | |
c3a02647 | 1764 | case OPT_Ofast: |
bf7a7185 | 1765 | case OPT_Og: |
903caebf NB |
1766 | /* Currently handled in a prescan. */ |
1767 | break; | |
1768 | ||
aee15221 RG |
1769 | case OPT_Werror: |
1770 | dc->warning_as_error_requested = value; | |
1771 | break; | |
1772 | ||
79cf5994 | 1773 | case OPT_Werror_: |
a7d0d30f JM |
1774 | if (lang_mask == CL_DRIVER) |
1775 | break; | |
1776 | ||
c5fa0890 JM |
1777 | enable_warning_as_error (arg, value, lang_mask, handlers, |
1778 | opts, opts_set, loc, dc); | |
79cf5994 DD |
1779 | break; |
1780 | ||
e01cc6dc | 1781 | case OPT_Wlarger_than_: |
d5478783 JM |
1782 | opts->x_larger_than_size = value; |
1783 | opts->x_warn_larger_than = value != -1; | |
e01cc6dc NB |
1784 | break; |
1785 | ||
5f0f4a3b | 1786 | case OPT_Wfatal_errors: |
d5478783 | 1787 | dc->fatal_errors = value; |
5f0f4a3b JM |
1788 | break; |
1789 | ||
a214518f | 1790 | case OPT_Wframe_larger_than_: |
d5478783 JM |
1791 | opts->x_frame_larger_than_size = value; |
1792 | opts->x_warn_frame_larger_than = value != -1; | |
a214518f SP |
1793 | break; |
1794 | ||
a11e0df4 EB |
1795 | case OPT_Wstack_usage_: |
1796 | opts->x_warn_stack_usage = value; | |
1797 | opts->x_flag_stack_usage_info = value != -1; | |
1798 | break; | |
1799 | ||
e01cc6dc | 1800 | case OPT_Wstrict_aliasing: |
d5478783 | 1801 | set_Wstrict_aliasing (opts, value); |
e01cc6dc NB |
1802 | break; |
1803 | ||
6ac01510 | 1804 | case OPT_Wstrict_overflow: |
d5478783 JM |
1805 | opts->x_warn_strict_overflow = (value |
1806 | ? (int) WARN_STRICT_OVERFLOW_CONDITIONAL | |
1807 | : 0); | |
6ac01510 ILT |
1808 | break; |
1809 | ||
5f0f4a3b | 1810 | case OPT_Wsystem_headers: |
d5478783 | 1811 | dc->dc_warn_system_headers = value; |
903caebf NB |
1812 | break; |
1813 | ||
d185d268 | 1814 | case OPT_aux_info: |
d5478783 | 1815 | opts->x_flag_gen_aux_info = 1; |
d185d268 NB |
1816 | break; |
1817 | ||
1818 | case OPT_auxbase_strip: | |
1819 | { | |
1820 | char *tmp = xstrdup (arg); | |
1821 | strip_off_ending (tmp, strlen (tmp)); | |
1822 | if (tmp[0]) | |
d5478783 | 1823 | opts->x_aux_base_name = tmp; |
fc429b48 TB |
1824 | else |
1825 | free (tmp); | |
d185d268 NB |
1826 | } |
1827 | break; | |
1828 | ||
1829 | case OPT_d: | |
299404a1 | 1830 | decode_d_option (arg, opts, loc, dc); |
d185d268 NB |
1831 | break; |
1832 | ||
058de654 | 1833 | case OPT_fcall_used_: |
058de654 | 1834 | case OPT_fcall_saved_: |
21bf1558 | 1835 | /* Deferred. */ |
058de654 | 1836 | break; |
6fb5fa3c DB |
1837 | |
1838 | case OPT_fdbg_cnt_: | |
68d070ac ML |
1839 | /* Deferred. */ |
1840 | break; | |
1841 | ||
0a090f42 | 1842 | case OPT_fdbg_cnt_list: |
299404a1 | 1843 | /* Deferred. */ |
68d070ac | 1844 | opts->x_exit_after_options = true; |
0a090f42 | 1845 | break; |
058de654 | 1846 | |
c8aea42c | 1847 | case OPT_fdebug_prefix_map_: |
299404a1 | 1848 | /* Deferred. */ |
c8aea42c PB |
1849 | break; |
1850 | ||
de32c0cb | 1851 | case OPT_fdiagnostics_show_location_: |
e6d4b984 | 1852 | diagnostic_prefixing_rule (dc) = (diagnostic_prefixing_rule_t) value; |
de32c0cb | 1853 | break; |
9fec0042 MLI |
1854 | |
1855 | case OPT_fdiagnostics_show_caret: | |
1856 | dc->show_caret = value; | |
1857 | break; | |
de32c0cb | 1858 | |
4b84d650 | 1859 | case OPT_fdiagnostics_color_: |
97aa8bb6 | 1860 | diagnostic_color_init (dc, value); |
4b84d650 JJ |
1861 | break; |
1862 | ||
2098fe9e | 1863 | case OPT_fdiagnostics_show_option: |
d5478783 | 1864 | dc->show_option_requested = value; |
2098fe9e DD |
1865 | break; |
1866 | ||
6de9cd9a | 1867 | case OPT_fdump_: |
21bf1558 | 1868 | /* Deferred. */ |
6de9cd9a DN |
1869 | break; |
1870 | ||
058de654 | 1871 | case OPT_ffast_math: |
d5478783 | 1872 | set_fast_math_flags (opts, value); |
058de654 NB |
1873 | break; |
1874 | ||
a1a82611 | 1875 | case OPT_funsafe_math_optimizations: |
d5478783 | 1876 | set_unsafe_math_optimizations_flags (opts, value); |
a1a82611 RE |
1877 | break; |
1878 | ||
058de654 | 1879 | case OPT_ffixed_: |
21bf1558 | 1880 | /* Deferred. */ |
058de654 NB |
1881 | break; |
1882 | ||
d302c9d6 | 1883 | case OPT_finline_limit_: |
48476d13 JM |
1884 | set_param_value ("max-inline-insns-single", value / 2, |
1885 | opts->x_param_values, opts_set->x_param_values); | |
1886 | set_param_value ("max-inline-insns-auto", value / 2, | |
1887 | opts->x_param_values, opts_set->x_param_values); | |
d302c9d6 NB |
1888 | break; |
1889 | ||
8d5a7d1f | 1890 | case OPT_finstrument_functions_exclude_function_list_: |
1ebc7e68 | 1891 | add_comma_separated_to_vector |
6a1f6c9c | 1892 | (&opts->x_flag_instrument_functions_exclude_functions, arg); |
8d5a7d1f ILT |
1893 | break; |
1894 | ||
1895 | case OPT_finstrument_functions_exclude_file_list_: | |
1ebc7e68 | 1896 | add_comma_separated_to_vector |
6a1f6c9c | 1897 | (&opts->x_flag_instrument_functions_exclude_files, arg); |
8d5a7d1f ILT |
1898 | break; |
1899 | ||
de32c0cb | 1900 | case OPT_fmessage_length_: |
d5478783 | 1901 | pp_set_line_maximum_length (dc->printer, value); |
9fec0042 | 1902 | diagnostic_set_caret_max_width (dc, value); |
de32c0cb NB |
1903 | break; |
1904 | ||
78c60e3d SS |
1905 | case OPT_fopt_info: |
1906 | case OPT_fopt_info_: | |
1907 | /* Deferred. */ | |
1908 | break; | |
1909 | ||
c713ddc0 | 1910 | case OPT_foffload_: |
b2b40051 MJ |
1911 | { |
1912 | const char *p = arg; | |
1913 | opts->x_flag_disable_hsa = true; | |
1914 | while (*p != 0) | |
1915 | { | |
1916 | const char *comma = strchr (p, ','); | |
1917 | ||
1918 | if ((strncmp (p, "disable", 7) == 0) | |
1919 | && (p[7] == ',' || p[7] == '\0')) | |
1920 | { | |
1921 | opts->x_flag_disable_hsa = true; | |
1922 | break; | |
1923 | } | |
1924 | ||
1925 | if ((strncmp (p, "hsa", 3) == 0) | |
1926 | && (p[3] == ',' || p[3] == '\0')) | |
1927 | { | |
1928 | #ifdef ENABLE_HSA | |
1929 | opts->x_flag_disable_hsa = false; | |
1930 | #else | |
1931 | sorry ("HSA has not been enabled during configuration"); | |
1932 | #endif | |
1933 | } | |
1934 | if (!comma) | |
1935 | break; | |
1936 | p = comma + 1; | |
1937 | } | |
1938 | break; | |
1939 | } | |
c713ddc0 BS |
1940 | |
1941 | #ifndef ACCEL_COMPILER | |
1942 | case OPT_foffload_abi_: | |
1943 | error_at (loc, "-foffload-abi option can be specified only for " | |
1944 | "offload compiler"); | |
1945 | break; | |
1946 | #endif | |
1947 | ||
467cecf3 JB |
1948 | case OPT_fpack_struct_: |
1949 | if (value <= 0 || (value & (value - 1)) || value > 16) | |
299404a1 JM |
1950 | error_at (loc, |
1951 | "structure alignment must be a small power of two, not %d", | |
1952 | value); | |
467cecf3 | 1953 | else |
299404a1 | 1954 | opts->x_initial_max_fld_align = value; |
467cecf3 JB |
1955 | break; |
1956 | ||
68a607d8 | 1957 | case OPT_fplugin_: |
68a607d8 | 1958 | case OPT_fplugin_arg_: |
21bf1558 | 1959 | /* Deferred. */ |
68a607d8 DN |
1960 | break; |
1961 | ||
2f908293 | 1962 | case OPT_fprofile_use_: |
0576d21f | 1963 | opts->x_profile_data_prefix = xstrdup (arg); |
d5478783 | 1964 | opts->x_flag_profile_use = true; |
2f908293 SP |
1965 | value = true; |
1966 | /* No break here - do -fprofile-use processing. */ | |
a8a5f53a | 1967 | case OPT_fprofile_use: |
be3c16c4 | 1968 | enable_fdo_optimizations (opts, opts_set, value); |
9cec31f4 | 1969 | if (!opts_set->x_flag_profile_reorder_functions) |
be3c16c4 DC |
1970 | opts->x_flag_profile_reorder_functions = value; |
1971 | /* Indirect call profiling should do all useful transformations | |
1972 | speculative devirtualization does. */ | |
bbc9396b JH |
1973 | if (!opts_set->x_flag_devirtualize_speculatively |
1974 | && opts->x_flag_value_profile_transformations) | |
1975 | opts->x_flag_devirtualize_speculatively = false; | |
a8a5f53a JH |
1976 | break; |
1977 | ||
be3c16c4 DC |
1978 | case OPT_fauto_profile_: |
1979 | opts->x_auto_profile_file = xstrdup (arg); | |
1980 | opts->x_flag_auto_profile = true; | |
1981 | value = true; | |
1982 | /* No break here - do -fauto-profile processing. */ | |
1983 | case OPT_fauto_profile: | |
1984 | enable_fdo_optimizations (opts, opts_set, value); | |
1985 | if (!opts_set->x_flag_profile_correction) | |
1986 | opts->x_flag_profile_correction = value; | |
1987 | maybe_set_param_value ( | |
1988 | PARAM_EARLY_INLINER_MAX_ITERATIONS, 10, | |
1989 | opts->x_param_values, opts_set->x_param_values); | |
1990 | break; | |
1991 | ||
2f908293 | 1992 | case OPT_fprofile_generate_: |
0576d21f | 1993 | opts->x_profile_data_prefix = xstrdup (arg); |
2f908293 SP |
1994 | value = true; |
1995 | /* No break here - do -fprofile-generate processing. */ | |
a8a5f53a | 1996 | case OPT_fprofile_generate: |
d4d24ba4 | 1997 | if (!opts_set->x_profile_arc_flag) |
d5478783 | 1998 | opts->x_profile_arc_flag = value; |
d4d24ba4 | 1999 | if (!opts_set->x_flag_profile_values) |
d5478783 | 2000 | opts->x_flag_profile_values = value; |
d4d24ba4 | 2001 | if (!opts_set->x_flag_inline_functions) |
d5478783 | 2002 | opts->x_flag_inline_functions = value; |
b0223c3e JH |
2003 | /* FIXME: Instrumentation we insert makes ipa-reference bitmaps |
2004 | quadratic. Disable the pass until better memory representation | |
2005 | is done. */ | |
1c58fe29 | 2006 | if (!opts_set->x_flag_ipa_reference) |
b0223c3e | 2007 | opts->x_flag_ipa_reference = false; |
a8a5f53a JH |
2008 | break; |
2009 | ||
ea0f3e87 XDL |
2010 | case OPT_ftree_vectorize: |
2011 | if (!opts_set->x_flag_tree_loop_vectorize) | |
2012 | opts->x_flag_tree_loop_vectorize = value; | |
2013 | if (!opts_set->x_flag_tree_slp_vectorize) | |
2014 | opts->x_flag_tree_slp_vectorize = value; | |
2015 | break; | |
5f0f4a3b | 2016 | case OPT_fshow_column: |
d5478783 | 2017 | dc->show_column = value; |
5f0f4a3b JM |
2018 | break; |
2019 | ||
de32c0cb NB |
2020 | case OPT_frandom_seed: |
2021 | /* The real switch is -fno-random-seed. */ | |
2022 | if (value) | |
5f20c657 | 2023 | return false; |
299404a1 | 2024 | /* Deferred. */ |
de32c0cb NB |
2025 | break; |
2026 | ||
2027 | case OPT_frandom_seed_: | |
299404a1 | 2028 | /* Deferred. */ |
de32c0cb NB |
2029 | break; |
2030 | ||
de32c0cb NB |
2031 | case OPT_fsched_verbose_: |
2032 | #ifdef INSN_SCHEDULING | |
299404a1 | 2033 | /* Handled with Var in common.opt. */ |
de32c0cb NB |
2034 | break; |
2035 | #else | |
5f20c657 | 2036 | return false; |
de32c0cb NB |
2037 | #endif |
2038 | ||
569fa502 | 2039 | case OPT_fsched_stalled_insns_: |
d5478783 JM |
2040 | opts->x_flag_sched_stalled_insns = value; |
2041 | if (opts->x_flag_sched_stalled_insns == 0) | |
2042 | opts->x_flag_sched_stalled_insns = -1; | |
569fa502 DN |
2043 | break; |
2044 | ||
569fa502 | 2045 | case OPT_fsched_stalled_insns_dep_: |
d5478783 | 2046 | opts->x_flag_sched_stalled_insns_dep = value; |
569fa502 | 2047 | break; |
6ff3a151 | 2048 | |
b38f3813 EB |
2049 | case OPT_fstack_check_: |
2050 | if (!strcmp (arg, "no")) | |
5e471ea6 | 2051 | opts->x_flag_stack_check = NO_STACK_CHECK; |
b38f3813 EB |
2052 | else if (!strcmp (arg, "generic")) |
2053 | /* This is the old stack checking method. */ | |
5e471ea6 | 2054 | opts->x_flag_stack_check = STACK_CHECK_BUILTIN |
b38f3813 EB |
2055 | ? FULL_BUILTIN_STACK_CHECK |
2056 | : GENERIC_STACK_CHECK; | |
2057 | else if (!strcmp (arg, "specific")) | |
2058 | /* This is the new stack checking method. */ | |
5e471ea6 | 2059 | opts->x_flag_stack_check = STACK_CHECK_BUILTIN |
b38f3813 EB |
2060 | ? FULL_BUILTIN_STACK_CHECK |
2061 | : STACK_CHECK_STATIC_BUILTIN | |
2062 | ? STATIC_BUILTIN_STACK_CHECK | |
2063 | : GENERIC_STACK_CHECK; | |
2064 | else | |
778e02fd | 2065 | warning_at (loc, 0, "unknown stack check parameter %qs", arg); |
b38f3813 EB |
2066 | break; |
2067 | ||
de32c0cb NB |
2068 | case OPT_fstack_limit: |
2069 | /* The real switch is -fno-stack-limit. */ | |
2070 | if (value) | |
5f20c657 | 2071 | return false; |
21bf1558 | 2072 | /* Deferred. */ |
de32c0cb NB |
2073 | break; |
2074 | ||
058de654 | 2075 | case OPT_fstack_limit_register_: |
058de654 | 2076 | case OPT_fstack_limit_symbol_: |
21bf1558 | 2077 | /* Deferred. */ |
058de654 NB |
2078 | break; |
2079 | ||
a11e0df4 EB |
2080 | case OPT_fstack_usage: |
2081 | opts->x_flag_stack_usage = value; | |
2082 | opts->x_flag_stack_usage_info = value != 0; | |
2083 | break; | |
2084 | ||
e01cc6dc | 2085 | case OPT_g: |
bc91b0e0 CC |
2086 | set_debug_level (NO_DEBUG, DEFAULT_GDB_EXTENSIONS, arg, opts, opts_set, |
2087 | loc); | |
df38ffef NB |
2088 | break; |
2089 | ||
2090 | case OPT_gcoff: | |
299404a1 | 2091 | set_debug_level (SDB_DEBUG, false, arg, opts, opts_set, loc); |
df38ffef NB |
2092 | break; |
2093 | ||
6782438d | 2094 | case OPT_gdwarf: |
f0defe58 | 2095 | if (arg && strlen (arg) != 0) |
6782438d SKS |
2096 | { |
2097 | error_at (loc, "%<-gdwarf%s%> is ambiguous; " | |
2098 | "use %<-gdwarf-%s%> for DWARF version " | |
2099 | "or %<-gdwarf -g%s%> for debug level", arg, arg, arg); | |
2100 | break; | |
2101 | } | |
2102 | else | |
f0defe58 SKS |
2103 | value = opts->x_dwarf_version; |
2104 | ||
2105 | /* FALLTHRU */ | |
53b2323e | 2106 | case OPT_gdwarf_: |
5d45c9c0 | 2107 | if (value < 2 || value > 5) |
299404a1 | 2108 | error_at (loc, "dwarf version %d is not supported", value); |
53b2323e | 2109 | else |
a7d0d30f | 2110 | opts->x_dwarf_version = value; |
299404a1 | 2111 | set_debug_level (DWARF2_DEBUG, false, "", opts, opts_set, loc); |
df38ffef NB |
2112 | break; |
2113 | ||
99ea153e SA |
2114 | case OPT_gsplit_dwarf: |
2115 | set_debug_level (NO_DEBUG, DEFAULT_GDB_EXTENSIONS, "", opts, opts_set, | |
2116 | loc); | |
2117 | break; | |
2118 | ||
df38ffef | 2119 | case OPT_ggdb: |
299404a1 | 2120 | set_debug_level (NO_DEBUG, 2, arg, opts, opts_set, loc); |
df38ffef NB |
2121 | break; |
2122 | ||
2123 | case OPT_gstabs: | |
2124 | case OPT_gstabs_: | |
299404a1 JM |
2125 | set_debug_level (DBX_DEBUG, code == OPT_gstabs_, arg, opts, opts_set, |
2126 | loc); | |
df38ffef NB |
2127 | break; |
2128 | ||
2129 | case OPT_gvms: | |
299404a1 | 2130 | set_debug_level (VMS_DEBUG, false, arg, opts, opts_set, loc); |
df38ffef NB |
2131 | break; |
2132 | ||
2133 | case OPT_gxcoff: | |
2134 | case OPT_gxcoff_: | |
299404a1 JM |
2135 | set_debug_level (XCOFF_DEBUG, code == OPT_gxcoff_, arg, opts, opts_set, |
2136 | loc); | |
e01cc6dc NB |
2137 | break; |
2138 | ||
29d7cbd1 RO |
2139 | case OPT_gz: |
2140 | case OPT_gz_: | |
2141 | /* Handled completely via specs. */ | |
2142 | break; | |
2143 | ||
d185d268 | 2144 | case OPT_pedantic_errors: |
d5478783 | 2145 | dc->pedantic_errors = 1; |
63bbf46d | 2146 | control_warning_option (OPT_Wpedantic, DK_ERROR, NULL, value, |
9b095bf1 MLI |
2147 | loc, lang_mask, |
2148 | handlers, opts, opts_set, | |
2149 | dc); | |
c04b6b38 RG |
2150 | break; |
2151 | ||
014d92e1 | 2152 | case OPT_flto: |
595c8dfa | 2153 | opts->x_flag_lto = value ? "" : NULL; |
e10909ce AK |
2154 | break; |
2155 | ||
5f0f4a3b | 2156 | case OPT_w: |
d5478783 | 2157 | dc->dc_inhibit_warnings = true; |
5f0f4a3b JM |
2158 | break; |
2159 | ||
3a789837 NF |
2160 | case OPT_fmax_errors_: |
2161 | dc->max_errors = value; | |
2162 | break; | |
2163 | ||
b352afba NC |
2164 | case OPT_fuse_ld_bfd: |
2165 | case OPT_fuse_ld_gold: | |
da18ea94 RAE |
2166 | case OPT_fuse_linker_plugin: |
2167 | /* No-op. Used by the driver and passed to us because it starts with f.*/ | |
2168 | break; | |
2169 | ||
955f5a07 JJ |
2170 | case OPT_fwrapv: |
2171 | if (value) | |
2172 | opts->x_flag_trapv = 0; | |
2173 | break; | |
2174 | ||
2175 | case OPT_ftrapv: | |
2176 | if (value) | |
2177 | opts->x_flag_wrapv = 0; | |
2178 | break; | |
2179 | ||
b84d4347 | 2180 | case OPT_fipa_icf: |
9d4ded75 ML |
2181 | opts->x_flag_ipa_icf_functions = value; |
2182 | opts->x_flag_ipa_icf_variables = value; | |
b84d4347 ML |
2183 | break; |
2184 | ||
50431bc4 ZD |
2185 | default: |
2186 | /* If the flag was handled in a standard way, assume the lack of | |
2187 | processing here is intentional. */ | |
46625112 | 2188 | gcc_assert (option_flag_var (scode, opts)); |
0e61db61 | 2189 | break; |
d7b42618 NB |
2190 | } |
2191 | ||
7d5a5747 MLI |
2192 | common_handle_option_auto (opts, opts_set, decoded, lang_mask, kind, |
2193 | loc, handlers, dc); | |
5f20c657 | 2194 | return true; |
d7b42618 | 2195 | } |
903caebf NB |
2196 | |
2197 | /* Handle --param NAME=VALUE. */ | |
2198 | static void | |
48476d13 | 2199 | handle_param (struct gcc_options *opts, struct gcc_options *opts_set, |
299404a1 | 2200 | location_t loc, const char *carg) |
903caebf NB |
2201 | { |
2202 | char *equal, *arg; | |
2203 | int value; | |
2204 | ||
2205 | arg = xstrdup (carg); | |
2206 | equal = strchr (arg, '='); | |
2207 | if (!equal) | |
299404a1 JM |
2208 | error_at (loc, "%s: --param arguments should be of the form NAME=VALUE", |
2209 | arg); | |
903caebf NB |
2210 | else |
2211 | { | |
d78182cc TV |
2212 | *equal = '\0'; |
2213 | ||
2214 | enum compiler_param index; | |
2215 | if (!find_param (arg, &index)) | |
2216 | error_at (loc, "invalid --param name %qs", arg); | |
903caebf NB |
2217 | else |
2218 | { | |
d78182cc TV |
2219 | if (!param_string_value_p (index, equal + 1, &value)) |
2220 | value = integral_argument (equal + 1); | |
2221 | ||
2222 | if (value == -1) | |
2223 | error_at (loc, "invalid --param value %qs", equal + 1); | |
2224 | else | |
2225 | set_param_value (arg, value, | |
2226 | opts->x_param_values, opts_set->x_param_values); | |
903caebf NB |
2227 | } |
2228 | } | |
2229 | ||
2230 | free (arg); | |
2231 | } | |
2232 | ||
d5478783 | 2233 | /* Used to set the level of strict aliasing warnings in OPTS, |
79bedddc SR |
2234 | when no level is specified (i.e., when -Wstrict-aliasing, and not |
2235 | -Wstrict-aliasing=level was given). | |
2236 | ONOFF is assumed to take value 1 when -Wstrict-aliasing is specified, | |
2237 | and 0 otherwise. After calling this function, wstrict_aliasing will be | |
2238 | set to the default value of -Wstrict_aliasing=level, currently 3. */ | |
65d4f2cd | 2239 | static void |
d5478783 | 2240 | set_Wstrict_aliasing (struct gcc_options *opts, int onoff) |
79bedddc SR |
2241 | { |
2242 | gcc_assert (onoff == 0 || onoff == 1); | |
2243 | if (onoff != 0) | |
d5478783 | 2244 | opts->x_warn_strict_aliasing = 3; |
621b5ed6 | 2245 | else |
d5478783 | 2246 | opts->x_warn_strict_aliasing = 0; |
79bedddc SR |
2247 | } |
2248 | ||
058de654 NB |
2249 | /* The following routines are useful in setting all the flags that |
2250 | -ffast-math and -fno-fast-math imply. */ | |
7bb3487f | 2251 | static void |
d5478783 | 2252 | set_fast_math_flags (struct gcc_options *opts, int set) |
058de654 | 2253 | { |
5e46b0c6 ILT |
2254 | if (!opts->frontend_set_flag_unsafe_math_optimizations) |
2255 | { | |
2256 | opts->x_flag_unsafe_math_optimizations = set; | |
2257 | set_unsafe_math_optimizations_flags (opts, set); | |
2258 | } | |
2259 | if (!opts->frontend_set_flag_finite_math_only) | |
2260 | opts->x_flag_finite_math_only = set; | |
2261 | if (!opts->frontend_set_flag_errno_math) | |
2262 | opts->x_flag_errno_math = !set; | |
058de654 | 2263 | if (set) |
039c3d42 | 2264 | { |
5e46b0c6 ILT |
2265 | if (!opts->frontend_set_flag_signaling_nans) |
2266 | opts->x_flag_signaling_nans = 0; | |
2267 | if (!opts->frontend_set_flag_rounding_math) | |
2268 | opts->x_flag_rounding_math = 0; | |
2269 | if (!opts->frontend_set_flag_cx_limited_range) | |
2270 | opts->x_flag_cx_limited_range = 1; | |
039c3d42 | 2271 | } |
058de654 NB |
2272 | } |
2273 | ||
b8698a0f L |
2274 | /* When -funsafe-math-optimizations is set the following |
2275 | flags are set as well. */ | |
7bb3487f | 2276 | static void |
d5478783 | 2277 | set_unsafe_math_optimizations_flags (struct gcc_options *opts, int set) |
a1a82611 | 2278 | { |
5e46b0c6 ILT |
2279 | if (!opts->frontend_set_flag_trapping_math) |
2280 | opts->x_flag_trapping_math = !set; | |
2281 | if (!opts->frontend_set_flag_signed_zeros) | |
2282 | opts->x_flag_signed_zeros = !set; | |
2283 | if (!opts->frontend_set_flag_associative_math) | |
2284 | opts->x_flag_associative_math = set; | |
2285 | if (!opts->frontend_set_flag_reciprocal_math) | |
2286 | opts->x_flag_reciprocal_math = set; | |
a1a82611 RE |
2287 | } |
2288 | ||
0576d21f | 2289 | /* Return true iff flags in OPTS are set as if -ffast-math. */ |
058de654 | 2290 | bool |
0576d21f | 2291 | fast_math_flags_set_p (const struct gcc_options *opts) |
058de654 | 2292 | { |
0576d21f JM |
2293 | return (!opts->x_flag_trapping_math |
2294 | && opts->x_flag_unsafe_math_optimizations | |
2295 | && opts->x_flag_finite_math_only | |
2296 | && !opts->x_flag_signed_zeros | |
2297 | && !opts->x_flag_errno_math); | |
058de654 | 2298 | } |
cf03fd63 | 2299 | |
ab442df7 MM |
2300 | /* Return true iff flags are set as if -ffast-math but using the flags stored |
2301 | in the struct cl_optimization structure. */ | |
2302 | bool | |
2303 | fast_math_flags_struct_set_p (struct cl_optimization *opt) | |
2304 | { | |
e3339d0f JM |
2305 | return (!opt->x_flag_trapping_math |
2306 | && opt->x_flag_unsafe_math_optimizations | |
2307 | && opt->x_flag_finite_math_only | |
2308 | && !opt->x_flag_signed_zeros | |
2309 | && !opt->x_flag_errno_math); | |
ab442df7 MM |
2310 | } |
2311 | ||
0576d21f JM |
2312 | /* Handle a debug output -g switch for options OPTS |
2313 | (OPTS_SET->x_write_symbols storing whether a debug type was passed | |
299404a1 JM |
2314 | explicitly), location LOC. EXTENDED is true or false to support |
2315 | extended output (2 is special and means "-ggdb" was given). */ | |
df38ffef | 2316 | static void |
0576d21f | 2317 | set_debug_level (enum debug_info_type type, int extended, const char *arg, |
299404a1 JM |
2318 | struct gcc_options *opts, struct gcc_options *opts_set, |
2319 | location_t loc) | |
df38ffef | 2320 | { |
0576d21f | 2321 | opts->x_use_gnu_debug_info_extensions = extended; |
df38ffef NB |
2322 | |
2323 | if (type == NO_DEBUG) | |
2324 | { | |
0576d21f | 2325 | if (opts->x_write_symbols == NO_DEBUG) |
df38ffef | 2326 | { |
0576d21f | 2327 | opts->x_write_symbols = PREFERRED_DEBUGGING_TYPE; |
df38ffef NB |
2328 | |
2329 | if (extended == 2) | |
2330 | { | |
c9665100 | 2331 | #if defined DWARF2_DEBUGGING_INFO || defined DWARF2_LINENO_DEBUGGING_INFO |
0576d21f | 2332 | opts->x_write_symbols = DWARF2_DEBUG; |
df38ffef | 2333 | #elif defined DBX_DEBUGGING_INFO |
0576d21f | 2334 | opts->x_write_symbols = DBX_DEBUG; |
df38ffef NB |
2335 | #endif |
2336 | } | |
2337 | ||
0576d21f | 2338 | if (opts->x_write_symbols == NO_DEBUG) |
299404a1 | 2339 | warning_at (loc, 0, "target system does not support debug output"); |
df38ffef NB |
2340 | } |
2341 | } | |
2342 | else | |
2343 | { | |
2344 | /* Does it conflict with an already selected type? */ | |
0576d21f JM |
2345 | if (opts_set->x_write_symbols != NO_DEBUG |
2346 | && opts->x_write_symbols != NO_DEBUG | |
2347 | && type != opts->x_write_symbols) | |
778e02fd | 2348 | error_at (loc, "debug format %qs conflicts with prior selection", |
299404a1 | 2349 | debug_type_names[type]); |
0576d21f JM |
2350 | opts->x_write_symbols = type; |
2351 | opts_set->x_write_symbols = type; | |
df38ffef NB |
2352 | } |
2353 | ||
bc91b0e0 CC |
2354 | /* A debug flag without a level defaults to level 2. |
2355 | If off or at level 1, set it to level 2, but if already | |
2356 | at level 3, don't lower it. */ | |
df38ffef NB |
2357 | if (*arg == '\0') |
2358 | { | |
bc91b0e0 | 2359 | if (opts->x_debug_info_level < DINFO_LEVEL_NORMAL) |
0576d21f | 2360 | opts->x_debug_info_level = DINFO_LEVEL_NORMAL; |
df38ffef NB |
2361 | } |
2362 | else | |
2363 | { | |
32e8bb8e ILT |
2364 | int argval = integral_argument (arg); |
2365 | if (argval == -1) | |
778e02fd | 2366 | error_at (loc, "unrecognised debug output level %qs", arg); |
32e8bb8e | 2367 | else if (argval > 3) |
778e02fd | 2368 | error_at (loc, "debug output level %qs is too high", arg); |
32e8bb8e | 2369 | else |
0576d21f | 2370 | opts->x_debug_info_level = (enum debug_info_levels) argval; |
df38ffef NB |
2371 | } |
2372 | } | |
2373 | ||
299404a1 JM |
2374 | /* Arrange to dump core on error for diagnostic context DC. (The |
2375 | regular error message is still printed first, except in the case of | |
2376 | abort ().) */ | |
75685792 | 2377 | |
c98cd5bf | 2378 | static void |
299404a1 | 2379 | setup_core_dumping (diagnostic_context *dc) |
75685792 | 2380 | { |
c98cd5bf JM |
2381 | #ifdef SIGABRT |
2382 | signal (SIGABRT, SIG_DFL); | |
2383 | #endif | |
2384 | #if defined(HAVE_SETRLIMIT) | |
2385 | { | |
2386 | struct rlimit rlim; | |
2387 | if (getrlimit (RLIMIT_CORE, &rlim) != 0) | |
40fecdd6 | 2388 | fatal_error (input_location, "getting core file size maximum limit: %m"); |
c98cd5bf JM |
2389 | rlim.rlim_cur = rlim.rlim_max; |
2390 | if (setrlimit (RLIMIT_CORE, &rlim) != 0) | |
40fecdd6 JM |
2391 | fatal_error (input_location, |
2392 | "setting core file size limit to maximum: %m"); | |
c98cd5bf JM |
2393 | } |
2394 | #endif | |
299404a1 | 2395 | diagnostic_abort_on_error (dc); |
75685792 | 2396 | } |
5c60a017 | 2397 | |
299404a1 JM |
2398 | /* Parse a -d<ARG> command line switch for OPTS, location LOC, |
2399 | diagnostic context DC. */ | |
5c60a017 | 2400 | |
c98cd5bf | 2401 | static void |
299404a1 JM |
2402 | decode_d_option (const char *arg, struct gcc_options *opts, |
2403 | location_t loc, diagnostic_context *dc) | |
5c60a017 | 2404 | { |
c98cd5bf | 2405 | int c; |
5c60a017 | 2406 | |
c98cd5bf JM |
2407 | while (*arg) |
2408 | switch (c = *arg++) | |
2409 | { | |
2410 | case 'A': | |
299404a1 | 2411 | opts->x_flag_debug_asm = 1; |
c98cd5bf JM |
2412 | break; |
2413 | case 'p': | |
299404a1 | 2414 | opts->x_flag_print_asm_name = 1; |
c98cd5bf JM |
2415 | break; |
2416 | case 'P': | |
299404a1 JM |
2417 | opts->x_flag_dump_rtl_in_asm = 1; |
2418 | opts->x_flag_print_asm_name = 1; | |
c98cd5bf | 2419 | break; |
c98cd5bf | 2420 | case 'x': |
299404a1 | 2421 | opts->x_rtl_dump_and_exit = 1; |
c98cd5bf JM |
2422 | break; |
2423 | case 'D': /* These are handled by the preprocessor. */ | |
2424 | case 'I': | |
2425 | case 'M': | |
2426 | case 'N': | |
2427 | case 'U': | |
2428 | break; | |
2429 | case 'H': | |
299404a1 | 2430 | setup_core_dumping (dc); |
c98cd5bf JM |
2431 | break; |
2432 | case 'a': | |
299404a1 | 2433 | opts->x_flag_dump_all_passed = true; |
c98cd5bf | 2434 | break; |
21bf1558 | 2435 | |
c98cd5bf | 2436 | default: |
299404a1 | 2437 | warning_at (loc, 0, "unrecognized gcc debugging option: %c", c); |
c98cd5bf JM |
2438 | break; |
2439 | } | |
5c60a017 | 2440 | } |
dc90f45b | 2441 | |
1ebe4b4f | 2442 | /* Enable (or disable if VALUE is 0) a warning option ARG (language |
c5fa0890 JM |
2443 | mask LANG_MASK, option handlers HANDLERS) as an error for option |
2444 | structures OPTS and OPTS_SET, diagnostic context DC (possibly | |
2445 | NULL), location LOC. This is used by -Werror=. */ | |
dc90f45b | 2446 | |
a4d8c676 | 2447 | static void |
5f20c657 | 2448 | enable_warning_as_error (const char *arg, int value, unsigned int lang_mask, |
1ebe4b4f | 2449 | const struct cl_option_handlers *handlers, |
c5fa0890 JM |
2450 | struct gcc_options *opts, |
2451 | struct gcc_options *opts_set, | |
a4d8c676 | 2452 | location_t loc, diagnostic_context *dc) |
dc90f45b MLI |
2453 | { |
2454 | char *new_option; | |
2455 | int option_index; | |
2456 | ||
2457 | new_option = XNEWVEC (char, strlen (arg) + 2); | |
2458 | new_option[0] = 'W'; | |
2459 | strcpy (new_option + 1, arg); | |
2460 | option_index = find_opt (new_option, lang_mask); | |
6e2f1956 | 2461 | if (option_index == OPT_SPECIAL_unknown) |
35632122 MLI |
2462 | error_at (loc, "-Werror=%s: no option -%s", arg, new_option); |
2463 | else if (!(cl_options[option_index].flags & CL_WARNING)) | |
2464 | error_at (loc, "-Werror=%s: -%s is not an option that controls warnings", | |
2465 | arg, new_option); | |
dc90f45b MLI |
2466 | else |
2467 | { | |
87cf0651 | 2468 | const diagnostic_t kind = value ? DK_ERROR : DK_WARNING; |
63bbf46d | 2469 | const char *arg = NULL; |
87cf0651 | 2470 | |
63bbf46d JJ |
2471 | if (cl_options[option_index].flags & CL_JOINED) |
2472 | arg = new_option + cl_options[option_index].opt_len; | |
2473 | control_warning_option (option_index, (int) kind, arg, value, | |
c5fa0890 JM |
2474 | loc, lang_mask, |
2475 | handlers, opts, opts_set, dc); | |
dc90f45b MLI |
2476 | } |
2477 | free (new_option); | |
2478 | } | |
5f0f4a3b JM |
2479 | |
2480 | /* Return malloced memory for the name of the option OPTION_INDEX | |
2481 | which enabled a diagnostic (context CONTEXT), originally of type | |
2482 | ORIG_DIAG_KIND but possibly converted to DIAG_KIND by options such | |
2483 | as -Werror. */ | |
2484 | ||
2485 | char * | |
2486 | option_name (diagnostic_context *context, int option_index, | |
2487 | diagnostic_t orig_diag_kind, diagnostic_t diag_kind) | |
2488 | { | |
2489 | if (option_index) | |
2490 | { | |
2491 | /* A warning classified as an error. */ | |
2492 | if ((orig_diag_kind == DK_WARNING || orig_diag_kind == DK_PEDWARN) | |
2493 | && diag_kind == DK_ERROR) | |
2494 | return concat (cl_options[OPT_Werror_].opt_text, | |
2495 | /* Skip over "-W". */ | |
2496 | cl_options[option_index].opt_text + 2, | |
2497 | NULL); | |
2498 | /* A warning with option. */ | |
2499 | else | |
2500 | return xstrdup (cl_options[option_index].opt_text); | |
2501 | } | |
2502 | /* A warning without option classified as an error. */ | |
9f8da907 RS |
2503 | else if ((orig_diag_kind == DK_WARNING || orig_diag_kind == DK_PEDWARN |
2504 | || diag_kind == DK_WARNING) | |
2505 | && context->warning_as_error_requested) | |
2506 | return xstrdup (cl_options[OPT_Werror].opt_text); | |
5f0f4a3b JM |
2507 | else |
2508 | return NULL; | |
2509 | } |