public inbox for fortran@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] PR fortran/91497 -- Silence conversion warnings for MIN1 and MAX1
@ 2021-11-02 12:57 Manfred Schwarb
  2021-11-02 13:26 ` Thomas Koenig
  0 siblings, 1 reply; 10+ messages in thread
From: Manfred Schwarb @ 2021-11-02 12:57 UTC (permalink / raw)
  To: fortran, gcc-patches

[-- Attachment #1: Type: text/plain, Size: 370 bytes --]

Hi,

In addition to the patches of Steve Kargl for PR 91497:
The MIN1 and MAX1 intrinsics do explicit type conversions and should
be silenced too for -Wconversion and -Wconversion-extra.

Adjust testcase to only use *4 and *8 real types, provide a second
testcase for *10 and *16 precisions.

Regtested on Linux x86_64.

Signed-off-by Manfred Schwarb <manfred99@gmx.ch>

[-- Attachment #2: pr91497.f90.patch --]
[-- Type: text/x-patch, Size: 6361 bytes --]

2021-11-02  Manfred Schwarb  <manfred99@gmx.ch>

gcc/testsuite/ChangeLog:

	PR fortran/91497
	* gfortran.dg/pr91497.f90: Adjust test to only use single and
	double precision. Add complex intrinsics.

--- a/gcc/testsuite/gfortran.dg/pr91497.f90
+++ b/gcc/testsuite/gfortran.dg/pr91497.f90
@@ -1,4 +1,4 @@
-! { dg-do compile { target { i?86-*-* x86_64-*-* } } }
+! { dg-do compile }
 ! { dg-options "-Wall" }
 ! Code contributed by Manfred Schwarb <manfred99 at gmx dot ch>
 ! PR fortran/91497
@@ -8,120 +8,120 @@
 !
 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
+      real*4 a, aa
+      real*8 b, bb
+      integer*2 e, ee
+      integer*4 f, ff
+      integer*8 g, gg
+      complex(4) ww
+      complex(8) xx
       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(b)    ! was: Change of value in conversion from 'REAL(8)' to 'REAL(4)'
       aa=REAL(e)
       aa=REAL(f)
       aa=REAL(g)
+      aa=REAL(b, kind=4)   ! was: Change of value in conversion from 'REAL(8)' to 'REAL(4)'
+      bb=REAL(a, kind=8)
+
       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)
+      aa=SNGL(b)    ! was: Change of value in conversion from 'REAL(8)' to 'REAL(4)'
+      aa=AINT(a)
+      bb=AINT(b)
+      aa=AINT(b, kind=4)
       bb=DINT(b)
+      aa=ANINT(a)
+      bb=ANINT(b)
+      aa=ANINT(b, kind=4)
       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)
+      !---DEC type conversions (-fdec):
+      !!aa=FLOATI(e)
+      !!aa=FLOATJ(f)
+      !!aa=FLOATK(g)
+      aa=AMAX0(f, f)
+      aa=AMIN0(f, f)
+      aa=AMAX0(g, g)
+      aa=AMIN0(g, g)
+
+      ee=INT(a)
+      ee=INT(a, kind=2)    ! was: Change of value in conversion from 'REAL(4)' to 'INTEGER(2)'
+      ee=INT(b, kind=2)    ! was: Change of value in conversion from 'REAL(8)' to 'INTEGER(2)'
       ee=INT(f, kind=2)
       ee=INT(g, kind=2)
+      ff=INT(b)
+      ff=INT(a, kind=4)    ! was: Change of value in conversion from 'REAL(4)' to 'INTEGER(4)'
+      ff=INT(b, kind=4)    ! was: Change of value in conversion from 'REAL(8)' to 'INTEGER(4)'
+      ff=INT(f, kind=4)
+      ff=INT(g, kind=4)
+      gg=INT(a)
+      gg=INT(a, kind=8)    ! was: Change of value in conversion from 'REAL(4)' to 'INTEGER(8)'
+      gg=INT(b, kind=8)    ! was: Change of value in conversion from 'REAL(8)' to 'INTEGER(8)'
+      gg=INT(f, kind=8)
+      gg=INT(g, kind=8)
+
       ee=IFIX(a)
+      ff=IFIX(a)
+      gg=IFIX(a)
       ee=IDINT(b)
-      ee=IDNINT(b)
-      ee=INT2(a)
-      ee=INT2(b)
-      ee=INT2(c)
-      ee=INT2(d)
+      ff=IDINT(b)
+      gg=IDINT(b)
+      ee=INT2(a)    ! was: Change of value in conversion from 'REAL(4)' to 'INTEGER(2)'
+      ee=INT2(b)    ! was: Change of value in conversion from 'REAL(8)' to 'INTEGER(2)'
       ee=INT2(f)
       ee=INT2(g)
+      gg=INT8(a)    ! was: Change of value in conversion from 'REAL(4)' to 'INTEGER(8)'
+      gg=INT8(b)    ! was: Change of value in conversion from 'REAL(8)' to 'INTEGER(8)'
+      gg=INT8(f)
+      gg=INT8(g)
+
+      ff=FLOOR(b)
+      ee=FLOOR(b, kind=2)
+      ff=FLOOR(b, kind=4)
+      gg=FLOOR(b, kind=8)
+      ff=CEILING(b)
+      ee=CEILING(b, kind=2)
+      ff=CEILING(b, kind=4)
+      gg=CEILING(b, kind=8)
+      ff=MAX1(a, a)    ! was: Change of value in conversion from 'REAL(4)' to 'INTEGER(4)'
+      ff=MIN1(a, a)    ! was: Change of value in conversion from 'REAL(4)' to 'INTEGER(4)'
+      gg=MAX1(b, b)    ! was: Change of value in conversion from 'REAL(8)' to 'INTEGER(4)'
+      gg=MIN1(b, b)    ! was: Change of value in conversion from 'REAL(8)' to 'INTEGER(4)'

-      ff=INT(a, kind=4)
+      ee=NINT(a, kind=2)
+      ee=NINT(b, kind=2)
+      ff=NINT(a)
+      ff=NINT(b)
       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)
+      ee=IDNINT(b)
+      ff=IDNINT(b)
       gg=IDNINT(b)
-      gg=INT8(a)
-      gg=INT8(b)
-      gg=INT8(c)
-      gg=INT8(d)
-      gg=INT8(g)
-end

+      ww=COMPLEX(a, a)
+      ww=COMPLEX(e, e)
+      ww=COMPLEX(g, g)
+      ww=COMPLEX(a, g)
+      xx=COMPLEX(b, g)
+      ww=CMPLX(a, a)
+      ww=CMPLX(b, b, kind=4)
+      xx=CMPLX(a, a, kind=8)
+
+      aa=REAL(ww)
+      bb=REAL(xx)
+      aa=REALPART(ww)
+      bb=REALPART(xx)
+      aa=AIMAG(ww)
+      bb=AIMAG(xx)
+      aa=IMAG(ww)
+      bb=IMAG(xx)
+      bb=DIMAG(xx)
+      aa=IMAGPART(ww)
+      bb=IMAGPART(xx)
+end

[-- Attachment #3: pr91497_2.f90.patch --]
[-- Type: text/x-patch, Size: 3206 bytes --]

2021-11-02  Manfred Schwarb  <manfred99@gmx.ch>

gcc/testsuite/ChangeLog:

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

--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/pr91497_2.f90
@@ -0,0 +1,80 @@
+! { dg-do compile }
+! { dg-require-effective-target fortran_real_10 }
+! { dg-require-effective-target fortran_real_16 }
+! { 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 cc
+      real*10 a, aa
+      real*16 b, bb
+      integer*2 ee
+      integer*4 ff
+      integer*8 gg
+      complex(10) ww
+      complex(16) xx
+      PARAMETER(a=3.1415927_10)
+      PARAMETER(b=3.1415927_16)
+
+      cc=REAL(a)    ! was: Change of value in conversion from 'REAL(10)' to 'REAL(4)'
+      cc=REAL(b)    ! was: Change of value in conversion from 'REAL(16)' to 'REAL(4)'
+      aa=REAL(b, kind=10)   ! was: Change of value in conversion from 'REAL(16)' to 'REAL(10)'
+      bb=REAL(a, kind=16)
+
+      cc=SNGL(a)    ! was: Change of value in conversion from 'REAL(10)' to 'REAL(4)'
+      cc=SNGL(b)    ! was: Change of value in conversion from 'REAL(16)' to 'REAL(4)'
+      aa=AINT(a)
+      bb=AINT(b)
+      aa=AINT(b, kind=10)
+      aa=ANINT(a)
+      bb=ANINT(b)
+      aa=ANINT(b, kind=10)
+
+      ff=INT(b)    ! was: Change of value in conversion from 'REAL(16)' to 'INTEGER(4)'
+      ff=INT(a, kind=4)    ! was: Change of value in conversion from 'REAL(10)' to 'INTEGER(4)'
+      ff=INT(b, kind=4)    ! was: Change of value in conversion from 'REAL(16)' to 'INTEGER(4)'
+      gg=INT(a, kind=8)    ! was: Change of value in conversion from 'REAL(10)' to 'INTEGER(8)'
+      gg=INT(b, kind=8)    ! was: Change of value in conversion from 'REAL(16)' to 'INTEGER(8)'
+
+      ee=INT2(a)    ! was: Change of value in conversion from 'REAL(10)' to 'INTEGER(2)'
+      ee=INT2(b)    ! was: Change of value in conversion from 'REAL(16)' to 'INTEGER(2)'
+      gg=INT8(a)    ! was: Change of value in conversion from 'REAL(10)' to 'INTEGER(8)'
+      gg=INT8(b)    ! was: Change of value in conversion from 'REAL(16)' to 'INTEGER(8)'
+
+      ff=FLOOR(a, kind=4)
+      gg=FLOOR(b, kind=8)
+      ff=CEILING(a, kind=4)
+      gg=CEILING(b, kind=8)
+      ff=MAX1(a, a)    ! was: Change of value in conversion from 'REAL(10)' to 'INTEGER(4)'
+      ff=MIN1(a, a)    ! was: Change of value in conversion from 'REAL(10)' to 'INTEGER(4)'
+      gg=MAX1(b, b)    ! was: Change of value in conversion from 'REAL(16)' to 'INTEGER(4)'
+      gg=MIN1(b, b)    ! was: Change of value in conversion from 'REAL(16)' to 'INTEGER(4)'
+
+      ff=NINT(a)
+      ff=NINT(b)
+      ff=NINT(a, kind=4)
+      ff=NINT(b, kind=4)
+      gg=NINT(a, kind=8)
+      gg=NINT(b, kind=8)
+
+      ww=COMPLEX(a, a)
+      xx=COMPLEX(b, b)
+      ww=CMPLX(b, b, kind=10)
+      xx=CMPLX(a, a, kind=16)
+
+      aa=REAL(ww)
+      bb=REAL(xx)
+      aa=REALPART(ww)
+      bb=REALPART(xx)
+      aa=AIMAG(ww)
+      bb=AIMAG(xx)
+      aa=IMAG(ww)
+      bb=IMAG(xx)
+      aa=IMAGPART(ww)
+      bb=IMAGPART(xx)
+end

[-- Attachment #4: simplify.c.patch --]
[-- Type: text/x-patch, Size: 1206 bytes --]

2021-11-02  Manfred Schwarb  <manfred99@gmx.ch>

gcc/fortran/ChangeLog:

	PR fortran/91497
	* simplify.c (simplify_min_max): Disable conversion warnings for
	MIN1 and MAX1.

--- a/gcc/fortran/simplify.c
+++ b/gcc/fortran/simplify.c
@@ -5087,6 +5087,7 @@ min_max_choose (gfc_expr *arg, gfc_expr
 static gfc_expr *
 simplify_min_max (gfc_expr *expr, int sign)
 {
+  int tmp1, tmp2;
   gfc_actual_arglist *arg, *last, *extremum;
   gfc_expr *tmp, *ret;
   const char *fname;
@@ -5131,7 +5132,16 @@ simplify_min_max (gfc_expr *expr, int si
   if ((tmp->ts.type != BT_INTEGER || tmp->ts.kind != gfc_integer_4_kind)
       && (strcmp (fname, "min1") == 0 || strcmp (fname, "max1") == 0))
     {
+      /* Explicit conversion, turn off -Wconversion and -Wconversion-extra
+         warnings.  */
+      tmp1 = warn_conversion;
+      tmp2 = warn_conversion_extra;
+      warn_conversion = warn_conversion_extra = 0;
+
       ret = gfc_convert_constant (tmp, BT_INTEGER, gfc_integer_4_kind);
+
+      warn_conversion = tmp1;
+      warn_conversion_extra = tmp2;
     }
   else if ((tmp->ts.type != BT_REAL || tmp->ts.kind != gfc_real_4_kind)
 	   && (strcmp (fname, "amin0") == 0 || strcmp (fname, "amax0") == 0))

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] PR fortran/91497 -- Silence conversion warnings for MIN1 and MAX1
  2021-11-02 12:57 [PATCH] PR fortran/91497 -- Silence conversion warnings for MIN1 and MAX1 Manfred Schwarb
@ 2021-11-02 13:26 ` Thomas Koenig
  2021-11-02 14:22   ` Manfred Schwarb
  0 siblings, 1 reply; 10+ messages in thread
From: Thomas Koenig @ 2021-11-02 13:26 UTC (permalink / raw)
  To: Manfred Schwarb, fortran, gcc-patches

Hi Manfred,

> In addition to the patches of Steve Kargl for PR 91497:
> The MIN1 and MAX1 intrinsics do explicit type conversions and should
> be silenced too for -Wconversion and -Wconversion-extra.
> 
> Adjust testcase to only use *4 and *8 real types, provide a second
> testcase for *10 and *16 precisions.
Two points:

We should modify existing test cases only when necessary, because
modification can impede a regression test.  It is better to create
a new one.

While we do recognize real*4 and real*8 and so on, these are
non-standard extensions, and I would like to avoid to have these
with new test cases.

Instead of real*8, you can use real(8) or double precision.

OK with these changes to the test cases.

Thanks for the patch!

Best regards

	Thomas

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] PR fortran/91497 -- Silence conversion warnings for MIN1 and MAX1
  2021-11-02 13:26 ` Thomas Koenig
