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

    <tr>
        <th>Summary</th>
        <td>
            [flang] iso_c_binding compilation error: Lowering to LLVM IR failed
        </td>
    </tr>

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

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

    <tr>
      <th>Reporter</th>
      <td>
          Try2Code
      </td>
    </tr>
</table>

<pre>
    The following program:
```fortran
module parsing_large_iso_c_mod
  use iso_c_binding
  implicit none
  private

  interface
 integer(c_size_t) function lib_strlen(charPtr) bind(c, name = "strlen")
 import c_size_t, c_ptr
      type(c_ptr), value :: charPtr
    end function lib_strlen

    subroutine lib_free(ptr) bind(c, name = "free")
      import c_ptr
      type(c_ptr), value, intent(in) :: ptr
    end subroutine lib_free
  end interface

contains

 function vlistCopyVarName(vlistId_dummy, varId_dummy) result(f_result)
 character(kind = c_char), dimension(:), pointer :: f_result
 integer(c_int), value :: vlistId_dummy
    integer(c_int), value :: varId_dummy
    type(c_ptr) :: cString
    integer :: rv_shape(1)
 character(kind = c_char), dimension(:), pointer :: temp
! original implementation, kept for reference, might influence the AST
! interface
!     function lib_vlistCopyVarName(vlistId_dummy, varId_dummy) bind(c, name =&
!     & 'vlistCopyVarName') result(c_result)
! import c_int, c_ptr
!       type(c_ptr) :: c_result
! integer(c_int), value :: vlistId_dummy
!       integer(c_int), value :: varId_dummy
!     end function lib_vlistCopyVarName
!   end interface
!   cString = lib_vlistCopyVarName(vlistId_dummy, varId_dummy)
    if(c_associated(cString)) then
      rv_shape(1) = int(lib_strlen(cString))
#ifdef FULL
      call c_f_pointer(cString, temp, rv_shape)
      allocate(f_result(rv_shape(1)))
      f_result = temp
#endif
      call lib_free(cString)
    else
      f_result => null()
    end if
  end function vlistCopyVarName

end module
```

can be compiled using
```shell
flang-new -cpp -c file.f90 -o file.o
```
but fails with
```shell
flang-new -cpp -DFULL -c file.f90 -o file.o
```

Compiler version:

```shell
flang-new version 18.0.0 (https://github.com/llvm/llvm-project 274ba2c910676cd34658fad33d3931c676b64e41)
```

Full compilation works with gfortran-11.2, aocc-4.1, nag-7.1


Can some provide hint how to work around this?
thx in advance
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJysVt-Po7YT_2ucl1EiMISEhzzsN_uNdNK2qnrXe0XGDOCesZFtst3-9ZVNSCCbq_ZOjVbZYObXZ-Yz42HWikYhHsj2f2T7vGKDa7U5fDFv9KgrXJW6ejt8aRFqLaV-FaqB3ujGsI4kTyR6JtETyaLxr9bGGabG005Xg0TombFCNYVkpsFCWF3wotPVKAMwWITxsBSqEqqZXoiul4ILB0ornA57I87MXR6vksqhqRmfpPxzg4bQPS-s-BsLR2gO9aC4E1qBFGVhnZGovETLzG_OeAHv358QegTFOgSSPAOhdJKlhOaTh67XxsHN_BF40TszReQ_7q3HEEIfzHuZM5ODN_tEkieYPF9VUFUPg1xgBbBDafTghMIgVBv0bvp_xzBKzRCEzxXGB0P3P3xylSN0L5R3eAHT3wN5FOVFwL--K9n4zbVyTCi7QHzNyFkK6466f_vKzK-s8wGGo09VUQ1d9zZGaW6PORi0g_Sx1sX0c8Lvs8-4Cyz5JlQVEsULf3xBXIkOlRXas8SjHE97HUKfcF8Nv2eeUO5R2ZcxX3P2Ec0ZuKveXamu5PrszKyXrvan9-Zc2JYF1fg_T4rDrr_UkMagjWiEYjI0NHaoHHPBwBG-Ye-g1gYM1mhQ8cCwTjStA6FqOfgjcC3C0-cvN4v35KFxYO2id36CLY96h9Bs6YTQDAjdvTe_WxCO3xMuxD21WyjwYmRM5r9f0AXRpiz8ONdujn6GcZP2u1H1Lh8z8Uf9Hl5cSBpY9nM1m_G7DkCYtZoL5jBU8tIEHlnuaaTmQ-6uBUIUIQ_75QUxNzJFn4i6whpOf7y8zE1yJiXwoi4uDTFXP45tQY8zx4thzKTU3N9t83G1v2_UWRij2iQb4p93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