Missing warning

Steve Kargl sgk@troutmask.apl.washington.edu
Thu Feb 28 20:32:00 GMT 2019


On Thu, Feb 28, 2019 at 08:06:06AM -0800, Steve Kargl wrote:
> Consider
> 
> % cat a.f90
>    integer i
>    real x
>    i = 10**23
>    x = 6.02 * 10**23
>    print *, i, x
> end
> 
> %  gfcx -o z a.f90 -Wall -fdump-parse-tree && ./z
> 
> a.f90:4:18:
> 
>     4 |    x = 6.02 * 10**23
>       |                  1
> Warning: Change of value in conversion from 'INTEGER(4)' to
> 'REAL(4)' at (1) [-Wconversion]
> ...
>  code:
>   ASSIGN MAIN__:i 100000000000000000000000
>   ASSIGN MAIN__:x 6.01999981e23
>   WRITE UNIT=6 FMT=-1
>   TRANSFER MAIN__:i
>   TRANSFER MAIN__:x
>   DT_END
>   
> ------------------------------------------
> 
>   -159383552   6.01999981E+23
> 
> It seems that the exponential operator is not range checking
> its result during constant folding.  The RHS side for the
> assignment of 'i' is too large for the decimal range for 
> a signed 32-bit integer.  The RHS of the assignment of 'x'
> accidentally gets the intended number.
> 
> F2018, 10.1.5.2.4 Evaluation of numeric intrinsic operations
> 
>    The execution of any numeric operation whose result is not defined
>    by the arithmetic used by the processor is prohibited. 
> 
> One might argument that the result for 'i' is valid Fortran
> as 2s-complement wrap semantics may be "the arithmetic used
> by the processor".  If that is the case, then the result for
> 'x' is wrong.  OTOH, the infinite precision result for 10**23
> shown in the dump as 10000000000000000000000 is outside of the
> range of a signed 32-bit integer.  I suspect that gfortran should
> be issuing a warning here.

LOL. It seems that I'm the guilty party for not issuing a
warning or error.  See r145261 for details.  I have
no idea what I was thinking 9 years ago.

-- 
Steve
20170425 https://www.youtube.com/watch?v=VWUpyCsUKR4
20161221 https://www.youtube.com/watch?v=IbCHE-hONow



More information about the Fortran mailing list