Skip to content

Commit 2f66e5f

Browse files
committed
[OpenACC] Fixed error recovery during jump diagnostics for OpenACC
We didn't consider/test a case where the structured block/loop would be empty, which happens when the body is ONLY a break. Fixes: #140712
1 parent 4fa2c62 commit 2f66e5f

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

clang/lib/Sema/JumpDiagnostics.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -602,7 +602,10 @@ void JumpScopeChecker::BuildScopeInformation(Stmt *S,
602602
Scopes.push_back(GotoScope(
603603
ParentScope, diag::note_acc_branch_into_compute_construct,
604604
diag::note_acc_branch_out_of_compute_construct, CC->getBeginLoc()));
605-
BuildScopeInformation(CC->getStructuredBlock(), NewParentScope);
605+
// This can be 'null' if the 'body' is a break that we diagnosed, so no
606+
// reason to put the scope into place.
607+
if (CC->getStructuredBlock())
608+
BuildScopeInformation(CC->getStructuredBlock(), NewParentScope);
606609
return;
607610
}
608611

@@ -612,7 +615,10 @@ void JumpScopeChecker::BuildScopeInformation(Stmt *S,
612615
Scopes.push_back(GotoScope(
613616
ParentScope, diag::note_acc_branch_into_compute_construct,
614617
diag::note_acc_branch_out_of_compute_construct, CC->getBeginLoc()));
615-
BuildScopeInformation(CC->getLoop(), NewParentScope);
618+
// This can be 'null' if the 'body' is a break that we diagnosed, so no
619+
// reason to put the scope into place.
620+
if (CC->getLoop())
621+
BuildScopeInformation(CC->getLoop(), NewParentScope);
616622
return;
617623
}
618624

clang/test/SemaOpenACC/gh140712.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// RUN: %clang_cc1 %s -fopenacc -verify
2+
3+
void foo() {
4+
switch (int x = 0) {
5+
case 0:
6+
#pragma acc parallel
7+
break; // expected-error{{invalid branch out of OpenACC Compute/Combined Construct}}
8+
}
9+
}

0 commit comments

Comments
 (0)