llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
29.27k stars 12.1k forks source link

[flang][OpenMP] assertion failure using default clause with critical #112572

Open tblah opened 1 month ago

tblah commented 1 month ago

Minimal reproducer:

INTEGER :: i
j=2
!$OMP PARALLEL default(private)
!$OMP critical(k2)
j=200
!$OMP END critical(k2)
!$OMP END PARALLEL
END 

flang -fopenmp file.f90

flang-20: warning: OpenMP support in flang is still experimental [-Wexperimental-option]
flang: llvm-project/flang/lib/Semantics/resolve-directives.cpp:783: Symbol *Fortran::semantics::DirectiveAttributeVisitor<llvm::omp::Directive>::DeclareNewPrivateAccessEntity(const Symbol &, Symbol::Flag, Scope &) [T = llvm::omp::Directive]: Assertion `object.owner() != currScope()' 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/bin/flang -fc1 -triple aarch64-unknown-linux-gnu -emit-obj -mrelocation-model pic -pic-level 2 -pic-is-pie -target-cpu generic -target-feature +outline-atomics -target-feature +v8a -target-feature +fp-armv8 -target-feature +neon -fopenmp -resource-dir path/lib/clang/20 -mframe-pointer=non-leaf -o /tmp/repo-017b14.o -x f95-cpp-input /tmp/repo.f90
 #0 0x0000be97fd554c40 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (path/bin/flang+0x2f54c40)
 #1 0x0000be97fd552abc llvm::sys::RunSignalHandlers() (path/bin/flang+0x2f52abc)
 #2 0x0000be97fd5554ac SignalHandler(int) Signals.cpp:0:0
 #3 0x0000ec1e70f3a8f8 (linux-vdso.so.1+0x8f8)
 #4 0x0000ec1e708c7628 (/lib/aarch64-linux-gnu/libc.so.6+0x87628)
 #5 0x0000ec1e7087cb3c raise (/lib/aarch64-linux-gnu/libc.so.6+0x3cb3c)
 #6 0x0000ec1e70867e00 abort (/lib/aarch64-linux-gnu/libc.so.6+0x27e00)
 #7 0x0000ec1e70875cbc (/lib/aarch64-linux-gnu/libc.so.6+0x35cbc)
 #8 0x0000ec1e70875d2c (/lib/aarch64-linux-gnu/libc.so.6+0x35d2c)
 #9 0x0000be97fe268bac Fortran::semantics::DirectiveAttributeVisitor<llvm::omp::Directive>::DeclareNewPrivateAccessEntity(Fortran::semantics::Symbol const&, Fortran::semantics::Symbol::Flag, Fortran::semantics::Scope&) (path/bin/flang+0x3c68bac)
#10 0x0000be97fe261448 Fortran::semantics::OmpAttributeVisitor::CreateImplicitSymbols(Fortran::semantics::Symbol const*, std::optional<Fortran::semantics::Symbol::Flag>) (path/bin/flang+0x3c61448)
#11 0x0000be97fe261954 Fortran::semantics::OmpAttributeVisitor::Post(Fortran::parser::Name const&) (path/flang+0x3c61954)
#12 0x0000be97fe2a0a78 void Fortran::parser::ForEachInTuple<0ul, void Fortran::parser::Walk<Fortran::semantics::OmpAttributeVisitor, Fortran::parser::OmpCriticalDirective, std::__cxx11::list<Fortran::parser::ExecutionPartConstruct, std::allocator<Fortran::parser::ExecutionPartConstruct>>, Fortran::parser::OmpEndCriticalDirective>(std::tuple<Fortran::parser::OmpCriticalDirective, std::__cxx11::list<Fortran::parser::ExecutionPartConstruct, std::allocator<Fortran::parser::ExecutionPartConstruct>>, Fortran::parser::OmpEndCriticalDirective> const&, Fortran::semantics::OmpAttributeVisitor&)::'lambda'(Fortran::semantics::OmpAttributeVisitor const&), std::tuple<Fortran::parser::OmpCriticalDirective, std::__cxx11::list<Fortran::parser::ExecutionPartConstruct, std::allocator<Fortran::parser::ExecutionPartConstruct>>, Fortran::parser::OmpEndCriticalDirective>>(std::tuple<Fortran::parser::OmpCriticalDirective, std::__cxx11::list<Fortran::parser::ExecutionPartConstruct, std::allocator<Fortran::parser::ExecutionPartConstruct>>, Fortran::parser::OmpEndCriticalDirective> const&, void Fortran::parser::Walk<Fortran::semantics::OmpAttributeVisitor, Fortran::parser::OmpCriticalDirective, std::__cxx11::list<Fortran::parser::ExecutionPartConstruct, std::allocator<Fortran::parser::ExecutionPartConstruct>>, Fortran::parser::OmpEndCriticalDirective>(std::tuple<Fortran::parser::OmpCriticalDirective, std::__cxx11::list<Fortran::parser::ExecutionPartConstruct, std::allocator<Fortran::parser::ExecutionPartConstruct>>, Fortran::parser::OmpEndCriticalDirective> const&, Fortran::semantics::OmpAttributeVisitor&)::'lambda'(Fortran::semantics::OmpAttributeVisitor const&)) (/home/tomecl01/build/release-assertions/bin/flang+0x3ca0a78)
#13 0x0000be97fe29fb44 void Fortran::common::log2visit::Log2VisitHelper<5ul, 9ul, void, void 
[...]
flang-20: error: unable to execute command: Aborted (core dumped)
flang-20: error: flang frontend command failed due to signal (use -v to see invocation)
flang version 20.0.0git (git@github.com:llvm/llvm-project.git 7ec32094933bbf0201ea0670209c090a00bf8d83)
Target: aarch64-unknown-linux-gnu

The reproducer is simplified from these test cases:

llvmbot commented 1 month ago

@llvm/issue-subscribers-flang-frontend

Author: Tom Eccles (tblah)

Minimal reproducer: ``` INTEGER :: i j=2 !$OMP PARALLEL default(private) !$OMP critical(k2) j=200 !$OMP END critical(k2) !$OMP END PARALLEL END ``` `flang -fopenmp file.f90` ``` flang-20: warning: OpenMP support in flang is still experimental [-Wexperimental-option] flang: llvm-project/flang/lib/Semantics/resolve-directives.cpp:783: Symbol *Fortran::semantics::DirectiveAttributeVisitor<llvm::omp::Directive>::DeclareNewPrivateAccessEntity(const Symbol &, Symbol::Flag, Scope &) [T = llvm::omp::Directive]: Assertion `object.owner() != currScope()' 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/bin/flang -fc1 -triple aarch64-unknown-linux-gnu -emit-obj -mrelocation-model pic -pic-level 2 -pic-is-pie -target-cpu generic -target-feature +outline-atomics -target-feature +v8a -target-feature +fp-armv8 -target-feature +neon -fopenmp -resource-dir path/lib/clang/20 -mframe-pointer=non-leaf -o /tmp/repo-017b14.o -x f95-cpp-input /tmp/repo.f90 #0 0x0000be97fd554c40 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (path/bin/flang+0x2f54c40) #1 0x0000be97fd552abc llvm::sys::RunSignalHandlers() (path/bin/flang+0x2f52abc) #2 0x0000be97fd5554ac SignalHandler(int) Signals.cpp:0:0 #3 0x0000ec1e70f3a8f8 (linux-vdso.so.1+0x8f8) #4 0x0000ec1e708c7628 (/lib/aarch64-linux-gnu/libc.so.6+0x87628) #5 0x0000ec1e7087cb3c raise (/lib/aarch64-linux-gnu/libc.so.6+0x3cb3c) #6 0x0000ec1e70867e00 abort (/lib/aarch64-linux-gnu/libc.so.6+0x27e00) #7 0x0000ec1e70875cbc (/lib/aarch64-linux-gnu/libc.so.6+0x35cbc) #8 0x0000ec1e70875d2c (/lib/aarch64-linux-gnu/libc.so.6+0x35d2c) #9 0x0000be97fe268bac Fortran::semantics::DirectiveAttributeVisitor<llvm::omp::Directive>::DeclareNewPrivateAccessEntity(Fortran::semantics::Symbol const&, Fortran::semantics::Symbol::Flag, Fortran::semantics::Scope&) (path/bin/flang+0x3c68bac) #10 0x0000be97fe261448 Fortran::semantics::OmpAttributeVisitor::CreateImplicitSymbols(Fortran::semantics::Symbol const*, std::optional<Fortran::semantics::Symbol::Flag>) (path/bin/flang+0x3c61448) #11 0x0000be97fe261954 Fortran::semantics::OmpAttributeVisitor::Post(Fortran::parser::Name const&) (path/flang+0x3c61954) #12 0x0000be97fe2a0a78 void Fortran::parser::ForEachInTuple<0ul, void Fortran::parser::Walk<Fortran::semantics::OmpAttributeVisitor, Fortran::parser::OmpCriticalDirective, std::__cxx11::list<Fortran::parser::ExecutionPartConstruct, std::allocator<Fortran::parser::ExecutionPartConstruct>>, Fortran::parser::OmpEndCriticalDirective>(std::tuple<Fortran::parser::OmpCriticalDirective, std::__cxx11::list<Fortran::parser::ExecutionPartConstruct, std::allocator<Fortran::parser::ExecutionPartConstruct>>, Fortran::parser::OmpEndCriticalDirective> const&, Fortran::semantics::OmpAttributeVisitor&)::'lambda'(Fortran::semantics::OmpAttributeVisitor const&), std::tuple<Fortran::parser::OmpCriticalDirective, std::__cxx11::list<Fortran::parser::ExecutionPartConstruct, std::allocator<Fortran::parser::ExecutionPartConstruct>>, Fortran::parser::OmpEndCriticalDirective>>(std::tuple<Fortran::parser::OmpCriticalDirective, std::__cxx11::list<Fortran::parser::ExecutionPartConstruct, std::allocator<Fortran::parser::ExecutionPartConstruct>>, Fortran::parser::OmpEndCriticalDirective> const&, void Fortran::parser::Walk<Fortran::semantics::OmpAttributeVisitor, Fortran::parser::OmpCriticalDirective, std::__cxx11::list<Fortran::parser::ExecutionPartConstruct, std::allocator<Fortran::parser::ExecutionPartConstruct>>, Fortran::parser::OmpEndCriticalDirective>(std::tuple<Fortran::parser::OmpCriticalDirective, std::__cxx11::list<Fortran::parser::ExecutionPartConstruct, std::allocator<Fortran::parser::ExecutionPartConstruct>>, Fortran::parser::OmpEndCriticalDirective> const&, Fortran::semantics::OmpAttributeVisitor&)::'lambda'(Fortran::semantics::OmpAttributeVisitor const&)) (/home/tomecl01/build/release-assertions/bin/flang+0x3ca0a78) #13 0x0000be97fe29fb44 void Fortran::common::log2visit::Log2VisitHelper<5ul, 9ul, void, void [...] flang-20: error: unable to execute command: Aborted (core dumped) flang-20: error: flang frontend command failed due to signal (use -v to see invocation) flang version 20.0.0git (git@github.com:llvm/llvm-project.git 7ec32094933bbf0201ea0670209c090a00bf8d83) Target: aarch64-unknown-linux-gnu ```
luporl commented 1 month ago

