public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/42809]  New: Too much noise with -Wconversion
@ 2010-01-19 22:39 anlauf at gmx dot de
  2010-01-19 22:42 ` [Bug fortran/42809] " pinskia at gcc dot gnu dot org
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: anlauf at gmx dot de @ 2010-01-19 22:39 UTC (permalink / raw)
  To: gcc-bugs

There is a lot of noise generated with -Wconversion:

program gfcbug100
  implicit none
  integer, parameter :: sp = kind (1.0)
  integer, parameter :: dp = kind (1.d0)
  real(sp)     :: s
  real(dp)     :: d
  complex(dp)  :: z

  s = 0         ! Warn if you are very picky
  d = s         ! No reason for a warning
  z = (0, 1)    ! Many warnings for this one!
end program gfcbug100

Which gives:

gfcbug100.f90:11.8:

  z = (0, 1)    ! Many warnings for this one!
        1
Warning: Conversion from INTEGER(4) to REAL(4) at (1)
gfcbug100.f90:11.11:

  z = (0, 1)    ! Many warnings for this one!
           1
Warning: Conversion from INTEGER(4) to REAL(4) at (1)
gfcbug100.f90:9.6:

  s = 0         ! Warn if you are very picky
      1
Warning: Conversion from INTEGER(4) to REAL(4) at (1)
gfcbug100.f90:10.6:

  d = s         ! No reason for a warning
      1
Warning: Conversion from REAL(4) to REAL(8) at (1)
gfcbug100.f90:11.6:

  z = (0, 1)    ! Many warnings for this one!
      1
Warning: Conversion from COMPLEX(4) to COMPLEX(8) at (1)


It would be nice if the promotion kind=4 to kind=8 would never
produce a warning in cases like the above as it is always exact.

Also, promoting integers to reals is often possible without any
loss of accuracy, this is certainly the case for 0 and 1 ;-)

The complex literal is particularly funny, generating 3 warnings.
This is at least one too much.  (0,1) gets promoted by default
to (0.0,1.0) as required by the standard, and the complex conversion
is exact.

Any attempt at reducing the above noise is greatly appreciated.


-- 
           Summary: Too much noise with -Wconversion
           Product: gcc
           Version: 4.5.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: anlauf at gmx dot de


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=42809


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

* [Bug fortran/42809] Too much noise with -Wconversion
  2010-01-19 22:39 [Bug fortran/42809] New: Too much noise with -Wconversion anlauf at gmx dot de
@ 2010-01-19 22:42 ` pinskia at gcc dot gnu dot org
  2010-01-19 22:59 ` anlauf at gmx dot de
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2010-01-19 22:42 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from pinskia at gcc dot gnu dot org  2010-01-19 22:42 -------
Well constants don't really need to be warned about if it does fit.  But really
an generic integer(4) to real(4) should be warned about really as not all
integer(4) fit into real(4).


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=42809


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

* [Bug fortran/42809] Too much noise with -Wconversion
  2010-01-19 22:39 [Bug fortran/42809] New: Too much noise with -Wconversion anlauf at gmx dot de
  2010-01-19 22:42 ` [Bug fortran/42809] " pinskia at gcc dot gnu dot org
@ 2010-01-19 22:59 ` anlauf at gmx dot de
  2010-01-20 23:02 ` anlauf at gmx dot de
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: anlauf at gmx dot de @ 2010-01-19 22:59 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from anlauf at gmx dot de  2010-01-19 22:59 -------
(In reply to comment #1)
> Well constants don't really need to be warned about if it does fit.  But really
> an generic integer(4) to real(4) should be warned about really as not all
> integer(4) fit into real(4).
> 

That's right.  For the conversion of a non-trivial integer(4) expression to
real(4) warnings are desired.  But for a known integer(4), one could use
the knowledge of the Fortran model of reals a check whether the modulus
of the integer is smaller than 2/epsilon(0._4).
(I hope that I got the factor of two correctly).


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=42809


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

* [Bug fortran/42809] Too much noise with -Wconversion
  2010-01-19 22:39 [Bug fortran/42809] New: Too much noise with -Wconversion anlauf at gmx dot de
  2010-01-19 22:42 ` [Bug fortran/42809] " pinskia at gcc dot gnu dot org
  2010-01-19 22:59 ` anlauf at gmx dot de
@ 2010-01-20 23:02 ` anlauf at gmx dot de
  2010-01-21 21:12 ` anlauf at gmx dot de
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: anlauf at gmx dot de @ 2010-01-20 23:02 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from anlauf at gmx dot de  2010-01-20 23:02 -------
Created an attachment (id=19669)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=19669&action=view)
Partial patch for conversion at assignment

