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

    <tr>
        <th>Summary</th>
        <td>
            [Flang] fatal internal error: nullptr dereference at llvm-project/flang/lib/Semantics/resolve-names.cpp(3712)
        </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/xaKhrEKMh

Reproducer:
```
module m
   type :: base
   end type

contains
   type(base) subroutine foo()
   end subroutine

end module
```

Stack dump:
```console
 #0 0x0000000003527048 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-llvmflang-trunk-20240202/bin/flang-new+0x3527048)
 #1 0x00000000035249bc SignalHandler(int) Signals.cpp:0:0
 #2 0x00007f5f94242520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
 #3 0x00007f5f942969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)
 #4 0x00007f5f94242476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)
 #5 0x00007f5f942287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)
 #6 0x00000000049afc29 (/opt/compiler-explorer/clang-llvmflang-trunk-20240202/bin/flang-new+0x49afc29)
 #7 0x0000000003dcc93a (/opt/compiler-explorer/clang-llvmflang-trunk-20240202/bin/flang-new+0x3dcc93a)
 #8 0x0000000003df0a9d Fortran::semantics::SubprogramVisitor::Pre(Fortran::parser::SubroutineStmt const&) (/opt/compiler-explorer/clang-llvmflang-trunk-20240202/bin/flang-new+0x3df0a9d)
 #9 0x0000000003df0c70 void Fortran::parser::Walk<Fortran::parser::SubroutineStmt, Fortran::semantics::ResolveNamesVisitor>(Fortran::parser::Statement<Fortran::parser::SubroutineStmt> const&, Fortran::semantics::ResolveNamesVisitor&) (/opt/compiler-explorer/clang-llvmflang-trunk-20240202/bin/flang-new+0x3df0c70)
#10 0x0000000003e21a09 Fortran::semantics::ResolveNamesVisitor::ResolveSpecificationParts(Fortran::semantics::ProgramTree&) (.part.0) resolve-names.cpp:0:0
#11 0x0000000003e21bad Fortran::semantics::ResolveNamesVisitor::ResolveSpecificationParts(Fortran::semantics::ProgramTree&) (.part.0) resolve-names.cpp:0:0
#12 0x0000000003e21fd6 Fortran::semantics::ResolveNamesVisitor::Pre(Fortran::parser::ProgramUnit const&) (/opt/compiler-explorer/clang-llvmflang-trunk-20240202/bin/flang-new+0x3e21fd6)
#13 0x0000000003e232af Fortran::semantics::ResolveNames(Fortran::semantics::SemanticsContext&, Fortran::parser::Program const&, Fortran::semantics::Scope&) (/opt/compiler-explorer/clang-llvmflang-trunk-20240202/bin/flang-new+0x3e232af)
#14 0x0000000003e79b61 Fortran::semantics::Semantics::Perform() (/opt/compiler-explorer/clang-llvmflang-trunk-20240202/bin/flang-new+0x3e79b61)
#15 0x000000000356a297 Fortran::frontend::FrontendAction::runSemanticChecks() (/opt/compiler-explorer/clang-llvmflang-trunk-20240202/bin/flang-new+0x356a297)
#16 0x0000000003882a20 Fortran::frontend::CodeGenAction::beginSourceFileAction() (/opt/compiler-explorer/clang-llvmflang-trunk-20240202/bin/flang-new+0x3882a20)
#17 0x0000000003569895 Fortran::frontend::FrontendAction::beginSourceFile(Fortran::frontend::CompilerInstance&, Fortran::frontend::FrontendInputFile const&) (/opt/compiler-explorer/clang-llvmflang-trunk-20240202/bin/flang-new+0x3569895)
#18 0x0000000003559767 Fortran::frontend::CompilerInstance::executeAction(Fortran::frontend::FrontendAction&) (/opt/compiler-explorer/clang-llvmflang-trunk-20240202/bin/flang-new+0x3559767)
#19 0x000000000356fafd Fortran::frontend::executeCompilerInvocation(Fortran::frontend::CompilerInstance*) (/opt/compiler-explorer/clang-llvmflang-trunk-20240202/bin/flang-new+0x356fafd)
#20 0x0000000001d61ba8 fc1_main(llvm::ArrayRef<char const*>, char const*) (/opt/compiler-explorer/clang-llvmflang-trunk-20240202/bin/flang-new+0x1d61ba8)
#21 0x0000000001c68c3d main (/opt/compiler-explorer/clang-llvmflang-trunk-20240202/bin/flang-new+0x1c68c3d)
#22 0x00007f5f94229d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
#23 0x00007f5f94229e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
#24 0x0000000001d60b0e _start (/opt/compiler-explorer/clang-llvmflang-trunk-20240202/bin/flang-new+0x1d60b0e)
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 ff3194037071e7f5fe859ad2173a5b67eed08b3b)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /opt/compiler-explorer/clang-llvmflang-trunk-20240202/bin
flang-new: note: diagnostic msg:
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzMWNtu47oV_Rr5hbBBUfcHP_gk49ODgxaDybR9NChyy2YjkQJJZZx-fUFKvlAJMnELDzqYOBbJvfZa-8JQpMaIvQRYR9lvUfa4oIM9KL1-XlKt1Q-zqBV_XX-DXis-MFG3gJREvyteq9ZGySbCjxHeHKztjXsi24hs9-PsSul9RLb_jsj2SP886C9__vUwLh8_T6CgzzhRjqf__rFTfGgBdeMTQsi-9oDc6mSDamrgPAGS-8lrfKakpUKawDoipTckFTJDrdVghQTUKBWRMiJVAHhZcA3rZkZi73IeP58sZc-ID13_VhtT0qiTNYpIghE-4tO_JCMFTkvUti_dqNS8mvHLVy2k9cjfNWVOymWRpj92ylgNtItIHpEHJKR1Kr2ureptRLZMdb1oQS_h2LdKg3ZjLZX7pQNq_DerB_m8JJikmGASkW0tZES246SEHxH5DR8nkpeARSSJZyrSqmboSewlbf9CJW-dt3IiNQ6bFetdfLD_OQORCah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