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

    <tr>
        <th>Summary</th>
        <td>
            [Flang] Assertion `actual.isProcedure()' failed.
        </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/97E1E7da5

Reproducer:
```f90
module m
  contains
    function f(i) result(res)
      character(len=i) :: res
    end function
end

subroutine s()
  use m
 procedure(f), pointer :: p

  contains
    subroutine ss()
 call sss(p)
    end subroutine
    subroutine sss(p)
 procedure(f), pointer :: p
    end subroutine
end
```

Stack dump:
```console
/app/example.f90:3:14: warning: Function result is never defined
      function f(i) result(res)
 ^
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0.      Program arguments: /opt/compiler-explorer/clang-llvmflang-trunk-20240810/bin/flang-new -fc1 -triple x86_64-unknown-linux-gnu -S -mrelocation-model pic -pic-level 2 -pic-is-pie -target-cpu x86-64 -mllvm -x86-asm-syntax=intel -resource-dir /opt/compiler-explorer/clang-llvmflang-trunk-20240810/lib/clang/20 -mframe-pointer=all -o /app/output.s -x f95-cpp-input /app/example.f90
 #0 0x00000000035514d8 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-llvmflang-trunk-20240810/bin/flang-new+0x35514d8)
 #1 0x000000000354ee7c SignalHandler(int) Signals.cpp:0:0
 #2 0x00007bba9c642520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
 #3 0x0000000004ea6d80 fir::dyn_cast_ptrEleTy(mlir::Type) (/opt/compiler-explorer/clang-llvmflang-trunk-20240810/bin/flang-new+0x4ea6d80)
 #4 0x0000000003993cfc Fortran::lower::genCallOpAndResult(mlir::Location, Fortran::lower::AbstractConverter&, Fortran::lower::SymMap&, Fortran::lower::StatementContext&, Fortran::lower::CallerInterface&, mlir::FunctionType, std::optional<mlir::Type>, bool) (/opt/compiler-explorer/clang-llvmflang-trunk-20240810/bin/flang-new+0x3993cfc)
 #5 0x00000000039963e7 genUserCall(llvm::SmallVector<std::optional<Fortran::lower::PreparedActualArgument>, 1u>&, Fortran::lower::CallerInterface&, mlir::FunctionType, (anonymous namespace)::CallContext&) ConvertCall.cpp:0:0
 #6 0x000000000399be6e genProcedureRef((anonymous namespace)::CallContext&) ConvertCall.cpp:0:0
 #7 0x000000000399de94 Fortran::lower::convertCallToHLFIR(mlir::Location, Fortran::lower::AbstractConverter&, Fortran::evaluate::ProcedureRef const&, std::optional<mlir::Type>, Fortran::lower::SymMap&, Fortran::lower::StatementContext&) (/opt/compiler-explorer/clang-llvmflang-trunk-20240810/bin/flang-new+0x399de94)
 #8 0x000000000396de9b (anonymous namespace)::FirConverter::genFIR(Fortran::lower::pft::Evaluation&, bool) (.constprop.0) Bridge.cpp:0:0
 #9 0x00000000039723fc (anonymous namespace)::FirConverter::lowerFunc(Fortran::lower::pft::FunctionLikeUnit&) Bridge.cpp:0:0
#10 0x000000000397285b (anonymous namespace)::FirConverter::lowerFunc(Fortran::lower::pft::FunctionLikeUnit&) Bridge.cpp:0:0
#11 0x000000000397422c Fortran::lower::LoweringBridge::lower(Fortran::parser::Program const&, Fortran::semantics::SemanticsContext const&) (/opt/compiler-explorer/clang-llvmflang-trunk-20240810/bin/flang-new+0x397422c)
#12 0x00000000038d9ae1 Fortran::frontend::CodeGenAction::beginSourceFileAction() (/opt/compiler-explorer/clang-llvmflang-trunk-20240810/bin/flang-new+0x38d9ae1)
#13 0x00000000035a7f15 Fortran::frontend::FrontendAction::beginSourceFile(Fortran::frontend::CompilerInstance&, Fortran::frontend::FrontendInputFile const&) (/opt/compiler-explorer/clang-llvmflang-trunk-20240810/bin/flang-new+0x35a7f15)
#14 0x0000000003597ba7 Fortran::frontend::CompilerInstance::executeAction(Fortran::frontend::FrontendAction&) (/opt/compiler-explorer/clang-llvmflang-trunk-20240810/bin/flang-new+0x3597ba7)
#15 0x00000000035adf5d Fortran::frontend::executeCompilerInvocation(Fortran::frontend::CompilerInstance*) (/opt/compiler-explorer/clang-llvmflang-trunk-20240810/bin/flang-new+0x35adf5d)
#16 0x0000000001c6f808 fc1_main(llvm::ArrayRef<char const*>, char const*) (/opt/compiler-explorer/clang-llvmflang-trunk-20240810/bin/flang-new+0x1c6f808)
#17 0x0000000001b5189c main (/opt/compiler-explorer/clang-llvmflang-trunk-20240810/bin/flang-new+0x1b5189c)
#18 0x00007bba9c629d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
#19 0x00007bba9c629e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
#20 0x0000000001c6e76e _start (/opt/compiler-explorer/clang-llvmflang-trunk-20240810/bin/flang-new+0x1c6e76e)
flang-new: error: unable to execute command: Segmentation fault (core dumped)
flang-new: error: flang frontend command failed due to signal (use -v to see invocation)
flang-new version 20.0.0git (https://github.com/llvm/llvm-project.git 51a3bc12176ab46f3d2ce6ad4aa26af088d3cf14)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /opt/compiler-explorer/clang-llvmflang-trunk-20240810/bin
```

With assertion-enabled flang-new, compiling the above reproducer results in the following assertion failure:
```txt
flang-new: /path_to_llvm_project/llvm-project/flang/lib/Lower/ConvertCall.cpp:1458: (anonymous namespace)::PreparedDummyArgument prepareProcedurePointerActualArgument(mlir::Location, fir::FirOpBuilder &, const Fortran::lower::PreparedActualArgument &, mlir::Type, const Fortran::lower::CallerInterface::PassedEntity &, (anonymous namespace)::CallContext &): Assertion `actual.isProcedure()' failed.
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy8WV9v27iy_zTKCyFDov5YesiDm0S7BXKxQdO999GgyJHNG4oUSCqxz6c_ICXZlhun6Z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