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

    <tr>
        <th>Summary</th>
        <td>
            [Flang] Compilation error when source-expr of source specifier in allocate statement is the sum of two internal functions
        </td>
    </tr>

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

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

    <tr>
      <th>Reporter</th>
      <td>
          ohno-fj
      </td>
    </tr>
</table>

<pre>
    ```
Version of flang-new : 19.0.0(f2f9cdd22171f0c54cad7c6b183857f3d856c344)/AArch64
```

When `source-expr` of `source` specifier in `allocate` statement is the sum of two internal functions (`SOURCE=(pptr() + pptr1())`), a compilation-time error occurs.
When there is only one internal function (`SOURCE=(pptr())`), the compilation succeeds.

The following are the test program, Flang-new, Gfortran and ifort compilation/execution result.

fe2_polymorphic_ut230_2.f90:
```fortran
module mod1
 type ty
     integer(kind=4) :: num=1
  end type ty
  type, extends(ty):: ty1
     integer(kind=8) :: num2=3
  end type ty1
end module mod1

program main
  use mod1
  TYPE con
 class(ty),POINTER::ptr
  END TYPE con
  INTERFACE OPERATOR(+)
 function pls(a,b)
       import ty1
       import ty
 class(ty), allocatable, intent(in) :: a
       class(ty), allocatable, intent(in) :: b
       type(ty1) :: pls
     END function pls
  END INTERFACE operator(+)
  TYPE(con)::obj(10)
 allocate(obj(1)%ptr,SOURCE=(pptr() + pptr1()))
  if(obj(1)%ptr%num == 70) print*,'pass'
contains
  function pptr()
 class(ty),allocatable::pptr
    allocate(pptr)
    pptr%num = 30
 end function pptr
  function pptr1()
 class(ty),allocatable::pptr1
    allocate(pptr1)
    pptr1%num = 40
 end function pptr1
END program main

function pls(a,b)
  use mod1
  class(ty), allocatable, intent(in) :: a
  class(ty), allocatable, intent(in) :: b
  type(ty1) :: pls
  pls%num = a%num + b%num
END function pls
```

```
$ flang-new fe2_polymorphic_ut230_2.f90
error: Semantic errors in fe2_polymorphic_ut230_2.f90
./fe2_polymorphic_ut230_2.f90:25:31: error: No intrinsic or user-defined OPERATOR(+) matches operand types CLASS(ty) and CLASS(ty)
    allocate(obj(1)%ptr,SOURCE=(pptr() + pptr1()))
 ^^^^^^^^^^^^^^^^
$
```

```
$ gfortran fe2_polymorphic_ut230_2.f90 ; ./a.out
 pass
$
```

```
$ ifort -diag-disable=10448 fe2_polymorphic_ut230_2.f90
fe2_polymorphic_ut230_2.f90(25): error #9140: The allocatable result of a function reference may not be argument associated with an allocatable dummy argument.   [PPTR]
 allocate(obj(1)%ptr,SOURCE=(pptr() + pptr1()))
------------------------------^
fe2_polymorphic_ut230_2.f90(25): error #9140: The allocatable result of a function reference may not be argument associated with an allocatable dummy argument.   [PPTR1]
 allocate(obj(1)%ptr,SOURCE=(pptr() + pptr1()))
---------------------------------------^
compilation aborted for fe2_polymorphic_ut230_2.f90 (code 1)
$
```

</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzUV1uP4jYU_jXm5QiU2AmEBx4YLlWlamc0M23Vp5XjOOBtYke2s7P8--okgQSYYTq7raqiKMS3c_nO1dw5tdNSLkh8R-L1iNd-b-zC7LUZ519GqckOCzINuidYk2D5m7ROGQ0mh7zgejfW8gUIW0I4nwSTgNAkp_lcZBml4SzMAxFHgmczMU3DhCXxLGdZEk8FiyJC54Rul0sr9tOoJX7Bq33_vpcayDRwprZCjuW3ypJpgAKcJnHsKilUrqQF1WznRWEE9-2a516WUntQDvxegqtLJOBfDCjtpdW8gLzWwiujHRCakGnwdP_r42pD2JrQpKq8xVk6B0LvAIdhO8ZnGjQfK-AgTFmpgiOdsVelBGmtsWCEqK2bDBTye2klimN0cQCj5bUgN-U444sqDTiDq4WQMjsybN_Pewm5KQrzovQOuJXNMS-dh8qaneUlktoejYqDn3JjveUauM5A4WDIhtCt_CZF3bC00tWFP2OYS_q5MsWhNLbaK_G59pQFn-kknweELS8s3nFqZ0uT1YWE0mRhOwH-UEnwh26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