Interesting, so there are legitimate cases where the privatized symbol is at the same scope as the original one.

An easy fix here would be to replace DeclareNewPrivateAccessEntity with DeclarePrivateAccessEntity, in makePrivateSymbol lambda, in flang/lib/Semantics/resolve-directives.cpp, as well as removing const from the symbol variables used in it.

luporl commented 1 month ago

Actually, replacing DeclareNewPrivateAccessEntity with DeclarePrivateAccessEntity didn't fix the issue, but an assert is hit in lowering instead:

Assertion failed: (hsb && "Host symbol box not found"), function doPrivatize, file DataSharingProcessor.cpp, line 455.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0.  Program arguments: /Users/leandro.lupori/home/git/flang-luporl/buildr/bin/flang-new -fc1 -triple arm64-apple-macosx14.0.0 -emit-obj -fcolor-diagnostics -mrelocation-model pic -pic-level 2 -target-cpu apple-m1 -target-feature +zcm -target-feature +zcz -target-feature +v8.4a -target-feature +aes -target-feature +altnzcv -target-feature +ccdp -target-feature +complxnum -target-feature +crc -target-feature +dotprod -target-feature +fp-armv8 -target-feature +fp16fml -target-feature +fptoint -target-feature +fullfp16 -target-feature +jsconv -target-feature +lse -target-feature +neon -target-feature +pauth -target-feature +perfmon -target-feature +predres -target-feature +ras -target-feature +rcpc -target-feature +rdm -target-feature +sb -target-feature +sha2 -target-feature +sha3 -target-feature +specrestrict -target-feature +ssbs -fopenmp -resource-dir /Users/leandro.lupori/home/git/flang-luporl/buildr/lib/clang/20 -mframe-pointer=non-leaf -o ftest.o -x f95-cpp-input ftest.f90
 #0 0x000000010073f994 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/Users/leandro.lupori/home/git/flang-luporl/buildr/bin/flang-new+0x1003e3994)
 #1 0x000000010073da18 llvm::sys::RunSignalHandlers() (/Users/leandro.lupori/home/git/flang-luporl/buildr/bin/flang-new+0x1003e1a18)
 #2 0x0000000100740050 SignalHandler(int) (/Users/leandro.lupori/home/git/flang-luporl/buildr/bin/flang-new+0x1003e4050)
 #3 0x0000000185666584 (/usr/lib/system/libsystem_platform.dylib+0x18047a584)
 #4 0x0000000185635c20 (/usr/lib/system/libsystem_pthread.dylib+0x180449c20)
 #5 0x0000000185542a30 (/usr/lib/system/libsystem_c.dylib+0x180356a30)
 #6 0x0000000185541d20 (/usr/lib/system/libsystem_c.dylib+0x180355d20)
 #7 0x000000010539b12c Fortran::lower::omp::DataSharingProcessor::doPrivatize(Fortran::semantics::Symbol const*, mlir::omp::PrivateClauseOps*) (.cold.3) (/Users/leandro.lupori/home/git/flang-luporl/buildr/bin/flang-new+0x10503f12c)
 #8 0x0000000101213ee8 Fortran::lower::omp::DataSharingProcessor::doPrivatize(Fortran::semantics::Symbol const*, mlir::omp::PrivateClauseOps*) (/Users/leandro.lupori/home/git/flang-luporl/buildr/bin/flang-new+0x100eb7ee8)
 #9 0x00000001012104a8 Fortran::lower::omp::DataSharingProcessor::processStep1(mlir::omp::PrivateClauseOps*) (/Users/leandro.lupori/home/git/flang-luporl/buildr/bin/flang-new+0x100eb44a8)
#10 0x00000001012483fc genOMPDispatch(Fortran::lower::AbstractConverter&, Fortran::lower::SymMap&, Fortran::semantics::SemanticsContext&, Fortran::lower::pft::Evaluation&, mlir::Location, llvm::SmallVector<tomp::DirectiveWithClauses<Fortran::lower::omp::Clause>, 0u> const&, tomp::DirectiveWithClauses<Fortran::lower::omp::Clause> const*) (/Users/leandro.lupori/home/git/flang-luporl/buildr/bin/flang-new+0x100eec3fc)
[...]

This will require further investigation.