Skip to content

[flang][OpenMP] improve semantic check for invalid goto #144040

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 1 commit into from
Jun 13, 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
8 changes: 6 additions & 2 deletions flang/lib/Semantics/resolve-directives.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3023,10 +3023,14 @@ void OmpAttributeVisitor::CheckSourceLabel(const parser::Label &label) {
void OmpAttributeVisitor::CheckLabelContext(const parser::CharBlock source,
const parser::CharBlock target, std::optional<DirContext> sourceContext,
std::optional<DirContext> targetContext) {
auto dirContextsSame = [](DirContext &lhs, DirContext &rhs) -> bool {
// Sometimes nested constructs share a scope but are different contexts
return (lhs.scope == rhs.scope) && (lhs.directive == rhs.directive);
};
unsigned version{context_.langOptions().OpenMPVersion};
if (targetContext &&
(!sourceContext ||
(sourceContext->scope != targetContext->scope &&
(!dirContextsSame(*targetContext, *sourceContext) &&
!DoesScopeContain(
&targetContext->scope, sourceContext->scope)))) {
context_
Expand All @@ -3038,7 +3042,7 @@ void OmpAttributeVisitor::CheckLabelContext(const parser::CharBlock source,
}
if (sourceContext &&
(!targetContext ||
(sourceContext->scope != targetContext->scope &&
(!dirContextsSame(*sourceContext, *targetContext) &&
!DoesScopeContain(
&sourceContext->scope, targetContext->scope)))) {
context_
Expand Down
15 changes: 15 additions & 0 deletions flang/test/Semantics/OpenMP/parallel-master-goto.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
! RUN: %python %S/../test_errors.py %s %flang -fopenmp
! Regression test for #143229

!$omp parallel
do i = 1, 2
!ERROR: invalid branch into an OpenMP structured block
!ERROR: invalid branch leaving an OpenMP structured block
goto 10
end do
!WARNING: OpenMP directive MASTER has been deprecated, please use MASKED instead.
!$omp master
10 print *, i
!$omp end master
!$omp end parallel
end
Loading