2012-10-16 Manuel López-Ibáñez <manu@gcc.gnu.org>
authormanu <manu@138bc75d-0d04-0410-961f-82ee72b054a4>
Tue, 16 Oct 2012 15:38:58 +0000 (15:38 +0000)
committermanu <manu@138bc75d-0d04-0410-961f-82ee72b054a4>
Tue, 16 Oct 2012 15:38:58 +0000 (15:38 +0000)
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.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@192503 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/ChangeLog
gcc/common.opt
gcc/doc/options.texi
gcc/opt-functions.awk
gcc/optc-gen.awk
gcc/opts.c

index 8d63981..7542474 100644 (file)
@@ -2,6 +2,17 @@
 
        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
+       PR c/40989
        * optc-gen.awk: Handle new form of LangEnabledBy.
        * opts.c (set_Wstrict_aliasing): Declare here. Make static.
        * common.opt (Wstrict-aliasing=,Wstrict-overflow=): Do not use Init.
index 0c6d578..e21fb71 100644 (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
index 8011502..0a8e1cd 100644 (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})
index 8b025b2..13de5e4 100644 (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 ""
+}
index 2b16875..87575c2 100644 (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);"
index aea0cfc..98bbd30 100644 (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;