camfort / fortran-src

Fortran parsing and static analysis infrastructure
https://hackage.haskell.org/package/fortran-src
Other
48 stars 20 forks source link

remove DoSpec from ExpImpliedDo #224

Open raehik opened 2 years ago

raehik commented 2 years ago

gfortran has some strange behaviour for implied DO loops:

program main
    integer i
    integer is(5)
    print *, i                  ! 0
    print *, ( i, i = -1, 2 )
    print *, i                  ! 3
    is = [ (i, i = 2, 6) ]
    print *, is
    print *, i                  ! 3
end

Putting aside the print behaviour, they feel like syntactic sugar. gfortran even tells you if it's the wrong shape for the assigning array, implying it evaluates them to arrays during compilation. Based on this, I feel the assignment inside implied DOs isn't a real assignment, just syntax reuse.

dorchard commented 2 years ago

The tricky thing is that now we've lost the data flow path due to an assignment...!

mrd commented 2 years ago

I wouldn't count on gfortran for sensible/reliable behaviour.