comparison gcc/opts.c @ 16:04ced10e8804

gcc 7
author kono
date Fri, 27 Oct 2017 22:46:09 +0900
parents f6334be47118
children 84e7813d76e9
comparison
equal deleted inserted replaced
15:561a7518be6b 16:04ced10e8804
1 /* Command line option handling. 1 /* Command line option handling.
2 Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 2 Copyright (C) 2002-2017 Free Software Foundation, Inc.
3 Free Software Foundation, Inc.
4 Contributed by Neil Booth. 3 Contributed by Neil Booth.
5 4
6 This file is part of GCC. 5 This file is part of GCC.
7 6
8 GCC is free software; you can redistribute it and/or modify it under 7 GCC is free software; you can redistribute it and/or modify it under
21 20
22 #include "config.h" 21 #include "config.h"
23 #include "system.h" 22 #include "system.h"
24 #include "intl.h" 23 #include "intl.h"
25 #include "coretypes.h" 24 #include "coretypes.h"
26 #include "tm.h" /* Needed by rtl.h and used for STACK_CHECK_BUILTIN,
27 STACK_CHECK_STATIC_BUILTIN, DEFAULT_GDB_EXTENSIONS,
28 DWARF2_DEBUGGING_INFO and DBX_DEBUGGING_INFO. */
29 #include "rtl.h" /* Needed by insn-attr.h. */
30 #include "opts.h" 25 #include "opts.h"
31 #include "options.h" 26 #include "tm.h"
32 #include "flags.h" 27 #include "flags.h"
33 #include "params.h" 28 #include "params.h"
34 #include "diagnostic.h" 29 #include "diagnostic.h"
35 #include "opts-diagnostic.h" 30 #include "opts-diagnostic.h"
36 #include "insn-attr.h" /* For INSN_SCHEDULING and DELAY_SLOTS. */ 31 #include "insn-attr-common.h"
37 #include "target.h" 32 #include "common/common-target.h"
33 #include "spellcheck.h"
34
35 static void set_Wstrict_aliasing (struct gcc_options *opts, int onoff);
36
37 /* Indexed by enum debug_info_type. */
38 const char *const debug_type_names[] =
39 {
40 "none", "stabs", "coff", "dwarf-2", "xcoff", "vms"
41 };
38 42
39 /* Parse the -femit-struct-debug-detailed option value 43 /* Parse the -femit-struct-debug-detailed option value
40 and set the flag variables. */ 44 and set the flag variables. */
41 45
42 #define MATCH( prefix, string ) \ 46 #define MATCH( prefix, string ) \
130 "at least as much as " 134 "at least as much as "
131 "%<-femit-struct-debug-detailed=ind:...%>"); 135 "%<-femit-struct-debug-detailed=ind:...%>");
132 } 136 }
133 } 137 }
134 138
135 /* Handle -ftree-vectorizer-verbose=VAL for options OPTS. */
136
137 static void
138 vect_set_verbosity_level (struct gcc_options *opts, int val)
139 {
140 if (val < MAX_VERBOSITY_LEVEL)
141 opts->x_user_vect_verbosity_level = (enum vect_verbosity_levels) val;
142 else
143 opts->x_user_vect_verbosity_level
144 = (enum vect_verbosity_levels) (MAX_VERBOSITY_LEVEL - 1);
145 }
146
147
148 /* Strip off a legitimate source ending from the input string NAME of 139 /* Strip off a legitimate source ending from the input string NAME of
149 length LEN. Rather than having to know the names used by all of 140 length LEN. Rather than having to know the names used by all of
150 our front ends, we strip off an ending of a period followed by 141 our front ends, we strip off an ending of a period followed by
151 up to five characters. (Java uses ".class".) */ 142 up to fource characters. (C++ uses ".cpp".) */
152 143
153 void 144 void
154 strip_off_ending (char *name, int len) 145 strip_off_ending (char *name, int len)
155 { 146 {
156 int i; 147 int i;
157 for (i = 2; i < 6 && len > i; i++) 148 for (i = 2; i < 5 && len > i; i++)
158 { 149 {
159 if (name[len - i] == '.') 150 if (name[len - i] == '.')
160 { 151 {
161 name[len - i] = '\0'; 152 name[len - i] = '\0';
162 break; 153 break;
173 const char *dot = 0; 164 const char *dot = 0;
174 const char *p = path; 165 const char *p = path;
175 char c = *p; 166 char c = *p;
176 while (c) 167 while (c)
177 { 168 {
178 if (IS_DIR_SEPARATOR(c)) 169 if (IS_DIR_SEPARATOR (c))
179 { 170 {
180 base = p + 1; 171 base = p + 1;
181 dot = 0; 172 dot = 0;
182 } 173 }
183 else if (c == '.') 174 else if (c == '.')
189 *base_out = base; 180 *base_out = base;
190 return dot - base; 181 return dot - base;
191 } 182 }
192 183
193 /* What to print when a switch has no documentation. */ 184 /* What to print when a switch has no documentation. */
194 static const char undocumented_msg[] = N_("This switch lacks documentation"); 185 static const char undocumented_msg[] = N_("This option lacks documentation.");
186 static const char use_diagnosed_msg[] = N_("Uses of this option are diagnosed.");
195 187
196 typedef char *char_p; /* For DEF_VEC_P. */ 188 typedef char *char_p; /* For DEF_VEC_P. */
197 DEF_VEC_P(char_p);
198 DEF_VEC_ALLOC_P(char_p,heap);
199 189
200 static void handle_param (struct gcc_options *opts, 190 static void handle_param (struct gcc_options *opts,
201 struct gcc_options *opts_set, location_t loc, 191 struct gcc_options *opts_set, location_t loc,
202 const char *carg); 192 const char *carg);
203 static void set_debug_level (enum debug_info_type type, int extended, 193 static void set_debug_level (enum debug_info_type type, int extended,
223 bool 213 bool
224 target_handle_option (struct gcc_options *opts, 214 target_handle_option (struct gcc_options *opts,
225 struct gcc_options *opts_set, 215 struct gcc_options *opts_set,
226 const struct cl_decoded_option *decoded, 216 const struct cl_decoded_option *decoded,
227 unsigned int lang_mask ATTRIBUTE_UNUSED, int kind, 217 unsigned int lang_mask ATTRIBUTE_UNUSED, int kind,
228 location_t loc ATTRIBUTE_UNUSED, 218 location_t loc,
229 const struct cl_option_handlers *handlers ATTRIBUTE_UNUSED, 219 const struct cl_option_handlers *handlers ATTRIBUTE_UNUSED,
230 diagnostic_context *dc) 220 diagnostic_context *dc, void (*) (void))
231 { 221 {
232 gcc_assert (opts == &global_options);
233 gcc_assert (opts_set == &global_options_set);
234 gcc_assert (dc == global_dc); 222 gcc_assert (dc == global_dc);
235 gcc_assert (decoded->canonical_option_num_elements <= 2);
236 gcc_assert (kind == DK_UNSPECIFIED); 223 gcc_assert (kind == DK_UNSPECIFIED);
237 /* Although the location is not passed down to 224 return targetm_common.handle_option (opts, opts_set, decoded, loc);
238 targetm.handle_option, do not make assertions about its value;
239 options may come from optimize attributes and having the correct
240 location in the handler is not generally important. */
241 return targetm.handle_option (decoded->opt_index, decoded->arg,
242 decoded->value);
243 } 225 }
244 226
245 /* Add comma-separated strings to a char_p vector. */ 227 /* Add comma-separated strings to a char_p vector. */
246 228
247 static void 229 static void
249 { 231 {
250 char *tmp; 232 char *tmp;
251 char *r; 233 char *r;
252 char *w; 234 char *w;
253 char *token_start; 235 char *token_start;
254 VEC(char_p,heap) *vec = (VEC(char_p,heap) *) *pvec; 236 vec<char_p> *v = (vec<char_p> *) *pvec;
237
238 vec_check_alloc (v, 1);
255 239
256 /* We never free this string. */ 240 /* We never free this string. */
257 tmp = xstrdup (arg); 241 tmp = xstrdup (arg);
258 242
259 r = tmp; 243 r = tmp;
264 { 248 {
265 if (*r == ',') 249 if (*r == ',')
266 { 250 {
267 *w++ = '\0'; 251 *w++ = '\0';
268 ++r; 252 ++r;
269 VEC_safe_push (char_p, heap, vec, token_start); 253 v->safe_push (token_start);
270 token_start = w; 254 token_start = w;
271 } 255 }
272 if (*r == '\\' && r[1] == ',') 256 if (*r == '\\' && r[1] == ',')
273 { 257 {
274 *w++ = ','; 258 *w++ = ',';
276 } 260 }
277 else 261 else
278 *w++ = *r++; 262 *w++ = *r++;
279 } 263 }
280 if (*token_start != '\0') 264 if (*token_start != '\0')
281 VEC_safe_push (char_p, heap, vec, token_start); 265 v->safe_push (token_start);
282 266
283 *pvec = vec; 267 *pvec = v;
268 }
269
270 /* Initialize opts_obstack. */
271
272 void
273 init_opts_obstack (void)
274 {
275 gcc_obstack_init (&opts_obstack);
284 } 276 }
285 277
286 /* Initialize OPTS and OPTS_SET before using them in parsing options. */ 278 /* Initialize OPTS and OPTS_SET before using them in parsing options. */
287 279
288 void 280 void
289 init_options_struct (struct gcc_options *opts, struct gcc_options *opts_set) 281 init_options_struct (struct gcc_options *opts, struct gcc_options *opts_set)
290 { 282 {
291 size_t num_params = get_num_compiler_params (); 283 size_t num_params = get_num_compiler_params ();
292 284
285 /* Ensure that opts_obstack has already been initialized by the time
286 that we initialize any gcc_options instances (PR jit/68446). */
287 gcc_assert (opts_obstack.chunk_size > 0);
288
293 *opts = global_options_init; 289 *opts = global_options_init;
294 memset (opts_set, 0, sizeof (*opts_set)); 290
291 if (opts_set)
292 memset (opts_set, 0, sizeof (*opts_set));
295 293
296 opts->x_param_values = XNEWVEC (int, num_params); 294 opts->x_param_values = XNEWVEC (int, num_params);
297 opts_set->x_param_values = XCNEWVEC (int, num_params); 295
296 if (opts_set)
297 opts_set->x_param_values = XCNEWVEC (int, num_params);
298
298 init_param_values (opts->x_param_values); 299 init_param_values (opts->x_param_values);
299
300 /* Use priority coloring if cover classes is not defined for the
301 target. */
302 if (targetm.ira_cover_classes == NULL)
303 opts->x_flag_ira_algorithm = IRA_ALGORITHM_PRIORITY;
304 300
305 /* Initialize whether `char' is signed. */ 301 /* Initialize whether `char' is signed. */
306 opts->x_flag_signed_char = DEFAULT_SIGNED_CHAR; 302 opts->x_flag_signed_char = DEFAULT_SIGNED_CHAR;
307 /* Set this to a special "uninitialized" value. The actual default 303 /* Set this to a special "uninitialized" value. The actual default
308 is set after target options have been processed. */ 304 is set after target options have been processed. */
309 opts->x_flag_short_enums = 2; 305 opts->x_flag_short_enums = 2;
310 306
311 /* Initialize target_flags before targetm.target_option.optimization 307 /* Initialize target_flags before default_options_optimization
312 so the latter can modify it. */ 308 so the latter can modify it. */
313 opts->x_target_flags = targetm.default_target_flags; 309 opts->x_target_flags = targetm_common.default_target_flags;
314 310
315 /* Some targets have ABI-specified unwind tables. */ 311 /* Some targets have ABI-specified unwind tables. */
316 opts->x_flag_unwind_tables = targetm.unwind_tables_default; 312 opts->x_flag_unwind_tables = targetm_common.unwind_tables_default;
317 313
318 /* Some targets have other target-specific initialization. */ 314 /* Some targets have other target-specific initialization. */
319 targetm.target_option.init_struct (opts); 315 targetm_common.option_init_struct (opts);
316 }
317
318 /* Release any allocations owned by OPTS. */
319
320 void
321 finalize_options_struct (struct gcc_options *opts)
322 {
323 XDELETEVEC (opts->x_param_values);
320 } 324 }
321 325
322 /* If indicated by the optimization level LEVEL (-Os if SIZE is set, 326 /* If indicated by the optimization level LEVEL (-Os if SIZE is set,
323 -Ofast if FAST is set), apply the option DEFAULT_OPT to OPTS and 327 -Ofast if FAST is set, -Og if DEBUG is set), apply the option DEFAULT_OPT
324 OPTS_SET, diagnostic context DC, location LOC, with language mask 328 to OPTS and OPTS_SET, diagnostic context DC, location LOC, with language
325 LANG_MASK and option handlers HANDLERS. */ 329 mask LANG_MASK and option handlers HANDLERS. */
326 330
327 static void 331 static void
328 maybe_default_option (struct gcc_options *opts, 332 maybe_default_option (struct gcc_options *opts,
329 struct gcc_options *opts_set, 333 struct gcc_options *opts_set,
330 const struct default_options *default_opt, 334 const struct default_options *default_opt,
331 int level, bool size, bool fast, 335 int level, bool size, bool fast, bool debug,
332 unsigned int lang_mask, 336 unsigned int lang_mask,
333 const struct cl_option_handlers *handlers, 337 const struct cl_option_handlers *handlers,
334 location_t loc, 338 location_t loc,
335 diagnostic_context *dc) 339 diagnostic_context *dc)
336 { 340 {
339 343
340 if (size) 344 if (size)
341 gcc_assert (level == 2); 345 gcc_assert (level == 2);
342 if (fast) 346 if (fast)
343 gcc_assert (level == 3); 347 gcc_assert (level == 3);
348 if (debug)
349 gcc_assert (level == 1);
344 350
345 switch (default_opt->levels) 351 switch (default_opt->levels)
346 { 352 {
347 case OPT_LEVELS_ALL: 353 case OPT_LEVELS_ALL:
348 enabled = true; 354 enabled = true;
355 case OPT_LEVELS_1_PLUS: 361 case OPT_LEVELS_1_PLUS:
356 enabled = (level >= 1); 362 enabled = (level >= 1);
357 break; 363 break;
358 364
359 case OPT_LEVELS_1_PLUS_SPEED_ONLY: 365 case OPT_LEVELS_1_PLUS_SPEED_ONLY:
360 enabled = (level >= 1 && !size); 366 enabled = (level >= 1 && !size && !debug);
367 break;
368
369 case OPT_LEVELS_1_PLUS_NOT_DEBUG:
370 enabled = (level >= 1 && !debug);
361 break; 371 break;
362 372
363 case OPT_LEVELS_2_PLUS: 373 case OPT_LEVELS_2_PLUS:
364 enabled = (level >= 2); 374 enabled = (level >= 2);
365 break; 375 break;
366 376
367 case OPT_LEVELS_2_PLUS_SPEED_ONLY: 377 case OPT_LEVELS_2_PLUS_SPEED_ONLY:
368 enabled = (level >= 2 && !size); 378 enabled = (level >= 2 && !size && !debug);
369 break; 379 break;
370 380
371 case OPT_LEVELS_3_PLUS: 381 case OPT_LEVELS_3_PLUS:
372 enabled = (level >= 3); 382 enabled = (level >= 3);
373 break; 383 break;
391 401
392 if (enabled) 402 if (enabled)
393 handle_generated_option (opts, opts_set, default_opt->opt_index, 403 handle_generated_option (opts, opts_set, default_opt->opt_index,
394 default_opt->arg, default_opt->value, 404 default_opt->arg, default_opt->value,
395 lang_mask, DK_UNSPECIFIED, loc, 405 lang_mask, DK_UNSPECIFIED, loc,
396 handlers, dc); 406 handlers, true, dc);
397 else if (default_opt->arg == NULL 407 else if (default_opt->arg == NULL
398 && !(option->flags & CL_REJECT_NEGATIVE)) 408 && !option->cl_reject_negative)
399 handle_generated_option (opts, opts_set, default_opt->opt_index, 409 handle_generated_option (opts, opts_set, default_opt->opt_index,
400 default_opt->arg, !default_opt->value, 410 default_opt->arg, !default_opt->value,
401 lang_mask, DK_UNSPECIFIED, loc, 411 lang_mask, DK_UNSPECIFIED, loc,
402 handlers, dc); 412 handlers, true, dc);
403 } 413 }
404 414
405 /* As indicated by the optimization level LEVEL (-Os if SIZE is set, 415 /* As indicated by the optimization level LEVEL (-Os if SIZE is set,
406 -Ofast if FAST is set), apply the options in array DEFAULT_OPTS to 416 -Ofast if FAST is set), apply the options in array DEFAULT_OPTS to
407 OPTS and OPTS_SET, diagnostic context DC, location LOC, with 417 OPTS and OPTS_SET, diagnostic context DC, location LOC, with
409 419
410 static void 420 static void
411 maybe_default_options (struct gcc_options *opts, 421 maybe_default_options (struct gcc_options *opts,
412 struct gcc_options *opts_set, 422 struct gcc_options *opts_set,
413 const struct default_options *default_opts, 423 const struct default_options *default_opts,
414 int level, bool size, bool fast, 424 int level, bool size, bool fast, bool debug,
415 unsigned int lang_mask, 425 unsigned int lang_mask,
416 const struct cl_option_handlers *handlers, 426 const struct cl_option_handlers *handlers,
417 location_t loc, 427 location_t loc,
418 diagnostic_context *dc) 428 diagnostic_context *dc)
419 { 429 {
420 size_t i; 430 size_t i;
421 431
422 for (i = 0; default_opts[i].levels != OPT_LEVELS_NONE; i++) 432 for (i = 0; default_opts[i].levels != OPT_LEVELS_NONE; i++)
423 maybe_default_option (opts, opts_set, &default_opts[i], 433 maybe_default_option (opts, opts_set, &default_opts[i],
424 level, size, fast, lang_mask, handlers, loc, dc); 434 level, size, fast, debug,
435 lang_mask, handlers, loc, dc);
425 } 436 }
426 437
427 /* Table of options enabled by default at different levels. */ 438 /* Table of options enabled by default at different levels. */
428 439
429 static const struct default_options default_options_table[] = 440 static const struct default_options default_options_table[] =
430 { 441 {
431 /* -O1 optimizations. */ 442 /* -O1 optimizations. */
432 { OPT_LEVELS_1_PLUS, OPT_fdefer_pop, NULL, 1 }, 443 { OPT_LEVELS_1_PLUS, OPT_fdefer_pop, NULL, 1 },
433 #ifdef DELAY_SLOTS 444 #if DELAY_SLOTS
434 { OPT_LEVELS_1_PLUS, OPT_fdelayed_branch, NULL, 1 }, 445 { OPT_LEVELS_1_PLUS, OPT_fdelayed_branch, NULL, 1 },
435 #endif 446 #endif
436 { OPT_LEVELS_1_PLUS, OPT_fguess_branch_probability, NULL, 1 }, 447 { OPT_LEVELS_1_PLUS, OPT_fguess_branch_probability, NULL, 1 },
437 { OPT_LEVELS_1_PLUS, OPT_fcprop_registers, NULL, 1 }, 448 { OPT_LEVELS_1_PLUS, OPT_fcprop_registers, NULL, 1 },
438 { OPT_LEVELS_1_PLUS, OPT_fforward_propagate, NULL, 1 }, 449 { OPT_LEVELS_1_PLUS, OPT_fforward_propagate, NULL, 1 },
439 { OPT_LEVELS_1_PLUS, OPT_fif_conversion, NULL, 1 }, 450 { OPT_LEVELS_1_PLUS_NOT_DEBUG, OPT_fif_conversion, NULL, 1 },
440 { OPT_LEVELS_1_PLUS, OPT_fif_conversion2, NULL, 1 }, 451 { OPT_LEVELS_1_PLUS_NOT_DEBUG, OPT_fif_conversion2, NULL, 1 },
441 { OPT_LEVELS_1_PLUS, OPT_fipa_pure_const, NULL, 1 }, 452 { OPT_LEVELS_1_PLUS, OPT_fipa_pure_const, NULL, 1 },
442 { OPT_LEVELS_1_PLUS, OPT_fipa_reference, NULL, 1 }, 453 { OPT_LEVELS_1_PLUS, OPT_fipa_reference, NULL, 1 },
443 { OPT_LEVELS_1_PLUS, OPT_fipa_profile, NULL, 1 }, 454 { OPT_LEVELS_1_PLUS, OPT_fipa_profile, NULL, 1 },
444 { OPT_LEVELS_1_PLUS, OPT_fmerge_constants, NULL, 1 }, 455 { OPT_LEVELS_1_PLUS, OPT_fmerge_constants, NULL, 1 },
456 { OPT_LEVELS_1_PLUS, OPT_freorder_blocks, NULL, 1 },
457 { OPT_LEVELS_1_PLUS, OPT_fshrink_wrap, NULL, 1 },
445 { OPT_LEVELS_1_PLUS, OPT_fsplit_wide_types, NULL, 1 }, 458 { OPT_LEVELS_1_PLUS, OPT_fsplit_wide_types, NULL, 1 },
446 { OPT_LEVELS_1_PLUS, OPT_ftree_ccp, NULL, 1 }, 459 { OPT_LEVELS_1_PLUS, OPT_ftree_ccp, NULL, 1 },
447 { OPT_LEVELS_1_PLUS, OPT_ftree_bit_ccp, NULL, 1 }, 460 { OPT_LEVELS_1_PLUS_NOT_DEBUG, OPT_ftree_bit_ccp, NULL, 1 },
461 { OPT_LEVELS_1_PLUS, OPT_ftree_coalesce_vars, NULL, 1 },
448 { OPT_LEVELS_1_PLUS, OPT_ftree_dce, NULL, 1 }, 462 { OPT_LEVELS_1_PLUS, OPT_ftree_dce, NULL, 1 },
449 { OPT_LEVELS_1_PLUS, OPT_ftree_dominator_opts, NULL, 1 }, 463 { OPT_LEVELS_1_PLUS, OPT_ftree_dominator_opts, NULL, 1 },
450 { OPT_LEVELS_1_PLUS, OPT_ftree_dse, NULL, 1 }, 464 { OPT_LEVELS_1_PLUS, OPT_ftree_dse, NULL, 1 },
451 { OPT_LEVELS_1_PLUS, OPT_ftree_ter, NULL, 1 }, 465 { OPT_LEVELS_1_PLUS, OPT_ftree_ter, NULL, 1 },
452 { OPT_LEVELS_1_PLUS, OPT_ftree_sra, NULL, 1 }, 466 { OPT_LEVELS_1_PLUS_NOT_DEBUG, OPT_ftree_sra, NULL, 1 },
453 { OPT_LEVELS_1_PLUS, OPT_ftree_copyrename, NULL, 1 },
454 { OPT_LEVELS_1_PLUS, OPT_ftree_fre, NULL, 1 }, 467 { OPT_LEVELS_1_PLUS, OPT_ftree_fre, NULL, 1 },
455 { OPT_LEVELS_1_PLUS, OPT_ftree_copy_prop, NULL, 1 }, 468 { OPT_LEVELS_1_PLUS, OPT_ftree_copy_prop, NULL, 1 },
456 { OPT_LEVELS_1_PLUS, OPT_ftree_sink, NULL, 1 }, 469 { OPT_LEVELS_1_PLUS, OPT_ftree_sink, NULL, 1 },
457 { OPT_LEVELS_1_PLUS, OPT_ftree_ch, NULL, 1 }, 470 { OPT_LEVELS_1_PLUS, OPT_ftree_ch, NULL, 1 },
458 { OPT_LEVELS_1_PLUS, OPT_fcombine_stack_adjustments, NULL, 1 }, 471 { OPT_LEVELS_1_PLUS, OPT_fcombine_stack_adjustments, NULL, 1 },
459 { OPT_LEVELS_1_PLUS, OPT_fcompare_elim, NULL, 1 }, 472 { OPT_LEVELS_1_PLUS, OPT_fcompare_elim, NULL, 1 },
473 { OPT_LEVELS_1_PLUS, OPT_ftree_slsr, NULL, 1 },
474 { OPT_LEVELS_1_PLUS_NOT_DEBUG, OPT_fbranch_count_reg, NULL, 1 },
475 { OPT_LEVELS_1_PLUS_NOT_DEBUG, OPT_fmove_loop_invariants, NULL, 1 },
476 { OPT_LEVELS_1_PLUS_NOT_DEBUG, OPT_ftree_pta, NULL, 1 },
477 { OPT_LEVELS_1_PLUS_NOT_DEBUG, OPT_fssa_phiopt, NULL, 1 },
478 { OPT_LEVELS_1_PLUS, OPT_ftree_builtin_call_dce, NULL, 1 },
460 479
461 /* -O2 optimizations. */ 480 /* -O2 optimizations. */
462 { OPT_LEVELS_2_PLUS, OPT_finline_small_functions, NULL, 1 }, 481 { OPT_LEVELS_2_PLUS, OPT_finline_small_functions, NULL, 1 },
463 { OPT_LEVELS_2_PLUS, OPT_findirect_inlining, NULL, 1 }, 482 { OPT_LEVELS_2_PLUS, OPT_findirect_inlining, NULL, 1 },
464 { OPT_LEVELS_2_PLUS, OPT_fpartial_inlining, NULL, 1 }, 483 { OPT_LEVELS_2_PLUS, OPT_fpartial_inlining, NULL, 1 },
474 #ifdef INSN_SCHEDULING 493 #ifdef INSN_SCHEDULING
475 /* Only run the pre-regalloc scheduling pass if optimizing for speed. */ 494 /* Only run the pre-regalloc scheduling pass if optimizing for speed. */
476 { OPT_LEVELS_2_PLUS_SPEED_ONLY, OPT_fschedule_insns, NULL, 1 }, 495 { OPT_LEVELS_2_PLUS_SPEED_ONLY, OPT_fschedule_insns, NULL, 1 },
477 { OPT_LEVELS_2_PLUS, OPT_fschedule_insns2, NULL, 1 }, 496 { OPT_LEVELS_2_PLUS, OPT_fschedule_insns2, NULL, 1 },
478 #endif 497 #endif
479 { OPT_LEVELS_2_PLUS, OPT_fregmove, NULL, 1 },
480 { OPT_LEVELS_2_PLUS, OPT_fstrict_aliasing, NULL, 1 }, 498 { OPT_LEVELS_2_PLUS, OPT_fstrict_aliasing, NULL, 1 },
481 { OPT_LEVELS_2_PLUS, OPT_fstrict_overflow, NULL, 1 }, 499 { OPT_LEVELS_2_PLUS_SPEED_ONLY, OPT_freorder_blocks_algorithm_, NULL,
482 { OPT_LEVELS_2_PLUS, OPT_freorder_blocks, NULL, 1 }, 500 REORDER_BLOCKS_ALGORITHM_STC },
483 { OPT_LEVELS_2_PLUS, OPT_freorder_functions, NULL, 1 }, 501 { OPT_LEVELS_2_PLUS, OPT_freorder_functions, NULL, 1 },
484 { OPT_LEVELS_2_PLUS, OPT_ftree_vrp, NULL, 1 }, 502 { OPT_LEVELS_2_PLUS, OPT_ftree_vrp, NULL, 1 },
485 { OPT_LEVELS_2_PLUS, OPT_ftree_builtin_call_dce, NULL, 1 }, 503 { OPT_LEVELS_2_PLUS, OPT_fcode_hoisting, NULL, 1 },
486 { OPT_LEVELS_2_PLUS, OPT_ftree_pre, NULL, 1 }, 504 { OPT_LEVELS_2_PLUS, OPT_ftree_pre, NULL, 1 },
487 { OPT_LEVELS_2_PLUS, OPT_ftree_switch_conversion, NULL, 1 }, 505 { OPT_LEVELS_2_PLUS, OPT_ftree_switch_conversion, NULL, 1 },
488 { OPT_LEVELS_2_PLUS, OPT_fipa_cp, NULL, 1 }, 506 { OPT_LEVELS_2_PLUS, OPT_fipa_cp, NULL, 1 },
507 { OPT_LEVELS_2_PLUS, OPT_fipa_bit_cp, NULL, 1 },
508 { OPT_LEVELS_2_PLUS, OPT_fipa_vrp, NULL, 1 },
489 { OPT_LEVELS_2_PLUS, OPT_fdevirtualize, NULL, 1 }, 509 { OPT_LEVELS_2_PLUS, OPT_fdevirtualize, NULL, 1 },
510 { OPT_LEVELS_2_PLUS, OPT_fdevirtualize_speculatively, NULL, 1 },
490 { OPT_LEVELS_2_PLUS, OPT_fipa_sra, NULL, 1 }, 511 { OPT_LEVELS_2_PLUS, OPT_fipa_sra, NULL, 1 },
491 { OPT_LEVELS_2_PLUS, OPT_falign_loops, NULL, 1 }, 512 { OPT_LEVELS_2_PLUS, OPT_falign_loops, NULL, 1 },
492 { OPT_LEVELS_2_PLUS, OPT_falign_jumps, NULL, 1 }, 513 { OPT_LEVELS_2_PLUS, OPT_falign_jumps, NULL, 1 },
493 { OPT_LEVELS_2_PLUS, OPT_falign_labels, NULL, 1 }, 514 { OPT_LEVELS_2_PLUS, OPT_falign_labels, NULL, 1 },
494 { OPT_LEVELS_2_PLUS, OPT_falign_functions, NULL, 1 }, 515 { OPT_LEVELS_2_PLUS, OPT_falign_functions, NULL, 1 },
516 { OPT_LEVELS_2_PLUS, OPT_ftree_tail_merge, NULL, 1 },
517 { OPT_LEVELS_2_PLUS, OPT_fvect_cost_model_, NULL, VECT_COST_MODEL_CHEAP },
518 { OPT_LEVELS_2_PLUS_SPEED_ONLY, OPT_foptimize_strlen, NULL, 1 },
519 { OPT_LEVELS_2_PLUS, OPT_fhoist_adjacent_loads, NULL, 1 },
520 { OPT_LEVELS_2_PLUS, OPT_fipa_icf, NULL, 1 },
521 { OPT_LEVELS_2_PLUS, OPT_fisolate_erroneous_paths_dereference, NULL, 1 },
522 { OPT_LEVELS_2_PLUS, OPT_fipa_ra, NULL, 1 },
523 { OPT_LEVELS_2_PLUS, OPT_flra_remat, NULL, 1 },
524 { OPT_LEVELS_2_PLUS, OPT_fstore_merging, NULL, 1 },
495 525
496 /* -O3 optimizations. */ 526 /* -O3 optimizations. */
497 { OPT_LEVELS_3_PLUS, OPT_ftree_loop_distribute_patterns, NULL, 1 }, 527 { OPT_LEVELS_3_PLUS, OPT_ftree_loop_distribute_patterns, NULL, 1 },
528 { OPT_LEVELS_3_PLUS, OPT_ftree_loop_distribution, NULL, 1 },
498 { OPT_LEVELS_3_PLUS, OPT_fpredictive_commoning, NULL, 1 }, 529 { OPT_LEVELS_3_PLUS, OPT_fpredictive_commoning, NULL, 1 },
530 { OPT_LEVELS_3_PLUS, OPT_fsplit_paths, NULL, 1 },
499 /* Inlining of functions reducing size is a good idea with -Os 531 /* Inlining of functions reducing size is a good idea with -Os
500 regardless of them being declared inline. */ 532 regardless of them being declared inline. */
501 { OPT_LEVELS_3_PLUS_AND_SIZE, OPT_finline_functions, NULL, 1 }, 533 { OPT_LEVELS_3_PLUS_AND_SIZE, OPT_finline_functions, NULL, 1 },
534 { OPT_LEVELS_1_PLUS_NOT_DEBUG, OPT_finline_functions_called_once, NULL, 1 },
535 { OPT_LEVELS_3_PLUS, OPT_fsplit_loops, NULL, 1 },
502 { OPT_LEVELS_3_PLUS, OPT_funswitch_loops, NULL, 1 }, 536 { OPT_LEVELS_3_PLUS, OPT_funswitch_loops, NULL, 1 },
503 { OPT_LEVELS_3_PLUS, OPT_fgcse_after_reload, NULL, 1 }, 537 { OPT_LEVELS_3_PLUS, OPT_fgcse_after_reload, NULL, 1 },
504 { OPT_LEVELS_3_PLUS, OPT_ftree_vectorize, NULL, 1 }, 538 { OPT_LEVELS_3_PLUS, OPT_ftree_loop_vectorize, NULL, 1 },
539 { OPT_LEVELS_3_PLUS, OPT_ftree_slp_vectorize, NULL, 1 },
540 { OPT_LEVELS_3_PLUS, OPT_fvect_cost_model_, NULL, VECT_COST_MODEL_DYNAMIC },
505 { OPT_LEVELS_3_PLUS, OPT_fipa_cp_clone, NULL, 1 }, 541 { OPT_LEVELS_3_PLUS, OPT_fipa_cp_clone, NULL, 1 },
542 { OPT_LEVELS_3_PLUS, OPT_ftree_partial_pre, NULL, 1 },
543 { OPT_LEVELS_3_PLUS, OPT_fpeel_loops, NULL, 1 },
506 544
507 /* -Ofast adds optimizations to -O3. */ 545 /* -Ofast adds optimizations to -O3. */
508 { OPT_LEVELS_FAST, OPT_ffast_math, NULL, 1 }, 546 { OPT_LEVELS_FAST, OPT_ffast_math, NULL, 1 },
509 547
510 { OPT_LEVELS_NONE, 0, NULL, 0 } 548 { OPT_LEVELS_NONE, 0, NULL, 0 }
522 const struct cl_option_handlers *handlers, 560 const struct cl_option_handlers *handlers,
523 diagnostic_context *dc) 561 diagnostic_context *dc)
524 { 562 {
525 unsigned int i; 563 unsigned int i;
526 int opt2; 564 int opt2;
565 bool openacc_mode = false;
527 566
528 /* Scan to see what optimization level has been specified. That will 567 /* Scan to see what optimization level has been specified. That will
529 determine the default value of many flags. */ 568 determine the default value of many flags. */
530 for (i = 1; i < decoded_options_count; i++) 569 for (i = 1; i < decoded_options_count; i++)
531 { 570 {
536 if (*opt->arg == '\0') 575 if (*opt->arg == '\0')
537 { 576 {
538 opts->x_optimize = 1; 577 opts->x_optimize = 1;
539 opts->x_optimize_size = 0; 578 opts->x_optimize_size = 0;
540 opts->x_optimize_fast = 0; 579 opts->x_optimize_fast = 0;
580 opts->x_optimize_debug = 0;
541 } 581 }
542 else 582 else
543 { 583 {
544 const int optimize_val = integral_argument (opt->arg); 584 const int optimize_val = integral_argument (opt->arg);
545 if (optimize_val == -1) 585 if (optimize_val == -1)
546 error_at (loc, 586 error_at (loc, "argument to %<-O%> should be a non-negative "
547 "argument to %qs should be a non-negative integer", 587 "integer, %<g%>, %<s%> or %<fast%>");
548 "-O");
549 else 588 else
550 { 589 {
551 opts->x_optimize = optimize_val; 590 opts->x_optimize = optimize_val;
552 if ((unsigned int) opts->x_optimize > 255) 591 if ((unsigned int) opts->x_optimize > 255)
553 opts->x_optimize = 255; 592 opts->x_optimize = 255;
554 opts->x_optimize_size = 0; 593 opts->x_optimize_size = 0;
555 opts->x_optimize_fast = 0; 594 opts->x_optimize_fast = 0;
595 opts->x_optimize_debug = 0;
556 } 596 }
557 } 597 }
558 break; 598 break;
559 599
560 case OPT_Os: 600 case OPT_Os:
561 opts->x_optimize_size = 1; 601 opts->x_optimize_size = 1;
562 602
563 /* Optimizing for size forces optimize to be 2. */ 603 /* Optimizing for size forces optimize to be 2. */
564 opts->x_optimize = 2; 604 opts->x_optimize = 2;
565 opts->x_optimize_fast = 0; 605 opts->x_optimize_fast = 0;
606 opts->x_optimize_debug = 0;
566 break; 607 break;
567 608
568 case OPT_Ofast: 609 case OPT_Ofast:
569 /* -Ofast only adds flags to -O3. */ 610 /* -Ofast only adds flags to -O3. */
570 opts->x_optimize_size = 0; 611 opts->x_optimize_size = 0;
571 opts->x_optimize = 3; 612 opts->x_optimize = 3;
572 opts->x_optimize_fast = 1; 613 opts->x_optimize_fast = 1;
614 opts->x_optimize_debug = 0;
615 break;
616
617 case OPT_Og:
618 /* -Og selects optimization level 1. */
619 opts->x_optimize_size = 0;
620 opts->x_optimize = 1;
621 opts->x_optimize_fast = 0;
622 opts->x_optimize_debug = 1;
623 break;
624
625 case OPT_fopenacc:
626 if (opt->value)
627 openacc_mode = true;
573 break; 628 break;
574 629
575 default: 630 default:
576 /* Ignore other options in this prescan. */ 631 /* Ignore other options in this prescan. */
577 break; 632 break;
578 } 633 }
579 } 634 }
580 635
581 maybe_default_options (opts, opts_set, default_options_table, 636 maybe_default_options (opts, opts_set, default_options_table,
582 opts->x_optimize, opts->x_optimize_size, 637 opts->x_optimize, opts->x_optimize_size,
583 opts->x_optimize_fast, lang_mask, handlers, loc, dc); 638 opts->x_optimize_fast, opts->x_optimize_debug,
639 lang_mask, handlers, loc, dc);
584 640
585 /* -O2 param settings. */ 641 /* -O2 param settings. */
586 opt2 = (opts->x_optimize >= 2); 642 opt2 = (opts->x_optimize >= 2);
643
644 if (openacc_mode
645 && !opts_set->x_flag_ipa_pta)
646 opts->x_flag_ipa_pta = true;
587 647
588 /* Track fields in field-sensitive alias analysis. */ 648 /* Track fields in field-sensitive alias analysis. */
589 maybe_set_param_value 649 maybe_set_param_value
590 (PARAM_MAX_FIELDS_FOR_FIELD_SENSITIVE, 650 (PARAM_MAX_FIELDS_FOR_FIELD_SENSITIVE,
591 opt2 ? 100 : default_param_value (PARAM_MAX_FIELDS_FOR_FIELD_SENSITIVE), 651 opt2 ? 100 : default_param_value (PARAM_MAX_FIELDS_FOR_FIELD_SENSITIVE),
593 653
594 /* For -O1 only do loop invariant motion for very small loops. */ 654 /* For -O1 only do loop invariant motion for very small loops. */
595 maybe_set_param_value 655 maybe_set_param_value
596 (PARAM_LOOP_INVARIANT_MAX_BBS_IN_LOOP, 656 (PARAM_LOOP_INVARIANT_MAX_BBS_IN_LOOP,
597 opt2 ? default_param_value (PARAM_LOOP_INVARIANT_MAX_BBS_IN_LOOP) : 1000, 657 opt2 ? default_param_value (PARAM_LOOP_INVARIANT_MAX_BBS_IN_LOOP) : 1000,
658 opts->x_param_values, opts_set->x_param_values);
659
660 /* At -Ofast, allow store motion to introduce potential race conditions. */
661 maybe_set_param_value
662 (PARAM_ALLOW_STORE_DATA_RACES,
663 opts->x_optimize_fast ? 1
664 : default_param_value (PARAM_ALLOW_STORE_DATA_RACES),
598 opts->x_param_values, opts_set->x_param_values); 665 opts->x_param_values, opts_set->x_param_values);
599 666
600 if (opts->x_optimize_size) 667 if (opts->x_optimize_size)
601 /* We want to crossjump as much as possible. */ 668 /* We want to crossjump as much as possible. */
602 maybe_set_param_value (PARAM_MIN_CROSSJUMP_INSNS, 1, 669 maybe_set_param_value (PARAM_MIN_CROSSJUMP_INSNS, 1,
604 else 671 else
605 maybe_set_param_value (PARAM_MIN_CROSSJUMP_INSNS, 672 maybe_set_param_value (PARAM_MIN_CROSSJUMP_INSNS,
606 default_param_value (PARAM_MIN_CROSSJUMP_INSNS), 673 default_param_value (PARAM_MIN_CROSSJUMP_INSNS),
607 opts->x_param_values, opts_set->x_param_values); 674 opts->x_param_values, opts_set->x_param_values);
608 675
676 /* Restrict the amount of work combine does at -Og while retaining
677 most of its useful transforms. */
678 if (opts->x_optimize_debug)
679 maybe_set_param_value (PARAM_MAX_COMBINE_INSNS, 2,
680 opts->x_param_values, opts_set->x_param_values);
681
609 /* Allow default optimizations to be specified on a per-machine basis. */ 682 /* Allow default optimizations to be specified on a per-machine basis. */
610 maybe_default_options (opts, opts_set, 683 maybe_default_options (opts, opts_set,
611 targetm.target_option.optimization_table, 684 targetm_common.option_optimization_table,
612 opts->x_optimize, opts->x_optimize_size, 685 opts->x_optimize, opts->x_optimize_size,
613 opts->x_optimize_fast, lang_mask, handlers, loc, dc); 686 opts->x_optimize_fast, opts->x_optimize_debug,
687 lang_mask, handlers, loc, dc);
614 } 688 }
615 689
616 /* After all options at LOC have been read into OPTS and OPTS_SET, 690 /* After all options at LOC have been read into OPTS and OPTS_SET,
617 finalize settings of those options and diagnose incompatible 691 finalize settings of those options and diagnose incompatible
618 combinations. */ 692 combinations. */
620 finish_options (struct gcc_options *opts, struct gcc_options *opts_set, 694 finish_options (struct gcc_options *opts, struct gcc_options *opts_set,
621 location_t loc) 695 location_t loc)
622 { 696 {
623 enum unwind_info_type ui_except; 697 enum unwind_info_type ui_except;
624 698
625 if (opts->x_dump_base_name && ! IS_ABSOLUTE_PATH (opts->x_dump_base_name)) 699 if (opts->x_dump_base_name
700 && ! IS_ABSOLUTE_PATH (opts->x_dump_base_name)
701 && ! opts->x_dump_base_name_prefixed)
626 { 702 {
627 /* First try to make OPTS->X_DUMP_BASE_NAME relative to the 703 /* First try to make OPTS->X_DUMP_BASE_NAME relative to the
628 OPTS->X_DUMP_DIR_NAME directory. Then try to make 704 OPTS->X_DUMP_DIR_NAME directory. Then try to make
629 OPTS->X_DUMP_BASE_NAME relative to the OPTS->X_AUX_BASE_NAME 705 OPTS->X_DUMP_BASE_NAME relative to the OPTS->X_AUX_BASE_NAME
630 directory, typically the directory to contain the object 706 directory, typically the directory to contain the object
631 file. */ 707 file. */
632 if (opts->x_dump_dir_name) 708 if (opts->x_dump_dir_name)
633 opts->x_dump_base_name = concat (opts->x_dump_dir_name, 709 opts->x_dump_base_name = opts_concat (opts->x_dump_dir_name,
634 opts->x_dump_base_name, NULL); 710 opts->x_dump_base_name, NULL);
635 else if (opts->x_aux_base_name 711 else if (opts->x_aux_base_name
636 && strcmp (opts->x_aux_base_name, HOST_BIT_BUCKET) != 0) 712 && strcmp (opts->x_aux_base_name, HOST_BIT_BUCKET) != 0)
637 { 713 {
638 const char *aux_base; 714 const char *aux_base;
639 715
640 base_of_path (opts->x_aux_base_name, &aux_base); 716 base_of_path (opts->x_aux_base_name, &aux_base);
641 if (opts->x_aux_base_name != aux_base) 717 if (opts->x_aux_base_name != aux_base)
642 { 718 {
643 int dir_len = aux_base - opts->x_aux_base_name; 719 int dir_len = aux_base - opts->x_aux_base_name;
644 char *new_dump_base_name = 720 char *new_dump_base_name
645 XNEWVEC (char, strlen (opts->x_dump_base_name) + dir_len + 1); 721 = XOBNEWVEC (&opts_obstack, char,
722 strlen (opts->x_dump_base_name) + dir_len + 1);
646 723
647 /* Copy directory component from OPTS->X_AUX_BASE_NAME. */ 724 /* Copy directory component from OPTS->X_AUX_BASE_NAME. */
648 memcpy (new_dump_base_name, opts->x_aux_base_name, dir_len); 725 memcpy (new_dump_base_name, opts->x_aux_base_name, dir_len);
649 /* Append existing OPTS->X_DUMP_BASE_NAME. */ 726 /* Append existing OPTS->X_DUMP_BASE_NAME. */
650 strcpy (new_dump_base_name + dir_len, opts->x_dump_base_name); 727 strcpy (new_dump_base_name + dir_len, opts->x_dump_base_name);
651 opts->x_dump_base_name = new_dump_base_name; 728 opts->x_dump_base_name = new_dump_base_name;
652 } 729 }
653 } 730 }
731 opts->x_dump_base_name_prefixed = true;
654 } 732 }
655 733
656 /* Handle related options for unit-at-a-time, toplevel-reorder, and 734 /* Handle related options for unit-at-a-time, toplevel-reorder, and
657 section-anchors. */ 735 section-anchors. */
658 if (!opts->x_flag_unit_at_a_time) 736 if (!opts->x_flag_unit_at_a_time)
665 error_at (loc, "toplevel reorder must be disabled when unit-at-a-time " 743 error_at (loc, "toplevel reorder must be disabled when unit-at-a-time "
666 "is disabled"); 744 "is disabled");
667 opts->x_flag_toplevel_reorder = 0; 745 opts->x_flag_toplevel_reorder = 0;
668 } 746 }
669 747
670 /* -Wmissing-noreturn is alias for -Wsuggest-attribute=noreturn. */ 748 /* -fself-test depends on the state of the compiler prior to
671 if (opts->x_warn_missing_noreturn) 749 compiling anything. Ideally it should be run on an empty source
672 opts->x_warn_suggest_attribute_noreturn = true; 750 file. However, in case we get run with actual source, assume
673 751 -fsyntax-only which will inhibit any compiler initialization
752 which may confuse the self tests. */
753 if (opts->x_flag_self_test)
754 opts->x_flag_syntax_only = 1;
755
756 if (opts->x_flag_tm && opts->x_flag_non_call_exceptions)
757 sorry ("transactional memory is not supported with non-call exceptions");
758
674 /* Unless the user has asked for section anchors, we disable toplevel 759 /* Unless the user has asked for section anchors, we disable toplevel
675 reordering at -O0 to disable transformations that might be surprising 760 reordering at -O0 to disable transformations that might be surprising
676 to end users and to get -fno-toplevel-reorder tested. */ 761 to end users and to get -fno-toplevel-reorder tested. */
677 if (!opts->x_optimize 762 if (!opts->x_optimize
678 && opts->x_flag_toplevel_reorder == 2 763 && opts->x_flag_toplevel_reorder == 2
689 opts->x_flag_section_anchors = 0; 774 opts->x_flag_section_anchors = 0;
690 } 775 }
691 776
692 if (!opts->x_flag_opts_finished) 777 if (!opts->x_flag_opts_finished)
693 { 778 {
779 /* We initialize opts->x_flag_pie to -1 so that targets can set a
780 default value. */
781 if (opts->x_flag_pie == -1)
782 {
783 /* We initialize opts->x_flag_pic to -1 so that we can tell if
784 -fpic, -fPIC, -fno-pic or -fno-PIC is used. */
785 if (opts->x_flag_pic == -1)
786 opts->x_flag_pie = DEFAULT_FLAG_PIE;
787 else
788 opts->x_flag_pie = 0;
789 }
790 /* If -fPIE or -fpie is used, turn on PIC. */
694 if (opts->x_flag_pie) 791 if (opts->x_flag_pie)
695 opts->x_flag_pic = opts->x_flag_pie; 792 opts->x_flag_pic = opts->x_flag_pie;
793 else if (opts->x_flag_pic == -1)
794 opts->x_flag_pic = 0;
696 if (opts->x_flag_pic && !opts->x_flag_pie) 795 if (opts->x_flag_pic && !opts->x_flag_pie)
697 opts->x_flag_shlib = 1; 796 opts->x_flag_shlib = 1;
698 opts->x_flag_opts_finished = true; 797 opts->x_flag_opts_finished = true;
699 } 798 }
799
800 /* We initialize opts->x_flag_stack_protect to -1 so that targets
801 can set a default value. */
802 if (opts->x_flag_stack_protect == -1)
803 opts->x_flag_stack_protect = DEFAULT_FLAG_SSP;
700 804
701 if (opts->x_optimize == 0) 805 if (opts->x_optimize == 0)
702 { 806 {
703 /* Inlining does not work if not optimizing, 807 /* Inlining does not work if not optimizing,
704 so force it not to be done. */ 808 so force it not to be done. */
710 sections of the .o and executable files does not work (currently) 814 sections of the .o and executable files does not work (currently)
711 with exception handling. This is because there is no support for 815 with exception handling. This is because there is no support for
712 generating unwind info. If opts->x_flag_exceptions is turned on 816 generating unwind info. If opts->x_flag_exceptions is turned on
713 we need to turn off the partitioning optimization. */ 817 we need to turn off the partitioning optimization. */
714 818
715 ui_except = targetm.except_unwind_info (opts); 819 ui_except = targetm_common.except_unwind_info (opts);
716 820
717 if (opts->x_flag_exceptions 821 if (opts->x_flag_exceptions
718 && opts->x_flag_reorder_blocks_and_partition 822 && opts->x_flag_reorder_blocks_and_partition
719 && (ui_except == UI_SJLJ || ui_except == UI_TARGET)) 823 && (ui_except == UI_SJLJ || ui_except >= UI_TARGET))
720 { 824 {
721 inform (loc, 825 if (opts_set->x_flag_reorder_blocks_and_partition)
722 "-freorder-blocks-and-partition does not work " 826 inform (loc,
723 "with exceptions on this architecture"); 827 "%<-freorder-blocks-and-partition%> does not work "
828 "with exceptions on this architecture");
724 opts->x_flag_reorder_blocks_and_partition = 0; 829 opts->x_flag_reorder_blocks_and_partition = 0;
725 opts->x_flag_reorder_blocks = 1; 830 opts->x_flag_reorder_blocks = 1;
726 } 831 }
727 832
728 /* If user requested unwind info, then turn off the partitioning 833 /* If user requested unwind info, then turn off the partitioning
729 optimization. */ 834 optimization. */
730 835
731 if (opts->x_flag_unwind_tables 836 if (opts->x_flag_unwind_tables
732 && !targetm.unwind_tables_default 837 && !targetm_common.unwind_tables_default
733 && opts->x_flag_reorder_blocks_and_partition 838 && opts->x_flag_reorder_blocks_and_partition
734 && (ui_except == UI_SJLJ || ui_except == UI_TARGET)) 839 && (ui_except == UI_SJLJ || ui_except >= UI_TARGET))
735 { 840 {
736 inform (loc, 841 if (opts_set->x_flag_reorder_blocks_and_partition)
737 "-freorder-blocks-and-partition does not support " 842 inform (loc,
738 "unwind info on this architecture"); 843 "%<-freorder-blocks-and-partition%> does not support "
844 "unwind info on this architecture");
739 opts->x_flag_reorder_blocks_and_partition = 0; 845 opts->x_flag_reorder_blocks_and_partition = 0;
740 opts->x_flag_reorder_blocks = 1; 846 opts->x_flag_reorder_blocks = 1;
741 } 847 }
742 848
743 /* If the target requested unwind info, then turn off the partitioning 849 /* If the target requested unwind info, then turn off the partitioning
744 optimization with a different message. Likewise, if the target does not 850 optimization with a different message. Likewise, if the target does not
745 support named sections. */ 851 support named sections. */
746 852
747 if (opts->x_flag_reorder_blocks_and_partition 853 if (opts->x_flag_reorder_blocks_and_partition
748 && (!targetm.have_named_sections 854 && (!targetm_common.have_named_sections
749 || (opts->x_flag_unwind_tables 855 || (opts->x_flag_unwind_tables
750 && targetm.unwind_tables_default 856 && targetm_common.unwind_tables_default
751 && (ui_except == UI_SJLJ || ui_except == UI_TARGET)))) 857 && (ui_except == UI_SJLJ || ui_except >= UI_TARGET))))
752 { 858 {
753 inform (loc, 859 if (opts_set->x_flag_reorder_blocks_and_partition)
754 "-freorder-blocks-and-partition does not work " 860 inform (loc,
755 "on this architecture"); 861 "%<-freorder-blocks-and-partition%> does not work "
862 "on this architecture");
756 opts->x_flag_reorder_blocks_and_partition = 0; 863 opts->x_flag_reorder_blocks_and_partition = 0;
757 opts->x_flag_reorder_blocks = 1; 864 opts->x_flag_reorder_blocks = 1;
758 } 865 }
759 866
760 if (opts->x_flag_reorder_blocks_and_partition
761 && !opts_set->x_flag_reorder_functions)
762 opts->x_flag_reorder_functions = 1;
763 867
764 /* Pipelining of outer loops is only possible when general pipelining 868 /* Pipelining of outer loops is only possible when general pipelining
765 capabilities are requested. */ 869 capabilities are requested. */
766 if (!opts->x_flag_sel_sched_pipelining) 870 if (!opts->x_flag_sel_sched_pipelining)
767 opts->x_flag_sel_sched_pipelining_outer_loops = 0; 871 opts->x_flag_sel_sched_pipelining_outer_loops = 0;
768 872
769 if (!targetm.ira_cover_classes
770 && opts->x_flag_ira_algorithm == IRA_ALGORITHM_CB)
771 {
772 inform (loc,
773 "-fira-algorithm=CB does not work on this architecture");
774 opts->x_flag_ira_algorithm = IRA_ALGORITHM_PRIORITY;
775 }
776
777 if (opts->x_flag_conserve_stack) 873 if (opts->x_flag_conserve_stack)
778 { 874 {
779 maybe_set_param_value (PARAM_LARGE_STACK_FRAME, 100, 875 maybe_set_param_value (PARAM_LARGE_STACK_FRAME, 100,
780 opts->x_param_values, opts_set->x_param_values); 876 opts->x_param_values, opts_set->x_param_values);
781 maybe_set_param_value (PARAM_STACK_FRAME_GROWTH, 40, 877 maybe_set_param_value (PARAM_STACK_FRAME_GROWTH, 40,
782 opts->x_param_values, opts_set->x_param_values); 878 opts->x_param_values, opts_set->x_param_values);
783 }
784 if (opts->x_flag_wpa || opts->x_flag_ltrans)
785 {
786 /* These passes are not WHOPR compatible yet. */
787 opts->x_flag_ipa_pta = 0;
788 opts->x_flag_ipa_struct_reorg = 0;
789 } 879 }
790 880
791 if (opts->x_flag_lto) 881 if (opts->x_flag_lto)
792 { 882 {
793 #ifdef ENABLE_LTO 883 #ifdef ENABLE_LTO
798 errors later. */ 888 errors later. */
799 opts->x_flag_whole_program = 0; 889 opts->x_flag_whole_program = 0;
800 #else 890 #else
801 error_at (loc, "LTO support has not been enabled in this configuration"); 891 error_at (loc, "LTO support has not been enabled in this configuration");
802 #endif 892 #endif
803 } 893 if (!opts->x_flag_fat_lto_objects
804 if ((opts->x_flag_lto_partition_balanced != 0) + (opts->x_flag_lto_partition_1to1 != 0) 894 && (!HAVE_LTO_PLUGIN
805 + (opts->x_flag_lto_partition_none != 0) >= 1) 895 || (opts_set->x_flag_use_linker_plugin
806 { 896 && !opts->x_flag_use_linker_plugin)))
807 if ((opts->x_flag_lto_partition_balanced != 0) 897 {
808 + (opts->x_flag_lto_partition_1to1 != 0) 898 if (opts_set->x_flag_fat_lto_objects)
809 + (opts->x_flag_lto_partition_none != 0) > 1) 899 error_at (loc, "%<-fno-fat-lto-objects%> are supported only with "
810 error_at (loc, "only one -flto-partition value can be specified"); 900 "linker plugin");
901 opts->x_flag_fat_lto_objects = 1;
902 }
811 } 903 }
812 904
813 /* We initialize opts->x_flag_split_stack to -1 so that targets can set a 905 /* We initialize opts->x_flag_split_stack to -1 so that targets can set a
814 default value if they choose based on other options. */ 906 default value if they choose based on other options. */
815 if (opts->x_flag_split_stack == -1) 907 if (opts->x_flag_split_stack == -1)
816 opts->x_flag_split_stack = 0; 908 opts->x_flag_split_stack = 0;
817 else if (opts->x_flag_split_stack) 909 else if (opts->x_flag_split_stack)
818 { 910 {
819 if (!targetm.supports_split_stack (true, opts)) 911 if (!targetm_common.supports_split_stack (true, opts))
820 { 912 {
821 error_at (loc, "%<-fsplit-stack%> is not supported by " 913 error_at (loc, "%<-fsplit-stack%> is not supported by "
822 "this compiler configuration"); 914 "this compiler configuration");
823 opts->x_flag_split_stack = 0; 915 opts->x_flag_split_stack = 0;
824 } 916 }
825 } 917 }
918
919 /* If stack splitting is turned on, and the user did not explicitly
920 request function partitioning, turn off partitioning, as it
921 confuses the linker when trying to handle partitioned split-stack
922 code that calls a non-split-stack functions. But if partitioning
923 was turned on explicitly just hope for the best. */
924 if (opts->x_flag_split_stack
925 && opts->x_flag_reorder_blocks_and_partition
926 && !opts_set->x_flag_reorder_blocks_and_partition)
927 opts->x_flag_reorder_blocks_and_partition = 0;
928
929 if (opts->x_flag_reorder_blocks_and_partition
930 && !opts_set->x_flag_reorder_functions)
931 opts->x_flag_reorder_functions = 1;
932
933 /* Tune vectorization related parametees according to cost model. */
934 if (opts->x_flag_vect_cost_model == VECT_COST_MODEL_CHEAP)
935 {
936 maybe_set_param_value (PARAM_VECT_MAX_VERSION_FOR_ALIAS_CHECKS,
937 6, opts->x_param_values, opts_set->x_param_values);
938 maybe_set_param_value (PARAM_VECT_MAX_VERSION_FOR_ALIGNMENT_CHECKS,
939 0, opts->x_param_values, opts_set->x_param_values);
940 maybe_set_param_value (PARAM_VECT_MAX_PEELING_FOR_ALIGNMENT,
941 0, opts->x_param_values, opts_set->x_param_values);
942 }
943
944 /* Set PARAM_MAX_STORES_TO_SINK to 0 if either vectorization or if-conversion
945 is disabled. */
946 if ((!opts->x_flag_tree_loop_vectorize && !opts->x_flag_tree_slp_vectorize)
947 || !opts->x_flag_tree_loop_if_convert)
948 maybe_set_param_value (PARAM_MAX_STORES_TO_SINK, 0,
949 opts->x_param_values, opts_set->x_param_values);
950
951 /* The -gsplit-dwarf option requires -ggnu-pubnames. */
952 if (opts->x_dwarf_split_debug_info)
953 opts->x_debug_generate_pub_sections = 2;
954
955 /* Userspace and kernel ASan conflict with each other. */
956 if ((opts->x_flag_sanitize & SANITIZE_USER_ADDRESS)
957 && (opts->x_flag_sanitize & SANITIZE_KERNEL_ADDRESS))
958 error_at (loc,
959 "%<-fsanitize=address%> is incompatible with "
960 "%<-fsanitize=kernel-address%>");
961
962 /* And with TSan. */
963 if ((opts->x_flag_sanitize & SANITIZE_ADDRESS)
964 && (opts->x_flag_sanitize & SANITIZE_THREAD))
965 error_at (loc,
966 "%<-fsanitize=address%> and %<-fsanitize=kernel-address%> "
967 "are incompatible with %<-fsanitize=thread%>");
968
969 if ((opts->x_flag_sanitize & SANITIZE_LEAK)
970 && (opts->x_flag_sanitize & SANITIZE_THREAD))
971 error_at (loc,
972 "%<-fsanitize=leak%> is incompatible with %<-fsanitize=thread%>");
973
974 /* Check error recovery for -fsanitize-recover option. */
975 for (int i = 0; sanitizer_opts[i].name != NULL; ++i)
976 if ((opts->x_flag_sanitize_recover & sanitizer_opts[i].flag)
977 && !sanitizer_opts[i].can_recover)
978 error_at (loc, "%<-fsanitize-recover=%s%> is not supported",
979 sanitizer_opts[i].name);
980
981 /* When instrumenting the pointers, we don't want to remove
982 the null pointer checks. */
983 if (opts->x_flag_sanitize & (SANITIZE_NULL | SANITIZE_NONNULL_ATTRIBUTE
984 | SANITIZE_RETURNS_NONNULL_ATTRIBUTE))
985 opts->x_flag_delete_null_pointer_checks = 0;
986
987 /* Aggressive compiler optimizations may cause false negatives. */
988 if (opts->x_flag_sanitize & ~(SANITIZE_LEAK | SANITIZE_UNREACHABLE))
989 opts->x_flag_aggressive_loop_optimizations = 0;
990
991 /* Enable -fsanitize-address-use-after-scope if address sanitizer is
992 enabled. */
993 if ((opts->x_flag_sanitize & SANITIZE_USER_ADDRESS)
994 && !opts_set->x_flag_sanitize_address_use_after_scope)
995 opts->x_flag_sanitize_address_use_after_scope = true;
996
997 /* Force -fstack-reuse=none in case -fsanitize-address-use-after-scope
998 is enabled. */
999 if (opts->x_flag_sanitize_address_use_after_scope)
1000 {
1001 if (opts->x_flag_stack_reuse != SR_NONE
1002 && opts_set->x_flag_stack_reuse != SR_NONE)
1003 error_at (loc,
1004 "%<-fsanitize-address-use-after-scope%> requires "
1005 "%<-fstack-reuse=none%> option");
1006
1007 opts->x_flag_stack_reuse = SR_NONE;
1008 }
1009
1010 if ((opts->x_flag_sanitize & SANITIZE_USER_ADDRESS) && opts->x_flag_tm)
1011 sorry ("transactional memory is not supported with %<-fsanitize=address%>");
1012
1013 if ((opts->x_flag_sanitize & SANITIZE_KERNEL_ADDRESS) && opts->x_flag_tm)
1014 sorry ("transactional memory is not supported with "
1015 "%<-fsanitize=kernel-address%>");
826 } 1016 }
827 1017
828 #define LEFT_COLUMN 27 1018 #define LEFT_COLUMN 27
829 1019
830 /* Output ITEM, of length ITEM_WIDTH, in the left column, 1020 /* Output ITEM, of length ITEM_WIDTH, in the left column,
862 && i > 0 && ISALPHA (help[i - 1])) 1052 && i > 0 && ISALPHA (help[i - 1]))
863 len = i + 1; 1053 len = i + 1;
864 } 1054 }
865 } 1055 }
866 1056
867 printf( " %-*.*s %.*s\n", col_width, item_width, item, len, help); 1057 printf (" %-*.*s %.*s\n", col_width, item_width, item, len, help);
868 item_width = 0; 1058 item_width = 0;
869 while (help[len] == ' ') 1059 while (help[len] == ' ')
870 len++; 1060 len++;
871 help += len; 1061 help += len;
872 remaining -= len; 1062 remaining -= len;
885 { 1075 {
886 unsigned int i; 1076 unsigned int i;
887 const char *help; 1077 const char *help;
888 bool found = false; 1078 bool found = false;
889 bool displayed = false; 1079 bool displayed = false;
1080 char new_help[256];
890 1081
891 if (include_flags == CL_PARAMS) 1082 if (include_flags == CL_PARAMS)
892 { 1083 {
893 for (i = 0; i < LAST_PARAM; i++) 1084 for (i = 0; i < LAST_PARAM; i++)
894 { 1085 {
903 } 1094 }
904 1095
905 /* Get the translation. */ 1096 /* Get the translation. */
906 help = _(help); 1097 help = _(help);
907 1098
1099 if (!opts->x_quiet_flag)
1100 {
1101 snprintf (new_help, sizeof (new_help),
1102 _("default %d minimum %d maximum %d"),
1103 compiler_params[i].default_value,
1104 compiler_params[i].min_value,
1105 compiler_params[i].max_value);
1106 help = new_help;
1107 }
908 wrap_help (help, param, strlen (param), columns); 1108 wrap_help (help, param, strlen (param), columns);
909 } 1109 }
910 putchar ('\n'); 1110 putchar ('\n');
911 return; 1111 return;
912 } 1112 }
917 if (!opts->x_help_enum_printed) 1117 if (!opts->x_help_enum_printed)
918 opts->x_help_enum_printed = XCNEWVAR (char, cl_enums_count); 1118 opts->x_help_enum_printed = XCNEWVAR (char, cl_enums_count);
919 1119
920 for (i = 0; i < cl_options_count; i++) 1120 for (i = 0; i < cl_options_count; i++)
921 { 1121 {
922 char new_help[128];
923 const struct cl_option *option = cl_options + i; 1122 const struct cl_option *option = cl_options + i;
924 unsigned int len; 1123 unsigned int len;
925 const char *opt; 1124 const char *opt;
926 const char *tab; 1125 const char *tab;
927 1126
952 help = option->help; 1151 help = option->help;
953 if (help == NULL) 1152 if (help == NULL)
954 { 1153 {
955 if (exclude_flags & CL_UNDOCUMENTED) 1154 if (exclude_flags & CL_UNDOCUMENTED)
956 continue; 1155 continue;
1156
957 help = undocumented_msg; 1157 help = undocumented_msg;
1158 }
1159
1160 if (option->alias_target < N_OPTS
1161 && cl_options [option->alias_target].help)
1162 {
1163 if (help == undocumented_msg)
1164 {
1165 /* For undocumented options that are aliases for other options
1166 that are documented, point the reader to the other option in
1167 preference of the former. */
1168 snprintf (new_help, sizeof new_help,
1169 _("Same as %s. Use the latter option instead."),
1170 cl_options [option->alias_target].opt_text);
1171 }
1172 else
1173 {
1174 /* For documented options with aliases, mention the aliased
1175 option's name for reference. */
1176 snprintf (new_help, sizeof new_help,
1177 _("%s Same as %s."),
1178 help, cl_options [option->alias_target].opt_text);
1179 }
1180
1181 help = new_help;
1182 }
1183
1184 if (option->warn_message)
1185 {
1186 /* Mention that the use of the option will trigger a warning. */
1187 if (help == new_help)
1188 snprintf (new_help + strlen (new_help),
1189 sizeof new_help - strlen (new_help),
1190 " %s", _(use_diagnosed_msg));
1191 else
1192 snprintf (new_help, sizeof new_help,
1193 "%s %s", help, _(use_diagnosed_msg));
1194
1195 help = new_help;
958 } 1196 }
959 1197
960 /* Get the translation. */ 1198 /* Get the translation. */
961 help = _(help); 1199 help = _(help);
962 1200
975 len = strlen (opt); 1213 len = strlen (opt);
976 } 1214 }
977 1215
978 /* With the -Q option enabled we change the descriptive text associated 1216 /* With the -Q option enabled we change the descriptive text associated
979 with an option to be an indication of its current setting. */ 1217 with an option to be an indication of its current setting. */
980 if (!quiet_flag) 1218 if (!opts->x_quiet_flag)
981 { 1219 {
982 void *flag_var = option_flag_var (i, opts); 1220 void *flag_var = option_flag_var (i, opts);
983 1221
984 if (len < (LEFT_COLUMN + 2)) 1222 if (len < (LEFT_COLUMN + 2))
985 strcpy (new_help, "\t\t"); 1223 strcpy (new_help, "\t\t");
994 if (option->var_type == CLVC_STRING) 1232 if (option->var_type == CLVC_STRING)
995 { 1233 {
996 if (* (const char **) flag_var != NULL) 1234 if (* (const char **) flag_var != NULL)
997 snprintf (new_help + strlen (new_help), 1235 snprintf (new_help + strlen (new_help),
998 sizeof (new_help) - strlen (new_help), 1236 sizeof (new_help) - strlen (new_help),
999 * (const char **) flag_var); 1237 "%s", * (const char **) flag_var);
1000 } 1238 }
1001 else if (option->var_type == CLVC_ENUM) 1239 else if (option->var_type == CLVC_ENUM)
1002 { 1240 {
1003 const struct cl_enum *e = &cl_enums[option->var_enum]; 1241 const struct cl_enum *e = &cl_enums[option->var_enum];
1004 int value; 1242 int value;
1008 enum_value_to_arg (e->values, &arg, value, lang_mask); 1246 enum_value_to_arg (e->values, &arg, value, lang_mask);
1009 if (arg == NULL) 1247 if (arg == NULL)
1010 arg = _("[default]"); 1248 arg = _("[default]");
1011 snprintf (new_help + strlen (new_help), 1249 snprintf (new_help + strlen (new_help),
1012 sizeof (new_help) - strlen (new_help), 1250 sizeof (new_help) - strlen (new_help),
1013 arg); 1251 "%s", arg);
1014 } 1252 }
1015 else 1253 else
1016 sprintf (new_help + strlen (new_help), 1254 sprintf (new_help + strlen (new_help),
1017 "%#x", * (int *) flag_var); 1255 "%d", * (int *) flag_var);
1018 } 1256 }
1019 else 1257 else
1020 strcat (new_help, option_enabled (i, opts) 1258 strcat (new_help, option_enabled (i, opts)
1021 ? _("[enabled]") : _("[disabled]")); 1259 ? _("[enabled]") : _("[disabled]"));
1022 } 1260 }
1023 1261
1024 help = new_help; 1262 help = new_help;
1025 } 1263 }
1026 1264
1265 if (option->range_max != -1)
1266 {
1267 char b[128];
1268 snprintf (b, sizeof (b), "<%d,%d>", option->range_min,
1269 option->range_max);
1270 opt = concat (opt, b, NULL);
1271 len += strlen (b);
1272 }
1273
1027 wrap_help (help, opt, len, columns); 1274 wrap_help (help, opt, len, columns);
1028 displayed = true; 1275 displayed = true;
1029 1276
1030 if (option->var_type == CLVC_ENUM 1277 if (option->var_type == CLVC_ENUM
1031 && opts->x_help_enum_printed[option->var_enum] != 2) 1278 && opts->x_help_enum_printed[option->var_enum] != 2)
1044 1291
1045 /* PR 31349: Tell the user how to see all of the 1292 /* PR 31349: Tell the user how to see all of the
1046 options supported by a specific front end. */ 1293 options supported by a specific front end. */
1047 for (i = 0; (1U << i) < CL_LANG_ALL; i ++) 1294 for (i = 0; (1U << i) < CL_LANG_ALL; i ++)
1048 if ((1U << i) & langs) 1295 if ((1U << i) & langs)
1049 printf (_(" None found. Use --help=%s to show *all* the options supported by the %s front-end\n"), 1296 printf (_(" None found. Use --help=%s to show *all* the options supported by the %s front-end.\n"),
1050 lang_names[i], lang_names[i]); 1297 lang_names[i], lang_names[i]);
1051 } 1298 }
1052 1299
1053 } 1300 }
1054 else if (! displayed) 1301 else if (! displayed)
1113 size_t i; 1360 size_t i;
1114 unsigned int flag; 1361 unsigned int flag;
1115 1362
1116 /* Sanity check: Make sure that we do not have more 1363 /* Sanity check: Make sure that we do not have more
1117 languages than we have bits available to enumerate them. */ 1364 languages than we have bits available to enumerate them. */
1118 gcc_assert ((1U << cl_lang_count) < CL_MIN_OPTION_CLASS); 1365 gcc_assert ((1U << cl_lang_count) <= CL_MIN_OPTION_CLASS);
1119 1366
1120 /* If we have not done so already, obtain 1367 /* If we have not done so already, obtain
1121 the desired maximum width of the output. */ 1368 the desired maximum width of the output. */
1122 if (opts->x_help_columns == 0) 1369 if (opts->x_help_columns == 0)
1123 { 1370 {
1124 const char *p; 1371 opts->x_help_columns = get_terminal_width ();
1125 1372 if (opts->x_help_columns == INT_MAX)
1126 p = getenv ("COLUMNS");
1127 if (p != NULL)
1128 {
1129 int value = atoi (p);
1130
1131 if (value > 0)
1132 opts->x_help_columns = value;
1133 }
1134
1135 if (opts->x_help_columns == 0)
1136 /* Use a reasonable default. */ 1373 /* Use a reasonable default. */
1137 opts->x_help_columns = 80; 1374 opts->x_help_columns = 80;
1138 } 1375 }
1139 1376
1140 /* Decide upon the title for the options that we are going to display. */ 1377 /* Decide upon the title for the options that we are going to display. */
1202 printf ("%s%s:\n", description, descrip_extra); 1439 printf ("%s%s:\n", description, descrip_extra);
1203 print_filtered_help (include_flags, exclude_flags, any_flags, 1440 print_filtered_help (include_flags, exclude_flags, any_flags,
1204 opts->x_help_columns, opts, lang_mask); 1441 opts->x_help_columns, opts, lang_mask);
1205 } 1442 }
1206 1443
1444 /* Enable FDO-related flags. */
1445
1446 static void
1447 enable_fdo_optimizations (struct gcc_options *opts,
1448 struct gcc_options *opts_set,
1449 int value)
1450 {
1451 if (!opts_set->x_flag_branch_probabilities)
1452 opts->x_flag_branch_probabilities = value;
1453 if (!opts_set->x_flag_profile_values)
1454 opts->x_flag_profile_values = value;
1455 if (!opts_set->x_flag_unroll_loops)
1456 opts->x_flag_unroll_loops = value;
1457 if (!opts_set->x_flag_peel_loops)
1458 opts->x_flag_peel_loops = value;
1459 if (!opts_set->x_flag_tracer)
1460 opts->x_flag_tracer = value;
1461 if (!opts_set->x_flag_value_profile_transformations)
1462 opts->x_flag_value_profile_transformations = value;
1463 if (!opts_set->x_flag_inline_functions)
1464 opts->x_flag_inline_functions = value;
1465 if (!opts_set->x_flag_ipa_cp)
1466 opts->x_flag_ipa_cp = value;
1467 if (!opts_set->x_flag_ipa_cp_clone
1468 && value && opts->x_flag_ipa_cp)
1469 opts->x_flag_ipa_cp_clone = value;
1470 if (!opts_set->x_flag_ipa_bit_cp
1471 && value && opts->x_flag_ipa_cp)
1472 opts->x_flag_ipa_bit_cp = value;
1473 if (!opts_set->x_flag_predictive_commoning)
1474 opts->x_flag_predictive_commoning = value;
1475 if (!opts_set->x_flag_split_loops)
1476 opts->x_flag_split_loops = value;
1477 if (!opts_set->x_flag_unswitch_loops)
1478 opts->x_flag_unswitch_loops = value;
1479 if (!opts_set->x_flag_gcse_after_reload)
1480 opts->x_flag_gcse_after_reload = value;
1481 if (!opts_set->x_flag_tree_loop_vectorize)
1482 opts->x_flag_tree_loop_vectorize = value;
1483 if (!opts_set->x_flag_tree_slp_vectorize)
1484 opts->x_flag_tree_slp_vectorize = value;
1485 if (!opts_set->x_flag_vect_cost_model)
1486 opts->x_flag_vect_cost_model = VECT_COST_MODEL_DYNAMIC;
1487 if (!opts_set->x_flag_tree_loop_distribute_patterns)
1488 opts->x_flag_tree_loop_distribute_patterns = value;
1489 }
1490
1491 /* -f{,no-}sanitize{,-recover}= suboptions. */
1492 const struct sanitizer_opts_s sanitizer_opts[] =
1493 {
1494 #define SANITIZER_OPT(name, flags, recover) \
1495 { #name, flags, sizeof #name - 1, recover }
1496 SANITIZER_OPT (address, (SANITIZE_ADDRESS | SANITIZE_USER_ADDRESS), true),
1497 SANITIZER_OPT (kernel-address, (SANITIZE_ADDRESS | SANITIZE_KERNEL_ADDRESS),
1498 true),
1499 SANITIZER_OPT (thread, SANITIZE_THREAD, false),
1500 SANITIZER_OPT (leak, SANITIZE_LEAK, false),
1501 SANITIZER_OPT (shift, SANITIZE_SHIFT, true),
1502 SANITIZER_OPT (shift-base, SANITIZE_SHIFT_BASE, true),
1503 SANITIZER_OPT (shift-exponent, SANITIZE_SHIFT_EXPONENT, true),
1504 SANITIZER_OPT (integer-divide-by-zero, SANITIZE_DIVIDE, true),
1505 SANITIZER_OPT (undefined, SANITIZE_UNDEFINED, true),
1506 SANITIZER_OPT (unreachable, SANITIZE_UNREACHABLE, false),
1507 SANITIZER_OPT (vla-bound, SANITIZE_VLA, true),
1508 SANITIZER_OPT (return, SANITIZE_RETURN, false),
1509 SANITIZER_OPT (null, SANITIZE_NULL, true),
1510 SANITIZER_OPT (signed-integer-overflow, SANITIZE_SI_OVERFLOW, true),
1511 SANITIZER_OPT (bool, SANITIZE_BOOL, true),
1512 SANITIZER_OPT (enum, SANITIZE_ENUM, true),
1513 SANITIZER_OPT (float-divide-by-zero, SANITIZE_FLOAT_DIVIDE, true),
1514 SANITIZER_OPT (float-cast-overflow, SANITIZE_FLOAT_CAST, true),
1515 SANITIZER_OPT (bounds, SANITIZE_BOUNDS, true),
1516 SANITIZER_OPT (bounds-strict, SANITIZE_BOUNDS | SANITIZE_BOUNDS_STRICT, true),
1517 SANITIZER_OPT (alignment, SANITIZE_ALIGNMENT, true),
1518 SANITIZER_OPT (nonnull-attribute, SANITIZE_NONNULL_ATTRIBUTE, true),
1519 SANITIZER_OPT (returns-nonnull-attribute, SANITIZE_RETURNS_NONNULL_ATTRIBUTE,
1520 true),
1521 SANITIZER_OPT (object-size, SANITIZE_OBJECT_SIZE, true),
1522 SANITIZER_OPT (vptr, SANITIZE_VPTR, true),
1523 SANITIZER_OPT (pointer-overflow, SANITIZE_POINTER_OVERFLOW, true),
1524 SANITIZER_OPT (builtin, SANITIZE_BUILTIN, true),
1525 SANITIZER_OPT (all, ~0U, true),
1526 #undef SANITIZER_OPT
1527 { NULL, 0U, 0UL, false }
1528 };
1529
1530 /* -f{,no-}sanitize-coverage= suboptions. */
1531 const struct sanitizer_opts_s coverage_sanitizer_opts[] =
1532 {
1533 #define COVERAGE_SANITIZER_OPT(name, flags) \
1534 { #name, flags, sizeof #name - 1, true }
1535 COVERAGE_SANITIZER_OPT (trace-pc, SANITIZE_COV_TRACE_PC),
1536 COVERAGE_SANITIZER_OPT (trace-cmp, SANITIZE_COV_TRACE_CMP),
1537 #undef COVERAGE_SANITIZER_OPT
1538 { NULL, 0U, 0UL, false }
1539 };
1540
1541 /* A struct for describing a run of chars within a string. */
1542
1543 struct string_fragment
1544 {
1545 string_fragment (const char *start, size_t len)
1546 : m_start (start), m_len (len) {}
1547
1548 const char *m_start;
1549 size_t m_len;
1550 };
1551
1552 /* Specialization of edit_distance_traits for string_fragment,
1553 for use by get_closest_sanitizer_option. */
1554
1555 template <>
1556 struct edit_distance_traits<const string_fragment &>
1557 {
1558 static size_t get_length (const string_fragment &fragment)
1559 {
1560 return fragment.m_len;
1561 }
1562
1563 static const char *get_string (const string_fragment &fragment)
1564 {
1565 return fragment.m_start;
1566 }
1567 };
1568
1569 /* Given ARG, an unrecognized sanitizer option, return the best
1570 matching sanitizer option, or NULL if there isn't one.
1571 OPTS is array of candidate sanitizer options.
1572 CODE is OPT_fsanitize_, OPT_fsanitize_recover_ or
1573 OPT_fsanitize_coverage_.
1574 VALUE is non-zero for the regular form of the option, zero
1575 for the "no-" form (e.g. "-fno-sanitize-recover="). */
1576
1577 static const char *
1578 get_closest_sanitizer_option (const string_fragment &arg,
1579 const struct sanitizer_opts_s *opts,
1580 enum opt_code code, int value)
1581 {
1582 best_match <const string_fragment &, const char*> bm (arg);
1583 for (int i = 0; opts[i].name != NULL; ++i)
1584 {
1585 /* -fsanitize=all is not valid, so don't offer it. */
1586 if (code == OPT_fsanitize_
1587 && opts[i].flag == ~0U
1588 && value)
1589 continue;
1590
1591 /* For -fsanitize-recover= (and not -fno-sanitize-recover=),
1592 don't offer the non-recoverable options. */
1593 if (code == OPT_fsanitize_recover_
1594 && !opts[i].can_recover
1595 && value)
1596 continue;
1597
1598 bm.consider (opts[i].name);
1599 }
1600 return bm.get_best_meaningful_candidate ();
1601 }
1602
1603 /* Parse comma separated sanitizer suboptions from P for option SCODE,
1604 adjust previous FLAGS and return new ones. If COMPLAIN is false,
1605 don't issue diagnostics. */
1606
1607 unsigned int
1608 parse_sanitizer_options (const char *p, location_t loc, int scode,
1609 unsigned int flags, int value, bool complain)
1610 {
1611 enum opt_code code = (enum opt_code) scode;
1612
1613 const struct sanitizer_opts_s *opts;
1614 if (code == OPT_fsanitize_coverage_)
1615 opts = coverage_sanitizer_opts;
1616 else
1617 opts = sanitizer_opts;
1618
1619 while (*p != 0)
1620 {
1621 size_t len, i;
1622 bool found = false;
1623 const char *comma = strchr (p, ',');
1624
1625 if (comma == NULL)
1626 len = strlen (p);
1627 else
1628 len = comma - p;
1629 if (len == 0)
1630 {
1631 p = comma + 1;
1632 continue;
1633 }
1634
1635 /* Check to see if the string matches an option class name. */
1636 for (i = 0; opts[i].name != NULL; ++i)
1637 if (len == opts[i].len && memcmp (p, opts[i].name, len) == 0)
1638 {
1639 /* Handle both -fsanitize and -fno-sanitize cases. */
1640 if (value && opts[i].flag == ~0U)
1641 {
1642 if (code == OPT_fsanitize_)
1643 {
1644 if (complain)
1645 error_at (loc, "%<-fsanitize=all%> option is not valid");
1646 }
1647 else
1648 flags |= ~(SANITIZE_THREAD | SANITIZE_LEAK
1649 | SANITIZE_UNREACHABLE | SANITIZE_RETURN);
1650 }
1651 else if (value)
1652 {
1653 /* Do not enable -fsanitize-recover=unreachable and
1654 -fsanitize-recover=return if -fsanitize-recover=undefined
1655 is selected. */
1656 if (code == OPT_fsanitize_recover_
1657 && opts[i].flag == SANITIZE_UNDEFINED)
1658 flags |= (SANITIZE_UNDEFINED
1659 & ~(SANITIZE_UNREACHABLE | SANITIZE_RETURN));
1660 else
1661 flags |= opts[i].flag;
1662 }
1663 else
1664 flags &= ~opts[i].flag;
1665 found = true;
1666 break;
1667 }
1668
1669 if (! found && complain)
1670 {
1671 const char *hint
1672 = get_closest_sanitizer_option (string_fragment (p, len),
1673 opts, code, value);
1674
1675 const char *suffix;
1676 if (code == OPT_fsanitize_recover_)
1677 suffix = "-recover";
1678 else if (code == OPT_fsanitize_coverage_)
1679 suffix = "-coverage";
1680 else
1681 suffix = "";
1682
1683 if (hint)
1684 error_at (loc,
1685 "unrecognized argument to -f%ssanitize%s= option: %q.*s;"
1686 " did you mean %qs?",
1687 value ? "" : "no-",
1688 suffix, (int) len, p, hint);
1689 else
1690 error_at (loc,
1691 "unrecognized argument to -f%ssanitize%s= option: %q.*s",
1692 value ? "" : "no-",
1693 suffix, (int) len, p);
1694 }
1695
1696 if (comma == NULL)
1697 break;
1698 p = comma + 1;
1699 }
1700 return flags;
1701 }
1702
1703 /* Parse string values of no_sanitize attribute passed in VALUE.
1704 Values are separated with comma. */
1705
1706 unsigned int
1707 parse_no_sanitize_attribute (char *value)
1708 {
1709 unsigned int flags = 0;
1710 unsigned int i;
1711 char *q = strtok (value, ",");
1712
1713 while (q != NULL)
1714 {
1715 for (i = 0; sanitizer_opts[i].name != NULL; ++i)
1716 if (strcmp (sanitizer_opts[i].name, q) == 0)
1717 {
1718 flags |= sanitizer_opts[i].flag;
1719 if (sanitizer_opts[i].flag == SANITIZE_UNDEFINED)
1720 flags |= SANITIZE_UNDEFINED_NONDEFAULT;
1721 break;
1722 }
1723
1724 if (sanitizer_opts[i].name == NULL)
1725 warning (OPT_Wattributes,
1726 "%<%s%> attribute directive ignored", q);
1727
1728 q = strtok (NULL, ",");
1729 }
1730
1731 return flags;
1732 }
1733
1207 /* Handle target- and language-independent options. Return zero to 1734 /* Handle target- and language-independent options. Return zero to
1208 generate an "unknown option" message. Only options that need 1735 generate an "unknown option" message. Only options that need
1209 extra handling need to be listed here; if you simply want 1736 extra handling need to be listed here; if you simply want
1210 DECODED->value assigned to a variable, it happens automatically. */ 1737 DECODED->value assigned to a variable, it happens automatically. */
1211 1738
1214 struct gcc_options *opts_set, 1741 struct gcc_options *opts_set,
1215 const struct cl_decoded_option *decoded, 1742 const struct cl_decoded_option *decoded,
1216 unsigned int lang_mask, int kind ATTRIBUTE_UNUSED, 1743 unsigned int lang_mask, int kind ATTRIBUTE_UNUSED,
1217 location_t loc, 1744 location_t loc,
1218 const struct cl_option_handlers *handlers, 1745 const struct cl_option_handlers *handlers,
1219 diagnostic_context *dc) 1746 diagnostic_context *dc,
1747 void (*target_option_override_hook) (void))
1220 { 1748 {
1221 size_t scode = decoded->opt_index; 1749 size_t scode = decoded->opt_index;
1222 const char *arg = decoded->arg; 1750 const char *arg = decoded->arg;
1223 int value = decoded->value; 1751 int value = decoded->value;
1224 enum opt_code code = (enum opt_code) scode; 1752 enum opt_code code = (enum opt_code) scode;
1235 { 1763 {
1236 unsigned int all_langs_mask = (1U << cl_lang_count) - 1; 1764 unsigned int all_langs_mask = (1U << cl_lang_count) - 1;
1237 unsigned int undoc_mask; 1765 unsigned int undoc_mask;
1238 unsigned int i; 1766 unsigned int i;
1239 1767
1768 if (lang_mask == CL_DRIVER)
1769 break;
1770
1240 undoc_mask = ((opts->x_verbose_flag | opts->x_extra_warnings) 1771 undoc_mask = ((opts->x_verbose_flag | opts->x_extra_warnings)
1241 ? 0 1772 ? 0
1242 : CL_UNDOCUMENTED); 1773 : CL_UNDOCUMENTED);
1774 target_option_override_hook ();
1243 /* First display any single language specific options. */ 1775 /* First display any single language specific options. */
1244 for (i = 0; i < cl_lang_count; i++) 1776 for (i = 0; i < cl_lang_count; i++)
1245 print_specific_help 1777 print_specific_help
1246 (1U << i, (all_langs_mask & (~ (1U << i))) | undoc_mask, 0, opts, 1778 (1U << i, (all_langs_mask & (~ (1U << i))) | undoc_mask, 0, opts,
1247 lang_mask); 1779 lang_mask);
1254 opts->x_exit_after_options = true; 1786 opts->x_exit_after_options = true;
1255 break; 1787 break;
1256 } 1788 }
1257 1789
1258 case OPT__target_help: 1790 case OPT__target_help:
1791 if (lang_mask == CL_DRIVER)
1792 break;
1793
1794 target_option_override_hook ();
1259 print_specific_help (CL_TARGET, CL_UNDOCUMENTED, 0, opts, lang_mask); 1795 print_specific_help (CL_TARGET, CL_UNDOCUMENTED, 0, opts, lang_mask);
1260 opts->x_exit_after_options = true; 1796 opts->x_exit_after_options = true;
1261
1262 /* Allow the target a chance to give the user some additional information. */
1263 if (targetm.help)
1264 targetm.help ();
1265 break; 1797 break;
1266 1798
1267 case OPT__help_: 1799 case OPT__help_:
1268 { 1800 {
1269 const char * a = arg; 1801 const char *a = arg;
1270 unsigned int include_flags = 0; 1802 unsigned int include_flags = 0;
1271 /* Note - by default we include undocumented options when listing 1803 /* Note - by default we include undocumented options when listing
1272 specific classes. If you only want to see documented options 1804 specific classes. If you only want to see documented options
1273 then add ",^undocumented" to the --help= option. E.g.: 1805 then add ",^undocumented" to the --help= option. E.g.:
1274 1806
1275 --help=target,^undocumented */ 1807 --help=target,^undocumented */
1276 unsigned int exclude_flags = 0; 1808 unsigned int exclude_flags = 0;
1809
1810 if (lang_mask == CL_DRIVER)
1811 break;
1277 1812
1278 /* Walk along the argument string, parsing each word in turn. 1813 /* Walk along the argument string, parsing each word in turn.
1279 The format is: 1814 The format is:
1280 arg = [^]{word}[,{arg}] 1815 arg = [^]{word}[,{arg}]
1281 word = {optimizers|target|warnings|undocumented| 1816 word = {optimizers|target|warnings|undocumented|
1282 params|common|<language>} */ 1817 params|common|<language>} */
1283 while (* a != 0) 1818 while (*a != 0)
1284 { 1819 {
1285 static const struct 1820 static const struct
1286 { 1821 {
1287 const char * string; 1822 const char *string;
1288 unsigned int flag; 1823 unsigned int flag;
1289 } 1824 }
1290 specifics[] = 1825 specifics[] =
1291 { 1826 {
1292 { "optimizers", CL_OPTIMIZATION }, 1827 { "optimizers", CL_OPTIMIZATION },
1297 { "joined", CL_JOINED }, 1832 { "joined", CL_JOINED },
1298 { "separate", CL_SEPARATE }, 1833 { "separate", CL_SEPARATE },
1299 { "common", CL_COMMON }, 1834 { "common", CL_COMMON },
1300 { NULL, 0 } 1835 { NULL, 0 }
1301 }; 1836 };
1302 unsigned int * pflags; 1837 unsigned int *pflags;
1303 const char * comma; 1838 const char *comma;
1304 unsigned int lang_flag, specific_flag; 1839 unsigned int lang_flag, specific_flag;
1305 unsigned int len; 1840 unsigned int len;
1306 unsigned int i; 1841 unsigned int i;
1307 1842
1308 if (* a == '^') 1843 if (*a == '^')
1309 { 1844 {
1310 ++ a; 1845 ++a;
1311 pflags = & exclude_flags; 1846 if (*a == '\0')
1847 {
1848 error_at (loc, "missing argument to %qs", "--help=^");
1849 break;
1850 }
1851 pflags = &exclude_flags;
1312 } 1852 }
1313 else 1853 else
1314 pflags = & include_flags; 1854 pflags = &include_flags;
1315 1855
1316 comma = strchr (a, ','); 1856 comma = strchr (a, ',');
1317 if (comma == NULL) 1857 if (comma == NULL)
1318 len = strlen (a); 1858 len = strlen (a);
1319 else 1859 else
1346 } 1886 }
1347 1887
1348 if (specific_flag != 0) 1888 if (specific_flag != 0)
1349 { 1889 {
1350 if (lang_flag == 0) 1890 if (lang_flag == 0)
1351 * pflags |= specific_flag; 1891 *pflags |= specific_flag;
1352 else 1892 else
1353 { 1893 {
1354 /* The option's argument matches both the start of a 1894 /* The option's argument matches both the start of a
1355 language name and the start of an option class name. 1895 language name and the start of an option class name.
1356 We have a special case for when the user has 1896 We have a special case for when the user has
1357 specified "--help=c", but otherwise we have to issue 1897 specified "--help=c", but otherwise we have to issue
1358 a warning. */ 1898 a warning. */
1359 if (strncasecmp (a, "c", len) == 0) 1899 if (strncasecmp (a, "c", len) == 0)
1360 * pflags |= lang_flag; 1900 *pflags |= lang_flag;
1361 else 1901 else
1362 warning_at (loc, 0, 1902 warning_at (loc, 0,
1363 "--help argument %q.*s is ambiguous, " 1903 "--help argument %q.*s is ambiguous, "
1364 "please be more specific", 1904 "please be more specific",
1365 len, a); 1905 len, a);
1366 } 1906 }
1367 } 1907 }
1368 else if (lang_flag != 0) 1908 else if (lang_flag != 0)
1369 * pflags |= lang_flag; 1909 *pflags |= lang_flag;
1370 else 1910 else
1371 warning_at (loc, 0, 1911 warning_at (loc, 0,
1372 "unrecognized argument to --help= option: %q.*s", 1912 "unrecognized argument to --help= option: %q.*s",
1373 len, a); 1913 len, a);
1374 1914
1376 break; 1916 break;
1377 a = comma + 1; 1917 a = comma + 1;
1378 } 1918 }
1379 1919
1380 if (include_flags) 1920 if (include_flags)
1381 print_specific_help (include_flags, exclude_flags, 0, opts, 1921 {
1382 lang_mask); 1922 target_option_override_hook ();
1923 print_specific_help (include_flags, exclude_flags, 0, opts,
1924 lang_mask);
1925 }
1383 opts->x_exit_after_options = true; 1926 opts->x_exit_after_options = true;
1384 break; 1927 break;
1385 } 1928 }
1386 1929
1387 case OPT__version: 1930 case OPT__version:
1931 if (lang_mask == CL_DRIVER)
1932 break;
1933
1388 opts->x_exit_after_options = true; 1934 opts->x_exit_after_options = true;
1935 break;
1936
1937 case OPT_fsanitize_:
1938 opts->x_flag_sanitize
1939 = parse_sanitizer_options (arg, loc, code,
1940 opts->x_flag_sanitize, value, true);
1941
1942 /* Kernel ASan implies normal ASan but does not yet support
1943 all features. */
1944 if (opts->x_flag_sanitize & SANITIZE_KERNEL_ADDRESS)
1945 {
1946 maybe_set_param_value (PARAM_ASAN_INSTRUMENTATION_WITH_CALL_THRESHOLD,
1947 0, opts->x_param_values,
1948 opts_set->x_param_values);
1949 maybe_set_param_value (PARAM_ASAN_GLOBALS, 0, opts->x_param_values,
1950 opts_set->x_param_values);
1951 maybe_set_param_value (PARAM_ASAN_STACK, 0, opts->x_param_values,
1952 opts_set->x_param_values);
1953 maybe_set_param_value (PARAM_ASAN_PROTECT_ALLOCAS, 0,
1954 opts->x_param_values,
1955 opts_set->x_param_values);
1956 maybe_set_param_value (PARAM_ASAN_USE_AFTER_RETURN, 0,
1957 opts->x_param_values,
1958 opts_set->x_param_values);
1959 }
1960 break;
1961
1962 case OPT_fsanitize_recover_:
1963 opts->x_flag_sanitize_recover
1964 = parse_sanitizer_options (arg, loc, code,
1965 opts->x_flag_sanitize_recover, value, true);
1966 break;
1967
1968 case OPT_fasan_shadow_offset_:
1969 /* Deferred. */
1970 break;
1971
1972 case OPT_fsanitize_address_use_after_scope:
1973 opts->x_flag_sanitize_address_use_after_scope = value;
1974 break;
1975
1976 case OPT_fsanitize_recover:
1977 if (value)
1978 opts->x_flag_sanitize_recover
1979 |= (SANITIZE_UNDEFINED | SANITIZE_UNDEFINED_NONDEFAULT)
1980 & ~(SANITIZE_UNREACHABLE | SANITIZE_RETURN);
1981 else
1982 opts->x_flag_sanitize_recover
1983 &= ~(SANITIZE_UNDEFINED | SANITIZE_UNDEFINED_NONDEFAULT);
1984 break;
1985
1986 case OPT_fsanitize_coverage_:
1987 opts->x_flag_sanitize_coverage
1988 = parse_sanitizer_options (arg, loc, code,
1989 opts->x_flag_sanitize_coverage, value, true);
1389 break; 1990 break;
1390 1991
1391 case OPT_O: 1992 case OPT_O:
1392 case OPT_Os: 1993 case OPT_Os:
1393 case OPT_Ofast: 1994 case OPT_Ofast:
1995 case OPT_Og:
1394 /* Currently handled in a prescan. */ 1996 /* Currently handled in a prescan. */
1395 break; 1997 break;
1396 1998
1999 case OPT_Werror:
2000 dc->warning_as_error_requested = value;
2001 break;
2002
1397 case OPT_Werror_: 2003 case OPT_Werror_:
2004 if (lang_mask == CL_DRIVER)
2005 break;
2006
1398 enable_warning_as_error (arg, value, lang_mask, handlers, 2007 enable_warning_as_error (arg, value, lang_mask, handlers,
1399 opts, opts_set, loc, dc); 2008 opts, opts_set, loc, dc);
1400 break; 2009 break;
1401 2010
1402 case OPT_Wlarger_than_: 2011 case OPT_Wlarger_than_:
1409 break; 2018 break;
1410 2019
1411 case OPT_Wframe_larger_than_: 2020 case OPT_Wframe_larger_than_:
1412 opts->x_frame_larger_than_size = value; 2021 opts->x_frame_larger_than_size = value;
1413 opts->x_warn_frame_larger_than = value != -1; 2022 opts->x_warn_frame_larger_than = value != -1;
2023 break;
2024
2025 case OPT_Wstack_usage_:
2026 opts->x_warn_stack_usage = value;
2027 opts->x_flag_stack_usage_info = value != -1;
1414 break; 2028 break;
1415 2029
1416 case OPT_Wstrict_aliasing: 2030 case OPT_Wstrict_aliasing:
1417 set_Wstrict_aliasing (opts, value); 2031 set_Wstrict_aliasing (opts, value);
1418 break; 2032 break;
1435 { 2049 {
1436 char *tmp = xstrdup (arg); 2050 char *tmp = xstrdup (arg);
1437 strip_off_ending (tmp, strlen (tmp)); 2051 strip_off_ending (tmp, strlen (tmp));
1438 if (tmp[0]) 2052 if (tmp[0])
1439 opts->x_aux_base_name = tmp; 2053 opts->x_aux_base_name = tmp;
2054 else
2055 free (tmp);
1440 } 2056 }
1441 break; 2057 break;
1442 2058
1443 case OPT_d: 2059 case OPT_d:
1444 decode_d_option (arg, opts, loc, dc); 2060 decode_d_option (arg, opts, loc, dc);
1448 case OPT_fcall_saved_: 2064 case OPT_fcall_saved_:
1449 /* Deferred. */ 2065 /* Deferred. */
1450 break; 2066 break;
1451 2067
1452 case OPT_fdbg_cnt_: 2068 case OPT_fdbg_cnt_:
2069 /* Deferred. */
2070 break;
2071
1453 case OPT_fdbg_cnt_list: 2072 case OPT_fdbg_cnt_list:
1454 /* Deferred. */ 2073 /* Deferred. */
2074 opts->x_exit_after_options = true;
1455 break; 2075 break;
1456 2076
1457 case OPT_fdebug_prefix_map_: 2077 case OPT_fdebug_prefix_map_:
1458 /* Deferred. */ 2078 /* Deferred. */
1459 break; 2079 break;
1460 2080
1461 case OPT_fdiagnostics_show_location_: 2081 case OPT_fdiagnostics_show_location_:
1462 diagnostic_prefixing_rule (dc) = (diagnostic_prefixing_rule_t) value; 2082 diagnostic_prefixing_rule (dc) = (diagnostic_prefixing_rule_t) value;
2083 break;
2084
2085 case OPT_fdiagnostics_show_caret:
2086 dc->show_caret = value;
2087 break;
2088
2089 case OPT_fdiagnostics_color_:
2090 diagnostic_color_init (dc, value);
2091 break;
2092
2093 case OPT_fdiagnostics_parseable_fixits:
2094 dc->parseable_fixits_p = value;
1463 break; 2095 break;
1464 2096
1465 case OPT_fdiagnostics_show_option: 2097 case OPT_fdiagnostics_show_option:
1466 dc->show_option_requested = value; 2098 dc->show_option_requested = value;
1467 break; 2099 break;
1499 (&opts->x_flag_instrument_functions_exclude_files, arg); 2131 (&opts->x_flag_instrument_functions_exclude_files, arg);
1500 break; 2132 break;
1501 2133
1502 case OPT_fmessage_length_: 2134 case OPT_fmessage_length_:
1503 pp_set_line_maximum_length (dc->printer, value); 2135 pp_set_line_maximum_length (dc->printer, value);
1504 break; 2136 diagnostic_set_caret_max_width (dc, value);
2137 break;
2138
2139 case OPT_fopt_info:
2140 case OPT_fopt_info_:
2141 /* Deferred. */
2142 break;
2143
2144 case OPT_foffload_:
2145 {
2146 const char *p = arg;
2147 opts->x_flag_disable_hsa = true;
2148 while (*p != 0)
2149 {
2150 const char *comma = strchr (p, ',');
2151
2152 if ((strncmp (p, "disable", 7) == 0)
2153 && (p[7] == ',' || p[7] == '\0'))
2154 {
2155 opts->x_flag_disable_hsa = true;
2156 break;
2157 }
2158
2159 if ((strncmp (p, "hsa", 3) == 0)
2160 && (p[3] == ',' || p[3] == '\0'))
2161 {
2162 #ifdef ENABLE_HSA
2163 opts->x_flag_disable_hsa = false;
2164 #else
2165 sorry ("HSA has not been enabled during configuration");
2166 #endif
2167 }
2168 if (!comma)
2169 break;
2170 p = comma + 1;
2171 }
2172 break;
2173 }
2174
2175 #ifndef ACCEL_COMPILER
2176 case OPT_foffload_abi_:
2177 error_at (loc, "%<-foffload-abi%> option can be specified only for "
2178 "offload compiler");
2179 break;
2180 #endif
1505 2181
1506 case OPT_fpack_struct_: 2182 case OPT_fpack_struct_:
1507 if (value <= 0 || (value & (value - 1)) || value > 16) 2183 if (value <= 0 || (value & (value - 1)) || value > 16)
1508 error_at (loc, 2184 error_at (loc,
1509 "structure alignment must be a small power of two, not %d", 2185 "structure alignment must be a small power of two, not %d",
1520 case OPT_fprofile_use_: 2196 case OPT_fprofile_use_:
1521 opts->x_profile_data_prefix = xstrdup (arg); 2197 opts->x_profile_data_prefix = xstrdup (arg);
1522 opts->x_flag_profile_use = true; 2198 opts->x_flag_profile_use = true;
1523 value = true; 2199 value = true;
1524 /* No break here - do -fprofile-use processing. */ 2200 /* No break here - do -fprofile-use processing. */
2201 /* FALLTHRU */
1525 case OPT_fprofile_use: 2202 case OPT_fprofile_use:
1526 if (!opts_set->x_flag_branch_probabilities) 2203 enable_fdo_optimizations (opts, opts_set, value);
1527 opts->x_flag_branch_probabilities = value; 2204 if (!opts_set->x_flag_profile_reorder_functions)
1528 if (!opts_set->x_flag_profile_values) 2205 opts->x_flag_profile_reorder_functions = value;
1529 opts->x_flag_profile_values = value; 2206 /* Indirect call profiling should do all useful transformations
1530 if (!opts_set->x_flag_unroll_loops) 2207 speculative devirtualization does. */
1531 opts->x_flag_unroll_loops = value; 2208 if (!opts_set->x_flag_devirtualize_speculatively
1532 if (!opts_set->x_flag_peel_loops) 2209 && opts->x_flag_value_profile_transformations)
1533 opts->x_flag_peel_loops = value; 2210 opts->x_flag_devirtualize_speculatively = false;
1534 if (!opts_set->x_flag_tracer) 2211 break;
1535 opts->x_flag_tracer = value; 2212
1536 if (!opts_set->x_flag_value_profile_transformations) 2213 case OPT_fauto_profile_:
1537 opts->x_flag_value_profile_transformations = value; 2214 opts->x_auto_profile_file = xstrdup (arg);
1538 if (!opts_set->x_flag_inline_functions) 2215 opts->x_flag_auto_profile = true;
1539 opts->x_flag_inline_functions = value; 2216 value = true;
1540 if (!opts_set->x_flag_ipa_cp) 2217 /* No break here - do -fauto-profile processing. */
1541 opts->x_flag_ipa_cp = value; 2218 /* FALLTHRU */
1542 if (!opts_set->x_flag_ipa_cp_clone 2219 case OPT_fauto_profile:
1543 && value && opts->x_flag_ipa_cp) 2220 enable_fdo_optimizations (opts, opts_set, value);
1544 opts->x_flag_ipa_cp_clone = value; 2221 if (!opts_set->x_flag_profile_correction)
1545 if (!opts_set->x_flag_predictive_commoning) 2222 opts->x_flag_profile_correction = value;
1546 opts->x_flag_predictive_commoning = value; 2223 maybe_set_param_value (
1547 if (!opts_set->x_flag_unswitch_loops) 2224 PARAM_EARLY_INLINER_MAX_ITERATIONS, 10,
1548 opts->x_flag_unswitch_loops = value; 2225 opts->x_param_values, opts_set->x_param_values);
1549 if (!opts_set->x_flag_gcse_after_reload)
1550 opts->x_flag_gcse_after_reload = value;
1551 break; 2226 break;
1552 2227
1553 case OPT_fprofile_generate_: 2228 case OPT_fprofile_generate_:
1554 opts->x_profile_data_prefix = xstrdup (arg); 2229 opts->x_profile_data_prefix = xstrdup (arg);
1555 value = true; 2230 value = true;
1556 /* No break here - do -fprofile-generate processing. */ 2231 /* No break here - do -fprofile-generate processing. */
2232 /* FALLTHRU */
1557 case OPT_fprofile_generate: 2233 case OPT_fprofile_generate:
1558 if (!opts_set->x_profile_arc_flag) 2234 if (!opts_set->x_profile_arc_flag)
1559 opts->x_profile_arc_flag = value; 2235 opts->x_profile_arc_flag = value;
1560 if (!opts_set->x_flag_profile_values) 2236 if (!opts_set->x_flag_profile_values)
1561 opts->x_flag_profile_values = value; 2237 opts->x_flag_profile_values = value;
1562 if (!opts_set->x_flag_value_profile_transformations)
1563 opts->x_flag_value_profile_transformations = value;
1564 if (!opts_set->x_flag_inline_functions) 2238 if (!opts_set->x_flag_inline_functions)
1565 opts->x_flag_inline_functions = value; 2239 opts->x_flag_inline_functions = value;
2240 if (!opts_set->x_flag_ipa_bit_cp)
2241 opts->x_flag_ipa_bit_cp = value;
1566 /* FIXME: Instrumentation we insert makes ipa-reference bitmaps 2242 /* FIXME: Instrumentation we insert makes ipa-reference bitmaps
1567 quadratic. Disable the pass until better memory representation 2243 quadratic. Disable the pass until better memory representation
1568 is done. */ 2244 is done. */
1569 if (!opts_set->x_flag_ipa_reference && in_lto_p) 2245 if (!opts_set->x_flag_ipa_reference)
1570 opts->x_flag_ipa_reference = false; 2246 opts->x_flag_ipa_reference = false;
1571 break; 2247 break;
1572 2248
2249 case OPT_fpatchable_function_entry_:
2250 {
2251 char *patch_area_arg = xstrdup (arg);
2252 char *comma = strchr (patch_area_arg, ',');
2253 if (comma)
2254 {
2255 *comma = '\0';
2256 function_entry_patch_area_size =
2257 integral_argument (patch_area_arg);
2258 function_entry_patch_area_start =
2259 integral_argument (comma + 1);
2260 }
2261 else
2262 {
2263 function_entry_patch_area_size =
2264 integral_argument (patch_area_arg);
2265 function_entry_patch_area_start = 0;
2266 }
2267 if (function_entry_patch_area_size < 0
2268 || function_entry_patch_area_start < 0
2269 || function_entry_patch_area_size
2270 < function_entry_patch_area_start)
2271 error ("invalid arguments for %<-fpatchable_function_entry%>");
2272 free (patch_area_arg);
2273 }
2274 break;
2275
2276 case OPT_ftree_vectorize:
2277 /* Automatically sets -ftree-loop-vectorize and
2278 -ftree-slp-vectorize. Nothing more to do here. */
2279 break;
1573 case OPT_fshow_column: 2280 case OPT_fshow_column:
1574 dc->show_column = value; 2281 dc->show_column = value;
1575 break; 2282 break;
1576 2283
1577 case OPT_frandom_seed: 2284 case OPT_frandom_seed:
1617 ? FULL_BUILTIN_STACK_CHECK 2324 ? FULL_BUILTIN_STACK_CHECK
1618 : STACK_CHECK_STATIC_BUILTIN 2325 : STACK_CHECK_STATIC_BUILTIN
1619 ? STATIC_BUILTIN_STACK_CHECK 2326 ? STATIC_BUILTIN_STACK_CHECK
1620 : GENERIC_STACK_CHECK; 2327 : GENERIC_STACK_CHECK;
1621 else 2328 else
1622 warning_at (loc, 0, "unknown stack check parameter \"%s\"", arg); 2329 warning_at (loc, 0, "unknown stack check parameter %qs", arg);
1623 break; 2330 break;
1624 2331
1625 case OPT_fstack_limit: 2332 case OPT_fstack_limit:
1626 /* The real switch is -fno-stack-limit. */ 2333 /* The real switch is -fno-stack-limit. */
1627 if (value) 2334 if (value)
1632 case OPT_fstack_limit_register_: 2339 case OPT_fstack_limit_register_:
1633 case OPT_fstack_limit_symbol_: 2340 case OPT_fstack_limit_symbol_:
1634 /* Deferred. */ 2341 /* Deferred. */
1635 break; 2342 break;
1636 2343
1637 case OPT_ftree_vectorizer_verbose_: 2344 case OPT_fstack_usage:
1638 vect_set_verbosity_level (opts, value); 2345 opts->x_flag_stack_usage = value;
2346 opts->x_flag_stack_usage_info = value != 0;
1639 break; 2347 break;
1640 2348
1641 case OPT_g: 2349 case OPT_g:
1642 set_debug_level (NO_DEBUG, DEFAULT_GDB_EXTENSIONS, arg, opts, opts_set, 2350 set_debug_level (NO_DEBUG, DEFAULT_GDB_EXTENSIONS, arg, opts, opts_set,
1643 loc); 2351 loc);
1644 break; 2352 break;
1645 2353
1646 case OPT_gcoff: 2354 case OPT_gcoff:
1647 set_debug_level (SDB_DEBUG, false, arg, opts, opts_set, loc); 2355 set_debug_level (SDB_DEBUG, false, arg, opts, opts_set, loc);
1648 break; 2356 break;
1649 2357
2358 case OPT_gdwarf:
2359 if (arg && strlen (arg) != 0)
2360 {
2361 error_at (loc, "%<-gdwarf%s%> is ambiguous; "
2362 "use %<-gdwarf-%s%> for DWARF version "
2363 "or %<-gdwarf -g%s%> for debug level", arg, arg, arg);
2364 break;
2365 }
2366 else
2367 value = opts->x_dwarf_version;
2368
2369 /* FALLTHRU */
1650 case OPT_gdwarf_: 2370 case OPT_gdwarf_:
1651 if (value < 2 || value > 4) 2371 if (value < 2 || value > 5)
1652 error_at (loc, "dwarf version %d is not supported", value); 2372 error_at (loc, "dwarf version %d is not supported", value);
1653 else 2373 else
1654 dwarf_version = value; 2374 opts->x_dwarf_version = value;
1655 set_debug_level (DWARF2_DEBUG, false, "", opts, opts_set, loc); 2375 set_debug_level (DWARF2_DEBUG, false, "", opts, opts_set, loc);
2376 break;
2377
2378 case OPT_gsplit_dwarf:
2379 set_debug_level (NO_DEBUG, DEFAULT_GDB_EXTENSIONS, "", opts, opts_set,
2380 loc);
1656 break; 2381 break;
1657 2382
1658 case OPT_ggdb: 2383 case OPT_ggdb:
1659 set_debug_level (NO_DEBUG, 2, arg, opts, opts_set, loc); 2384 set_debug_level (NO_DEBUG, 2, arg, opts, opts_set, loc);
1660 break; 2385 break;
1673 case OPT_gxcoff_: 2398 case OPT_gxcoff_:
1674 set_debug_level (XCOFF_DEBUG, code == OPT_gxcoff_, arg, opts, opts_set, 2399 set_debug_level (XCOFF_DEBUG, code == OPT_gxcoff_, arg, opts, opts_set,
1675 loc); 2400 loc);
1676 break; 2401 break;
1677 2402
2403 case OPT_gz:
2404 case OPT_gz_:
2405 /* Handled completely via specs. */
2406 break;
2407
1678 case OPT_pedantic_errors: 2408 case OPT_pedantic_errors:
1679 opts->x_pedantic = 1;
1680 dc->pedantic_errors = 1; 2409 dc->pedantic_errors = 1;
2410 control_warning_option (OPT_Wpedantic, DK_ERROR, NULL, value,
2411 loc, lang_mask,
2412 handlers, opts, opts_set,
2413 dc);
1681 break; 2414 break;
1682 2415
1683 case OPT_flto: 2416 case OPT_flto:
1684 opts->x_flag_lto = value ? "" : NULL; 2417 opts->x_flag_lto = value ? "" : NULL;
1685 break; 2418 break;
1690 2423
1691 case OPT_fmax_errors_: 2424 case OPT_fmax_errors_:
1692 dc->max_errors = value; 2425 dc->max_errors = value;
1693 break; 2426 break;
1694 2427
2428 case OPT_fuse_ld_bfd:
2429 case OPT_fuse_ld_gold:
1695 case OPT_fuse_linker_plugin: 2430 case OPT_fuse_linker_plugin:
1696 /* No-op. Used by the driver and passed to us because it starts with f.*/ 2431 /* No-op. Used by the driver and passed to us because it starts with f.*/
2432 break;
2433
2434 case OPT_fwrapv:
2435 if (value)
2436 opts->x_flag_trapv = 0;
2437 break;
2438
2439 case OPT_ftrapv:
2440 if (value)
2441 opts->x_flag_wrapv = 0;
2442 break;
2443
2444 case OPT_fipa_icf:
2445 opts->x_flag_ipa_icf_functions = value;
2446 opts->x_flag_ipa_icf_variables = value;
1697 break; 2447 break;
1698 2448
1699 default: 2449 default:
1700 /* If the flag was handled in a standard way, assume the lack of 2450 /* If the flag was handled in a standard way, assume the lack of
1701 processing here is intentional. */ 2451 processing here is intentional. */
1702 gcc_assert (option_flag_var (scode, opts)); 2452 gcc_assert (option_flag_var (scode, opts));
1703 break; 2453 break;
1704 } 2454 }
1705 2455
2456 common_handle_option_auto (opts, opts_set, decoded, lang_mask, kind,
2457 loc, handlers, dc);
1706 return true; 2458 return true;
1707 } 2459 }
1708 2460
1709 /* Handle --param NAME=VALUE. */ 2461 /* Handle --param NAME=VALUE. */
1710 static void 2462 static void
1719 if (!equal) 2471 if (!equal)
1720 error_at (loc, "%s: --param arguments should be of the form NAME=VALUE", 2472 error_at (loc, "%s: --param arguments should be of the form NAME=VALUE",
1721 arg); 2473 arg);
1722 else 2474 else
1723 { 2475 {
1724 value = integral_argument (equal + 1); 2476 *equal = '\0';
1725 if (value == -1) 2477
1726 error_at (loc, "invalid --param value %qs", equal + 1); 2478 enum compiler_param index;
2479 if (!find_param (arg, &index))
2480 {
2481 const char *suggestion = find_param_fuzzy (arg);
2482 if (suggestion)
2483 error_at (loc, "invalid --param name %qs; did you mean %qs?",
2484 arg, suggestion);
2485 else
2486 error_at (loc, "invalid --param name %qs", arg);
2487 }
1727 else 2488 else
1728 { 2489 {
1729 *equal = '\0'; 2490 if (!param_string_value_p (index, equal + 1, &value))
1730 set_param_value (arg, value, 2491 value = integral_argument (equal + 1);
1731 opts->x_param_values, opts_set->x_param_values); 2492
2493 if (value == -1)
2494 error_at (loc, "invalid --param value %qs", equal + 1);
2495 else
2496 set_param_value (arg, value,
2497 opts->x_param_values, opts_set->x_param_values);
1732 } 2498 }
1733 } 2499 }
1734 2500
1735 free (arg); 2501 free (arg);
1736 } 2502 }
1739 when no level is specified (i.e., when -Wstrict-aliasing, and not 2505 when no level is specified (i.e., when -Wstrict-aliasing, and not
1740 -Wstrict-aliasing=level was given). 2506 -Wstrict-aliasing=level was given).
1741 ONOFF is assumed to take value 1 when -Wstrict-aliasing is specified, 2507 ONOFF is assumed to take value 1 when -Wstrict-aliasing is specified,
1742 and 0 otherwise. After calling this function, wstrict_aliasing will be 2508 and 0 otherwise. After calling this function, wstrict_aliasing will be
1743 set to the default value of -Wstrict_aliasing=level, currently 3. */ 2509 set to the default value of -Wstrict_aliasing=level, currently 3. */
1744 void 2510 static void
1745 set_Wstrict_aliasing (struct gcc_options *opts, int onoff) 2511 set_Wstrict_aliasing (struct gcc_options *opts, int onoff)
1746 { 2512 {
1747 gcc_assert (onoff == 0 || onoff == 1); 2513 gcc_assert (onoff == 0 || onoff == 1);
1748 if (onoff != 0) 2514 if (onoff != 0)
1749 opts->x_warn_strict_aliasing = 3; 2515 opts->x_warn_strict_aliasing = 3;
1765 opts->x_flag_finite_math_only = set; 2531 opts->x_flag_finite_math_only = set;
1766 if (!opts->frontend_set_flag_errno_math) 2532 if (!opts->frontend_set_flag_errno_math)
1767 opts->x_flag_errno_math = !set; 2533 opts->x_flag_errno_math = !set;
1768 if (set) 2534 if (set)
1769 { 2535 {
2536 if (opts->frontend_set_flag_excess_precision_cmdline
2537 == EXCESS_PRECISION_DEFAULT)
2538 opts->x_flag_excess_precision_cmdline
2539 = set ? EXCESS_PRECISION_FAST : EXCESS_PRECISION_DEFAULT;
1770 if (!opts->frontend_set_flag_signaling_nans) 2540 if (!opts->frontend_set_flag_signaling_nans)
1771 opts->x_flag_signaling_nans = 0; 2541 opts->x_flag_signaling_nans = 0;
1772 if (!opts->frontend_set_flag_rounding_math) 2542 if (!opts->frontend_set_flag_rounding_math)
1773 opts->x_flag_rounding_math = 0; 2543 opts->x_flag_rounding_math = 0;
1774 if (!opts->frontend_set_flag_cx_limited_range) 2544 if (!opts->frontend_set_flag_cx_limited_range)
1797 { 2567 {
1798 return (!opts->x_flag_trapping_math 2568 return (!opts->x_flag_trapping_math
1799 && opts->x_flag_unsafe_math_optimizations 2569 && opts->x_flag_unsafe_math_optimizations
1800 && opts->x_flag_finite_math_only 2570 && opts->x_flag_finite_math_only
1801 && !opts->x_flag_signed_zeros 2571 && !opts->x_flag_signed_zeros
1802 && !opts->x_flag_errno_math); 2572 && !opts->x_flag_errno_math
2573 && opts->x_flag_excess_precision_cmdline
2574 == EXCESS_PRECISION_FAST);
1803 } 2575 }
1804 2576
1805 /* Return true iff flags are set as if -ffast-math but using the flags stored 2577 /* Return true iff flags are set as if -ffast-math but using the flags stored
1806 in the struct cl_optimization structure. */ 2578 in the struct cl_optimization structure. */
1807 bool 2579 bool
1831 { 2603 {
1832 opts->x_write_symbols = PREFERRED_DEBUGGING_TYPE; 2604 opts->x_write_symbols = PREFERRED_DEBUGGING_TYPE;
1833 2605
1834 if (extended == 2) 2606 if (extended == 2)
1835 { 2607 {
1836 #ifdef DWARF2_DEBUGGING_INFO 2608 #if defined DWARF2_DEBUGGING_INFO || defined DWARF2_LINENO_DEBUGGING_INFO
1837 opts->x_write_symbols = DWARF2_DEBUG; 2609 opts->x_write_symbols = DWARF2_DEBUG;
1838 #elif defined DBX_DEBUGGING_INFO 2610 #elif defined DBX_DEBUGGING_INFO
1839 opts->x_write_symbols = DBX_DEBUG; 2611 opts->x_write_symbols = DBX_DEBUG;
1840 #endif 2612 #endif
1841 } 2613 }
1848 { 2620 {
1849 /* Does it conflict with an already selected type? */ 2621 /* Does it conflict with an already selected type? */
1850 if (opts_set->x_write_symbols != NO_DEBUG 2622 if (opts_set->x_write_symbols != NO_DEBUG
1851 && opts->x_write_symbols != NO_DEBUG 2623 && opts->x_write_symbols != NO_DEBUG
1852 && type != opts->x_write_symbols) 2624 && type != opts->x_write_symbols)
1853 error_at (loc, "debug format \"%s\" conflicts with prior selection", 2625 error_at (loc, "debug format %qs conflicts with prior selection",
1854 debug_type_names[type]); 2626 debug_type_names[type]);
1855 opts->x_write_symbols = type; 2627 opts->x_write_symbols = type;
1856 opts_set->x_write_symbols = type; 2628 opts_set->x_write_symbols = type;
1857 } 2629 }
1858 2630
1859 /* A debug flag without a level defaults to level 2. */ 2631 /* A debug flag without a level defaults to level 2.
2632 If off or at level 1, set it to level 2, but if already
2633 at level 3, don't lower it. */
1860 if (*arg == '\0') 2634 if (*arg == '\0')
1861 { 2635 {
1862 if (!opts->x_debug_info_level) 2636 if (opts->x_debug_info_level < DINFO_LEVEL_NORMAL)
1863 opts->x_debug_info_level = DINFO_LEVEL_NORMAL; 2637 opts->x_debug_info_level = DINFO_LEVEL_NORMAL;
1864 } 2638 }
1865 else 2639 else
1866 { 2640 {
1867 int argval = integral_argument (arg); 2641 int argval = integral_argument (arg);
1868 if (argval == -1) 2642 if (argval == -1)
1869 error_at (loc, "unrecognised debug output level \"%s\"", arg); 2643 error_at (loc, "unrecognized debug output level %qs", arg);
1870 else if (argval > 3) 2644 else if (argval > 3)
1871 error_at (loc, "debug output level %s is too high", arg); 2645 error_at (loc, "debug output level %qs is too high", arg);
1872 else 2646 else
1873 opts->x_debug_info_level = (enum debug_info_levels) argval; 2647 opts->x_debug_info_level = (enum debug_info_levels) argval;
1874 } 2648 }
1875 } 2649 }
1876 2650
1886 #endif 2660 #endif
1887 #if defined(HAVE_SETRLIMIT) 2661 #if defined(HAVE_SETRLIMIT)
1888 { 2662 {
1889 struct rlimit rlim; 2663 struct rlimit rlim;
1890 if (getrlimit (RLIMIT_CORE, &rlim) != 0) 2664 if (getrlimit (RLIMIT_CORE, &rlim) != 0)
1891 fatal_error ("getting core file size maximum limit: %m"); 2665 fatal_error (input_location, "getting core file size maximum limit: %m");
1892 rlim.rlim_cur = rlim.rlim_max; 2666 rlim.rlim_cur = rlim.rlim_max;
1893 if (setrlimit (RLIMIT_CORE, &rlim) != 0) 2667 if (setrlimit (RLIMIT_CORE, &rlim) != 0)
1894 fatal_error ("setting core file size limit to maximum: %m"); 2668 fatal_error (input_location,
2669 "setting core file size limit to maximum: %m");
1895 } 2670 }
1896 #endif 2671 #endif
1897 diagnostic_abort_on_error (dc); 2672 diagnostic_abort_on_error (dc);
1898 } 2673 }
1899 2674
1916 opts->x_flag_print_asm_name = 1; 2691 opts->x_flag_print_asm_name = 1;
1917 break; 2692 break;
1918 case 'P': 2693 case 'P':
1919 opts->x_flag_dump_rtl_in_asm = 1; 2694 opts->x_flag_dump_rtl_in_asm = 1;
1920 opts->x_flag_print_asm_name = 1; 2695 opts->x_flag_print_asm_name = 1;
1921 break;
1922 case 'v':
1923 opts->x_graph_dump_format = vcg;
1924 break; 2696 break;
1925 case 'x': 2697 case 'x':
1926 opts->x_rtl_dump_and_exit = 1; 2698 opts->x_rtl_dump_and_exit = 1;
1927 break; 2699 break;
1928 case 'D': /* These are handled by the preprocessor. */ 2700 case 'D': /* These are handled by the preprocessor. */
1962 new_option = XNEWVEC (char, strlen (arg) + 2); 2734 new_option = XNEWVEC (char, strlen (arg) + 2);
1963 new_option[0] = 'W'; 2735 new_option[0] = 'W';
1964 strcpy (new_option + 1, arg); 2736 strcpy (new_option + 1, arg);
1965 option_index = find_opt (new_option, lang_mask); 2737 option_index = find_opt (new_option, lang_mask);
1966 if (option_index == OPT_SPECIAL_unknown) 2738 if (option_index == OPT_SPECIAL_unknown)
1967 { 2739 error_at (loc, "-Werror=%s: no option -%s", arg, new_option);
1968 error_at (loc, "-Werror=%s: no option -%s", arg, new_option); 2740 else if (!(cl_options[option_index].flags & CL_WARNING))
1969 } 2741 error_at (loc, "-Werror=%s: -%s is not an option that controls warnings",
2742 arg, new_option);
1970 else 2743 else
1971 { 2744 {
1972 const diagnostic_t kind = value ? DK_ERROR : DK_WARNING; 2745 const diagnostic_t kind = value ? DK_ERROR : DK_WARNING;
1973 2746 const char *arg = NULL;
1974 control_warning_option (option_index, (int) kind, value, 2747
2748 if (cl_options[option_index].flags & CL_JOINED)
2749 arg = new_option + cl_options[option_index].opt_len;
2750 control_warning_option (option_index, (int) kind, arg, value,
1975 loc, lang_mask, 2751 loc, lang_mask,
1976 handlers, opts, opts_set, dc); 2752 handlers, opts, opts_set, dc);
1977 } 2753 }
1978 free (new_option); 2754 free (new_option);
1979 } 2755 }
1999 /* A warning with option. */ 2775 /* A warning with option. */
2000 else 2776 else
2001 return xstrdup (cl_options[option_index].opt_text); 2777 return xstrdup (cl_options[option_index].opt_text);
2002 } 2778 }
2003 /* A warning without option classified as an error. */ 2779 /* A warning without option classified as an error. */
2004 else if (orig_diag_kind == DK_WARNING || orig_diag_kind == DK_PEDWARN 2780 else if ((orig_diag_kind == DK_WARNING || orig_diag_kind == DK_PEDWARN
2005 || diag_kind == DK_WARNING) 2781 || diag_kind == DK_WARNING)
2006 { 2782 && context->warning_as_error_requested)
2007 if (context->warning_as_error_requested) 2783 return xstrdup (cl_options[OPT_Werror].opt_text);
2008 return xstrdup (cl_options[OPT_Werror].opt_text);
2009 else
2010 return xstrdup (_("enabled by default"));
2011 }
2012 else 2784 else
2013 return NULL; 2785 return NULL;
2014 } 2786 }