[flang][OpenMP] Fix crash on DECLARE REDUCTION in unparse-with-symbols (#157871)

This commit is contained in:
Krzysztof Parzyszek
2025-09-10 10:07:04 -05:00
committed by GitHub
parent fa0bb6a20e
commit fc9fe0f7b7
2 changed files with 24 additions and 1 deletions

View File

@@ -37,6 +37,8 @@ public:
template <typename T> void Post(const parser::Statement<T> &) {
currStmt_ = std::nullopt;
}
void Post(const parser::Name &name);
bool Pre(const parser::AccClause &clause) {
currStmt_ = clause.source;
return true;
@@ -57,7 +59,6 @@ public:
return true;
}
void Post(const parser::OpenMPThreadprivate &) { currStmt_ = std::nullopt; }
void Post(const parser::Name &name);
bool Pre(const parser::OpenMPDeclareMapperConstruct &x) {
currStmt_ = x.source;
@@ -67,6 +68,14 @@ public:
currStmt_ = std::nullopt;
}
bool Pre(const parser::OpenMPDeclareReductionConstruct &x) {
currStmt_ = x.source;
return true;
}
void Post(const parser::OpenMPDeclareReductionConstruct &) {
currStmt_ = std::nullopt;
}
bool Pre(const parser::OpenMPDeclareTargetConstruct &x) {
currStmt_ = x.source;
return true;
@@ -120,6 +129,7 @@ void SymbolDumpVisitor::Indent(llvm::raw_ostream &out, int indent) const {
void SymbolDumpVisitor::Post(const parser::Name &name) {
if (const auto *symbol{name.symbol}) {
if (!symbol->has<MiscDetails>()) {
CHECK(currStmt_.has_value());
symbols_.emplace(currStmt_.value().begin(), symbol);
}
}

View File

@@ -0,0 +1,13 @@
!RUN: %flang_fc1 -fdebug-unparse-with-symbols -fopenmp %s | FileCheck %s
! This used to crash.
subroutine f00
!$omp declare reduction(fred : integer, real : omp_out = omp_in + omp_out)
end
!CHECK: !DEF: /f00 (Subroutine) Subprogram
!CHECK: subroutine f00
!CHECK: !$omp declare reduction (fred:integer,real:omp_out = omp_in+omp_out)
!CHECK: end subroutine