diff mbox series

PR fortran/91497 -- Silence conversion warnings

Message ID 20191003141141.GA8118@troutmask.apl.washington.edu
State New
Headers show
Series PR fortran/91497 -- Silence conversion warnings | expand

Commit Message

Steve Kargl Oct. 3, 2019, 2:11 p.m. UTC
The attach patch silences -Wconversion and -Wconversion-extra
warnings that had previously been issued for explicit conversions
(see testcase for examples).

The patch has been tested on x86-*-freebsd.  OK to commit?

2019-10-03  Steven G. Kargl  <kargl@gcc.gnu.org>

	PR fortran/91497
	* simplify.c (gfc_simplify_dble, simplify_intconv, gfc_simplify_real,
	gfc_simplify_sngl): Disable -Wconversion and -Wconversion-extra
	warnings for explicit conversion of literal constants.

2019-10-03  Steven G. Kargl  <kargl@gcc.gnu.org>

	PR fortran/91497
	* gfortran.dg/pr91497.f90: New test.

Comments

Thomas Koenig Oct. 3, 2019, 4:41 p.m. UTC | #1
Steve,

> The attach patch silences -Wconversion and -Wconversion-extra
> warnings that had previously been issued for explicit conversions
> (see testcase for examples).
> 
> The patch has been tested on x86-*-freebsd.  OK to commit?

OK.

Thanks a lot for the patch!

Regards

	Thomas
Rainer Orth Oct. 4, 2019, 3:49 p.m. UTC | #2
Hi Steve,

> The attach patch silences -Wconversion and -Wconversion-extra
> warnings that had previously been issued for explicit conversions
> (see testcase for examples).
>
> The patch has been tested on x86-*-freebsd.  OK to commit?
>
> 2019-10-03  Steven G. Kargl  <kargl@gcc.gnu.org>
>
> 	PR fortran/91497
> 	* simplify.c (gfc_simplify_dble, simplify_intconv, gfc_simplify_real,
> 	gfc_simplify_sngl): Disable -Wconversion and -Wconversion-extra
> 	warnings for explicit conversion of literal constants.
>
> 2019-10-03  Steven G. Kargl  <kargl@gcc.gnu.org>
>
> 	PR fortran/91497
> 	* gfortran.dg/pr91497.f90: New test.

the new testcases FAILs on sparc and a couple of other targets:

+FAIL: gfortran.dg/pr91497.f90   -O  (test for excess errors)

Excess errors:
/vol/gcc/src/hg/trunk/local/gcc/testsuite/gfortran.dg/pr91497.f90:13:13: Error: Old-style type declaration REAL*10 not supported at (1)
/vol/gcc/src/hg/trunk/local/gcc/testsuite/gfortran.dg/pr91497.f90:20:30: Error: Invalid real kind 10 at (1)
/vol/gcc/src/hg/trunk/local/gcc/testsuite/gfortran.dg/pr91497.f90:55:22: Error: Invalid kind for REAL at (1)

	Rainer
Steve Kargl Oct. 4, 2019, 4 p.m. UTC | #3
On Fri, Oct 04, 2019 at 05:49:13PM +0200, Rainer Orth wrote:
> 
> > The attach patch silences -Wconversion and -Wconversion-extra
> > warnings that had previously been issued for explicit conversions
> > (see testcase for examples).
> >
> > The patch has been tested on x86-*-freebsd.  OK to commit?
> >
> > 2019-10-03  Steven G. Kargl  <kargl@gcc.gnu.org>
> >
> > 	PR fortran/91497
> > 	* simplify.c (gfc_simplify_dble, simplify_intconv, gfc_simplify_real,
> > 	gfc_simplify_sngl): Disable -Wconversion and -Wconversion-extra
> > 	warnings for explicit conversion of literal constants.
> >
> > 2019-10-03  Steven G. Kargl  <kargl@gcc.gnu.org>
> >
> > 	PR fortran/91497
> > 	* gfortran.dg/pr91497.f90: New test.
> 
> the new testcases FAILs on sparc and a couple of other targets:
> 
> +FAIL: gfortran.dg/pr91497.f90   -O  (test for excess errors)
> 
> Excess errors:
> /vol/gcc/src/hg/trunk/local/gcc/testsuite/gfortran.dg/pr91497.f90:13:13: Error: Old-style type declaration REAL*10 not supported at (1)
> /vol/gcc/src/hg/trunk/local/gcc/testsuite/gfortran.dg/pr91497.f90:20:30: Error: Invalid real kind 10 at (1)
> /vol/gcc/src/hg/trunk/local/gcc/testsuite/gfortran.dg/pr91497.f90:55:22: Error: Invalid kind for REAL at (1)
> 

