public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/47659] New: -Wconversion[-extra] should emit warning for constant expressions
@ 2011-02-09 10:41 thenlich at users dot sourceforge.net
  2011-02-09 16:21 ` [Bug fortran/47659] " kargl at gcc dot gnu.org
                   ` (10 more replies)
  0 siblings, 11 replies; 12+ messages in thread
From: thenlich at users dot sourceforge.net @ 2011-02-09 10:41 UTC (permalink / raw)
  To: gcc-bugs

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

           Summary: -Wconversion[-extra] should emit warning for constant
                    expressions
           Product: gcc
           Version: 4.6.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: thenlich@users.sourceforge.net


When the options -Wconversion or -Wconversion-extra are in effect, the compiler
does not generate a warning if a constant real expression is converted to a
different real kind

There should be a warning in this case because the conversion can give
surprising results, e.g.:

real(8) d1, d2
d1 = .13 ! <== no warning
d2 = .13d0
print *, d1, d2, d2-d1
end

Output:
  0.12999999523162842       0.13000000000000000       4.76837158647214210E-009

In this case the option -Wconversion-extra should give a warning on "d1 = .13"
because a constant was specified which does not represent the decimal value
with the same precision as the target variable can hold. The user most likely
wanted to specify "d1 = .13d0"


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

* [Bug fortran/47659] -Wconversion[-extra] should emit warning for constant expressions
  2011-02-09 10:41 [Bug fortran/47659] New: -Wconversion[-extra] should emit warning for constant expressions thenlich at users dot sourceforge.net
@ 2011-02-09 16:21 ` kargl at gcc dot gnu.org
  2011-07-30 23:08 ` tkoenig at gcc dot gnu.org
                   ` (9 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: kargl at gcc dot gnu.org @ 2011-02-09 16:21 UTC (permalink / raw)
  To: gcc-bugs

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

kargl at gcc dot gnu.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Priority|P3                          |P5
                 CC|                            |kargl at gcc dot gnu.org
           Severity|normal                      |enhancement


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

* [Bug fortran/47659] -Wconversion[-extra] should emit warning for constant expressions
  2011-02-09 10:41 [Bug fortran/47659] New: -Wconversion[-extra] should emit warning for constant expressions thenlich at users dot sourceforge.net
  2011-02-09 16:21 ` [Bug fortran/47659] " kargl at gcc dot gnu.org
