Skip to content

Commit 7587a32

Browse files
authored
[flang][OpenMP] Fix crash in unparse-with-symbols for CRITICAL (#151962)
1 parent 9f50224 commit 7587a32

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed

flang/lib/Semantics/unparse-with-symbols.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,33 @@ class SymbolDumpVisitor {
7070
currStmt_ = std::nullopt;
7171
}
7272

73+
bool Pre(const parser::OmpCriticalDirective &x) {
74+
currStmt_ = x.source;
75+
return true;
76+
}
77+
void Post(const parser::OmpCriticalDirective &) { currStmt_ = std::nullopt; }
78+
79+
bool Pre(const parser::OmpEndCriticalDirective &x) {
80+
currStmt_ = x.source;
81+
return true;
82+
}
83+
void Post(const parser::OmpEndCriticalDirective &) {
84+
currStmt_ = std::nullopt;
85+
}
86+
87+
// Directive arguments can be objects with symbols.
88+
bool Pre(const parser::OmpBeginDirective &x) {
89+
currStmt_ = x.source;
90+
return true;
91+
}
92+
void Post(const parser::OmpBeginDirective &) { currStmt_ = std::nullopt; }
93+
94+
bool Pre(const parser::OmpEndDirective &x) {
95+
currStmt_ = x.source;
96+
return true;
97+
}
98+
void Post(const parser::OmpEndDirective &) { currStmt_ = std::nullopt; }
99+
73100
private:
74101
std::optional<SourceName> currStmt_; // current statement we are processing
75102
std::multimap<const char *, const Symbol *> symbols_; // ___location to symbol
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
!RUN: %flang_fc1 -fdebug-unparse-with-symbols -fopenmp -fopenmp-version=50 %s | FileCheck --ignore-case --check-prefix="UNPARSE" %s
2+
3+
subroutine f
4+
implicit none
5+
integer :: x
6+
!$omp critical(c)
7+
x = 0
8+
!$omp end critical(c)
9+
end
10+
11+
!UNPARSE: !DEF: /f (Subroutine) Subprogram
12+
!UNPARSE: subroutine f
13+
!UNPARSE: implicit none
14+
!UNPARSE: !DEF: /f/x ObjectEntity INTEGER(4)
15+
!UNPARSE: integer x
16+
!UNPARSE: !$omp critical (c)
17+
!UNPARSE: !REF: /f/x
18+
!UNPARSE: x = 0
19+
!UNPARSE: !$omp end critical (c)
20+
!UNPARSE: end subroutine
21+

0 commit comments

Comments
 (0)