[flang-commits] [flang] 63a6e51 - [Flang][OpenMP] Fix issue with empty critical or critical without surrounding context (#71944)

via flang-commits flang-commits at lists.llvm.org
Mon Nov 27 07:56:43 PST 2023


Author: Kiran Chandramohan
Date: 2023-11-27T15:56:39Z
New Revision: 63a6e51f8ad68a1f573b3a278486124c0ade8711

URL: https://github.com/llvm/llvm-project/commit/63a6e51f8ad68a1f573b3a278486124c0ade8711
DIFF: https://github.com/llvm/llvm-project/commit/63a6e51f8ad68a1f573b3a278486124c0ade8711.diff

LOG: [Flang][OpenMP] Fix issue with empty critical or critical without surrounding context (#71944)

Add the sourcerange for critical directive.

Fixes #65571

Added: 
    flang/test/Semantics/OpenMP/critical-empty.f90

Modified: 
    flang/lib/Semantics/resolve-names.cpp

Removed: 
    


################################################################################
diff  --git a/flang/lib/Semantics/resolve-names.cpp b/flang/lib/Semantics/resolve-names.cpp
index 8f15f2f51da7c89..0e59c3dd3b1af4f 100644
--- a/flang/lib/Semantics/resolve-names.cpp
+++ b/flang/lib/Semantics/resolve-names.cpp
@@ -1459,6 +1459,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) {

diff  --git a/flang/test/Semantics/OpenMP/critical-empty.f90 b/flang/test/Semantics/OpenMP/critical-empty.f90
new file mode 100644
index 000000000000000..2001c8a14a7ba40
--- /dev/null
+++ b/flang/test/Semantics/OpenMP/critical-empty.f90
@@ -0,0 +1,6 @@
+! RUN: %python %S/../test_errors.py %s %flang_fc1 -fopenmp 
+! Test that there are no errors for an empty critical construct
+
+!$omp critical
+!$omp end critical
+end


        


More information about the flang-commits mailing list