[clang] [OpenACC] Add 'clause' parsing infrastructure plus a few clauses (PR #75052)

2023-12-18 Thread Erich Keane via cfe-commits

https://github.com/erichkeane closed 
https://github.com/llvm/llvm-project/pull/75052
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [OpenACC] Add 'clause' parsing infrastructure plus a few clauses (PR #75052)

2023-12-18 Thread Erich Keane via cfe-commits

https://github.com/erichkeane updated 
https://github.com/llvm/llvm-project/pull/75052

>From 0bcee977f95f87a5ccf7bc53d6cd0a5d9521d963 Mon Sep 17 00:00:00 2001
From: erichkeane 
Date: Fri, 8 Dec 2023 09:18:40 -0800
Subject: [PATCH 1/4] [OpenACC] Add 'clause' parsing infrastructure plus a few
 clauses

As we've now finished parsing the constructs, we're moving onto
implementing 'clause' parsing.  While some are complicated and require
their own patch, the handful added here are simple to parse (that is,
they are a single identifier).

This patch adds the infrastructure to parse these and a clause-list in
its entirety. This adds some complication to how we are diagnosing
parsing errors elsewhere, so a few changes were made to better recover
from errors.
---
 .../clang/Basic/DiagnosticParseKinds.td   |  4 +-
 clang/include/clang/Basic/OpenACCKinds.h  | 13 +++
 clang/lib/Parse/ParseOpenACC.cpp  | 86 +--
 .../ParserOpenACC/parse-cache-construct.c |  4 +-
 clang/test/ParserOpenACC/parse-clauses.c  | 64 ++
 clang/test/ParserOpenACC/parse-constructs.c   | 68 +++
 .../test/ParserOpenACC/parse-wait-construct.c | 24 +++---
 clang/test/ParserOpenACC/unimplemented.c  |  6 +-
 clang/test/ParserOpenACC/unimplemented.cpp|  6 +-
 9 files changed, 208 insertions(+), 67 deletions(-)
 create mode 100644 clang/test/ParserOpenACC/parse-clauses.c

diff --git a/clang/include/clang/Basic/DiagnosticParseKinds.td 
b/clang/include/clang/Basic/DiagnosticParseKinds.td
index 6150fc36430ab1..e4b1069cde1850 100644
--- a/clang/include/clang/Basic/DiagnosticParseKinds.td
+++ b/clang/include/clang/Basic/DiagnosticParseKinds.td
@@ -1358,11 +1358,9 @@ def err_acc_unexpected_directive
 def warn_pragma_acc_unimplemented
 : Warning<"OpenACC directives not yet implemented, pragma ignored">,
   InGroup;
-def warn_pragma_acc_unimplemented_clause_parsing
-: Warning<"OpenACC clause parsing not yet implemented">,
-  InGroup;
 def err_acc_invalid_directive
 : Error<"invalid OpenACC directive %select{%1|'%1 %2'}0">;
+def err_acc_invalid_clause : Error<"invalid OpenACC clause %0">;
 def err_acc_missing_directive : Error<"expected OpenACC directive">;
 def err_acc_invalid_open_paren
 : Error<"expected clause-list or newline in OpenACC directive">;
diff --git a/clang/include/clang/Basic/OpenACCKinds.h 
b/clang/include/clang/Basic/OpenACCKinds.h
index 62c0a4c1a9dea4..e907c192ed6d29 100644
--- a/clang/include/clang/Basic/OpenACCKinds.h
+++ b/clang/include/clang/Basic/OpenACCKinds.h
@@ -69,6 +69,19 @@ enum class OpenACCAtomicKind {
   Capture,
   Invalid,
 };
+
+// Represents the kind of an OpenACC clause.
+enum class OpenACCClauseKind {
+  Finalize,
+  IfPresent,
+  Seq,
+  Independent,
+  Auto,
+  Worker,
+  Vector,
+  NoHost,
+  Invalid,
+};
 } // namespace clang
 
 #endif // LLVM_CLANG_BASIC_OPENACCKINDS_H
diff --git a/clang/lib/Parse/ParseOpenACC.cpp b/clang/lib/Parse/ParseOpenACC.cpp
index f7f096762e91a6..2ad296e23e8f00 100644
--- a/clang/lib/Parse/ParseOpenACC.cpp
+++ b/clang/lib/Parse/ParseOpenACC.cpp
@@ -69,6 +69,29 @@ OpenACCDirectiveKindEx getOpenACCDirectiveKind(Token Tok) {
   .Default(OpenACCDirectiveKindEx::Invalid);
 }
 
+// Translate single-token string representations to the OpenCC Clause Kind.
+OpenACCClauseKind getOpenACCClauseKind(Token Tok) {
+  // auto is a keyword in some language modes, so make sure we parse it
+  // correctly.
+  if (Tok.is(tok::kw_auto))
+return OpenACCClauseKind::Auto;
+
+  if (!Tok.is(tok::identifier))
+return OpenACCClauseKind::Invalid;
+
+  return llvm::StringSwitch(
+  Tok.getIdentifierInfo()->getName())
+.Case("finalize", OpenACCClauseKind::Finalize)
+.Case("if_present", OpenACCClauseKind::IfPresent)
+.Case("seq", OpenACCClauseKind::Seq)
+.Case("independent", OpenACCClauseKind::Independent)
+.Case("auto", OpenACCClauseKind::Auto)
+.Case("worker", OpenACCClauseKind::Worker)
+.Case("vector", OpenACCClauseKind::Vector)
+.Case("nohost", OpenACCClauseKind::NoHost)
+.Default(OpenACCClauseKind::Invalid);
+}
+
 // Since 'atomic' is effectively a compound directive, this will decode the
 // second part of the directive.
 OpenACCAtomicKind getOpenACCAtomicKind(Token Tok) {
@@ -164,6 +187,10 @@ ParseOpenACCEnterExitDataDirective(Parser , Token 
FirstTok,
 return OpenACCDirectiveKind::Invalid;
   }
 
+  // Consume the second name anyway, this way we can continue on without making
+  // this oddly look like a clause.
+  P.ConsumeAnyToken();
+
   if (!isOpenACCDirectiveKind(OpenACCDirectiveKind::Data, SecondTok)) {
 if (!SecondTok.is(tok::identifier))
   P.Diag(SecondTok, diag::err_expected) << tok::identifier;
@@ -174,8 +201,6 @@ ParseOpenACCEnterExitDataDirective(Parser , Token 
FirstTok,
 return OpenACCDirectiveKind::Invalid;
   }
 
-  P.ConsumeToken();
-
   return ExtDirKind == OpenACCDirectiveKindEx::Enter
  ? 

[clang] [OpenACC] Add 'clause' parsing infrastructure plus a few clauses (PR #75052)

2023-12-18 Thread Alexey Bataev via cfe-commits

alexey-bataev wrote:

LG with nits

https://github.com/llvm/llvm-project/pull/75052
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [OpenACC] Add 'clause' parsing infrastructure plus a few clauses (PR #75052)

2023-12-18 Thread Alexey Bataev via cfe-commits


@@ -69,6 +69,19 @@ enum class OpenACCAtomicKind {
   Capture,
   Invalid,
 };
+
+// Represents the kind of an OpenACC clause.
+enum class OpenACCClauseKind {
+  Finalize,

alexey-bataev wrote:

Add the comments with the description of each clause kind?

https://github.com/llvm/llvm-project/pull/75052
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [OpenACC] Add 'clause' parsing infrastructure plus a few clauses (PR #75052)

2023-12-18 Thread Alexey Bataev via cfe-commits

https://github.com/alexey-bataev approved this pull request.


https://github.com/llvm/llvm-project/pull/75052
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [OpenACC] Add 'clause' parsing infrastructure plus a few clauses (PR #75052)

2023-12-18 Thread Alexey Bataev via cfe-commits


@@ -69,6 +69,19 @@ enum class OpenACCAtomicKind {
   Capture,
   Invalid,
 };
+
+// Represents the kind of an OpenACC clause.

alexey-bataev wrote:

Use '///' kind of comment here

https://github.com/llvm/llvm-project/pull/75052
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [OpenACC] Add 'clause' parsing infrastructure plus a few clauses (PR #75052)

2023-12-18 Thread Alexey Bataev via cfe-commits

https://github.com/alexey-bataev edited 
https://github.com/llvm/llvm-project/pull/75052
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [OpenACC] Add 'clause' parsing infrastructure plus a few clauses (PR #75052)

2023-12-18 Thread via cfe-commits


@@ -262,12 +291,52 @@ OpenACCDirectiveKind ParseOpenACCDirectiveKind(Parser ) 
{
   return DirKind;
 }
 
+bool ParseOpenACCClause(Parser ) {

cor3ntin wrote:

Thanks

https://github.com/llvm/llvm-project/pull/75052
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [OpenACC] Add 'clause' parsing infrastructure plus a few clauses (PR #75052)

2023-12-18 Thread via cfe-commits

https://github.com/cor3ntin approved this pull request.

LGTM

https://github.com/llvm/llvm-project/pull/75052
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [OpenACC] Add 'clause' parsing infrastructure plus a few clauses (PR #75052)

2023-12-18 Thread via cfe-commits

https://github.com/cor3ntin edited 
https://github.com/llvm/llvm-project/pull/75052
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [OpenACC] Add 'clause' parsing infrastructure plus a few clauses (PR #75052)

2023-12-18 Thread via cfe-commits


@@ -69,6 +69,29 @@ OpenACCDirectiveKindEx getOpenACCDirectiveKind(Token Tok) {
   .Default(OpenACCDirectiveKindEx::Invalid);
 }
 
+// Translate single-token string representations to the OpenCC Clause Kind.
+OpenACCClauseKind getOpenACCClauseKind(Token Tok) {

cor3ntin wrote:

I missed that!

https://github.com/llvm/llvm-project/pull/75052
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [OpenACC] Add 'clause' parsing infrastructure plus a few clauses (PR #75052)

2023-12-13 Thread Erich Keane via cfe-commits

https://github.com/erichkeane updated 
https://github.com/llvm/llvm-project/pull/75052

>From 0bcee977f95f87a5ccf7bc53d6cd0a5d9521d963 Mon Sep 17 00:00:00 2001
From: erichkeane 
Date: Fri, 8 Dec 2023 09:18:40 -0800
Subject: [PATCH 1/3] [OpenACC] Add 'clause' parsing infrastructure plus a few
 clauses

As we've now finished parsing the constructs, we're moving onto
implementing 'clause' parsing.  While some are complicated and require
their own patch, the handful added here are simple to parse (that is,
they are a single identifier).

This patch adds the infrastructure to parse these and a clause-list in
its entirety. This adds some complication to how we are diagnosing
parsing errors elsewhere, so a few changes were made to better recover
from errors.
---
 .../clang/Basic/DiagnosticParseKinds.td   |  4 +-
 clang/include/clang/Basic/OpenACCKinds.h  | 13 +++
 clang/lib/Parse/ParseOpenACC.cpp  | 86 +--
 .../ParserOpenACC/parse-cache-construct.c |  4 +-
 clang/test/ParserOpenACC/parse-clauses.c  | 64 ++
 clang/test/ParserOpenACC/parse-constructs.c   | 68 +++
 .../test/ParserOpenACC/parse-wait-construct.c | 24 +++---
 clang/test/ParserOpenACC/unimplemented.c  |  6 +-
 clang/test/ParserOpenACC/unimplemented.cpp|  6 +-
 9 files changed, 208 insertions(+), 67 deletions(-)
 create mode 100644 clang/test/ParserOpenACC/parse-clauses.c

diff --git a/clang/include/clang/Basic/DiagnosticParseKinds.td 
b/clang/include/clang/Basic/DiagnosticParseKinds.td
index 6150fc36430ab1..e4b1069cde1850 100644
--- a/clang/include/clang/Basic/DiagnosticParseKinds.td
+++ b/clang/include/clang/Basic/DiagnosticParseKinds.td
@@ -1358,11 +1358,9 @@ def err_acc_unexpected_directive
 def warn_pragma_acc_unimplemented
 : Warning<"OpenACC directives not yet implemented, pragma ignored">,
   InGroup;
-def warn_pragma_acc_unimplemented_clause_parsing
-: Warning<"OpenACC clause parsing not yet implemented">,
-  InGroup;
 def err_acc_invalid_directive
 : Error<"invalid OpenACC directive %select{%1|'%1 %2'}0">;
+def err_acc_invalid_clause : Error<"invalid OpenACC clause %0">;
 def err_acc_missing_directive : Error<"expected OpenACC directive">;
 def err_acc_invalid_open_paren
 : Error<"expected clause-list or newline in OpenACC directive">;
diff --git a/clang/include/clang/Basic/OpenACCKinds.h 
b/clang/include/clang/Basic/OpenACCKinds.h
index 62c0a4c1a9dea4..e907c192ed6d29 100644
--- a/clang/include/clang/Basic/OpenACCKinds.h
+++ b/clang/include/clang/Basic/OpenACCKinds.h
@@ -69,6 +69,19 @@ enum class OpenACCAtomicKind {
   Capture,
   Invalid,
 };
+
+// Represents the kind of an OpenACC clause.
+enum class OpenACCClauseKind {
+  Finalize,
+  IfPresent,
+  Seq,
+  Independent,
+  Auto,
+  Worker,
+  Vector,
+  NoHost,
+  Invalid,
+};
 } // namespace clang
 
 #endif // LLVM_CLANG_BASIC_OPENACCKINDS_H
diff --git a/clang/lib/Parse/ParseOpenACC.cpp b/clang/lib/Parse/ParseOpenACC.cpp
index f7f096762e91a6..2ad296e23e8f00 100644
--- a/clang/lib/Parse/ParseOpenACC.cpp
+++ b/clang/lib/Parse/ParseOpenACC.cpp
@@ -69,6 +69,29 @@ OpenACCDirectiveKindEx getOpenACCDirectiveKind(Token Tok) {
   .Default(OpenACCDirectiveKindEx::Invalid);
 }
 
+// Translate single-token string representations to the OpenCC Clause Kind.
+OpenACCClauseKind getOpenACCClauseKind(Token Tok) {
+  // auto is a keyword in some language modes, so make sure we parse it
+  // correctly.
+  if (Tok.is(tok::kw_auto))
+return OpenACCClauseKind::Auto;
+
+  if (!Tok.is(tok::identifier))
+return OpenACCClauseKind::Invalid;
+
+  return llvm::StringSwitch(
+  Tok.getIdentifierInfo()->getName())
+.Case("finalize", OpenACCClauseKind::Finalize)
+.Case("if_present", OpenACCClauseKind::IfPresent)
+.Case("seq", OpenACCClauseKind::Seq)
+.Case("independent", OpenACCClauseKind::Independent)
+.Case("auto", OpenACCClauseKind::Auto)
+.Case("worker", OpenACCClauseKind::Worker)
+.Case("vector", OpenACCClauseKind::Vector)
+.Case("nohost", OpenACCClauseKind::NoHost)
+.Default(OpenACCClauseKind::Invalid);
+}
+
 // Since 'atomic' is effectively a compound directive, this will decode the
 // second part of the directive.
 OpenACCAtomicKind getOpenACCAtomicKind(Token Tok) {
@@ -164,6 +187,10 @@ ParseOpenACCEnterExitDataDirective(Parser , Token 
FirstTok,
 return OpenACCDirectiveKind::Invalid;
   }
 
+  // Consume the second name anyway, this way we can continue on without making
+  // this oddly look like a clause.
+  P.ConsumeAnyToken();
+
   if (!isOpenACCDirectiveKind(OpenACCDirectiveKind::Data, SecondTok)) {
 if (!SecondTok.is(tok::identifier))
   P.Diag(SecondTok, diag::err_expected) << tok::identifier;
@@ -174,8 +201,6 @@ ParseOpenACCEnterExitDataDirective(Parser , Token 
FirstTok,
 return OpenACCDirectiveKind::Invalid;
   }
 
-  P.ConsumeToken();
-
   return ExtDirKind == OpenACCDirectiveKindEx::Enter
  ? 

[clang] [OpenACC] Add 'clause' parsing infrastructure plus a few clauses (PR #75052)

2023-12-13 Thread Erich Keane via cfe-commits


@@ -262,12 +291,52 @@ OpenACCDirectiveKind ParseOpenACCDirectiveKind(Parser ) 
{
   return DirKind;
 }
 
+bool ParseOpenACCClause(Parser ) {

erichkeane wrote:

So the individual clauses each have their own 'grammar'.  I DID comment the 
'clause-list' below best I could, but there is no  clause 'grammar' in the 
standard.  The one's ive mentioned are the ones where it is all a single 
identifier-token (or 'auto' as you've seen :/).

I'll spend a few moments typing something up to make this more clear however.

https://github.com/llvm/llvm-project/pull/75052
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [OpenACC] Add 'clause' parsing infrastructure plus a few clauses (PR #75052)

2023-12-13 Thread Erich Keane via cfe-commits


@@ -208,6 +233,10 @@ OpenACCDirectiveKind ParseOpenACCDirectiveKind(Parser ) {
   // introspect on the spelling before then.
   if (FirstTok.isNot(tok::identifier)) {
 P.Diag(FirstTok, diag::err_acc_missing_directive);
+
+if (!FirstTok.isAnnotation())
+  P.ConsumeAnyToken();

erichkeane wrote:

Done!

https://github.com/llvm/llvm-project/pull/75052
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [OpenACC] Add 'clause' parsing infrastructure plus a few clauses (PR #75052)

2023-12-13 Thread Erich Keane via cfe-commits


@@ -69,6 +69,29 @@ OpenACCDirectiveKindEx getOpenACCDirectiveKind(Token Tok) {
   .Default(OpenACCDirectiveKindEx::Invalid);
 }
 
+// Translate single-token string representations to the OpenCC Clause Kind.
+OpenACCClauseKind getOpenACCClauseKind(Token Tok) {
+  // auto is a keyword in some language modes, so make sure we parse it
+  // correctly.
+  if (Tok.is(tok::kw_auto))
+return OpenACCClauseKind::Auto;
+
+  if (!Tok.is(tok::identifier))
+return OpenACCClauseKind::Invalid;
+
+  return llvm::StringSwitch(
+ Tok.getIdentifierInfo()->getName())
+  .Case("finalize", OpenACCClauseKind::Finalize)
+  .Case("if_present", OpenACCClauseKind::IfPresent)
+  .Case("seq", OpenACCClauseKind::Seq)
+  .Case("independent", OpenACCClauseKind::Independent)
+  .Case("auto", OpenACCClauseKind::Auto)
+  .Case("worker", OpenACCClauseKind::Worker)
+  .Case("vector", OpenACCClauseKind::Vector)
+  .Case("nohost", OpenACCClauseKind::NoHost)
+  .Default(OpenACCClauseKind::Invalid);
+}

erichkeane wrote:

Sure! Done.

https://github.com/llvm/llvm-project/pull/75052
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [OpenACC] Add 'clause' parsing infrastructure plus a few clauses (PR #75052)

2023-12-13 Thread Erich Keane via cfe-commits


@@ -69,6 +69,29 @@ OpenACCDirectiveKindEx getOpenACCDirectiveKind(Token Tok) {
   .Default(OpenACCDirectiveKindEx::Invalid);
 }
 
+// Translate single-token string representations to the OpenCC Clause Kind.
+OpenACCClauseKind getOpenACCClauseKind(Token Tok) {

erichkeane wrote:

They are instead in an anonymous namespace,which has the same effect with a 
much less likelihood of someone forgetting static :D

https://github.com/llvm/llvm-project/pull/75052
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [OpenACC] Add 'clause' parsing infrastructure plus a few clauses (PR #75052)

2023-12-13 Thread via cfe-commits


@@ -69,6 +69,29 @@ OpenACCDirectiveKindEx getOpenACCDirectiveKind(Token Tok) {
   .Default(OpenACCDirectiveKindEx::Invalid);
 }
 
+// Translate single-token string representations to the OpenCC Clause Kind.
+OpenACCClauseKind getOpenACCClauseKind(Token Tok) {

cor3ntin wrote:

Should this be static (ditto for the rest of the functions in the files)

https://github.com/llvm/llvm-project/pull/75052
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [OpenACC] Add 'clause' parsing infrastructure plus a few clauses (PR #75052)

2023-12-13 Thread via cfe-commits


@@ -262,12 +291,52 @@ OpenACCDirectiveKind ParseOpenACCDirectiveKind(Parser ) 
{
   return DirKind;
 }
 
+bool ParseOpenACCClause(Parser ) {

cor3ntin wrote:

Can you add a description of the grammar?

https://github.com/llvm/llvm-project/pull/75052
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [OpenACC] Add 'clause' parsing infrastructure plus a few clauses (PR #75052)

2023-12-13 Thread via cfe-commits


@@ -208,6 +233,10 @@ OpenACCDirectiveKind ParseOpenACCDirectiveKind(Parser ) {
   // introspect on the spelling before then.
   if (FirstTok.isNot(tok::identifier)) {
 P.Diag(FirstTok, diag::err_acc_missing_directive);
+
+if (!FirstTok.isAnnotation())
+  P.ConsumeAnyToken();

cor3ntin wrote:

I'm assuming that's for the end of pragma annotation. Shouldn't the test be 
more specific?

https://github.com/llvm/llvm-project/pull/75052
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [OpenACC] Add 'clause' parsing infrastructure plus a few clauses (PR #75052)

2023-12-13 Thread via cfe-commits


@@ -69,6 +69,29 @@ OpenACCDirectiveKindEx getOpenACCDirectiveKind(Token Tok) {
   .Default(OpenACCDirectiveKindEx::Invalid);
 }
 
+// Translate single-token string representations to the OpenCC Clause Kind.
+OpenACCClauseKind getOpenACCClauseKind(Token Tok) {
+  // auto is a keyword in some language modes, so make sure we parse it
+  // correctly.
+  if (Tok.is(tok::kw_auto))
+return OpenACCClauseKind::Auto;
+
+  if (!Tok.is(tok::identifier))
+return OpenACCClauseKind::Invalid;
+
+  return llvm::StringSwitch(
+ Tok.getIdentifierInfo()->getName())
+  .Case("finalize", OpenACCClauseKind::Finalize)
+  .Case("if_present", OpenACCClauseKind::IfPresent)
+  .Case("seq", OpenACCClauseKind::Seq)
+  .Case("independent", OpenACCClauseKind::Independent)
+  .Case("auto", OpenACCClauseKind::Auto)
+  .Case("worker", OpenACCClauseKind::Worker)
+  .Case("vector", OpenACCClauseKind::Vector)
+  .Case("nohost", OpenACCClauseKind::NoHost)
+  .Default(OpenACCClauseKind::Invalid);
+}

cor3ntin wrote:

Can you sort alphabetically?

https://github.com/llvm/llvm-project/pull/75052
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [OpenACC] Add 'clause' parsing infrastructure plus a few clauses (PR #75052)

2023-12-11 Thread via cfe-commits

github-actions[bot] wrote:




:warning: C/C++ code formatter, clang-format found issues in your code. 
:warning:



You can test this locally with the following command:


``bash
git-clang-format --diff 29bd78b2f61e638f6c26bc417ae476754b91e985 
0bcee977f95f87a5ccf7bc53d6cd0a5d9521d963 -- 
clang/test/ParserOpenACC/parse-clauses.c 
clang/include/clang/Basic/OpenACCKinds.h clang/lib/Parse/ParseOpenACC.cpp 
clang/test/ParserOpenACC/parse-cache-construct.c 
clang/test/ParserOpenACC/parse-constructs.c 
clang/test/ParserOpenACC/parse-wait-construct.c 
clang/test/ParserOpenACC/unimplemented.c 
clang/test/ParserOpenACC/unimplemented.cpp
``





View the diff from clang-format here.


``diff
diff --git a/clang/lib/Parse/ParseOpenACC.cpp b/clang/lib/Parse/ParseOpenACC.cpp
index 2ad296e23e..50a8d85450 100644
--- a/clang/lib/Parse/ParseOpenACC.cpp
+++ b/clang/lib/Parse/ParseOpenACC.cpp
@@ -80,16 +80,16 @@ OpenACCClauseKind getOpenACCClauseKind(Token Tok) {
 return OpenACCClauseKind::Invalid;
 
   return llvm::StringSwitch(
-  Tok.getIdentifierInfo()->getName())
-.Case("finalize", OpenACCClauseKind::Finalize)
-.Case("if_present", OpenACCClauseKind::IfPresent)
-.Case("seq", OpenACCClauseKind::Seq)
-.Case("independent", OpenACCClauseKind::Independent)
-.Case("auto", OpenACCClauseKind::Auto)
-.Case("worker", OpenACCClauseKind::Worker)
-.Case("vector", OpenACCClauseKind::Vector)
-.Case("nohost", OpenACCClauseKind::NoHost)
-.Default(OpenACCClauseKind::Invalid);
+ Tok.getIdentifierInfo()->getName())
+  .Case("finalize", OpenACCClauseKind::Finalize)
+  .Case("if_present", OpenACCClauseKind::IfPresent)
+  .Case("seq", OpenACCClauseKind::Seq)
+  .Case("independent", OpenACCClauseKind::Independent)
+  .Case("auto", OpenACCClauseKind::Auto)
+  .Case("worker", OpenACCClauseKind::Worker)
+  .Case("vector", OpenACCClauseKind::Vector)
+  .Case("nohost", OpenACCClauseKind::NoHost)
+  .Default(OpenACCClauseKind::Invalid);
 }
 
 // Since 'atomic' is effectively a compound directive, this will decode the
@@ -313,7 +313,7 @@ bool ParseOpenACCClause(Parser ) {
 // have to do this because 'SkipUntil' considers paren balancing, which isn't
 // what we want.
 void SkipUntilEndOfDirective(Parser ) {
-  while(P.getCurToken().isNot(tok::annot_pragma_openacc_end))
+  while (P.getCurToken().isNot(tok::annot_pragma_openacc_end))
 P.ConsumeAnyToken();
 }
 
@@ -330,7 +330,8 @@ void ParseOpenACCClauseList(Parser ) {
   P.ConsumeToken();
 FirstClause = false;
 
-// Recovering from a bad clause is really difficult, so we just give up on 
error.
+// Recovering from a bad clause is really difficult, so we just give up on
+// error.
 if (ParseOpenACCClause(P)) {
   SkipUntilEndOfDirective(P);
   return;

``




https://github.com/llvm/llvm-project/pull/75052
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [OpenACC] Add 'clause' parsing infrastructure plus a few clauses (PR #75052)

2023-12-11 Thread Erich Keane via cfe-commits

https://github.com/erichkeane updated 
https://github.com/llvm/llvm-project/pull/75052

>From 0bcee977f95f87a5ccf7bc53d6cd0a5d9521d963 Mon Sep 17 00:00:00 2001
From: erichkeane 
Date: Fri, 8 Dec 2023 09:18:40 -0800
Subject: [PATCH 1/2] [OpenACC] Add 'clause' parsing infrastructure plus a few
 clauses

As we've now finished parsing the constructs, we're moving onto
implementing 'clause' parsing.  While some are complicated and require
their own patch, the handful added here are simple to parse (that is,
they are a single identifier).

This patch adds the infrastructure to parse these and a clause-list in
its entirety. This adds some complication to how we are diagnosing
parsing errors elsewhere, so a few changes were made to better recover
from errors.
---
 .../clang/Basic/DiagnosticParseKinds.td   |  4 +-
 clang/include/clang/Basic/OpenACCKinds.h  | 13 +++
 clang/lib/Parse/ParseOpenACC.cpp  | 86 +--
 .../ParserOpenACC/parse-cache-construct.c |  4 +-
 clang/test/ParserOpenACC/parse-clauses.c  | 64 ++
 clang/test/ParserOpenACC/parse-constructs.c   | 68 +++
 .../test/ParserOpenACC/parse-wait-construct.c | 24 +++---
 clang/test/ParserOpenACC/unimplemented.c  |  6 +-
 clang/test/ParserOpenACC/unimplemented.cpp|  6 +-
 9 files changed, 208 insertions(+), 67 deletions(-)
 create mode 100644 clang/test/ParserOpenACC/parse-clauses.c

diff --git a/clang/include/clang/Basic/DiagnosticParseKinds.td 
b/clang/include/clang/Basic/DiagnosticParseKinds.td
index 6150fc36430ab1..e4b1069cde1850 100644
--- a/clang/include/clang/Basic/DiagnosticParseKinds.td
+++ b/clang/include/clang/Basic/DiagnosticParseKinds.td
@@ -1358,11 +1358,9 @@ def err_acc_unexpected_directive
 def warn_pragma_acc_unimplemented
 : Warning<"OpenACC directives not yet implemented, pragma ignored">,
   InGroup;
-def warn_pragma_acc_unimplemented_clause_parsing
-: Warning<"OpenACC clause parsing not yet implemented">,
-  InGroup;
 def err_acc_invalid_directive
 : Error<"invalid OpenACC directive %select{%1|'%1 %2'}0">;
+def err_acc_invalid_clause : Error<"invalid OpenACC clause %0">;
 def err_acc_missing_directive : Error<"expected OpenACC directive">;
 def err_acc_invalid_open_paren
 : Error<"expected clause-list or newline in OpenACC directive">;
diff --git a/clang/include/clang/Basic/OpenACCKinds.h 
b/clang/include/clang/Basic/OpenACCKinds.h
index 62c0a4c1a9dea4..e907c192ed6d29 100644
--- a/clang/include/clang/Basic/OpenACCKinds.h
+++ b/clang/include/clang/Basic/OpenACCKinds.h
@@ -69,6 +69,19 @@ enum class OpenACCAtomicKind {
   Capture,
   Invalid,
 };
+
+// Represents the kind of an OpenACC clause.
+enum class OpenACCClauseKind {
+  Finalize,
+  IfPresent,
+  Seq,
+  Independent,
+  Auto,
+  Worker,
+  Vector,
+  NoHost,
+  Invalid,
+};
 } // namespace clang
 
 #endif // LLVM_CLANG_BASIC_OPENACCKINDS_H
diff --git a/clang/lib/Parse/ParseOpenACC.cpp b/clang/lib/Parse/ParseOpenACC.cpp
index f7f096762e91a6..2ad296e23e8f00 100644
--- a/clang/lib/Parse/ParseOpenACC.cpp
+++ b/clang/lib/Parse/ParseOpenACC.cpp
@@ -69,6 +69,29 @@ OpenACCDirectiveKindEx getOpenACCDirectiveKind(Token Tok) {
   .Default(OpenACCDirectiveKindEx::Invalid);
 }
 
+// Translate single-token string representations to the OpenCC Clause Kind.
+OpenACCClauseKind getOpenACCClauseKind(Token Tok) {
+  // auto is a keyword in some language modes, so make sure we parse it
+  // correctly.
+  if (Tok.is(tok::kw_auto))
+return OpenACCClauseKind::Auto;
+
+  if (!Tok.is(tok::identifier))
+return OpenACCClauseKind::Invalid;
+
+  return llvm::StringSwitch(
+  Tok.getIdentifierInfo()->getName())
+.Case("finalize", OpenACCClauseKind::Finalize)
+.Case("if_present", OpenACCClauseKind::IfPresent)
+.Case("seq", OpenACCClauseKind::Seq)
+.Case("independent", OpenACCClauseKind::Independent)
+.Case("auto", OpenACCClauseKind::Auto)
+.Case("worker", OpenACCClauseKind::Worker)
+.Case("vector", OpenACCClauseKind::Vector)
+.Case("nohost", OpenACCClauseKind::NoHost)
+.Default(OpenACCClauseKind::Invalid);
+}
+
 // Since 'atomic' is effectively a compound directive, this will decode the
 // second part of the directive.
 OpenACCAtomicKind getOpenACCAtomicKind(Token Tok) {
@@ -164,6 +187,10 @@ ParseOpenACCEnterExitDataDirective(Parser , Token 
FirstTok,
 return OpenACCDirectiveKind::Invalid;
   }
 
+  // Consume the second name anyway, this way we can continue on without making
+  // this oddly look like a clause.
+  P.ConsumeAnyToken();
+
   if (!isOpenACCDirectiveKind(OpenACCDirectiveKind::Data, SecondTok)) {
 if (!SecondTok.is(tok::identifier))
   P.Diag(SecondTok, diag::err_expected) << tok::identifier;
@@ -174,8 +201,6 @@ ParseOpenACCEnterExitDataDirective(Parser , Token 
FirstTok,
 return OpenACCDirectiveKind::Invalid;
   }
 
-  P.ConsumeToken();
-
   return ExtDirKind == OpenACCDirectiveKindEx::Enter
  ? 

[clang] [OpenACC] Add 'clause' parsing infrastructure plus a few clauses (PR #75052)

2023-12-11 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Erich Keane (erichkeane)


Changes

As we've now finished parsing the constructs, we're moving onto implementing 
'clause' parsing.  While some are complicated and require their own patch, the 
handful added here are simple to parse (that is,
they are a single identifier).

This patch adds the infrastructure to parse these and a clause-list in its 
entirety. This adds some complication to how we are diagnosing parsing errors 
elsewhere, so a few changes were made to better recover from errors.

---

Patch is 28.06 KiB, truncated to 20.00 KiB below, full version: 
https://github.com/llvm/llvm-project/pull/75052.diff


9 Files Affected:

- (modified) clang/include/clang/Basic/DiagnosticParseKinds.td (+1-3) 
- (modified) clang/include/clang/Basic/OpenACCKinds.h (+13) 
- (modified) clang/lib/Parse/ParseOpenACC.cpp (+78-8) 
- (modified) clang/test/ParserOpenACC/parse-cache-construct.c (+2-2) 
- (added) clang/test/ParserOpenACC/parse-clauses.c (+64) 
- (modified) clang/test/ParserOpenACC/parse-constructs.c (+32-36) 
- (modified) clang/test/ParserOpenACC/parse-wait-construct.c (+12-12) 
- (modified) clang/test/ParserOpenACC/unimplemented.c (+3-3) 
- (modified) clang/test/ParserOpenACC/unimplemented.cpp (+3-3) 


``diff
diff --git a/clang/include/clang/Basic/DiagnosticParseKinds.td 
b/clang/include/clang/Basic/DiagnosticParseKinds.td
index 6150fc36430ab1..e4b1069cde1850 100644
--- a/clang/include/clang/Basic/DiagnosticParseKinds.td
+++ b/clang/include/clang/Basic/DiagnosticParseKinds.td
@@ -1358,11 +1358,9 @@ def err_acc_unexpected_directive
 def warn_pragma_acc_unimplemented
 : Warning<"OpenACC directives not yet implemented, pragma ignored">,
   InGroup;
-def warn_pragma_acc_unimplemented_clause_parsing
-: Warning<"OpenACC clause parsing not yet implemented">,
-  InGroup;
 def err_acc_invalid_directive
 : Error<"invalid OpenACC directive %select{%1|'%1 %2'}0">;
+def err_acc_invalid_clause : Error<"invalid OpenACC clause %0">;
 def err_acc_missing_directive : Error<"expected OpenACC directive">;
 def err_acc_invalid_open_paren
 : Error<"expected clause-list or newline in OpenACC directive">;
diff --git a/clang/include/clang/Basic/OpenACCKinds.h 
b/clang/include/clang/Basic/OpenACCKinds.h
index 62c0a4c1a9dea4..e907c192ed6d29 100644
--- a/clang/include/clang/Basic/OpenACCKinds.h
+++ b/clang/include/clang/Basic/OpenACCKinds.h
@@ -69,6 +69,19 @@ enum class OpenACCAtomicKind {
   Capture,
   Invalid,
 };
+
+// Represents the kind of an OpenACC clause.
+enum class OpenACCClauseKind {
+  Finalize,
+  IfPresent,
+  Seq,
+  Independent,
+  Auto,
+  Worker,
+  Vector,
+  NoHost,
+  Invalid,
+};
 } // namespace clang
 
 #endif // LLVM_CLANG_BASIC_OPENACCKINDS_H
diff --git a/clang/lib/Parse/ParseOpenACC.cpp b/clang/lib/Parse/ParseOpenACC.cpp
index f7f096762e91a6..2ad296e23e8f00 100644
--- a/clang/lib/Parse/ParseOpenACC.cpp
+++ b/clang/lib/Parse/ParseOpenACC.cpp
@@ -69,6 +69,29 @@ OpenACCDirectiveKindEx getOpenACCDirectiveKind(Token Tok) {
   .Default(OpenACCDirectiveKindEx::Invalid);
 }
 
+// Translate single-token string representations to the OpenCC Clause Kind.
+OpenACCClauseKind getOpenACCClauseKind(Token Tok) {
+  // auto is a keyword in some language modes, so make sure we parse it
+  // correctly.
+  if (Tok.is(tok::kw_auto))
+return OpenACCClauseKind::Auto;
+
+  if (!Tok.is(tok::identifier))
+return OpenACCClauseKind::Invalid;
+
+  return llvm::StringSwitch(
+  Tok.getIdentifierInfo()->getName())
+.Case("finalize", OpenACCClauseKind::Finalize)
+.Case("if_present", OpenACCClauseKind::IfPresent)
+.Case("seq", OpenACCClauseKind::Seq)
+.Case("independent", OpenACCClauseKind::Independent)
+.Case("auto", OpenACCClauseKind::Auto)
+.Case("worker", OpenACCClauseKind::Worker)
+.Case("vector", OpenACCClauseKind::Vector)
+.Case("nohost", OpenACCClauseKind::NoHost)
+.Default(OpenACCClauseKind::Invalid);
+}
+
 // Since 'atomic' is effectively a compound directive, this will decode the
 // second part of the directive.
 OpenACCAtomicKind getOpenACCAtomicKind(Token Tok) {
@@ -164,6 +187,10 @@ ParseOpenACCEnterExitDataDirective(Parser , Token 
FirstTok,
 return OpenACCDirectiveKind::Invalid;
   }
 
+  // Consume the second name anyway, this way we can continue on without making
+  // this oddly look like a clause.
+  P.ConsumeAnyToken();
+
   if (!isOpenACCDirectiveKind(OpenACCDirectiveKind::Data, SecondTok)) {
 if (!SecondTok.is(tok::identifier))
   P.Diag(SecondTok, diag::err_expected) << tok::identifier;
@@ -174,8 +201,6 @@ ParseOpenACCEnterExitDataDirective(Parser , Token 
FirstTok,
 return OpenACCDirectiveKind::Invalid;
   }
 
-  P.ConsumeToken();
-
   return ExtDirKind == OpenACCDirectiveKindEx::Enter
  ? OpenACCDirectiveKind::EnterData
  : OpenACCDirectiveKind::ExitData;
@@ -208,6 +233,10 @@ OpenACCDirectiveKind ParseOpenACCDirectiveKind(Parser 

[clang] [OpenACC] Add 'clause' parsing infrastructure plus a few clauses (PR #75052)

2023-12-11 Thread Erich Keane via cfe-commits

https://github.com/erichkeane created 
https://github.com/llvm/llvm-project/pull/75052

As we've now finished parsing the constructs, we're moving onto implementing 
'clause' parsing.  While some are complicated and require their own patch, the 
handful added here are simple to parse (that is,
they are a single identifier).

This patch adds the infrastructure to parse these and a clause-list in its 
entirety. This adds some complication to how we are diagnosing parsing errors 
elsewhere, so a few changes were made to better recover from errors.

>From 0bcee977f95f87a5ccf7bc53d6cd0a5d9521d963 Mon Sep 17 00:00:00 2001
From: erichkeane 
Date: Fri, 8 Dec 2023 09:18:40 -0800
Subject: [PATCH] [OpenACC] Add 'clause' parsing infrastructure plus a few
 clauses

As we've now finished parsing the constructs, we're moving onto
implementing 'clause' parsing.  While some are complicated and require
their own patch, the handful added here are simple to parse (that is,
they are a single identifier).

This patch adds the infrastructure to parse these and a clause-list in
its entirety. This adds some complication to how we are diagnosing
parsing errors elsewhere, so a few changes were made to better recover
from errors.
---
 .../clang/Basic/DiagnosticParseKinds.td   |  4 +-
 clang/include/clang/Basic/OpenACCKinds.h  | 13 +++
 clang/lib/Parse/ParseOpenACC.cpp  | 86 +--
 .../ParserOpenACC/parse-cache-construct.c |  4 +-
 clang/test/ParserOpenACC/parse-clauses.c  | 64 ++
 clang/test/ParserOpenACC/parse-constructs.c   | 68 +++
 .../test/ParserOpenACC/parse-wait-construct.c | 24 +++---
 clang/test/ParserOpenACC/unimplemented.c  |  6 +-
 clang/test/ParserOpenACC/unimplemented.cpp|  6 +-
 9 files changed, 208 insertions(+), 67 deletions(-)
 create mode 100644 clang/test/ParserOpenACC/parse-clauses.c

diff --git a/clang/include/clang/Basic/DiagnosticParseKinds.td 
b/clang/include/clang/Basic/DiagnosticParseKinds.td
index 6150fc36430ab..e4b1069cde185 100644
--- a/clang/include/clang/Basic/DiagnosticParseKinds.td
+++ b/clang/include/clang/Basic/DiagnosticParseKinds.td
@@ -1358,11 +1358,9 @@ def err_acc_unexpected_directive
 def warn_pragma_acc_unimplemented
 : Warning<"OpenACC directives not yet implemented, pragma ignored">,
   InGroup;
-def warn_pragma_acc_unimplemented_clause_parsing
-: Warning<"OpenACC clause parsing not yet implemented">,
-  InGroup;
 def err_acc_invalid_directive
 : Error<"invalid OpenACC directive %select{%1|'%1 %2'}0">;
+def err_acc_invalid_clause : Error<"invalid OpenACC clause %0">;
 def err_acc_missing_directive : Error<"expected OpenACC directive">;
 def err_acc_invalid_open_paren
 : Error<"expected clause-list or newline in OpenACC directive">;
diff --git a/clang/include/clang/Basic/OpenACCKinds.h 
b/clang/include/clang/Basic/OpenACCKinds.h
index 62c0a4c1a9dea..e907c192ed6d2 100644
--- a/clang/include/clang/Basic/OpenACCKinds.h
+++ b/clang/include/clang/Basic/OpenACCKinds.h
@@ -69,6 +69,19 @@ enum class OpenACCAtomicKind {
   Capture,
   Invalid,
 };
+
+// Represents the kind of an OpenACC clause.
+enum class OpenACCClauseKind {
+  Finalize,
+  IfPresent,
+  Seq,
+  Independent,
+  Auto,
+  Worker,
+  Vector,
+  NoHost,
+  Invalid,
+};
 } // namespace clang
 
 #endif // LLVM_CLANG_BASIC_OPENACCKINDS_H
diff --git a/clang/lib/Parse/ParseOpenACC.cpp b/clang/lib/Parse/ParseOpenACC.cpp
index f7f096762e91a..2ad296e23e8f0 100644
--- a/clang/lib/Parse/ParseOpenACC.cpp
+++ b/clang/lib/Parse/ParseOpenACC.cpp
@@ -69,6 +69,29 @@ OpenACCDirectiveKindEx getOpenACCDirectiveKind(Token Tok) {
   .Default(OpenACCDirectiveKindEx::Invalid);
 }
 
+// Translate single-token string representations to the OpenCC Clause Kind.
+OpenACCClauseKind getOpenACCClauseKind(Token Tok) {
+  // auto is a keyword in some language modes, so make sure we parse it
+  // correctly.
+  if (Tok.is(tok::kw_auto))
+return OpenACCClauseKind::Auto;
+
+  if (!Tok.is(tok::identifier))
+return OpenACCClauseKind::Invalid;
+
+  return llvm::StringSwitch(
+  Tok.getIdentifierInfo()->getName())
+.Case("finalize", OpenACCClauseKind::Finalize)
+.Case("if_present", OpenACCClauseKind::IfPresent)
+.Case("seq", OpenACCClauseKind::Seq)
+.Case("independent", OpenACCClauseKind::Independent)
+.Case("auto", OpenACCClauseKind::Auto)
+.Case("worker", OpenACCClauseKind::Worker)
+.Case("vector", OpenACCClauseKind::Vector)
+.Case("nohost", OpenACCClauseKind::NoHost)
+.Default(OpenACCClauseKind::Invalid);
+}
+
 // Since 'atomic' is effectively a compound directive, this will decode the
 // second part of the directive.
 OpenACCAtomicKind getOpenACCAtomicKind(Token Tok) {
@@ -164,6 +187,10 @@ ParseOpenACCEnterExitDataDirective(Parser , Token 
FirstTok,
 return OpenACCDirectiveKind::Invalid;
   }
 
+  // Consume the second name anyway, this way we can continue on without making
+  // this oddly look like a