Well, that's a bummer.  I'll see about fixing this week.
Steve Kargl Oct. 4, 2019, 8:11 p.m. UTC | #4
On Fri, Oct 04, 2019 at 05:49:13PM +0200, Rainer Orth wrote:
> 
> > The attach patch silences -Wconversion and -Wconversion-extra
> > warnings that had previously been issued for explicit conversions
> > (see testcase for examples).
> >
> > The patch has been tested on x86-*-freebsd.  OK to commit?
> >
> > 2019-10-03  Steven G. Kargl  <kargl@gcc.gnu.org>
> >
> > 	PR fortran/91497
> > 	* simplify.c (gfc_simplify_dble, simplify_intconv, gfc_simplify_real,
> > 	gfc_simplify_sngl): Disable -Wconversion and -Wconversion-extra
> > 	warnings for explicit conversion of literal constants.
> >
> > 2019-10-03  Steven G. Kargl  <kargl@gcc.gnu.org>
> >
> > 	PR fortran/91497
> > 	* gfortran.dg/pr91497.f90: New test.
> 
> the new testcases FAILs on sparc and a couple of other targets:
> 
> +FAIL: gfortran.dg/pr91497.f90   -O  (test for excess errors)
> 
> Excess errors:
> /vol/gcc/src/hg/trunk/local/gcc/testsuite/gfortran.dg/pr91497.f90:13:13: Error: Old-style type declaration REAL*10 not supported at (1)
> /vol/gcc/src/hg/trunk/local/gcc/testsuite/gfortran.dg/pr91497.f90:20:30: Error: Invalid real kind 10 at (1)
> /vol/gcc/src/hg/trunk/local/gcc/testsuite/gfortran.dg/pr91497.f90:55:22: Error: Invalid kind for REAL at (1)
> 

Does the attach patch fix targets without REAL(10) and REAL(16)?
Rainer Orth Oct. 5, 2019, 1:18 p.m. UTC | #5
Hi Steve,

>> the new testcases FAILs on sparc and a couple of other targets:
>> 
>> +FAIL: gfortran.dg/pr91497.f90   -O  (test for excess errors)
>> 
>> Excess errors:
>> /vol/gcc/src/hg/trunk/local/gcc/testsuite/gfortran.dg/pr91497.f90:13:13:
>> Error: Old-style type declaration REAL*10 not supported at (1)
>> /vol/gcc/src/hg/trunk/local/gcc/testsuite/gfortran.dg/pr91497.f90:20:30:
>> Error: Invalid real kind 10 at (1)
>> /vol/gcc/src/hg/trunk/local/gcc/testsuite/gfortran.dg/pr91497.f90:55:22:
>> Error: Invalid kind for REAL at (1)
>> 
>
> Does the attach patch fix targets without REAL(10) and REAL(16)?

unfortunately not: I get

FAIL: gfortran.dg/pr91497_1.f90   -O  (test for excess errors)
Excess errors:
/vol/gcc/src/hg/trunk/local/gcc/testsuite/gfortran.dg/pr91497_1.f90:16:13: Error: Old-style type declaration REAL*10 not supported at (1)
/vol/gcc/src/hg/trunk/local/gcc/testsuite/gfortran.dg/pr91497_1.f90:23:30: Error: Invalid real kind 10 at (1)
/vol/gcc/src/hg/trunk/local/gcc/testsuite/gfortran.dg/pr91497_1.f90:30:15: Error: Symbol 'c' at (1) has no IMPLICIT type
/vol/gcc/src/hg/trunk/local/gcc/testsuite/gfortran.dg/pr91497_1.f90:54:8: Error: Symbol 'cc' at (1) has no IMPLICIT type
/vol/gcc/src/hg/trunk/local/gcc/testsuite/gfortran.dg/pr91497_1.f90:54:22: Error: Invalid kind for REAL at (1)

