From patchwork Sun Nov 23 20:24:29 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Tobias Burnus X-Patchwork-Id: 413460 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 8A40814012B for ; Mon, 24 Nov 2014 07:24:43 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :message-id:date:from:mime-version:to:subject:references :in-reply-to:content-type; q=dns; s=default; b=gwGI9wWToOr8iEFx6 ZkaZNDlKLhvnSsebocGwNQcwz3J0/TQKyTpb+wu/CFj+Mm4Y3mxpc0N1ucnlg0ke s5u045uNkJH2KVwVYaRNT8xHqbAf7IVssme3DoF3FLCpOStNDLY2yHnq/HrXALih WQy8a5UM5de1KLxPEUfSqgqeKE= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :message-id:date:from:mime-version:to:subject:references :in-reply-to:content-type; s=default; bh=Stn/yfsWzdHm9InWuH8maFz AMIA=; b=Rir9f/zhiKPYTgl/UQGAni1pJGGKNwiyq6ejkpkhL82vJKgLnoyW4i1 w5Zv+YV5HScd5sFtWEUKRD92hrVySumbq3UI6EQLOB2Vs9VRs94kfBgp5v/wHi3u Pcy51boI35h03uU+5HqRW56aaHZiw9Dmw0rdNLdQvr/mJATHYD1Y= Received: (qmail 24119 invoked by alias); 23 Nov 2014 20:24:36 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 24107 invoked by uid 89); 23 Nov 2014 20:24:35 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.0 required=5.0 tests=AWL, BAYES_00 autolearn=ham version=3.3.2 X-HELO: mx01.qsc.de Received: from mx01.qsc.de (HELO mx01.qsc.de) (213.148.129.14) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-SHA encrypted) ESMTPS; Sun, 23 Nov 2014 20:24:34 +0000 Received: from tux.net-b.de (port-92-194-114-130.dynamic.qsc.de [92.194.114.130]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mx01.qsc.de (Postfix) with ESMTPSA id 6B5813CDD1; Sun, 23 Nov 2014 21:24:30 +0100 (CET) Message-ID: <5472427D.9060909@net-b.de> Date: Sun, 23 Nov 2014 21:24:29 +0100 From: Tobias Burnus User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.2.0 MIME-Version: 1.0 To: =?windows-1252?Q?Manuel_L=F3pez-Ib=E1=F1ez?= , Gcc Patch List , "Joseph S. Myers" Subject: Re: [Patch, option handling] optc-gen.awk - support || in EnabledBy() References: In-Reply-To: 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 2014-11-23 Tobias Burnus Manuel López-Ibáñez 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 == "") {