Skip to content

Commit 926cf8d

Browse files
committed
[OpenMP][][LLVM] Update alloca IP after PrivCB in OMPIRBUIlder
Fixes a crash uncovered by [pr77666.f90](https://github.com/llvm/llvm-test-suite/blob/main/Fortran/gfortran/regression/gomp/pr77666.f90) in the test suite. In particular, whenever `PrivCB` (the callback responsible for generating privatizaiton logic for an OMP variable) generates a multi-block privatization region, the insertion point diverges: the BB component of the IP can become a different BB from the parent block of the instruction iterator component of the IP. This PR updates the IP to make sure that the BB is the parent block of the instruction iterator.
1 parent 461cc86 commit 926cf8d

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
! Tests the OMPIRBuilder can handle multiple privatization regions that contain
2+
! multiple BBs (for example, for allocatables).
3+
4+
! RUN: %flang -S -emit-llvm -fopenmp -mmlir --openmp-enable-delayed-privatization \
5+
! RUN: -o - %s 2>&1 | FileCheck %s
6+
7+
subroutine foo(x)
8+
integer, allocatable :: x, y
9+
!$omp parallel private(x, y)
10+
x = y
11+
!$omp end parallel
12+
end
13+
14+
! CHECK-LABEL: define void @foo_
15+
! CHECK: ret void
16+
! CHECK-NEXT: }
17+
18+
! CHECK-LABEL: define internal void @foo_..omp_par
19+
! CHECK-DAG: call ptr @malloc
20+
! CHECK-DAG: call ptr @malloc
21+
! CHECK-DAG: call void @free
22+
! CHECK-DAG: call void @free
23+
! CHECK: }

llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1583,6 +1583,9 @@ IRBuilder<>::InsertPoint OpenMPIRBuilder::createParallel(
15831583
} else {
15841584
Builder.restoreIP(
15851585
PrivCB(InnerAllocaIP, Builder.saveIP(), V, *Inner, ReplacementValue));
1586+
InnerAllocaIP = {InnerAllocaIP.getPoint()->getParent(),
1587+
InnerAllocaIP.getPoint()};
1588+
15861589
assert(ReplacementValue &&
15871590
"Expected copy/create callback to set replacement value!");
15881591
if (ReplacementValue == &V)

0 commit comments

Comments
 (0)