on sparc-sun-solaris2.11.

	Rainer
Steve Kargl Oct. 5, 2019, 1:27 p.m. UTC | #6
On Sat, Oct 05, 2019 at 03:18:45PM +0200, Rainer Orth wrote:
> Hi Steve,
> 
> >> the new testcases FAILs on sparc and a couple of other targets:
> >> 
> >> +FAIL: gfortran.dg/pr91497.f90   -O  (test for excess errors)
> >> 
> >> Excess errors:
> >> /vol/gcc/src/hg/trunk/local/gcc/testsuite/gfortran.dg/pr91497.f90:13:13:
> >> Error: Old-style type declaration REAL*10 not supported at (1)
> >> /vol/gcc/src/hg/trunk/local/gcc/testsuite/gfortran.dg/pr91497.f90:20:30:
> >> Error: Invalid real kind 10 at (1)
> >> /vol/gcc/src/hg/trunk/local/gcc/testsuite/gfortran.dg/pr91497.f90:55:22:
> >> Error: Invalid kind for REAL at (1)
> >> 
> >
> > Does the attach patch fix targets without REAL(10) and REAL(16)?
> 
> unfortunately not: I get
> 

The failures are in a test with 

+! { dg-require-effective-target fortran_large_real }

so that directive does not do what I thought.  Guess I'll
simply stripe out the testing of large REAL kinds.
Steve Kargl Oct. 5, 2019, 2:28 p.m. UTC | #7
On Sat, Oct 05, 2019 at 06:27:08AM -0700, Steve Kargl wrote:
> On Sat, Oct 05, 2019 at 03:18:45PM +0200, Rainer Orth wrote:
> > Hi Steve,
> > 
> > >> the new testcases FAILs on sparc and a couple of other targets:
> > >> 
> > >> +FAIL: gfortran.dg/pr91497.f90   -O  (test for excess errors)
> > >> 
> > >> Excess errors:
> > >> /vol/gcc/src/hg/trunk/local/gcc/testsuite/gfortran.dg/pr91497.f90:13:13:
> > >> Error: Old-style type declaration REAL*10 not supported at (1)
> > >> /vol/gcc/src/hg/trunk/local/gcc/testsuite/gfortran.dg/pr91497.f90:20:30:
> > >> Error: Invalid real kind 10 at (1)
> > >> /vol/gcc/src/hg/trunk/local/gcc/testsuite/gfortran.dg/pr91497.f90:55:22:
> > >> Error: Invalid kind for REAL at (1)
> > >> 
> > >
> > > Does the attach patch fix targets without REAL(10) and REAL(16)?
> > 
> > unfortunately not: I get
> > 
> 
> The failures are in a test with 
> 
> +! { dg-require-effective-target fortran_large_real }
> 
> so that directive does not do what I thought.  Guess I'll
> simply stripe out the testing of large REAL kinds.
> 

Should be fixed with

Index: gcc/testsuite/ChangeLog
===================================================================
--- gcc/testsuite/ChangeLog	(revision 276625)
+++ gcc/testsuite/ChangeLog	(working copy)
@@ -1,3 +1,8 @@
+2019-10-05  Steven G. Kargl  <kargl@gcc.gnu.org>
+
+	PR fortran/91497
+	* gfortran.dg/pr91497.f90: Run on i?86-*-* and x86_64-*-* only.
+
 2019-10-05  Paul Thomas  <pault@gcc.gnu.org>
 
 	PR fortran/91926
Index: gcc/testsuite/gfortran.dg/pr91497.f90
===================================================================
--- gcc/testsuite/gfortran.dg/pr91497.f90	(revision 276625)
+++ gcc/testsuite/gfortran.dg/pr91497.f90	(working copy)
@@ -1,4 +1,4 @@
-! { dg-do compile }
+! { dg-do compile { target { i?86-*-* x86_64-*-* } } }
 ! { dg-options "-Wall" }
 ! Code contributed by Manfred Schwarb <manfred99 at gmx dot ch>
 ! PR fortran/91497
diff mbox series

Patch

