aboutsummaryrefslogtreecommitdiff
path: root/gcc/opts.c
diff options
context:
space:
mode:
authorJoseph Myers <joseph@codesourcery.com>2010-11-24 00:51:48 +0000
committerJoseph Myers <jsm28@gcc.gnu.org>2010-11-24 00:51:48 +0000
commitc98cd5bff60fa2a0bd31fcdbd2f0758a32639c09 (patch)
treee78bd9fc9f3b4e8df779c5d10ba572a064b6c4cf /gcc/opts.c
parent3862bc3a55766907dbd1518e9f153abb34eb6785 (diff)
downloadgcc-c98cd5bff60fa2a0bd31fcdbd2f0758a32639c09.zip
gcc-c98cd5bff60fa2a0bd31fcdbd2f0758a32639c09.tar.gz
gcc-c98cd5bff60fa2a0bd31fcdbd2f0758a32639c09.tar.bz2
flag-types.h (struct visibility_flags): Don't declare here.
* flag-types.h (struct visibility_flags): Don't declare here. * flags.h (strip_off_ending, fast_math_flags_set_p, fast_math_flags_struct_set_p): Declare here. (visibility_options): Don't declare here. * opts-common.c (option_enabled, get_option_state): Move from opts.c. * opts-global.c: Include diagnostic.h instead of diagnostic-core.h. Include tree.h, langhooks.h, lto-streamer.h and toplev.h. (const_char_p, ignored_options, in_fnames, num_in_fnames, write_langs, complain_wrong_lang, postpone_unknown_option_warning, print_ignored_options, unknown_option_callback, post_handling_callback, lang_handle_option, add_input_filename, read_cmdline_options, initial_lang_mask, init_options_once, decode_cmdline_options_to_array_default_mask, set_default_handlers, decode_options): Move from opts.c. (print_ignored_options): Use warning_at instead of saving and restoring input_location. * opts.c: Include <signal.h> and <sys/resource.h>. Include rtl.h instead of expr.h. Don't include langhooks.h, except.h or lto-streamer.h. Add more comments on includes. (strip_off_ending, setup_core_dumping, decode_d_option): Move from toplev.c. (visibility_options): Move to c-family/c-common.c. (const_char_p, ignored_options, in_fnames, num_in_fnames, write_langs, complain_wrong_lang, postpone_unknown_option_warning, print_ignored_options, unknown_option_callback, post_handling_callback, lang_handle_option, add_input_filename, read_cmdline_options, initial_lang_mask, init_options_once, decode_cmdline_options_to_array_default_mask, set_default_handlers, decode_options): Move to opts-global.c. (target_handle_option, default_options_optimization, finish_options, common_handle_option): Remove static. (option_enabled, get_option_state): Move to opts-common.c. * opts.h (common_handle_option, target_handle_option, finish_options, default_options_optimization): Declare. * toplev.c: Don't include <signal.h> or <sys/resource.h>. (setup_core_dumping, strip_off_ending, decode_d_option): Move to opts.c. * toplev.h (strip_off_ending, decode_d_option, fast_math_flags_set_p, fast_math_flags_struct_set_p): Don't declare here. * Makefile.in (opts.o, opts-global.o): Update dependencies. c-family: * c-common.c (visibility_options): Move from ../opts.c. * c-common.h (struct visibility_flags, visibility_options): Declare here. * c-opts.c (finish_options): Rename to c_finish_options. (c_common_init): Update call to finish_options. From-SVN: r167105
Diffstat (limited to 'gcc/opts.c')
-rw-r--r--gcc/opts.c474
1 files changed, 94 insertions, 380 deletions
diff --git a/gcc/opts.c b/gcc/opts.c
index 9e9572d..a088bc5 100644
--- a/gcc/opts.c
+++ b/gcc/opts.c
@@ -21,25 +21,30 @@ along with GCC; see the file COPYING3. If not see
#include "config.h"
#include "system.h"
+
+#include <signal.h>
+
+#ifdef HAVE_SYS_RESOURCE_H
+# include <sys/resource.h>
+#endif
+
#include "intl.h"
#include "coretypes.h"
-#include "tm.h"
-#include "tree.h"
-#include "expr.h"
-#include "langhooks.h"
+#include "tm.h" /* Needed by rtl.h and used for DWARF2_DEBUGGING_INFO
+ and DBX_DEBUGGING_INFO. */
+#include "tree.h" /* For vect_set_verbosity_level. */
+#include "rtl.h" /* Needed by insn-attr.h. */
#include "opts.h"
#include "options.h"
#include "flags.h"
-#include "toplev.h"
+#include "toplev.h" /* For set_random_seed and enable_rtl_dump_file. */
#include "params.h"
#include "diagnostic.h"
#include "opts-diagnostic.h"
-#include "insn-attr.h" /* For INSN_SCHEDULING. */
+#include "insn-attr.h" /* For INSN_SCHEDULING and DELAY_SLOTS. */
#include "target.h"
#include "dbgcnt.h"
#include "debug.h"
-#include "except.h"
-#include "lto-streamer.h"
/* Run the second compilation of -fcompare-debug. Not defined using
Var in common.opt because this is used in Ada code and so must be
@@ -136,6 +141,25 @@ set_struct_debug_option (struct gcc_options *opts, const char *spec)
}
}
+/* Strip off a legitimate source ending from the input string NAME of
+ length LEN. Rather than having to know the names used by all of
+ our front ends, we strip off an ending of a period followed by
+ up to five characters. (Java uses ".class".) */
+
+void
+strip_off_ending (char *name, int len)
+{
+ int i;
+ for (i = 2; i < 6 && len > i; i++)
+ {
+ if (name[len - i] == '.')
+ {
+ name[len - i] = '\0';
+ break;
+ }
+ }
+}
+
/* Find the base name of a path, stripping off both directories and
a single final extension. */
int
@@ -162,9 +186,6 @@ base_of_path (const char *path, const char **base_out)
return dot - base;
}
-/* Global visibility options. */
-struct visibility_flags visibility_options;
-
/* What to print when a switch has no documentation. */
static const char undocumented_msg[] = N_("This switch lacks documentation");
@@ -172,32 +193,13 @@ typedef char *char_p; /* For DEF_VEC_P. */
DEF_VEC_P(char_p);
DEF_VEC_ALLOC_P(char_p,heap);
-typedef const char *const_char_p; /* For DEF_VEC_P. */
-DEF_VEC_P(const_char_p);
-DEF_VEC_ALLOC_P(const_char_p,heap);
-
-static VEC(const_char_p,heap) *ignored_options;
-
-/* Input file names. */
-const char **in_fnames;
-unsigned num_in_fnames;
-
-static bool common_handle_option (struct gcc_options *opts,
- struct gcc_options *opts_set,
- const struct cl_decoded_option *decoded,
- unsigned int lang_mask, int kind,
- location_t loc,
- const struct cl_option_handlers *handlers,
- diagnostic_context *dc);
static void handle_param (struct gcc_options *opts,
struct gcc_options *opts_set, const char *carg);
-static char *write_langs (unsigned int lang_mask);
-static void complain_wrong_lang (const struct cl_decoded_option *,
- unsigned int lang_mask);
static void set_debug_level (enum debug_info_type type, int extended,
const char *arg, struct gcc_options *opts,
struct gcc_options *opts_set);
static void set_fast_math_flags (struct gcc_options *opts, int set);
+static void decode_d_option (const char *arg);
static void set_unsafe_math_optimizations_flags (struct gcc_options *opts,
int set);
static void enable_warning_as_error (const char *arg, int value,
@@ -208,155 +210,10 @@ static void enable_warning_as_error (const char *arg, int value,
location_t loc,
diagnostic_context *dc);
-/* Return a malloced slash-separated list of languages in MASK. */
-static char *
-write_langs (unsigned int mask)
-{
- unsigned int n = 0, len = 0;
- const char *lang_name;
- char *result;
-
- for (n = 0; (lang_name = lang_names[n]) != 0; n++)
- if (mask & (1U << n))
- len += strlen (lang_name) + 1;
-
- result = XNEWVEC (char, len);
- len = 0;
- for (n = 0; (lang_name = lang_names[n]) != 0; n++)
- if (mask & (1U << n))
- {
- if (len)
- result[len++] = '/';
- strcpy (result + len, lang_name);
- len += strlen (lang_name);
- }
-
- result[len] = 0;
-
- return result;
-}
-
-/* Complain that switch DECODED does not apply to this front end (mask
- LANG_MASK). */
-static void
-complain_wrong_lang (const struct cl_decoded_option *decoded,
- unsigned int lang_mask)
-{
- const struct cl_option *option = &cl_options[decoded->opt_index];
- const char *text = decoded->orig_option_with_args_text;
- char *ok_langs = NULL, *bad_lang = NULL;
- unsigned int opt_flags = option->flags;
-
- if (!lang_hooks.complain_wrong_lang_p (option))
- return;
-
- opt_flags &= ((1U << cl_lang_count) - 1) | CL_DRIVER;
- if (opt_flags != CL_DRIVER)
- ok_langs = write_langs (opt_flags);
- if (lang_mask != CL_DRIVER)
- bad_lang = write_langs (lang_mask);
-
- if (opt_flags == CL_DRIVER)
- error ("command line option %qs is valid for the driver but not for %s",
- text, bad_lang);
- else if (lang_mask == CL_DRIVER)
- gcc_unreachable ();
- else
- /* Eventually this should become a hard error IMO. */
- warning (0, "command line option %qs is valid for %s but not for %s",
- text, ok_langs, bad_lang);
-
- free (ok_langs);
- free (bad_lang);
-}
-
-/* Buffer the unknown option described by the string OPT. Currently,
- we only complain about unknown -Wno-* options if they may have
- prevented a diagnostic. Otherwise, we just ignore them.
- Note that if we do complain, it is only as a warning, not an error;
- passing the compiler an unrecognised -Wno-* option should never
- change whether the compilation succeeds or fails. */
-
-static void postpone_unknown_option_warning(const char *opt)
-{
- VEC_safe_push (const_char_p, heap, ignored_options, opt);
-}
-
-/* Produce a warning for each option previously buffered. */
-
-void print_ignored_options (void)
-{
- location_t saved_loc = input_location;
-
- input_location = 0;
-
- while (!VEC_empty (const_char_p, ignored_options))
- {
- const char *opt;
- opt = VEC_pop (const_char_p, ignored_options);
- warning (0, "unrecognized command line option \"%s\"", opt);
- }
-
- input_location = saved_loc;
-}
-
-/* Handle an unknown option DECODED, returning true if an error should be
- given. */
-
-static bool
-unknown_option_callback (const struct cl_decoded_option *decoded)
-{
- const char *opt = decoded->arg;
-
- if (opt[1] == 'W' && opt[2] == 'n' && opt[3] == 'o' && opt[4] == '-'
- && !(decoded->errors & CL_ERR_NEGATIVE))
- {
- /* We don't generate warnings for unknown -Wno-* options unless
- we issue diagnostics. */
- postpone_unknown_option_warning (opt);
- return false;
- }
- else
- return true;
-}
-
-/* Note that an option DECODED has been successfully handled with a
- handler for mask MASK. */
-
-static void
-post_handling_callback (const struct cl_decoded_option *decoded ATTRIBUTE_UNUSED,
- unsigned int mask ATTRIBUTE_UNUSED)
-{
-#ifdef ENABLE_LTO
- lto_register_user_option (decoded->opt_index, decoded->arg,
- decoded->value, mask);
-#endif
-}
-
-/* Handle a front-end option; arguments and return value as for
- handle_option. */
-
-static bool
-lang_handle_option (struct gcc_options *opts,
- struct gcc_options *opts_set,
- const struct cl_decoded_option *decoded,
- unsigned int lang_mask ATTRIBUTE_UNUSED, int kind,
- location_t loc,
- const struct cl_option_handlers *handlers,
- diagnostic_context *dc)
-{
- gcc_assert (opts == &global_options);
- gcc_assert (opts_set == &global_options_set);
- gcc_assert (dc == global_dc);
- gcc_assert (decoded->canonical_option_num_elements <= 2);
- return lang_hooks.handle_option (decoded->opt_index, decoded->arg,
- decoded->value, kind, loc, handlers);
-}
-
/* Handle a back-end option; arguments and return value as for
handle_option. */
-static bool
+bool
target_handle_option (struct gcc_options *opts,
struct gcc_options *opts_set,
const struct cl_decoded_option *decoded,
@@ -378,15 +235,6 @@ target_handle_option (struct gcc_options *opts,
decoded->value);
}
-/* Handle FILENAME from the command line. */
-static void
-add_input_filename (const char *filename)
-{
- num_in_fnames++;
- in_fnames = XRESIZEVEC (const char *, in_fnames, num_in_fnames);
- in_fnames[num_in_fnames - 1] = filename;
-}
-
/* Add comma-separated strings to a char_p vector. */
static void
@@ -428,61 +276,6 @@ add_comma_separated_to_vector (void **pvec, const char *arg)
*pvec = vec;
}
-/* Handle the vector of command line options (located at LOC), storing
- the results of processing DECODED_OPTIONS and DECODED_OPTIONS_COUNT
- in OPTS and OPTS_SET and using DC for diagnostic state. LANG_MASK
- contains has a single bit set representing the current language.
- HANDLERS describes what functions to call for the options. */
-static void
-read_cmdline_options (struct gcc_options *opts, struct gcc_options *opts_set,
- struct cl_decoded_option *decoded_options,
- unsigned int decoded_options_count,
- location_t loc,
- unsigned int lang_mask,
- const struct cl_option_handlers *handlers,
- diagnostic_context *dc)
-{
- unsigned int i;
-
- for (i = 1; i < decoded_options_count; i++)
- {
- if (decoded_options[i].opt_index == OPT_SPECIAL_input_file)
- {
- /* Input files should only ever appear on the main command
- line. */
- gcc_assert (opts == &global_options);
- gcc_assert (opts_set == &global_options_set);
-
- if (main_input_filename == NULL)
- {
- main_input_filename = decoded_options[i].arg;
- main_input_baselength
- = base_of_path (main_input_filename, &main_input_basename);
- }
- add_input_filename (decoded_options[i].arg);
- continue;
- }
-
- read_cmdline_option (opts, opts_set,
- decoded_options + i, loc, lang_mask, handlers,
- dc);
- }
-}
-
-/* Language mask determined at initialization. */
-static unsigned int initial_lang_mask;
-
-/* Initialize global options-related settings at start-up. */
-
-void
-init_options_once (void)
-{
- /* Perform language-specific options initialization. */
- initial_lang_mask = lang_hooks.option_lang_mask ();
-
- lang_hooks.initialize_diagnostics (global_dc);
-}
-
/* Initialize OPTS and OPTS_SET before using them in parsing options. */
void
@@ -519,21 +312,6 @@ init_options_struct (struct gcc_options *opts, struct gcc_options *opts_set)
targetm.target_option.init_struct (opts);
}
-/* Decode command-line options to an array, like
- decode_cmdline_options_to_array and with the same arguments but
- using the default lang_mask. */
-
-void
-decode_cmdline_options_to_array_default_mask (unsigned int argc,
- const char **argv,
- struct cl_decoded_option **decoded_options,
- unsigned int *decoded_options_count)
-{
- decode_cmdline_options_to_array (argc, argv,
- initial_lang_mask | CL_COMMON | CL_TARGET,
- decoded_options, decoded_options_count);
-}
-
/* If indicated by the optimization level LEVEL (-Os if SIZE is set,
-Ofast if FAST is set), apply the option DEFAULT_OPT to OPTS and
OPTS_SET, diagnostic context DC, location LOC, with language mask
@@ -725,7 +503,7 @@ static const struct default_options default_options_table[] =
/* Default the options in OPTS and OPTS_SET based on the optimization
settings in DECODED_OPTIONS and DECODED_OPTIONS_COUNT. */
-static void
+void
default_options_optimization (struct gcc_options *opts,
struct gcc_options *opts_set,
struct cl_decoded_option *decoded_options,
@@ -826,69 +604,10 @@ default_options_optimization (struct gcc_options *opts,
ofast, lang_mask, handlers, loc, dc);
}
-static void finish_options (struct gcc_options *, struct gcc_options *);
-
-/* Set *HANDLERS to the default set of option handlers for use in the
- compilers proper (not the driver). */
-void
-set_default_handlers (struct cl_option_handlers *handlers)
-{
- handlers->unknown_option_callback = unknown_option_callback;
- handlers->wrong_lang_callback = complain_wrong_lang;
- handlers->post_handling_callback = post_handling_callback;
- handlers->num_handlers = 3;
- handlers->handlers[0].handler = lang_handle_option;
- handlers->handlers[0].mask = initial_lang_mask;
- handlers->handlers[1].handler = common_handle_option;
- handlers->handlers[1].mask = CL_COMMON;
- handlers->handlers[2].handler = target_handle_option;
- handlers->handlers[2].mask = CL_TARGET;
-}
-
-/* Parse command line options and set default flag values. Do minimal
- options processing. The decoded options are in *DECODED_OPTIONS
- and *DECODED_OPTIONS_COUNT; settings go in OPTS, OPTS_SET and DC;
- the options are located at LOC. */
-void
-decode_options (struct gcc_options *opts, struct gcc_options *opts_set,
- struct cl_decoded_option *decoded_options,
- unsigned int decoded_options_count,
- location_t loc, diagnostic_context *dc)
-{
- struct cl_option_handlers handlers;
-
- unsigned int lang_mask;
-
- lang_mask = initial_lang_mask;
-
- set_default_handlers (&handlers);
-
- /* Enable -Werror=coverage-mismatch by default. */
- control_warning_option (OPT_Wcoverage_mismatch, (int) DK_ERROR, true,
- loc, lang_mask,
- &handlers, opts, opts_set, dc);
-
- default_options_optimization (opts, opts_set,
- decoded_options, decoded_options_count,
- loc, lang_mask, &handlers, dc);
-
-#ifdef ENABLE_LTO
- /* Clear any options currently held for LTO. */
- lto_clear_user_options ();
-#endif
-
- read_cmdline_options (opts, opts_set,
- decoded_options, decoded_options_count,
- loc, lang_mask,
- &handlers, dc);
-
- finish_options (opts, opts_set);
-}
-
/* After all options have been read into OPTS and OPTS_SET, finalize
settings of those options and diagnose incompatible
combinations. */
-static void
+void
finish_options (struct gcc_options *opts, struct gcc_options *opts_set)
{
static bool first_time_p = true;
@@ -1419,7 +1138,7 @@ print_specific_help (unsigned int include_flags,
extra handling need to be listed here; if you simply want
DECODED->value assigned to a variable, it happens automatically. */
-static bool
+bool
common_handle_option (struct gcc_options *opts,
struct gcc_options *opts_set,
const struct cl_decoded_option *decoded,
@@ -2145,76 +1864,71 @@ set_debug_level (enum debug_info_type type, int extended, const char *arg,
}
}
-/* Return 1 if option OPT_IDX is enabled in OPTS, 0 if it is disabled,
- or -1 if it isn't a simple on-off switch. */
+/* Arrange to dump core on error. (The regular error message is still
+ printed first, except in the case of abort ().) */
-int
-option_enabled (int opt_idx, void *opts)
+static void
+setup_core_dumping (void)
{
- const struct cl_option *option = &(cl_options[opt_idx]);
- struct gcc_options *optsg = (struct gcc_options *) opts;
- void *flag_var = option_flag_var (opt_idx, optsg);
-
- if (flag_var)
- switch (option->var_type)
- {
- case CLVC_BOOLEAN:
- return *(int *) flag_var != 0;
-
- case CLVC_EQUAL:
- return *(int *) flag_var == option->var_value;
-
- case CLVC_BIT_CLEAR:
- return (*(int *) flag_var & option->var_value) == 0;
-
- case CLVC_BIT_SET:
- return (*(int *) flag_var & option->var_value) != 0;
-
- case CLVC_STRING:
- case CLVC_DEFER:
- break;
- }
- return -1;
+#ifdef SIGABRT
+ signal (SIGABRT, SIG_DFL);
+#endif
+#if defined(HAVE_SETRLIMIT)
+ {
+ struct rlimit rlim;
+ if (getrlimit (RLIMIT_CORE, &rlim) != 0)
+ fatal_error ("getting core file size maximum limit: %m");
+ rlim.rlim_cur = rlim.rlim_max;
+ if (setrlimit (RLIMIT_CORE, &rlim) != 0)
+ fatal_error ("setting core file size limit to maximum: %m");
+ }
+#endif
+ diagnostic_abort_on_error (global_dc);
}
-/* Fill STATE with the current state of option OPTION in OPTS. Return
- true if there is some state to store. */
+/* Parse a -d<ARG> command line switch. */
-bool
-get_option_state (struct gcc_options *opts, int option,
- struct cl_option_state *state)
+static void
+decode_d_option (const char *arg)
{
- void *flag_var = option_flag_var (option, opts);
-
- if (flag_var == 0)
- return false;
+ int c;
- switch (cl_options[option].var_type)
- {
- case CLVC_BOOLEAN:
- case CLVC_EQUAL:
- state->data = flag_var;
- state->size = sizeof (int);
- break;
-
- case CLVC_BIT_CLEAR:
- case CLVC_BIT_SET:
- state->ch = option_enabled (option, opts);
- state->data = &state->ch;
- state->size = 1;
- break;
-
- case CLVC_STRING:
- state->data = *(const char **) flag_var;
- if (state->data == 0)
- state->data = "";
- state->size = strlen ((const char *) state->data) + 1;
- break;
+ while (*arg)
+ switch (c = *arg++)
+ {
+ case 'A':
+ flag_debug_asm = 1;
+ break;
+ case 'p':
+ flag_print_asm_name = 1;
+ break;
+ case 'P':
+ flag_dump_rtl_in_asm = 1;
+ flag_print_asm_name = 1;
+ break;
+ case 'v':
+ graph_dump_format = vcg;
+ break;
+ case 'x':
+ rtl_dump_and_exit = 1;
+ break;
+ case 'D': /* These are handled by the preprocessor. */
+ case 'I':
+ case 'M':
+ case 'N':
+ case 'U':
+ break;
+ case 'H':
+ setup_core_dumping ();
+ break;
+ case 'a':
+ enable_rtl_dump_file ();
+ break;
- case CLVC_DEFER:
- return false;
- }
- return true;
+ default:
+ warning (0, "unrecognized gcc debugging option: %c", c);
+ break;
+ }
}
/* Enable (or disable if VALUE is 0) a warning option ARG (language