[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:
erichkeane
2025-05-20 06:30:04 -07:00
parent 4fa2c62e32
commit 2f66e5fcba
2 changed files with 17 additions and 2 deletions

View File

@@ -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;
}

View 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}}
}
}