A patch that addresses the trivial part of the problem:
the conversions from kind(x) to kind(y), where x < y
Not too elegant, but works.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=42809


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

* [Bug fortran/42809] Too much noise with -Wconversion
  2010-01-19 22:39 [Bug fortran/42809] New: Too much noise with -Wconversion anlauf at gmx dot de
                   ` (2 preceding siblings ...)
  2010-01-20 23:02 ` anlauf at gmx dot de
@ 2010-01-21 21:12 ` anlauf at gmx dot de
  2010-01-22 20:43 ` anlauf at gmx dot de
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: anlauf at gmx dot de @ 2010-01-21 21:12 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from anlauf at gmx dot de  2010-01-21 21:11 -------
Created an attachment (id=19684)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=19684&action=view)
Slightly improved version of the previous patch

I have improved the patch so that now the following
assignments do not throw a warning: e.g.
real(4) <- integer(1,2)
real(8) <- integer(1,2,4)
dto. for complex on the l.h.s.
This assumes the standard IEEE representations of
reals which have a sufficiently large number of
mantissa bits to accomodate the converted value from
the integer of smaller kind.

It works for me, up to the cases where the converted
value is known to be an integer exactly representable
as a real with the desired kind, see my comment above.

The patch works apparently correctly with
-fdefault-real-8 and -fdefault-integer-8 (ugh!).

I have regtested the patch and found a probably unrelated
failure:

FAIL: gfortran.dg/vect/fast-math-mgrid-resid.f scan-tree-dump-times optimized
"vect_var[^\n]*\+ " 13

The patch is just at the limit of 10 lines, so
whoever wants to take it feel free to do so.
I have left only the work to provide a testcase
for the testsuite. ;-)

Enjoy.


-- 

anlauf at gmx dot de changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
  Attachment #19669|0                           |1
        is obsolete|                            |


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=42809


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

* [Bug fortran/42809] Too much noise with -Wconversion
  2010-01-19 22:39 [Bug fortran/42809] New: Too much noise with -Wconversion anlauf at gmx dot de
                   ` (3 preceding siblings ...)
  2010-01-21 21:12 ` anlauf at gmx dot de
@ 2010-01-22 20:43 ` anlauf at gmx dot de
  2010-05-08 17:29 ` dfranke at gcc dot gnu dot org
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: anlauf at gmx dot de @ 2010-01-22 20:43 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #5 from anlauf at gmx dot de  2010-01-22 20:43 -------
There is also a lot of noise when a derived type with default
initialization is instantiated.  Moreover, the warnings point
to an unexpected locus.  Consider:

module bla
  implicit none
  integer, parameter :: i1 = 1, i2 = 2
  type t_datum
     integer(i1) :: state  = 0
     integer(i2) :: flags  = 0
  end type t_datum
  type t_x
    type(t_datum) :: a
    type(t_datum) :: b
  end type t_x
contains
  subroutine dummy
  end subroutine dummy
end module bla
!------------------------------------------------
module foo
  use bla, only: t_x,   &! Derived type
                 dummy   ! Some unused subroutine
  implicit none
contains
  subroutine work
    type (t_x)  :: x
  end subroutine work
end module foo


This gives:

gfcbug101.f90:19.49:

                 dummy   ! Some unused subroutine
                                                 1
Warning: Conversion from INTEGER(4) to INTEGER(1) at (1)
gfcbug101.f90:19.49:

                 dummy   ! Some unused subroutine
                                                 1
Warning: Conversion from INTEGER(4) to INTEGER(2) at (1)
gfcbug101.f90:19.49:

                 dummy   ! Some unused subroutine
                                                 1
Warning: Conversion from INTEGER(4) to INTEGER(1) at (1)
gfcbug101.f90:19.49:

                 dummy   ! Some unused subroutine
                                                 1
Warning: Conversion from INTEGER(4) to INTEGER(2) at (1)


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=42809


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

* [Bug fortran/42809] Too much noise with -Wconversion
  2010-01-19 22:39 [Bug fortran/42809] New: Too much noise with -Wconversion anlauf at gmx dot de
                   ` (4 preceding siblings ...)
  2010-01-22 20:43 ` anlauf at gmx dot de
