[clang] 4e330fa - [OpenACC] Implement combined construct allowed-after device-type rule

via cfe-commits cfe-commits at lists.llvm.org
Wed Nov 13 12:18:22 PST 2024


Author: erichkeane
Date: 2024-11-13T12:18:15-08:00
New Revision: 4e330faac2b9a9172f4f16842196200989d6fbf3

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

LOG: [OpenACC] Implement combined construct allowed-after device-type rule

This patch implements the 'only X is allowed after' rule for combined
constructs on a device-type clause. This was left as a set of 'TODO' in
the previous patch, plus more issues were found with the TODO list,
    which are fixed here.

Added: 
    

Modified: 
    clang/lib/Sema/SemaOpenACC.cpp
    clang/test/SemaOpenACC/combined-construct-device_type-clause.c

Removed: 
    


################################################################################
diff  --git a/clang/lib/Sema/SemaOpenACC.cpp b/clang/lib/Sema/SemaOpenACC.cpp
index 7bf99eb7148761..78953a89f65e30 100644
--- a/clang/lib/Sema/SemaOpenACC.cpp
+++ b/clang/lib/Sema/SemaOpenACC.cpp
@@ -434,6 +434,7 @@ bool checkValidAfterDeviceType(
   // This is only a requirement on compute and loop constructs so far, so this
   // is fine otherwise.
   if (!isOpenACCComputeDirectiveKind(NewClause.getDirectiveKind()) &&
+      !isOpenACCCombinedDirectiveKind(NewClause.getDirectiveKind()) &&
       NewClause.getDirectiveKind() != OpenACCDirectiveKind::Loop)
     return false;
 

diff  --git a/clang/test/SemaOpenACC/combined-construct-device_type-clause.c b/clang/test/SemaOpenACC/combined-construct-device_type-clause.c
index 3d5cb7eb305b03..316fc905c13a98 100644
--- a/clang/test/SemaOpenACC/combined-construct-device_type-clause.c
+++ b/clang/test/SemaOpenACC/combined-construct-device_type-clause.c
@@ -43,14 +43,12 @@ void uses() {
 #pragma acc parallel loop device_type(*) vector
   for(int i = 0; i < 5; ++i);
 
-  // TODOexpected-error at +2{{OpenACC clause 'finalize' may not follow a 'device_type' clause in a 'serial loop' construct}}
-  // TODOexpected-note at +1{{previous clause is here}}
-  // expected-warning at +1{{OpenACC clause 'finalize' not yet implemented, clause ignored}}
+  // expected-error at +2{{OpenACC clause 'finalize' may not follow a 'device_type' clause in a 'serial loop' construct}}
+  // expected-note at +1{{previous clause is here}}
 #pragma acc serial loop device_type(*) finalize
   for(int i = 0; i < 5; ++i);
-  // TODOexpected-error at +2{{OpenACC clause 'if_present' may not follow a 'device_type' clause in a 'kernels loop' construct}}
-  // TODOexpected-note at +1{{previous clause is here}}
-  // expected-warning at +1{{OpenACC clause 'if_present' not yet implemented, clause ignored}}
+  // expected-error at +2{{OpenACC clause 'if_present' may not follow a 'device_type' clause in a 'kernels loop' construct}}
+  // expected-note at +1{{previous clause is here}}
 #pragma acc kernels loop device_type(*) if_present
   for(int i = 0; i < 5; ++i);
 #pragma acc parallel loop device_type(*) seq
@@ -62,133 +60,134 @@ void uses() {
   // expected-warning at +1{{OpenACC clause 'worker' not yet implemented, clause ignored}}
 #pragma acc parallel loop device_type(*) worker
   for(int i = 0; i < 5; ++i);
-  // TODOexpected-error at +2{{OpenACC clause 'nohost' may not follow a 'device_type' clause in a 'loop' construct}}
-  // TODOexpected-note at +1{{previous clause is here}}
-  // expected-warning at +1{{OpenACC clause 'nohost' not yet implemented, clause ignored}}
+  // expected-error at +2{{OpenACC clause 'nohost' may not follow a 'device_type' clause in a 'serial loop' construct}}
+  // expected-note at +1{{previous clause is here}}
 #pragma acc serial loop device_type(*) nohost
   for(int i = 0; i < 5; ++i);
-  // expected-warning at +1{{OpenACC clause 'default' not yet implemented, clause ignored}}
+  // expected-error at +2{{OpenACC clause 'default' may not follow a 'device_type' clause in a 'kernels loop' construct}}
+  // expected-note at +1{{previous clause is here}}
 #pragma acc kernels loop device_type(*) default(none)
   for(int i = 0; i < 5; ++i);
-  // expected-warning at +1{{OpenACC clause 'if' not yet implemented, clause ignored}}
+  // expected-error at +2{{OpenACC clause 'if' may not follow a 'device_type' clause in a 'parallel loop' construct}}
+  // expected-note at +1{{previous clause is here}}
 #pragma acc parallel loop device_type(*) if(1)
   for(int i = 0; i < 5; ++i);
-  // expected-warning at +1{{OpenACC clause 'self' not yet implemented, clause ignored}}
+  // expected-error at +2{{OpenACC clause 'self' may not follow a 'device_type' clause in a 'serial loop' construct}}
+  // expected-note at +1{{previous clause is here}}
 #pragma acc serial loop device_type(*) self
   for(int i = 0; i < 5; ++i);
 
   int Var;
   int *VarPtr;
-  // expected-warning at +1{{OpenACC clause 'copy' not yet implemented, clause ignored}}
+  // expected-error at +2{{OpenACC clause 'copy' may not follow a 'device_type' clause in a 'kernels loop' construct}}
+  // expected-note at +1{{previous clause is here}}
 #pragma acc kernels loop device_type(*) copy(Var)
   for(int i = 0; i < 5; ++i);
-  // expected-warning at +2{{OpenACC clause name 'pcopy' is a deprecated clause name and is now an alias for 'copy'}}
-  // expected-warning at +1{{OpenACC clause 'pcopy' not yet implemented, clause ignored}}
+  // expected-error at +2{{OpenACC clause 'pcopy' may not follow a 'device_type' clause in a 'parallel loop' construct}}
+  // expected-note at +1{{previous clause is here}}
 #pragma acc parallel loop device_type(*) pcopy(Var)
   for(int i = 0; i < 5; ++i);
-  // expected-warning at +2{{OpenACC clause name 'present_or_copy' is a deprecated clause name and is now an alias for 'copy'}}
-  // expected-warning at +1{{OpenACC clause 'present_or_copy' not yet implemented, clause ignored}}
+  // expected-error at +2{{OpenACC clause 'present_or_copy' may not follow a 'device_type' clause in a 'serial loop' construct}}
+  // expected-note at +1{{previous clause is here}}
 #pragma acc serial loop device_type(*) present_or_copy(Var)
   for(int i = 0; i < 5; ++i);
-  // TODOexpected-error at +2{{OpenACC clause 'use_device' may not follow a 'device_type' clause in a 'loop' construct}}
-  // TODOexpected-note at +1{{previous clause is here}}
-  // expected-warning at +1{{OpenACC clause 'use_device' not yet implemented, clause ignored}}
+  // expected-error at +2{{OpenACC clause 'use_device' may not follow a 'device_type' clause in a 'kernels loop' construct}}
+  // expected-note at +1{{previous clause is here}}
 #pragma acc kernels loop device_type(*) use_device(Var)
   for(int i = 0; i < 5; ++i);
-  // expected-warning at +1{{OpenACC clause 'attach' not yet implemented, clause ignored}}
+  // expected-error at +2{{OpenACC clause 'attach' may not follow a 'device_type' clause in a 'parallel loop' construct}}
+  // expected-note at +1{{previous clause is here}}
 #pragma acc parallel loop device_type(*) attach(Var)
   for(int i = 0; i < 5; ++i);
-  // TODOexpected-error at +2{{OpenACC clause 'delete' may not follow a 'device_type' clause in a 'loop' construct}}
-  // TODOexpected-note at +1{{previous clause is here}}
-  // expected-warning at +1{{OpenACC clause 'delete' not yet implemented, clause ignored}}
+  // expected-error at +2{{OpenACC clause 'delete' may not follow a 'device_type' clause in a 'serial loop' construct}}
+  // expected-note at +1{{previous clause is here}}
 #pragma acc serial loop device_type(*) delete(Var)
   for(int i = 0; i < 5; ++i);
-  // TODOexpected-error at +2{{OpenACC clause 'detach' may not follow a 'device_type' clause in a 'loop' construct}}
-  // TODOexpected-note at +1{{previous clause is here}}
-  // expected-warning at +1{{OpenACC clause 'detach' not yet implemented, clause ignored}}
+  // expected-error at +2{{OpenACC clause 'detach' may not follow a 'device_type' clause in a 'kernels loop' construct}}
+  // expected-note at +1{{previous clause is here}}
 #pragma acc kernels loop device_type(*) detach(Var)
   for(int i = 0; i < 5; ++i);
-  // TODOexpected-error at +2{{OpenACC clause 'device' may not follow a 'device_type' clause in a 'loop' construct}}
-  // TODOexpected-note at +1{{previous clause is here}}
-  // expected-warning at +1{{OpenACC clause 'device' not yet implemented, clause ignored}}
+  // expected-error at +2{{OpenACC clause 'device' may not follow a 'device_type' clause in a 'parallel loop' construct}}
+  // expected-note at +1{{previous clause is here}}
 #pragma acc parallel loop device_type(*) device(VarPtr)
   for(int i = 0; i < 5; ++i);
-  // expected-warning at +1{{OpenACC clause 'deviceptr' not yet implemented, clause ignored}}
+  // expected-error at +2{{OpenACC clause 'deviceptr' may not follow a 'device_type' clause in a 'serial loop' construct}}
+  // expected-note at +1{{previous clause is here}}
 #pragma acc serial loop device_type(*) deviceptr(VarPtr)
   for(int i = 0; i < 5; ++i);
-  // TODOexpected-error at +2{{OpenACC clause 'device_resident' may not follow a 'device_type' clause in a 'loop' construct}}
-  // TODOexpected-note at +1{{previous clause is here}}
-  // expected-warning at +1{{OpenACC clause 'device_resident' not yet implemented, clause ignored}}
+  // expected-error at +2{{OpenACC clause 'device_resident' may not follow a 'device_type' clause in a 'kernels loop' construct}}
+  // expected-note at +1{{previous clause is here}}
 #pragma acc kernels loop device_type(*)  device_resident(VarPtr)
   for(int i = 0; i < 5; ++i);
-  // expected-warning at +1{{OpenACC clause 'firstprivate' not yet implemented, clause ignored}}
+  // expected-error at +2{{OpenACC clause 'firstprivate' may not follow a 'device_type' clause in a 'parallel loop' construct}}
+  // expected-note at +1{{previous clause is here}}
 #pragma acc parallel loop device_type(*) firstprivate(Var)
   for(int i = 0; i < 5; ++i);
-  // TODOexpected-error at +2{{OpenACC clause 'host' may not follow a 'device_type' clause in a 'loop' construct}}
-  // TODOexpected-note at +1{{previous clause is here}}
-  // expected-warning at +1{{OpenACC clause 'host' not yet implemented, clause ignored}}
+  // expected-error at +2{{OpenACC clause 'host' may not follow a 'device_type' clause in a 'serial loop' construct}}
+  // expected-note at +1{{previous clause is here}}
 #pragma acc serial loop device_type(*) host(Var)
   for(int i = 0; i < 5; ++i);
-  // TODOexpected-error at +2{{OpenACC clause 'link' may not follow a 'device_type' clause in a 'loop' construct}}
-  // TODOexpected-note at +1{{previous clause is here}}
-  // expected-warning at +1{{OpenACC clause 'link' not yet implemented, clause ignored}}
+  // expected-error at +2{{OpenACC clause 'link' may not follow a 'device_type' clause in a 'parallel loop' construct}}
+  // expected-note at +1{{previous clause is here}}
 #pragma acc parallel loop device_type(*) link(Var)
   for(int i = 0; i < 5; ++i);
-  // expected-warning at +1{{OpenACC clause 'no_create' not yet implemented, clause ignored}}
+  // expected-error at +2{{OpenACC clause 'no_create' may not follow a 'device_type' clause in a 'serial loop' construct}}
+  // expected-note at +1{{previous clause is here}}
 #pragma acc serial loop device_type(*) no_create(Var)
   for(int i = 0; i < 5; ++i);
-  // expected-warning at +1{{OpenACC clause 'present' not yet implemented, clause ignored}}
+  // expected-error at +2{{OpenACC clause 'present' may not follow a 'device_type' clause in a 'kernels loop' construct}}
+  // expected-note at +1{{previous clause is here}}
 #pragma acc kernels loop device_type(*) present(Var)
   for(int i = 0; i < 5; ++i);
-  // TODOexpected-error at +2{{OpenACC clause 'private' may not follow a 'device_type' clause in a 'loop' construct}}
-  // TODOexpected-note at +1{{previous clause is here}}
-  // expected-warning at +1{{OpenACC clause 'private' not yet implemented, clause ignored}}
+  // expected-error at +2{{OpenACC clause 'private' may not follow a 'device_type' clause in a 'parallel loop' construct}}
+  // expected-note at +1{{previous clause is here}}
 #pragma acc parallel loop device_type(*) private(Var)
   for(int i = 0; i < 5; ++i);
-  // expected-warning at +1{{OpenACC clause 'copyout' not yet implemented, clause ignored}}
+  // expected-error at +2{{OpenACC clause 'copyout' may not follow a 'device_type' clause in a 'serial loop' construct}}
+  // expected-note at +1{{previous clause is here}}
 #pragma acc serial loop device_type(*) copyout(Var)
   for(int i = 0; i < 5; ++i);
-  // expected-warning at +2{{OpenACC clause name 'pcopyout' is a deprecated clause name and is now an alias for 'copyout'}}
-  // expected-warning at +1{{OpenACC clause 'pcopyout' not yet implemented, clause ignored}}
+  // expected-error at +2{{OpenACC clause 'pcopyout' may not follow a 'device_type' clause in a 'serial loop' construct}}
+  // expected-note at +1{{previous clause is here}}
 #pragma acc serial loop device_type(*) pcopyout(Var)
   for(int i = 0; i < 5; ++i);
-  // expected-warning at +2{{OpenACC clause name 'present_or_copyout' is a deprecated clause name and is now an alias for 'copyout'}}
-  // expected-warning at +1{{OpenACC clause 'present_or_copyout' not yet implemented, clause ignored}}
+  // expected-error at +2{{OpenACC clause 'present_or_copyout' may not follow a 'device_type' clause in a 'parallel loop' construct}}
+  // expected-note at +1{{previous clause is here}}
 #pragma acc parallel loop device_type(*) present_or_copyout(Var)
   for(int i = 0; i < 5; ++i);
-  // expected-warning at +1{{OpenACC clause 'copyin' not yet implemented, clause ignored}}
+  // expected-error at +2{{OpenACC clause 'copyin' may not follow a 'device_type' clause in a 'serial loop' construct}}
+  // expected-note at +1{{previous clause is here}}
 #pragma acc serial loop device_type(*) copyin(Var)
   for(int i = 0; i < 5; ++i);
-  // expected-warning at +2{{OpenACC clause name 'pcopyin' is a deprecated clause name and is now an alias for 'copyin'}}
-  // expected-warning at +1{{OpenACC clause 'pcopyin' not yet implemented, clause ignored}}
+  // expected-error at +2{{OpenACC clause 'pcopyin' may not follow a 'device_type' clause in a 'serial loop' construct}}
+  // expected-note at +1{{previous clause is here}}
 #pragma acc serial loop device_type(*) pcopyin(Var)
   for(int i = 0; i < 5; ++i);
-  // expected-warning at +2{{OpenACC clause name 'present_or_copyin' is a deprecated clause name and is now an alias for 'copyin'}}
-  // expected-warning at +1{{OpenACC clause 'present_or_copyin' not yet implemented, clause ignored}}
+  // expected-error at +2{{OpenACC clause 'present_or_copyin' may not follow a 'device_type' clause in a 'parallel loop' construct}}
+  // expected-note at +1{{previous clause is here}}
 #pragma acc parallel loop device_type(*) present_or_copyin(Var)
   for(int i = 0; i < 5; ++i);
-  // expected-warning at +1{{OpenACC clause 'create' not yet implemented, clause ignored}}
+  // expected-error at +2{{OpenACC clause 'create' may not follow a 'device_type' clause in a 'serial loop' construct}}
+  // expected-note at +1{{previous clause is here}}
 #pragma acc serial loop device_type(*) create(Var)
   for(int i = 0; i < 5; ++i);
-  // expected-warning at +2{{OpenACC clause name 'pcreate' is a deprecated clause name and is now an alias for 'create'}}
-  // expected-warning at +1{{OpenACC clause 'pcreate' not yet implemented, clause ignored}}
+  // expected-error at +2{{OpenACC clause 'pcreate' may not follow a 'device_type' clause in a 'serial loop' construct}}
+  // expected-note at +1{{previous clause is here}}
 #pragma acc serial loop device_type(*) pcreate(Var)
   for(int i = 0; i < 5; ++i);
-  // expected-warning at +2{{OpenACC clause name 'present_or_create' is a deprecated clause name and is now an alias for 'create'}}
-  // expected-warning at +1{{OpenACC clause 'present_or_create' not yet implemented, clause ignored}}
+  // expected-error at +2{{OpenACC clause 'present_or_create' may not follow a 'device_type' clause in a 'parallel loop' construct}}
+  // expected-note at +1{{previous clause is here}}
 #pragma acc parallel loop device_type(*) present_or_create(Var)
   for(int i = 0; i < 5; ++i);
-  // TODOexpected-error at +2{{OpenACC clause 'reduction' may not follow a 'device_type' clause in a 'loop' construct}}
-  // TODOexpected-note at +1{{previous clause is here}}
-  // expected-warning at +1{{OpenACC clause 'reduction' not yet implemented, clause ignored}}
+  // expected-error at +2{{OpenACC clause 'reduction' may not follow a 'device_type' clause in a 'serial loop' construct}}
+  // expected-note at +1{{previous clause is here}}
 #pragma acc serial loop device_type(*) reduction(+:Var)
   for(int i = 0; i < 5; ++i);
   // expected-warning at +1{{OpenACC clause 'collapse' not yet implemented, clause ignored}}
 #pragma acc serial loop device_type(*) collapse(1)
   for(int i = 0; i < 5; ++i);
-  // TODOexpected-error at +2{{OpenACC clause 'bind' may not follow a 'device_type' clause in a 'loop' construct}}
-  // TODOexpected-note at +1{{previous clause is here}}
-  // expected-warning at +1{{OpenACC clause 'bind' not yet implemented, clause ignored}}
+  // expected-error at +2{{OpenACC clause 'bind' may not follow a 'device_type' clause in a 'parallel loop' construct}}
+  // expected-note at +1{{previous clause is here}}
 #pragma acc parallel loop device_type(*) bind(Var)
   for(int i = 0; i < 5; ++i);
   // expected-error at +1{{OpenACC 'vector_length' clause is not valid on 'serial loop' directive}}
@@ -200,14 +199,12 @@ void uses() {
   // expected-warning at +1{{OpenACC clause 'num_workers' not yet implemented, clause ignored}}
 #pragma acc parallel loop device_type(*) num_workers(1)
   for(int i = 0; i < 5; ++i);
-  // TODOexpected-error at +2{{OpenACC clause 'device_num' may not follow a 'device_type' clause in a 'loop' construct}}
-  // TODOexpected-note at +1{{previous clause is here}}
-  // expected-warning at +1{{OpenACC clause 'device_num' not yet implemented, clause ignored}}
+  // expected-error at +2{{OpenACC clause 'device_num' may not follow a 'device_type' clause in a 'serial loop' construct}}
+  // expected-note at +1{{previous clause is here}}
 #pragma acc serial loop device_type(*) device_num(1)
   for(int i = 0; i < 5; ++i);
-  // TODOexpected-error at +2{{OpenACC clause 'default_async' may not follow a 'device_type' clause in a 'loop' construct}}
-  // TODOexpected-note at +1{{previous clause is here}}
-  // expected-warning at +1{{OpenACC clause 'default_async' not yet implemented, clause ignored}}
+  // expected-error at +2{{OpenACC clause 'default_async' may not follow a 'device_type' clause in a 'serial loop' construct}}
+  // expected-note at +1{{previous clause is here}}
 #pragma acc serial loop device_type(*) default_async(1)
   for(int i = 0; i < 5; ++i);
   // expected-warning at +1{{OpenACC clause 'async' not yet implemented, clause ignored}}


        


More information about the cfe-commits mailing list