Patchwork [fortran] Handle -Wextra, -fcompare-reals is implied with -Wextra

login
register
mail settings
Submitter Thomas Koenig
Date Sept. 23, 2012, 7:58 p.m.
Message ID <505F69DF.5090706@netcologne.de>
Download mbox | patch
Permalink /patch/186276/
State New
Headers show

Comments

Thomas Koenig - Sept. 23, 2012, 7:58 p.m.
Hello world,

the attatched patch (this time for real!) implements
-Wextra for the Fortran front end, and adds -fcompare-reals
to -Wextra.

@manu:  In the PR, you mentioned that it would be nice if
LangEnabledBy was used in the opt files.  I tried adding that
to the common.opt file for Wextra, but that led to the following
regressions:

FAIL: 17_intro/headers/c++1998/all_c++200x_compatibility.cc (test for 
excess errors)
FAIL: 17_intro/headers/c++1998/all.cc (test for excess errors)
FAIL: 17_intro/headers/c++1998/all_pedantic_errors.cc (test for excess 
errors)
FAIL: 17_intro/headers/c++1998/stdc++.cc (test for excess errors)
FAIL: 17_intro/headers/c++1998/stdc++_multiple_inclusion.cc (test for 
excess errors)
FAIL: 17_intro/headers/c++200x/stdc++.cc (test for excess errors)
FAIL: 17_intro/headers/c++200x/stdc++_multiple_inclusion.cc (test for 
excess errors)

so I left this part out.

Regression-tested.  OK for trunk?

	Thomas

2012-09-23  Thomas König  <tkoenig@gcc.gnu.org>

         PR fortran/54465
         * lang.opt (Wextra):  Add.
         * invoke.texi:  Document that -Wc-binding-type, -Wconversion
         and -Wline-truncation are implied by -Wall.  Document that
         -Wcompare-reals is implied by -Wextra.
         * options.c (set_Wextra):  New function.
         (gfc_handle_option):  Handle -Wextra.

2012-09-23  Thomas König  <tkoenig@gcc.gnu.org>

         PR fortran/54465
         * gfortran.dg/wextra_1.f:  New test.
Manuel López-Ibáñez - Sept. 23, 2012, 9:46 p.m.
On 23 September 2012 21:58, Thomas Koenig <tkoenig@netcologne.de> wrote:
> Hello world,
>
> the attatched patch (this time for real!) implements
> -Wextra for the Fortran front end, and adds -fcompare-reals
> to -Wextra.
>
> @manu:  In the PR, you mentioned that it would be nice if
> LangEnabledBy was used in the opt files.  I tried adding that
> to the common.opt file for Wextra, but that led to the following
> regressions:

The usage should be to add LangEnabledBy(Fortran,Wextra) to
fortran/lang.opt, see the examples in c-family/c.opt. However, the
actual problem seems to be that gfortran uses their own option
variables and not the ones generated by the common machinery (which
are generated in any case, so it is a bit of a waste to duplicate
them).

It is up to the gfortran maintainers to enforce using the common
machinery or keep re-inventing the wheel.  If gfortran wants to ever
support -Werror= and #pragma GCC diagnostics and other such goodies,
all this code will need to be eventually moved to the common machinery
(or duplicate the features in the Fortran FE).

Cheers,

Manuel.
Thomas Koenig - Sept. 24, 2012, 5:34 a.m.
Am 23.09.2012 23:46, schrieb Manuel López-Ibáñez:

> However, the
> actual problem seems to be that gfortran uses their own option
> variables and not the ones generated by the common machinery (which
> are generated in any case, so it is a bit of a waste to duplicate
> them).
>
> It is up to the gfortran maintainers to enforce using the common
> machinery or keep re-inventing the wheel.

I have submitted PR 54687 to track this issue.  Maybe somebody
from inside (or outside :-) the gfortran maintainer community
has time to work on it.

	Thomas
Thomas Koenig - Sept. 28, 2012, 4:44 p.m.
I wrote:

> the attatched patch (this time for real!) implements
> -Wextra for the Fortran front end, and adds -fcompare-reals
> to -Wextra.

Ping?

Patch

Index: fortran/lang.opt
===================================================================
--- fortran/lang.opt	(Revision 191649)
+++ fortran/lang.opt	(Arbeitskopie)
@@ -230,6 +230,10 @@  Wconversion-extra
 Fortran Warning
 Warn about most implicit conversions
 
+Wextra
+Fortran Warning
+Print extra (possibly unwanted) warnings
+
 Wfunction-elimination
 Fortran Warning
 Warn about function call elimination
Index: fortran/invoke.texi
===================================================================
--- fortran/invoke.texi	(Revision 191649)
+++ fortran/invoke.texi	(Arbeitskopie)
@@ -778,7 +778,8 @@  avoid such temporaries.
 Warn if the a variable might not be C interoperable.  In particular, warn if 
 the variable has been declared using an intrinsic type with default kind
 instead of using a kind parameter defined for C interoperability in the
-intrinsic @code{ISO_C_Binding} module.
+intrinsic @code{ISO_C_Binding} module.  This option is implied by
+@option{-Wall}.
 
 @item -Wcharacter-truncation
 @opindex @code{Wcharacter-truncation}
@@ -788,7 +789,8 @@  Warn when a character assignment will truncate the
 @item -Wline-truncation
 @opindex @code{Wline-truncation}
 @cindex warnings, line truncation
-Warn when a source code line will be truncated.
+Warn when a source code line will be truncated.  This option is
+implied by @option{-Wall}.
 
 @item -Wconversion
 @opindex @code{Wconversion}
@@ -884,7 +886,7 @@  encountered, which yield an UNDERFLOW during compi
 Warn if a user-defined procedure or module procedure has the same name as an
 intrinsic; in this case, an explicit interface or @code{EXTERNAL} or
 @code{INTRINSIC} declaration might be needed to get calls later resolved to
-the desired intrinsic/procedure.
+the desired intrinsic/procedure.  This option is implied by @option{-Wall}.
 
 @item -Wunused-dummy-argument
 @opindex @code{Wunused-dummy-argument}
@@ -939,6 +941,7 @@  allocatable variable; this includes scalars and de
 @item -Wcompare-reals
 @opindex @code{Wcompare-reals}
 Warn when comparing real or complex types for equality or inequality.
+This option is implied by @option{-Wextra}.
 
 @item -Wtarget-lifetime
 @opindex @code{Wtargt-lifetime}
Index: fortran/options.c
===================================================================
--- fortran/options.c	(Revision 191649)
+++ fortran/options.c	(Arbeitskopie)
@@ -483,8 +483,15 @@  set_Wall (int setting)
   warn_maybe_uninitialized = setting;
 }
 
+/* Set the options for -Wextra.  */
 
 static void
+set_Wextra (int setting)
+{
+  gfc_option.warn_compare_reals = setting;
+}
+
+static void
 gfc_handle_module_path_options (const char *arg)
 {
 
@@ -653,6 +660,15 @@  gfc_handle_option (size_t scode, const char *arg,
       gfc_option.warn_conversion_extra = value;
       break;
 
+    case OPT_Wextra:
+      handle_generated_option (&global_options, &global_options_set,
+			       OPT_Wunused_parameter, NULL, value,
+			       gfc_option_lang_mask (), kind, loc,
+			       handlers, global_dc);
+      set_Wextra (value);
+
+      break;
+
     case OPT_Wfunction_elimination:
       gfc_option.warn_function_elimination = value;
       break;