From 4ff887c594396a9a889db4ba873fd8259fd6f50a Mon Sep 17 00:00:00 2001 From: jsm28 Date: Sat, 23 Oct 2010 22:26:08 +0000 Subject: [PATCH] * gcc.c (n_switches_alloc_debug_check): New. (set_option_handlers): New. (process_command): Use set_option_handlers. (do_self_spec): Pass spec-generated options through option handlers. (main): Also save and restore n_switches_alloc when swapping switch arrays. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@165891 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/ChangeLog | 10 +++++ gcc/gcc.c | 126 +++++++++++++++++++++++++++++++--------------------------- 2 files changed, 78 insertions(+), 58 deletions(-) diff --git a/gcc/ChangeLog b/gcc/ChangeLog index bae819764bf..809f3bec33b 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,13 @@ +2010-10-23 Joseph Myers + + * gcc.c (n_switches_alloc_debug_check): New. + (set_option_handlers): New. + (process_command): Use set_option_handlers. + (do_self_spec): Pass spec-generated options through option + handlers. + (main): Also save and restore n_switches_alloc when swapping + switch arrays. + 2010-10-23 Richard Henderson PR target/46144 diff --git a/gcc/gcc.c b/gcc/gcc.c index 30029d5f329..13635d52b8a 100644 --- a/gcc/gcc.c +++ b/gcc/gcc.c @@ -2810,6 +2810,8 @@ static struct switchstr *switches_debug_check[2]; static int n_switches_debug_check[2]; +static int n_switches_alloc_debug_check[2]; + static char *debug_check_temp_file[2]; /* Language is one of three things: @@ -3506,6 +3508,19 @@ driver_handle_option (struct gcc_options *opts, return true; } +/* Put the driver's standard set of option handlers in *HANDLERS. */ + +static void +set_option_handlers (struct cl_option_handlers *handlers) +{ + handlers->unknown_option_callback = driver_unknown_option_callback; + handlers->wrong_lang_callback = driver_wrong_lang_callback; + handlers->post_handling_callback = driver_post_handling_callback; + handlers->num_handlers = 1; + handlers->handlers[0].handler = driver_handle_option; + handlers->handlers[0].mask = CL_DRIVER; +} + /* Create the vector `switches' and its contents. Store its length in `n_switches'. */ @@ -3730,12 +3745,7 @@ process_command (unsigned int decoded_options_count, last_language_n_infiles = -1; - handlers.unknown_option_callback = driver_unknown_option_callback; - handlers.wrong_lang_callback = driver_wrong_lang_callback; - handlers.post_handling_callback = driver_post_handling_callback; - handlers.num_handlers = 1; - handlers.handlers[0].handler = driver_handle_option; - handlers.handlers[0].mask = CL_DRIVER; + set_option_handlers (&handlers); for (j = 1; j < decoded_options_count; j++) { @@ -4250,66 +4260,59 @@ do_self_spec (const char *spec) if (argbuf_index > 0) { - switches = XRESIZEVEC (struct switchstr, switches, - n_switches + argbuf_index + 1); + const char **argbuf_copy; + struct cl_decoded_option *decoded_options; + struct cl_option_handlers handlers; + unsigned int decoded_options_count; + unsigned int j; - for (i = 0; i < argbuf_index; i++) - { - struct switchstr *sw; - const char *p = argbuf[i]; - int c = *p; - - /* Each switch should start with '-'. */ - if (c != '-') - fatal_error ("switch %qs does not start with %<-%>", argbuf[i]); + /* Create a copy of argbuf with a dummy argv[0] entry for + decode_cmdline_options_to_array. */ + argbuf_copy = XNEWVEC (const char *, argbuf_index + 1); + argbuf_copy[0] = ""; + memcpy (argbuf_copy + 1, argbuf, argbuf_index * sizeof (const char *)); - p++; - c = *p; + decode_cmdline_options_to_array (argbuf_index + 1, argbuf_copy, + CL_DRIVER, &decoded_options, + &decoded_options_count); - sw = &switches[n_switches++]; - sw->part1 = p; - sw->live_cond = 0; - sw->validated = 0; - sw->ordering = 0; + set_option_handlers (&handlers); - /* Deal with option arguments in separate argv elements. */ - if ((SWITCH_TAKES_ARG (c) > (p[1] != 0)) - || WORD_SWITCH_TAKES_ARG (p)) + for (j = 1; j < decoded_options_count; j++) + { + switch (decoded_options[j].opt_index) { - int j = 0; - int n_args = WORD_SWITCH_TAKES_ARG (p); + case OPT_SPECIAL_input_file: + /* Specs should only generate options, not input + files. */ + if (strcmp (decoded_options[j].arg, "-") != 0) + fatal_error ("switch %qs does not start with %<-%>", + decoded_options[j].arg); + else + fatal_error ("spec-generated switch is just %<-%>"); + break; - if (n_args == 0) - { - /* Count only the option arguments in separate argv elements. */ - n_args = SWITCH_TAKES_ARG (c) - (p[1] != 0); - } - if (i + n_args >= argbuf_index) - fatal_error ("argument to %<-%s%> is missing", p); - sw->args - = XNEWVEC (const char *, n_args + 1); - while (j < n_args) - sw->args[j++] = argbuf[++i]; - /* Null-terminate the vector. */ - sw->args[j] = 0; - } - else if (c == 'o') - { - /* On some systems, ld cannot handle "-o" without - a space. So split the option from its argument. */ - char *part1 = XNEWVEC (char, 2); - part1[0] = c; - part1[1] = '\0'; - - sw->part1 = part1; - sw->args = XNEWVEC (const char *, 2); - sw->args[0] = xstrdup (p+1); - sw->args[1] = 0; + case OPT_fcompare_debug_second: + case OPT_fcompare_debug: + case OPT_fcompare_debug_: + case OPT_o: + /* Avoid duplicate processing of some options from + compare-debug specs; just save them here. */ + save_switch (decoded_options[j].canonical_option[0], + (decoded_options[j].canonical_option_num_elements + - 1), + &decoded_options[j].canonical_option[1], false); + break; + + default: + read_cmdline_option (&global_options, &global_options_set, + decoded_options + j, CL_DRIVER, &handlers, + global_dc); + break; } - else - sw->args = 0; } + alloc_switch (); switches[n_switches].part1 = 0; } } @@ -6271,14 +6274,17 @@ main (int argc, char **argv) if (!compare_debug_second) { n_switches_debug_check[1] = n_switches; + n_switches_alloc_debug_check[1] = n_switches_alloc; switches_debug_check[1] = XDUPVEC (struct switchstr, switches, - n_switches + 1); + n_switches_alloc); do_self_spec ("%:compare-debug-self-opt()"); n_switches_debug_check[0] = n_switches; + n_switches_alloc_debug_check[0] = n_switches_alloc; switches_debug_check[0] = switches; n_switches = n_switches_debug_check[1]; + n_switches_alloc = n_switches_alloc_debug_check[1]; switches = switches_debug_check[1]; } @@ -6294,9 +6300,11 @@ main (int argc, char **argv) if (!compare_debug_second) { n_switches_debug_check[1] = n_switches; + n_switches_alloc_debug_check[1] = n_switches_alloc; switches_debug_check[1] = switches; compare_debug = -compare_debug; n_switches = n_switches_debug_check[0]; + n_switches_alloc = n_switches_debug_check[0]; switches = switches_debug_check[0]; } } @@ -6712,12 +6720,14 @@ warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\n" compare_debug = -compare_debug; n_switches = n_switches_debug_check[1]; + n_switches_alloc = n_switches_alloc_debug_check[1]; switches = switches_debug_check[1]; value = do_spec (input_file_compiler->spec); compare_debug = -compare_debug; n_switches = n_switches_debug_check[0]; + n_switches_alloc = n_switches_alloc_debug_check[0]; switches = switches_debug_check[0]; if (value < 0) -- 2.11.0