[Flang][OpenMP] Error of the conditional compilation with an empty statement
This is an issue from Fujitsu testsuite.
Flang-new terminates abnormally when compiling the conditional compilation sentinel with an empty statement.
According to the document of OpenMP 5.0, the sentinel should be replaced by two spaces in this case.
The following are the test program, Flang-new and gfortran compilation result.
! test.f90
!$
print *,'pass'
end
$ flang-new -v -fopenmp test.f90
flang-new version 17.0.0 (https://github.com/llvm/llvm-project.git 289828b1c0a6bc6eed8a634376a5152adae2283b)
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-03cb8d.o -x f95-cpp-input test.f90
/path/to/gcc/11.2.0/include/c++/11.2.0/bits/stl_vector.h:1063: std::vector<_Tp, _Alloc>::const_reference std::vector<_Tp, _Alloc>::operator[](std::vector<_Tp, _Alloc>::size_type) const [with _Tp = char; _Alloc = std::allocator<char>; std::vector<_Tp, _Alloc>::const_reference = const char&; std::vector<_Tp, _Alloc>::size_type = long unsigned int]: Assertion '__n < this->size()' failed.
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-03cb8d.o -x f95-cpp-input test.f90
#0 0x0000ffff977afc70 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/path/to/install/bin/../lib/libLLVMSupport.so.17git+0x19fc70)
#1 0x0000ffff977add50 llvm::sys::RunSignalHandlers() (/path/to/install/bin/../lib/libLLVMSupport.so.17git+0x19dd50)
#2 0x0000ffff977adec0 SignalHandler(int) Signals.cpp:0:0
#3 0x0000ffff991f066c (linux-vdso.so.1+0x66c)
#4 0x0000ffff97192dbc raise (/lib64/libc.so.6+0x32dbc)
#5 0x0000ffff97180928 abort (/lib64/libc.so.6+0x20928)
#6 0x0000ffff928648c0 std::__detail::__variant::__gen_vtable_impl<std::__detail::__variant::_Multi_array<std::__detail::__variant::__variant_idx_cookie (*)(std::__detail::__variant::_Move_assign_base<false, Fortran::parser::NullInit, Fortran::parser::Name>::operator=(std::__detail::__variant::_Move_assign_base<false, Fortran::parser::NullInit, Fortran::parser::Name>&&)::'lambda'(auto&&, auto)&&, std::variant<Fortran::parser::NullInit, Fortran::parser::Name>&)>, std::integer_sequence<unsigned long, 0ul>>::__visit_invoke(std::__detail::__variant::_Move_assign_base<false, Fortran::parser::NullInit, Fortran::parser::Name>::operator=(std::__detail::__variant::_Move_assign_base<false, Fortran::parser::NullInit, Fortran::parser::Name>&&)::'lambda'(auto&&, auto)&&, std::variant<Fortran::parser::NullInit, Fortran::parser::Name>&) (/path/to/install/bin/../lib/../lib/libFortranParser.so.17git+0x848c0)
#7 0x0000ffff92a2d1ec Fortran::parser::Prescanner::Statement() (/path/to/install/bin/../lib/../lib/libFortranParser.so.17git+0x24d1ec)
#8 0x0000ffff92a2b9d0 Fortran::parser::Prescanner::Prescan(Fortran::common::Interval<Fortran::parser::Provenance>) (/path/to/install/bin/../lib/../lib/libFortranParser.so.17git+0x24b9d0)
#9 0x0000ffff92a17458 Fortran::parser::Parsing::Prescan(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&, Fortran::parser::Options) (/path/to/install/bin/../lib/../lib/libFortranParser.so.17git+0x237458)
#10 0x0000ffff9839126c Fortran::frontend::FrontendAction::runPrescan() (/path/to/install/bin/../lib/libflangFrontend.so.17git+0x5126c)
#11 0x0000ffff9845699c Fortran::frontend::CodeGenAction::beginSourceFileAction() (/path/to/install/bin/../lib/libflangFrontend.so.17git+0x11699c)
#12 0x0000ffff98392150 Fortran::frontend::FrontendAction::beginSourceFile(Fortran::frontend::CompilerInstance&, Fortran::frontend::FrontendInputFile const&) (/path/to/install/bin/../lib/libflangFrontend.so.17git+0x52150)
#13 0x0000ffff98383310 Fortran::frontend::CompilerInstance::executeAction(Fortran::frontend::FrontendAction&) (/path/to/install/bin/../lib/libflangFrontend.so.17git+0x43310)
#14 0x0000ffff988c30a8 Fortran::frontend::executeCompilerInvocation(Fortran::frontend::CompilerInstance*) (/path/to/install/bin/../lib/libflangFrontendTool.so.17git+0x30a8)
#15 0x0000000000406170 fc1_main(llvm::ArrayRef<char const*>, char const*) (/path/to/install/bin/flang-new+0x406170)
#16 0x0000000000403524 main (/path/to/install/bin/flang-new+0x403524)
#17 0x0000ffff97180d64 __libc_start_main (/lib64/libc.so.6+0x20d64)
#18 0x00000000004039c0 _start (/path/to/install/bin/flang-new+0x4039c0)
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)
Fujitsu flang-new version 17.0.0 (https://github.com/llvm/llvm-project.git 289828b1c0a6bc6eed8a634376a5152adae2283b)
Target: aarch64-unknown-linux-gnu
Thread model: posix
InstalledDir: /path/to/install/bin
flang-new: error: unable to execute command: Aborted (core dumped)
flang-new: note: diagnostic msg: Error generating preprocessed source(s).
$ gfortran -v -fopenmp test.f90
Driving: gfortran -v -fopenmp test.f90 -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.3.1 20190507 (Red Hat 8.3.1-4) (GCC)
:
$
@llvm/issue-subscribers-openmp
@llvm/issue-subscribers-flang-frontend
I am unable to reproduce this crash using current LLVM sources built with gcc 11.2.0.
Though the version of gcc was different, I couldn't reproduce this crash in another machine. Perhaps I made a mistake when I built gcc 11.2.0.
Thank you for checking this issue.