[clang] eca25bb - [OpenACC] Implement 'copyout' clause parsing.

via cfe-commits cfe-commits at lists.llvm.org
Tue Jan 16 07:04:36 PST 2024


Author: erichkeane
Date: 2024-01-16T07:04:28-08:00
New Revision: eca25bbdbb4f4681cd82de80e92b5f1315f0996a

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

LOG: [OpenACC] Implement 'copyout' clause parsing.

This is a fairly simple clause that just requires parsing a potential
'zero:' in front of a Clause var-list.  This patch implements/tests
that.

Added: 
    

Modified: 
    clang/include/clang/Basic/OpenACCKinds.h
    clang/lib/Parse/ParseOpenACC.cpp
    clang/test/ParserOpenACC/parse-clauses.c

Removed: 
    


################################################################################
diff  --git a/clang/include/clang/Basic/OpenACCKinds.h b/clang/include/clang/Basic/OpenACCKinds.h
index 399222dbf71b2a..8f85ffed784231 100644
--- a/clang/include/clang/Basic/OpenACCKinds.h
+++ b/clang/include/clang/Basic/OpenACCKinds.h
@@ -205,6 +205,9 @@ enum class OpenACCClauseKind {
   /// 'private' clause, allowed on 'parallel', 'serial', 'loop', 'parallel
   /// loop', and 'serial loop' constructs.
   Private,
+  /// 'copyout' clause, allowed on Compute and Combined constructs, plus 'data',
+  /// 'exit data', and 'declare'.
+  CopyOut,
 
   /// Represents an invalid clause, for the purposes of parsing.
   Invalid,
@@ -288,6 +291,9 @@ inline const StreamingDiagnostic &operator<<(const StreamingDiagnostic &Out,
   case OpenACCClauseKind::Private:
     return Out << "private";
 
+  case OpenACCClauseKind::CopyOut:
+    return Out << "copyout";
+
   case OpenACCClauseKind::Invalid:
     return Out << "<invalid>";
   }

diff  --git a/clang/lib/Parse/ParseOpenACC.cpp b/clang/lib/Parse/ParseOpenACC.cpp
index a5a028e1c6a799..cdc7cf24b66312 100644
--- a/clang/lib/Parse/ParseOpenACC.cpp
+++ b/clang/lib/Parse/ParseOpenACC.cpp
@@ -92,6 +92,7 @@ OpenACCClauseKind getOpenACCClauseKind(Token Tok) {
       .Case("attach", OpenACCClauseKind::Attach)
       .Case("auto", OpenACCClauseKind::Auto)
       .Case("copy", OpenACCClauseKind::Copy)
+      .Case("copyout", OpenACCClauseKind::CopyOut)
       .Case("default", OpenACCClauseKind::Default)
       .Case("delete", OpenACCClauseKind::Delete)
       .Case("detach", OpenACCClauseKind::Detach)
@@ -146,6 +147,7 @@ enum class OpenACCSpecialTokenKind {
   ReadOnly,
   DevNum,
   Queues,
+  Zero,
 };
 
 bool isOpenACCSpecialToken(OpenACCSpecialTokenKind Kind, Token Tok) {
@@ -159,6 +161,8 @@ bool isOpenACCSpecialToken(OpenACCSpecialTokenKind Kind, Token Tok) {
     return Tok.getIdentifierInfo()->isStr("devnum");
   case OpenACCSpecialTokenKind::Queues:
     return Tok.getIdentifierInfo()->isStr("queues");
+  case OpenACCSpecialTokenKind::Zero:
+    return Tok.getIdentifierInfo()->isStr("zero");
   }
   llvm_unreachable("Unknown 'Kind' Passed");
 }
@@ -395,6 +399,7 @@ ClauseParensKind getClauseParensKind(OpenACCClauseKind Kind) {
   case OpenACCClauseKind::Default:
   case OpenACCClauseKind::If:
   case OpenACCClauseKind::Copy:
+  case OpenACCClauseKind::CopyOut:
   case OpenACCClauseKind::UseDevice:
   case OpenACCClauseKind::NoCreate:
   case OpenACCClauseKind::Present:
@@ -554,6 +559,12 @@ bool Parser::ParseOpenACCClauseParams(OpenACCClauseKind Kind) {
         return true;
       break;
     }
+    case OpenACCClauseKind::CopyOut:
+      tryParseAndConsumeSpecialTokenKind(*this, OpenACCSpecialTokenKind::Zero,
+                                         Kind);
+      if (ParseOpenACCClauseVarList(Kind))
+        return true;
+      break;
     case OpenACCClauseKind::Attach:
     case OpenACCClauseKind::Copy:
     case OpenACCClauseKind::Delete:
@@ -696,7 +707,8 @@ ExprResult Parser::ParseOpenACCIDExpression() {
 /// - a common block name between slashes (fortran only)
 bool Parser::ParseOpenACCVar() {
   OpenACCArraySectionRAII ArraySections(*this);
-  ExprResult Res = ParseAssignmentExpression();
+  ExprResult Res =
+      getActions().CorrectDelayedTyposInExpr(ParseAssignmentExpression());
   return Res.isInvalid();
 }
 

diff  --git a/clang/test/ParserOpenACC/parse-clauses.c b/clang/test/ParserOpenACC/parse-clauses.c
index 053d007839dc71..bbabbf6b082fa2 100644
--- a/clang/test/ParserOpenACC/parse-clauses.c
+++ b/clang/test/ParserOpenACC/parse-clauses.c
@@ -497,6 +497,38 @@ void VarListClauses() {
   // expected-warning at +1{{OpenACC directives not yet implemented, pragma ignored}}
 #pragma acc serial device(s.array[s.value : 5], s.value), seq
 
+  // expected-error at +2{{expected ','}}
+  // expected-warning at +1{{OpenACC directives not yet implemented, pragma ignored}}
+#pragma acc serial copyout(s.array[s.value] s.array[s.value :5] ), seq
+
+  // expected-warning at +1{{OpenACC directives not yet implemented, pragma ignored}}
+#pragma acc serial copyout(s.array[s.value : 5], s.value), seq
+
+  // expected-warning at +1{{OpenACC directives not yet implemented, pragma ignored}}
+#pragma acc serial copyout(zero:s.array[s.value : 5], s.value), seq
+
+  // expected-warning at +1{{OpenACC directives not yet implemented, pragma ignored}}
+#pragma acc serial copyout(zero : s.array[s.value : 5], s.value), seq
+
+  // expected-error at +2{{use of undeclared identifier 'zero'}}
+  // expected-warning at +1{{OpenACC directives not yet implemented, pragma ignored}}
+#pragma acc serial copyout(zero s.array[s.value : 5], s.value), seq
+
+  // expected-error at +2{{invalid tag 'readonly' on 'copyout' clause}}
+  // expected-warning at +1{{OpenACC directives not yet implemented, pragma ignored}}
+#pragma acc serial copyout(readonly:s.array[s.value : 5], s.value), seq
+
+  // expected-error at +2{{invalid tag 'invalid' on 'copyout' clause}}
+  // expected-warning at +1{{OpenACC directives not yet implemented, pragma ignored}}
+#pragma acc serial copyout(invalid:s.array[s.value : 5], s.value), seq
+
+  // expected-error at +2{{invalid tag 'invalid' on 'copyout' clause}}
+  // expected-warning at +1{{OpenACC directives not yet implemented, pragma ignored}}
+#pragma acc serial copyout(invalid:s.array[s.value : 5], s.value), seq
+
+  // expected-error at +2{{use of undeclared identifier 'invalid'}}
+  // expected-warning at +1{{OpenACC directives not yet implemented, pragma ignored}}
+#pragma acc serial copyout(invalid s.array[s.value : 5], s.value), seq
 }
 
   // expected-warning at +1{{OpenACC directives not yet implemented, pragma ignored}}


        


More information about the cfe-commits mailing list