[clang] 6119340 - [OpenACC] Audit/add tests to ensure we enforce appertainment correctly

via cfe-commits cfe-commits at lists.llvm.org
Fri May 31 12:38:38 PDT 2024


Author: erichkeane
Date: 2024-05-31T12:38:33-07:00
New Revision: 6119340e0bc538fbb884cea405fd6add9ed5798c

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

LOG: [OpenACC] Audit/add tests to ensure we enforce appertainment correctly

I apparently missed a few other clauses as well when doing my initial
implementation, so this adds tests for all, and fixes up the few that
had problems.

This is something that I'll do better to keep an eye on, though
shouldn't be necessary once the rest of the clauses are implemented and
we can remove the 'default' case.

Added: 
    

Modified: 
    clang/lib/Sema/SemaOpenACC.cpp
    clang/test/SemaOpenACC/compute-construct-async-clause.c
    clang/test/SemaOpenACC/compute-construct-attach-clause.c
    clang/test/SemaOpenACC/compute-construct-copy-clause.c
    clang/test/SemaOpenACC/compute-construct-copyin-clause.c
    clang/test/SemaOpenACC/compute-construct-copyout-clause.c
    clang/test/SemaOpenACC/compute-construct-create-clause.c
    clang/test/SemaOpenACC/compute-construct-default-clause.c
    clang/test/SemaOpenACC/compute-construct-deviceptr-clause.c
    clang/test/SemaOpenACC/compute-construct-firstprivate-clause.c
    clang/test/SemaOpenACC/compute-construct-if-clause.c
    clang/test/SemaOpenACC/compute-construct-no_create-clause.c
    clang/test/SemaOpenACC/compute-construct-num_gangs-clause.c
    clang/test/SemaOpenACC/compute-construct-num_workers-clause.c
    clang/test/SemaOpenACC/compute-construct-present-clause.c
    clang/test/SemaOpenACC/compute-construct-private-clause.c
    clang/test/SemaOpenACC/compute-construct-reduction-clause.c
    clang/test/SemaOpenACC/compute-construct-self-clause.c
    clang/test/SemaOpenACC/compute-construct-vector_length-clause.c
    clang/test/SemaOpenACC/compute-construct-wait-clause.c

Removed: 
    


################################################################################
diff  --git a/clang/lib/Sema/SemaOpenACC.cpp b/clang/lib/Sema/SemaOpenACC.cpp
index 6ae3c64bbf82c..5b4d01860c0bd 100644
--- a/clang/lib/Sema/SemaOpenACC.cpp
+++ b/clang/lib/Sema/SemaOpenACC.cpp
@@ -170,6 +170,57 @@ bool doesClauseApplyToDirective(OpenACCDirectiveKind DirectiveKind,
     default:
       return false;
     }