Index: gcc/fortran/simplify.c
===================================================================
--- gcc/fortran/simplify.c	(revision 276474)
+++ gcc/fortran/simplify.c	(working copy)
@@ -2189,11 +2189,22 @@  gfc_expr *
 gfc_simplify_dble (gfc_expr *e)
 {
   gfc_expr *result = NULL;
+  int tmp1, tmp2;
 
   if (e->expr_type != EXPR_CONSTANT)
     return NULL;
 
+  /* For explicit conversion, turn off -Wconversion and -Wconversion-extra
+     warnings.  */
+  tmp1 = warn_conversion;
+  tmp2 = warn_conversion_extra;
+  warn_conversion = warn_conversion_extra = 0;
+
   result = gfc_convert_constant (e, BT_REAL, gfc_default_double_kind);
+
+  warn_conversion = tmp1;
+  warn_conversion_extra = tmp2;
+
   if (result == &gfc_bad_expr)
     return &gfc_bad_expr;
 
@@ -3572,6 +3583,7 @@  static gfc_expr *
 simplify_intconv (gfc_expr *e, int kind, const char *name)
 {
   gfc_expr *result = NULL;
+  int tmp1, tmp2;
 
   /* Convert BOZ to integer, and return without range checking.  */
   if (e->ts.type == BT_BOZ)
@@ -3585,7 +3597,17 @@  simplify_intconv (gfc_expr *e, int kind, const char *n
   if (e->expr_type != EXPR_CONSTANT)
     return NULL;
 
+  /* For explicit conversion, turn off -Wconversion and -Wconversion-extra
+     warnings.  */
+  tmp1 = warn_conversion;
+  tmp2 = warn_conversion_extra;
+  warn_conversion = warn_conversion_extra = 0;
+
   result = gfc_convert_constant (e, BT_INTEGER, kind);
+
+  warn_conversion = tmp1;
+  warn_conversion_extra = tmp2;
+
   if (result == &gfc_bad_expr)
     return &gfc_bad_expr;
 
@@ -6472,7 +6494,7 @@  gfc_expr *
 gfc_simplify_real (gfc_expr *e, gfc_expr *k)
 {
   gfc_expr *result = NULL;
-  int kind;
+  int kind, tmp1, tmp2;
 
   /* Convert BOZ to real, and return without range checking.  */
   if (e->ts.type == BT_BOZ)
@@ -6500,7 +6522,17 @@  gfc_simplify_real (gfc_expr *e, gfc_expr *k)
   if (e->expr_type != EXPR_CONSTANT)
     return NULL;
 
+  /* For explicit conversion, turn off -Wconversion and -Wconversion-extra
+     warnings.  */
+  tmp1 = warn_conversion;
+  tmp2 = warn_conversion_extra;
+  warn_conversion = warn_conversion_extra = 0;
+
   result = gfc_convert_constant (e, BT_REAL, kind);
+
+  warn_conversion = tmp1;
+  warn_conversion_extra = tmp2;
+
   if (result == &gfc_bad_expr)
     return &gfc_bad_expr;
 
@@ -7551,11 +7583,22 @@  gfc_expr *
 gfc_simplify_sngl (gfc_expr *a)
 {
   gfc_expr *result;
+  int tmp1, tmp2;
 
   if (a->expr_type != EXPR_CONSTANT)
     return NULL;
 
+  /* For explicit conversion, turn off -Wconversion and -Wconversion-extra
+     warnings.  */
+  tmp1 = warn_conversion;
+  tmp2 = warn_conversion_extra;
+  warn_conversion = warn_conversion_extra = 0;
+
   result = gfc_real2real (a, gfc_default_real_kind);
+
+  warn_conversion = tmp1;
+  warn_conversion_extra = tmp2;
+
   return range_check (result, "SNGL");
 }
 
Index: gcc/testsuite/gfortran.dg/pr91497.f90
===================================================================
--- gcc/testsuite/gfortran.dg/pr91497.f90	(nonexistent)
+++ gcc/testsuite/gfortran.dg/pr91497.f90	(working copy)
@@ -0,0 +1,127 @@ 
+! { dg-do compile }
+! { dg-options "-Wall" }
+! Code contributed by Manfred Schwarb <manfred99 at gmx dot ch>
+! PR fortran/91497
+!
+! Prior to applying the patch for this PR, the following code
+! would generate numerous conversion warnings.
+!
+program foo
+
+      real*4 a,aa
+      real*8 b,bb
+      real*10 c,cc
+      real*16 d
+      integer*2 e,ee
+      integer*4 f,ff
+      integer*8 g,gg
+      PARAMETER(a=3.1415927_4)
+      PARAMETER(b=3.1415927_8)
+      PARAMETER(c=3.1415927_10)
+      PARAMETER(d=3.1415927_16)
+      PARAMETER(e=123_2)
+      PARAMETER(f=123_4)
+      PARAMETER(g=123_8)
+
+      aa=REAL(b)
+      aa=REAL(c)
+      aa=REAL(d)
+      aa=REAL(e)
+      aa=REAL(f)
+      aa=REAL(g)
+      aa=FLOAT(f)
+      aa=FLOOR(b)
+      aa=FLOOR(c)
+      aa=FLOOR(d)
+      aa=CEILING(b)
+      aa=CEILING(c)
+      aa=CEILING(d)
+      !---unknown but documented type conversions:
+      !!aa=FLOATI(e)
+      !!aa=FLOATJ(f)
+      !!aa=FLOATK(g)
+      !---documentation is wrong for sngl:
+      aa=SNGL(c)
+      aa=SNGL(d)
+      bb=REAL(c, kind=8)
+      bb=REAL(d, kind=8)
+      bb=DBLE(c)
+      bb=DBLE(d)
+      bb=DFLOAT(g)
+      bb=FLOOR(c)
+      bb=FLOOR(d)
+      bb=CEILING(c)
+      bb=CEILING(d)
+      cc=REAL(d, kind=10)
+      cc=FLOOR(d)
+      cc=CEILING(d)
+
+      aa=AINT(b)
+      aa=ANINT(b)
+      aa=AINT(c)
+      aa=ANINT(c)
+      aa=AINT(d)
+      aa=ANINT(d)
+      bb=DINT(b)
+      bb=DNINT(b)
+
+      ee=INT(a, kind=2)
+      ee=NINT(a, kind=2)
+      ee=INT(b, kind=2)
+      ee=NINT(b, kind=2)
+      ee=INT(c, kind=2)
+      ee=NINT(c, kind=2)
+      ee=INT(d, kind=2)
+      ee=NINT(d, kind=2)
+      ee=INT(f, kind=2)
+      ee=INT(g, kind=2)
+      ee=IFIX(a)
+      ee=IDINT(b)
+      ee=IDNINT(b)
+      ee=INT2(a)
+      ee=INT2(b)
+      ee=INT2(c)
+      ee=INT2(d)
+      ee=INT2(f)
+      ee=INT2(g)
+
+      ff=INT(a, kind=4)
+      ff=NINT(a, kind=4)
+      ff=INT(b, kind=4)
+      ff=NINT(b, kind=4)
+      ff=INT(c, kind=4)
+      ff=NINT(c, kind=4)
+      ff=INT(d, kind=4)
+      ff=NINT(d, kind=4)
+      ff=INT(f, kind=4)
+      ff=INT(g, kind=4)
+      ff=IFIX(a)
+      ff=IDINT(b)
+      ff=IDNINT(b)
+      !---LONG not allowed anymore in gfortran 10 (?):
+      !!ff=LONG(a)
+      !!ff=LONG(b)
+      !!ff=LONG(c)
+      !!ff=LONG(d)
+      !!ff=LONG(g)
+
+      gg=INT(a, kind=8)
+      gg=NINT(a, kind=8)
+      gg=INT(b, kind=8)
+      gg=NINT(b, kind=8)
+      gg=INT(c, kind=8)
+      gg=NINT(c, kind=8)
+      gg=INT(d, kind=8)
+      gg=NINT(d, kind=8)
+      gg=INT(f, kind=8)
+      gg=INT(g, kind=8)
+      gg=IFIX(a)
+      gg=IDINT(b)
+      gg=IDNINT(b)
+      gg=INT8(a)
+      gg=INT8(b)
+      gg=INT8(c)
+      gg=INT8(d)
+      gg=INT8(g)
+end
+