[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
This commit is contained in:
@@ -602,7 +602,10 @@ void JumpScopeChecker::BuildScopeInformation(Stmt *S,
|
||||
Scopes.push_back(GotoScope(
|
||||
ParentScope, diag::note_acc_branch_into_compute_construct,
|
||||
diag::note_acc_branch_out_of_compute_construct, CC->getBeginLoc()));
|
||||
BuildScopeInformation(CC->getStructuredBlock(), NewParentScope);
|
||||
// This can be 'null' if the 'body' is a break that we diagnosed, so no
|
||||
// reason to put the scope into place.
|
||||
if (CC->getStructuredBlock())
|
||||
BuildScopeInformation(CC->getStructuredBlock(), NewParentScope);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -612,7 +615,10 @@ void JumpScopeChecker::BuildScopeInformation(Stmt *S,
|
||||
Scopes.push_back(GotoScope(
|
||||
ParentScope, diag::note_acc_branch_into_compute_construct,
|
||||
diag::note_acc_branch_out_of_compute_construct, CC->getBeginLoc()));
|
||||
BuildScopeInformation(CC->getLoop(), NewParentScope);
|
||||
// This can be 'null' if the 'body' is a break that we diagnosed, so no
|
||||
// reason to put the scope into place.
|
||||
if (CC->getLoop())
|
||||
BuildScopeInformation(CC->getLoop(), NewParentScope);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
9
clang/test/SemaOpenACC/gh140712.cpp
Normal file
9
clang/test/SemaOpenACC/gh140712.cpp
Normal file
@@ -0,0 +1,9 @@
|
||||
// RUN: %clang_cc1 %s -fopenacc -verify
|
||||
|
||||
void foo() {
|
||||
switch (int x = 0) {
|
||||
case 0:
|
||||
#pragma acc parallel
|
||||
break; // expected-error{{invalid branch out of OpenACC Compute/Combined Construct}}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user