@ 2021-11-02 14:22   ` Manfred Schwarb
  2021-11-02 18:39     ` Thomas Koenig
  0 siblings, 1 reply; 10+ messages in thread
From: Manfred Schwarb @ 2021-11-02 14:22 UTC (permalink / raw)
  To: Thomas Koenig, fortran, gcc-patches

Am 02.11.21 um 14:26 schrieb Thomas Koenig:
> Hi Manfred,
>
>> In addition to the patches of Steve Kargl for PR 91497:
>> The MIN1 and MAX1 intrinsics do explicit type conversions and should
>> be silenced too for -Wconversion and -Wconversion-extra.
>>
>> Adjust testcase to only use *4 and *8 real types, provide a second
>> testcase for *10 and *16 precisions.
> Two points:
>
> We should modify existing test cases only when necessary, because
> modification can impede a regression test.  It is better to create
> a new one.
>

Yes, but this was a quick-and-dirty test of mine, and I realized only afterwards
that Steve had used it as-is. The new testcase is more consistent and more complete.
Sandra got errors on targets without REAL(16) support and requested changes,
so I decided to split it.

So you want me to "split" it in 3 parts?
- existing test as is, only for targets with REAL(16) support
- additional tests incl. complex intrinsics for targets with REAL(16) support
- additional tests incl. complex intrinsics for all targets, only single and double precision

