Skip to content

[flang][openmp] initialize allocatable components of firstprivate copies #121808

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion flang/lib/Lower/Bridge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -833,7 +833,11 @@ class FirConverter : public Fortran::lower::AbstractConverter {
if_builder.end();
},
[&](const auto &) -> void {
if (skipDefaultInit)
// Always initialize allocatable component descriptor, even when the
// value is later copied from the host (e.g. firstprivate) because the
// assignment from the host to the copy will fail if the component
// descriptors are not initialized.
if (skipDefaultInit && !hlfir::mayHaveAllocatableComponent(hSymType))
return;
// Initialize local/private derived types with default
// initialization (Fortran 2023 section 11.1.7.5 and OpenMP 5.2
Expand Down
19 changes: 19 additions & 0 deletions flang/test/Lower/OpenMP/firstprivate-alloc-comp.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
! Test delayed privatization for derived types with allocatable components.
! RUN: %flang_fc1 -emit-hlfir -fopenmp -o - %s | FileCheck %s

subroutine firstprivate_alloc_comp
type t1
integer, allocatable :: c(:)
end type
type(t1) :: x
!$omp parallel firstprivate(x)
print *, allocated(x%c)
!$omp end parallel
end

call firstprivate_alloc_comp()
end
! 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 {
! CHECK: fir.call @_FortranAInitialize(
! CHECK: } copy {
! ...
Loading