[clang] [OpenACC] Implement 'break' and 'continue' errors for Compute Cnstrcts (PR #82543)
Erich Keane via cfe-commits
cfe-commits at lists.llvm.org
Thu Feb 22 07:11:36 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:
Sorry if I'm being dumb here, but I don't really get the question? We're trying to avoid diagnosing when the `breakParent` is a `switch`, so we are excluding it. If we were to NOT use the inversion, we would be diagnosing ONLY on a the switch (the opposite of what I want?).
So the logic for when to diagnose is:
`S->isOpenACCComputeConstructScope()` <-- Diagnose if the 'current' breakParent is a Compute Construct
OR
`(!S->isDirectlySwitchScope() && S->getParent() && S->getParent()->isOpenACCComputeConstructScope()))` <-- If the Parent of the `breakParent` is a Compute Construct, unless it is a `switch`.
https://github.com/llvm/llvm-project/pull/82543
More information about the cfe-commits
mailing list