Skip to content

Commit 6ca31ad

Browse files
authored
[flang][OpenMP] improve semantic check for invalid goto (#144040)
Fixes #143229
1 parent 4a47634 commit 6ca31ad

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

flang/lib/Semantics/resolve-directives.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3023,10 +3023,14 @@ void OmpAttributeVisitor::CheckSourceLabel(const parser::Label &label) {
30233023
void OmpAttributeVisitor::CheckLabelContext(const parser::CharBlock source,
30243024
const parser::CharBlock target, std::optional<DirContext> sourceContext,
30253025
std::optional<DirContext> targetContext) {
3026+
auto dirContextsSame = [](DirContext &lhs, DirContext &rhs) -> bool {
3027+
// Sometimes nested constructs share a scope but are different contexts
3028+
return (lhs.scope == rhs.scope) && (lhs.directive == rhs.directive);
3029+
};
30263030
unsigned version{context_.langOptions().OpenMPVersion};
30273031
if (targetContext &&
30283032
(!sourceContext ||
3029-
(sourceContext->scope != targetContext->scope &&
3033+
(!dirContextsSame(*targetContext, *sourceContext) &&
30303034
!DoesScopeContain(
30313035
&targetContext->scope, sourceContext->scope)))) {
30323036
context_
@@ -3038,7 +3042,7 @@ void OmpAttributeVisitor::CheckLabelContext(const parser::CharBlock source,
30383042
}
30393043
if (sourceContext &&
30403044
(!targetContext ||
3041-
(sourceContext->scope != targetContext->scope &&
3045+
(!dirContextsSame(*sourceContext, *targetContext) &&
30423046
!DoesScopeContain(
30433047
&sourceContext->scope, targetContext->scope)))) {
30443048
context_
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
! RUN: %python %S/../test_errors.py %s %flang -fopenmp
2+
! Regression test for #143229
3+
4+
!$omp parallel
5+
do i = 1, 2
6+
!ERROR: invalid branch into an OpenMP structured block
7+
!ERROR: invalid branch leaving an OpenMP structured block
8+
goto 10
9+
end do
10+
!WARNING: OpenMP directive MASTER has been deprecated, please use MASKED instead.
11+
!$omp master
12+
10 print *, i
13+
!$omp end master
14+
!$omp end parallel
15+
end

0 commit comments

Comments
 (0)