Skip to content

[Flang][OpenMP] NFC: Trivial changes in OmpCycleChecker #91024

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 7, 2024

Conversation

kiranchandramohan
Copy link
Contributor

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.

Copy link
Contributor

@NimishMishra NimishMishra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks

Copy link
Contributor

@luporl luporl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks for this improvement.

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.
@llvmbot llvmbot added flang Flang issues not falling into any other category flang:openmp flang:semantics labels May 6, 2024
@llvmbot
Copy link
Member

llvmbot commented May 6, 2024

@llvm/pr-subscribers-flang-openmp

@llvm/pr-subscribers-flang-semantics

Author: Kiran Chandramohan (kiranchandramohan)

Changes

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.


Full diff: https://github.com/llvm/llvm-project/pull/91024.diff

1 Files Affected:

  • (modified) flang/lib/Semantics/check-omp-structure.cpp (+12-7)
diff --git a/flang/lib/Semantics/check-omp-structure.cpp b/flang/lib/Semantics/check-omp-structure.cpp
index ab76fe59911b78..70863c5f20e891 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) {

@kiranchandramohan kiranchandramohan merged commit 6ad37a4 into llvm:main May 7, 2024
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
flang:openmp flang:semantics flang Flang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants