Skip to content

[flang][OpenMP] Fix crash in unparse-with-symbols for CRITICAL #151962

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions flang/lib/Semantics/unparse-with-symbols.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 21 additions & 0 deletions flang/test/Parser/OpenMP/critical-unparse-with-symbols.f90
Original file line number Diff line number Diff line change
@@ -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