[flang-commits] [flang] [flang][OpenMP] Make lastprivate work with reallocated variables (PR #106559)
Tom Eccles via flang-commits
flang-commits at lists.llvm.org
Fri Aug 30 03:08:49 PDT 2024
================
@@ -36,3 +24,45 @@ program lastprivate_allocatable
! CHECK-NEXT: }
! CHECK-NEXT: omp.yield
! CHECK-NEXT: }
+program lastprivate_allocatable
+ integer, allocatable :: a
+ integer :: i
+ ! a is unallocated here
+ !$omp parallel do lastprivate(a)
+ do i=1,1
+ a = 42
+ enddo
+ !$omp end parallel do
+ ! a should be allocated here
+end program
+
+! CHECK-LABEL: func @_QPlastprivate_realloc()
+! CHECK: %[[A:.*]]:2 = hlfir.declare %{{.*}} {fortran_attrs = #fir.var_attrs<allocatable>, uniq_name = "_QFlastprivate_reallocEa"} :
+! CHECK-SAME: (!fir.ref<!fir.box<!fir.heap<!fir.array<?x!fir.complex<4>>>>>) ->
+! CHECK-SAME: (!fir.ref<!fir.box<!fir.heap<!fir.array<?x!fir.complex<4>>>>>, !fir.ref<!fir.box<!fir.heap<!fir.array<?x!fir.complex<4>>>>>)
+! CHECK: omp.parallel {
+! CHECK: %[[A_PRIV:.*]]:2 = hlfir.declare %{{.*}} {fortran_attrs = #fir.var_attrs<allocatable>, uniq_name = "_QFlastprivate_reallocEa"} :
+! CHECK-SAME: (!fir.ref<!fir.box<!fir.heap<!fir.array<?x!fir.complex<4>>>>>) ->
+! CHECK-SAME: (!fir.ref<!fir.box<!fir.heap<!fir.array<?x!fir.complex<4>>>>>, !fir.ref<!fir.box<!fir.heap<!fir.array<?x!fir.complex<4>>>>>)
+! CHECK: omp.sections {
+! CHECK: omp.section {
+! CHECK: fir.if %{{.*}} {
----------------
tblah wrote:
> If the original list item does not have the POINTER attribute, its update occurs as if by intrinsic assignment unless it has a type bound procedure as a deļ¬ned assignment.
If an allocated allocatable is assigned to an unallocated allocatable, the lhs is allocated as part of the assignment. So I think we should still do the assignment, even if the list item was unallocated.
https://github.com/llvm/llvm-project/pull/106559
More information about the flang-commits
mailing list