Skip to content

Commit 18ea14a

Browse files
committed
[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()`.
1 parent 461cc86 commit 18ea14a

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

flang/lib/Optimizer/Builder/FIRBuilder.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,8 @@ mlir::Block *fir::FirOpBuilder::getAllocaBlock() {
252252
.getParentOfType<mlir::omp::OutlineableOpenMPOpInterface>()) {
253253
return ompOutlineableIface.getAllocaBlock();
254254
}
255-
if (getRegion().getParentOfType<mlir::omp::DeclareReductionOp>())
255+
if (getRegion().getParentOfType<mlir::omp::DeclareReductionOp>() ||
256+
getRegion().getParentOfType<mlir::omp::PrivateClauseOp>())
256257
return &getRegion().front();
257258
if (auto accRecipeIface =
258259
getRegion().getParentOfType<mlir::acc::RecipeInterface>()) {

flang/test/Lower/OpenMP/delayed-privatization-allocatable-firstprivate.f90

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
! Test delayed privatization for allocatables: `firstprivate`.
22

3+
! RUN: split-file %s %t
4+
35
! RUN: %flang_fc1 -emit-hlfir -fopenmp -mmlir --openmp-enable-delayed-privatization \
4-
! RUN: -o - %s 2>&1 | FileCheck %s
5-
! RUN: bbc -emit-hlfir -fopenmp --openmp-enable-delayed-privatization -o - %s 2>&1 |\
6+
! RUN: -o - %t/test_ir.f90 2>&1 | FileCheck %s
7+
! RUN: bbc -emit-hlfir -fopenmp --openmp-enable-delayed-privatization -o - %t/test_ir.f90 2>&1 |\
68
! RUN: FileCheck %s
79

10+
!--- test_ir.f90
811
subroutine delayed_privatization_allocatable
912
implicit none
1013
integer, allocatable :: var1
@@ -34,3 +37,17 @@ subroutine delayed_privatization_allocatable
3437
! CHECK-NEXT: %[[ORIG_BASE_LD:.*]] = fir.load %[[ORIG_BASE_ADDR]]
3538
! CHECK-NEXT: hlfir.assign %[[ORIG_BASE_LD]] to %[[PRIV_BASE_BOX]] temporary_lhs
3639
! CHECK-NEXT: }
40+
41+
! RUN: %flang -fopenmp -mmlir --openmp-enable-delayed-privatization \
42+
! RUN: -o - %t/test_compilation_to_obj.f90
43+
44+
!--- test_compilation_to_obj.f90
45+
46+
program compilation_to_obj
47+
real, allocatable :: t(:)
48+
49+
!$omp parallel firstprivate(t)
50+
t(1) = 3.14
51+
!$omp end parallel
52+
53+
end program compilation_to_obj

0 commit comments

Comments
 (0)