[flang-commits] [flang] [Flang] [Semantics] [OpenMP] Added missing semantic check with nested target region. (PR #115344)
Raghu Maddhipatla via flang-commits
flang-commits at lists.llvm.org
Thu Nov 7 09:15:19 PST 2024
https://github.com/raghavendhra created https://github.com/llvm/llvm-project/pull/115344
Issue semantic warning for any combination of nested OMP TARGET directives inside an OMP TARGET DATA directive and vice versa.
>From 076e3f2cfaf6cf17dc5a179d60b8c1a095004724 Mon Sep 17 00:00:00 2001
From: Raghu Maddhipatla <Raghu.Maddhipatla at amd.com>
Date: Thu, 7 Nov 2024 10:50:42 -0600
Subject: [PATCH] [Flang] [Semantics] [OpenMP] Added missing semantic check
with nested target region.
---
flang/lib/Semantics/check-omp-structure.cpp | 17 ++++++++++++++++-
flang/test/Semantics/OpenMP/nested-simd.f90 | 1 +
flang/test/Semantics/OpenMP/nested-target.f90 | 15 ++++++++++++++-
3 files changed, 31 insertions(+), 2 deletions(-)
diff --git a/flang/lib/Semantics/check-omp-structure.cpp b/flang/lib/Semantics/check-omp-structure.cpp
index 014604627f2cd1..d4fa32d5f26520 100644
--- a/flang/lib/Semantics/check-omp-structure.cpp
+++ b/flang/lib/Semantics/check-omp-structure.cpp
@@ -785,7 +785,8 @@ void OmpStructureChecker::CheckTargetNest(const parser::OpenMPConstruct &c) {
std::get<parser::OmpBeginBlockDirective>(c.t)};
const auto &beginDir{
std::get<parser::OmpBlockDirective>(beginBlockDir.t)};
- if (beginDir.v == llvm::omp::Directive::OMPD_target_data) {
+ if (beginDir.v == llvm::omp::Directive::OMPD_target_data ||
+ llvm::omp::allTargetSet.test(beginDir.v)) {
eligibleTarget = false;
ineligibleTargetDir = beginDir.v;
}
@@ -984,6 +985,20 @@ void OmpStructureChecker::Enter(const parser::OpenMPBlockConstruct &x) {
if (llvm::omp::topTeamsSet.test(GetContextParent().directive)) {
HasInvalidTeamsNesting(beginDir.v, beginDir.source);
}
+ if ((llvm::omp::allTargetSet.test(GetContext().directive) ||
+ (GetContext().directive ==
+ llvm::omp::Directive::OMPD_target_data)) &&
+ (llvm::omp::allTargetSet.test(GetContextParent().directive) ||
+ (GetContextParent().directive ==
+ llvm::omp::Directive::OMPD_target_data))) {
+ context_.Warn(common::UsageWarning::OpenMPUsage,
+ parser::FindSourceLocation(x),
+ "If %s directive is nested inside %s region, the behaviour is unspecified"_port_en_US,
+ parser::ToUpperCaseLetters(
+ getDirectiveName(GetContext().directive).str()),
+ parser::ToUpperCaseLetters(
+ getDirectiveName(GetContextParent().directive).str()));
+ }
if (GetContext().directive == llvm::omp::Directive::OMPD_master) {
CheckMasterNesting(x);
}
diff --git a/flang/test/Semantics/OpenMP/nested-simd.f90 b/flang/test/Semantics/OpenMP/nested-simd.f90
index 4149b6d97e9dc7..73e72cd5bf6a5a 100644
--- a/flang/test/Semantics/OpenMP/nested-simd.f90
+++ b/flang/test/Semantics/OpenMP/nested-simd.f90
@@ -166,6 +166,7 @@ SUBROUTINE NESTED_BAD(N)
end do
!$omp end task
!ERROR: The only OpenMP constructs that can be encountered during execution of a 'SIMD' region are the `ATOMIC` construct, the `LOOP` construct, the `SIMD` construct and the `ORDERED` construct with the `SIMD` clause.
+ !ERROR: If TARGET directive is nested inside TARGET SIMD region, the behaviour is unspecified
!$omp target
do J = 1, N
K = 2
diff --git a/flang/test/Semantics/OpenMP/nested-target.f90 b/flang/test/Semantics/OpenMP/nested-target.f90
index 2267f70715d3ed..b054292ef54d58 100644
--- a/flang/test/Semantics/OpenMP/nested-target.f90
+++ b/flang/test/Semantics/OpenMP/nested-target.f90
@@ -5,7 +5,7 @@
! 2.12.5 Target Construct
program main
- integer :: i, j, N = 10
+ integer :: i, j, N = 10, n1, n2, res(100)
real :: a, arrayA(512), arrayB(512), ai(10)
real, allocatable :: B(:)
@@ -50,4 +50,17 @@ program main
!$omp end target
deallocate(B)
+ n1 = 10
+ n2 = 10
+ !$omp target teams map(to:a)
+ !PORTABILITY: If TARGET DATA directive is nested inside TARGET TEAMS region, the behaviour is unspecified
+ !$omp target data map(n1,n2)
+ do i=1, n1
+ do j=1, n2
+ res((i-1)*10+j) = i*j
+ end do
+ end do
+ !$omp end target data
+ !$omp end target teams
+
end program main
More information about the flang-commits
mailing list