This patch suppresses the messages printed when the primary module is not found.
[official-gcc.git] / gcc-4_7 / gcc / opts-global.c
blob1768747de08d181d2671e8ff8045e5fe6ee1076e
1 /* Command line option handling. Code involving global state that
2 should not be shared with the driver.
3 Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
4 Free Software Foundation, Inc.
6 This file is part of GCC.
8 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
10 Software Foundation; either version 3, or (at your option) any later
11 version.
13 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 for more details.
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING3. If not see
20 <http://www.gnu.org/licenses/>. */
22 #include "config.h"
23 #include "system.h"
24 #include "coretypes.h"
25 #include "diagnostic.h"
26 #include "opts.h"
27 #include "flags.h"
28 #include "ggc.h"
29 #include "tree.h" /* Required by langhooks.h. */
30 #include "langhooks.h"
31 #include "tm.h" /* Required by rtl.h. */
32 #include "rtl.h"
33 #include "dbgcnt.h"
34 #include "debug.h"
35 #include "lto-streamer.h"
36 #include "output.h"
37 #include "plugin.h"
38 #include "toplev.h"
39 #include "tree-pass.h"
40 #include "params.h"
41 #include "l-ipo.h"
42 #include "xregex.h"
44 typedef const char *const_char_p; /* For DEF_VEC_P. */
45 DEF_VEC_P(const_char_p);
46 DEF_VEC_ALLOC_P(const_char_p,heap);
48 static VEC(const_char_p,heap) *ignored_options;
50 /* Input file names. */
51 const char **in_fnames;
52 unsigned num_in_fnames;
54 static struct reg_func_attr_patterns
56 regex_t r;
57 const char *attribute;
58 struct reg_func_attr_patterns *next;
59 } *reg_func_attr_patterns;
61 /* Return a malloced slash-separated list of languages in MASK. */
63 static char *
64 write_langs (unsigned int mask)
66 unsigned int n = 0, len = 0;
67 const char *lang_name;
68 char *result;
70 for (n = 0; (lang_name = lang_names[n]) != 0; n++)
71 if (mask & (1U << n))
72 len += strlen (lang_name) + 1;
74 result = XNEWVEC (char, len);
75 len = 0;
76 for (n = 0; (lang_name = lang_names[n]) != 0; n++)
77 if (mask & (1U << n))
79 if (len)
80 result[len++] = '/';
81 strcpy (result + len, lang_name);
82 len += strlen (lang_name);
85 result[len] = 0;
87 return result;
90 /* Add strings like attribute_str:pattern... to attribute pattern list. */
92 static void
93 add_attribute_pattern (const char *arg)
95 char *tmp;
96 char *pattern_str;
97 struct reg_func_attr_patterns *one_pat;
98 int ec;
100 /* We never free this string. */
101 tmp = xstrdup (arg);
103 pattern_str = strchr (tmp, ':');
104 if (!pattern_str)
105 error ("invalid pattern in -ffunction-attribute-list option: %qs", tmp);
107 *pattern_str = '\0';
108 pattern_str ++;
110 one_pat = XCNEW (struct reg_func_attr_patterns);
111 one_pat->next = reg_func_attr_patterns;
112 one_pat->attribute = tmp;
113 reg_func_attr_patterns = one_pat;
114 if ((ec= regcomp (&one_pat->r, pattern_str, REG_EXTENDED|REG_NOSUB) != 0))
116 char err[100];
117 regerror (ec, &one_pat->r, err, 99);
118 error ("invalid pattern in -ffunction-attribute-list option: %qs: %qs",
119 pattern_str, err);
123 /* Match FNDECL's name with user specified patterns, and add attributes
124 to FNDECL. */
126 void
127 pattern_match_function_attributes (tree fndecl)
129 const char *name;
130 struct reg_func_attr_patterns *one_pat;
132 if (!fndecl)
133 return;
135 if (!reg_func_attr_patterns)
136 return;
138 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (fndecl));
140 for (one_pat = reg_func_attr_patterns; one_pat; one_pat = one_pat->next)
141 if (regexec (&one_pat->r, name, 0, NULL, 0) == 0)
142 decl_attributes (&fndecl, tree_cons (
143 get_identifier (one_pat->attribute), NULL, NULL), 0);
146 /* Complain that switch DECODED does not apply to this front end (mask
147 LANG_MASK). */
149 static void
150 complain_wrong_lang (const struct cl_decoded_option *decoded,
151 unsigned int lang_mask)
153 const struct cl_option *option = &cl_options[decoded->opt_index];
154 const char *text = decoded->orig_option_with_args_text;
155 char *ok_langs = NULL, *bad_lang = NULL;
156 unsigned int opt_flags = option->flags;
158 if (!lang_hooks.complain_wrong_lang_p (option))
159 return;
161 opt_flags &= ((1U << cl_lang_count) - 1) | CL_DRIVER;
162 if (opt_flags != CL_DRIVER)
163 ok_langs = write_langs (opt_flags);
164 if (lang_mask != CL_DRIVER)
165 bad_lang = write_langs (lang_mask);
167 if (opt_flags == CL_DRIVER)
168 error ("command line option %qs is valid for the driver but not for %s",
169 text, bad_lang);
170 else if (lang_mask == CL_DRIVER)
171 gcc_unreachable ();
172 else
173 /* Eventually this should become a hard error IMO. */
174 warning (0, "command line option %qs is valid for %s but not for %s",
175 text, ok_langs, bad_lang);
177 free (ok_langs);
178 free (bad_lang);
181 /* Buffer the unknown option described by the string OPT. Currently,
182 we only complain about unknown -Wno-* options if they may have
183 prevented a diagnostic. Otherwise, we just ignore them. Note that
184 if we do complain, it is only as a warning, not an error; passing
185 the compiler an unrecognised -Wno-* option should never change
186 whether the compilation succeeds or fails. */
188 static void
189 postpone_unknown_option_warning (const char *opt)
191 VEC_safe_push (const_char_p, heap, ignored_options, opt);
194 /* Produce a warning for each option previously buffered. */
196 void
197 print_ignored_options (void)
199 while (!VEC_empty (const_char_p, ignored_options))
201 const char *opt;
203 opt = VEC_pop (const_char_p, ignored_options);
204 warning_at (UNKNOWN_LOCATION, 0,
205 "unrecognized command line option \"%s\"", opt);
209 /* Handle an unknown option DECODED, returning true if an error should
210 be given. */
212 static bool
213 unknown_option_callback (const struct cl_decoded_option *decoded)
215 const char *opt = decoded->arg;
217 if (opt[1] == 'W' && opt[2] == 'n' && opt[3] == 'o' && opt[4] == '-'
218 && !(decoded->errors & CL_ERR_NEGATIVE))
220 /* We don't generate warnings for unknown -Wno-* options unless
221 we issue diagnostics. */
222 postpone_unknown_option_warning (opt);
223 return false;
225 else
226 return true;
229 /* Handle a front-end option; arguments and return value as for
230 handle_option. */
232 static bool
233 lang_handle_option (struct gcc_options *opts,
234 struct gcc_options *opts_set,
235 const struct cl_decoded_option *decoded,
236 unsigned int lang_mask ATTRIBUTE_UNUSED, int kind,
237 location_t loc,
238 const struct cl_option_handlers *handlers,
239 diagnostic_context *dc)
241 gcc_assert (opts == &global_options);
242 gcc_assert (opts_set == &global_options_set);
243 gcc_assert (dc == global_dc);
244 gcc_assert (decoded->canonical_option_num_elements <= 2);
245 return lang_hooks.handle_option (decoded->opt_index, decoded->arg,
246 decoded->value, kind, loc, handlers);
249 /* Handle FILENAME from the command line. */
251 void
252 add_input_filename (const char *filename)
254 num_in_fnames++;
255 in_fnames = XRESIZEVEC (const char *, in_fnames, num_in_fnames);
256 in_fnames[num_in_fnames - 1] = filename;
259 /* GCC command-line options saved to the LIPO profile data file.
260 See detailed comment in opts.h. */
261 const char **lipo_cl_args;
262 unsigned num_lipo_cl_args;
264 /* Inspect the given GCC command-line arguments, which are part of one GCC
265 switch, and decide whether or not to store these to the LIPO profile data
266 file. */
267 static void
268 lipo_save_cl_args (struct cl_decoded_option *decoded)
270 const char *opt = decoded->orig_option_with_args_text;
271 /* Store the following command-line flags to the lipo profile data file:
272 (1) -f... (except -frandom-seed...)
273 (2) -m...
274 (3) -W...
275 (4) -O...
276 (5) --param...
278 if (opt[0] == '-'
279 && (opt[1] == 'f' || opt[1] == 'm' || opt[1] == 'W' || opt[1] == 'O'
280 || (strstr (opt, "--param") == opt) || (strstr (opt, "-std=")))
281 && !strstr(opt, "-frandom-seed")
282 && !strstr(opt, "-fripa-disallow-opt-mismatch")
283 && !strstr(opt, "-Wripa-opt-mismatch"))
285 num_lipo_cl_args++;
286 lipo_cl_args = XRESIZEVEC (const char *, lipo_cl_args, num_lipo_cl_args);
287 lipo_cl_args[num_lipo_cl_args - 1] = opt;
291 /* Handle the vector of command line options (located at LOC), storing
292 the results of processing DECODED_OPTIONS and DECODED_OPTIONS_COUNT
293 in OPTS and OPTS_SET and using DC for diagnostic state. LANG_MASK
294 contains has a single bit set representing the current language.
295 HANDLERS describes what functions to call for the options. */
297 static void
298 read_cmdline_options (struct gcc_options *opts, struct gcc_options *opts_set,
299 struct cl_decoded_option *decoded_options,
300 unsigned int decoded_options_count,
301 location_t loc,
302 unsigned int lang_mask,
303 const struct cl_option_handlers *handlers,
304 diagnostic_context *dc)
306 unsigned int i;
307 int force_multi_module = 0;
308 static int cur_mod_id = 0;
310 force_multi_module = PARAM_VALUE (PARAM_FORCE_LIPO_MODE);
312 for (i = 1; i < decoded_options_count; i++)
314 if (decoded_options[i].opt_index == OPT_SPECIAL_input_file)
316 /* Input files should only ever appear on the main command
317 line. */
318 gcc_assert (opts == &global_options);
319 gcc_assert (opts_set == &global_options_set);
321 if (opts->x_main_input_filename == NULL)
323 opts->x_main_input_filename = decoded_options[i].arg;
324 opts->x_main_input_baselength
325 = base_of_path (opts->x_main_input_filename,
326 &opts->x_main_input_basename);
328 add_input_filename (decoded_options[i].arg);
329 if (force_multi_module)
330 add_module_info (++cur_mod_id, (num_in_fnames == 1), num_in_fnames - 1);
331 continue;
334 read_cmdline_option (opts, opts_set,
335 decoded_options + i, loc, lang_mask, handlers,
336 dc);
337 lipo_save_cl_args (decoded_options + i);
341 /* Language mask determined at initialization. */
342 static unsigned int initial_lang_mask;
344 /* Initialize global options-related settings at start-up. */
346 void
347 init_options_once (void)
349 /* Perform language-specific options initialization. */
350 initial_lang_mask = lang_hooks.option_lang_mask ();
352 lang_hooks.initialize_diagnostics (global_dc);
355 /* Decode command-line options to an array, like
356 decode_cmdline_options_to_array and with the same arguments but
357 using the default lang_mask. */
359 void
360 decode_cmdline_options_to_array_default_mask (unsigned int argc,
361 const char **argv,
362 struct cl_decoded_option **decoded_options,
363 unsigned int *decoded_options_count)
365 decode_cmdline_options_to_array (argc, argv,
366 initial_lang_mask | CL_COMMON | CL_TARGET,
367 decoded_options, decoded_options_count);
370 /* Set *HANDLERS to the default set of option handlers for use in the
371 compilers proper (not the driver). */
372 void
373 set_default_handlers (struct cl_option_handlers *handlers)
375 handlers->unknown_option_callback = unknown_option_callback;
376 handlers->wrong_lang_callback = complain_wrong_lang;
377 handlers->num_handlers = 3;
378 handlers->handlers[0].handler = lang_handle_option;
379 handlers->handlers[0].mask = initial_lang_mask;
380 handlers->handlers[1].handler = common_handle_option;
381 handlers->handlers[1].mask = CL_COMMON;
382 handlers->handlers[2].handler = target_handle_option;
383 handlers->handlers[2].mask = CL_TARGET;
386 /* Parse command line options and set default flag values. Do minimal
387 options processing. The decoded options are in *DECODED_OPTIONS
388 and *DECODED_OPTIONS_COUNT; settings go in OPTS, OPTS_SET and DC;
389 the options are located at LOC. */
390 void
391 decode_options (struct gcc_options *opts, struct gcc_options *opts_set,
392 struct cl_decoded_option *decoded_options,
393 unsigned int decoded_options_count,
394 location_t loc, diagnostic_context *dc)
396 struct cl_option_handlers handlers;
398 unsigned int lang_mask;
400 lang_mask = initial_lang_mask;
402 set_default_handlers (&handlers);
404 default_options_optimization (opts, opts_set,
405 decoded_options, decoded_options_count,
406 loc, lang_mask, &handlers, dc);
408 read_cmdline_options (opts, opts_set,
409 decoded_options, decoded_options_count,
410 loc, lang_mask,
411 &handlers, dc);
413 finish_options (opts, opts_set, loc);
416 /* Process common options that have been deferred until after the
417 handlers have been called for all options. */
419 void
420 handle_common_deferred_options (void)
422 unsigned int i;
423 cl_deferred_option *opt;
424 VEC(cl_deferred_option,heap) *vec
425 = (VEC(cl_deferred_option,heap) *) common_deferred_options;
427 if (flag_dump_all_passed)
428 enable_rtl_dump_file ();
430 FOR_EACH_VEC_ELT (cl_deferred_option, vec, i, opt)
432 switch (opt->opt_index)
434 case OPT_fcall_used_:
435 fix_register (opt->arg, 0, 1);
436 break;
438 case OPT_fcall_saved_:
439 fix_register (opt->arg, 0, 0);
440 break;
442 case OPT_fdbg_cnt_:
443 dbg_cnt_process_opt (opt->arg);
444 break;
446 case OPT_fdbg_cnt_list:
447 dbg_cnt_list_all_counters ();
448 break;
450 case OPT_fdebug_prefix_map_:
451 add_debug_prefix_map (opt->arg);
452 break;
454 case OPT_fdump_:
455 if (!dump_switch_p (opt->arg))
456 error ("unrecognized command line option %<-fdump-%s%>", opt->arg);
457 break;
459 case OPT_fenable_:
460 case OPT_fdisable_:
461 if (opt->opt_index == OPT_fenable_)
462 enable_pass (opt->arg);
463 else
464 disable_pass (opt->arg);
465 break;
467 case OPT_ffixed_:
468 /* Deferred. */
469 fix_register (opt->arg, 1, 1);
470 break;
472 case OPT_fplugin_:
473 #ifdef ENABLE_PLUGIN
474 add_new_plugin (opt->arg);
475 #else
476 error ("plugin support is disabled; configure with --enable-plugin");
477 #endif
478 break;
480 case OPT_fplugin_arg_:
481 #ifdef ENABLE_PLUGIN
482 parse_plugin_arg_opt (opt->arg);
483 #else
484 error ("plugin support is disabled; configure with --enable-plugin");
485 #endif
486 break;
488 case OPT_frandom_seed:
489 /* The real switch is -fno-random-seed. */
490 if (!opt->value)
491 set_random_seed (NULL);
492 break;
494 case OPT_frandom_seed_:
495 set_random_seed (opt->arg);
496 break;
498 case OPT_ffunction_attribute_list_:
499 add_attribute_pattern (opt->arg);
500 break;
502 case OPT_fstack_limit:
503 /* The real switch is -fno-stack-limit. */
504 if (!opt->value)
505 stack_limit_rtx = NULL_RTX;
506 break;
508 case OPT_fstack_limit_register_:
510 int reg = decode_reg_name (opt->arg);
511 if (reg < 0)
512 error ("unrecognized register name %qs", opt->arg);
513 else
514 stack_limit_rtx = gen_rtx_REG (Pmode, reg);
516 break;
518 case OPT_fstack_limit_symbol_:
519 stack_limit_rtx = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (opt->arg));
520 break;
522 default:
523 gcc_unreachable ();