aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKareem Ergawy <kareem.ergawy@amd.com>2024-05-29 11:58:59 +0200
committerGitHub <noreply@github.com>2024-05-29 11:58:59 +0200
commite1aa8ad6faa1524f12338ca58d1eadfde6f29f34 (patch)
tree263a202df28010c7853c39fa18d1977031b1f5c5
parent78cc9cbba23fd1783a9b233ae745f126ece56cc7 (diff)
downloadllvm-e1aa8ad6faa1524f12338ca58d1eadfde6f29f34.zip
llvm-e1aa8ad6faa1524f12338ca58d1eadfde6f29f34.tar.gz
llvm-e1aa8ad6faa1524f12338ca58d1eadfde6f29f34.tar.bz2
[flang][OpenMP] Fix bug in emitting `dealloc` logic (#93641)
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.
-rw-r--r--flang/lib/Lower/OpenMP/DataSharingProcessor.cpp2
-rw-r--r--flang/test/Lower/OpenMP/allocatable-multiple-vars.f9028
2 files changed, 29 insertions, 1 deletions
diff --git a/flang/lib/Lower/OpenMP/DataSharingProcessor.cpp b/flang/lib/Lower/OpenMP/DataSharingProcessor.cpp
index b722e19..557a968 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 0000000..e6450a1
--- /dev/null
+++ b/flang/test/Lower/OpenMP/allocatable-multiple-vars.f90
@@ -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: }