+  case OpenACCClauseKind::CopyIn:
+  case OpenACCClauseKind::PCopyIn:
+  case OpenACCClauseKind::PresentOrCopyIn:
+    switch (DirectiveKind) {
+    case OpenACCDirectiveKind::Parallel:
+    case OpenACCDirectiveKind::Serial:
+    case OpenACCDirectiveKind::Kernels:
+    case OpenACCDirectiveKind::Data:
+    case OpenACCDirectiveKind::EnterData:
+    case OpenACCDirectiveKind::Declare:
+    case OpenACCDirectiveKind::ParallelLoop:
+    case OpenACCDirectiveKind::SerialLoop:
+    case OpenACCDirectiveKind::KernelsLoop:
+      return true;
+    default:
+      return false;
+    }
+  case OpenACCClauseKind::CopyOut:
+  case OpenACCClauseKind::PCopyOut:
+  case OpenACCClauseKind::PresentOrCopyOut:
+    switch (DirectiveKind) {
+    case OpenACCDirectiveKind::Parallel:
+    case OpenACCDirectiveKind::Serial:
+    case OpenACCDirectiveKind::Kernels:
+    case OpenACCDirectiveKind::Data:
+    case OpenACCDirectiveKind::ExitData:
+    case OpenACCDirectiveKind::Declare:
+    case OpenACCDirectiveKind::ParallelLoop:
+    case OpenACCDirectiveKind::SerialLoop:
+    case OpenACCDirectiveKind::KernelsLoop:
+      return true;
+    default:
+      return false;
+    }
+  case OpenACCClauseKind::Create:
+  case OpenACCClauseKind::PCreate:
+  case OpenACCClauseKind::PresentOrCreate:
+    switch (DirectiveKind) {
+    case OpenACCDirectiveKind::Parallel:
+    case OpenACCDirectiveKind::Serial:
+    case OpenACCDirectiveKind::Kernels:
+    case OpenACCDirectiveKind::Data:
+    case OpenACCDirectiveKind::EnterData:
+    case OpenACCDirectiveKind::ParallelLoop:
+    case OpenACCDirectiveKind::SerialLoop:
+    case OpenACCDirectiveKind::KernelsLoop:
+      return true;
+    default:
+      return false;
+    }
+
   case OpenACCClauseKind::Attach:
     switch (DirectiveKind) {
     case OpenACCDirectiveKind::Parallel:

diff  --git a/clang/test/SemaOpenACC/compute-construct-async-clause.c b/clang/test/SemaOpenACC/compute-construct-async-clause.c
index a8af06bc0afd6..999db74ffbb8b 100644
--- a/clang/test/SemaOpenACC/compute-construct-async-clause.c
+++ b/clang/test/SemaOpenACC/compute-construct-async-clause.c
@@ -38,4 +38,9 @@ void Test() {
 
 #pragma acc kernels async(SomeE)
   while(1);
+
+  // expected-error at +2{{OpenACC 'async' clause is not valid on 'loop' directive}}
+  // expected-warning at +1{{OpenACC construct 'loop' not yet implemented}}
+#pragma acc loop async(1)
+  for(;;);
 }

diff  --git a/clang/test/SemaOpenACC/compute-construct-attach-clause.c b/clang/test/SemaOpenACC/compute-construct-attach-clause.c
index deca99f5bae47..7696620271818 100644
--- a/clang/test/SemaOpenACC/compute-construct-attach-clause.c
+++ b/clang/test/SemaOpenACC/compute-construct-attach-clause.c
@@ -58,4 +58,9 @@ void uses() {
 
 #pragma acc parallel attach(s.PtrMem)
   while (1);
+
+  // expected-error at +2{{OpenACC 'attach' clause is not valid on 'loop' directive}}
+  // expected-warning at +1{{OpenACC construct 'loop' not yet implemented}}
+#pragma acc loop attach(LocalInt)
+  for(;;);
 }

diff  --git a/clang/test/SemaOpenACC/compute-construct-copy-clause.c b/clang/test/SemaOpenACC/compute-construct-copy-clause.c
index 2b43480be8b4f..7adf0e18fa042 100644
--- a/clang/test/SemaOpenACC/compute-construct-copy-clause.c
+++ b/clang/test/SemaOpenACC/compute-construct-copy-clause.c
@@ -59,4 +59,17 @@ void uses(int IntParam, short *PointerParam, float ArrayParam[5], Complete Compo
   // expected-error at +1{{OpenACC variable is not a valid variable name, sub-array, array element, member of a composite variable, or composite variable member}}
 #pragma acc parallel copy((float)ArrayParam[2])
   while(1);
+
+  // expected-error at +2{{OpenACC 'copy' clause is not valid on 'loop' directive}}
+  // expected-warning at +1{{OpenACC construct 'loop' not yet implemented}}
+#pragma acc loop copy(LocalInt)
+  for(;;);
+  // expected-error at +2{{OpenACC 'pcopy' clause is not valid on 'loop' directive}}
+  // expected-warning at +1{{OpenACC construct 'loop' not yet implemented}}
+#pragma acc loop pcopy(LocalInt)
+  for(;;);
+  // expected-error at +2{{OpenACC 'present_or_copy' clause is not valid on 'loop' directive}}
+  // expected-warning at +1{{OpenACC construct 'loop' not yet implemented}}
+#pragma acc loop present_or_copy(LocalInt)
+  for(;;);
 }

diff  --git a/clang/test/SemaOpenACC/compute-construct-copyin-clause.c b/clang/test/SemaOpenACC/compute-construct-copyin-clause.c
index 5ea4db9e5fae9..d557357756568 100644
--- a/clang/test/SemaOpenACC/compute-construct-copyin-clause.c
+++ b/clang/test/SemaOpenACC/compute-construct-copyin-clause.c
@@ -65,4 +65,17 @@ void uses(int IntParam, short *PointerParam, float ArrayParam[5], Complete Compo
   // expected-error at +1{{OpenACC variable is not a valid variable name, sub-array, array element, member of a composite variable, or composite variable member}}
 #pragma acc parallel copyin(invalid:(float)ArrayParam[2])
   while(1);
+
+  // expected-error at +2{{OpenACC 'copyin' clause is not valid on 'loop' directive}}
+  // expected-warning at +1{{OpenACC construct 'loop' not yet implemented}}
+#pragma acc loop copyin(LocalInt)
+  for(;;);
+  // expected-error at +2{{OpenACC 'pcopyin' clause is not valid on 'loop' directive}}
+  // expected-warning at +1{{OpenACC construct 'loop' not yet implemented}}
+#pragma acc loop pcopyin(LocalInt)
+  for(;;);
+  // expected-error at +2{{OpenACC 'present_or_copyin' clause is not valid on 'loop' directive}}
+  // expected-warning at +1{{OpenACC construct 'loop' not yet implemented}}
+#pragma acc loop present_or_copyin(LocalInt)
+  for(;;);
 }

diff  --git a/clang/test/SemaOpenACC/compute-construct-copyout-clause.c b/clang/test/SemaOpenACC/compute-construct-copyout-clause.c
index a035ab3242e3a..432823b6746a3 100644
--- a/clang/test/SemaOpenACC/compute-construct-copyout-clause.c
+++ b/clang/test/SemaOpenACC/compute-construct-copyout-clause.c
@@ -65,4 +65,17 @@ void uses(int IntParam, short *PointerParam, float ArrayParam[5], Complete Compo
   // expected-error at +1{{OpenACC variable is not a valid variable name, sub-array, array element, member of a composite variable, or composite variable member}}
 #pragma acc parallel copyout(invalid:(float)ArrayParam[2])
   while(1);
+
+  // expected-error at +2{{OpenACC 'copyout' clause is not valid on 'loop' directive}}
+  // expected-warning at +1{{OpenACC construct 'loop' not yet implemented}}
+#pragma acc loop copyout(LocalInt)
+  for(;;);
+  // expected-error at +2{{OpenACC 'pcopyout' clause is not valid on 'loop' directive}}
+  // expected-warning at +1{{OpenACC construct 'loop' not yet implemented}}
+#pragma acc loop pcopyout(LocalInt)
+  for(;;);
+  // expected-error at +2{{OpenACC 'present_or_copyout' clause is not valid on 'loop' directive}}
+  // expected-warning at +1{{OpenACC construct 'loop' not yet implemented}}
+#pragma acc loop present_or_copyout(LocalInt)
+  for(;;);
 }

diff  --git a/clang/test/SemaOpenACC/compute-construct-create-clause.c b/clang/test/SemaOpenACC/compute-construct-create-clause.c
index 5cfa9b0c5cc3c..319025c9628cf 100644
--- a/clang/test/SemaOpenACC/compute-construct-create-clause.c
+++ b/clang/test/SemaOpenACC/compute-construct-create-clause.c
@@ -66,4 +66,17 @@ void uses(int IntParam, short *PointerParam, float ArrayParam[5], Complete Compo
   // expected-error at +1{{OpenACC variable is not a valid variable name, sub-array, array element, member of a composite variable, or composite variable member}}
 #pragma acc parallel create(invalid:(float)ArrayParam[2])
   while(1);
+
+  // expected-error at +2{{OpenACC 'create' clause is not valid on 'loop' directive}}
+  // expected-warning at +1{{OpenACC construct 'loop' not yet implemented}}
+#pragma acc loop create(LocalInt)
+  for(;;);
+  // expected-error at +2{{OpenACC 'pcreate' clause is not valid on 'loop' directive}}
+  // expected-warning at +1{{OpenACC construct 'loop' not yet implemented}}
+#pragma acc loop pcreate(LocalInt)
+  for(;;);
+  // expected-error at +2{{OpenACC 'present_or_create' clause is not valid on 'loop' directive}}
+  // expected-warning at +1{{OpenACC construct 'loop' not yet implemented}}
+#pragma acc loop present_or_create(LocalInt)
+  for(;;);
 }

diff  --git a/clang/test/SemaOpenACC/compute-construct-default-clause.c b/clang/test/SemaOpenACC/compute-construct-default-clause.c
index b1235fcca1f6a..bcafb02cb4df1 100644
--- a/clang/test/SemaOpenACC/compute-construct-default-clause.c
+++ b/clang/test/SemaOpenACC/compute-construct-default-clause.c
@@ -52,4 +52,9 @@ void SingleOnly() {
   // expected-error at +1{{OpenACC 'default' clause is not valid on 'wait' directive}}
   #pragma acc wait default(none)
   while(0);
+
+  // expected-error at +2{{OpenACC 'default' clause is not valid on 'loop' directive}}
+  // expected-warning at +1{{OpenACC construct 'loop' not yet implemented}}
+#pragma acc loop default(present)
+  for(;;);
 }

diff  --git a/clang/test/SemaOpenACC/compute-construct-deviceptr-clause.c b/clang/test/SemaOpenACC/compute-construct-deviceptr-clause.c
index ae8269b9779a4..8ec911f6dbf1d 100644
--- a/clang/test/SemaOpenACC/compute-construct-deviceptr-clause.c
+++ b/clang/test/SemaOpenACC/compute-construct-deviceptr-clause.c
@@ -58,4 +58,9 @@ void uses() {
 
 #pragma acc parallel deviceptr(s.PtrMem)
   while (1);
+
+  // expected-error at +2{{OpenACC 'deviceptr' clause is not valid on 'loop' directive}}
+  // expected-warning at +1{{OpenACC construct 'loop' not yet implemented}}
+#pragma acc loop deviceptr(LocalInt)
+  for(;;);
 }

diff  --git a/clang/test/SemaOpenACC/compute-construct-firstprivate-clause.c b/clang/test/SemaOpenACC/compute-construct-firstprivate-clause.c
index eacda7bbbbba2..14f5af60cc855 100644
--- a/clang/test/SemaOpenACC/compute-construct-firstprivate-clause.c
+++ b/clang/test/SemaOpenACC/compute-construct-firstprivate-clause.c
@@ -52,4 +52,9 @@ void uses(int IntParam, short *PointerParam, float ArrayParam[5], Complete Compo
   // expected-error at +1{{OpenACC variable is not a valid variable name, sub-array, array element, member of a composite variable, or composite variable member}}
 #pragma acc parallel firstprivate((float)ArrayParam[2])
   while(1);
+
+  // expected-error at +2{{OpenACC 'firstprivate' clause is not valid on 'loop' directive}}
+  // expected-warning at +1{{OpenACC construct 'loop' not yet implemented}}
+#pragma acc loop firstprivate(LocalInt)
+  for(;;);
 }

diff  --git a/clang/test/SemaOpenACC/compute-construct-if-clause.c b/clang/test/SemaOpenACC/compute-construct-if-clause.c
index 767b8414b3a68..21e7ce413e908 100644
--- a/clang/test/SemaOpenACC/compute-construct-if-clause.c
+++ b/clang/test/SemaOpenACC/compute-construct-if-clause.c
@@ -59,4 +59,9 @@ void BoolExpr(int *I, float *F) {
   // expected-warning at +1{{OpenACC clause 'if' not yet implemented}}
 #pragma acc kernels loop if (*I < *F)
   while(0);
+
+  // expected-error at +2{{OpenACC 'if' clause is not valid on 'loop' directive}}
+  // expected-warning at +1{{OpenACC construct 'loop' not yet implemented}}
+#pragma acc loop if(I)
+  for(;;);
 }

diff  --git a/clang/test/SemaOpenACC/compute-construct-no_create-clause.c b/clang/test/SemaOpenACC/compute-construct-no_create-clause.c
index 4ff06eaf132b0..5afd644462147 100644
--- a/clang/test/SemaOpenACC/compute-construct-no_create-clause.c
+++ b/clang/test/SemaOpenACC/compute-construct-no_create-clause.c
@@ -51,4 +51,9 @@ void uses(int IntParam, short *PointerParam, float ArrayParam[5], Complete Compo
   // expected-error at +1{{OpenACC variable is not a valid variable name, sub-array, array element, member of a composite variable, or composite variable member}}
 #pragma acc parallel no_create((float)ArrayParam[2])
   while(1);
+
+  // expected-error at +2{{OpenACC 'no_create' clause is not valid on 'loop' directive}}
+  // expected-warning at +1{{OpenACC construct 'loop' not yet implemented}}
+#pragma acc loop no_create(LocalInt)
+  for(;;);
 }

diff  --git a/clang/test/SemaOpenACC/compute-construct-num_gangs-clause.c b/clang/test/SemaOpenACC/compute-construct-num_gangs-clause.c
index cdc6847b47f94..9c2a5a781059e 100644
--- a/clang/test/SemaOpenACC/compute-construct-num_gangs-clause.c
+++ b/clang/test/SemaOpenACC/compute-construct-num_gangs-clause.c
@@ -51,4 +51,9 @@ void Test() {
   // expected-error at +1{{too many integer expression arguments provided to OpenACC 'num_gangs' clause: 'parallel' directive expects maximum of 3, 4 were provided}}
 #pragma acc parallel num_gangs(getS(), 1, getS(), 1)
   while(1);
+
+  // expected-error at +2{{OpenACC 'num_gangs' clause is not valid on 'loop' directive}}
+  // expected-warning at +1{{OpenACC construct 'loop' not yet implemented}}
+#pragma acc loop num_gangs(1)
+  for(;;);
 }

diff  --git a/clang/test/SemaOpenACC/compute-construct-num_workers-clause.c b/clang/test/SemaOpenACC/compute-construct-num_workers-clause.c
index 19e247a2f810a..a84bd3699536a 100644
--- a/clang/test/SemaOpenACC/compute-construct-num_workers-clause.c
+++ b/clang/test/SemaOpenACC/compute-construct-num_workers-clause.c
@@ -30,4 +30,9 @@ void Test() {
 
 #pragma acc kernels num_workers(SomeE)
   while(1);
+
+  // expected-error at +2{{OpenACC 'num_workers' clause is not valid on 'loop' directive}}
+  // expected-warning at +1{{OpenACC construct 'loop' not yet implemented}}
+#pragma acc loop num_workers(1)
+  for(;;);
 }

diff  --git a/clang/test/SemaOpenACC/compute-construct-present-clause.c b/clang/test/SemaOpenACC/compute-construct-present-clause.c
index 1d50a6b1275b8..5ace750da7efe 100644
--- a/clang/test/SemaOpenACC/compute-construct-present-clause.c
+++ b/clang/test/SemaOpenACC/compute-construct-present-clause.c
@@ -51,4 +51,9 @@ void uses(int IntParam, short *PointerParam, float ArrayParam[5], Complete Compo
   // expected-error at +1{{OpenACC variable is not a valid variable name, sub-array, array element, member of a composite variable, or composite variable member}}
 #pragma acc parallel present((float)ArrayParam[2])
   while(1);
+
+  // expected-error at +2{{OpenACC 'present' clause is not valid on 'loop' directive}}
+  // expected-warning at +1{{OpenACC construct 'loop' not yet implemented}}
+#pragma acc loop present(LocalInt)
+  for(;;);
 }

diff  --git a/clang/test/SemaOpenACC/compute-construct-private-clause.c b/clang/test/SemaOpenACC/compute-construct-private-clause.c
index 3e6dbaafbc6fa..d979fd909f11c 100644
--- a/clang/test/SemaOpenACC/compute-construct-private-clause.c
+++ b/clang/test/SemaOpenACC/compute-construct-private-clause.c
@@ -134,4 +134,9 @@ void uses(int IntParam, short *PointerParam, float ArrayParam[5], Complete Compo
   // expected-error at +1{{OpenACC variable is not a valid variable name, sub-array, array element, member of a composite variable, or composite variable member}}
 #pragma acc parallel private((float)ArrayParam[2])
   while(1);
+
+  // expected-error at +2{{OpenACC 'private' clause is not valid on 'init' directive}}
+  // expected-warning at +1{{OpenACC construct 'init' not yet implemented}}
+#pragma acc init private(LocalInt)
+  for(;;);
 }

diff  --git a/clang/test/SemaOpenACC/compute-construct-reduction-clause.c b/clang/test/SemaOpenACC/compute-construct-reduction-clause.c
index 9c0debd345031..80310f0e7afc6 100644
--- a/clang/test/SemaOpenACC/compute-construct-reduction-clause.c
+++ b/clang/test/SemaOpenACC/compute-construct-reduction-clause.c
@@ -104,4 +104,9 @@ void uses(unsigned Parm) {
   // expected-error at +1{{OpenACC variable is not a valid variable name, sub-array, array element, or composite variable member}}
 #pragma acc parallel reduction(&:HA.array[1:2])
   while (1);
+
+  // expected-error at +2{{OpenACC 'reduction' clause is not valid on 'init' directive}}
+  // expected-warning at +1{{OpenACC construct 'init' not yet implemented}}
+#pragma acc init reduction(+:I)
+  for(;;);
 }

diff  --git a/clang/test/SemaOpenACC/compute-construct-self-clause.c b/clang/test/SemaOpenACC/compute-construct-self-clause.c
index fbed2953419a2..634a2d8857b7e 100644
--- a/clang/test/SemaOpenACC/compute-construct-self-clause.c
+++ b/clang/test/SemaOpenACC/compute-construct-self-clause.c
@@ -79,4 +79,9 @@ void WarnMaybeNotUsed(int val1, int val2) {
   // expected-error at +1{{use of undeclared identifier 'invalid'}}
 #pragma acc parallel if(invalid) self(val1)
   while(0);
+
+  // expected-error at +2{{OpenACC 'self' clause is not valid on 'loop' directive}}
+  // expected-warning at +1{{OpenACC construct 'loop' not yet implemented}}
+#pragma acc loop self
+  for(;;);
 }

diff  --git a/clang/test/SemaOpenACC/compute-construct-vector_length-clause.c b/clang/test/SemaOpenACC/compute-construct-vector_length-clause.c
index cd85bdefb602d..83055f81fbb2c 100644
--- a/clang/test/SemaOpenACC/compute-construct-vector_length-clause.c
+++ b/clang/test/SemaOpenACC/compute-construct-vector_length-clause.c
@@ -30,4 +30,9 @@ void Test() {
 
 #pragma acc kernels vector_length(SomeE)
   while(1);
+
+  // expected-error at +2{{OpenACC 'vector_length' clause is not valid on 'loop' directive}}
+  // expected-warning at +1{{OpenACC construct 'loop' not yet implemented}}
+#pragma acc loop vector_length(1)
+  for(;;);
 }

diff  --git a/clang/test/SemaOpenACC/compute-construct-wait-clause.c b/clang/test/SemaOpenACC/compute-construct-wait-clause.c
index 254aba8442fee..0878288ca4a2c 100644
--- a/clang/test/SemaOpenACC/compute-construct-wait-clause.c
+++ b/clang/test/SemaOpenACC/compute-construct-wait-clause.c
@@ -35,4 +35,9 @@ void uses() {
   // expected-error at +1{{OpenACC clause 'wait' requires expression of integer type ('struct NotConvertible' invalid)}}
 #pragma acc parallel wait(devnum:arr : queues: arr, NC, 5)
   while(1);
+
+  // expected-error at +2{{OpenACC 'wait' clause is not valid on 'loop' directive}}
+  // expected-warning at +1{{OpenACC construct 'loop' not yet implemented}}
+#pragma acc loop wait
+  for(;;);
 }


        


More information about the cfe-commits mailing list