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

    <tr>
        <th>Summary</th>
        <td>
            [Flang] fatal internal error: CHECK(!start.IsTopLevel()) failed at /root/llvm-project/flang/lib/Semantics/tools.cpp(80)
        </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>
    Reproducible on Godbolt:
https://godbolt.org/z/fefT39bTe

Reproducer:
```console
$ cat test.f90
real x(f())
f() = 0.0
end
```

Stack dump:
```console
fatal internal error: CHECK(!start.IsTopLevel()) failed at /root/llvm-project/flang/lib/Semantics/tools.cpp(80)
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-20240507/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-20240507/lib/clang/19 -mframe-pointer=all -o /app/output.s -x f95-cpp-input /app/example.f90
 #0 0x000000000377f328 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-llvmflang-trunk-20240507/bin/flang-new+0x377f328)
 #1 0x000000000377cc9c SignalHandler(int) Signals.cpp:0:0
 #2 0x00007bd906a42520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
 #3 0x00007bd906a969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)
 #4 0x00007bd906a42476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)
 #5 0x00007bd906a287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)
 #6 0x0000000004cef8e9 (/opt/compiler-explorer/clang-llvmflang-trunk-20240507/bin/flang-new+0x4cef8e9)
 #7 0x0000000004131fb8 (/opt/compiler-explorer/clang-llvmflang-trunk-20240507/bin/flang-new+0x4131fb8)
 #8 0x0000000004132a05 Fortran::semantics::IsHostAssociated(Fortran::semantics::Symbol const&, Fortran::semantics::Scope const&) (/opt/compiler-explorer/clang-llvmflang-trunk-20240507/bin/flang-new+0x4132a05)
 #9 0x000000000409cb05 Fortran::semantics::SubprogramVisitor::HandleStmtFunction(Fortran::parser::StmtFunctionStmt const&) (/opt/compiler-explorer/clang-llvmflang-trunk-20240507/bin/flang-new+0x409cb05)
#10 0x000000000409d0c8 void Fortran::parser::Walk<Fortran::common::Indirection<Fortran::parser::StmtFunctionStmt, false>, Fortran::semantics::ResolveNamesVisitor>(Fortran::parser::Statement<Fortran::common::Indirection<Fortran::parser::StmtFunctionStmt, false>> const&, Fortran::semantics::ResolveNamesVisitor&) (/opt/compiler-explorer/clang-llvmflang-trunk-20240507/bin/flang-new+0x409d0c8)
#11 0x00000000040a8fa5 void Fortran::parser::Walk<Fortran::parser::DeclarationConstruct, Fortran::semantics::ResolveNamesVisitor>(std::__cxx11::list<Fortran::parser::DeclarationConstruct, std::allocator<Fortran::parser::DeclarationConstruct>> const&, Fortran::semantics::ResolveNamesVisitor&) (/opt/compiler-explorer/clang-llvmflang-trunk-20240507/bin/flang-new+0x40a8fa5)
#12 0x00000000040aa70d Fortran::semantics::ResolveNamesVisitor::Pre(Fortran::parser::SpecificationPart const&) (/opt/compiler-explorer/clang-llvmflang-trunk-20240507/bin/flang-new+0x40aa70d)
#13 0x00000000040a87a9 std::enable_if<TupleTrait<Fortran::parser::SpecificationPart>, void>::type Fortran::parser::Walk<Fortran::parser::SpecificationPart, Fortran::semantics::ResolveNamesVisitor>(Fortran::parser::SpecificationPart const&, Fortran::semantics::ResolveNamesVisitor&) (/opt/compiler-explorer/clang-llvmflang-trunk-20240507/bin/flang-new+0x40a87a9)
#14 0x00000000040cf644 Fortran::semantics::ResolveNamesVisitor::ResolveSpecificationParts(Fortran::semantics::ProgramTree&) (.part.0) resolve-names.cpp:0:0
#15 0x00000000040cfcd6 Fortran::semantics::ResolveNamesVisitor::Pre(Fortran::parser::ProgramUnit const&) (/opt/compiler-explorer/clang-llvmflang-trunk-20240507/bin/flang-new+0x40cfcd6)
#16 0x00000000040d11e4 Fortran::semantics::ResolveNames(Fortran::semantics::SemanticsContext&, Fortran::parser::Program const&, Fortran::semantics::Scope&) (/opt/compiler-explorer/clang-llvmflang-trunk-20240507/bin/flang-new+0x40d11e4)
#17 0x00000000041295e1 Fortran::semantics::Semantics::Perform() (/opt/compiler-explorer/clang-llvmflang-trunk-20240507/bin/flang-new+0x41295e1)
#18 0x00000000037d01f5 Fortran::frontend::FrontendAction::runSemanticChecks() (/opt/compiler-explorer/clang-llvmflang-trunk-20240507/bin/flang-new+0x37d01f5)
#19 0x0000000003af6cd2 Fortran::frontend::CodeGenAction::beginSourceFileAction() (/opt/compiler-explorer/clang-llvmflang-trunk-20240507/bin/flang-new+0x3af6cd2)
#20 0x00000000037cf605 Fortran::frontend::FrontendAction::beginSourceFile(Fortran::frontend::CompilerInstance&, Fortran::frontend::FrontendInputFile const&) (/opt/compiler-explorer/clang-llvmflang-trunk-20240507/bin/flang-new+0x37cf605)
#21 0x00000000037bf077 Fortran::frontend::CompilerInstance::executeAction(Fortran::frontend::FrontendAction&) (/opt/compiler-explorer/clang-llvmflang-trunk-20240507/bin/flang-new+0x37bf077)
#22 0x00000000037d564d Fortran::frontend::executeCompilerInvocation(Fortran::frontend::CompilerInstance*) (/opt/compiler-explorer/clang-llvmflang-trunk-20240507/bin/flang-new+0x37d564d)
#23 0x0000000001f3c928 fc1_main(llvm::ArrayRef<char const*>, char const*) (/opt/compiler-explorer/clang-llvmflang-trunk-20240507/bin/flang-new+0x1f3c928)
#24 0x0000000001e2b804 main (/opt/compiler-explorer/clang-llvmflang-trunk-20240507/bin/flang-new+0x1e2b804)
#25 0x00007bd906a29d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
#26 0x00007bd906a29e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
#27 0x0000000001f3b88e _start (/opt/compiler-explorer/clang-llvmflang-trunk-20240507/bin/flang-new+0x1f3b88e)
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 6e5ed351be68017e46120b8ad1aa89d75b0ca204)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /opt/compiler-explorer/clang-llvmflang-trunk-20240507/bin
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzMWd1u2zoSfhr5hpBBUbIsXfjCJ4lPiz1YFE1299KgyJHDDUUKJJU6-_QLUvKPlNZpeuqihRuY0mhmvvlm6BGHWit2CmAVLf6IFrcz2rlHbVZPMTVGf7GzSvOX1WdojeYdE5UEpBX6U_NKSxel6wjfRnj96Fxr_YpsIrLZ9Xfn2uwisvlfRDY11A9pWT1AL97_PSgFc9QT5bj_MK2slgdxkiFGHXJg3bwucX_VAJVoH5GijkgRkdJ_wo1hjaL0FuH5IA2KT0ycu3LvKHtCvGvaN1ypqaMSCeXAKCoRGKO99-jmw93NP4LdxDpq3PyjfdDtX_AM8ugdqqmQwBF1KCIbo7WLyEbK5yZujf4vML-sJVU-aFJUEdncQ0OVE8xGZOO0lnbO2jYiRYGPYD_9dbe-v0O2qxrhEEVVt0MGWm0cchpNeBHusavmTDeD4df2hbUdeHOIKo6EYrLjgNwjIGaofUQVZU_OUAbzbwYOzyNcfjJ6Z2iDqNl1DSjnnfCodeutMN20QoKJYd9KbcD4ax557N0JMYid6dRTTDDJ8AIvI7KphDoEKFbwBcU1S1DsjGgloH2Rb_Ms7tST0l9ULIXq9vFOdSi-R3FjQGpGndAqbjQHiVrBUNwKFkvPECL9Qti4FYBiR80OXMzazuuN8wzFjX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