[flang-commits] [flang] 7587a32 - [flang][OpenMP] Fix crash in unparse-with-symbols for CRITICAL (#151962)
via flang-commits
flang-commits at lists.llvm.org
Tue Aug 5 05:52:54 PDT 2025
Author: Krzysztof Parzyszek
Date: 2025-08-05T07:52:50-05:00
New Revision: 7587a32d49d2cd8a9a90d98adcd9d557b6f14be4
URL: https://github.com/llvm/llvm-project/commit/7587a32d49d2cd8a9a90d98adcd9d557b6f14be4
DIFF: https://github.com/llvm/llvm-project/commit/7587a32d49d2cd8a9a90d98adcd9d557b6f14be4.diff
LOG: [flang][OpenMP] Fix crash in unparse-with-symbols for CRITICAL (#151962)
Added:
flang/test/Parser/OpenMP/critical-unparse-with-symbols.f90
Modified:
flang/lib/Semantics/unparse-with-symbols.cpp
Removed:
################################################################################
diff --git a/flang/lib/Semantics/unparse-with-symbols.cpp b/flang/lib/Semantics/unparse-with-symbols.cpp
index f1e2e4ea7f119..3093e39ba2411 100644
--- a/flang/lib/Semantics/unparse-with-symbols.cpp
+++ b/flang/lib/Semantics/unparse-with-symbols.cpp
@@ -70,6 +70,33 @@ 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
+
More information about the flang-commits
mailing list