llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

[Flang] Possible incorrect semantics check on function result?

Open jonathonpenix opened this issue 4 years ago • 2 comments

Small reproducer is below:

module testing
contains
subroutine foo(func)
  interface
    function func(p) result (res)
      REAL, DIMENSION(:) :: p
      REAL, DIMENSION(size(p)) :: res
    end function
  end interface
end subroutine

function bar(p) result(res)
  REAL, DIMENSION(:) :: p
  REAL, DIMENSION(size(p)) :: res
end function
end module

program test
  use testing
  call foo(bar)
end program

I think this is valid Fortran (but I am not 100% sure) and gfortran and ifort both accept it (https://godbolt.org/z/Mr6v7To9e) but I am seeing the following error with flang:

error: Semantic errors in red_test.f90
./red_test.f90:20:12: error: Actual procedure argument has interface incompatible with dummy argument 'func=': function results have distinct extents
    call foo(bar)
             ^^^

Changing the check here to use !ShapesAreCompatible rather than the != operator seems to allow this to pass, but I'm not sure if this breaks other things yet/if this a coincidental "fix" (and assuming the source code above is valid).

jonathonpenix avatar Aug 17 '22 23:08 jonathonpenix

@llvm/issue-subscribers-flang-frontend

llvmbot avatar Aug 17 '22 23:08 llvmbot

Fixed by c1a77839cc99!

jonathonpenix avatar Aug 19 '22 19:08 jonathonpenix