OTOH, it is perhaps not worth the trouble to do REAL(10) and REAL(16) tests, either
it warns or it does not.

> While we do recognize real*4 and real*8 and so on, these are
> non-standard extensions, and I would like to avoid to have these
> with new test cases.
>
> Instead of real*8, you can use real(8) or double precision.
>

Well, double precision is deprecated AFAIK.

> OK with these changes to the test cases.
>
> Thanks for the patch!
>
> Best regards
>
>     Thomas


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] PR fortran/91497 -- Silence conversion warnings for MIN1 and MAX1
  2021-11-02 14:22   ` Manfred Schwarb
@ 2021-11-02 18:39     ` Thomas Koenig
  2021-11-06 15:37       ` Manfred Schwarb
  0 siblings, 1 reply; 10+ messages in thread
From: Thomas Koenig @ 2021-11-02 18:39 UTC (permalink / raw)
  To: Manfred Schwarb, fortran, gcc-patches

On 02.11.21 15:22, Manfred Schwarb wrote:
> Am 02.11.21 um 14:26 schrieb Thomas Koenig:
>> Hi Manfred,
>>
>>> In addition to the patches of Steve Kargl for PR 91497:
>>> The MIN1 and MAX1 intrinsics do explicit type conversions and should
>>> be silenced too for -Wconversion and -Wconversion-extra.
>>>
>>> Adjust testcase to only use *4 and *8 real types, provide a second
>>> testcase for *10 and *16 precisions.
>> Two points:
>>
>> We should modify existing test cases only when necessary, because
>> modification can impede a regression test.  It is better to create
>> a new one.
>>
> 
> Yes, but this was a quick-and-dirty test of mine, and I realized only afterwards
> that Steve had used it as-is. The new testcase is more consistent and more complete.
> Sandra got errors on targets without REAL(16) support and requested changes,
> so I decided to split it.
> 
> So you want me to "split" it in 3 parts?
> - existing test as is, only for targets with REAL(16) support
> - additional tests incl. complex intrinsics for targets with REAL(16) support
> - additional tests incl. complex intrinsics for all targets, only single and double precision
> 
> OTOH, it is perhaps not worth the trouble to do REAL(10) and REAL(16) tests, either
> it warns or it does not.

Anything that tests both complex and REAL(16) is fine by me.  I don't
think you need to test the combination of COMPLEX(16), both
codepaths have been seen by that time :-)

Or you can split it three ways, like you wrote above.

>> While we do recognize real*4 and real*8 and so on, these are
>> non-standard extensions, and I would like to avoid to have these
>> with new test cases.
>>
>> Instead of real*8, you can use real(8) or double precision.
>>
> 
> Well, double precision is deprecated AFAIK.

Not in Fortran 2018.

Best regards

	Thomas

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] PR fortran/91497 -- Silence conversion warnings for MIN1 and MAX1
  2021-11-02 18:39     ` Thomas Koenig
