optimisation of overflowing integers

Jorge D'Elia jdelia@intec.unl.edu.ar
Tue Mar 18 11:31:00 GMT 2014


Hi,

I tried to use the suggested flag -fsanitize=undefined 
with the (experimental) version:

$ gfortran-beta --version                                      
GNU Fortran (GCC) 4.9.0 20140315 (experimental) [trunk revision 208587]
Copyright (C) 2014 Free Software Foundation, Inc.

However an ICE is found:

$ gfortran-beta -fsanitize=undefined -o test087.exe test087.f90
test087.f90: In function 'ribm':
test087.f90:15:0: internal compiler error: Segmentation fault
   subroutine ribm (rndm,ial)
 ^
Please submit a full bug report,
with preprocessed source if appropriate.
See <http://gcc.gnu.org/bugs.html> for instructions.

On the other hand

$ gfortran-beta -o test087.exe test087.f90
$ test087.exe 
  0.290384561       623596113

where

$ which gfortran-beta
/usr/local/gfortran-beta/bin/gfortran-beta

$ cat /proc/version
Linux version 2.6.35.14-106.fc14.i686 (mockbuild@x86-01.phx2.fedoraproject.org) 
(gcc version 4.5.1 20100924 (Red Hat 4.5.1-4) (GCC) ) 
#1 SMP Wed Nov 23 13:57:33 UTC 2011

$ cat test087.f90
program testribm
  implicit none
  real :: r
  integer :: i
  data i /12345/
  call ribm (r,i)
  call ribm (r,i)
  call ribm (r,i)
  call ribm (r,i)
  call ribm (r,i)
  call ribm (r,i)
  print *,r,i
contains
  subroutine ribm (rndm,ial)
    implicit none
    integer :: ial
    real    :: rndm, al
    ial = ial * 65539
    if (ial.lt.0) then
      ial = ial + 2147483647 + 1
    endif
    al = ial
    rndm = al*0.4656613e-9
  end subroutine ribm
end program testribm


Regards,
Jorge

----- Mensaje original -----
> De: "Tobias Burnus" <burnus@net-b.de>
> Para: "N.M. Maclaren" <nmm1@cam.ac.uk>, fortran@gcc.gnu.org
> Enviados: Martes, 18 de Marzo 2014 3:53:04
> Asunto: Re: optimisation of overflowing integers
> 
> N.M. Maclaren wrote:
> > The errors occur at run-time - NAG Fortran is the only currently active
> > Fortran compiler that checks for such things (and you need -C=all).
> > So the answers are "no" and "no".
> 
> Try GCC/gfortran 4.9 (with the bug fix patch to PR60557), namely:
> 
> $ gfortran -fsanitize=undefined bar.f90
> $ ./a.out
> bar.f90:19: runtime error: signed integer overflow: 809078955 * 65539
> cannot be represented in type 'integer(kind=4)'
>    0.290384561       623596113
> 
> Tobias
> 



More information about the Fortran mailing list