Skip to content

Commit e4dfb33

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 e4dfb33

File tree

2 files changed

+23
-0
lines changed

2 files changed

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