[flang-commits] [flang] [flang][OpenMP] Handle `omp.private` in `FirOpBuilder::getAllocaBlock()` (PR #93927)
Kareem Ergawy via flang-commits
flang-commits at lists.llvm.org
Fri May 31 00:27:42 PDT 2024
https://github.com/ergawy updated https://github.com/llvm/llvm-project/pull/93927
>From b9b7eec6c21759313d01ef99f1444c82903a21a5 Mon Sep 17 00:00:00 2001
From: ergawy <kareem.ergawy at amd.com>
Date: Fri, 31 May 2024 01:10:08 -0500
Subject: [PATCH] [flang][OpenMP] Handle `omp.private` in
`FirOpBuilder::getAllocaBlock()`
Fixes a crash uncovered by [pr89651](https://github.com/llvm/llvm-test-suite/blob/main/Fortran/gfortran/regression/gomp/pr89651.f90) in the test suite.
Fixes a crash caused by missing handling of `omp.private` ops in
`FirOpBuilder::getAllocaBlock()`.
---
flang/lib/Optimizer/Builder/FIRBuilder.cpp | 3 ++-
...privatization-allocatable-firstprivate.f90 | 21 +++++++++++++++++--
2 files changed, 21 insertions(+), 3 deletions(-)
diff --git a/flang/lib/Optimizer/Builder/FIRBuilder.cpp b/flang/lib/Optimizer/Builder/FIRBuilder.cpp
index 3c3fd02d7c88e..48d4397f448e8 100644
--- a/flang/lib/Optimizer/Builder/FIRBuilder.cpp
+++ b/flang/lib/Optimizer/Builder/FIRBuilder.cpp
@@ -252,7 +252,8 @@ mlir::Block *fir::FirOpBuilder::getAllocaBlock() {
.getParentOfType<mlir::omp::OutlineableOpenMPOpInterface>()) {
return ompOutlineableIface.getAllocaBlock();
}
- if (getRegion().getParentOfType<mlir::omp::DeclareReductionOp>())
+ if (getRegion().getParentOfType<mlir::omp::DeclareReductionOp>() ||
+ getRegion().getParentOfType<mlir::omp::PrivateClauseOp>())
return &getRegion().front();
if (auto accRecipeIface =
getRegion().getParentOfType<mlir::acc::RecipeInterface>()) {
diff --git a/flang/test/Lower/OpenMP/delayed-privatization-allocatable-firstprivate.f90 b/flang/test/Lower/OpenMP/delayed-privatization-allocatable-firstprivate.f90
index aa835f82b2730..5ca06b98b47bd 100644
--- a/flang/test/Lower/OpenMP/delayed-privatization-allocatable-firstprivate.f90
+++ b/flang/test/Lower/OpenMP/delayed-privatization-allocatable-firstprivate.f90
@@ -1,10 +1,13 @@
! Test delayed privatization for allocatables: `firstprivate`.
+! RUN: split-file %s %t
+
! RUN: %flang_fc1 -emit-hlfir -fopenmp -mmlir --openmp-enable-delayed-privatization \
-! RUN: -o - %s 2>&1 | FileCheck %s
-! RUN: bbc -emit-hlfir -fopenmp --openmp-enable-delayed-privatization -o - %s 2>&1 |\
+! RUN: -o - %t/test_ir.f90 2>&1 | FileCheck %s
+! RUN: bbc -emit-hlfir -fopenmp --openmp-enable-delayed-privatization -o - %t/test_ir.f90 2>&1 |\
! RUN: FileCheck %s
+!--- test_ir.f90
subroutine delayed_privatization_allocatable
implicit none
integer, allocatable :: var1
@@ -34,3 +37,17 @@ subroutine delayed_privatization_allocatable
! CHECK-NEXT: %[[ORIG_BASE_LD:.*]] = fir.load %[[ORIG_BASE_ADDR]]
! CHECK-NEXT: hlfir.assign %[[ORIG_BASE_LD]] to %[[PRIV_BASE_BOX]] temporary_lhs
! CHECK-NEXT: }
+
+! RUN: %flang -c -fopenmp -mmlir --openmp-enable-delayed-privatization \
+! RUN: -o - %t/test_compilation_to_obj.f90
+
+!--- test_compilation_to_obj.f90
+
+program compilation_to_obj
+ real, allocatable :: t(:)
+
+!$omp parallel firstprivate(t)
+ t(1) = 3.14
+!$omp end parallel
+
+end program compilation_to_obj
More information about the flang-commits
mailing list