Skip to content

Commit 63a6e51

Browse files
[Flang][OpenMP] Fix issue with empty critical or critical without surrounding context (#71944)
Add the sourcerange for critical directive. Fixes #65571
1 parent 12bb291 commit 63a6e51

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

flang/lib/Semantics/resolve-names.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1459,6 +1459,20 @@ class OmpVisitor : public virtual DeclarationVisitor {
14591459
void Post(const parser::OmpEndSectionsDirective &) {
14601460
messageHandler().set_currStmtSource(std::nullopt);
14611461
}
1462+
bool Pre(const parser::OmpCriticalDirective &x) {
1463+
AddOmpSourceRange(x.source);
1464+
return true;
1465+
}
1466+
void Post(const parser::OmpCriticalDirective &) {
1467+
messageHandler().set_currStmtSource(std::nullopt);
1468+
}
1469+
bool Pre(const parser::OmpEndCriticalDirective &x) {
1470+
AddOmpSourceRange(x.source);
1471+
return true;
1472+
}
1473+
void Post(const parser::OmpEndCriticalDirective &) {
1474+
messageHandler().set_currStmtSource(std::nullopt);
1475+
}
14621476
};
14631477

14641478
bool OmpVisitor::NeedsScope(const parser::OpenMPBlockConstruct &x) {
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
! RUN: %python %S/../test_errors.py %s %flang_fc1 -fopenmp
2+
! Test that there are no errors for an empty critical construct
3+
4+
!$omp critical
5+
!$omp end critical
6+
end

0 commit comments

Comments
 (0)