re PR c/53063 (encode group options in the .opt files)

2012-10-16  Manuel López-Ibáñez  <manu@gcc.gnu.org>

	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
This commit is contained in:
Manuel López-Ibáñez 2012-10-16 15:38:58 +00:00
parent 65d4f2cd2a
commit d919140b83
6 changed files with 71 additions and 22 deletions

View File

@ -1,3 +1,14 @@
2012-10-16 Manuel López-Ibáñez <manu@gcc.gnu.org>
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 <manu@gcc.gnu.org>
PR c/53063

View File

@ -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

View File

@ -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})

View File

@ -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 ""
}

View File

@ -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);"

View File

@ -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;