Issue 204299
Summary [Flang][OpenMP] ICE with user-defined operators specified in declare reduction directives
Labels flang:ir, crash-on-valid, flang:openmp
Assignees
Reporter yus3710-fj
    ## Summary

This issue looks similar to #188880, but the root cause might be different. Compilation abnormally terminates when user-defined operators are specified in `declare reduction` directives.

* 7.6.1 OpenMP Reduction and Induction Identifiers

> A reduction identifier is either a base language identifier, a user-defined operator, an allowed intrinsic procedure name or one of the following operators: `+`, `*`, `.and.`, `.or.`, `.eqv.` or `.neqv.`. The intrinsic procedure names that are allowed as reduction identifiers are `max`, `min`, `iand`, `ior` and `ieor`.

### Reproducer

* test.f90

```fortran
interface operator(.zzzz.)
 function zzzz_op(a)
    integer, intent(in) :: a
    integer :: zzzz_op
 end function zzzz_op
end interface

!$omp declare reduction(.zzzz.:integer:omp_out=omp_in) initializer(omp_priv=0)
integer::x
!$omp parallel reduction(.zzzz.:x)
!$omp end parallel
end
```

* commands

```console
$ flang --version
flang version 23.0.0git (https://github.com/llvm/llvm-project.git e84e480bb5a53c794f303683df6460ddb44bb7ac)
Target: aarch64-unknown-linux-gnu
Thread model: posix
InstalledDir: /path/to/llvm/build/bin
Build config: +assertions
$ flang test.f90 -fopenmp && ./a.out
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace and instructions to reproduce the bug.
Stack dump:
0.      Program arguments: /path/to/llvm/build/bin/flang -fc1 -triple aarch64-unknown-linux-gnu -emit-obj -fcolor-diagnostics -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/to/llvm/build/lib/clang/23 -fintrinsic-modules-path /path/to/llvm/build/lib/clang/23/finclude/flang/aarch64-unknown-linux-gnu -mframe-pointer=non-leaf-no-reserve -o /tmp/test-af0f56.o -x f95 test.f90
 #0 0x0000ffffa986ff30 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/path/to/llvm/build/bin/../lib/libLLVM.so.23.0git+0x87ff30)
 #1 0x0000ffffa986d3e0 SignalHandler(int, siginfo_t*, void*) Signals.cpp:0:0
 #2 0x0000ffffbbaf47f0 (linux-vdso.so.1+0x7f0)
 #3 0x0000ffffa8b4c320 __pthread_kill_implementation /usr/src/debug/glibc-2.39-124.el10_2.aarch64/nptl/pthread_kill.c:44:76
 #4 0x0000ffffa8afada0 gsignal /usr/src/debug/glibc-2.39-124.el10_2.aarch64/signal/../sysdeps/posix/raise.c:27:6
 #5 0x0000ffffa8ae5a08 abort /usr/src/debug/glibc-2.39-124.el10_2.aarch64/stdlib/abort.c:81:7
 #6 0x0000000000802e8c Fortran::evaluate::Constant<Fortran::evaluate::Type<(Fortran::common::TypeCategory)1, 1>>::GetScalarValue() const (.part.0) ConvertConstant.cpp:0:0
 #7 0x0000000000be4b5c bool Fortran::lower::omp::ReductionProcessor::processReductionArguments<mlir::omp::DeclareReductionOp, llvm::SmallVector<tomp::type::ReductionIdentifierT<Fortran::lower::omp::IdTyTemplate<Fortran::evaluate::Expr<Fortran::evaluate::SomeType>>, Fortran::evaluate::Expr<Fortran::evaluate::SomeType>>, 0u>>(mlir::Location, Fortran::lower::AbstractConverter&, llvm::SmallVector<tomp::type::ReductionIdentifierT<Fortran::lower::omp::IdTyTemplate<Fortran::evaluate::Expr<Fortran::evaluate::SomeType>>, Fortran::evaluate::Expr<Fortran::evaluate::SomeType>>, 0u> const&, llvm::SmallVectorImpl<mlir::Value>&, llvm::SmallVectorImpl<bool>&, llvm::SmallVectorImpl<mlir::Attribute>&, llvm::SmallVectorImpl<Fortran::semantics::Symbol const*> const&, llvm::DenseMap<Fortran::semantics::Symbol const*, mlir::Value, llvm::DenseMapInfo<Fortran::semantics::Symbol const*, void>, llvm::detail::DenseMapPair<Fortran::semantics::Symbol const*, mlir::Value>>*) (/path/to/llvm/build/bin/flang+0xbe4b5c)
 #8 0x0000000000e50d80 Fortran::lower::omp::ClauseProcessor::processReduction(mlir::Location, mlir::omp::ReductionClauseOps&, llvm::SmallVectorImpl<tomp::type::ObjectT<Fortran::lower::omp::IdTyTemplate<Fortran::evaluate::Expr<Fortran::evaluate::SomeType>>, Fortran::evaluate::Expr<Fortran::evaluate::SomeType>>>&, llvm::DenseMap<Fortran::semantics::Symbol const*, mlir::Value, llvm::DenseMapInfo<Fortran::semantics::Symbol const*, void>, llvm::detail::DenseMapPair<Fortran::semantics::Symbol const*, mlir::Value>>*) const::'lambda'(tomp::clause::ReductionT<Fortran::evaluate::DynamicType, Fortran::lower::omp::IdTyTemplate<Fortran::evaluate::Expr<Fortran::evaluate::SomeType>>, Fortran::evaluate::Expr<Fortran::evaluate::SomeType>> const&, Fortran::parser::CharBlock const&)::operator()(tomp::clause::ReductionT<Fortran::evaluate::DynamicType, Fortran::lower::omp::IdTyTemplate<Fortran::evaluate::Expr<Fortran::evaluate::SomeType>>, Fortran::evaluate::Expr<Fortran::evaluate::SomeType>> const&, Fortran::parser::CharBlock const&) const (.isra.0) ClauseProcessor.cpp:0:0
 #9 0x0000000000e4659c bool Fortran::lower::omp::ClauseProcessor::findRepeatableClause<tomp::clause::ReductionT<Fortran::evaluate::DynamicType, Fortran::lower::omp::IdTyTemplate<Fortran::evaluate::Expr<Fortran::evaluate::SomeType>>, Fortran::evaluate::Expr<Fortran::evaluate::SomeType>>>(std::function<void (tomp::clause::ReductionT<Fortran::evaluate::DynamicType, Fortran::lower::omp::IdTyTemplate<Fortran::evaluate::Expr<Fortran::evaluate::SomeType>>, Fortran::evaluate::Expr<Fortran::evaluate::SomeType>> const&, Fortran::parser::CharBlock const&)>) const (/path/to/llvm/build/bin/flang+0xe4659c)
#10 0x0000000000e46630 Fortran::lower::omp::ClauseProcessor::processReduction(mlir::Location, mlir::omp::ReductionClauseOps&, llvm::SmallVectorImpl<tomp::type::ObjectT<Fortran::lower::omp::IdTyTemplate<Fortran::evaluate::Expr<Fortran::evaluate::SomeType>>, Fortran::evaluate::Expr<Fortran::evaluate::SomeType>>>&, llvm::DenseMap<Fortran::semantics::Symbol const*, mlir::Value, llvm::DenseMapInfo<Fortran::semantics::Symbol const*, void>, llvm::detail::DenseMapPair<Fortran::semantics::Symbol const*, mlir::Value>>*) const (/path/to/llvm/build/bin/flang+0xe46630)
#11 0x0000000000b4105c genParallelClauses(Fortran::lower::AbstractConverter&, Fortran::semantics::SemanticsContext&, Fortran::lower::StatementContext&, llvm::SmallVector<Fortran::lower::omp::Clause, 0u> const&, mlir::Location, mlir::omp::detail::Clauses<mlir::omp::AllocateClauseOps, mlir::omp::IfClauseOps, mlir::omp::NumThreadsClauseOps, mlir::omp::PrivateClauseOps, mlir::omp::ProcBindClauseOps, mlir::omp::ReductionClauseOps>&, llvm::SmallVectorImpl<tomp::type::ObjectT<Fortran::lower::omp::IdTyTemplate<Fortran::evaluate::Expr<Fortran::evaluate::SomeType>>, Fortran::evaluate::Expr<Fortran::evaluate::SomeType>>>&) (.constprop.0) OpenMP.cpp:0:0
#12 0x0000000000b71c44 genStandaloneParallel(Fortran::lower::AbstractConverter&, Fortran::lower::SymMap&, Fortran::lower::StatementContext&, 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*) OpenMP.cpp:0:0
#13 0x0000000000b6efec 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*) OpenMP.cpp:0:0
#14 0x0000000000b7e2d4 Fortran::lower::genOpenMPConstruct(Fortran::lower::AbstractConverter&, Fortran::lower::SymMap&, Fortran::semantics::SemanticsContext&, Fortran::lower::pft::Evaluation&, Fortran::parser::OpenMPConstruct const&) (/path/to/llvm/build/bin/flang+0xb7e2d4)
#15 0x000000000096e7d4 void Fortran::common::log2visit::Log2VisitHelper<47ul, 92ul, void, Fortran::common::visitors<auto Fortran::lower::pft::ReferenceVariantBase<true, Fortran::parser::AllocateStmt, Fortran::parser::AssignmentStmt, Fortran::parser::BackspaceStmt, Fortran::parser::CallStmt, Fortran::parser::CloseStmt, Fortran::parser::ContinueStmt, Fortran::parser::CycleStmt, Fortran::parser::DeallocateStmt, Fortran::parser::EndfileStmt, Fortran::parser::EventPostStmt, Fortran::parser::EventWaitStmt, Fortran::parser::ExitStmt, Fortran::parser::FailImageStmt, Fortran::parser::FlushStmt, Fortran::parser::FormTeamStmt, Fortran::parser::GotoStmt, Fortran::parser::IfStmt, Fortran::parser::InquireStmt, Fortran::parser::LockStmt, Fortran::parser::NotifyWaitStmt, Fortran::parser::NullifyStmt, Fortran::parser::OpenStmt, Fortran::parser::PointerAssignmentStmt, Fortran::parser::PrintStmt, Fortran::parser::ReadStmt, Fortran::parser::ReturnStmt, Fortran::parser::RewindStmt, Fortran::parser::StopStmt, Fortran::parser::SyncAllStmt, Fortran::parser::SyncImagesStmt, Fortran::parser::SyncMemoryStmt, Fortran::parser::SyncTeamStmt, Fortran::parser::UnlockStmt, Fortran::parser::WaitStmt, Fortran::parser::WhereStmt, Fortran::parser::WriteStmt, Fortran::parser::ComputedGotoStmt, Fortran::parser::ForallStmt, Fortran::parser::ArithmeticIfStmt, Fortran::parser::AssignStmt, Fortran::parser::AssignedGotoStmt, Fortran::parser::PauseStmt, Fortran::parser::EntryStmt, Fortran::parser::FormatStmt, Fortran::parser::AssociateStmt, Fortran::parser::EndAssociateStmt, Fortran::parser::BlockStmt, Fortran::parser::EndBlockStmt, Fortran::parser::SelectCaseStmt, Fortran::parser::CaseStmt, Fortran::parser::EndSelectStmt, Fortran::parser::ChangeTeamStmt, Fortran::parser::EndChangeTeamStmt, Fortran::parser::CriticalStmt, Fortran::parser::EndCriticalStmt, Fortran::parser::NonLabelDoStmt, Fortran::parser::EndDoStmt, Fortran::parser::IfThenStmt, Fortran::parser::ElseIfStmt, Fortran::parser::ElseStmt, Fortran::parser::EndIfStmt, Fortran::parser::SelectRankStmt, Fortran::parser::SelectRankCaseStmt, Fortran::parser::SelectTypeStmt, Fortran::parser::TypeGuardStmt, Fortran::parser::WhereConstructStmt, Fortran::parser::MaskedElsewhereStmt, Fortran::parser::ElsewhereStmt, Fortran::parser::EndWhereStmt, Fortran::parser::ForallConstructStmt, Fortran::parser::EndForallStmt, Fortran::parser::EndProgramStmt, Fortran::parser::EndFunctionStmt, Fortran::parser::EndSubroutineStmt, Fortran::parser::EndMpSubprogramStmt, Fortran::parser::AssociateConstruct, Fortran::parser::BlockConstruct, Fortran::parser::CaseConstruct, Fortran::parser::ChangeTeamConstruct, Fortran::parser::CriticalConstruct, Fortran::parser::DoConstruct, Fortran::parser::IfConstruct, Fortran::parser::SelectRankConstruct, Fortran::parser::SelectTypeConstruct, Fortran::parser::WhereConstruct, Fortran::parser::ForallConstruct, Fortran::parser::CompilerDirective, Fortran::parser::OpenACCConstruct, Fortran::parser::OpenACCRoutineConstruct, Fortran::parser::OpenACCDeclarativeConstruct, Fortran::parser::OpenMPConstruct, Fortran::parser::OpenMPDeclarativeConstruct, Fortran::parser::CUFKernelDoConstruct>::visit<(anonymous namespace)::FirConverter::genFIR(Fortran::lower::pft::Evaluation&, bool)::'lambda'(auto const&)>(auto&&) const::'lambda'(auto)>, std::variant<Fortran::common::Reference<Fortran::parser::AllocateStmt const>, Fortran::common::Reference<Fortran::parser::AssignmentStmt const>, Fortran::common::Reference<Fortran::parser::BackspaceStmt const>, Fortran::common::Reference<Fortran::parser::CallStmt const>, Fortran::common::Reference<Fortran::parser::CloseStmt const>, Fortran::common::Reference<Fortran::parser::ContinueStmt const>, Fortran::common::Reference<Fortran::parser::CycleStmt const>, Fortran::common::Reference<Fortran::parser::DeallocateStmt const>, Fortran::common::Reference<Fortran::parser::EndfileStmt const>, Fortran::common::Reference<Fortran::parser::EventPostStmt const>, Fortran::common::Reference<Fortran::parser::EventWaitStmt const>, Fortran::common::Reference<Fortran::parser::ExitStmt const>, Fortran::common::Reference<Fortran::parser::FailImageStmt const>, Fortran::common::Reference<Fortran::parser::FlushStmt const>, Fortran::common::Reference<Fortran::parser::FormTeamStmt const>, Fortran::common::Reference<Fortran::parser::GotoStmt const>, Fortran::common::Reference<Fortran::parser::IfStmt const>, Fortran::common::Reference<Fortran::parser::InquireStmt const>, Fortran::common::Reference<Fortran::parser::LockStmt const>, Fortran::common::Reference<Fortran::parser::NotifyWaitStmt const>, Fortran::common::Reference<Fortran::parser::NullifyStmt const>, Fortran::common::Reference<Fortran::parser::OpenStmt const>, Fortran::common::Reference<Fortran::parser::PointerAssignmentStmt const>, Fortran::common::Reference<Fortran::parser::PrintStmt const>, Fortran::common::Reference<Fortran::parser::ReadStmt const>, Fortran::common::Reference<Fortran::parser::ReturnStmt const>, Fortran::common::Reference<Fortran::parser::RewindStmt const>, Fortran::common::Reference<Fortran::parser::StopStmt const>, Fortran::common::Reference<Fortran::parser::SyncAllStmt const>, Fortran::common::Reference<Fortran::parser::SyncImagesStmt const>, Fortran::common::Reference<Fortran::parser::SyncMemoryStmt const>, Fortran::common::Reference<Fortran::parser::SyncTeamStmt const>, Fortran::common::Reference<Fortran::parser::UnlockStmt const>, Fortran::common::Reference<Fortran::parser::WaitStmt const>, Fortran::common::Reference<Fortran::parser::WhereStmt const>, Fortran::common::Reference<Fortran::parser::WriteStmt const>, Fortran::common::Reference<Fortran::parser::ComputedGotoStmt const>, Fortran::common::Reference<Fortran::parser::ForallStmt const>, Fortran::common::Reference<Fortran::parser::ArithmeticIfStmt const>, Fortran::common::Reference<Fortran::parser::AssignStmt const>, Fortran::common::Reference<Fortran::parser::AssignedGotoStmt const>, Fortran::common::Reference<Fortran::parser::PauseStmt const>, Fortran::common::Reference<Fortran::parser::EntryStmt const>, Fortran::common::Reference<Fortran::parser::FormatStmt const>, Fortran::common::Reference<Fortran::parser::AssociateStmt const>, Fortran::common::Reference<Fortran::parser::EndAssociateStmt const>, Fortran::common::Reference<Fortran::parser::BlockStmt const>, Fortran::common::Reference<Fortran::parser::EndBlockStmt const>, Fortran::common::Reference<Fortran::parser::SelectCaseStmt const>, Fortran::common::Reference<Fortran::parser::CaseStmt const>, Fortran::common::Reference<Fortran::parser::EndSelectStmt const>, Fortran::common::Reference<Fortran::parser::ChangeTeamStmt const>, Fortran::common::Reference<Fortran::parser::EndChangeTeamStmt const>, Fortran::common::Reference<Fortran::parser::CriticalStmt const>, Fortran::common::Reference<Fortran::parser::EndCriticalStmt const>, Fortran::common::Reference<Fortran::parser::NonLabelDoStmt const>, Fortran::common::Reference<Fortran::parser::EndDoStmt const>, Fortran::common::Reference<Fortran::parser::IfThenStmt const>, Fortran::common::Reference<Fortran::parser::ElseIfStmt const>, Fortran::common::Reference<Fortran::parser::ElseStmt const>, Fortran::common::Reference<Fortran::parser::EndIfStmt const>, Fortran::common::Reference<Fortran::parser::SelectRankStmt const>, Fortran::common::Reference<Fortran::parser::SelectRankCaseStmt const>, Fortran::common::Reference<Fortran::parser::SelectTypeStmt co<truncated>Please see the issue for the entire body.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to