Skip to content

Commit 570c168

Browse files
authored
[flang][openacc] Support single array element in data clause (#70065)
`gatherDataOperandAddrAndBounds` was crashing when a single array element was passed in a data clause. This patch fixes the issue.
1 parent fa7c50d commit 570c168

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

flang/lib/Lower/DirectivesCommon.h

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -898,9 +898,17 @@ mlir::Value gatherDataOperandAddrAndBounds(
898898
builder, operandLocation, converter, compExv, baseAddr);
899899
}
900900
} else {
901-
// Scalar or full array.
902-
if (const auto *dataRef{
903-
std::get_if<Fortran::parser::DataRef>(&designator.u)}) {
901+
if (Fortran::parser::Unwrap<Fortran::parser::ArrayElement>(
902+
designator)) {
903+
// Single array element.
904+
fir::ExtendedValue compExv =
905+
converter.genExprAddr(operandLocation, *expr, stmtCtx);
906+
baseAddr = fir::getBase(compExv);
907+
asFortran << (*expr).AsFortran();
908+
} else if (const auto *dataRef{
909+
std::get_if<Fortran::parser::DataRef>(
910+
&designator.u)}) {
911+
// Scalar or full array.
904912
const Fortran::parser::Name &name =
905913
Fortran::parser::GetLastName(*dataRef);
906914
fir::ExtendedValue dataExv =

flang/test/Lower/OpenACC/acc-enter-data.f90

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -803,3 +803,17 @@ subroutine acc_enter_data_derived_type()
803803
!CHECK: acc.enter_data dataOperands(%[[CREATE]] : !fir.ref<!fir.array<10xf32>>)
804804

805805
end subroutine
806+
807+
subroutine acc_enter_data_single_array_element()
808+
type t1
809+
real, allocatable :: a(:, :)
810+
end type t1
811+
type(t1), allocatable :: e(:)
812+
allocate(e(10)%a(5,5))
813+
814+
!$acc enter data create(e(2)%a(1,2))
815+
816+
!CHECK: %[[CREATE:.*]] = acc.create varPtr(%{{.*}} : !fir.ref<f32>) -> !fir.ref<f32> {name = "e(2_8)%a(1_8,2_8)", structured = false}
817+
!CHECK: acc.enter_data dataOperands(%[[CREATE]] : !fir.ref<f32>)
818+
819+
end subroutine

0 commit comments

Comments
 (0)