@ 2021-11-06 15:37       ` Manfred Schwarb
  2021-11-06 18:28         ` Thomas Koenig
  0 siblings, 1 reply; 10+ messages in thread
From: Manfred Schwarb @ 2021-11-06 15:37 UTC (permalink / raw)
  To: Thomas Koenig, fortran, gcc-patches

[-- Attachment #1: Type: text/plain, Size: 2180 bytes --]

Am 02.11.21 um 19:39 schrieb Thomas Koenig:
> On 02.11.21 15:22, Manfred Schwarb wrote:
>> Am 02.11.21 um 14:26 schrieb Thomas Koenig:
>>> Hi Manfred,
>>>
>>>> In addition to the patches of Steve Kargl for PR 91497:
>>>> The MIN1 and MAX1 intrinsics do explicit type conversions and should
>>>> be silenced too for -Wconversion and -Wconversion-extra.
>>>>
>>>> Adjust testcase to only use *4 and *8 real types, provide a second
>>>> testcase for *10 and *16 precisions.
>>> Two points:
>>>
>>> We should modify existing test cases only when necessary, because
>>> modification can impede a regression test.  It is better to create
>>> a new one.
>>>

I only changed the test case to use dg-require-effective-target and real(n) notation now.

Added a second case without real(10) and real(16), but for all targets, which
covers MIN1 and MAX1 too.


>>
>> Yes, but this was a quick-and-dirty test of mine, and I realized only afterwards
>> that Steve had used it as-is. The new testcase is more consistent and more complete.
>> Sandra got errors on targets without REAL(16) support and requested changes,
>> so I decided to split it.
>>
>> So you want me to "split" it in 3 parts?
>> - existing test as is, only for targets with REAL(16) support
>> - additional tests incl. complex intrinsics for targets with REAL(16) support
>> - additional tests incl. complex intrinsics for all targets, only single and double precision
>>
>> OTOH, it is perhaps not worth the trouble to do REAL(10) and REAL(16) tests, either
>> it warns or it does not.
>
> Anything that tests both complex and REAL(16) is fine by me.  I don't
> think you need to test the combination of COMPLEX(16), both
> codepaths have been seen by that time :-)
>
> Or you can split it three ways, like you wrote above.
>
>>> While we do recognize real*4 and real*8 and so on, these are
>>> non-standard extensions, and I would like to avoid to have these
>>> with new test cases.
>>>
>>> Instead of real*8, you can use real(8) or double precision.
>>>
>>
>> Well, double precision is deprecated AFAIK.
>
> Not in Fortran 2018.
>
> Best regards
>
> 	Thomas
>


