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

    <tr>
        <th>Summary</th>
        <td>
            [Flang][OpenMP] crash when a structure exists
        </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>
    Compiling the following programs with `-fopenmp` causes a crash.
```console
$ cat struct.f90
structure /s/
end structure

end
```

Compile with: `flang-new -fopenmp struct.f90`

Output:
```console
fatal internal error: SemanticsContext::FindScope(): invalid source location for 'structure /s/'
```

Stack dump:
```console
 #0 0x0000561f919513c3 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) 
 #1 0x0000561f91951a3e SignalHandler(int) Signals.cpp:0:0
 #2 0x00007f6348bf7520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
 #3 0x00007f6348c4ba7c __pthread_kill_implementation ./nptl/pthread_kill.c:44:76
 #4 0x00007f6348c4ba7c __pthread_kill_internal ./nptl/pthread_kill.c:78:10
 #5 0x00007f6348c4ba7c pthread_kill ./nptl/pthread_kill.c:89:10
 #6 0x00007f6348bf7476 gsignal ./signal/../sysdeps/posix/raise.c:27:6
 #7 0x00007f6348bdd7f3 abort ./stdlib/abort.c:81:7
 #8 0x0000561f929098b6 Fortran::common::getFlangRepositoryPath[abi:cxx11]()
 #9 0x0000561f921d3219 
#10 0x0000561f92346a88 Fortran::semantics::Scope* GetScope<Fortran::parser::MainProgram>(Fortran::semantics::SemanticsContext&, Fortran::parser::MainProgram const&) resolve-directives.cpp:0:0
#11 0x0000561f92346958 _ZNSt8__detail9__variant17__gen_vtable_implINS0_12_Multi_arrayIPFNS0_21__deduce_visit_resultIPN7Fortran9semantics6SymbolEEEOZZNS5_23ResolveOmpTopLevelPartsERNS5_16SemanticsContextERKNS4_6parser7ProgramEENK4$_15clIZNS5_23ResolveOmpTopLevelPartsESA_SE_E4$_16EEDaT_EUlRSI_E_RKSt7variantIJNS4_6common11IndirectionINSB_11MainProgramELb0EEENSO_INSB_18FunctionSubprogramELb0EEENSO_INSB_20SubroutineSubprogramELb0EEENSO_INSB_6ModuleELb0EEENSO_INSB_9SubmoduleELb0EEENSO_INSB_9BlockDataELb0EEENSO_INSB_17CompilerDirectiveELb0EEENSO_INSB_23OpenACCRoutineConstructELb0EEEEEEJEEESt16integer_sequenceImJLm0EEEE14__visit_invokeESL_S17_ resolve-directives.cpp:0:0
#12 0x0000561f92343b29 Fortran::semantics::ResolveOmpTopLevelParts(Fortran::semantics::SemanticsContext&, Fortran::parser::Program const&) 
#13 0x0000561f921859f2 Fortran::semantics::ResolveNames(Fortran::semantics::SemanticsContext&, Fortran::parser::Program const&, Fortran::semantics::Scope&) 
#14 0x0000561f921d3d6b Fortran::semantics::Semantics::Perform() 
#15 0x0000561f91972835 Fortran::frontend::FrontendAction::runSemanticChecks() 
#16 0x0000561f91d65f43 Fortran::frontend::CodeGenAction::beginSourceFileAction() 
#17 0x0000561f91971f13 Fortran::frontend::FrontendAction::beginSourceFile(Fortran::frontend::CompilerInstance&, Fortran::frontend::FrontendInputFile const&) 
#18 0x0000561f91968cf0 Fortran::frontend::CompilerInstance::executeAction(Fortran::frontend::FrontendAction&) 
#19 0x0000561f919751aa Fortran::frontend::executeCompilerInvocation(Fortran::frontend::CompilerInstance*) 
#20 0x0000561f91637f8d fc1_main(llvm::ArrayRef<char const*>, char const*) 
#21 0x0000561f91636f76 main 
#22 0x00007f6348bded90 __libc_start_call_main ./csu/../sysdeps/nptl/libc_start_call_main.h:58:16
#23 0x00007f6348bdee40 call_init ./csu/../csu/libc-start.c:128:20
#24 0x00007f6348bdee40 __libc_start_main ./csu/../csu/libc-start.c:379:5
#25 0x0000561f916364d5 _start 
flang-new: error: unable to execute command: Aborted
flang-new: error: flang frontend command failed due to signal (use -v to see invocation)
flang-new version 18.0.0 (https://github.com/llvm/llvm-project.git e2210cefb18171496573957945f9bd48eb631170)
Target: x86_64-unknown-linux-gnu
Thread model: posix
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy0WE1zo7rS_jXKRhUXEt-LLBwHn9fzkUmFeTezoQQ0tm6ExJWEk_z7WwIc24zHJ6fq3qqkjKTW00-3ukU3zBi-lQB3KLxH4cMN6-1O6buXW6a1ejU3parf71aq7bjgcovtDnCjhFCvbtRptdWsNfiV2x1GkXfbqA5k26HIwxXrDRjMcKWZ2S2Q94C8JYq88a9S0igB0ywNcMUsNlb3lV00qTfOj-NeA0Z0bRBdj9Mga_yxNCEcFmZqTldHK2Agi_yl49sIJre3El7xgfkph_PtP3rb9Rb5y2uWNMwygbm0oCUTGLRW2unKoWXS8sqslLTwNsD4yzWXdV6pDhBNEE2dIJd7JniNjep1BVioilmuJG6UxojGv3uExldMzi2rXnDdt93f8MaI-h723jzP88KINClJQ-JXPhZi345kzbsZH540l3ZA_qlZ5bgfhTR7LZSxGliLaIToyvkC0RQf1ZC5GuYDzvlWMvF_TNYCNKLJtGucNouqcwZ4w_8HEJ2A4ibyg6Rs4pB6ePDkWvAS0fVbEhVRcCu47N9ut7IfF6qFUYsI0XvvLaAh9ZzjPzD9M8wqKFlc4aLo7E4Dq4sXLkTB205AC9KOJ7NAdC07KxBdn4otKuQvgwD5yzg64gefwT9EzzXkOEH-kpx4I7yEfLrtKlySzuCiuXODOMJbM5zHgDQ-IrpeDKN3U0PnArJThr8hutaMGxiwaYz85YkP4nPouo4bH7NSaTsC23o8vmFqZEecxUeE5DSEaOqlSRnhtdJWMznGYaXaVk3PW7Brl-fP4LhZpd-fmN2h8J6V3Im-vRGCwocpBz-UpGdKSO1TcghjF8Vn2UL9IGJJcs7BHHJ-HE6JvsR_gR2f_dWZfMe0AT0-f2dcPo23K_IzRJOryPPLZcy8z4BjdwuMG1KswSixh9uaa6gs38OFxHOmk7npaZjg4tdjbpOiqME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