[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:05:13 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:

>What is "ignorability"? Sorry, just asking to understand the context more correctly.

The idea is that we should be able to 'ignore' the pragmas and have the program still have meaning.  A big part of the 'theory' here is that you should be able to add pragmas to existing code and get 'descriptive' messages that show what you did wrong, and a pragma introducing a scope isnt really 'true' (so having it observably act as a scope seems wrong).

>These constructs, if enabled, should be pretty similar to lambdas, so I assume it should be fine to diagnose dangling break/continue here. The diagnostics might be improved, though.

I think the difference is that the lambda introduces a lookup scope/etc, whereas these pragmas aren't supposed to.  For example, setting the 'function' scope prevents something like:

```
auto foo(int i) {
#pragma acc parallel
int j = function_call();

return i + j;
}
```
from working. See : https://godbolt.org/z/Gq8Yen1vr (for the omp example).

This is actually something that is supposed to work in OpenACC, so introducing the scope makes that not work.

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


More information about the cfe-commits mailing list