Your message dated Mon, 17 Dec 2012 14:57:46 -0800
with message-id <20121217225746.ga23...@math.sfu.ca>
and subject line Re: Bug#696058: gfortran: [gfortran] incorrect logic in -O2 
old-style
has caused the Debian Bug report #696058,
regarding gfortran: [gfortran] incorrect logic in -O2 old-style loop
to be marked as done.

This means that you claim that the problem has been dealt with.
If this is not the case it is now your responsibility to reopen the
Bug report if necessary, and/or fix the problem forthwith.

(NB: If you are a system administrator and have no idea what this
message is talking about, this may indicate a serious mail system
misconfiguration somewhere. Please contact ow...@bugs.debian.org
immediately.)


-- 
696058: http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=696058
Debian Bug Tracking System
Contact ow...@bugs.debian.org with problems
--- Begin Message ---
Package: gfortran
Version: 4:4.7.2-1exp1
Severity: normal

Comparision logic fails between "wrapped around" integers inside an inverted
while loop hack. This occurs only on optimisation level 2 and if the
loop does not have an upper limit.

I encountered this when trying to emperically check the integer
limits. Attached is a small example code and the unexpected output when
compiled with "gfortran -O2 ltbug.f". The last line should read 
"( 127 < -128 )= F" and execution should terminate there, but instead
continues indefinitely.

-- System Information:
Debian Release: 7.0
  APT prefers unstable
  APT policy: (600, 'unstable'), (500, 'testing'), (400, 'stable'), (300, 
'experimental')
Architecture: amd64 (x86_64)
Foreign Architectures: i386

Kernel: Linux 3.6.10.01 (SMP w/4 CPU cores)
Locale: LANG=en_CA.UTF-8, LC_CTYPE=en_CA.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/dash

Versions of packages gfortran depends on:
ii  cpp           4:4.7.2-1exp1
ii  gcc           4:4.7.2-1exp1
ii  gfortran-4.7  4.7.2-4

gfortran recommends no packages.

Versions of packages gfortran suggests:
ii  gfortran-doc       5:4
pn  gfortran-multilib  <none>

