[flang-commits] [flang] [Flang][OpenMP] NFC: Trivial changes in OmpCycleChecker (PR #91024)

Kiran Chandramohan via flang-commits flang-commits at lists.llvm.org
Fri May 3 15:29:32 PDT 2024


https://github.com/kiranchandramohan created https://github.com/llvm/llvm-project/pull/91024

Cycle is associated with construct-names and not labels. Change name of a few variables to reflect this. Also add appropriate comment to describe the else case of error checking.

>From 02c0c95e3d67841ce7a53dcd875e6b05b59eb26e Mon Sep 17 00:00:00 2001
From: Kiran Chandramohan <kiran.chandramohan at arm.com>
Date: Fri, 3 May 2024 22:17:45 +0000
Subject: [PATCH] [Flang][OpenMP] NFC: Trivial changes in OmpCycleChecker

Cycle is associated with construct-names and not labels. Change
name of a few variables to reflect this. Also add appropriate
comment to describe the else case of error checking.
---
 flang/lib/Semantics/check-omp-structure.cpp | 19 ++++++++++++-------
 1 file changed, 12 insertions(+), 7 deletions(-)

diff --git a/flang/lib/Semantics/check-omp-structure.cpp b/flang/lib/Semantics/check-omp-structure.cpp
index ab76fe59911b78..9c0fe534caef24 100644
--- a/flang/lib/Semantics/check-omp-structure.cpp
+++ b/flang/lib/Semantics/check-omp-structure.cpp
@@ -94,9 +94,10 @@ class OmpCycleChecker {
 
   bool Pre(const parser::DoConstruct &dc) {
     cycleLevel_--;
-    const auto &labelName{std::get<0>(std::get<0>(dc.t).statement.t)};
-    if (labelName) {
-      labelNamesandLevels_.emplace(labelName.value().ToString(), cycleLevel_);
+    const auto &constructName{std::get<0>(std::get<0>(dc.t).statement.t)};
+    if (constructName) {
+      constructNamesandLevels_.emplace(
+          constructName.value().ToString(), cycleLevel_);
     }
     return true;
   }
@@ -105,10 +106,14 @@ class OmpCycleChecker {
     std::map<std::string, std::int64_t>::iterator it;
     bool err{false};
     if (cyclestmt.v) {
-      it = labelNamesandLevels_.find(cyclestmt.v->source.ToString());
-      err = (it != labelNamesandLevels_.end() && it->second > 0);
+      it = constructNamesandLevels_.find(cyclestmt.v->source.ToString());
+      err = (it != constructNamesandLevels_.end() && it->second > 0);
+    } else {
+      // If there is no label then the cycle statement is associated with the
+      // closest enclosing DO. Use its level for the checks.
+      err = cycleLevel_ > 0;
     }
-    if (cycleLevel_ > 0 || err) {
+    if (err) {
       context_.Say(*cycleSource_,
           "CYCLE statement to non-innermost associated loop of an OpenMP DO "
           "construct"_err_en_US);
@@ -125,7 +130,7 @@ class OmpCycleChecker {
   SemanticsContext &context_;
   const parser::CharBlock *cycleSource_;
   std::int64_t cycleLevel_;
-  std::map<std::string, std::int64_t> labelNamesandLevels_;
+  std::map<std::string, std::int64_t> constructNamesandLevels_;
 };
 
 bool OmpStructureChecker::IsCloselyNestedRegion(const OmpDirectiveSet &set) {



More information about the flang-commits mailing list