aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoseph Myers <joseph@codesourcery.com>2010-07-28 10:36:21 +0100
committerJoseph Myers <jsm28@gcc.gnu.org>2010-07-28 10:36:21 +0100
commiteea13eaddc2a75a685f8a074e57f3510f9ca9c57 (patch)
tree8fceb4a0955d8a639a2e7420a4f65b586c873f62
parent57e15568e886ab57612d45618deb416c8f63eec2 (diff)
downloadgcc-eea13eaddc2a75a685f8a074e57f3510f9ca9c57.zip
gcc-eea13eaddc2a75a685f8a074e57f3510f9ca9c57.tar.gz
gcc-eea13eaddc2a75a685f8a074e57f3510f9ca9c57.tar.bz2
darwin-driver.c (SWITCH_TAKES_ARG, [...]): Remove.
* config/darwin-driver.c (SWITCH_TAKES_ARG, WORD_SWITCH_TAKES_ARG): Remove. * cppspec.c (SWITCH_TAKES_ARG, WORD_SWITCH_TAKES_ARG): Remove. * defaults.h (DEFAULT_SWITCH_TAKES_ARG, DEFAULT_WORD_SWITCH_TAKES_ARG): Move from gcc.h. (SWITCH_TAKES_ARG, WORD_SWITCH_TAKES_ARG): Move default definitions from gcc.c. * gcc.c (SWITCH_TAKES_ARG, WORD_SWITCH_TAKES_ARG): Move to defaults.h. * gcc.h (DEFAULT_SWITCH_TAKES_ARG, DEFAULT_WORD_SWITCH_TAKES_ARG): Move to defaults.h. * opts-common.c: Include tm.h. (decode_cmdline_option): Use SWITCH_TAKES_ARG and WORD_SWITCH_TAKES_ARG to count arguments to unknown options. Handle more than one argument. Set canonical_option_num_elements. (decode_cmdline_options_to_array): Set canonical_option_num_elements and trailing elements of canonical_option. * opts.h (struct cl_decoded_option): Allow four elements in canonical_option. Add field canonical_option_num_elements. * Makefile.in (opts-common.o): Update dependencies. ada: * gcc-interface/misc.c (gnat_init_options): Ignore erroneous options. Check canonical_option_num_elements on options copied. fortran: * gfortranspec.c (SWITCH_TAKES_ARG, WORD_SWITCH_TAKES_ARG): Remove. From-SVN: r162620
-rw-r--r--gcc/ChangeLog24
-rw-r--r--gcc/Makefile.in2
-rw-r--r--gcc/ada/ChangeLog5
-rw-r--r--gcc/ada/gcc-interface/misc.c7
-rw-r--r--gcc/config/darwin-driver.c8
-rw-r--r--gcc/cppspec.c8
-rw-r--r--gcc/defaults.h32
-rw-r--r--gcc/fortran/ChangeLog5
-rw-r--r--gcc/fortran/gfortranspec.c16
-rw-r--r--gcc/gcc.c7
-rw-r--r--gcc/gcc.h25
-rw-r--r--gcc/opts-common.c71
-rw-r--r--gcc/opts.h10
13 files changed, 135 insertions, 85 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 2ec4403..177c873 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,27 @@
+2010-07-28 Joseph Myers <joseph@codesourcery.com>
+
+ * config/darwin-driver.c (SWITCH_TAKES_ARG,
+ WORD_SWITCH_TAKES_ARG): Remove.
+ * cppspec.c (SWITCH_TAKES_ARG, WORD_SWITCH_TAKES_ARG): Remove.
+ * defaults.h (DEFAULT_SWITCH_TAKES_ARG,
+ DEFAULT_WORD_SWITCH_TAKES_ARG): Move from gcc.h.
+ (SWITCH_TAKES_ARG, WORD_SWITCH_TAKES_ARG): Move default
+ definitions from gcc.c.
+ * gcc.c (SWITCH_TAKES_ARG, WORD_SWITCH_TAKES_ARG): Move to
+ defaults.h.
+ * gcc.h (DEFAULT_SWITCH_TAKES_ARG, DEFAULT_WORD_SWITCH_TAKES_ARG):
+ Move to defaults.h.
+ * opts-common.c: Include tm.h.
+ (decode_cmdline_option): Use SWITCH_TAKES_ARG and
+ WORD_SWITCH_TAKES_ARG to count arguments to unknown options.
+ Handle more than one argument. Set canonical_option_num_elements.
+ (decode_cmdline_options_to_array): Set
+ canonical_option_num_elements and trailing elements of
+ canonical_option.
+ * opts.h (struct cl_decoded_option): Allow four elements in
+ canonical_option. Add field canonical_option_num_elements.
+ * Makefile.in (opts-common.o): Update dependencies.
+
2010-07-28 Eric Botcazou <ebotcazou@adacore.com>
PR middle-end/44790
diff --git a/gcc/Makefile.in b/gcc/Makefile.in
index 6a99e23..49724aa 100644
--- a/gcc/Makefile.in
+++ b/gcc/Makefile.in
@@ -2806,7 +2806,7 @@ opts.o : opts.c opts.h options.h $(TOPLEV_H) $(DIAGNOSTIC_CORE_H) $(CONFIG_H) $(
$(FLAGS_H) $(PARAMS_H) $(TREE_PASS_H) $(DBGCNT_H) debug.h \
$(PLUGIN_H) $(EXCEPT_H) $(LTO_STREAMER_H) opts-diagnostic.h
opts-common.o : opts-common.c opts.h options.h $(CONFIG_H) $(SYSTEM_H) \
- coretypes.h intl.h $(DIAGNOSTIC_H)
+ coretypes.h intl.h $(DIAGNOSTIC_H) $(TM_H)
targhooks.o : targhooks.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TREE_H) \
$(EXPR_H) $(TM_H) $(RTL_H) $(TM_P_H) $(FUNCTION_H) output.h $(TOPLEV_H) $(DIAGNOSTIC_CORE_H) \
$(MACHMODE_H) $(TARGET_DEF_H) $(TARGET_H) $(GGC_H) gt-targhooks.h \
diff --git a/gcc/ada/ChangeLog b/gcc/ada/ChangeLog
index 6b983fc..c6198c8 100644
--- a/gcc/ada/ChangeLog
+++ b/gcc/ada/ChangeLog
@@ -1,3 +1,8 @@
+2010-07-28 Joseph Myers <joseph@codesourcery.com>
+
+ * gcc-interface/misc.c (gnat_init_options): Ignore erroneous
+ options. Check canonical_option_num_elements on options copied.
+
2010-07-27 Joseph Myers <joseph@codesourcery.com>
* gcc-interface/misc.c (gnat_handle_option): Update prototype and
diff --git a/gcc/ada/gcc-interface/misc.c b/gcc/ada/gcc-interface/misc.c
index 01b33a3..c104e29 100644
--- a/gcc/ada/gcc-interface/misc.c
+++ b/gcc/ada/gcc-interface/misc.c
@@ -272,8 +272,13 @@ gnat_init_options (unsigned int decoded_options_count,
save_argc = 0;
for (i = 0; i < decoded_options_count; i++)
{
+ if (decoded_options[i].errors
+ || decoded_options[i].opt_index == OPT_SPECIAL_unknown)
+ continue;
+ gcc_assert (decoded_options[i].canonical_option_num_elements >= 1
+ && decoded_options[i].canonical_option_num_elements <= 2);
save_argv[save_argc++] = decoded_options[i].canonical_option[0];
- if (decoded_options[i].canonical_option[1] != NULL)
+ if (decoded_options[i].canonical_option_num_elements >= 2)
save_argv[save_argc++] = decoded_options[i].canonical_option[1];
}
save_argv[save_argc] = NULL;
diff --git a/gcc/config/darwin-driver.c b/gcc/config/darwin-driver.c
index f66e5a0..b23efc5 100644
--- a/gcc/config/darwin-driver.c
+++ b/gcc/config/darwin-driver.c
@@ -27,14 +27,6 @@ along with GCC; see the file COPYING3. If not see
#include <sys/sysctl.h>
#include "xregex.h"
-#ifndef SWITCH_TAKES_ARG
-#define SWITCH_TAKES_ARG(CHAR) DEFAULT_SWITCH_TAKES_ARG(CHAR)
-#endif
-
-#ifndef WORD_SWITCH_TAKES_ARG
-#define WORD_SWITCH_TAKES_ARG(STR) DEFAULT_WORD_SWITCH_TAKES_ARG (STR)
-#endif
-
/* When running on a Darwin system and using that system's headers and
libraries, default the -mmacosx-version-min flag to be the version
of the system on which the compiler is running. */
diff --git a/gcc/cppspec.c b/gcc/cppspec.c
index c3adaa1..f9a5268 100644
--- a/gcc/cppspec.c
+++ b/gcc/cppspec.c
@@ -30,14 +30,6 @@ along with GCC; see the file COPYING3. If not see
assume the user knows what they're doing. If no explicit input is
mentioned, it will read stdin. */
-#ifndef SWITCH_TAKES_ARG
-#define SWITCH_TAKES_ARG(CHAR) DEFAULT_SWITCH_TAKES_ARG(CHAR)
-#endif
-
-#ifndef WORD_SWITCH_TAKES_ARG
-#define WORD_SWITCH_TAKES_ARG(STR) DEFAULT_WORD_SWITCH_TAKES_ARG (STR)
-#endif
-
/* Suffixes for known sorts of input files. Note that we do not list
files which are normally considered to have been preprocessed already,
since the user's expectation is that `cpp' always preprocesses. */
diff --git a/gcc/defaults.h b/gcc/defaults.h
index c2e68a7..c772ff5 100644
--- a/gcc/defaults.h
+++ b/gcc/defaults.h
@@ -32,6 +32,38 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
#define GET_ENVIRONMENT(VALUE, NAME) do { (VALUE) = getenv (NAME); } while (0)
#endif
+/* This defines which switch letters take arguments. */
+
+#define DEFAULT_SWITCH_TAKES_ARG(CHAR) \
+ ((CHAR) == 'D' || (CHAR) == 'U' || (CHAR) == 'o' \
+ || (CHAR) == 'e' || (CHAR) == 'T' || (CHAR) == 'u' \
+ || (CHAR) == 'I' || (CHAR) == 'J' || (CHAR) == 'm' \
+ || (CHAR) == 'x' || (CHAR) == 'L' || (CHAR) == 'A' \
+ || (CHAR) == 'B' )
+
+/* This defines which multi-letter switches take arguments. */
+
+#define DEFAULT_WORD_SWITCH_TAKES_ARG(STR) \
+ (!strcmp (STR, "Tdata") || !strcmp (STR, "Ttext") \
+ || !strcmp (STR, "Tbss") || !strcmp (STR, "include") \
+ || !strcmp (STR, "imacros") || !strcmp (STR, "aux-info") \
+ || !strcmp (STR, "idirafter") || !strcmp (STR, "iprefix") \
+ || !strcmp (STR, "iwithprefix") || !strcmp (STR, "iwithprefixbefore") \
+ || !strcmp (STR, "iquote") || !strcmp (STR, "isystem") \
+ || !strcmp (STR, "isysroot") \
+ || !strcmp (STR, "-param") || !strcmp (STR, "specs") \
+ || !strcmp (STR, "MF") || !strcmp (STR, "MT") || !strcmp (STR, "MQ") \
+ || !strcmp (STR, "fintrinsic-modules-path") \
+ || !strcmp (STR, "dumpbase") || !strcmp (STR, "dumpdir"))
+
+#ifndef SWITCH_TAKES_ARG
+#define SWITCH_TAKES_ARG(CHAR) DEFAULT_SWITCH_TAKES_ARG (CHAR)
+#endif
+
+#ifndef WORD_SWITCH_TAKES_ARG
+#define WORD_SWITCH_TAKES_ARG(STR) DEFAULT_WORD_SWITCH_TAKES_ARG (STR)
+#endif
+
/* Store in OUTPUT a string (made with alloca) containing an
assembler-name for a local static variable or function named NAME.
LABELNO is an integer which is different for each call. */
diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog
index e0b7374..f03041e 100644
--- a/gcc/fortran/ChangeLog
+++ b/gcc/fortran/ChangeLog
@@ -1,3 +1,8 @@
+2010-07-28 Joseph Myers <joseph@codesourcery.com>
+
+ * gfortranspec.c (SWITCH_TAKES_ARG, WORD_SWITCH_TAKES_ARG):
+ Remove.
+
2010-07-28 Tobias Burnus <burnus@net-b.de>
PR fortran/45077
diff --git a/gcc/fortran/gfortranspec.c b/gcc/fortran/gfortranspec.c
index 61f1547..0c3e9ab 100644
--- a/gcc/fortran/gfortranspec.c
+++ b/gcc/fortran/gfortranspec.c
@@ -113,22 +113,6 @@ static void append_arg (const char *);
static int g77_newargc;
static const char **g77_newargv;
-/* --- This comes from gcc.c (2.8.1) verbatim: */
-
-/* This defines which switch letters take arguments. */
-
-#ifndef SWITCH_TAKES_ARG
-#define SWITCH_TAKES_ARG(CHAR) DEFAULT_SWITCH_TAKES_ARG(CHAR)
-#endif
-
-/* This defines which multi-letter switches take arguments. */
-
-#ifndef WORD_SWITCH_TAKES_ARG
-#define WORD_SWITCH_TAKES_ARG(STR) DEFAULT_WORD_SWITCH_TAKES_ARG (STR)
-#endif
-
-/* --- End of verbatim. */
-
/* Assumes text[0] == '-'. Returns number of argv items that belong to
(and follow) this one, an option id for options important to the
caller, and a pointer to the first char of the arg, if embedded (else
diff --git a/gcc/gcc.c b/gcc/gcc.c
index efaf813..62b3378 100644
--- a/gcc/gcc.c
+++ b/gcc/gcc.c
@@ -946,13 +946,6 @@ struct user_specs
static struct user_specs *user_specs_head, *user_specs_tail;
-#ifndef SWITCH_TAKES_ARG
-#define SWITCH_TAKES_ARG(CHAR) DEFAULT_SWITCH_TAKES_ARG(CHAR)
-#endif
-
-#ifndef WORD_SWITCH_TAKES_ARG
-#define WORD_SWITCH_TAKES_ARG(STR) DEFAULT_WORD_SWITCH_TAKES_ARG (STR)
-#endif
#ifdef HAVE_TARGET_EXECUTABLE_SUFFIX
/* This defines which switches stop a full compilation. */
diff --git a/gcc/gcc.h b/gcc/gcc.h
index af8f002..8d59773 100644
--- a/gcc/gcc.h
+++ b/gcc/gcc.h
@@ -32,31 +32,6 @@ struct spec_function
const char *(*func) (int, const char **);
};
-/* This defines which switch letters take arguments. */
-
-#define DEFAULT_SWITCH_TAKES_ARG(CHAR) \
- ((CHAR) == 'D' || (CHAR) == 'U' || (CHAR) == 'o' \
- || (CHAR) == 'e' || (CHAR) == 'T' || (CHAR) == 'u' \
- || (CHAR) == 'I' || (CHAR) == 'J' || (CHAR) == 'm' \
- || (CHAR) == 'x' || (CHAR) == 'L' || (CHAR) == 'A' \
- || (CHAR) == 'B' )
-
-/* This defines which multi-letter switches take arguments. */
-
-#define DEFAULT_WORD_SWITCH_TAKES_ARG(STR) \
- (!strcmp (STR, "Tdata") || !strcmp (STR, "Ttext") \
- || !strcmp (STR, "Tbss") || !strcmp (STR, "include") \
- || !strcmp (STR, "imacros") || !strcmp (STR, "aux-info") \
- || !strcmp (STR, "idirafter") || !strcmp (STR, "iprefix") \
- || !strcmp (STR, "iwithprefix") || !strcmp (STR, "iwithprefixbefore") \
- || !strcmp (STR, "iquote") || !strcmp (STR, "isystem") \
- || !strcmp (STR, "isysroot") \
- || !strcmp (STR, "-param") || !strcmp (STR, "specs") \
- || !strcmp (STR, "MF") || !strcmp (STR, "MT") || !strcmp (STR, "MQ") \
- || !strcmp (STR, "fintrinsic-modules-path") \
- || !strcmp (STR, "dumpbase") || !strcmp (STR, "dumpdir"))
-
-
/* These are exported by gcc.c. */
extern int do_spec (const char *);
extern void record_temp_file (const char *, int, int);
diff --git a/gcc/opts-common.c b/gcc/opts-common.c
index d84938a..8028015 100644
--- a/gcc/opts-common.c
+++ b/gcc/opts-common.c
@@ -24,6 +24,7 @@ along with GCC; see the file COPYING3. If not see
#include "opts.h"
#include "options.h"
#include "diagnostic.h"
+#include "tm.h" /* For SWITCH_TAKES_ARG and WORD_SWITCH_TAKES_ARG. */
/* Perform a binary search to find which option the command-line INPUT
matches. Returns its index in the option array, and
@@ -138,7 +139,9 @@ decode_cmdline_option (const char **argv, unsigned int lang_mask,
const char *opt, *arg = 0;
char *dup = 0;
int value = 1;
- unsigned int result = 1;
+ unsigned int result = 1, i;
+ size_t total_len;
+ char *p;
const struct cl_option *option;
int errors = 0;
@@ -242,22 +245,54 @@ decode_cmdline_option (const char **argv, unsigned int lang_mask,
decoded->arg = arg;
decoded->value = value;
decoded->errors = errors;
- switch (result)
+
+ if (opt_index == OPT_SPECIAL_unknown)
{
- case 1:
- decoded->orig_option_with_args_text = argv[0];
- decoded->canonical_option[0] = argv[0];
- decoded->canonical_option[1] = NULL;
- break;
- case 2:
- decoded->orig_option_with_args_text = concat (argv[0], " ",
- argv[1], NULL);
- decoded->canonical_option[0] = argv[0];
- decoded->canonical_option[1] = argv[1];
- break;
- default:
- gcc_unreachable ();
+ /* Skip the correct number of arguments for options handled
+ through specs. */
+ const char *popt = argv[0] + 1;
+ int c = *popt;
+
+ gcc_assert (result == 1);
+ if (SWITCH_TAKES_ARG (c) > (popt[1] != 0))
+ result += SWITCH_TAKES_ARG (c) - (popt[1] != 0);
+ else if (WORD_SWITCH_TAKES_ARG (popt))
+ result += WORD_SWITCH_TAKES_ARG (popt);
+ if (result > 1)
+ for (i = 1; i < result; i++)
+ if (argv[i] == NULL)
+ {
+ result = i;
+ break;
+ }
}
+
+ gcc_assert (result >= 1 && result <= ARRAY_SIZE (decoded->canonical_option));
+ decoded->canonical_option_num_elements = result;
+ total_len = 0;
+ for (i = 0; i < ARRAY_SIZE (decoded->canonical_option); i++)
+ {
+ if (i < result)
+ {
+ decoded->canonical_option[i] = argv[i];
+ total_len += strlen (argv[i]) + 1;
+ }
+ else
+ decoded->canonical_option[i] = NULL;
+ }
+ decoded->orig_option_with_args_text = p = XNEWVEC (char, total_len);
+ for (i = 0; i < result; i++)
+ {
+ size_t len = strlen (argv[i]);
+
+ memcpy (p, argv[i], len);
+ p += len;
+ if (i == result - 1)
+ *p++ = 0;
+ else
+ *p++ = ' ';
+ }
+
return result;
}
@@ -284,8 +319,11 @@ decode_cmdline_options_to_array (unsigned int argc, const char **argv,
opt_array[0].opt_index = OPT_SPECIAL_program_name;
opt_array[0].arg = argv[0];
opt_array[0].orig_option_with_args_text = argv[0];
+ opt_array[0].canonical_option_num_elements = 1;
opt_array[0].canonical_option[0] = argv[0];
opt_array[0].canonical_option[1] = NULL;
+ opt_array[0].canonical_option[2] = NULL;
+ opt_array[0].canonical_option[3] = NULL;
opt_array[0].value = 1;
opt_array[0].errors = 0;
num_decoded_options = 1;
@@ -300,8 +338,11 @@ decode_cmdline_options_to_array (unsigned int argc, const char **argv,
opt_array[num_decoded_options].opt_index = OPT_SPECIAL_input_file;
opt_array[num_decoded_options].arg = opt;
opt_array[num_decoded_options].orig_option_with_args_text = opt;
+ opt_array[num_decoded_options].canonical_option_num_elements = 1;
opt_array[num_decoded_options].canonical_option[0] = opt;
opt_array[num_decoded_options].canonical_option[1] = NULL;
+ opt_array[num_decoded_options].canonical_option[2] = NULL;
+ opt_array[num_decoded_options].canonical_option[3] = NULL;
opt_array[num_decoded_options].value = 1;
opt_array[num_decoded_options].errors = 0;
num_decoded_options++;
diff --git a/gcc/opts.h b/gcc/opts.h
index 6613da0..005a846 100644
--- a/gcc/opts.h
+++ b/gcc/opts.h
@@ -121,10 +121,12 @@ struct cl_decoded_option
/* The canonical form of the option and its argument, for when it is
necessary to reconstruct argv elements (in particular, for
processing specs and passing options to subprocesses from the
- driver). The first element of this array is non-NULL; the second
- is NULL if the canonical form uses only one argv element,
- non-NULL otherwise. */
- const char *canonical_option[2];
+ driver). */
+ const char *canonical_option[4];
+
+ /* The number of elements in the canonical form of the option and
+ arguments; always at least 1. */
+ size_t canonical_option_num_elements;
/* For a boolean option, 1 for the true case and 0 for the "no-"
case. For an unsigned integer option, the value of the