@ 2011-07-30 23:08 ` tkoenig at gcc dot gnu.org
  2011-08-07 19:31 ` tkoenig at gcc dot gnu.org
                   ` (8 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: tkoenig at gcc dot gnu.org @ 2011-07-30 23:08 UTC (permalink / raw)
  To: gcc-bugs

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

Thomas Koenig <tkoenig at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2011.07.30 23:07:25
                 CC|                            |tkoenig at gcc dot gnu.org
     Ever Confirmed|0                           |1

--- Comment #1 from Thomas Koenig <tkoenig at gcc dot gnu.org> 2011-07-30 23:07:25 UTC ---
Confirmed.


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

* [Bug fortran/47659] -Wconversion[-extra] should emit warning for constant expressions
  2011-02-09 10:41 [Bug fortran/47659] New: -Wconversion[-extra] should emit warning for constant expressions thenlich at users dot sourceforge.net
  2011-02-09 16:21 ` [Bug fortran/47659] " kargl at gcc dot gnu.org
  2011-07-30 23:08 ` tkoenig at gcc dot gnu.org
@ 2011-08-07 19:31 ` tkoenig at gcc dot gnu.org
  2011-08-07 21:21 ` tkoenig at gcc dot gnu.org
                   ` (7 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: tkoenig at gcc dot gnu.org @ 2011-08-07 19:31 UTC (permalink / raw)
  To: gcc-bugs

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

Thomas Koenig <tkoenig at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |ASSIGNED
         AssignedTo|unassigned at gcc dot       |tkoenig at gcc dot gnu.org
                   |gnu.org                     |

--- Comment #2 from Thomas Koenig <tkoenig at gcc dot gnu.org> 2011-08-07 19:31:03 UTC ---
Working on it.


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

* [Bug fortran/47659] -Wconversion[-extra] should emit warning for constant expressions
  2011-02-09 10:41 [Bug fortran/47659] New: -Wconversion[-extra] should emit warning for constant expressions thenlich at users dot sourceforge.net
                   ` (2 preceding siblings ...)
  2011-08-07 19:31 ` tkoenig at gcc dot gnu.org
@ 2011-08-07 21:21 ` tkoenig at gcc dot gnu.org
  2011-08-08  6:08 ` thenlich at users dot sourceforge.net
                   ` (6 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: tkoenig at gcc dot gnu.org @ 2011-08-07 21:21 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Thomas Koenig <tkoenig at gcc dot gnu.org> 2011-08-07 21:20:36 UTC ---
Created attachment 24945
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=24945
Proposed patch

Here's a patch.

For

    real a
    a = 2.3d0

it checks for truncation correctly and only warns if digits are lost.

Unfortunately, for the case of

   double precision a
   a = 1.2

I don't see a good way of getting at the original string of numbers to
see if the 1.2 would have been interpreted differently if it had been
a double precision number.

What should we do?  Not warn for integers (like I did here) or warn
unconditionally?


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

* [Bug fortran/47659] -Wconversion[-extra] should emit warning for constant expressions
  2011-02-09 10:41 [Bug fortran/47659] New: -Wconversion[-extra] should emit warning for constant expressions thenlich at users dot sourceforge.net
                   ` (3 preceding siblings ...)
  2011-08-07 21:21 ` tkoenig at gcc dot gnu.org
@ 2011-08-08  6:08 ` thenlich at users dot sourceforge.net
  2011-08-08 14:51 ` sgk at troutmask dot apl.washington.edu
                   ` (5 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: thenlich at users dot sourceforge.net @ 2011-08-08  6:08 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from Thomas Henlich <thenlich at users dot sourceforge.net> 2011-08-08 06:07:33 UTC ---
It is not safe to omit the warning for integers: the constant could have been
truncated to an integer, as in:

    real(8) :: r8
    r8 = 12345678.9
    print *, r8

=> 12345679.0000000

So the best we can do is probably the unconditional warning. Maybe the warning
in this case should only be emitted when -Wconversion-extra is in effect.
That's how it works for variables (conversion to a higher precision), it should
be the same for constants (for consistency).

Similarly, for -Wconversion-extra the conversion to a lower precision should
always give a warning, even if no digits are lost.


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

* [Bug fortran/47659] -Wconversion[-extra] should emit warning for constant expressions
  2011-02-09 10:41 [Bug fortran/47659] New: -Wconversion[-extra] should emit warning for constant expressions thenlich at users dot sourceforge.net
                   ` (4 preceding siblings ...)
  2011-08-08  6:08 ` thenlich at users dot sourceforge.net
@ 2011-08-08 14:51 ` sgk at troutmask dot apl.washington.edu
  2011-08-21 16:41 ` tkoenig at gcc dot gnu.org
                   ` (4 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: sgk at troutmask dot apl.washington.edu @ 2011-08-08 14:51 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 from Steve Kargl <sgk at troutmask dot apl.washington.edu> 2011-08-08 14:50:33 UTC ---
On Mon, Aug 08, 2011 at 06:07:36AM +0000, thenlich at users dot sourceforge.net
wrote:
> http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47659
> 
> --- Comment #4 from Thomas Henlich <thenlich at users dot sourceforge.net> 2011-08-08 06:07:33 UTC ---
> It is not safe to omit the warning for integers: the constant could have been
> truncated to an integer, as in:
> 
>     real(8) :: r8
>     r8 = 12345678.9
>     print *, r8
> 
> => 12345679.0000000

Technically, the above is not a truncation to integer.  The
rhs is rounded.


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

* [Bug fortran/47659] -Wconversion[-extra] should emit warning for constant expressions
  2011-02-09 10:41 [Bug fortran/47659] New: -Wconversion[-extra] should emit warning for constant expressions thenlich at users dot sourceforge.net
                   ` (5 preceding siblings ...)
  2011-08-08 14:51 ` sgk at troutmask dot apl.washington.edu
@ 2011-08-21 16:41 ` tkoenig at gcc dot gnu.org
  2011-09-05  7:56 ` thenlich at users dot sourceforge.net
                   ` (3 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: tkoenig at gcc dot gnu.org @ 2011-08-21 16:41 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #6 from Thomas Koenig <tkoenig at gcc dot gnu.org> 2011-08-21 16:35:31 UTC ---
Author: tkoenig
Date: Sun Aug 21 16:35:28 2011
New Revision: 177942

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=177942
Log:
2011-08-21  Thomas Koenig  <tkoenig@gcc.gnu.org>

    PR fortran/47659
    * expr.c (gfc_check_assign): Check for type conversions when the
    right-hand side is a constant REAL/COMPLEX contstant the left-hand
    side is also REAL/COMPLEX.  Don't warn when a narrowing conversion
    for REAL does not change the value of the constant.

2011-08-21  Thomas Koenig  <tkoenig@gcc.gnu.org>

    PR fortran/47659
    * gfortran.dg/warn_conversion_2.f90:  Also warn about conversion
    of a constant resulting from simplification.
    * gfortran.dg/warn_conversion_3.f90:  New test.


Added:
    trunk/gcc/testsuite/gfortran.dg/warn_conversion_3.f90
Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/expr.c
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/testsuite/gfortran.dg/warn_conversion_2.f90


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

* [Bug fortran/47659] -Wconversion[-extra] should emit warning for constant expressions
  2011-02-09 10:41 [Bug fortran/47659] New: -Wconversion[-extra] should emit warning for constant expressions thenlich at users dot sourceforge.net
                   ` (6 preceding siblings ...)
  2011-08-21 16:41 ` tkoenig at gcc dot gnu.org
@ 2011-09-05  7:56 ` thenlich at users dot sourceforge.net
  2012-05-04 16:12 ` david.folkner at gmail dot com
                   ` (2 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: thenlich at users dot sourceforge.net @ 2011-09-05  7:56 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #7 from Thomas Henlich <thenlich at users dot sourceforge.net> 2011-09-05 07:55:13 UTC ---
Would it be feasible to generate a warning for line 3 of the following:

    real(8) :: a, b
    a = 1.4d0
    b = a / 1.3


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

* [Bug fortran/47659] -Wconversion[-extra] should emit warning for constant expressions
  2011-02-09 10:41 [Bug fortran/47659] New: -Wconversion[-extra] should emit warning for constant expressions thenlich at users dot sourceforge.net
                   ` (7 preceding siblings ...)
  2011-09-05  7:56 ` thenlich at users dot sourceforge.net
@ 2012-05-04 16:12 ` david.folkner at gmail dot com
  2012-12-23 21:55 ` anlauf at gmx dot de
  2015-06-06 16:20 ` tkoenig at gcc dot gnu.org
  10 siblings, 0 replies; 12+ messages in thread
From: david.folkner at gmail dot com @ 2012-05-04 16:12 UTC (permalink / raw)
  To: gcc-bugs

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

David Folkner <david.folkner at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |david.folkner at gmail dot
                   |                            |com

--- Comment #8 from David Folkner <david.folkner at gmail dot com> 2012-05-04 16:10:58 UTC ---
Would it be possible to generate a warning for the following cases:

Case (1) - Line 2
real(8)::a
a = 0.13

Case (2) - Line 2
real(4)::a
a = 0.13_8

Case (3) - Line 3
real(8)::a,b
a = 0.13_8
b = a/0.13

Case (4) - Line 4
real(8)::a
integer::b
b = 2
a = 0.5_8*b


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

* [Bug fortran/47659] -Wconversion[-extra] should emit warning for constant expressions
  2011-02-09 10:41 [Bug fortran/47659] New: -Wconversion[-extra] should emit warning for constant expressions thenlich at users dot sourceforge.net
                   ` (8 preceding siblings ...)
  2012-05-04 16:12 ` david.folkner at gmail dot com
@ 2012-12-23 21:55 ` anlauf at gmx dot de
  2015-06-06 16:20 ` tkoenig at gcc dot gnu.org
  10 siblings, 0 replies; 12+ messages in thread
From: anlauf at gmx dot de @ 2012-12-23 21:55 UTC (permalink / raw)
  To: gcc-bugs


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

Harald Anlauf <anlauf at gmx dot de> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |anlauf at gmx dot de

--- Comment #9 from Harald Anlauf <anlauf at gmx dot de> 2012-12-23 21:54:54 UTC ---
Some more cases where a warning is desired
or the current behavior is inconsistent:

  real(8) :: a = 0.1_8
  real(4) :: b = 0.2
  print *, 0.1_8 ** 0.2            ! No Warning
  print *, exp (0.2 * log (0.1_8)) ! No Warning
  print *,     a ** b              ! No Warning
  print *, exp (b   * log (a))     ! Warning
end


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

* [Bug fortran/47659] -Wconversion[-extra] should emit warning for constant expressions
  2011-02-09 10:41 [Bug fortran/47659] New: -Wconversion[-extra] should emit warning for constant expressions thenlich at users dot sourceforge.net
                   ` (9 preceding siblings ...)
  2012-12-23 21:55 ` anlauf at gmx dot de
@ 2015-06-06 16:20 ` tkoenig at gcc dot gnu.org
  10 siblings, 0 replies; 12+ messages in thread
From: tkoenig at gcc dot gnu.org @ 2015-06-06 16:20 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=47659

Thomas Koenig <tkoenig at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|---                         |FIXED

--- Comment #10 from Thomas Koenig <tkoenig at gcc dot gnu.org> ---
With this commit

https://gcc.gnu.org/viewcvs?rev=224190&root=gcc&view=rev

we should have most cases covered.


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

end of thread, other threads:[~2015-06-06 16:20 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-02-09 10:41 [Bug fortran/47659] New: -Wconversion[-extra] should emit warning for constant expressions thenlich at users dot sourceforge.net
2011-02-09 16:21 ` [Bug fortran/47659] " kargl at gcc dot gnu.org
2011-07-30 23:08 ` tkoenig at gcc dot gnu.org
2011-08-07 19:31 ` tkoenig at gcc dot gnu.org
2011-08-07 21:21 ` tkoenig at gcc dot gnu.org
2011-08-08  6:08 ` thenlich at users dot sourceforge.net
2011-08-08 14:51 ` sgk at troutmask dot apl.washington.edu
2011-08-21 16:41 ` tkoenig at gcc dot gnu.org
2011-09-05  7:56 ` thenlich at users dot sourceforge.net
2012-05-04 16:12 ` david.folkner at gmail dot com
2012-12-23 21:55 ` anlauf at gmx dot de
2015-06-06 16:20 ` tkoenig at gcc dot gnu.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).