[flang-commits] [flang] [flang][OpenMP] Fix bug in emitting `dealloc` logic (PR #93641)
Kareem Ergawy via flang-commits
flang-commits at lists.llvm.org
Wed May 29 02:10:31 PDT 2024
https://github.com/ergawy updated https://github.com/llvm/llvm-project/pull/93641
>From 344cb0045aa0577339209caca95eb4030a903acd Mon Sep 17 00:00:00 2001
From: ergawy <kareem.ergawy at amd.com>
Date: Tue, 28 May 2024 23:09:40 -0500
Subject: [PATCH 1/2] [flang][OpenMP] Fix bug in emitting `dealloc` logic
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.
---
.../lib/Lower/OpenMP/DataSharingProcessor.cpp | 2 +-
.../OpenMP/allocatable-multiple-vars.f90 | 28 +++++++++++++++++++
2 files changed, 29 insertions(+), 1 deletion(-)
create mode 100644 flang/test/Lower/OpenMP/allocatable-multiple-vars.f90
diff --git a/flang/lib/Lower/OpenMP/DataSharingProcessor.cpp b/flang/lib/Lower/OpenMP/DataSharingProcessor.cpp
index b722e19272ca1..557a9685024c5 100644
--- a/flang/lib/Lower/OpenMP/DataSharingProcessor.cpp
+++ b/flang/lib/Lower/OpenMP/DataSharingProcessor.cpp
@@ -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);
diff --git a/flang/test/Lower/OpenMP/allocatable-multiple-vars.f90 b/flang/test/Lower/OpenMP/allocatable-multiple-vars.f90
new file mode 100644
index 0000000000000..0df029ee97d5c
--- /dev/null
+++ b/flang/test/Lower/OpenMP/allocatable-multiple-vars.f90
@@ -0,0 +1,28 @@
+! Test delayed 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: }
>From a920857fb16cbad8ae942786226c09d246c7d139 Mon Sep 17 00:00:00 2001
From: Kareem Ergawy <kareem.ergawy at amd.com>
Date: Wed, 29 May 2024 11:10:24 +0200
Subject: [PATCH 2/2] Fix comment
Co-authored-by: Kiran Chandramohan <kiranchandramohan at gmail.com>
---
flang/test/Lower/OpenMP/allocatable-multiple-vars.f90 | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/flang/test/Lower/OpenMP/allocatable-multiple-vars.f90 b/flang/test/Lower/OpenMP/allocatable-multiple-vars.f90
index 0df029ee97d5c..e6450a13e13a0 100644
--- a/flang/test/Lower/OpenMP/allocatable-multiple-vars.f90
+++ b/flang/test/Lower/OpenMP/allocatable-multiple-vars.f90
@@ -1,4 +1,4 @@
-! Test delayed privatization for multiple allocatable variables.
+! 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
More information about the flang-commits
mailing list