diff mbox

[option,handling] optc-gen.awk - support || in EnabledBy()

Message ID 5472427D.9060909@net-b.de
State New
Headers show

Commit Message

Tobias Burnus Nov. 23, 2014, 8:24 p.m. UTC
Manuel López-Ibáñez wrote:
> For what is worth, the patch looks good to me, except that the form
> EnabledBy(@var{opt} || @var{opt2} needs documentation in
> doc/options.texi.
Done.

> Perhaps it could be more condensed as (untested!):
Seems to work - hence: Done.

> A version handling LangEnabledBy(Lang, Wx || Wy) should be fairly
> similar and probably even more useful, if you wish to fix also that.
Done.

> If I recall correctly, there are several -W* flags in common.opt and
> c-family/c.opt that benefit from this cleanup (Wpointer-sign being
> one). It would be nice to convert them to the new format together with
> the patch.

I did so. Remarks:

* Wnonnull cannot be converted due to the ">=1" condition:
LangEnabledBy(C ObjC C++ ObjC++,Wformat=,warn_format >= 1,0)
LangEnabledBy(C ObjC C++ ObjC++,Wall)

* Wsign-compare has:
LangEnabledBy(C++ ObjC++,Wall)
EnabledBy(Wextra)
Hence, -Wextra is enabled for all languages and not only C languages. Is 
this intended? Combining would still not be possible as only for C++ 
languages it is enabled by -Wall.

* Wmain: Similarly, -Wall is only for C/ObjC while -Wpedantic is also 
for C++/ObjC++.

Thus, I didn't touch those.


Build on x86-64-gnu-linux with checking that the resulting options.c 
remains the same.
OK for the trunk?

Tobias

Comments

Joseph Myers Nov. 28, 2014, 11:28 p.m. UTC | #1
On Sun, 23 Nov 2014, Tobias Burnus wrote:

> Build on x86-64-gnu-linux with checking that the resulting options.c remains
> the same.
> OK for the trunk?

OK.
diff mbox

Patch

2014-11-23  Tobias Burnus  <burnus@net-b.de>
	    Manuel López-Ibáñez  <manu@gcc.gnu.org>

gcc/c-family/
	* c.opt (Wdelete-non-virtual-dtor, Wenum-compare, Wnarrowing,
	Wpointer-sign, Wvariadic-macros): Combine duplicated warning
	lines into a single one using || for LangEnabledBy.
gcc/
	* opt-functions.awk (lang_enabled_by): Support || for
	enabled-by.
	* optc-gen.awk: Ditto.
	* doc/options.texi (LangEnabledBy, EnabledBy): Document the
	|| syntax.

fortran/
	* lang.opt (Wtabs): Combine duplicated item into a single
	one using || for LangEnabledBy.

diff --git a/gcc/c-family/c.opt b/gcc/c-family/c.opt
index 85dcb98..b9f7c65 100644
--- a/gcc/c-family/c.opt
+++ b/gcc/c-family/c.opt
@@ -372,13 +372,9 @@  C++ ObjC++ Var(warn_delete_incomplete) Init(1) Warning
 Warn when deleting a pointer to incomplete type
 
 Wdelete-non-virtual-dtor
-C++ ObjC++ Var(warn_delnonvdtor) Warning LangEnabledBy(C++ ObjC++,Wall)
+C++ ObjC++ Var(warn_delnonvdtor) Warning LangEnabledBy(C++ ObjC++,Wall || Weffc++)
 Warn about deleting polymorphic objects with non-virtual destructors
 
-Wdelete-non-virtual-dtor
-LangEnabledBy(C++ ObjC++,Weffc++)
-;
-
 Wdeprecated
 C C++ ObjC ObjC++ CPP(cpp_warn_deprecated) CppReason(CPP_W_DEPRECATED) Var(warn_deprecated) Init(1) Warning
 Warn if a deprecated compiler feature, class, method, or field is used
@@ -408,13 +404,9 @@  C ObjC C++ ObjC++ CPP(warn_endif_labels) CppReason(CPP_W_ENDIF_LABELS) Var(cpp_w
 Warn about stray tokens after #elif and #endif
 
 Wenum-compare
-C ObjC C++ ObjC++ Var(warn_enum_compare) Init(-1) Warning LangEnabledBy(C ObjC,Wall)
+C ObjC C++ ObjC++ Var(warn_enum_compare) Init(-1) Warning LangEnabledBy(C ObjC,Wall || Wc++-compat)
 Warn about comparison of different enum types
 
-Wenum-compare
-LangEnabledBy(C ObjC,Wc++-compat)
-;
-
 Werror
 C ObjC C++ ObjC++
 ; Documented in common.opt
@@ -614,13 +606,9 @@  C ObjC C++ ObjC++ CPP(warn_multichar) CppReason(CPP_W_MULTICHAR) Var(cpp_warn_mu
 Warn about use of multi-character character constants
 
 Wnarrowing
-C ObjC C++ ObjC++ Warning Var(warn_narrowing) Init(-1) LangEnabledBy(C++ ObjC++,Wall)
+C ObjC C++ ObjC++ Warning Var(warn_narrowing) Init(-1) LangEnabledBy(C++ ObjC++,Wall || Wc++0x-compat)
 Warn about narrowing conversions within { } that are ill-formed in C++11
 
-Wnarrowing
-C ObjC C++ ObjC++ LangEnabledBy(C++ ObjC++,Wc++0x-compat)
-;
-
 Wnested-externs
 C ObjC Var(warn_nested_externs) Warning
 Warn about \"extern\" declarations not at file scope
@@ -721,13 +709,9 @@  C ObjC C++ ObjC++ Var(warn_pointer_arith) Warning LangEnabledBy(C ObjC C++ ObjC+
 Warn about function pointer arithmetic
 
 Wpointer-sign
-C ObjC Var(warn_pointer_sign) Warning LangEnabledBy(C ObjC,Wall)
+C ObjC Var(warn_pointer_sign) Warning LangEnabledBy(C ObjC,Wall || Wpedantic)
 Warn when a pointer differs in signedness in an assignment
 
-Wpointer-sign
-C ObjC LangEnabledBy(C ObjC,Wpedantic)
-;
-
 Wpointer-to-int-cast
 C ObjC Var(warn_pointer_to_int_cast) Init(1) Warning
 Warn when a pointer is cast to an integer of a different size
@@ -877,13 +861,9 @@  C ObjC C++ ObjC++ Var(warn_unused_result) Init(1) Warning
 Warn if a caller of a function, marked with attribute warn_unused_result, does not use its return value
 
 Wvariadic-macros
-C ObjC C++ ObjC++ CPP(warn_variadic_macros) CppReason(CPP_W_VARIADIC_MACROS) Var(cpp_warn_variadic_macros) Init(0) Warning LangEnabledBy(C ObjC C++ ObjC++,Wpedantic)
+C ObjC C++ ObjC++ CPP(warn_variadic_macros) CppReason(CPP_W_VARIADIC_MACROS) Var(cpp_warn_variadic_macros) Init(0) Warning LangEnabledBy(C ObjC C++ ObjC++,Wpedantic || Wtraditional)
 Warn about using variadic macros
 
-Wvariadic-macros
-LangEnabledBy(C ObjC C++ ObjC++,Wtraditional)
-;
-
 Wvarargs
 C ObjC C++ ObjC++ Warning Var(warn_varargs) Init(1)
 Warn about questionable usage of the macros used to retrieve variable arguments
diff --git a/gcc/doc/options.texi b/gcc/doc/options.texi
index bcffdf8..1ead097 100644
--- a/gcc/doc/options.texi
+++ b/gcc/doc/options.texi
@@ -459,15 +459,18 @@  value of @option{-fmath-errno} for languages that do not use
 @code{errno}.
 
 @item EnabledBy(@var{opt})
+@itemx EnabledBy(@var{opt} || @var{opt2})
 @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
+@option{-@var{opt}}; multiple options can be given, separated by
+@code{||}.  The third form using @code{&&} 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})
 When compiling for the given language, the option is set to the value
-of @option{-@var{opt}}, if not explicitly set. In the second form, if
+of @option{-@var{opt}}, if not explicitly set. @var{opt} can be also a list
+of @code{||} separated options. In the second form, if
 @var{opt} is used in the positive form then @var{posarg} is considered
 to be passed to the option, and if @var{opt} is used in the negative
 form then @var{negarg} is considered to be passed to the option.  It
diff --git a/gcc/fortran/lang.opt b/gcc/fortran/lang.opt
index 5da0453..a8f1636 100644
--- a/gcc/fortran/lang.opt
+++ b/gcc/fortran/lang.opt
@@ -298,13 +298,9 @@  Fortran Warning
 Warn about \"suspicious\" constructs
 
 Wtabs
-Fortran Warning Var(warn_tabs) LangEnabledBy(Fortran,Wall)
+Fortran Warning Var(warn_tabs) LangEnabledBy(Fortran,Wall || Wpedantic)
 Permit nonconforming uses of the tab character
 
-Wtabs
-LangEnabledBy(Fortran,Wpedantic)
-;
-
 Wunderflow
 Fortran Warning
 Warn about underflow of numerical constant expressions
diff --git a/gcc/opt-functions.awk b/gcc/opt-functions.awk
index 381bb50..a83b4a8 100644
--- a/gcc/opt-functions.awk
+++ b/gcc/opt-functions.awk
@@ -319,29 +319,33 @@  function search_var_name(name, opt_numbers, opts, flags, n_opts)
 function lang_enabled_by(enabledby_langs, enabledby_name, enabledby_posarg, enabledby_negarg)
 {
     n_enabledby_arg_langs = split(enabledby_langs, enabledby_arg_langs, " ");
-    enabledby_index = opt_numbers[enabledby_name];
-    if (enabledby_index == "") {
-        print "#error LangEnabledby: " enabledby_name 
+    if (enabledby_posarg != "" && enabledby_negarg != "") {
+        with_args = "," enabledby_posarg "," enabledby_negarg
+    } else if (enabledby_posarg == "" && enabledby_negarg == "") {
+        with_args = ""
     } else {
-        if (enabledby_posarg != "" && enabledby_negarg != "") {
-            with_args = "," enabledby_posarg "," enabledby_negarg
-        } else if (enabledby_posarg == "" && enabledby_negarg == "") {
-            with_args = ""
+        print "#error LangEnabledBy("enabledby_langs","enabledby_name", " \
+            enabledby_posarg", " enabledby_negargs                  \
+            ") with three arguments, it should have either 2 or 4"
+    }
+
+    n_enabledby_array = split(enabledby_name, enabledby_array, " \\|\\| ");
+    for (k = 1; k <= n_enabledby_array; k++) {
+        enabledby_index = opt_numbers[enabledby_array[k]];
+        if (enabledby_index == "") {
+             print "#error LangEnabledBy("enabledby_langs","enabledby_name", " \
+                 enabledby_posarg", " enabledby_negargs") has invalid ENABLEDBY_NAME"
         } else {
-            print "#error LangEnabledBy("enabledby_langs","enabledby_name", " \
-                enabledby_posarg", " enabledby_negargs                  \
-                ") with three arguments, it should have either 2 or 4"
-        }
-        
-        for (j = 1; j <= n_enabledby_arg_langs; j++) {
-            lang_name = lang_sanitized_name(enabledby_arg_langs[j]);
-            lang_index = lang_numbers[enabledby_arg_langs[j]];
-            if (enables[lang_name,enabledby_name] == "") {
-                enabledby[lang_name,n_enabledby_lang[lang_index]] = enabledby_name;
-                n_enabledby_lang[lang_index]++;
+            for (j = 1; j <= n_enabledby_arg_langs; j++) {
+                 lang_name = lang_sanitized_name(enabledby_arg_langs[j]);
+                 lang_index = lang_numbers[enabledby_arg_langs[j]];
+                 if (enables[lang_name,enabledby_array[k]] == "") {
+                     enabledby[lang_name,n_enabledby_lang[lang_index]] = enabledby_array[k];
+                     n_enabledby_lang[lang_index]++;
+                 }
+                 enables[lang_name,enabledby_array[k]] \
+                     = enables[lang_name,enabledby_array[k]] opts[i] with_args ";";
             }
-            enables[lang_name,enabledby_name] = enables[lang_name,enabledby_name] opts[i] with_args ";";
         }
     }
 }
-
diff --git a/gcc/optc-gen.awk b/gcc/optc-gen.awk
index ecb225c..8868510 100644
--- a/gcc/optc-gen.awk
+++ b/gcc/optc-gen.awk
@@ -38,8 +38,16 @@  for (i = 0; i < n_langs; i++) {
 for (i = 0; i < n_opts; i++) {
     enabledby_arg = opt_args("EnabledBy", flags[i]);
     if (enabledby_arg != "") {
-        n_enabledby_names = split(enabledby_arg, enabledby_names, " && ");
-        if (n_enabledby_names > 2) {
+        logical_and = index(enabledby_arg, " && ");
+        if (logical_and != 0) {
+            # EnabledBy(arg1 && arg2)
+            split_sep = " && ";
+        } else {
+            # EnabledBy(arg) or EnabledBy(arg1 || arg2 || arg3)
+            split_sep = " \\|\\| ";
+        }
+        n_enabledby_names = split(enabledby_arg, enabledby_names, split_sep);
+        if (logical_and != 0 && n_enabledby_names > 2) {
             print "#error EnabledBy (Wfoo && Wbar && Wbaz) not currently supported"
         }
         for (j = 1; j <= n_enabledby_names; j++) {
@@ -49,7 +57,7 @@  for (i = 0; i < n_opts; i++) {
                 print "#error Enabledby: " enabledby_name 
             } else {
                 condition = "";
-                if (n_enabledby_names == 2) {
+                if (logical_and != 0) {
                     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 == "") {