<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/139129>139129</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[flang] Semantic error on pure subroutine that compiles with gfortran and ifx
</td>
</tr>
<tr>
<th>Labels</th>
<td>
flang
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
R-Goc
</td>
</tr>
</table>
<pre>
Hitting this issue when trying to compile fortran-stdlib ([issue there](https://github.com/fortran-lang/stdlib/issues/990)).
Other compilers accept this code. Compiling [stdlib-error.f90](https://github.com/fortran-lang/stdlib/blob/master/src/stdlib_error.fypp):
```
error: Semantic errors in src/CMakeFiles/fortran_stdlib.dir/stdlib_error.f90-pp.f90
/code/rbfx-new/standalone/batched-assembly/stdlib/build/src/stdlib_error.f90:245:14: error: Left-hand side of assignment is not definable
ierr_out = ierr
^^^^^^^^
/code/rbfx-new/standalone/batched-assembly/stdlib/build/src/stdlib_error.f90:245:14: because: 'ierr_out' is polymorphic in a pure subprogram
ierr_out = ierr
^^^^^^^^
/code/rbfx-new/standalone/batched-assembly/stdlib/build/src/stdlib_error.f90:239:56: Declaration of 'ierr_out'
class(state_type), optional, intent(inout) :: ierr_out
^^^^^^^^
```
This is the [function](https://github.com/fortran-lang/stdlib/blob/c14d599a7b9dabf8789be6ecc484339599f595c8/src/stdlib_error.fypp#L239):
```fortran
pure subroutine error_handling(ierr,ierr_out)
class(state_type), intent(in) :: ierr
class(state_type), optional, intent(inout) :: ierr_out
character(len=:),allocatable :: err_msg
if (present(ierr_out)) then
! Return error flag
ierr_out = ierr
elseif (ierr%error()) then
err_msg = ierr%print()
error stop err_msg
end if
end subroutine error_handling
```
[state_type](https://github.com/fortran-lang/stdlib/blob/c14d599a7b9dabf8789be6ecc484339599f595c8/src/stdlib_error.fypp#L52):
```fortran
type :: state_type
!> The current exit state
integer(ilp) :: state = STDLIB_SUCCESS
!> Message associated to the current state
character(len=MSG_LENGTH) :: message = repeat(' ',MSG_LENGTH)
!> Location of the state change
character(len=NAME_LENGTH) :: where_at = repeat(' ',NAME_LENGTH)
contains
!> Cleanup
procedure :: destroy => state_destroy
!> Parse error constructor
procedure, private :: state_parse_at_location
procedure, private :: state_parse_arguments
generic :: parse => state_parse_at_location, &
state_parse_arguments
!> Print error message
procedure :: print => state_print
procedure :: print_msg => state_message
!> State properties
procedure :: ok => state_is_ok
procedure :: error => state_is_error
!> Handle optional error message
procedure :: handle => error_handling
end type state_type
```
state_type is also extended by two methods:
```fortran
interface state_type
module procedure new_state
module procedure new_state_nowhere
end interface state_type
```
which are defined [here](https://github.com/fortran-lang/stdlib/blob/c14d599a7b9dabf8789be6ecc484339599f595c8/src/stdlib_error.fypp#L513):
```fortran
pure type(state_type) function new_state(where_at,flag,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10, &
a11,a12,a13,a14,a15,a16,a17,a18,a19,a20)
!> Location
character(len=*),intent(in) :: where_at
!> Input error flag
integer,intent(in) :: flag
!> Optional rank-agnostic arguments
class(*),optional,intent(in),dimension(..) :: a1,a2,a3,a4,a5,a6,a7,a8,a9,a10, &
a11,a12,a13,a14,a15,a16,a17,a18,a19,a20
! Init object
call new_state%parse(where_at,flag,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10, &
a11,a12,a13,a14,a15,a16,a17,a18,a19,a20)
end function new_state
!> Error creation message, from N input variables (numeric or strings)
pure type(state_type) function new_state_nowhere(flag,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10, &
a11,a12,a13,a14,a15,a16,a17,a18,a19,a20) &
result(new_state)
!> Input error flag
integer,intent(in) :: flag
!> Optional rank-agnostic arguments
class(*),optional,intent(in),dimension(..) :: a1,a2,a3,a4,a5,a6,a7,a8,a9,a10, &
a11,a12,a13,a14,a15,a16,a17,a18,a19,a20
! Init object
call new_state%parse(flag,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10, &
a11,a12,a13,a14,a15,a16,a17,a18,a19,a20)
end function new_state_nowhere
```
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJzkWF1v2zrS_jX0DWFDoixbuvBF6iRtgbTnxUnfa4OixhK3FCmQVNP8-8VQsi35I9mzZ7EtsEagJBJn5pmvZ8bizslKA2xI-oGk9zPe-drYzZ_zj0bMClO-bj5J76WuqK-lo9K5DuhLDZp6-xpuGypM00oFdG-st1zPnS-VLChhGUk_9BK-BgskvScsq71vHUnuCHsk7LGSvu6KhTANYY8HBYrrirDHXg9hj0GHI-wxzyPCcsLyBSXR3R-o9WDdOsqFgNb3QIUpYUG34RnCJOmHXt0crDV2sc-jfxtOoQz-arjzYPGBFcfHu0H9a9si0uQOgZJVNPxEd-E53n-GhmsvBQ13HJWa9oq2X_h3eJQqeDxg2PXaF6W0F6byaN62waEIvUDPCXu0xf7nXMNLOM51yZXReL_gXtRQzrlz0BTqdeJYJ1V5w6E8IskdW6YkuYuXiP_oyBPs_bzmuqROlkDNnvZF1YD2VDqqjacl7KXmhQIS3dHpR4K1O9N5SpL78A8eIenD9Z__qosFCN45CFlk6wNQwtboVmvUa2NsW0uBueO07SxQ1xWtNZXlDbrxu_mWYEWmK3ToHoTilntpNKZs6t80S0Jx5wjLnOcedv61hdCEW2paFOcK_5bag_aEZVIHHTnFpkpOMXjP9VGPfOupBlkDG3ffaYGG_m7DinhZpnnO10Ve8mKfrbO8gBUIscyWSZKneb5P81Rkb7V08oRBDJ09Bj1YRh8PZWBN56WGvk922B9IRBggrAO2PYU7H4f7ZrBHAT6L7r8k_ldzNVFac8tFILtMgSbJfYg_6uVKGcE9tvZBCepoXHWmQ2KNZa0FN5geuc9yTLU-5wbCYvon-M7qPoh0r3h1s60OH1AOemN9oNOeqFj2hqUB8kkfS1srA86z9AynjaXOm3bk6-mpLqncn7zH_2-Xw7Tww5Q6Ju63KPeUvVntCPSQ-BH0Se4Ji0nyQL_VQEVnLY4F-Cl9fz7kU3uoQnVJ1Y7KMRwISXn-dv_0-cPu-f-324f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