[flang-commits] [flang] 130d295 - [Flang][OpenMP] Fix a corner case where target region is empty
Kiran Chandramohan via flang-commits
flang-commits at lists.llvm.org
Thu Feb 16 03:08:03 PST 2023
Author: Kiran Chandramohan
Date: 2023-02-16T11:07:47Z
New Revision: 130d2953d878ab137b491501f3a2c579cd9e2075
URL: https://github.com/llvm/llvm-project/commit/130d2953d878ab137b491501f3a2c579cd9e2075
DIFF: https://github.com/llvm/llvm-project/commit/130d2953d878ab137b491501f3a2c579cd9e2075.diff
LOG: [Flang][OpenMP] Fix a corner case where target region is empty
Reviewed By: psoni2628, raghavendhra
Differential Revision: https://reviews.llvm.org/D144110
Added:
flang/test/Semantics/OpenMP/omp-target.f90
Modified:
flang/lib/Semantics/check-omp-structure.cpp
Removed:
################################################################################
diff --git a/flang/lib/Semantics/check-omp-structure.cpp b/flang/lib/Semantics/check-omp-structure.cpp
index 98b367d686f11..2c77467a455ec 100644
--- a/flang/lib/Semantics/check-omp-structure.cpp
+++ b/flang/lib/Semantics/check-omp-structure.cpp
@@ -2634,24 +2634,28 @@ void OmpStructureChecker::CheckPrivateSymbolsInOuterCxt(
bool OmpStructureChecker::CheckTargetBlockOnlyTeams(
const parser::Block &block) {
bool nestedTeams{false};
- auto it{block.begin()};
-
- if (const auto *ompConstruct{parser::Unwrap<parser::OpenMPConstruct>(*it)}) {
- if (const auto *ompBlockConstruct{
- std::get_if<parser::OpenMPBlockConstruct>(&ompConstruct->u)}) {
- const auto &beginBlockDir{
- std::get<parser::OmpBeginBlockDirective>(ompBlockConstruct->t)};
- const auto &beginDir{
- std::get<parser::OmpBlockDirective>(beginBlockDir.t)};
- if (beginDir.v == llvm::omp::Directive::OMPD_teams) {
- nestedTeams = true;
+
+ if (!block.empty()) {
+ auto it{block.begin()};
+ if (const auto *ompConstruct{
+ parser::Unwrap<parser::OpenMPConstruct>(*it)}) {
+ if (const auto *ompBlockConstruct{
+ std::get_if<parser::OpenMPBlockConstruct>(&ompConstruct->u)}) {
+ const auto &beginBlockDir{
+ std::get<parser::OmpBeginBlockDirective>(ompBlockConstruct->t)};
+ const auto &beginDir{
+ std::get<parser::OmpBlockDirective>(beginBlockDir.t)};
+ if (beginDir.v == llvm::omp::Directive::OMPD_teams) {
+ nestedTeams = true;
+ }
}
}
- }
- if (nestedTeams && ++it == block.end()) {
- return true;
+ if (nestedTeams && ++it == block.end()) {
+ return true;
+ }
}
+
return false;
}
diff --git a/flang/test/Semantics/OpenMP/omp-target.f90 b/flang/test/Semantics/OpenMP/omp-target.f90
new file mode 100644
index 0000000000000..994c04048edff
--- /dev/null
+++ b/flang/test/Semantics/OpenMP/omp-target.f90
@@ -0,0 +1,11 @@
+! RUN: %python %S/../test_errors.py %s %flang_fc1 -fopenmp -Werror
+
+! Corner cases in OpenMP target directives
+
+subroutine empty_target()
+ integer :: i
+
+ !$omp target map(i)
+ !$omp end target
+
+end subroutine
More information about the flang-commits
mailing list