Skip to content

[Flang][OpenMP] Compilation abnormally terminates when a variable declared in equivalence statement is defined in common statement, and the common-block-name is specified in threadprivate directive and copyprivate clause #122825

@ohno-fj

Description

@ohno-fj
Version of flang : 20.0.0(f4230b4332262dffb0bd3b7a2f8d6deb2e96488e)/AArch64

When a variable declared in equivalence statement is defined in common statement, and the common-block-name is specified in threadprivate directive and copyprivate clause, a compilation terminates abnormally.

The following are the test program, Flang, Gfortran and ifx compilation/execution result.

snggx596_.f90:

subroutine s1
equivalence (k(2),kk)
      common /com1/ k(2)
!$omp threadprivate(/com1/)

!$omp parallel
k=0
!$omp single
k(1)=1
kk=2
!$omp end single copyprivate(/com1/)
if (any(k/=[1,2])) print *,1011,k
if (   (kk/=2)) print *,1012,kk
!$omp end parallel
end
call s1
print *,'pass'
end
$ flang -fopenmp snggx596_.f90
flang-20: warning: OpenMP support in flang is still experimental [-Wexperimental-option]
flang: /work/groups/ssoft/compiler/llvm/src/llvm-main/llvm/include/llvm/Support/Casting.h:572: decltype(auto) llvm::cast(From&) [with To = fir::ReferenceType; From = mlir::Type]: Assertion `isa<To>(Val) && "cast<Ty>() argument of incompatible type!"' failed.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0.      Program arguments: /work/groups/ssoft/compiler/llvm/aarch64/main-20250106-f4230b433226/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 /work/groups/ssoft/compiler/llvm/aarch64/main-20250106-f4230b433226/lib/clang/20 -mframe-pointer=non-leaf -o /tmp/snggx596_-f5b158.o -x f95-cpp-input snggx596_.f90

 #0 0x000040002f051638 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/work/groups/ssoft/compiler/llvm/aarch64/main-latest/lib/libLLVM.so.20.0git+0x59d1638)
 #1 0x000040002f04f6c0 llvm::sys::RunSignalHandlers() (/work/groups/ssoft/compiler/llvm/aarch64/main-latest/lib/libLLVM.so.20.0git+0x59cf6c0)
 #2 0x000040002f04f818 SignalHandler(int) Signals.cpp:0:0
 #3 0x00004000246d07a0 (linux-vdso.so.1+0x7a0)
 #4 0x0000400033eb6274 raise (/lib64/libc.so.6+0x36274)
 #5 0x0000400033ea0a2c abort (/lib64/libc.so.6+0x20a2c)
 #6 0x0000400033eafba0 __assert_fail_base (/lib64/libc.so.6+0x2fba0)
 #7 0x0000400033eafc18 __assert_perror_fail (/lib64/libc.so.6+0x2fc18)
 #8 0x0000000005d1d770 Fortran::lower::omp::createCopyFunc(mlir::Location, Fortran::lower::AbstractConverter&, mlir::Type, fir::FortranVariableFlagsEnum) ClauseProcessor.cpp:0:0
 #9 0x0000000005d1db28 Fortran::lower::omp::ClauseProcessor::processCopyprivate(mlir::Location, mlir::omp::CopyprivateClauseOps&) const::'lambda'(Fortran::semantics::Symbol*)::operator()(Fortran::semantics::Symbol*) const ClauseProcessor.cpp:0:0
#10 0x0000000005d1df24 std::_Function_handler<void (tomp::clause::CopyprivateT<Fortran::evaluate::DynamicType, Fortran::lower::omp::IdTyTemplate<Fortran::evaluate::Expr<Fortran::evaluate::SomeType>>, Fortran::evaluate::Expr<Fortran::evaluate::SomeType>> const&, Fortran::parser::CharBlock const&), Fortran::lower::omp
::ClauseProcessor::processCopyprivate(mlir::Location, mlir::omp::CopyprivateClauseOps&) const::'lambda0'(tomp::clause::CopyprivateT<Fortran::evaluate::DynamicType, Fortran::lower::omp::IdTyTemplate<Fortran::evaluate::Expr<Fortran::evaluate::SomeType>>, Fortran::evaluate::Expr<Fortran::evaluate::SomeType>> const&, Fo
rtran::parser::CharBlock const&)>::_M_invoke(std::_Any_data const&, tomp::clause::CopyprivateT<Fortran::evaluate::DynamicType, Fortran::lower::omp::IdTyTemplate<Fortran::evaluate::Expr<Fortran::evaluate::SomeType>>, Fortran::evaluate::Expr<Fortran::evaluate::SomeType>> const&, Fortran::parser::CharBlock const&) Clau
seProcessor.cpp:0:0
#11 0x0000000005d1a9dc Fortran::lower::omp::ClauseProcessor::processCopyprivate(mlir::Location, mlir::omp::CopyprivateClauseOps&) const (/work/groups/ssoft/compiler/llvm/aarch64/main-20250106-f4230b433226/bin/flang+0x5d1a9dc)
#12 0x0000000005cda780 genSingleOp(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::om
p::Clause> const*) OpenMP.cpp:0:0
#13 0x0000000005cdcfb4 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 0x0000000005ce17d0 std::__detail::__variant::__gen_vtable_impl<std::__detail::__variant::_Multi_array<void (*)(genOMP(Fortran::lower::AbstractConverter&, Fortran::lower::SymMap&, Fortran::semantics::SemanticsContext&, Fortran::lower::pft::Evaluation&, Fortran::parser::OpenMPConstruct const&)::'lambda'(auto&&)&&,
 std::variant<Fortran::parser::OpenMPStandaloneConstruct, Fortran::parser::OpenMPSectionsConstruct, Fortran::parser::OpenMPSectionConstruct, Fortran::parser::OpenMPLoopConstruct, Fortran::parser::OpenMPBlockConstruct, Fortran::parser::OpenMPAtomicConstruct, Fortran::parser::OpenMPDeclarativeAllocate, Fortran::parser
::OpenMPUtilityConstruct, Fortran::parser::OpenMPExecutableAllocate, Fortran::parser::OpenMPAllocatorsConstruct, Fortran::parser::OpenMPCriticalConstruct> const&)>, std::tuple<std::variant<Fortran::parser::OpenMPStandaloneConstruct, Fortran::parser::OpenMPSectionsConstruct, Fortran::parser::OpenMPSectionConstruct, F
ortran::parser::OpenMPLoopConstruct, Fortran::parser::OpenMPBlockConstruct, Fortran::parser::OpenMPAtomicConstruct, Fortran::parser::OpenMPDeclarativeAllocate, Fortran::parser::OpenMPUtilityConstruct, Fortran::parser::OpenMPExecutableAllocate, Fortran::parser::OpenMPAllocatorsConstruct, Fortran::parser::OpenMPCritic
alConstruct> const&>, std::integer_sequence<unsigned long, 4ul>>::__visit_invoke(genOMP(Fortran::lower::AbstractConverter&, Fortran::lower::SymMap&, Fortran::semantics::SemanticsContext&, Fortran::lower::pft::Evaluation&, Fortran::parser::OpenMPConstruct const&)::'lambda'(auto&&)&&, std::variant<Fortran::parser::Ope
nMPStandaloneConstruct, Fortran::parser::OpenMPSectionsConstruct, Fortran::parser::OpenMPSectionConstruct, Fortran::parser::OpenMPLoopConstruct, Fortran::parser::OpenMPBlockConstruct, Fortran::parser::OpenMPAtomicConstruct, Fortran::parser::OpenMPDeclarativeAllocate, Fortran::parser::OpenMPUtilityConstruct, Fortran:
:parser::OpenMPExecutableAllocate, Fortran::parser::OpenMPAllocatorsConstruct, Fortran::parser::OpenMPCriticalConstruct> const&) OpenMP.cpp:0:0
#15 0x0000000005cc4ff4 Fortran::lower::genOpenMPConstruct(Fortran::lower::AbstractConverter&, Fortran::lower::SymMap&, Fortran::semantics::SemanticsContext&, Fortran::lower::pft::Evaluation&, Fortran::parser::OpenMPConstruct const&) (/work/groups/ssoft/compiler/llvm/aarch64/main-20250106-f4230b433226/bin/flang+0x5cc
4ff4)
#16 0x00000000059039e0 std::__detail::__variant::__gen_vtable_impl<std::__detail::__variant::_Multi_array<void (*)(Fortran::common::visitors<auto Fortran::lower::pft::ReferenceVariantBase<true, Fortran::parser::AllocateStmt, Fortran::parser::AssignmentStmt, Fortran::parser::BackspaceStmt, Fortran::parser::CallStmt,
- Omitted -
#17 0x000000000595e158 (anonymous namespace)::FirConverter::genFIR(Fortran::lower::pft::Evaluation&, bool) Bridge.cpp:0:0
#18 0x0000000005cb88f8 genNestedEvaluations(Fortran::lower::AbstractConverter&, Fortran::lower::pft::Evaluation&, int) (.constprop.51062) OpenMP.cpp:0:0
#19 0x0000000005cd61d4 createBodyOfOp(mlir::Operation&, OpWithBodyGenInfo const&, llvm::SmallVector<tomp::DirectiveWithClauses<Fortran::lower::omp::Clause>, 0u> const&, tomp::DirectiveWithClauses<Fortran::lower::omp::Clause> const*) OpenMP.cpp:0:0
#20 0x0000000005cd670c genParallelOp(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*, mlir::omp::detail::Clauses<mlir::omp::AllocateClauseOps, mlir::omp::IfClauseOps, mlir::omp::NumThreadsClauseOps, mlir::omp::PrivateClauseOps, mlir::omp::ProcBindClauseOps, mlir::omp::ReductionClauseOps>&, Fortran::common::openmp::EntryBlockArgs const&, Fortran::lower::omp::DataSharingProcessor*,
 bool) OpenMP.cpp:0:0
#21 0x0000000005cdceb4 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
#22 0x0000000005ce17d0 std::__detail::__variant::__gen_vtable_impl<std::__detail::__variant::_Multi_array<void (*)(genOMP(Fortran::lower::AbstractConverter&, Fortran::lower::SymMap&, Fortran::semantics::SemanticsContext&, Fortran::lower::pft::Evaluation&, 
Fortran::parser::OpenMPConstruct const&)::'lambda'(auto&&)&&,
 std::variant<Fortran::parser::OpenMPStandaloneConstruct, Fortran::parser::OpenMPSectionsConstruct, Fortran::parser::OpenMPSectionConstruct, Fortran::parser::OpenMPLoopConstruct, Fortran::parser::OpenMPBlockConstruct, Fortran::parser::OpenMPAtomicConstruct, Fortran::parser::OpenMPDeclarativeAllocate, Fortran::parser
::OpenMPUtilityConstruct, Fortran::parser::OpenMPExecutableAllocate, Fortran::parser::OpenMPAllocatorsConstruct, Fortran::parser::OpenMPCriticalConstruct> const&)>, std::tuple<std::variant<Fortran::parser::OpenMPStandaloneConstruct, Fortran::parser::OpenMPSectionsConstruct, Fortran::parser::OpenMPSectionConstruct, F
ortran::parser::OpenMPLoopConstruct, Fortran::parser::OpenMPBlockConstruct, Fortran::parser::OpenMPAtomicConstruct, Fortran::parser::OpenMPDeclarativeAllocate, Fortran::parser::OpenMPUtilityConstruct, Fortran::parser::OpenMPExecutableAllocate, Fortran::parser::OpenMPAllocatorsConstruct, Fortran::parser::OpenMPCritic
alConstruct> const&>, std::integer_sequence<unsigned long, 4ul>>::__visit_invoke(genOMP(Fortran::lower::AbstractConverter&, Fortran::lower::SymMap&, Fortran::semantics::SemanticsContext&, Fortran::lower::pft::Evaluation&, Fortran::parser::OpenMPConstruct const&)::'lambda'(auto&&)&&, std::variant<Fortran::parser::Ope
nMPStandaloneConstruct, Fortran::parser::OpenMPSectionsConstruct, Fortran::parser::OpenMPSectionConstruct, Fortran::parser::OpenMPLoopConstruct, Fortran::parser::OpenMPBlockConstruct, Fortran::parser::OpenMPAtomicConstruct, Fortran::parser::OpenMPDeclarativeAllocate, Fortran::parser::OpenMPUtilityConstruct, Fortran:
:parser::OpenMPExecutableAllocate, Fortran::parser::OpenMPAllocatorsConstruct, Fortran::parser::OpenMPCriticalConstruct> const&) OpenMP.cpp:0:0
#23 0x0000000005cc4ff4 Fortran::lower::genOpenMPConstruct(Fortran::lower::AbstractConverter&, Fortran::lower::SymMap&, Fortran::semantics::SemanticsContext&, Fortran::lower::pft::Evaluation&, Fortran::parser::OpenMPConstruct const&) (/work/groups/ssoft/compiler/llvm/aarch64/main-20250106-f4230b433226/bin/flang+0x5cc
4ff4)
#24 0x00000000059039e0 std::__detail::__variant::__gen_vtable_impl<std::__detail::__variant::_Multi_array<void (*)(Fortran::common::visitors<auto Fortran::lower::pft::ReferenceVariantBase<true, Fortran::parser::AllocateStmt, Fortran::parser::AssignmentStmt, Fortran::parser::BackspaceStmt, 
#25 0x00000000059673e4 (anonymous namespace)::FirConverter::lowerFunc(Fortran::lower::pft::FunctionLikeUnit&) Bridge.cpp:0:0
- Omitted -
#26 0x000000000594cc08 Fortran::lower::LoweringBridge::lower(Fortran::parser::Program const&, Fortran::semantics::SemanticsContext const&) (/work/groups/ssoft/compiler/llvm/aarch64/main-20250106-f4230b433226/bin/flang+0x594cc08)
#27 0x00000000058e46f4 Fortran::frontend::CodeGenAction::beginSourceFileAction() (/work/groups/ssoft/compiler/llvm/aarch64/main-20250106-f4230b433226/bin/flang+0x58e46f4)
#28 0x00000000057fa124 Fortran::frontend::FrontendAction::beginSourceFile(Fortran::frontend::CompilerInstance&, Fortran::frontend::FrontendInputFile const&) (/work/groups/ssoft/compiler/llvm/aarch64/main-20250106-f4230b433226/bin/flang+0x57fa124)
#29 0x00000000057eb1a0 Fortran::frontend::CompilerInstance::executeAction(Fortran::frontend::FrontendAction&) (/work/groups/ssoft/compiler/llvm/aarch64/main-20250106-f4230b433226/bin/flang+0x57eb1a0)
#30 0x00000000057fe8f4 Fortran::frontend::executeCompilerInvocation(Fortran::frontend::CompilerInstance*) (/work/groups/ssoft/compiler/llvm/aarch64/main-20250106-f4230b433226/bin/flang+0x57fe8f4)
#31 0x00000000057e3978 fc1_main(llvm::ArrayRef<char const*>, char const*) (/work/groups/ssoft/compiler/llvm/aarch64/main-20250106-f4230b433226/bin/flang+0x57e3978)
#32 0x00000000057e33d0 main (/work/groups/ssoft/compiler/llvm/aarch64/main-20250106-f4230b433226/bin/flang+0x57e33d0)
#33 0x0000400033ea4384 __libc_start_main (/lib64/libc.so.6+0x24384)
#34 0x00000000057e189c _start (/work/groups/ssoft/compiler/llvm/aarch64/main-20250106-f4230b433226/bin/flang+0x57e189c)
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 (https://github.com/llvm/llvm-project.git f4230b4332262dffb0bd3b7a2f8d6deb2e96488e)
Target: aarch64-unknown-linux-gnu
Thread model: posix
InstalledDir: /work/groups/ssoft/compiler/llvm/aarch64/main-20250106-f4230b433226/bin
Build config: +assertions
flang-20: warning: OpenMP support in flang is still experimental [-Wexperimental-option]
flang-20: note: diagnostic msg:
********************

PLEASE ATTACH THE FOLLOWING FILES TO THE BUG REPORT:
Preprocessed source(s) and associated run script(s) are located at:
flang-20: note: diagnostic msg: /tmp/snggx596_-75126f
flang-20: note: diagnostic msg: /tmp/snggx596_-75126f.sh
flang-20: note: diagnostic msg:

********************
$
$ cat /tmp/snggx596_-75126f
#line "./snggx596_.f90" 1
      subroutine s1
      equivalence(k(2),kk)
      common /com1/ k(2)
!$omp threadprivate(/com1/)

!$omp parallel
      k=0
!$omp single
      k(1)=1
      kk=2
!$omp end single copyprivate(/com1/)
      if(any(k/=[1,2])) print *,1011,k
      if((kk/=2)) print *,1012,kk
!$omp end parallel
      end
      call s1
      print *,'pass'
      end
$
$ cat /tmp/snggx596_-75126f.sh
# Crash reproducer for clang version 20.0.0git (https://github.com/llvm/llvm-project.git f4230b4332262dffb0bd3b7a2f8d6deb2e96488e)
# Driver args: "-fopenmp" "snggx596_.f90"
# Original command:  "/work/groups/ssoft/compiler/llvm/aarch64/main-20250106-f4230b433226/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-featur
e" "+fp-armv8" "-target-feature" "+neon" "-fopenmp" "-resource-dir" "/work/groups/ssoft/compiler/llvm/aarch64/main-20250106-f4230b433226/lib/clang/20" "-mframe-pointer=non-leaf" "-o" "/tmp/snggx596_-f5b158.o" "-x" "f95-cpp-input" "snggx596_.f90"
 "/work/groups/ssoft/compiler/llvm/aarch64/main-20250106-f4230b433226/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" "-tar
get-feature" "+neon" "-fopenmp" "-mframe-pointer=non-leaf" "-x" "f95-cpp-input" "snggx596_-75126f"
$
$ gfortran -fopenmp snggx596_.f90
snggx596_.f90:2:14:

    2 | equivalence (k(2),kk)
      |              1
Error: EQUIVALENCE attribute conflicts with THREADPRIVATE attribute in ‘k’ at (1)
snggx596_.f90:3:19:

    3 |       common /com1/ k(2)
      |                   1
Error: EQUIVALENCE attribute conflicts with THREADPRIVATE attribute in ‘k’ at (1)
$
$ export OMP_NUM_THREADS=2; ifx -qopenmp snggx596_.f90; ./a.out
 pass
$

Metadata

Metadata

Assignees

Labels

Type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions