[flang-commits] [flang] 570c168 - [flang][openacc] Support single array element in data clause (#70065)
via flang-commits
flang-commits at lists.llvm.org
Tue Oct 24 11:40:58 PDT 2023
Author: Valentin Clement (バレンタイン クレメン)
Date: 2023-10-24T11:40:53-07:00
New Revision: 570c168e867382ed77f46f7e0427fb869a7a7e08
URL: https://github.com/llvm/llvm-project/commit/570c168e867382ed77f46f7e0427fb869a7a7e08
DIFF: https://github.com/llvm/llvm-project/commit/570c168e867382ed77f46f7e0427fb869a7a7e08.diff
LOG: [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.
Added:
Modified:
flang/lib/Lower/DirectivesCommon.h
flang/test/Lower/OpenACC/acc-enter-data.f90
Removed:
################################################################################
diff --git a/flang/lib/Lower/DirectivesCommon.h b/flang/lib/Lower/DirectivesCommon.h
index ed44598bc925212..eef92160ae1fd45 100644
--- a/flang/lib/Lower/DirectivesCommon.h
+++ b/flang/lib/Lower/DirectivesCommon.h
@@ -898,9 +898,17 @@ mlir::Value gatherDataOperandAddrAndBounds(
builder, operandLocation, converter, compExv, baseAddr);
}
} else {
- // Scalar or full array.
- if (const auto *dataRef{
- std::get_if<Fortran::parser::DataRef>(&designator.u)}) {
+ if (Fortran::parser::Unwrap<Fortran::parser::ArrayElement>(
+ designator)) {
+ // Single array element.
+ fir::ExtendedValue compExv =
+ converter.genExprAddr(operandLocation, *expr, stmtCtx);
+ baseAddr = fir::getBase(compExv);
+ asFortran << (*expr).AsFortran();
+ } else if (const auto *dataRef{
+ std::get_if<Fortran::parser::DataRef>(
+ &designator.u)}) {
+ // Scalar or full array.
const Fortran::parser::Name &name =
Fortran::parser::GetLastName(*dataRef);
fir::ExtendedValue dataExv =
diff --git a/flang/test/Lower/OpenACC/acc-enter-data.f90 b/flang/test/Lower/OpenACC/acc-enter-data.f90
index 93418a1fca3ec5c..0938d137ca02c36 100644
--- a/flang/test/Lower/OpenACC/acc-enter-data.f90
+++ b/flang/test/Lower/OpenACC/acc-enter-data.f90
@@ -803,3 +803,17 @@ subroutine acc_enter_data_derived_type()
!CHECK: acc.enter_data dataOperands(%[[CREATE]] : !fir.ref<!fir.array<10xf32>>)
end subroutine
+
+subroutine acc_enter_data_single_array_element()
+ type t1
+ real, allocatable :: a(:, :)
+ end type t1
+ type(t1), allocatable :: e(:)
+ allocate(e(10)%a(5,5))
+
+ !$acc enter data create(e(2)%a(1,2))
+
+!CHECK: %[[CREATE:.*]] = acc.create varPtr(%{{.*}} : !fir.ref<f32>) -> !fir.ref<f32> {name = "e(2_8)%a(1_8,2_8)", structured = false}
+!CHECK: acc.enter_data dataOperands(%[[CREATE]] : !fir.ref<f32>)
+
+end subroutine
More information about the flang-commits
mailing list