<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/57204>57204</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            [Flang] Possible incorrect semantics check on function result?
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            flang:frontend
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          jpenix-quic
      </td>
    </tr>
</table>

<pre>
    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](https://github.com/llvm/llvm-project/blob/main/flang/lib/Evaluate/characteristics.cpp#L895) 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). 
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJydVduSmzgQ_Rr8oooLCxubBx6843HVVOWytbPvW0I0RhlARBKTmXz9ngZ8SWazW1kXllCrJfU5fVoUtnzNH1vVNMJR72w5aHLCeFFQY79GyT6KD1F8btN4fsZhC--GRCAfTHeabNp2QZnOTyM_FM4OmCVRWRvJXTV0OpLZNCuE6QK5Smk6G4Rgj2BsJybXXQ93hOaHJggM8Xaznn9_3O_fR_JOHB4-3H98fPj0EV4cN5Zxl-xF_1_u3nyj-aibZXzUZSF15SW0s5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