-- no debconf information
      program main
      implicit none
      integer*1 amax,amin,atmp
      integer i
      amin=-128
      atmp=amin-1
      
      print*,'outside loops, logic is good'
      print*,'(',atmp,'<',amin,')=',atmp.lt.amin

      print*,'in finite loop, logic is good'
      amin=0
      do i=1,256
         atmp=amin-1
         print*,'(',atmp,'<',amin,')=',atmp.lt.amin
         if ( atmp .lt. amin) then
            amin=atmp
         else
            goto 100
         end if
      end do
 100  continue

      print*,'without loop index, logic is bad'
      amin=0
      do
         atmp=amin-1
         print*,'(',atmp,'<',amin,')=',atmp.lt.amin
         if ( atmp .lt. amin) then
            amin=atmp
         else
            goto 200
         end if
      end do
 200  continue
      stop
      end program main
 outside loops, logic is good
 (  127 < -128 )= F
 in finite loop, logic is good
 (   -1 <    0 )= T
 (   -2 <   -1 )= T
 (   -3 <   -2 )= T
 (   -4 <   -3 )= T
 (   -5 <   -4 )= T
 (   -6 <   -5 )= T
 (   -7 <   -6 )= T
 (   -8 <   -7 )= T
 (   -9 <   -8 )= T
 (  -10 <   -9 )= T
 (  -11 <  -10 )= T
 (  -12 <  -11 )= T
 (  -13 <  -12 )= T
 (  -14 <  -13 )= T
 (  -15 <  -14 )= T
 (  -16 <  -15 )= T
 (  -17 <  -16 )= T
 (  -18 <  -17 )= T
 (  -19 <  -18 )= T
 (  -20 <  -19 )= T
 (  -21 <  -20 )= T
 (  -22 <  -21 )= T
 (  -23 <  -22 )= T
 (  -24 <  -23 )= T
 (  -25 <  -24 )= T
 (  -26 <  -25 )= T
 (  -27 <  -26 )= T
 (  -28 <  -27 )= T
 (  -29 <  -28 )= T
 (  -30 <  -29 )= T
 (  -31 <  -30 )= T
 (  -32 <  -31 )= T
 (  -33 <  -32 )= T
 (  -34 <  -33 )= T
 (  -35 <  -34 )= T
 (  -36 <  -35 )= T
 (  -37 <  -36 )= T
 (  -38 <  -37 )= T
 (  -39 <  -38 )= T
 (  -40 <  -39 )= T
 (  -41 <  -40 )= T
 (  -42 <  -41 )= T
 (  -43 <  -42 )= T
 (  -44 <  -43 )= T
 (  -45 <  -44 )= T
 (  -46 <  -45 )= T
 (  -47 <  -46 )= T
 (  -48 <  -47 )= T
 (  -49 <  -48 )= T
 (  -50 <  -49 )= T
 (  -51 <  -50 )= T
 (  -52 <  -51 )= T
 (  -53 <  -52 )= T
 (  -54 <  -53 )= T
 (  -55 <  -54 )= T
 (  -56 <  -55 )= T
 (  -57 <  -56 )= T
 (  -58 <  -57 )= T
 (  -59 <  -58 )= T
 (  -60 <  -59 )= T
 (  -61 <  -60 )= T
 (  -62 <  -61 )= T
 (  -63 <  -62 )= T
 (  -64 <  -63 )= T
 (  -65 <  -64 )= T
 (  -66 <  -65 )= T
 (  -67 <  -66 )= T
 (  -68 <  -67 )= T
 (  -69 <  -68 )= T
 (  -70 <  -69 )= T
 (  -71 <  -70 )= T
 (  -72 <  -71 )= T
 (  -73 <  -72 )= T
 (  -74 <  -73 )= T
 (  -75 <  -74 )= T
 (  -76 <  -75 )= T
 (  -77 <  -76 )= T
 (  -78 <  -77 )= T
 (  -79 <  -78 )= T
 (  -80 <  -79 )= T
 (  -81 <  -80 )= T
 (  -82 <  -81 )= T
 (  -83 <  -82 )= T
 (  -84 <  -83 )= T
 (  -85 <  -84 )= T
 (  -86 <  -85 )= T
 (  -87 <  -86 )= T
 (  -88 <  -87 )= T
 (  -89 <  -88 )= T
 (  -90 <  -89 )= T
 (  -91 <  -90 )= T
 (  -92 <  -91 )= T
 (  -93 <  -92 )= T
 (  -94 <  -93 )= T
 (  -95 <  -94 )= T
 (  -96 <  -95 )= T
 (  -97 <  -96 )= T
 (  -98 <  -97 )= T
 (  -99 <  -98 )= T
 ( -100 <  -99 )= T
 ( -101 < -100 )= T
 ( -102 < -101 )= T
 ( -103 < -102 )= T
 ( -104 < -103 )= T
 ( -105 < -104 )= T
 ( -106 < -105 )= T
 ( -107 < -106 )= T
 ( -108 < -107 )= T
 ( -109 < -108 )= T
 ( -110 < -109 )= T
 ( -111 < -110 )= T
 ( -112 < -111 )= T
 ( -113 < -112 )= T
 ( -114 < -113 )= T
 ( -115 < -114 )= T
 ( -116 < -115 )= T
 ( -117 < -116 )= T
 ( -118 < -117 )= T
 ( -119 < -118 )= T
 ( -120 < -119 )= T
 ( -121 < -120 )= T
 ( -122 < -121 )= T
 ( -123 < -122 )= T
 ( -124 < -123 )= T
 ( -125 < -124 )= T
 ( -126 < -125 )= T
 ( -127 < -126 )= T
 ( -128 < -127 )= T
 (  127 < -128 )= F
 without loop index, logic is bad
 (   -1 <    0 )= T
 (   -2 <   -1 )= T
 (   -3 <   -2 )= T
 (   -4 <   -3 )= T
 (   -5 <   -4 )= T
 (   -6 <   -5 )= T
 (   -7 <   -6 )= T
 (   -8 <   -7 )= T
 (   -9 <   -8 )= T
 (  -10 <   -9 )= T
 (  -11 <  -10 )= T
 (  -12 <  -11 )= T
 (  -13 <  -12 )= T
 (  -14 <  -13 )= T
 (  -15 <  -14 )= T
 (  -16 <  -15 )= T
 (  -17 <  -16 )= T
 (  -18 <  -17 )= T
 (  -19 <  -18 )= T
 (  -20 <  -19 )= T
 (  -21 <  -20 )= T
 (  -22 <  -21 )= T
 (  -23 <  -22 )= T
 (  -24 <  -23 )= T
 (  -25 <  -24 )= T
 (  -26 <  -25 )= T
 (  -27 <  -26 )= T
 (  -28 <  -27 )= T
 (  -29 <  -28 )= T
 (  -30 <  -29 )= T
 (  -31 <  -30 )= T
 (  -32 <  -31 )= T
 (  -33 <  -32 )= T
 (  -34 <  -33 )= T
 (  -35 <  -34 )= T
 (  -36 <  -35 )= T
 (  -37 <  -36 )= T
 (  -38 <  -37 )= T
 (  -39 <  -38 )= T
 (  -40 <  -39 )= T
 (  -41 <  -40 )= T
 (  -42 <  -41 )= T
 (  -43 <  -42 )= T
 (  -44 <  -43 )= T
 (  -45 <  -44 )= T
 (  -46 <  -45 )= T
 (  -47 <  -46 )= T
 (  -48 <  -47 )= T
 (  -49 <  -48 )= T
 (  -50 <  -49 )= T
 (  -51 <  -50 )= T
 (  -52 <  -51 )= T
 (  -53 <  -52 )= T
 (  -54 <  -53 )= T
 (  -55 <  -54 )= T
 (  -56 <  -55 )= T
 (  -57 <  -56 )= T
 (  -58 <  -57 )= T
 (  -59 <  -58 )= T
 (  -60 <  -59 )= T
 (  -61 <  -60 )= T
 (  -62 <  -61 )= T
 (  -63 <  -62 )= T
 (  -64 <  -63 )= T
 (  -65 <  -64 )= T
 (  -66 <  -65 )= T
 (  -67 <  -66 )= T
 (  -68 <  -67 )= T
 (  -69 <  -68 )= T
 (  -70 <  -69 )= T
 (  -71 <  -70 )= T
 (  -72 <  -71 )= T
 (  -73 <  -72 )= T
 (  -74 <  -73 )= T
 (  -75 <  -74 )= T
 (  -76 <  -75 )= T
 (  -77 <  -76 )= T
 (  -78 <  -77 )= T
 (  -79 <  -78 )= T
 (  -80 <  -79 )= T
 (  -81 <  -80 )= T
 (  -82 <  -81 )= T
 (  -83 <  -82 )= T
 (  -84 <  -83 )= T
 (  -85 <  -84 )= T
 (  -86 <  -85 )= T
 (  -87 <  -86 )= T
 (  -88 <  -87 )= T
 (  -89 <  -88 )= T
 (  -90 <  -89 )= T
 (  -91 <  -90 )= T
 (  -92 <  -91 )= T
 (  -93 <  -92 )= T
 (  -94 <  -93 )= T
 (  -95 <  -94 )= T
 (  -96 <  -95 )= T
 (  -97 <  -96 )= T
 (  -98 <  -97 )= T
 (  -99 <  -98 )= T
 ( -100 <  -99 )= T
 ( -101 < -100 )= T
 ( -102 < -101 )= T
 ( -103 < -102 )= T
 ( -104 < -103 )= T
 ( -105 < -104 )= T
 ( -106 < -105 )= T
 ( -107 < -106 )= T
 ( -108 < -107 )= T
 ( -109 < -108 )= T
 ( -110 < -109 )= T
 ( -111 < -110 )= T
 ( -112 < -111 )= T
 ( -113 < -112 )= T
 ( -114 < -113 )= T
 ( -115 < -114 )= T
 ( -116 < -115 )= T
 ( -117 < -116 )= T
 ( -118 < -117 )= T
 ( -119 < -118 )= T
 ( -120 < -119 )= T
 ( -121 < -120 )= T
 ( -122 < -121 )= T
 ( -123 < -122 )= T
 ( -124 < -123 )= T
 ( -125 < -124 )= T
 ( -126 < -125 )= T
 ( -127 < -126 )= T
 ( -128 < -127 )= T
 (  127 < -128 )= T
...

--- End Message ---
--- Begin Message ---
I was worried it might be something like that. Thankyou for the detailed
response.

Kevin
On Mon 12.12.17 03:05, Tobias Burnus wrote:
Kevin Mitchell wrote:

Comparision logic fails between "wrapped around" integers inside an inverted
while loop hack. This occurs only on optimisation level 2 and if the
loop does not have an upper limit.

I encountered this when trying to emperically check the integer
limits. Attached is a small example code and the unexpected output when
compiled with "gfortran -O2 ltbug.f". The last line should read
"( 127 < -128 )= F" and execution should terminate there, but instead
continues indefinitely.

I believe that that's a bug in the program. Fortran (like C) does not define the semantic for integer wrapping around [at least not for signed integers; though Fortran doesn't have unsigned integers].

Work around: -fno-strict-overflow. (-fstrict-overflow is enabled by default with -O2 or higher).


I have some trouble pin-pointing it in the Fortran standard; nonetheless some quotes from Fortran 2008: ftp://ftp.nag.co.uk/sc22wg5/N1801-N1850/N1830.pdf

* The standard doesn't define the semantics, hence, the catch it all applies: "A program (2.2.2) is a standard-conforming program if it uses only those forms and relationships described herein and if the program has an interpretation according to this part of ISO/IEC 1539." (Section "1.5 Conformance").

* "The execution of any numeric operation whose result is not defined by the arithmetic used by the processor is prohibited." (7.1.5.2.4 Evaluation of numeric intrinsic operations)

* And the numerical model is stated in "13.4 Numeric models".


The following quote is more explicit albeit not normative. It comes from the draft Fortran appendix to ISO/IEC Technical Report (TR) 24772 "Guidance to avoiding vulnerabilities in programming languages through language selection and use". [That's one of the few free-of-charge ISO standards.] The Fortran appendix has been written by members of the Fortran standardization committee and has been voted on. See ftp://ftp.nag.co.uk/sc22wg5/N1901-N1950/N1947.pdf

Namely: "if an integer operation results in a value outside the supported range, the program is not conforming. This might not be detected. Likewise, assigning a value to an integer variable whose range does not include the value, renders the program not conforming."

Tobias

--- End Message ---

Reply via email to