Patchwork [fortran] Reduce Explosion of noise from -Wall

login
register
mail settings
Submitter Thomas Koenig
Date Aug. 22, 2012, 8:47 p.m.
Message ID <50354566.1050109@netcologne.de>
Download mbox | patch
Permalink /patch/179405/
State New
Headers show

Comments

Thomas Koenig - Aug. 22, 2012, 8:47 p.m.
Am 22.08.2012 11:18, schrieb Tobias Burnus:

> Regarding -Wcompare-real, I wonder whether it makes sense to either
> ignore comparisions against zero or to put them into a different flag
> (-Wcompare-real-zero);

Here is a patch to not warn for comparisons against zero.
Regression-tested, also tested with make info and make dvi.

OK for trunk?

	Thomas

012-08-22  Thomas König  <tkoenig@gcc.gnu.org>

         PR fortran/54298
         * invoke.texi:  Document that -Wcompare-reals does not warn for
         comparison against zero.
         * resolve.c (is_real_zero):  New function.
         (is_complex_zero):  New function.
         (resolve_operator):  If the comparison is against real or complex
         zero, don't warn about equality/inequality comparisions.
         Document how to suppress the warning in the error message.

2012-08-22  Thomas König  <tkoenig@gcc.gnu.org>

         PR fortran/54298
         * gfortran.dg/compare_real_2.f90:  New test.
Steve Kargl - Aug. 23, 2012, 2:40 a.m.
On Wed, Aug 22, 2012 at 10:47:34PM +0200, Thomas Koenig wrote:
> Am 22.08.2012 11:18, schrieb Tobias Burnus:
> 
> >Regarding -Wcompare-real, I wonder whether it makes sense to either
> >ignore comparisions against zero or to put them into a different flag
> >(-Wcompare-real-zero);
> 
> Here is a patch to not warn for comparisons against zero.
> Regression-tested, also tested with make info and make dvi.
> 
> OK for trunk?
> 

I would rather see the -Wcompare-real option removed
from -Wall.  The patch does nothing for the 158 warnings
for comparison with ONE in BLAS.  This, of course, is
just my opinion and you're moe than welcomed to ignore
it.

Patch

Index: invoke.texi
===================================================================
--- invoke.texi	(Revision 190541)
+++ invoke.texi	(Arbeitskopie)
@@ -939,7 +939,8 @@  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.
-Enabled by @option{-Wall}.
+Comparisons against zero are not warned about.  Enabled by
+@option{-Wall}.
 
 @item -Wtarget-lifetime
 @opindex @code{Wtargt-lifetime}
Index: resolve.c
===================================================================
--- resolve.c	(Revision 190541)
+++ resolve.c	(Arbeitskopie)
@@ -3876,7 +3876,27 @@  compare_shapes (gfc_expr *op1, gfc_expr *op2)
   return t;
 }
 
+/* Check if an expr is a zero REAL constant.  */
 
+static bool
+is_real_zero (gfc_expr *e)
+{
+  return e->ts.type == BT_REAL && e->expr_type == EXPR_CONSTANT
+    && mpfr_sgn (e->value.real) == 0;
+    
+}
+
+/* Check if an expr is a zero COMPLEX constant.  */
+
+static bool
+is_complex_zero (gfc_expr *e)
+{
+  return e->ts.type == BT_COMPLEX && e->expr_type == EXPR_CONSTANT
+    && mpfr_sgn (mpc_realref (e->value.complex)) == 0
+    && mpfr_sgn (mpc_imagref (e->value.complex)) == 0;
+
+}
+
 /* Resolve an operator expression node.  This can involve replacing the
    operation with a user defined function call.  */
 
@@ -4047,11 +4067,16 @@  resolve_operator (gfc_expr *e)
 		{
 		  const char *msg;
 
+		  /* Comparisons against zero are usually legitimate, so let's not warn.  */
+		  if (is_real_zero (op1) || is_real_zero (op2)
+		      || is_complex_zero (op1) || is_complex_zero (op2))
+		    break;
+
 		  if (op == INTRINSIC_EQ || op == INTRINSIC_EQ_OS)
-		    msg = "Equality comparison for %s at %L";
+		    msg = "Equality comparison for %s at %L [use -Wno-compare-reals to suppress]";
 		  else
-		    msg = "Inequality comparison for %s at %L";
-		  
+		    msg = "Inequality comparison for %s at %L [use -Wno-compare-reals to suppress]";
+
 		  gfc_warning (msg, gfc_typename (&op1->ts), &op1->where);
 		}
 	    }