optimisation of overflowing integers

Steve Kargl sgk@troutmask.apl.washington.edu
Mon Mar 17 15:53:00 GMT 2014


On Mon, Mar 17, 2014 at 04:22:02PM +0100, Davide Mancusi wrote:
>
> I was mildly shocked by the result of gfortran's optimisation.

I'm mildly shocked that someone relying on processor dependent
behavior is mildly shcokced when the program doesn't do what is
desired.

> I was wondering:
> 1. does gfortran's aggressive optimisation qualify as a bug?
> 2. wouldn't gfortran's unexpected behaviour warrant at least a
> warning? Note that no warning is generated, even with -Wall -Wextra
> -pedantic.

% gfc4x -o z ffo1.f90 && ./z
  0.290384561       623596113
% gfc4x -o z -O ffo1.f90 && ./z
  0.290384561       623596113
% gfc4x -o z -O2 ffo1.f90 && ./z
 -0.709615409     -1523887535
% gfc4x -o z -O2 -fwrapv ffo1.f90 && ./z
  0.290384561       623596113
% gfc4x -o z -O2 -Wstrict-overflow ffo1.f90 && ./z
ffo1.f90: In function 'testribm':
ffo1.f90:19:0: warning: assuming signed overflow does not occur
when simplifying conditional to constant [-Wstrict-overflow]
     if(ial.lt.0) then
 ^
ffo1.f90:19:0: warning: assuming signed overflow does not occur
when simplifying conditional to constant [-Wstrict-overflow]
     if(ial.lt.0) then
 ^
ffo1.f90:19:0: warning: assuming signed overflow does not occur
when simplifying conditional to constant [-Wstrict-overflow]
     if(ial.lt.0) then
 ^
 -0.709615409     -1523887535

-- 
Steve



More information about the Fortran mailing list