Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions flang/test/Lower/OpenMP/target-data-if-false.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
!RUN: %flang_fc1 -emit-llvm -fopenmp %openmp_flags -fopenmp-version=52 %s -o - | FileCheck %s

!Check that this doesn't crash.

!CHECK-LABEL: define void @f00_()
!CHECK: call i1 @_FortranAioOutputDerivedType

subroutine f00
use iso_c_binding
type(c_ptr) :: x

!$omp target data use_device_ptr(x) if(.false.)
print *, x
!$omp end target data
end

!CHECK-LABEL: define void @f01_()
!CHECK: call i1 @_FortranAioOutputInteger32
subroutine f01
integer :: x

!$omp target data use_device_addr(x) if(.false.)
print *, x
!$omp end target data
end
Original file line number Diff line number Diff line change
Expand Up @@ -4518,6 +4518,8 @@ convertOmpTargetData(Operation *op, llvm::IRBuilderBase &builder,
using BodyGenTy = llvm::OpenMPIRBuilder::BodyGenTy;
auto bodyGenCB = [&](InsertPointTy codeGenIP, BodyGenTy bodyGenType)
-> llvm::OpenMPIRBuilder::InsertPointOrErrorTy {
// We must always restoreIP regardless of doing anything the caller
// does not restore it, leading to incorrect (no) branch generation.
builder.restoreIP(codeGenIP);
assert(isa<omp::TargetDataOp>(op) &&
"BodyGen requested for non TargetDataOp");
Expand Down Expand Up @@ -4549,9 +4551,18 @@ convertOmpTargetData(Operation *op, llvm::IRBuilderBase &builder,
}
break;
case BodyGenTy::DupNoPriv:
// We must always restoreIP regardless of doing anything the caller
// does not restore it, leading to incorrect (no) branch generation.
builder.restoreIP(codeGenIP);
if (info.DevicePtrInfoMap.empty()) {
// For host device we still need to do the mapping for codegen,
// otherwise it may try to lookup a missing value.
if (!ompBuilder->Config.IsTargetDevice.value_or(false)) {
mapUseDevice(llvm::OpenMPIRBuilder::DeviceInfoTy::Address,
blockArgIface.getUseDeviceAddrBlockArgs(),
useDeviceAddrVars, mapData);
mapUseDevice(llvm::OpenMPIRBuilder::DeviceInfoTy::Pointer,
blockArgIface.getUseDevicePtrBlockArgs(),
useDevicePtrVars, mapData);
}
}
break;
case BodyGenTy::NoPriv:
// If device info is available then region has already been generated
Expand Down