Skip to content

[flang][OpenMP] Allow structure component in task depend clauses #141923

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 30, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions flang/include/flang/Evaluate/tools.h
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,16 @@ const Symbol *IsArrayElement(const Expr<T> &expr, bool intoSubstring = true,
return nullptr;
}

template <typename T>
bool isStructureComponent(const Fortran::evaluate::Expr<T> &expr) {
if (auto dataRef{ExtractDataRef(expr, /*intoSubstring=*/false)}) {
const Fortran::evaluate::DataRef *ref{&*dataRef};
return std::holds_alternative<Fortran::evaluate::Component>(ref->u);
}

return false;
}

template <typename A>
std::optional<NamedEntity> ExtractNamedEntity(const A &x) {
if (auto dataRef{ExtractDataRef(x)}) {
Expand Down
5 changes: 5 additions & 0 deletions flang/lib/Lower/OpenMP/ClauseProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -944,6 +944,11 @@ bool ClauseProcessor::processDepend(lower::SymMap &symMap,
converter.getCurrentLocation(), converter, expr, symMap, stmtCtx);
dependVar = entity.getBase();
}
} else if (evaluate::isStructureComponent(*object.ref())) {
SomeExpr expr = *object.ref();
hlfir::EntityWithAttributes entity = convertExprToHLFIR(
converter.getCurrentLocation(), converter, expr, symMap, stmtCtx);
dependVar = entity.getBase();
} else {
semantics::Symbol *sym = object.sym();
dependVar = converter.getSymbolAddress(*sym);
Expand Down
8 changes: 2 additions & 6 deletions flang/lib/Semantics/check-omp-structure.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5493,12 +5493,8 @@ void OmpStructureChecker::CheckDependList(const parser::DataRef &d) {
// Check if the base element is valid on Depend Clause
CheckDependList(elem.value().base);
},
[&](const common::Indirection<parser::StructureComponent> &) {
context_.Say(GetContext().clauseSource,
"A variable that is part of another variable "
"(such as an element of a structure) but is not an array "
"element or an array section cannot appear in a DEPEND "
"clause"_err_en_US);
[&](const common::Indirection<parser::StructureComponent> &comp) {
CheckDependList(comp.value().base);
},
[&](const common::Indirection<parser::CoindexedNamedObject> &) {
context_.Say(GetContext().clauseSource,
Expand Down
21 changes: 21 additions & 0 deletions flang/test/Lower/OpenMP/task-depend-structure-component.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
! RUN: %flang_fc1 -emit-hlfir -fopenmp %s -o - | FileCheck %s

subroutine depend
type :: my_struct
integer :: my_component(10)
end type

type(my_struct) :: my_var

!$omp task depend(in:my_var%my_component)
!$omp end task
end subroutine depend

! CHECK: %[[VAR_ALLOC:.*]] = fir.alloca !fir.type<{{.*}}my_struct{{.*}}> {bindc_name = "my_var", {{.*}}}
! CHECK: %[[VAR_DECL:.*]]:2 = hlfir.declare %[[VAR_ALLOC]]

! CHECK: %[[COMP_SELECTOR:.*]] = hlfir.designate %[[VAR_DECL]]#0{"my_component"}

! CHECK: omp.task depend(taskdependin -> %[[COMP_SELECTOR]] : {{.*}}) {
! CHECK: omp.terminator
! CHECK: }
49 changes: 0 additions & 49 deletions flang/test/Semantics/OpenMP/depend02.f90

This file was deleted.