[Bug middle-end/58746] New: Incorrect warning with -Waggressive-loop-optimizations

Joost.VandeVondele at mat dot ethz.ch gcc-bugzilla@gcc.gnu.org
Wed Oct 16 12:45:00 GMT 2013


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

            Bug ID: 58746
           Summary: Incorrect warning with -Waggressive-loop-optimizations
           Product: gcc
           Version: 4.9.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: middle-end
          Assignee: unassigned at gcc dot gnu.org
          Reporter: Joost.VandeVondele at mat dot ethz.ch

Only when compiled with LTO, the following testcase yields:

 gfortran  -flto=jobserver -use-linker-plugin -O2 -g -ffree-form test.f90 
test.f90: In function ‘expint.constprop’:
test.f90:43:0: warning: iteration 2147483646 invokes undefined behavior
[-Waggressive-loop-optimizations]
         DO ii=1,nm1
 ^
test.f90:43:0: note: containing loop

However, nm1 is clearly 0, by inspection of the code and as the write statement
at runtime illustrates:
 nm1=           0

> cat test.f90 
MODULE mathlib
  IMPLICIT NONE
  INTEGER, PARAMETER :: dp = SELECTED_REAL_KIND ( 14, 200 )
  INTEGER, PARAMETER :: maxfac = 30
  REAL(KIND=dp), PARAMETER, DIMENSION (0:maxfac) :: fac = 1
  CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'mathlib'
CONTAINS
  FUNCTION expint(n,x)
    INTEGER                                  :: n
    REAL(dp)                                 :: x, expint

    CHARACTER(len=*), PARAMETER :: routineN = 'expint', &
      routineP = moduleN//':'//routineN
    INTEGER, PARAMETER                       :: maxit = 100
    REAL(dp), PARAMETER :: eps = 6.e-14_dp, &
      euler = 0.5772156649015328606065120_dp, fpmin = TINY(0.0_dp)

    INTEGER                                  :: i, ii, nm1
    REAL(dp)                                 :: del, fact, h, psi

    nm1=n-1
    write(6,*) "nm1=",nm1

    expint=-LOG(x)-euler
    fact=1.0_dp
    DO i=1,MAXIT
      fact=-fact*x/i
      IF(i.NE.nm1) THEN
        del=-fact/(i-nm1)
      ELSE
        psi=-euler 
        DO ii=1,nm1
          psi=psi+1.0_dp/ii
        END DO
        del=fact*(-LOG(x)+psi)
      END IF
      expint=expint+del
      IF(ABS(del).LT.ABS(expint)*EPS) RETURN
    END DO

  END FUNCTION expint
END MODULE
USE  mathlib
REAL(KIND=dp), VOLATILE :: r=0.1_dp
r = expint(1,r)
END


More information about the Gcc-bugs mailing list