Skip to content

Commit

Permalink
[flang][OpenMP] Fix bug in emitting dealloc logic (#93641)
Browse files Browse the repository at this point in the history
Fixes a bug in emiting deacllocation logic when delayed privatization is
disabled. I introduced the bug when implementing delayed privatization
for allocatables: when delayed privatization is disabled the
deacllocation ops are emitted for only one allocatable variables.
  • Loading branch information
ergawy authored May 29, 2024
1 parent 78cc9cb commit e1aa8ad
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
2 changes: 1 addition & 1 deletion flang/lib/Lower/OpenMP/DataSharingProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ void DataSharingProcessor::insertDeallocs() {
if (semantics::IsAllocatable(sym->GetUltimate())) {
if (!useDelayedPrivatization) {
converter.createHostAssociateVarCloneDealloc(*sym);
return;
continue;
}

lower::SymbolBox hsb = converter.lookupOneLevelUpSymbol(*sym);
Expand Down
28 changes: 28 additions & 0 deletions flang/test/Lower/OpenMP/allocatable-multiple-vars.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
! Test early privatization for multiple allocatable variables.

! RUN: %flang_fc1 -emit-hlfir -fopenmp -mmlir --openmp-enable-delayed-privatization=false \
! RUN: -o - %s 2>&1 | FileCheck %s

! RUN: bbc -emit-hlfir -fopenmp --openmp-enable-delayed-privatization=false -o - %s 2>&1 |\
! RUN: FileCheck %s

subroutine delayed_privatization_allocatable
implicit none
integer, allocatable :: var1, var2

!$omp parallel private(var1, var2)
var1 = 10
var2 = 20
!$omp end parallel
end subroutine

! Verify that private versions of each variable are both allocated and freed
! within the parallel region.

! CHECK: omp.parallel {
! CHECK: fir.allocmem
! CHECK: fir.allocmem
! CHECK: fir.freemem
! CHECK: fir.freemem
! CHECK: omp.terminator
! CHECK-NEXT: }

0 comments on commit e1aa8ad

Please sign in to comment.