<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/65571>65571</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[Flang][OpenMP] Compilation error of `critical` construct not in parallel regions
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue,
flang
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
yus3710-fj
</td>
</tr>
</table>
<pre>
This is an issue from Fujitsu testsuite.
Flang-new terminates abnormally when compiling `critical` construct not in parallel regions.
The following are the test program, Flang-new and gfortran compilation result.
```fortran
! test.f90
!$omp critical
!$omp end critical
end
```
```console
$ flang-new -v test.f90 -fopenmp
flang-new version 18.0.0 (https://github.com/llvm/llvm-project.git 701e6f7630474b637e0bc45d009bf2ec47f2d3fd)
Target: aarch64-unknown-linux-gnu
Thread model: posix
InstalledDir: /path/to/install/bin
Found candidate GCC installation: /usr/lib/gcc/aarch64-redhat-linux/8
Selected GCC installation: /usr/lib/gcc/aarch64-redhat-linux/8
Candidate multilib: .;@m64
Selected multilib: .;@m64
"/path/to/install/bin/flang-new" -fc1 -triple aarch64-unknown-linux-gnu -emit-obj -fopenmp -fcolor-diagnostics -mrelocation-model pic -pic-level 2 -pic-is-pie -target-cpu generic -target-feature +neon -target-feature +v8a -o /tmp/test-66b0ac.o -x f95-cpp-input test.f90
fatal internal error: SemanticsContext::FindScope(): invalid source location for 'critical'
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0. Program arguments: /path/to/install/bin/flang-new -fc1 -triple aarch64-unknown-linux-gnu -emit-obj -fopenmp -fcolor-diagnostics -mrelocation-model pic -pic-level 2 -pic-is-pie -target-cpu generic -target-feature +neon -target-feature +v8a -o /tmp/test-66b0ac.o -x f95-cpp-input test.f90
#0 0x0000ffff90545f60 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/path/to/install/bin/../lib/libLLVMSupport.so.18git+0x1a5f60)
#1 0x0000ffff90543b40 llvm::sys::RunSignalHandlers() (/path/to/install/bin/../lib/libLLVMSupport.so.18git+0x1a3b40)
#2 0x0000ffff90543cb0 SignalHandler(int) Signals.cpp:0:0
#3 0x0000ffff9202066c (linux-vdso.so.1+0x66c)
#4 0x0000ffff8ff22dbc raise (/lib64/libc.so.6+0x32dbc)
#5 0x0000ffff8ff10928 abort (/lib64/libc.so.6+0x20928)
#6 0x0000ffff8b3a2714 (/path/to/install/bin/../lib/../lib/libFortranCommon.so.18git+0x2714)
#7 0x0000ffff8c5644f4 (/path/to/install/bin/../lib/../lib/libFortranSemantics.so.18git+0x5744f4)
#8 0x0000ffff8c4a2b44 std::enable_if<TupleTrait<Fortran::parser::OpenMPCriticalConstruct>, void>::type Fortran::parser::Walk<Fortran::parser::OpenMPCriticalConstruct, Fortran::semantics::OmpAttributeVisitor>(Fortran::parser::OpenMPCriticalConstruct const&, Fortran::semantics::OmpAttributeVisitor&) (/path/to/install/bin/../lib/../lib/libFortranSemantics.so.18git+0x4b2b44)
#9 0x0000ffff8c4a1c30 void Fortran::common::log2visit::Log2VisitHelper<0ul, 0ul, void, void Fortran::parser::Walk<Fortran::semantics::OmpAttributeVisitor, Fortran::parser::ExecutableConstruct, Fortran::parser::Statement<Fortran::common::Indirection<Fortran::parser::FormatStmt, false>>, Fortran::parser::Statement<Fortran::common::Indirection<Fortran::parser::EntryStmt, false>>, Fortran::parser::Statement<Fortran::common::Indirection<Fortran::parser::DataStmt, false>>, Fortran::parser::Statement<Fortran::common::Indirection<Fortran::parser::NamelistStmt, false>>, Fortran::parser::ErrorRecovery>(std::variant<Fortran::parser::ExecutableConstruct, Fortran::parser::Statement<Fortran::common::Indirection<Fortran::parser::FormatStmt, false>>, Fortran::parser::Statement<Fortran::common::Indirection<Fortran::parser::EntryStmt, false>>, Fortran::parser::Statement<Fortran::common::Indirection<Fortran::parser::DataStmt, false>>, Fortran::parser::Statement<Fortran::common::Indirection<Fortran::parser::NamelistStmt, false>>, Fortran::parser::ErrorRecovery> const&, Fortran::semantics::OmpAttributeVisitor&)::'lambda'(Fortran::semantics::OmpAttributeVisitor const&), std::variant<Fortran::parser::ExecutableConstruct, Fortran::parser::Statement<Fortran::common::Indirection<Fortran::parser::FormatStmt, false>>, Fortran::parser::Statement<Fortran::common::Indirection<Fortran::parser::EntryStmt, false>>, Fortran::parser::Statement<Fortran::common::Indirection<Fortran::parser::DataStmt, false>>, Fortran::parser::Statement<Fortran::common::Indirection<Fortran::parser::NamelistStmt, false>>, Fortran::parser::ErrorRecovery> const&>(void Fortran::parser::Walk<Fortran::semantics::OmpAttributeVisitor, Fortran::parser::ExecutableConstruct, Fortran::parser::Statement<Fortran::common::Indirection<Fortran::parser::FormatStmt, false>>, Fortran::parser::Statement<Fortran::common::Indirection<Fortran::parser::EntryStmt, false>>, Fortran::parser::Statement<Fortran::common::Indirection<Fortran::parser::DataStmt, false>>, Fortran::parser::Statement<Fortran::common::Indirection<Fortran::parser::NamelistStmt, false>>, Fortran::parser::ErrorRecovery>(std::variant<Fortran::parser::ExecutableConstruct, Fortran::parser::Statement<Fortran::common::Indirection<Fortran::parser::FormatStmt, false>>, Fortran::parser::Statement<Fortran::common::Indirection<Fortran::parser::EntryStmt, false>>, Fortran::parser::Statement<Fortran::common::Indirection<Fortran::parser::DataStmt, false>>, Fortran::parser::Statement<Fortran::common::Indirection<Fortran::parser::NamelistStmt, false>>, Fortran::parser::ErrorRecovery> const&, Fortran::semantics::OmpAttributeVisitor&)::'lambda'(Fortran::semantics::OmpAttributeVisitor const&)&&, unsigned long, std::variant<Fortran::parser::ExecutableConstruct, Fortran::parser::Statement<Fortran::common::Indirection<Fortran::parser::FormatStmt, false>>, Fortran::parser::Statement<Fortran::common::Indirection<Fortran::parser::EntryStmt, false>>, Fortran::parser::Statement<Fortran::common::Indirection<Fortran::parser::DataStmt, false>>, Fortran::parser::Statement<Fortran::common::Indirection<Fortran::parser::NamelistStmt, false>>, Fortran::parser::ErrorRecovery> const&) (.isra.0) resolve-directives.cpp:0:0
#10 0x0000ffff8c4a4560 void Fortran::parser::ForEachInTuple<0ul, void Fortran::parser::Walk<Fortran::semantics::OmpAttributeVisitor, std::optional<Fortran::parser::Statement<Fortran::parser::ProgramStmt>>, Fortran::parser::SpecificationPart, Fortran::parser::ExecutionPart, std::optional<Fortran::parser::InternalSubprogramPart>, Fortran::parser::Statement<Fortran::parser::EndProgramStmt>>(std::tuple<std::optional<Fortran::parser::Statement<Fortran::parser::ProgramStmt>>, Fortran::parser::SpecificationPart, Fortran::parser::ExecutionPart, std::optional<Fortran::parser::InternalSubprogramPart>, Fortran::parser::Statement<Fortran::parser::EndProgramStmt>> const&, Fortran::semantics::OmpAttributeVisitor&)::'lambda'(Fortran::semantics::OmpAttributeVisitor const&), std::tuple<std::optional<Fortran::parser::Statement<Fortran::parser::ProgramStmt>>, Fortran::parser::SpecificationPart, Fortran::parser::ExecutionPart, std::optional<Fortran::parser::InternalSubprogramPart>, Fortran::parser::Statement<Fortran::parser::EndProgramStmt>>>(std::tuple<std::optional<Fortran::parser::Statement<Fortran::parser::ProgramStmt>>, Fortran::parser::SpecificationPart, Fortran::parser::ExecutionPart, std::optional<Fortran::parser::InternalSubprogramPart>, Fortran::parser::Statement<Fortran::parser::EndProgramStmt>> const&, void Fortran::parser::Walk<Fortran::semantics::OmpAttributeVisitor, std::optional<Fortran::parser::Statement<Fortran::parser::ProgramStmt>>, Fortran::parser::SpecificationPart, Fortran::parser::ExecutionPart, std::optional<Fortran::parser::InternalSubprogramPart>, Fortran::parser::Statement<Fortran::parser::EndProgramStmt>>(std::tuple<std::optional<Fortran::parser::Statement<Fortran::parser::ProgramStmt>>, Fortran::parser::SpecificationPart, Fortran::parser::ExecutionPart, std::optional<Fortran::parser::InternalSubprogramPart>, Fortran::parser::Statement<Fortran::parser::EndProgramStmt>> const&, Fortran::semantics::OmpAttributeVisitor&)::'lambda'(Fortran::semantics::OmpAttributeVisitor const&)) (/path/to/install/bin/../lib/../lib/libFortranSemantics.so.18git+0x4b4560)
#11 0x0000ffff8c4a51c0 Fortran::semantics::ResolveOmpParts(Fortran::semantics::SemanticsContext&, Fortran::parser::ProgramUnit const&) (/path/to/install/bin/../lib/../lib/libFortranSemantics.so.18git+0x4b51c0)
#12 0x0000ffff8c533940 Fortran::semantics::ResolveNamesVisitor::Pre(Fortran::parser::ProgramUnit const&) (.part.0) resolve-names.cpp:0:0
#13 0x0000ffff8c5349e8 Fortran::semantics::ResolveNames(Fortran::semantics::SemanticsContext&, Fortran::parser::Program const&, Fortran::semantics::Scope&) (/path/to/install/bin/../lib/../lib/libFortranSemantics.so.18git+0x5449e8)
#14 0x0000ffff8c5a7ac4 Fortran::semantics::Semantics::Perform() (/path/to/install/bin/../lib/../lib/libFortranSemantics.so.18git+0x5b7ac4)
#15 0x0000ffff911630d4 Fortran::frontend::FrontendAction::runSemanticChecks() (/path/to/install/bin/../lib/libflangFrontend.so.18git+0x530d4)
#16 0x0000ffff9122da20 Fortran::frontend::CodeGenAction::beginSourceFileAction() (/path/to/install/bin/../lib/libflangFrontend.so.18git+0x11da20)
#17 0x0000ffff91164bf0 Fortran::frontend::FrontendAction::beginSourceFile(Fortran::frontend::CompilerInstance&, Fortran::frontend::FrontendInputFile const&) (/path/to/install/bin/../lib/libflangFrontend.so.18git+0x54bf0)
#18 0x0000ffff91154350 Fortran::frontend::CompilerInstance::executeAction(Fortran::frontend::FrontendAction&) (/path/to/install/bin/../lib/libflangFrontend.so.18git+0x44350)
#19 0x0000ffff916b3bbc Fortran::frontend::executeCompilerInvocation(Fortran::frontend::CompilerInstance*) (/path/to/install/bin/../lib/libflangFrontendTool.so.18git+0x3bbc)
#20 0x00000000004048dc fc1_main(llvm::ArrayRef<char const*>, char const*) (/path/to/install/bin/flang-new+0x4048dc)
#21 0x0000000000403108 main (/path/to/install/bin/flang-new+0x403108)
#22 0x0000ffff8ff10d64 __libc_start_main (/lib64/libc.so.6+0x20d64)
#23 0x00000000004035d0 _start (/path/to/install/bin/flang-new+0x4035d0)
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 18.0.0 (https://github.com/llvm/llvm-project.git 701e6f7630474b637e0bc45d009bf2ec47f2d3fd)
Target: aarch64-unknown-linux-gnu
Thread model: posix
InstalledDir: /path/to/install/bin
flang-new: note: diagnostic msg:
********************
PLEASE ATTACH THE FOLLOWING FILES TO THE BUG REPORT:
Preprocessed source(s) and associated run script(s) are located at:
flang-new: note: diagnostic msg: /tmp/test-c4a7d8
flang-new: note: diagnostic msg: /tmp/test-c4a7d8.sh
flang-new: note: diagnostic msg:
********************
```
```console
$ gfortran -v test.f90 -fopenmp
Driving: gfortran -v test.f90 -fopenmp -l gfortran -l m -shared-libgcc
Using built-in specs.
COLLECT_GCC=gfortran
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/aarch64-redhat-linux/8/lto-wrapper
Target: aarch64-redhat-linux
Configured with: ../configure --enable-bootstrap --enable-languages=c,c++,fortran,lto --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-shared --enable-threads=posix --enable-checking=release --enable-multilib --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-gcc-major-version-only --with-linker-hash-style=gnu --enable-plugin --enable-initfini-array --with-isl --disable-libmpx --enable-gnu-indirect-function --build=aarch64-redhat-linux
Thread model: posix
gcc version 8.4.1 20200928 (Red Hat 8.4.1-1) (GCC)
:
$
```
This issue isn't reproduced if the program is not the main program but a subroutine subprogram.
```console
$ cat test_sub.f90
subroutine sub
!$omp critical
!$omp end critical
end
$ flang-new test_sub.f90 -c -fopenmp
$
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzsW19T27gW_zTm5Ywzjuw4yQMPaSBtZ9iFAXb3kZHlY0etLPlKcoD99HckO3-cQgqU3t6dTYdCLMnn_M5fndg61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