[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 15:15:58 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:

> Ok, I see. For OpenMP this is correct behavior per standard.
> 
> > And checking the 'is loop with a parent openacc scope' doesn't work if the openacc-pragma is inside the loop.
> 
> Why it does not work?

Because the statement might not be a loop!  So just saying, "is this a loop inside a pragma " would miss other cases where break could be valid (switch and statement exprs, and a few others).

https://github.com/llvm/llvm-project/pull/82543


More information about the cfe-commits mailing list