Skip to content

[flang][OpenMP] Fix crash in unparse-with-symbols for CRITICAL #151962

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 2 commits into from
Aug 5, 2025

Conversation

kparzysz
Copy link
Contributor

@kparzysz kparzysz commented Aug 4, 2025

No description provided.

@kparzysz kparzysz requested review from tblah and Stylie777 August 4, 2025 13:31
@llvmbot llvmbot added flang Flang issues not falling into any other category flang:openmp flang:semantics flang:parser labels Aug 4, 2025
@llvmbot
Copy link
Member

llvmbot commented Aug 4, 2025

@llvm/pr-subscribers-flang-semantics
@llvm/pr-subscribers-flang-openmp

@llvm/pr-subscribers-flang-parser

Author: Krzysztof Parzyszek (kparzysz)

Changes

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

2 Files Affected:

  • (modified) flang/lib/Semantics/unparse-with-symbols.cpp (+33)
  • (added) flang/test/Parser/OpenMP/critical-unparse-with-symbols.f90 (+21)
diff --git a/flang/lib/Semantics/unparse-with-symbols.cpp b/flang/lib/Semantics/unparse-with-symbols.cpp
index f1e2e4ea7f119..4548fbeba5df6 100644
--- a/flang/lib/Semantics/unparse-with-symbols.cpp
+++ b/flang/lib/Semantics/unparse-with-symbols.cpp
@@ -70,6 +70,39 @@ class SymbolDumpVisitor {
     currStmt_ = std::nullopt;
   }
 
+  bool Pre(const parser::OmpCriticalDirective &x) {
+    currStmt_ = x.source;
+    return true;
+  }
+  void Post(const parser::OmpCriticalDirective &) {
+    currStmt_ = std::nullopt;
+  }
+
+  bool Pre(const parser::OmpEndCriticalDirective &x) {
+    currStmt_ = x.source;
+    return true;
+  }
+  void Post(const parser::OmpEndCriticalDirective &) {
+    currStmt_ = std::nullopt;
+  }
+
+  // Directive arguments can be objects with symbols.
+  bool Pre(const parser::OmpBeginDirective &x) {
+    currStmt_ = x.source;
+    return true;
+  }
+  void Post(const parser::OmpBeginDirective &) {
+    currStmt_ = std::nullopt;
+  }
+
+  bool Pre(const parser::OmpEndDirective &x) {
+    currStmt_ = x.source;
+    return true;
+  }
+  void Post(const parser::OmpEndDirective &) {
+    currStmt_ = std::nullopt;
+  }
+
 private:
   std::optional<SourceName> currStmt_; // current statement we are processing
   std::multimap<const char *, const Symbol *> symbols_; // ___location to symbol
diff --git a/flang/test/Parser/OpenMP/critical-unparse-with-symbols.f90 b/flang/test/Parser/OpenMP/critical-unparse-with-symbols.f90
new file mode 100644
index 0000000000000..4d0d93ac48740
--- /dev/null
+++ b/flang/test/Parser/OpenMP/critical-unparse-with-symbols.f90
@@ -0,0 +1,21 @@
+!RUN: %flang_fc1 -fdebug-unparse-with-symbols -fopenmp -fopenmp-version=50 %s | FileCheck --ignore-case --check-prefix="UNPARSE" %s
+
+subroutine f
+  implicit none
+  integer :: x
+  !$omp critical(c)
+  x = 0
+  !$omp end critical(c)
+end
+
+!UNPARSE: !DEF: /f (Subroutine) Subprogram
+!UNPARSE: subroutine f
+!UNPARSE:  implicit none
+!UNPARSE:  !DEF: /f/x ObjectEntity INTEGER(4)
+!UNPARSE:  integer x
+!UNPARSE: !$omp critical (c)
+!UNPARSE:  !REF: /f/x
+!UNPARSE:  x = 0
+!UNPARSE: !$omp end critical (c)
+!UNPARSE: end subroutine
+

Copy link

github-actions bot commented Aug 4, 2025

✅ With the latest revision this PR passed the C/C++ code formatter.

Copy link
Contributor

@Stylie777 Stylie777 left a comment

Choose a reason for hiding this comment

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

LGTM

@kparzysz kparzysz merged commit 7587a32 into main Aug 5, 2025
9 checks passed
@kparzysz kparzysz deleted the users/kparzysz/a06-unparse-with-symbols branch August 5, 2025 12:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
flang:openmp flang:parser flang:semantics flang Flang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants