[flang-commits] [flang] [flang][OpenMP] Fix crash in unparse-with-symbols for CRITICAL (PR #151962)
Krzysztof Parzyszek via flang-commits
flang-commits at lists.llvm.org
Mon Aug 4 06:37:21 PDT 2025
https://github.com/kparzysz updated https://github.com/llvm/llvm-project/pull/151962
>From 73171dd21e3e14bcf0f25e4b5e6e4ab3679ad7d5 Mon Sep 17 00:00:00 2001
From: Krzysztof Parzyszek <Krzysztof.Parzyszek at amd.com>
Date: Mon, 4 Aug 2025 07:59:47 -0500
Subject: [PATCH 1/2] [flang][OpenMP] Fix crash in unparse-with-symbols for
CRITICAL
---
flang/lib/Semantics/unparse-with-symbols.cpp | 33 +++++++++++++++++++
.../OpenMP/critical-unparse-with-symbols.f90 | 21 ++++++++++++
2 files changed, 54 insertions(+)
create mode 100644 flang/test/Parser/OpenMP/critical-unparse-with-symbols.f90
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
+
>From 1b33e0ff393735c84a58d721c929a7fc74909c94 Mon Sep 17 00:00:00 2001
From: Krzysztof Parzyszek <Krzysztof.Parzyszek at amd.com>
Date: Mon, 4 Aug 2025 08:37:04 -0500
Subject: [PATCH 2/2] format
---
flang/lib/Semantics/unparse-with-symbols.cpp | 12 +++---------
1 file changed, 3 insertions(+), 9 deletions(-)
diff --git a/flang/lib/Semantics/unparse-with-symbols.cpp b/flang/lib/Semantics/unparse-with-symbols.cpp
index 4548fbeba5df6..3093e39ba2411 100644
--- a/flang/lib/Semantics/unparse-with-symbols.cpp
+++ b/flang/lib/Semantics/unparse-with-symbols.cpp
@@ -74,9 +74,7 @@ class SymbolDumpVisitor {
currStmt_ = x.source;
return true;
}
- void Post(const parser::OmpCriticalDirective &) {
- currStmt_ = std::nullopt;
- }
+ void Post(const parser::OmpCriticalDirective &) { currStmt_ = std::nullopt; }
bool Pre(const parser::OmpEndCriticalDirective &x) {
currStmt_ = x.source;
@@ -91,17 +89,13 @@ class SymbolDumpVisitor {
currStmt_ = x.source;
return true;
}
- void Post(const parser::OmpBeginDirective &) {
- currStmt_ = std::nullopt;
- }
+ 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;
- }
+ void Post(const parser::OmpEndDirective &) { currStmt_ = std::nullopt; }
private:
std::optional<SourceName> currStmt_; // current statement we are processing
More information about the flang-commits
mailing list