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

    <tr>
        <th>Summary</th>
        <td>
            [Flang] llvm-project/flang/lib/Lower/CallInterface.cpp:541: Fortran::evaluate::characteristics::Procedure Fortran::lower::CalleeInterface::characterize() const: Assertion `characteristic && "Fail to get characteristic from symbol"' 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/7vWE6o8ab

With assertion-enabled flang-new, the following assertion failure was observed.
```txt
flang-new: /path_to_llvm_project/llvm-project/flang/lib/Lower/CallInterface.cpp:541: Fortran::evaluate::characteristics::Procedure Fortran::lower::CalleeInterface::characterize() const: Assertion `characteristic && "Fail to get characteristic from symbol"' failed.
```

Reproducer:
```console
$ cat test.f90
module m
    contains
        subroutine s1(a1)
            procedure(s2) :: a1
        end subroutine
        subroutine s2(a2)
 procedure(s1) :: a2
        end subroutine
end module
```

Stack dump from Godbolt:
```console
terminate called after throwing an instance of 'std::bad_alloc'
  what(): std::bad_alloc
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-20240511/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-20240511/lib/clang/19 -mframe-pointer=all -o /app/output.s -x f95-cpp-input /app/example.f90
 #0 0x0000000003796638 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-llvmflang-trunk-20240511/bin/flang-new+0x3796638)
 #1 0x0000000003793fac SignalHandler(int) Signals.cpp:0:0
 #2 0x000075af93242520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
 #3 0x000075af932969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)
 #4 0x000075af93242476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)
 #5 0x000075af932287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)
 #6 0x000075af93773bfd (/opt/compiler-explorer/gcc-snapshot/lib64/libstdc++.so.6+0xadbfd)
 #7 0x000075af93784f7a (/opt/compiler-explorer/gcc-snapshot/lib64/libstdc++.so.6+0xbef7a)
 #8 0x000075af937737a9 std::unexpected() (/opt/compiler-explorer/gcc-snapshot/lib64/libstdc++.so.6+0xad7a9)
 #9 0x000075af937851f7 (/opt/compiler-explorer/gcc-snapshot/lib64/libstdc++.so.6+0xbf1f7)
#10 0x000075af93776229 std::__throw_bad_array_new_length() (/opt/compiler-explorer/gcc-snapshot/lib64/libstdc++.so.6+0xb0229)
#11 0x00000000043879c1 (/opt/compiler-explorer/clang-llvmflang-trunk-20240511/bin/flang-new+0x43879c1)
#12 0x000000000438a0f7 Fortran::evaluate::characteristics::Procedure::Procedure(Fortran::evaluate::characteristics::Procedure const&) (/opt/compiler-explorer/clang-llvmflang-trunk-20240511/bin/flang-new+0x438a0f7)
#13 0x0000000003bacc8b Fortran::lower::CalleeInterface::characterize() const (/opt/compiler-explorer/clang-llvmflang-trunk-20240511/bin/flang-new+0x3bacc8b)
#14 0x0000000003bb6b78 Fortran::lower::CallInterface<Fortran::lower::CalleeInterface>::declare() (/opt/compiler-explorer/clang-llvmflang-trunk-20240511/bin/flang-new+0x3bb6b78)
#15 0x0000000003b6cfeb (anonymous namespace)::FirConverter::declareFunction(Fortran::lower::pft::FunctionLikeUnit&) Bridge.cpp:0:0
#16 0x0000000003b71836 std::__detail::__variant::__gen_vtable_impl<true, std::__detail::__variant::_Multi_array<void (*)(Fortran::common::visitors<(anonymous namespace)::FirConverter::run(Fortran::lower::pft::Program&)::'lambda'(Fortran::lower::pft::FunctionLikeUnit&), (anonymous namespace)::FirConverter::run(Fortran::lower::pft::Program&)::'lambda0'(Fortran::lower::pft::ModuleLikeUnit&), (anonymous namespace)::FirConverter::run(Fortran::lower::pft::Program&)::'lambda1'(Fortran::lower::pft::BlockDataUnit&), (anonymous namespace)::FirConverter::run(Fortran::lower::pft::Program&)::'lambda2'(Fortran::lower::pft::CompilerDirectiveUnit&), (anonymous namespace)::FirConverter::run(Fortran::lower::pft::Program&)::'lambda3'(Fortran::lower::pft::OpenACCDirectiveUnit&)>&&, std::variant<Fortran::lower::pft::FunctionLikeUnit, Fortran::lower::pft::ModuleLikeUnit, Fortran::lower::pft::BlockDataUnit, Fortran::lower::pft::CompilerDirectiveUnit, Fortran::lower::pft::OpenACCDirectiveUnit>&)>, std::tuple<std::variant<Fortran::lower::pft::FunctionLikeUnit, Fortran::lower::pft::ModuleLikeUnit, Fortran::lower::pft::BlockDataUnit, Fortran::lower::pft::CompilerDirectiveUnit, Fortran::lower::pft::OpenACCDirectiveUnit>&>, std::integer_sequence<unsigned long, 1ul>>::__visit_invoke(Fortran::common::visitors<(anonymous namespace)::FirConverter::run(Fortran::lower::pft::Program&)::'lambda'(Fortran::lower::pft::FunctionLikeUnit&), (anonymous namespace)::FirConverter::run(Fortran::lower::pft::Program&)::'lambda0'(Fortran::lower::pft::ModuleLikeUnit&), (anonymous namespace)::FirConverter::run(Fortran::lower::pft::Program&)::'lambda1'(Fortran::lower::pft::BlockDataUnit&), (anonymous namespace)::FirConverter::run(Fortran::lower::pft::Program&)::'lambda2'(Fortran::lower::pft::CompilerDirectiveUnit&), (anonymous namespace)::FirConverter::run(Fortran::lower::pft::Program&)::'lambda3'(Fortran::lower::pft::OpenACCDirectiveUnit&)>&&, std::variant<Fortran::lower::pft::FunctionLikeUnit, Fortran::lower::pft::ModuleLikeUnit, Fortran::lower::pft::BlockDataUnit, Fortran::lower::pft::CompilerDirectiveUnit, Fortran::lower::pft::OpenACCDirectiveUnit>&) Bridge.cpp:0:0
#17 0x0000000003b832d5 Fortran::lower::LoweringBridge::lower(Fortran::parser::Program const&, Fortran::semantics::SemanticsContext const&) (/opt/compiler-explorer/clang-llvmflang-trunk-20240511/bin/flang-new+0x3b832d5)
#18 0x0000000003b15039 Fortran::frontend::CodeGenAction::beginSourceFileAction() (/opt/compiler-explorer/clang-llvmflang-trunk-20240511/bin/flang-new+0x3b15039)
#19 0x00000000037e7125 Fortran::frontend::FrontendAction::beginSourceFile(Fortran::frontend::CompilerInstance&, Fortran::frontend::FrontendInputFile const&) (/opt/compiler-explorer/clang-llvmflang-trunk-20240511/bin/flang-new+0x37e7125)
#20 0x00000000037d6b37 Fortran::frontend::CompilerInstance::executeAction(Fortran::frontend::FrontendAction&) (/opt/compiler-explorer/clang-llvmflang-trunk-20240511/bin/flang-new+0x37d6b37)
#21 0x00000000037ed16d Fortran::frontend::executeCompilerInvocation(Fortran::frontend::CompilerInstance*) (/opt/compiler-explorer/clang-llvmflang-trunk-20240511/bin/flang-new+0x37ed16d)
#22 0x0000000001f3f798 fc1_main(llvm::ArrayRef<char const*>, char const*) (/opt/compiler-explorer/clang-llvmflang-trunk-20240511/bin/flang-new+0x1f3f798)
#23 0x0000000001e2db04 main (/opt/compiler-explorer/clang-llvmflang-trunk-20240511/bin/flang-new+0x1e2db04)
#24 0x000075af93229d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
#25 0x000075af93229e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
#26 0x0000000001f3e6fe _start (/opt/compiler-explorer/clang-llvmflang-trunk-20240511/bin/flang-new+0x1f3e6fe)
flang-new: error: unable to execute command: Aborted (core dumped)
flang-new: error: flang frontend command failed due to signal (use -v to see invocation)
flang-new version 19.0.0git (https://github.com/llvm/llvm-project.git 504cf554639360525c3f746e7296a242350b2af9)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /opt/compiler-explorer/clang-llvmflang-trunk-20240511/bin
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzsWl1z4yjW_jXKDSWXhL4vcuE48bxd1VNv12S25tKF0JHMBoEWkOPMr98CybGlTtJOb7wztRVXfxgM5znPc-AAQkRr1giAay-58ZLbK9KbrVTXDz5RSj7qq1JWT9crRfQWMaOB14hppKBTsuopKzkgKdAvsiolN1609IJbL1hujem0LeG1h9fN8OtCqsbD6z89vM52f9ylMifl0Hz49w9mtohoDcowKXwQpORQoZoT0fgCHj28QmYLqJacy0cmmmNjVBPGewXokWgkSw1qB9ViNJ4Gwx-zN0PN0WK0RB5ed8RsN0ZuON-1m07JfwI1Hl7bon8sul62mpUeXn-Vj6A8vF4Rzr8IA6omFBa067xomcShtbyWyigirAzREnaE98TAUKJbogg1oJg2jOqh8puSFCrLYtKTOyT31YIBPMPNbf0JHs49XCAqhbbBQMtngbw0mIIiD6ceTpGH8ZowjoxEDRg0a1Qr2SL91JaSexh7OHNKf6_taRx_GwfH4PW0nfVMchhrcYwoMciANou6GI20suo5oHYoIYQsHUOY0Mca-9F9qWRvmACkQw_nJPRwMW1iP91BVQ_nGlt1BtkQCaeNQVQnNl_HwhYLH7EmAOEpAP4xgK0bCL8h6L0h9AFVfdsN8ZjPtpfVNaBaJogBRO2wqRCpDShktmqcPAIxoQ0RFJCskYczbarB9ZJUG8K5pB7ODhwet8QMw8tye6Gpa_ft693y_s7SbJlBBJV9Y5OFVMYOsFlaYGbblwsq23GyfT_nmNY9aA-vEREVYoLyvgKXBKjLSCWhD0bZmTdX6lmcYOEFxTclG0VaRFTTtyCMHme-7CwKlW3HOCgf9h2Xys1r6nKEdWfIFkb14sHHAY6DJAw9vC6ZOCQFm0qQX9MQ-UaxjgPa5-kmjf1ePAj5KHzORL_3G9Ej_x75rQIuKXFJrpUVcNQxivyOUZ_DDjjCQ4Fpv2OAfENUA8anXW_t-mmM_NY6hnxbJLr19ZMwZO9Ft0wY4MhXoGWvKPg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