[-- Attachment #2: simplify.c.patch --]
[-- Type: text/x-patch, Size: 1206 bytes --]

2021-11-06  Manfred Schwarb  <manfred99@gmx.ch>

gcc/fortran/ChangeLog:

	PR fortran/91497
	* simplify.c (simplify_min_max): Disable conversion warnings for
	MIN1 and MAX1.

--- a/gcc/fortran/simplify.c
+++ b/gcc/fortran/simplify.c
@@ -5087,6 +5087,7 @@ min_max_choose (gfc_expr *arg, gfc_expr
 static gfc_expr *
 simplify_min_max (gfc_expr *expr, int sign)
 {
+  int tmp1, tmp2;
   gfc_actual_arglist *arg, *last, *extremum;
   gfc_expr *tmp, *ret;
   const char *fname;
@@ -5131,7 +5132,16 @@ simplify_min_max (gfc_expr *expr, int si
   if ((tmp->ts.type != BT_INTEGER || tmp->ts.kind != gfc_integer_4_kind)
       && (strcmp (fname, "min1") == 0 || strcmp (fname, "max1") == 0))
     {
+      /* Explicit conversion, turn off -Wconversion and -Wconversion-extra
+         warnings.  */
+      tmp1 = warn_conversion;
+      tmp2 = warn_conversion_extra;
+      warn_conversion = warn_conversion_extra = 0;
+
       ret = gfc_convert_constant (tmp, BT_INTEGER, gfc_integer_4_kind);
+
+      warn_conversion = tmp1;
+      warn_conversion_extra = tmp2;
     }
   else if ((tmp->ts.type != BT_REAL || tmp->ts.kind != gfc_real_4_kind)
 	   && (strcmp (fname, "amin0") == 0 || strcmp (fname, "amax0") == 0))

[-- Attachment #3: testsuite.patch --]
[-- Type: text/x-patch, Size: 5807 bytes --]

2021-11-06  Manfred Schwarb  <manfred99@gmx.ch>

gcc/testsuite/ChangeLog:

	PR fortran/91497
	* gfortran.dg/pr91497.f90: Adjust test to use
	dg-require-effective-target directive.
	* gfortran.dg/pr91497_2.f90: New test to cover all targets.
	Cover MAX1 and MIN1 intrinsics.

--- a/gcc/testsuite/gfortran.dg/pr91497.f90
+++ b/gcc/testsuite/gfortran.dg/pr91497.f90
@@ -1,4 +1,6 @@
-! { dg-do compile { target { i?86-*-* x86_64-*-* } } }
+! { dg-do compile }
+! { dg-require-effective-target fortran_real_10 }
+! { dg-require-effective-target fortran_real_16 }
 ! { dg-options "-Wall" }
 ! Code contributed by Manfred Schwarb <manfred99 at gmx dot ch>
 ! PR fortran/91497
@@ -8,13 +10,13 @@
 !
 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
+      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)
@@ -36,11 +38,10 @@ program foo
       aa=CEILING(b)
       aa=CEILING(c)
       aa=CEILING(d)
-      !---unknown but documented type conversions:
+      !---DEC specific type conversions (-fdec):
       !!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)
@@ -98,7 +99,7 @@ program foo
       ff=IFIX(a)
       ff=IDINT(b)
       ff=IDNINT(b)
-      !---LONG not allowed anymore in gfortran 10 (?):
+      !---LONG support got removed:
       !!ff=LONG(a)
       !!ff=LONG(b)
       !!ff=LONG(c)
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/pr91497_2.f90
@@ -0,0 +1,124 @@
+! { 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.
+! Additional test case to cover all targets.
+!
+program foo
+
+      real(4) a, aa
+      real(8) b, bb
+      integer(2) e, ee
+      integer(4) f, ff
+      integer(8) g, gg
+      complex(4) ww
+      complex(8) xx
+      PARAMETER(a=3.1415927_4)
+      PARAMETER(b=3.1415927_8)
+      PARAMETER(e=123_2)
+      PARAMETER(f=123_4)
+      PARAMETER(g=123_8)
+
+      aa=REAL(b)    ! was: Change of value in conversion from 'REAL(8)' to 'REAL(4)'
+      aa=REAL(e)
+      aa=REAL(f)
+      aa=REAL(g)
+      aa=REAL(b, kind=4)   ! was: Change of value in conversion from 'REAL(8)' to 'REAL(4)'
+      bb=REAL(a, kind=8)
+
+      aa=FLOAT(f)
+      bb=DFLOAT(g)
+      aa=SNGL(b)    ! was: Change of value in conversion from 'REAL(8)' to 'REAL(4)'
+      aa=AINT(a)
+      bb=AINT(b)
+      aa=AINT(b, kind=4)
+      bb=DINT(b)
+      aa=ANINT(a)
+      bb=ANINT(b)
+      aa=ANINT(b, kind=4)
+      bb=DNINT(b)
+      aa=AMAX0(f, f)
+      aa=AMIN0(f, f)
+      aa=AMAX0(g, g)
+      aa=AMIN0(g, g)
+
+      ee=INT(a)
+      ee=INT(a, kind=2)    ! was: Change of value in conversion from 'REAL(4)' to 'INTEGER(2)'
+      ee=INT(b, kind=2)    ! was: Change of value in conversion from 'REAL(8)' to 'INTEGER(2)'
+      ee=INT(f, kind=2)
+      ee=INT(g, kind=2)
+      ff=INT(b)
+      ff=INT(a, kind=4)    ! was: Change of value in conversion from 'REAL(4)' to 'INTEGER(4)'
+      ff=INT(b, kind=4)    ! was: Change of value in conversion from 'REAL(8)' to 'INTEGER(4)'
+      ff=INT(f, kind=4)
+      ff=INT(g, kind=4)
+      gg=INT(a)
+      gg=INT(a, kind=8)    ! was: Change of value in conversion from 'REAL(4)' to 'INTEGER(8)'
+      gg=INT(b, kind=8)    ! was: Change of value in conversion from 'REAL(8)' to 'INTEGER(8)'
+      gg=INT(f, kind=8)
+      gg=INT(g, kind=8)
+
+      ee=IFIX(a)
+      ff=IFIX(a)
+      gg=IFIX(a)
+      ee=IDINT(b)
+      ff=IDINT(b)
+      gg=IDINT(b)
+      ee=INT2(a)    ! was: Change of value in conversion from 'REAL(4)' to 'INTEGER(2)'
+      ee=INT2(b)    ! was: Change of value in conversion from 'REAL(8)' to 'INTEGER(2)'
+      ee=INT2(f)
+      ee=INT2(g)
+      gg=INT8(a)    ! was: Change of value in conversion from 'REAL(4)' to 'INTEGER(8)'
+      gg=INT8(b)    ! was: Change of value in conversion from 'REAL(8)' to 'INTEGER(8)'
+      gg=INT8(f)
+      gg=INT8(g)
+
+      ff=FLOOR(b)
+      ee=FLOOR(b, kind=2)
+      ff=FLOOR(b, kind=4)
+      gg=FLOOR(b, kind=8)
+      ff=CEILING(b)
+      ee=CEILING(b, kind=2)
+      ff=CEILING(b, kind=4)
+      gg=CEILING(b, kind=8)
+      ff=MAX1(a, a)    ! was: Change of value in conversion from 'REAL(4)' to 'INTEGER(4)'
+      ff=MIN1(a, a)    ! was: Change of value in conversion from 'REAL(4)' to 'INTEGER(4)'
+      gg=MAX1(b, b)    ! was: Change of value in conversion from 'REAL(8)' to 'INTEGER(4)'
+      gg=MIN1(b, b)    ! was: Change of value in conversion from 'REAL(8)' to 'INTEGER(4)'
+
+      ee=NINT(a, kind=2)
+      ee=NINT(b, kind=2)
+      ff=NINT(a)
+      ff=NINT(b)
+      ff=NINT(a, kind=4)
+      ff=NINT(b, kind=4)
+      gg=NINT(a, kind=8)
+      gg=NINT(b, kind=8)
+      ee=IDNINT(b)
+      ff=IDNINT(b)
+      gg=IDNINT(b)
+
+      ww=COMPLEX(a, a)
+      ww=COMPLEX(e, e)
+      ww=COMPLEX(g, g)
+      ww=COMPLEX(a, g)
+      xx=COMPLEX(b, g)
+      ww=CMPLX(a, a)
+      ww=CMPLX(b, b, kind=4)
+      xx=CMPLX(a, a, kind=8)
+
+      aa=REAL(ww)
+      bb=REAL(xx)
+      aa=REALPART(ww)
+      bb=REALPART(xx)
+      aa=AIMAG(ww)
+      bb=AIMAG(xx)
+      aa=IMAG(ww)
+      bb=IMAG(xx)
+      bb=DIMAG(xx)
+      aa=IMAGPART(ww)
+      bb=IMAGPART(xx)
+end

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] PR fortran/91497 -- Silence conversion warnings for MIN1 and MAX1
  2021-11-06 15:37       ` Manfred Schwarb
@ 2021-11-06 18:28         ` Thomas Koenig
  2021-12-13 11:18           ` Manfred Schwarb
  0 siblings, 1 reply; 10+ messages in thread
From: Thomas Koenig @ 2021-11-06 18:28 UTC (permalink / raw)
  To: Manfred Schwarb, fortran, gcc-patches


Hi Manfred,

looks good to me.

Thanks for the patch!

Best regards

	Thomas

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] PR fortran/91497 -- Silence conversion warnings for MIN1 and MAX1
  2021-11-06 18:28         ` Thomas Koenig
@ 2021-12-13 11:18           ` Manfred Schwarb
  2021-12-13 12:29             ` Martin Liška
  0 siblings, 1 reply; 10+ messages in thread
From: Manfred Schwarb @ 2021-12-13 11:18 UTC (permalink / raw)
  To: Thomas Koenig, fortran

Thomas,

Am 06.11.21 um 19:28 schrieb Thomas Koenig:
>
> Hi Manfred,
>
> looks good to me.
>
> Thanks for the patch!
>

could you commit it for me? I do not have commit access.

Thanks,
Manfred


> Best regards
>
>     Thomas


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] PR fortran/91497 -- Silence conversion warnings for MIN1 and MAX1
  2021-12-13 11:18           ` Manfred Schwarb
@ 2021-12-13 12:29             ` Martin Liška
  2021-12-14  0:22               ` Manfred Schwarb
  0 siblings, 1 reply; 10+ messages in thread
From: Martin Liška @ 2021-12-13 12:29 UTC (permalink / raw)
  To: Manfred Schwarb, Thomas Koenig, fortran

On 12/13/21 12:18, Manfred Schwarb via Fortran wrote:
> could you commit it for me? I do not have commit access.

I can definitely do that, but please attach the patches as output of git format-patch
so that git am can be directly used.

Cheers,
Martin

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] PR fortran/91497 -- Silence conversion warnings for MIN1 and MAX1
  2021-12-13 12:29             ` Martin Liška
@ 2021-12-14  0:22               ` Manfred Schwarb
  2021-12-14 15:32                 ` Martin Liška
  0 siblings, 1 reply; 10+ messages in thread
From: Manfred Schwarb @ 2021-12-14  0:22 UTC (permalink / raw)
  To: Martin Liška, Thomas Koenig, fortran

Am 13.12.21 um 13:29 schrieb Martin Liška:
> On 12/13/21 12:18, Manfred Schwarb via Fortran wrote:
>> could you commit it for me? I do not have commit access.
>
> I can definitely do that, but please attach the patches as output of git format-patch
> so that git am can be directly used.
>

Thanks. I do not have much experience with git, and I developed the patch the old-fashioned
way. I tried "git format-patch", but this simply returned nothing. Sorry, I gave up for now.

Cheers,
Manfred


> Cheers,
> Martin
>


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] PR fortran/91497 -- Silence conversion warnings for MIN1 and MAX1
  2021-12-14  0:22               ` Manfred Schwarb
@ 2021-12-14 15:32                 ` Martin Liška
  0 siblings, 0 replies; 10+ messages in thread
From: Martin Liška @ 2021-12-14 15:32 UTC (permalink / raw)
  To: Manfred Schwarb, Thomas Koenig, fortran

On 12/14/21 01:22, Manfred Schwarb wrote:
> Am 13.12.21 um 13:29 schrieb Martin Liška:
>> On 12/13/21 12:18, Manfred Schwarb via Fortran wrote:
>>> could you commit it for me? I do not have commit access.
>>
>> I can definitely do that, but please attach the patches as output of git format-patch
>> so that git am can be directly used.
>>
> 
> Thanks. I do not have much experience with git, and I developed the patch the old-fashioned
> way. I tried "git format-patch", but this simply returned nothing. Sorry, I gave up for now.

Never mind, I wrote a commit message title and pushed that as:
https://gcc.gnu.org/git/?p=gcc.git;a=commit;h=44aa890d8fb4afa843cf6cb7452fd5d6f3dd61fe
https://gcc.gnu.org/git/?p=gcc.git;a=commit;h=f1215db08126fbd2d69d971d65611508cf83b4ae

Thanks for patches,
Martin

> 
> Cheers,
> Manfred
> 
> 
>> Cheers,
>> Martin
>>
> 


^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2021-12-14 15:32 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-02 12:57 [PATCH] PR fortran/91497 -- Silence conversion warnings for MIN1 and MAX1 Manfred Schwarb
2021-11-02 13:26 ` Thomas Koenig
2021-11-02 14:22   ` Manfred Schwarb
2021-11-02 18:39     ` Thomas Koenig
2021-11-06 15:37       ` Manfred Schwarb
2021-11-06 18:28         ` Thomas Koenig
2021-12-13 11:18           ` Manfred Schwarb
2021-12-13 12:29             ` Martin Liška
2021-12-14  0:22               ` Manfred Schwarb
2021-12-14 15:32                 ` Martin Liška

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).