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