[flang-commits] [flang] 5268389 - [flang][openacc] Fix crash with array section in acc declare in function

Valentin Clement via flang-commits flang-commits at lists.llvm.org
Mon Aug 28 08:59:10 PDT 2023


Author: Valentin Clement
Date: 2023-08-28T08:59:04-07:00
New Revision: 52683899fcaa45160ba6b669ddd3ec53ce3714f8

URL: https://github.com/llvm/llvm-project/commit/52683899fcaa45160ba6b669ddd3ec53ce3714f8
DIFF: https://github.com/llvm/llvm-project/commit/52683899fcaa45160ba6b669ddd3ec53ce3714f8.diff

LOG: [flang][openacc] Fix crash with array section in acc declare in function

getSymbolFromAccObject was hitting the fatal error when
trying to retrieve the symbol on array section

Reviewed By: razvanlupusoru

Differential Revision: https://reviews.llvm.org/D158881

Added: 
    

Modified: 
    flang/lib/Lower/OpenACC.cpp
    flang/test/Lower/OpenACC/acc-declare.f90

Removed: 
    


################################################################################
diff  --git a/flang/lib/Lower/OpenACC.cpp b/flang/lib/Lower/OpenACC.cpp
index 24de69302c8c57..5ec04722cd5e11 100644
--- a/flang/lib/Lower/OpenACC.cpp
+++ b/flang/lib/Lower/OpenACC.cpp
@@ -526,6 +526,13 @@ getSymbolFromAccObject(const Fortran::parser::AccObject &accObject) {
     if (const auto *name =
             Fortran::semantics::getDesignatorNameIfDataRef(*designator))
       return *name->symbol;
+    if (const auto *arrayElement =
+            Fortran::parser::Unwrap<Fortran::parser::ArrayElement>(
+                *designator)) {
+      const Fortran::parser::Name &name =
+          Fortran::parser::GetLastName(arrayElement->base);
+      return *name.symbol;
+    }
   } else if (const auto *name =
                  std::get_if<Fortran::parser::Name>(&accObject.u)) {
     return *name->symbol;

diff  --git a/flang/test/Lower/OpenACC/acc-declare.f90 b/flang/test/Lower/OpenACC/acc-declare.f90
index b95dfc239e125a..92966c3c367f3c 100644
--- a/flang/test/Lower/OpenACC/acc-declare.f90
+++ b/flang/test/Lower/OpenACC/acc-declare.f90
@@ -278,6 +278,24 @@ subroutine acc_declare_multiple_directive(a, b)
 ! CHECK: acc.copyout accPtr(%[[CREATE]] : !fir.ref<!fir.array<100xi32>>) bounds(%{{.*}}) to varPtr(%[[ARG1]] : !fir.ref<!fir.array<100xi32>>) {name = "b"}
 ! CHECK: acc.copyout accPtr(%[[COPYIN]] : !fir.ref<!fir.array<100xi32>>) bounds(%{{.*}}) to varPtr(%[[ARG0]] : !fir.ref<!fir.array<100xi32>>) {dataClause = #acc<data_clause acc_copy>, name = "a"}
 
+  subroutine acc_declare_array_section(a)
+    integer :: a(:)
+    !$acc declare copy(a(1:10))
+
+    do i = 1, 100
+      a(i) = i
+    end do
+  end subroutine
+
+! CHECK-LABEL: func.func @_QMacc_declarePacc_declare_array_section(
+! CHECK-SAME:    %[[ARG0:.*]]: !fir.box<!fir.array<?xi32>> {fir.bindc_name = "a"}) {
+! CHECK: %[[BOX_ADDR:.*]] = fir.box_addr %arg0 {acc.declare = #acc.declare<dataClause =  acc_copy>} : (!fir.box<!fir.array<?xi32>>) -> !fir.ref<!fir.array<?xi32>>
+! CHECK: %[[COPYIN:.*]] = acc.copyin varPtr(%[[BOX_ADDR]] : !fir.ref<!fir.array<?xi32>>) bounds(%{{.*}}) -> !fir.ref<!fir.array<?xi32>> {dataClause = #acc<data_clause acc_copy>, name = "a(1:10)"}
+! CHECK: acc.declare dataOperands(%4 : !fir.ref<!fir.array<?xi32>>) {
+! CHECK:   acc.terminator
+! CHECK: }
+! CHECK: acc.copyout accPtr(%[[COPYIN]] : !fir.ref<!fir.array<?xi32>>) bounds(%{{.*}}) to varPtr(%[[BOX_ADDR]] : !fir.ref<!fir.array<?xi32>>) {dataClause = #acc<data_clause acc_copy>, name = "a(1:10)"}
+
 end module
 
 module acc_declare_allocatable_test


        


More information about the flang-commits mailing list