@ 2010-05-08 17:29 ` dfranke at gcc dot gnu dot org
  2010-05-10 17:12 ` dfranke at gcc dot gnu dot org
  2010-05-10 19:26 ` dfranke at gcc dot gnu dot org
  7 siblings, 0 replies; 9+ messages in thread
From: dfranke at gcc dot gnu dot org @ 2010-05-08 17:29 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #6 from dfranke at gcc dot gnu dot org  2010-05-08 17:28 -------
Patch for initial report:
    http://gcc.gnu.org/ml/fortran/2010-05/msg00067.html


(In reply to comment #5)
> There is also a lot of noise when a derived type with default
> initialization is instantiated.  Moreover, the warnings point
> to an unexpected locus.

The warnings here are, to some extend, correct. There are two instances of
type(t_datum), both generate warning for 'state' and 'flags' each as both are
initialized by INTEGER(4). This INTEGER(4) may contain a value that does not
fit INTEGER(1|2).

About the locus: I agree that it is surprising. However, although the modules
are next to each other here, they might be in different source files somewhere
- or there might be no source file for the module at all. Hence, the locus
points to the USE statement.

The bad pointer position is another instance of the many PRs complaining about
this. I think this PR should be closed after a patch for -Wconversion was
applied and a new one for the error locus should be opened.


-- 

dfranke at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |dfranke at gcc dot gnu dot
                   |                            |org
             Status|UNCONFIRMED                 |NEW
     Ever Confirmed|0                           |1
   Last reconfirmed|0000-00-00 00:00:00         |2010-05-08 17:28:45
               date|                            |


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=42809


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

* [Bug fortran/42809] Too much noise with -Wconversion
  2010-01-19 22:39 [Bug fortran/42809] New: Too much noise with -Wconversion anlauf at gmx dot de
                   ` (5 preceding siblings ...)
  2010-05-08 17:29 ` dfranke at gcc dot gnu dot org
@ 2010-05-10 17:12 ` dfranke at gcc dot gnu dot org
  2010-05-10 19:26 ` dfranke at gcc dot gnu dot org
  7 siblings, 0 replies; 9+ messages in thread
From: dfranke at gcc dot gnu dot org @ 2010-05-10 17:12 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #7 from dfranke at gcc dot gnu dot org  2010-05-10 17:11 -------
Subject: Bug 42809

Author: dfranke
Date: Mon May 10 17:10:53 2010
New Revision: 159238

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=159238
Log:
gcc/fortran/:
2010-05-10  Daniel Franke  <franke.daniel@gmail.com>

        PR fortran/27866
        PR fortran/35003
        PR fortran/42809
        * intrinsic.c (gfc_convert_type_warn): Be more discriminative
        about conversion warnings.

gcc/testsuite/:
2010-05-08  Daniel Franke  <franke.daniel@gmail.com>

        PR fortran/27866
        PR fortran/35003
        PR fortran/42809
        * gfortran.dg/array_constructor_type_17.f03: Updated match string.
        * gfortran.dg/warn_conversion.f90: New.


Added:
    trunk/gcc/testsuite/gfortran.dg/warn_conversion.f90
Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/intrinsic.c
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/testsuite/gfortran.dg/array_constructor_type_17.f03


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=42809


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

* [Bug fortran/42809] Too much noise with -Wconversion
  2010-01-19 22:39 [Bug fortran/42809] New: Too much noise with -Wconversion anlauf at gmx dot de
                   ` (6 preceding siblings ...)
  2010-05-10 17:12 ` dfranke at gcc dot gnu dot org
@ 2010-05-10 19:26 ` dfranke at gcc dot gnu dot org
  7 siblings, 0 replies; 9+ messages in thread
From: dfranke at gcc dot gnu dot org @ 2010-05-10 19:26 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #8 from dfranke at gcc dot gnu dot org  2010-05-10 19:26 -------
(In reply to comment #6)
> The bad pointer position is another instance of the many PRs complaining about
> this. I think this PR should be closed after a patch for -Wconversion was
> applied and a new one for the error locus should be opened.

Fixed the conversion warnings. See PR44055 for a follow up to get some of the
warnings now omitted back. Closing.


-- 

dfranke at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED
   Target Milestone|---                         |4.6.0


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=42809


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

end of thread, other threads:[~2010-05-10 19:26 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-01-19 22:39 [Bug fortran/42809] New: Too much noise with -Wconversion anlauf at gmx dot de
2010-01-19 22:42 ` [Bug fortran/42809] " pinskia at gcc dot gnu dot org
2010-01-19 22:59 ` anlauf at gmx dot de
2010-01-20 23:02 ` anlauf at gmx dot de
2010-01-21 21:12 ` anlauf at gmx dot de
2010-01-22 20:43 ` anlauf at gmx dot de
2010-05-08 17:29 ` dfranke at gcc dot gnu dot org
2010-05-10 17:12 ` dfranke at gcc dot gnu dot org
2010-05-10 19:26 ` dfranke at gcc dot gnu dot org

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).