[clang] [OpenACC] Implement 'break' and 'continue' errors for Compute Cnstrcts (PR #82543)
Erich Keane via cfe-commits
cfe-commits at lists.llvm.org
Wed Feb 21 14:16:22 PST 2024
================
@@ -3371,6 +3379,20 @@ Sema::ActOnBreakStmt(SourceLocation BreakLoc, Scope *CurScope) {
if (S->isOpenMPLoopScope())
return StmtError(Diag(BreakLoc, diag::err_omp_loop_cannot_use_stmt)
<< "break");
+
+ // OpenACC doesn't allow 'break'ing from a compute construct, so diagnose if
+ // we are trying to do so. This can come in 2 flavors: 1-the break'able thing
+ // (besides the compute construct) 'contains' the compute construct, at which
+ // point the 'break' scope will be the compute construct. Else it could be a
+ // loop of some sort that has a direct parent of the compute construct.
+ // However, a 'break' in a 'switch' marked as a compute construct doesn't
+ // count as 'branch out of' the compute construct.
+ if (S->isOpenACCComputeConstructScope() ||
+ (!S->isDirectlySwitchScope() && S->getParent() &&
----------------
erichkeane wrote:
This is covering 2 separate cases.
First:
```
switch(F) { <-- Switch scope
case 1:
#pragma acc parallel <-- compute-construct scope
break;
}
```
In this case, this is the pre-'||' check, the pragma's scope itself (created in ParseOpenACC.cpp) will be the 'break parent' of current, which cannot be broken from (so it is diagnosed). This can NEVER be a 'switch' scope, as it is a 'pragma acc compute-construct' scope.
Second:
```
#pragma acc parallel <-- compute construct scope
switch(F) { <-- switch scope
case 1:
break;
}
```
This is how the OpenMP variant of this diagnostic works, the 'scope' here is the 'switch scope'. Additionally, the 'parent' of this one is the Compute Construct scope. So everything after the '||' handles this. (note that `isOpenMPLoopScope` handles this by implicitly checking the 'parent'). Since we have the 'switch' scope (or other loop/scope/etc), we have to check that it is directly inside of the pragma scope. Since this one CAN be a 'switch'/any other loop/scope/etc, we have to check it, as well as checking the 'parent' for being an OpenACC Compute construct.
https://github.com/llvm/llvm-project/pull/82543
More information about the cfe-commits
mailing list