Skip to content
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

[Flang][OpenMP] Fix issue with empty critical or critical without surrounding context #71944

Merged
merged 2 commits into from
Nov 27, 2023

Conversation

kiranchandramohan
Copy link
Contributor

Add the sourcerange for critical directive.

Fixes #65571

Add the sourcerange for critical directive.

Fixes llvm#65571
@llvmbot llvmbot added flang Flang issues not falling into any other category flang:semantics labels Nov 10, 2023
@llvmbot
Copy link
Collaborator

llvmbot commented Nov 10, 2023

@llvm/pr-subscribers-flang-openmp

@llvm/pr-subscribers-flang-semantics

Author: Kiran Chandramohan (kiranchandramohan)

Changes

Add the sourcerange for critical directive.

Fixes #65571


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

1 Files Affected:

  • (modified) flang/lib/Semantics/resolve-names.cpp (+14)
diff --git a/flang/lib/Semantics/resolve-names.cpp b/flang/lib/Semantics/resolve-names.cpp
index 98773a1b9d6ab45..58d88f1bb428387 100644
--- a/flang/lib/Semantics/resolve-names.cpp
+++ b/flang/lib/Semantics/resolve-names.cpp
@@ -1452,6 +1452,20 @@ class OmpVisitor : public virtual DeclarationVisitor {
   void Post(const parser::OmpEndSectionsDirective &) {
     messageHandler().set_currStmtSource(std::nullopt);
   }
+  bool Pre(const parser::OmpCriticalDirective &x) {
+    AddOmpSourceRange(x.source);
+    return true;
+  }
+  void Post(const parser::OmpCriticalDirective &) {
+    messageHandler().set_currStmtSource(std::nullopt);
+  }
+  bool Pre(const parser::OmpEndCriticalDirective &x) {
+    AddOmpSourceRange(x.source);
+    return true;
+  }
+  void Post(const parser::OmpEndCriticalDirective &) {
+    messageHandler().set_currStmtSource(std::nullopt);
+  }
 };
 
 bool OmpVisitor::NeedsScope(const parser::OpenMPBlockConstruct &x) {

@DavidTruby
Copy link
Member

Is there a way to add a test for this? For example could we use the example in the linked issue and check it doesn't error anymore?

@kiranchandramohan
Copy link
Contributor Author

Is there a way to add a test for this? For example could we use the example in the linked issue and check it doesn't error anymore?

Have added a test.

Copy link
Member

@DavidTruby DavidTruby left a comment

Choose a reason for hiding this comment

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

LGTM

@kiranchandramohan kiranchandramohan merged commit 63a6e51 into llvm:main Nov 27, 2023
4 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.

[Flang][OpenMP] Compilation error of critical construct not in parallel regions
3 participants