This is the mail archive of the fortran@gcc.gnu.org mailing list for the GNU Fortran project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Bug report


Dear developers of GNU Fortran,

it seems I've found a bug in the compiler.

Please look at the example code in the attachement.

An elemental function ff cals another elemental function gg.
Exactly the same does the function f1.

The only difference is that ff calls gg with an array argument while
f1 makes two calls with scalar argument.

Both functions, ff and f1, work well if the optional argument b is present.

If the optional argument b is absent, f1 works well but ff results into
Segmentation fault


Here is the version of the compiler I have been using:

kostyuk@cosmic:~$ gfortran --version
GNU Fortran (Ubuntu/Linaro 4.4.4-14ubuntu5) 4.4.5
Copyright (C) 2010 Free Software Foundation, Inc.

Here is the Linux version:

kostyuk@cosmic:~$ uname -r
2.6.35-30-generic


Best regards,

Andriy Kostyuk.
PROGRAM test
  IMPLICIT NONE
  REAL(KIND=8), DIMENSION(2) :: aa, rr
  aa(1)=10.
  aa(2)=11.
  WRITE(*,*) 'Both f1 and ff work if the optional parameter is present:'
  rr=f1(aa,1)
  WRITE(*,*) ' rr(1)=', rr(1), '  rr(2)=', rr(2)
  rr=ff(aa,1)
  WRITE(*,*) ' rr(1)=', rr(1), '  rr(2)=', rr(2)
  WRITE(*,*) 'But only f1 works if the optional parameter is absent:'
  rr=f1(aa)
  WRITE(*,*) ' rr(1)=', rr(1), '  rr(2)=', rr(2)
  rr=ff(aa)
  WRITE(*,*) ' rr(1)=', rr(1), '  rr(2)=', rr(2)


CONTAINS 

    ELEMENTAL REAL(KIND=8) FUNCTION ff(a,b)
      IMPLICIT NONE
      REAL(KIND=8), INTENT(IN) :: a
      INTEGER, INTENT(IN), OPTIONAL :: b
      REAL(KIND=8), DIMENSION(2) :: ac
      ac(1)=a
      ac(2)=a**2
      ff=SUM(gg(ac,b))
    END FUNCTION ff

    ELEMENTAL REAL(KIND=8) FUNCTION f1(a,b)
      IMPLICIT NONE
      REAL(KIND=8), INTENT(IN) :: a
      INTEGER, INTENT(IN), OPTIONAL :: b
      REAL(KIND=8), DIMENSION(2) :: ac
      ac(1)=a
      ac(2)=a**2
      f1=gg(ac(1),b)+gg(ac(2),b) ! This is the same as in ff, but without using the elemental feature of gg
    END FUNCTION f1

    ELEMENTAL REAL(KIND=8) FUNCTION gg(a,b)
      IMPLICIT NONE
      REAL(KIND=8), INTENT(IN) :: a
      INTEGER, INTENT(IN), OPTIONAL :: b
      INTEGER ::b1
      IF(PRESENT(b)) THEN
        b1=b
      ELSE
        b1=1
      ENDIF
      gg=a**b1
    END FUNCTION gg


END PROGRAM test

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]