Skip to content

Commit 6a95d5c

Browse files
committed
[flang][openmp] initialize allocatable components of firstprivate copies
1 parent d68ea31 commit 6a95d5c

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

flang/lib/Lower/Bridge.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -833,7 +833,11 @@ class FirConverter : public Fortran::lower::AbstractConverter {
833833
if_builder.end();
834834
},
835835
[&](const auto &) -> void {
836-
if (skipDefaultInit)
836+
// Always initialize allocatable component descriptor, even when the
837+
// value is later copied from the host (e.g. firstprivate) because the
838+
// assignment from the host to the copy will fail if the component
839+
// descriptors are not initialized.
840+
if (skipDefaultInit && !hlfir::mayHaveAllocatableComponent(hSymType))
837841
return;
838842
// Initialize local/private derived types with default
839843
// initialization (Fortran 2023 section 11.1.7.5 and OpenMP 5.2
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
! Test delayed privatization for derived types with allocatable components.
2+
! RUN: %flang_fc1 -emit-hlfir -fopenmp -o - %s | FileCheck %s
3+
4+
subroutine firstprivate_alloc_comp
5+
type t1
6+
integer, allocatable :: c(:)
7+
end type
8+
type(t1) :: x
9+
!$omp parallel firstprivate(x)
10+
print *, allocated(x%c)
11+
!$omp end parallel
12+
end
13+
14+
call firstprivate_alloc_comp()
15+
end
16+
! CHECK-LABEL: omp.private {type = firstprivate} @_QFfirstprivate_alloc_compEx_firstprivate_ref_rec__QFfirstprivate_alloc_compTt1 : !fir.ref<!fir.type<_QFfirstprivate_alloc_compTt1{c:!fir.box<!fir.heap<!fir.array<?xi32>>>}>> alloc {
17+
! CHECK: fir.call @_FortranAInitialize(
18+
! CHECK: } copy {
19+
! ...

0 commit comments

Comments
 (0)