Skip to content

Commit 236ab35

Browse files
authored
[Flang][MLIR][OpenMP] Fix Target Data if (present(...)) causing LLVM-… (llvm#2526)
2 parents 7ec8b71 + c22262c commit 236ab35

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4158,6 +4158,9 @@ convertOmpTargetData(Operation *op, llvm::IRBuilderBase &builder,
41584158
}
41594159
break;
41604160
case BodyGenTy::DupNoPriv:
4161+
// We must always restoreIP regardless of doing anything the caller
4162+
// does not restore it, leading to incorrect (no) branch generation.
4163+
builder.restoreIP(codeGenIP);
41614164
break;
41624165
case BodyGenTy::NoPriv:
41634166
// If device info is available then region has already been generated
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
! Offloading test that tests that if(present(a)) compiles and executes without
2+
! causing any compilation errors, primarily a regression test that does not
3+
! yield interesting results.
4+
! REQUIRES: flang, amdgpu
5+
6+
! RUN: %libomptarget-compile-fortran-run-and-check-generic
7+
module mod
8+
implicit none
9+
contains
10+
subroutine routine(a)
11+
implicit none
12+
real, dimension(:), optional :: a
13+
integer :: i
14+
!$omp target data if(present(a)) map(alloc:a)
15+
do i = 1, 10
16+
a(i) = i
17+
end do
18+
!$omp end target data
19+
end subroutine routine
20+
end module mod
21+
22+
program main
23+
use mod
24+
real :: a(10)
25+
call routine(a)
26+
print *, a
27+
end program main
28+
29+
! CHECK: 1. 2. 3. 4. 5. 6. 7. 8. 9. 10.

0 commit comments

Comments
 (0)