comparison gcc/opts-global.c @ 16:04ced10e8804

gcc 7
author kono
date Fri, 27 Oct 2017 22:46:09 +0900
parents 561a7518be6b
children 84e7813d76e9
comparison
equal deleted inserted replaced
15:561a7518be6b 16:04ced10e8804
1 /* Command line option handling. Code involving global state that 1 /* Command line option handling. Code involving global state that
2 should not be shared with the driver. 2 should not be shared with the driver.
3 Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 3 Copyright (C) 2002-2017 Free Software Foundation, Inc.
4 Free Software Foundation, Inc.
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
9 the terms of the GNU General Public License as published by the Free 8 the terms of the GNU General Public License as published by the Free
20 <http://www.gnu.org/licenses/>. */ 19 <http://www.gnu.org/licenses/>. */
21 20
22 #include "config.h" 21 #include "config.h"
23 #include "system.h" 22 #include "system.h"
24 #include "coretypes.h" 23 #include "coretypes.h"
24 #include "backend.h"
25 #include "rtl.h"
26 #include "tree.h"
27 #include "tree-pass.h"
25 #include "diagnostic.h" 28 #include "diagnostic.h"
26 #include "opts.h" 29 #include "opts.h"
27 #include "flags.h" 30 #include "flags.h"
28 #include "ggc.h"
29 #include "tree.h" /* Required by langhooks.h. */
30 #include "langhooks.h" 31 #include "langhooks.h"
31 #include "tm.h" /* Required by rtl.h. */
32 #include "rtl.h"
33 #include "dbgcnt.h" 32 #include "dbgcnt.h"
34 #include "debug.h" 33 #include "debug.h"
35 #include "lto-streamer.h"
36 #include "output.h" 34 #include "output.h"
37 #include "plugin.h" 35 #include "plugin.h"
38 #include "toplev.h" 36 #include "toplev.h"
39 #include "tree-pass.h" 37 #include "context.h"
38 #include "stringpool.h"
39 #include "attribs.h"
40 #include "asan.h"
40 41
41 typedef const char *const_char_p; /* For DEF_VEC_P. */ 42 typedef const char *const_char_p; /* For DEF_VEC_P. */
42 DEF_VEC_P(const_char_p); 43
43 DEF_VEC_ALLOC_P(const_char_p,heap); 44 static vec<const_char_p> ignored_options;
44
45 static VEC(const_char_p,heap) *ignored_options;
46 45
47 /* Input file names. */ 46 /* Input file names. */
48 const char **in_fnames; 47 const char **in_fnames;
49 unsigned num_in_fnames; 48 unsigned num_in_fnames;
50 49
51 /* Return a malloced slash-separated list of languages in MASK. */ 50 /* Return a malloced slash-separated list of languages in MASK. */
52 51
53 static char * 52 char *
54 write_langs (unsigned int mask) 53 write_langs (unsigned int mask)
55 { 54 {
56 unsigned int n = 0, len = 0; 55 unsigned int n = 0, len = 0;
57 const char *lang_name; 56 const char *lang_name;
58 char *result; 57 char *result;
114 113
115 /* Buffer the unknown option described by the string OPT. Currently, 114 /* Buffer the unknown option described by the string OPT. Currently,
116 we only complain about unknown -Wno-* options if they may have 115 we only complain about unknown -Wno-* options if they may have
117 prevented a diagnostic. Otherwise, we just ignore them. Note that 116 prevented a diagnostic. Otherwise, we just ignore them. Note that
118 if we do complain, it is only as a warning, not an error; passing 117 if we do complain, it is only as a warning, not an error; passing
119 the compiler an unrecognised -Wno-* option should never change 118 the compiler an unrecognized -Wno-* option should never change
120 whether the compilation succeeds or fails. */ 119 whether the compilation succeeds or fails. */
121 120
122 static void 121 static void
123 postpone_unknown_option_warning (const char *opt) 122 postpone_unknown_option_warning (const char *opt)
124 { 123 {
125 VEC_safe_push (const_char_p, heap, ignored_options, opt); 124 ignored_options.safe_push (opt);
126 } 125 }
127 126
128 /* Produce a warning for each option previously buffered. */ 127 /* Produce a warning for each option previously buffered. */
129 128
130 void 129 void
131 print_ignored_options (void) 130 print_ignored_options (void)
132 { 131 {
133 while (!VEC_empty (const_char_p, ignored_options)) 132 while (!ignored_options.is_empty ())
134 { 133 {
135 const char *opt; 134 const char *opt;
136 135
137 opt = VEC_pop (const_char_p, ignored_options); 136 opt = ignored_options.pop ();
138 warning_at (UNKNOWN_LOCATION, 0, 137 warning_at (UNKNOWN_LOCATION, 0,
139 "unrecognized command line option \"%s\"", opt); 138 "unrecognized command line option %qs", opt);
140 } 139 }
141 } 140 }
142 141
143 /* Handle an unknown option DECODED, returning true if an error should 142 /* Handle an unknown option DECODED, returning true if an error should
144 be given. */ 143 be given. */
158 } 157 }
159 else 158 else
160 return true; 159 return true;
161 } 160 }
162 161
163 /* Note that an option DECODED has been successfully handled with a
164 handler for mask MASK. */
165
166 static void
167 post_handling_callback (const struct cl_decoded_option *decoded ATTRIBUTE_UNUSED,
168 unsigned int mask ATTRIBUTE_UNUSED)
169 {
170 #ifdef ENABLE_LTO
171 lto_register_user_option (decoded->opt_index, decoded->arg,
172 decoded->value, mask);
173 #endif
174 }
175
176 /* Handle a front-end option; arguments and return value as for 162 /* Handle a front-end option; arguments and return value as for
177 handle_option. */ 163 handle_option. */
178 164
179 static bool 165 static bool
180 lang_handle_option (struct gcc_options *opts, 166 lang_handle_option (struct gcc_options *opts,
181 struct gcc_options *opts_set, 167 struct gcc_options *opts_set,
182 const struct cl_decoded_option *decoded, 168 const struct cl_decoded_option *decoded,
183 unsigned int lang_mask ATTRIBUTE_UNUSED, int kind, 169 unsigned int lang_mask ATTRIBUTE_UNUSED, int kind,
184 location_t loc, 170 location_t loc,
185 const struct cl_option_handlers *handlers, 171 const struct cl_option_handlers *handlers,
186 diagnostic_context *dc) 172 diagnostic_context *dc,
173 void (*) (void))
187 { 174 {
188 gcc_assert (opts == &global_options); 175 gcc_assert (opts == &global_options);
189 gcc_assert (opts_set == &global_options_set); 176 gcc_assert (opts_set == &global_options_set);
190 gcc_assert (dc == global_dc); 177 gcc_assert (dc == global_dc);
191 gcc_assert (decoded->canonical_option_num_elements <= 2); 178 gcc_assert (decoded->canonical_option_num_elements <= 2);
256 { 243 {
257 /* Perform language-specific options initialization. */ 244 /* Perform language-specific options initialization. */
258 initial_lang_mask = lang_hooks.option_lang_mask (); 245 initial_lang_mask = lang_hooks.option_lang_mask ();
259 246
260 lang_hooks.initialize_diagnostics (global_dc); 247 lang_hooks.initialize_diagnostics (global_dc);
248 /* ??? Ideally, we should do this earlier and the FEs will override
249 it if desired (none do it so far). However, the way the FEs
250 construct their pretty-printers means that all previous settings
251 are overriden. */
252 diagnostic_color_init (global_dc);
261 } 253 }
262 254
263 /* Decode command-line options to an array, like 255 /* Decode command-line options to an array, like
264 decode_cmdline_options_to_array and with the same arguments but 256 decode_cmdline_options_to_array and with the same arguments but
265 using the default lang_mask. */ 257 using the default lang_mask. */
276 } 268 }
277 269
278 /* Set *HANDLERS to the default set of option handlers for use in the 270 /* Set *HANDLERS to the default set of option handlers for use in the
279 compilers proper (not the driver). */ 271 compilers proper (not the driver). */
280 void 272 void
281 set_default_handlers (struct cl_option_handlers *handlers) 273 set_default_handlers (struct cl_option_handlers *handlers,
274 void (*target_option_override_hook) (void))
282 { 275 {
283 handlers->unknown_option_callback = unknown_option_callback; 276 handlers->unknown_option_callback = unknown_option_callback;
284 handlers->wrong_lang_callback = complain_wrong_lang; 277 handlers->wrong_lang_callback = complain_wrong_lang;
285 handlers->post_handling_callback = post_handling_callback; 278 handlers->target_option_override_hook = target_option_override_hook;
286 handlers->num_handlers = 3; 279 handlers->num_handlers = 3;
287 handlers->handlers[0].handler = lang_handle_option; 280 handlers->handlers[0].handler = lang_handle_option;
288 handlers->handlers[0].mask = initial_lang_mask; 281 handlers->handlers[0].mask = initial_lang_mask;
289 handlers->handlers[1].handler = common_handle_option; 282 handlers->handlers[1].handler = common_handle_option;
290 handlers->handlers[1].mask = CL_COMMON; 283 handlers->handlers[1].mask = CL_COMMON;
298 the options are located at LOC. */ 291 the options are located at LOC. */
299 void 292 void
300 decode_options (struct gcc_options *opts, struct gcc_options *opts_set, 293 decode_options (struct gcc_options *opts, struct gcc_options *opts_set,
301 struct cl_decoded_option *decoded_options, 294 struct cl_decoded_option *decoded_options,
302 unsigned int decoded_options_count, 295 unsigned int decoded_options_count,
303 location_t loc, diagnostic_context *dc) 296 location_t loc, diagnostic_context *dc,
297 void (*target_option_override_hook) (void))
304 { 298 {
305 struct cl_option_handlers handlers; 299 struct cl_option_handlers handlers;
306 300
307 unsigned int lang_mask; 301 unsigned int lang_mask;
308 302
309 lang_mask = initial_lang_mask; 303 lang_mask = initial_lang_mask;
310 304
311 set_default_handlers (&handlers); 305 set_default_handlers (&handlers, target_option_override_hook);
312
313 /* Enable -Werror=coverage-mismatch by default. */
314 control_warning_option (OPT_Wcoverage_mismatch, (int) DK_ERROR, true,
315 loc, lang_mask,
316 &handlers, opts, opts_set, dc);
317 306
318 default_options_optimization (opts, opts_set, 307 default_options_optimization (opts, opts_set,
319 decoded_options, decoded_options_count, 308 decoded_options, decoded_options_count,
320 loc, lang_mask, &handlers, dc); 309 loc, lang_mask, &handlers, dc);
321
322 #ifdef ENABLE_LTO
323 /* Clear any options currently held for LTO. */
324 lto_clear_user_options ();
325 #endif
326 310
327 read_cmdline_options (opts, opts_set, 311 read_cmdline_options (opts, opts_set,
328 decoded_options, decoded_options_count, 312 decoded_options, decoded_options_count,
329 loc, lang_mask, 313 loc, lang_mask,
330 &handlers, dc); 314 &handlers, dc);
331 315
332 finish_options (opts, opts_set, loc); 316 finish_options (opts, opts_set, loc);
333 } 317 }
334 318
319 /* Hold command-line options associated with stack limitation. */
320 const char *opt_fstack_limit_symbol_arg = NULL;
321 int opt_fstack_limit_register_no = -1;
322
335 /* Process common options that have been deferred until after the 323 /* Process common options that have been deferred until after the
336 handlers have been called for all options. */ 324 handlers have been called for all options. */
337 325
338 void 326 void
339 handle_common_deferred_options (void) 327 handle_common_deferred_options (void)
340 { 328 {
341 unsigned int i; 329 unsigned int i;
342 cl_deferred_option *opt; 330 cl_deferred_option *opt;
343 VEC(cl_deferred_option,heap) *vec 331 vec<cl_deferred_option> v;
344 = (VEC(cl_deferred_option,heap) *) common_deferred_options; 332
333 if (common_deferred_options)
334 v = *((vec<cl_deferred_option> *) common_deferred_options);
335 else
336 v = vNULL;
345 337
346 if (flag_dump_all_passed) 338 if (flag_dump_all_passed)
347 enable_rtl_dump_file (); 339 enable_rtl_dump_file ();
348 340
349 FOR_EACH_VEC_ELT (cl_deferred_option, vec, i, opt) 341 if (flag_opt_info)
342 opt_info_switch_p (NULL);
343
344 FOR_EACH_VEC_ELT (v, i, opt)
350 { 345 {
351 switch (opt->opt_index) 346 switch (opt->opt_index)
352 { 347 {
353 case OPT_fcall_used_: 348 case OPT_fcall_used_:
354 fix_register (opt->arg, 0, 1); 349 fix_register (opt->arg, 0, 1);
369 case OPT_fdebug_prefix_map_: 364 case OPT_fdebug_prefix_map_:
370 add_debug_prefix_map (opt->arg); 365 add_debug_prefix_map (opt->arg);
371 break; 366 break;
372 367
373 case OPT_fdump_: 368 case OPT_fdump_:
374 if (!dump_switch_p (opt->arg)) 369 if (!g->get_dumps ()->dump_switch_p (opt->arg))
375 error ("unrecognized command line option %<-fdump-%s%>", opt->arg); 370 error ("unrecognized command line option %<-fdump-%s%>", opt->arg);
376 break; 371 break;
372
373 case OPT_fopt_info_:
374 if (!opt_info_switch_p (opt->arg))
375 error ("unrecognized command line option %<-fopt-info-%s%>",
376 opt->arg);
377 break;
378
379 case OPT_fenable_:
380 case OPT_fdisable_:
381 if (opt->opt_index == OPT_fenable_)
382 enable_pass (opt->arg);
383 else
384 disable_pass (opt->arg);
385 break;
377 386
378 case OPT_ffixed_: 387 case OPT_ffixed_:
379 /* Deferred. */ 388 /* Deferred. */
380 fix_register (opt->arg, 1, 1); 389 fix_register (opt->arg, 1, 1);
381 break; 390 break;
416 { 425 {
417 int reg = decode_reg_name (opt->arg); 426 int reg = decode_reg_name (opt->arg);
418 if (reg < 0) 427 if (reg < 0)
419 error ("unrecognized register name %qs", opt->arg); 428 error ("unrecognized register name %qs", opt->arg);
420 else 429 else
421 stack_limit_rtx = gen_rtx_REG (Pmode, reg); 430 {
431 /* Deactivate previous OPT_fstack_limit_symbol_ options. */
432 opt_fstack_limit_symbol_arg = NULL;
433 opt_fstack_limit_register_no = reg;
434 }
422 } 435 }
423 break; 436 break;
424 437
425 case OPT_fstack_limit_symbol_: 438 case OPT_fstack_limit_symbol_:
426 stack_limit_rtx = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (opt->arg)); 439 /* Deactivate previous OPT_fstack_limit_register_ options. */
440 opt_fstack_limit_register_no = -1;
441 opt_fstack_limit_symbol_arg = opt->arg;
442 break;
443
444 case OPT_fasan_shadow_offset_:
445 if (!(flag_sanitize & SANITIZE_KERNEL_ADDRESS))
446 error ("-fasan-shadow-offset should only be used "
447 "with -fsanitize=kernel-address");
448 if (!set_asan_shadow_offset (opt->arg))
449 error ("unrecognized shadow offset %qs", opt->arg);
450 break;
451
452 case OPT_fsanitize_sections_:
453 set_sanitized_sections (opt->arg);
427 break; 454 break;
428 455
429 default: 456 default:
430 gcc_unreachable (); 457 gcc_unreachable ();
431 } 458 }