Author: erichkeane
Date: 2025-05-19T09:57:22-07:00
New Revision: e3950a049a8f098b8d28a9c89fe3f21f5c0b1682

URL: 
https://github.com/llvm/llvm-project/commit/e3950a049a8f098b8d28a9c89fe3f21f5c0b1682
DIFF: 
https://github.com/llvm/llvm-project/commit/e3950a049a8f098b8d28a9c89fe3f21f5c0b1682.diff

LOG: [OpenACC] Fix 'vector' checking when inside combined construct

For some reason when implementing 'vector' I didn't include switch
entries for the combined constructs.  I audited the rest of the uses of
this pattern, and got it right everywhere else, so I'm not sure why I
missed it here.

Fixes: #140339

Added: 
    clang/test/SemaOpenACC/gh140339.cpp

Modified: 
    clang/lib/Sema/SemaOpenACCClause.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/Sema/SemaOpenACCClause.cpp 
b/clang/lib/Sema/SemaOpenACCClause.cpp
index 88bd963a738ce..7249602f9cb04 100644
--- a/clang/lib/Sema/SemaOpenACCClause.cpp
+++ b/clang/lib/Sema/SemaOpenACCClause.cpp
@@ -1271,9 +1271,11 @@ OpenACCClause 
*SemaOpenACCClauseVisitor::VisitVectorClause(
       switch (SemaRef.getActiveComputeConstructInfo().Kind) {
       case OpenACCDirectiveKind::Invalid:
       case OpenACCDirectiveKind::Parallel:
+      case OpenACCDirectiveKind::ParallelLoop:
         // No restriction on when 'parallel' can contain an argument.
         break;
       case OpenACCDirectiveKind::Serial:
+      case OpenACCDirectiveKind::SerialLoop:
         // GCC disallows this, and there is no real good reason for us to 
permit
         // it, so disallow until we come up with a use case that makes sense.
         DiagIntArgInvalid(SemaRef, IntExpr, "length", 
OpenACCClauseKind::Vector,
@@ -1281,7 +1283,8 @@ OpenACCClause 
*SemaOpenACCClauseVisitor::VisitVectorClause(
                           SemaRef.getActiveComputeConstructInfo().Kind);
         IntExpr = nullptr;
         break;
-      case OpenACCDirectiveKind::Kernels: {
+      case OpenACCDirectiveKind::Kernels:
+      case OpenACCDirectiveKind::KernelsLoop: {
         const auto *Itr =
             llvm::find_if(SemaRef.getActiveComputeConstructInfo().Clauses,
                           llvm::IsaPred<OpenACCVectorLengthClause>);

diff  --git a/clang/test/SemaOpenACC/gh140339.cpp 
b/clang/test/SemaOpenACC/gh140339.cpp
new file mode 100644
index 0000000000000..8f94355c46654
--- /dev/null
+++ b/clang/test/SemaOpenACC/gh140339.cpp
@@ -0,0 +1,22 @@
+// RUN: %clang_cc1 %s -fopenacc -verify
+
+void foo() {
+#pragma acc parallel loop
+  for (int i = 0; i < 5; ++i) {
+#pragma acc loop vector(1)
+    for(int j = 0; j < 5; ++j);
+  }
+
+#pragma acc serial loop
+  for (int i = 0; i < 5; ++i) {
+    // expected-error@+1{{'length' argument on 'vector' clause is not 
permitted on a 'loop' construct associated with a 'serial loop' compute 
construct}}
+#pragma acc loop vector(1)
+    for(int j = 0; j < 5; ++j);
+  }
+
+#pragma acc kernels loop
+  for (int i = 0; i < 5; ++i) {
+#pragma acc loop vector(1)
+    for(int j = 0; j < 5; ++j);
+  }
+}


        
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to