<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/112572>112572</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[flang][OpenMP] assertion failure using default clause with critical
</td>
</tr>
<tr>
<th>Labels</th>
<td>
crash-on-valid,
flang:openmp
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
tblah
</td>
</tr>
</table>
<pre>
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
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzsWE9v2zoS_zT0hZBBUZIlHXxwYntfgf4JmmDfsaCokc2GIgWSctJvvyAlO5brJpt32cMGaBFrOPOb_9RomLVipwCWKLtB2XrGerfXZukqyfazSte_ll-EEi2T2EBndN1zMChZIbJGZIUWZPwXHj99fdj8a_Md-_NkhcVA_YmSNR35aYxo-u3LHb5bfV99_rz5jGtoWC8dokVnxIE5QLS8ZOZGOMGZRLR4pKfzgEvIJfPm6_oPAlOeowXDmadc9QktSCOZ2uGo0R2otsONkDBvyjOWa3JBKKLEB-KJGSXUzv_81oH6codt33XaOCwUHtCFxdYJKTE8d2BEC8oxiVF2E_19Tol054RWKFufafG4Uh7aqDP6J3CH6Hag060UFaLbe2iZcoJbRLcGrJYHiGphgDtxADvnXYeSVV4kHuj-V1tpiRFdbbVxhqkhmfYEER7XR-mVc0ZUvYN_CyucNii59aYMXLrtLthRshkpwCUz8BWe7oa0rzgHazfKC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