diff options
author | Joseph Myers <joseph@codesourcery.com> | 2010-09-02 12:41:22 +0100 |
---|---|---|
committer | Joseph Myers <jsm28@gcc.gnu.org> | 2010-09-02 12:41:22 +0100 |
commit | 5de8299cec99d5a056149ce23d09d3db5cbf0116 (patch) | |
tree | 963a2e047cab0d224c64b2b3500d48fa1fd9039f /gcc/opts-common.c | |
parent | f7e4c09b548c7220ac3277b46478bb40438f4a44 (diff) | |
download | gcc-5de8299cec99d5a056149ce23d09d3db5cbf0116.tar.gz |
re PR driver/44076 (-MT <target> behaves different as -MT<target> (w/o space))
PR driver/44076
* opts.h (struct cl_option): Add alias_arg, neg_alias_arg and
alias_target fields.
* opt-functions.awk (opt_sanitized_name): Don't handle
finline-limit=, Wlarger-than= and ftemplate-depth= specially.
* optc-gen.awk: Generate alias fields.
* opth-gen.awk: Explicitly give values for OPT_* enum constants.
Don't generate such constants for aliases.
* opts-common.c (generate_canonical_option): New.
(decode_cmdline_option): Handle aliases. Use
generate_canonical_option for known options instead of copying the
input option text.
* doc/options.texi (Alias): Document.
* common.opt (W, Wlarger-than-, aux-info=, finline-limit-,
fstack-check, specs): Mark as aliases.
* gcc.c (driver_handle_option): Canonicalize -L options to joined
arguments.
(driver_handle_option): Don't handle OPT_specs.
* opts.c (common_handle_option): Don't handle options marked as
aliases.
(enable_warning_as_error): Handle aliases.
* stor-layout.c (layout_decl): Use OPT_Wlarger_than_ instead of
OPT_Wlarger_than_eq.
* tree-optimize.c (tree_rest_of_compilation): Use
OPT_Wlarger_than_ instead of OPT_Wlarger_than_eq.
c-family:
* c.opt (Wcomments, Werror-implicit-function-declaration,
ftemplate-depth-, std=c89, std=c9x, std=gnu89, std=gnu9x,
std=iso9899:1990, std=iso9899:1999, std=iso9899:199x): Mark as
aliases.
* c-common.c (option_codes): Use OPT_Wcomment instead of
OPT_Wcomments.
* c-opts.c (warning_as_error_callback, c_common_handle_option):
Don't handle options marked as aliases.
java:
* lang.opt (CLASSPATH, bootclasspath, classpath, encoding,
fCLASSPATH=): Mark as Java options and as aliases.
* jvspec.c (jvgenmain_spec): Don't handle -fCLASSPATH*.
(lang_specific_driver): Don't handle options marked as aliases.
* lang.c (java_handle_option): Don't handle OPT_fCLASSPATH_.
testsuite:
* gcc.dg/cpp/warn-comments-3.c: New. Based on warn-comments-2.c
but using -Werror=comment.
* gcc.dg/cpp/warn-comments.c, gcc.dg/cpp/warn-comments-2.c: Adjust
expected error messages.
From-SVN: r163770
Diffstat (limited to 'gcc/opts-common.c')
-rw-r--r-- | gcc/opts-common.c | 157 |
1 files changed, 126 insertions, 31 deletions
diff --git a/gcc/opts-common.c b/gcc/opts-common.c index 871e4662d3b..07758967e6d 100644 --- a/gcc/opts-common.c +++ b/gcc/opts-common.c @@ -144,6 +144,58 @@ option_ok_for_language (const struct cl_option *option, return true; } + +/* Fill in the canonical option part of *DECODED with an option + described by OPT_INDEX, ARG and VALUE. */ + +static void +generate_canonical_option (size_t opt_index, const char *arg, int value, + struct cl_decoded_option *decoded) +{ + const struct cl_option *option = &cl_options[opt_index]; + const char *opt_text = option->opt_text; + + if (value == 0 + && !(option->flags & CL_REJECT_NEGATIVE) + && (opt_text[1] == 'W' || opt_text[1] == 'f' || opt_text[1] == 'm')) + { + char *t = XNEWVEC (char, option->opt_len + 5); + t[0] = '-'; + t[1] = opt_text[1]; + t[2] = 'n'; + t[3] = 'o'; + t[4] = '-'; + memcpy (t + 5, opt_text + 2, option->opt_len); + opt_text = t; + } + + decoded->canonical_option[2] = NULL; + decoded->canonical_option[3] = NULL; + + if (arg) + { + if (option->flags & CL_SEPARATE) + { + decoded->canonical_option[0] = opt_text; + decoded->canonical_option[1] = arg; + decoded->canonical_option_num_elements = 2; + } + else + { + gcc_assert (option->flags & CL_JOINED); + decoded->canonical_option[0] = concat (opt_text, arg, NULL); + decoded->canonical_option[1] = NULL; + decoded->canonical_option_num_elements = 1; + } + } + else + { + decoded->canonical_option[0] = opt_text; + decoded->canonical_option[1] = NULL; + decoded->canonical_option_num_elements = 1; + } +} + /* Decode the switch beginning at ARGV for the language indicated by LANG_MASK (including CL_COMMON and CL_TARGET if applicable), into the structure *DECODED. Returns the number of switches @@ -245,13 +297,64 @@ decode_cmdline_option (const char **argv, unsigned int lang_mask, result = 1; } + if (arg == NULL && (separate_arg_flag || joined_arg_flag)) + errors |= CL_ERR_MISSING_ARG; + + /* Is this option an alias? */ + if (option->alias_target != N_OPTS) + { + size_t new_opt_index = option->alias_target; + const struct cl_option *new_option = &cl_options[new_opt_index]; + + /* The new option must not be an alias itself. */ + gcc_assert (new_option->alias_target == N_OPTS); + + if (option->neg_alias_arg) + { + gcc_assert (option->alias_arg != NULL); + gcc_assert (arg == NULL); + if (value) + arg = option->alias_arg; + else + arg = option->neg_alias_arg; + value = 1; + } + else if (option->alias_arg) + { + gcc_assert (value == 1); + gcc_assert (arg == NULL); + arg = option->alias_arg; + } + + opt_index = new_opt_index; + option = new_option; + + if (value == 0) + gcc_assert (!(option->flags & CL_REJECT_NEGATIVE)); + + /* Recompute what arguments are allowed. */ + separate_arg_flag = ((option->flags & CL_SEPARATE) + && !((option->flags & CL_NO_DRIVER_ARG) + && (lang_mask & CL_DRIVER))); + joined_arg_flag = (option->flags & CL_JOINED) != 0; + + if (!(errors & CL_ERR_MISSING_ARG)) + { + if (separate_arg_flag || joined_arg_flag) + gcc_assert (arg != NULL); + else + gcc_assert (arg == NULL); + } + + /* Recheck for disabled options. */ + if (option->flags & CL_DISABLED) + errors |= CL_ERR_DISABLED; + } + /* Check if this is a switch for a different front end. */ if (!option_ok_for_language (option, lang_mask)) errors |= CL_ERR_WRONG_LANG; - if (arg == NULL && (separate_arg_flag || joined_arg_flag)) - errors |= CL_ERR_MISSING_ARG; - /* If the switch takes an integer, convert it. */ if (arg && (option->flags & CL_UINTEGER)) { @@ -296,12 +399,17 @@ decode_cmdline_option (const char **argv, unsigned int lang_mask, { if (i < result) { - decoded->canonical_option[i] = argv[i]; + if (opt_index == OPT_SPECIAL_unknown) + decoded->canonical_option[i] = argv[i]; + else + decoded->canonical_option[i] = NULL; total_len += strlen (argv[i]) + 1; } else decoded->canonical_option[i] = NULL; } + if (opt_index != OPT_SPECIAL_unknown) + generate_canonical_option (opt_index, arg, value, decoded); decoded->orig_option_with_args_text = p = XNEWVEC (char, total_len); for (i = 0; i < result; i++) { @@ -571,39 +679,26 @@ generate_option (size_t opt_index, const char *arg, int value, decoded->opt_index = opt_index; decoded->arg = arg; - decoded->canonical_option[2] = NULL; - decoded->canonical_option[3] = NULL; decoded->value = value; decoded->errors = (option_ok_for_language (option, lang_mask) ? 0 : CL_ERR_WRONG_LANG); - if (arg) + generate_canonical_option (opt_index, arg, value, decoded); + switch (decoded->canonical_option_num_elements) { - if (option->flags & CL_SEPARATE) - { - decoded->orig_option_with_args_text = concat (option->opt_text, " ", - arg, NULL); - decoded->canonical_option[0] = option->opt_text; - decoded->canonical_option[1] = arg; - decoded->canonical_option_num_elements = 2; - } - else - { - gcc_assert (option->flags & CL_JOINED); - decoded->orig_option_with_args_text = concat (option->opt_text, arg, - NULL); - decoded->canonical_option[0] = decoded->orig_option_with_args_text; - decoded->canonical_option[1] = NULL; - decoded->canonical_option_num_elements = 1; - } - } - else - { - decoded->orig_option_with_args_text = option->opt_text; - decoded->canonical_option[0] = option->opt_text; - decoded->canonical_option[1] = NULL; - decoded->canonical_option_num_elements = 1; + case 1: + decoded->orig_option_with_args_text = decoded->canonical_option[0]; + break; + + case 2: + decoded->orig_option_with_args_text + = concat (decoded->canonical_option[0], " ", + decoded->canonical_option[1], NULL); + break; + + default: + gcc_unreachable (); } } |