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

    <tr>
        <th>Summary</th>
        <td>
            [Flang] [HLFIR] flang-new crashes (but it doesn't with `-flang-deprecated-no-hlfir`)
        </td>
    </tr>

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

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

    <tr>
      <th>Reporter</th>
      <td>
          k-arrows
      </td>
    </tr>
</table>

<pre>
    Crash itself is reproducible on Godbolt: 
https://godbolt.org/z/MTEKP7f7b

Reproducer:
```console
$ cat test.f03
module m1
    type base
        type(base), pointer :: next => null()
    end type
end module

module m2
    use m1
 type, extends(base) :: child
        integer :: i
    end type
end module

program p
    use m2
    type(base) :: b
 type(child), target :: c
    b = base(c%next)
end
```

If assertion is turned on, I can get the following message:
```txt
flang-new: /path_to_llvm_project/llvm-project/llvm/include/llvm/Support/Casting.h:662: decltype(auto) llvm::dyn_cast(From *) [To = mlir::omp::OutlineableOpenMPOpInterface, From = mlir::Operation]: Assertion `detail::isPresent(Val) && "dyn_cast on a non-existent value"' failed.
```

By specifying `-flang-deprecated-no-hlfir`, I can avoid the crash.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyUlN9v4zYMx_8a-UVI4NCxHT_4IW3OW7EdWtwOey1ki7a1yZIh0f2xv36Q1SZNDxh2QBBYNEl9-CVN4b0aDGLN8huWnxKx0Ghd_fdGOGeffdJa-VrfOuFHrsij7rny3OHsrFw61Wrk1vBfrGytJpYdOUtPLD2ORLNn2ZFBw6AZ4uutdQOD5h8GzdfvX357KPuyje7x_9tbVnQhMr4o0vjrrPFW45sV9rwTxAk9bfs0i9bJykUjn3bxyDnn9Dojb4XHi-ndzOCwvoCKwS2frTKEjoeLsyM3-EKcZSeWfeFm0ZrBITiek6CRMclqCad4-cdq3nHgErb4D3gR4pbjC6GR_sLzDtGN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