From d919140b83feaa44cf32f4e3e9c31ac78278ac27 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20L=C3=B3pez-Ib=C3=A1=C3=B1ez?= Date: Tue, 16 Oct 2012 15:38:58 +0000 Subject: [PATCH] re PR c/53063 (encode group options in the .opt files) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 2012-10-16 Manuel López-Ibáñez PR c/53063 PR c/40989 * doc/options.texi (EnabledBy): Document new form. * optc-gen.awk: Handle new form of EnabledBy. * common.opt (Wunused-but-set-parameter): Use EnabledBy. (Wunused-parameter): Likewise. * opts.c (finish_options): Do not handle them explicitly. * opt-functions.awk (search_var_name): New. From-SVN: r192503 --- gcc/ChangeLog | 11 ++++++++++ gcc/common.opt | 4 ++-- gcc/doc/options.texi | 5 ++++- gcc/opt-functions.awk | 16 +++++++++++++++ gcc/optc-gen.awk | 48 ++++++++++++++++++++++++++++++++++--------- gcc/opts.c | 9 -------- 6 files changed, 71 insertions(+), 22 deletions(-) diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 8d639811a3a..7542474a53e 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,14 @@ +2012-10-16 Manuel López-Ibáñez + + PR c/53063 + PR c/40989 + * doc/options.texi (EnabledBy): Document new form. + * optc-gen.awk: Handle new form of EnabledBy. + * common.opt (Wunused-but-set-parameter): Use EnabledBy. + (Wunused-parameter): Likewise. + * opts.c (finish_options): Do not handle them explicitly. + * opt-functions.awk (search_var_name): New. + 2012-10-16 Manuel López-Ibáñez PR c/53063 diff --git a/gcc/common.opt b/gcc/common.opt index 0c6d578335a..e21fb71bbd4 100644 --- a/gcc/common.opt +++ b/gcc/common.opt @@ -673,7 +673,7 @@ Common Var(warn_unused) Init(0) Warning Enable all -Wunused- warnings Wunused-but-set-parameter -Common Var(warn_unused_but_set_parameter) Init(-1) Warning +Common Var(warn_unused_but_set_parameter) Warning EnabledBy(Wunused && Wextra) Warn when a function parameter is only set, otherwise unused Wunused-but-set-variable @@ -689,7 +689,7 @@ Common Var(warn_unused_label) Warning EnabledBy(Wunused) Warn when a label is unused Wunused-parameter -Common Var(warn_unused_parameter) Init(-1) Warning +Common Var(warn_unused_parameter) Warning EnabledBy(Wunused && Wextra) Warn when a function parameter is unused Wunused-value diff --git a/gcc/doc/options.texi b/gcc/doc/options.texi index 8011502f9f1..0a8e1cd49b5 100644 --- a/gcc/doc/options.texi +++ b/gcc/doc/options.texi @@ -460,7 +460,10 @@ value of @option{-fmath-errno} for languages that do not use @code{errno}. @item EnabledBy(@var{opt}) -If not explicitly set, the option is set to the value of @option{-@var{opt}}. +@itemx EnabledBy(@var{opt} && @var{opt2}) +If not explicitly set, the option is set to the value of +@option{-@var{opt}}. The second form specifies that the option is +only set if both @var{opt} and @var{opt2} are set. @item LangEnabledBy(@var{language}, @var{opt}) @itemx LangEnabledBy(@var{language}, @var{opt}, @var{posarg}, @var{negarg}) diff --git a/gcc/opt-functions.awk b/gcc/opt-functions.awk index 8b025b2cf32..13de5e48ed1 100644 --- a/gcc/opt-functions.awk +++ b/gcc/opt-functions.awk @@ -297,3 +297,19 @@ function lang_sanitized_name(name) gsub( "[^" alnum "_]", "X", name ) return name } + +# Search for a valid var_name among all OPTS equal to option NAME. +# If not found, return "". +function search_var_name(name, opt_numbers, opts, flags, n_opts) +{ + opt_var_name = var_name(flags[opt_numbers[name]]); + if (opt_var_name != "") { + return opt_var_name; + } + for (k = 0; k < n_opts; k++) { + if (opts[k] == name && var_name(flags[k]) != "") { + return var_name(flags[k]); + } + } + return "" +} diff --git a/gcc/optc-gen.awk b/gcc/optc-gen.awk index 2b168756ef5..87575c22af1 100644 --- a/gcc/optc-gen.awk +++ b/gcc/optc-gen.awk @@ -39,16 +39,35 @@ for (i = 0; i < n_langs; i++) { for (i = 0; i < n_opts; i++) { enabledby_arg = opt_args("EnabledBy", flags[i]); if (enabledby_arg != "") { - enabledby_name = enabledby_arg; - enabledby_index = opt_numbers[enabledby_name]; - if (enabledby_index == "") { - print "#error Enabledby: " enabledby_name - } else { - if (enables[enabledby_name] == "") { - enabledby[n_enabledby] = enabledby_name; - n_enabledby++; + n_enabledby_names = split(enabledby_arg, enabledby_names, " && "); + if (n_enabledby_names > 2) { + print "#error EnabledBy (Wfoo && Wbar && Wbaz) not currently supported" + } + for (j = 1; j <= n_enabledby_names; j++) { + enabledby_name = enabledby_names[j]; + enabledby_index = opt_numbers[enabledby_name]; + if (enabledby_index == "") { + print "#error Enabledby: " enabledby_name + } else { + condition = ""; + if (n_enabledby_names == 2) { + opt_var_name_1 = search_var_name(enabledby_names[1], opt_numbers, opts, flags, n_opts); + opt_var_name_2 = search_var_name(enabledby_names[2], opt_numbers, opts, flags, n_opts); + if (opt_var_name_1 == "") { + print "#error " enabledby_names[1] " does not have a Var() flag" + } + if (opt_var_name_2 == "") { + print "#error " enabledby_names[2] " does not have a Var() flag" + } + condition = "opts->x_" opt_var_name_1 " && opts->x_" opt_var_name_2; + } + if (enables[enabledby_name] == "") { + enabledby[n_enabledby] = enabledby_name; + n_enabledby++; + } + enables[enabledby_name] = enables[enabledby_name] opts[i] ";"; + enablesif[enabledby_name] = enablesif[enabledby_name] condition ";"; } - enables[enabledby_name] = enables[enabledby_name] opts[i] ";"; } } @@ -395,14 +414,23 @@ print " gcc_assert (decoded->canonical_option_num_elements <= 2); " print " " print " switch (code) " print " { " +# Handle EnabledBy for (i = 0; i < n_enabledby; i++) { enabledby_name = enabledby[i]; print " case " opt_enum(enabledby_name) ":" n_enables = split(enables[enabledby_name], thisenable, ";"); + n_enablesif = split(enablesif[enabledby_name], thisenableif, ";"); + if (n_enables != n_enablesif) { + print "#error n_enables != n_enablesif: Something went wrong!" + } for (j = 1; j < n_enables; j++) { opt_var_name = var_name(flags[opt_numbers[thisenable[j]]]); if (opt_var_name != "") { - print " if (!opts_set->x_" opt_var_name ")" + condition = "!opts_set->x_" opt_var_name + if (thisenableif[j] != "") { + condition = condition " && (" thisenableif[j] ")" + } + print " if (" condition ")" print " handle_generated_option (opts, opts_set," print " " opt_enum(thisenable[j]) ", NULL, value," print " lang_mask, kind, loc, handlers, dc);" diff --git a/gcc/opts.c b/gcc/opts.c index aea0cfc839f..98bbd302c8e 100644 --- a/gcc/opts.c +++ b/gcc/opts.c @@ -830,15 +830,6 @@ finish_options (struct gcc_options *opts, struct gcc_options *opts_set, opts->x_param_values, opts_set->x_param_values); /* This replaces set_Wunused. */ - /* Wunused-parameter is enabled if both -Wunused -Wextra are enabled. */ - if (opts->x_warn_unused_parameter == -1) - opts->x_warn_unused_parameter = (opts->x_warn_unused - && opts->x_extra_warnings); - /* Wunused-but-set-parameter is enabled if both -Wunused -Wextra are - enabled. */ - if (opts->x_warn_unused_but_set_parameter == -1) - opts->x_warn_unused_but_set_parameter = (opts->x_warn_unused - && opts->x_extra_warnings); /* Wunused-local-typedefs is enabled by -Wunused or -Wall. */ if (opts->x_warn_unused_local_typedefs == -1) opts->x_warn_unused_local_typedefs = opts->x_warn_unused;