Skip to content

Commit fc9fe0f

Browse files
authored
[flang][OpenMP] Fix crash on DECLARE REDUCTION in unparse-with-symbols (#157871)
1 parent fa0bb6a commit fc9fe0f

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ class SymbolDumpVisitor {
3737
template <typename T> void Post(const parser::Statement<T> &) {
3838
currStmt_ = std::nullopt;
3939
}
40+
void Post(const parser::Name &name);
41+
4042
bool Pre(const parser::AccClause &clause) {
4143
currStmt_ = clause.source;
4244
return true;
@@ -57,7 +59,6 @@ class SymbolDumpVisitor {
5759
return true;
5860
}
5961
void Post(const parser::OpenMPThreadprivate &) { currStmt_ = std::nullopt; }
60-
void Post(const parser::Name &name);
6162

6263
bool Pre(const parser::OpenMPDeclareMapperConstruct &x) {
6364
currStmt_ = x.source;
@@ -67,6 +68,14 @@ class SymbolDumpVisitor {
6768
currStmt_ = std::nullopt;
6869
}
6970

71+
bool Pre(const parser::OpenMPDeclareReductionConstruct &x) {
72+
currStmt_ = x.source;
73+
return true;
74+
}
75+
void Post(const parser::OpenMPDeclareReductionConstruct &) {
76+
currStmt_ = std::nullopt;
77+
}
78+
7079
bool Pre(const parser::OpenMPDeclareTargetConstruct &x) {
7180
currStmt_ = x.source;
7281
return true;
@@ -120,6 +129,7 @@ void SymbolDumpVisitor::Indent(llvm::raw_ostream &out, int indent) const {
120129
void SymbolDumpVisitor::Post(const parser::Name &name) {
121130
if (const auto *symbol{name.symbol}) {
122131
if (!symbol->has<MiscDetails>()) {
132+
CHECK(currStmt_.has_value());
123133
symbols_.emplace(currStmt_.value().begin(), symbol);
124134
}
125135
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
!RUN: %flang_fc1 -fdebug-unparse-with-symbols -fopenmp %s | FileCheck %s
2+
3+
! This used to crash.
4+
5+
subroutine f00
6+
!$omp declare reduction(fred : integer, real : omp_out = omp_in + omp_out)
7+
end
8+
9+
!CHECK: !DEF: /f00 (Subroutine) Subprogram
10+
!CHECK: subroutine f00
11+
!CHECK: !$omp declare reduction (fred:integer,real:omp_out = omp_in+omp_out)
12+
!CHECK: end subroutine
13+

0 commit comments

Comments
 (0)