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

    <tr>
        <th>Summary</th>
        <td>
            flang-new OpenMP reduction compiler crash
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

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

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

<pre>
    Reproducer below

flang-new -fopenmp -c -o ompmod.o ompmod.f90

llvm-project/llvm/include/llvm/Support/Casting.h:566: decltype(auto) llvm::cast(const From&) [with To = fir::ReferenceType; From = mlir::Type]: Assertion `isa<To>(Val) && "cast<Ty>() argument of incompatible type!"' failed.

Interestingly, if the array size is made explicit (e.g. replace len with 10) it gives a sensible error instead of a crash:

llvm-project/flang/lib/Lower/OpenMP.cpp:1129: not yet implemented: Reduction of some types is not supported


MODULE ompmod

    USE omp_lib

    IMPLICIT NONE

 PRIVATE

CONTAINS

  SUBROUTINE ompmods(len, fa)

 INTEGER, INTENT(IN) :: len
    double precision, INTENT(OUT) :: fa(len)
    double precision, DIMENSION(:), ALLOCATABLE :: ary

!$omp parallel               & 
!$omp   reduction(+:fa) 

    ALLOCATE(ary(len))

!$omp barrier 

    DEALLOCATE(ary)

!$omp end parallel 

  END SUBROUTINE ompmods

END MODULE ompmod




</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJx8VE2PozgQ_TXOpdQR2PmAAwfytUJKk1aanuvK4CLxrsHINt2b_fUrO9OTpHdmckCEelX1_Oq5uLXy1CNmZL4i882Ej-6sTfY3SsHfpZ3UWlyyIw5Gi7FBAzUq_UGiDYny67NVvD899fgBT60esO8GeGrgSYPuhk6L6Y-XNo3u85R6754Go__CxhG6838J3cm-UaPA24fXcRi08Yg1t072p-mZsHy-WBCWg8BGucuAhCZ8dJrQFEIaywnLG24doUmje-tgZ3RH6MIjyHz1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