[clang] Nameof operator (PR #104777)

2024-08-19 Thread Urvi Rav via cfe-commits

https://github.com/ravurvi20 created 
https://github.com/llvm/llvm-project/pull/104777

This Pull Request introduces the `__nameof` operator, enabling users to obtain 
the symbolic name of any enumerator value. When the `__nameof` operator is 
used, the compiler will return the fully qualified name of the enum constant, 
enhancing readability and debugging capabilities.
*Problem Statement:*
C++ enum classes allow developers to define enumerator values, which can 
simplify code and improve readability. However, there are times when 
understanding or logging the actual names of these enumerator values is 
necessary, especially in complex codebases or during debugging. Developers need 
a straightforward way to retrieve the symbolic names of enum constants to 
better understand and manage their code.
*Proposed Solution:*
The proposed solution is to implement a compiler feature that allows the use of 
a `__nameof` operator to retrieve the symbolic names of enumerator values. This 
operator will construct and return the fully qualified name of the enum 
constant, providing clarity and aiding in debugging.
Implementation:
*1. EnumNameVisitor Class:*
Introduced the `EnumNameVisitor` class to handle the `__nameof` operator.
Implemented logic to construct the fully qualified name of the enum constant in 
the format `EnumName::EnumConstant`.
  Added methods to traverse the expression tree, identify `DeclRefExpr` nodes, 
and fetch the name from the node.
*2. Parser Modifications:*
Updated the parser to recognize and parse the `__nameof` operator.
Integrated the handling of the `__nameof` operator into the semantic analysis 
phase to ensure accurate name retrieval.
 
*3. Test Case:*
```
#include
using namespace std;
// Define an enumeration
enum Day {
Monday,
Tuesday,
Wednesday,
Thursday,
Friday,
Saturday,
Sunday
};
enum Month{
January,
February,
March,
April,
May,
June,
July,
August,
September,
October,
November,
December
};
int main() {
   cout<<"Symbolic Name for ";
+def err_invalid_enum_decl : Error<"unsupported declaration type. "
+  "Only enum constants are supported">;
 def err_ice_too_large : Error<
   "integer constant expression evaluates to value %0 that cannot be "
   "represented in a %1-bit %select{signed|unsigned}2 integer type">;
diff --git a/clang/include/clang/Basic/TokenKinds.def 
b/clang/include/clang/Basic/TokenKinds.def
index 9c4b17465e18a1..5d7daa076cad26 100644
--- a/clang/include/clang/Basic/TokenKinds.def
+++ b/clang/include/clang/Basic/TokenKinds.def
@@ -311,6 +311,7 @@ KEYWORD(register, KEYALL)
 KEYWORD(return  , KEYALL)
 KEYWORD(short   , KEYALL)
 KEYWORD(signed  , KEYALL)
+UNARY_EXPR_OR_TYPE_TRAIT(__nameof, nameof, KEYALL)
 UNARY_EXPR_OR_TYPE_TRAIT(sizeof, SizeOf, KEYALL)
 UNARY_EXPR_OR_TYPE_TRAIT(__datasizeof, DataSizeOf, KEYCXX)
 KEYWORD(static  , KEYALL)
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 174b9dbc6d980c..4f5b152fa96f6b 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -244,6 +244,7 @@ class PossiblyUnreachableDiag;
 class RISCVIntrinsicManager;
 class SemaPPCallbacks;
 class TemplateDeductionInfo;
+static std::vector enumvector;
 } // namespace sema
 
 namespace threadSafety {
diff --git a/clang/lib/Parse/ParseExpr.cpp b/clang/lib/Parse/ParseExpr.cpp
index eb7447fa038e47..08ed45457027d2 100644
--- a/clang/lib/Parse/ParseExpr.cpp
+++ b/clang/lib/Parse/ParseExpr.cpp
@@ -1491,6 +1491,7 @@ ExprResult Parser::ParseCastExpression(CastParseKind 
ParseKind,
   // unary-expression: '__datasizeof' unary-expression
   // unary-expressi

[clang] default clause replaced by otherwise clause for metadirective in OpenMP 5.2 (PR #125648)

2025-02-04 Thread Urvi Rav via cfe-commits

https://github.com/ravurvi20 updated 
https://github.com/llvm/llvm-project/pull/125648

>From 189dd3cc2230ea5752969f02f119b6ee30e3df69 Mon Sep 17 00:00:00 2001
From: Urvi Rav 
Date: Tue, 4 Feb 2025 01:35:41 -0600
Subject: [PATCH 1/2] default clause replaced by otherwise clause for
 metadirective

---
 .../clang/Basic/DiagnosticParseKinds.td   |  4 
 clang/lib/Parse/ParseOpenMP.cpp   | 15 ++
 clang/test/OpenMP/metadirective_ast_print.c   | 20 +--
 .../metadirective_device_arch_codegen.cpp |  2 +-
 .../metadirective_device_isa_codegen.cpp  |  4 ++--
 ...etadirective_device_isa_codegen_amdgcn.cpp |  4 ++--
 .../metadirective_device_kind_codegen.c   |  2 +-
 .../metadirective_device_kind_codegen.cpp |  2 +-
 clang/test/OpenMP/metadirective_empty.cpp |  4 ++--
 .../metadirective_implementation_codegen.c| 12 +--
 .../metadirective_implementation_codegen.cpp  | 12 +--
 clang/test/OpenMP/metadirective_messages.cpp  | 12 +++
 12 files changed, 58 insertions(+), 35 deletions(-)

diff --git a/clang/include/clang/Basic/DiagnosticParseKinds.td 
b/clang/include/clang/Basic/DiagnosticParseKinds.td
index c513dab810d1f5..4b8449e9ee9b62 100644
--- a/clang/include/clang/Basic/DiagnosticParseKinds.td
+++ b/clang/include/clang/Basic/DiagnosticParseKinds.td
@@ -1657,6 +1657,10 @@ def err_omp_expected_colon : Error<"missing ':' in %0">;
 def err_omp_missing_comma : Error< "missing ',' after %0">;
 def err_omp_expected_context_selector
 : Error<"expected valid context selector in %0">;
+def err_omp_unknown_clause
+: Error<"unknown clause '%0' in %1">;
+def warn_omp_default_deprecated : Warning<"'default' clause for"
+  " 'metadirective' is deprecated; use 'otherwise' instead">, 
InGroup;
 def err_omp_requires_out_inout_depend_type : Error<
   "reserved locator 'omp_all_memory' requires 'out' or 'inout' "
   "dependency types">;
diff --git a/clang/lib/Parse/ParseOpenMP.cpp b/clang/lib/Parse/ParseOpenMP.cpp
index 89b83938f352df..673806ef28b9fc 100644
--- a/clang/lib/Parse/ParseOpenMP.cpp
+++ b/clang/lib/Parse/ParseOpenMP.cpp
@@ -2743,6 +2743,15 @@ StmtResult 
Parser::ParseOpenMPDeclarativeOrExecutableDirective(
   OpenMPClauseKind CKind = Tok.isAnnotation()
? OMPC_unknown
: getOpenMPClauseKind(PP.getSpelling(Tok));
+  // Check if the clause is unrecognized.
+  if (CKind == OMPC_unknown) {
+Diag(Tok, diag::err_omp_unknown_clause)
+<< PP.getSpelling(Tok) << "metadirective";
+return Directive;
+  }
+  if(CKind == OMPC_default) {
+Diag(Tok, diag::warn_omp_default_deprecated);
+  }
   SourceLocation Loc = ConsumeToken();
 
   // Parse '('.
@@ -2769,6 +2778,12 @@ StmtResult 
Parser::ParseOpenMPDeclarativeOrExecutableDirective(
   return Directive;
 }
   }
+  if (CKind == OMPC_otherwise) {
+// Check for 'otherwise' keyword.
+if (Tok.is(tok::identifier) && Tok.getIdentifierInfo()->getName() == 
"otherwise") {
+ConsumeToken();  // Consume 'otherwise'
+}
+  }
   // Skip Directive for now. We will parse directive in the second 
iteration
   int paren = 0;
   while (Tok.isNot(tok::r_paren) || paren != 0) {
diff --git a/clang/test/OpenMP/metadirective_ast_print.c 
b/clang/test/OpenMP/metadirective_ast_print.c
index d9ff7e76452160..28efaac5949427 100644
--- a/clang/test/OpenMP/metadirective_ast_print.c
+++ b/clang/test/OpenMP/metadirective_ast_print.c
@@ -15,18 +15,18 @@ void bar(void);
 #define N 10
 void foo(void) {
 #pragma omp metadirective when(device = {kind(cpu)} \
-   : parallel) default()
+   : parallel) otherwise()
   bar();
 #pragma omp metadirective when(implementation = {vendor(score(0)  \
 : llvm)}, \
device = {kind(cpu)}   \
-   : parallel) default(target teams)
+   : parallel) otherwise(target teams)
   bar();
 #pragma omp metadirective when(device = {kind(gpu)}
 \
: target teams) when(implementation = 
{vendor(llvm)} \
-: parallel) default()
+: parallel) otherwise()
   bar();
-#pragma omp metadirective default(target) when(implementation = 
{vendor(score(5)  \
+#pragma omp metadirective otherwise(target) when(implementation = 
{vendor(score(5)  \
 : 
llvm)}, \
device = {kind(cpu, host)}  
   \
: parallel)
@@ -40,15 +40,15 @@ void foo(void) {
   for (int i = 0; i < 100; i++)
 ;

[clang] default clause replaced by otherwise clause for metadirective in OpenMP 5.2 (PR #125648)

2025-02-06 Thread Urvi Rav via cfe-commits

https://github.com/ravurvi20 updated 
https://github.com/llvm/llvm-project/pull/125648

>From 189dd3cc2230ea5752969f02f119b6ee30e3df69 Mon Sep 17 00:00:00 2001
From: Urvi Rav 
Date: Tue, 4 Feb 2025 01:35:41 -0600
Subject: [PATCH 1/3] default clause replaced by otherwise clause for
 metadirective

---
 .../clang/Basic/DiagnosticParseKinds.td   |  4 
 clang/lib/Parse/ParseOpenMP.cpp   | 15 ++
 clang/test/OpenMP/metadirective_ast_print.c   | 20 +--
 .../metadirective_device_arch_codegen.cpp |  2 +-
 .../metadirective_device_isa_codegen.cpp  |  4 ++--
 ...etadirective_device_isa_codegen_amdgcn.cpp |  4 ++--
 .../metadirective_device_kind_codegen.c   |  2 +-
 .../metadirective_device_kind_codegen.cpp |  2 +-
 clang/test/OpenMP/metadirective_empty.cpp |  4 ++--
 .../metadirective_implementation_codegen.c| 12 +--
 .../metadirective_implementation_codegen.cpp  | 12 +--
 clang/test/OpenMP/metadirective_messages.cpp  | 12 +++
 12 files changed, 58 insertions(+), 35 deletions(-)

diff --git a/clang/include/clang/Basic/DiagnosticParseKinds.td 
b/clang/include/clang/Basic/DiagnosticParseKinds.td
index c513dab810d1f53..4b8449e9ee9b629 100644
--- a/clang/include/clang/Basic/DiagnosticParseKinds.td
+++ b/clang/include/clang/Basic/DiagnosticParseKinds.td
@@ -1657,6 +1657,10 @@ def err_omp_expected_colon : Error<"missing ':' in %0">;
 def err_omp_missing_comma : Error< "missing ',' after %0">;
 def err_omp_expected_context_selector
 : Error<"expected valid context selector in %0">;
+def err_omp_unknown_clause
+: Error<"unknown clause '%0' in %1">;
+def warn_omp_default_deprecated : Warning<"'default' clause for"
+  " 'metadirective' is deprecated; use 'otherwise' instead">, 
InGroup;
 def err_omp_requires_out_inout_depend_type : Error<
   "reserved locator 'omp_all_memory' requires 'out' or 'inout' "
   "dependency types">;
diff --git a/clang/lib/Parse/ParseOpenMP.cpp b/clang/lib/Parse/ParseOpenMP.cpp
index 89b83938f352dff..673806ef28b9fc6 100644
--- a/clang/lib/Parse/ParseOpenMP.cpp
+++ b/clang/lib/Parse/ParseOpenMP.cpp
@@ -2743,6 +2743,15 @@ StmtResult 
Parser::ParseOpenMPDeclarativeOrExecutableDirective(
   OpenMPClauseKind CKind = Tok.isAnnotation()
? OMPC_unknown
: getOpenMPClauseKind(PP.getSpelling(Tok));
+  // Check if the clause is unrecognized.
+  if (CKind == OMPC_unknown) {
+Diag(Tok, diag::err_omp_unknown_clause)
+<< PP.getSpelling(Tok) << "metadirective";
+return Directive;
+  }
+  if(CKind == OMPC_default) {
+Diag(Tok, diag::warn_omp_default_deprecated);
+  }
   SourceLocation Loc = ConsumeToken();
 
   // Parse '('.
@@ -2769,6 +2778,12 @@ StmtResult 
Parser::ParseOpenMPDeclarativeOrExecutableDirective(
   return Directive;
 }
   }
+  if (CKind == OMPC_otherwise) {
+// Check for 'otherwise' keyword.
+if (Tok.is(tok::identifier) && Tok.getIdentifierInfo()->getName() == 
"otherwise") {
+ConsumeToken();  // Consume 'otherwise'
+}
+  }
   // Skip Directive for now. We will parse directive in the second 
iteration
   int paren = 0;
   while (Tok.isNot(tok::r_paren) || paren != 0) {
diff --git a/clang/test/OpenMP/metadirective_ast_print.c 
b/clang/test/OpenMP/metadirective_ast_print.c
index d9ff7e764521607..28efaac5949427b 100644
--- a/clang/test/OpenMP/metadirective_ast_print.c
+++ b/clang/test/OpenMP/metadirective_ast_print.c
@@ -15,18 +15,18 @@ void bar(void);
 #define N 10
 void foo(void) {
 #pragma omp metadirective when(device = {kind(cpu)} \
-   : parallel) default()
+   : parallel) otherwise()
   bar();
 #pragma omp metadirective when(implementation = {vendor(score(0)  \
 : llvm)}, \
device = {kind(cpu)}   \
-   : parallel) default(target teams)
+   : parallel) otherwise(target teams)
   bar();
 #pragma omp metadirective when(device = {kind(gpu)}
 \
: target teams) when(implementation = 
{vendor(llvm)} \
-: parallel) default()
+: parallel) otherwise()
   bar();
-#pragma omp metadirective default(target) when(implementation = 
{vendor(score(5)  \
+#pragma omp metadirective otherwise(target) when(implementation = 
{vendor(score(5)  \
 : 
llvm)}, \
device = {kind(cpu, host)}  
   \
: parallel)
@@ -40,15 +40,15 @@ void foo(void) {
   for (int i = 0; i < 100; i++)

[clang] default clause replaced by otherwise clause for metadirective in OpenMP 5.2 (PR #125648)

2025-02-06 Thread Urvi Rav via cfe-commits

https://github.com/ravurvi20 updated 
https://github.com/llvm/llvm-project/pull/125648

>From 189dd3cc2230ea5752969f02f119b6ee30e3df69 Mon Sep 17 00:00:00 2001
From: Urvi Rav 
Date: Tue, 4 Feb 2025 01:35:41 -0600
Subject: [PATCH 1/3] default clause replaced by otherwise clause for
 metadirective

---
 .../clang/Basic/DiagnosticParseKinds.td   |  4 
 clang/lib/Parse/ParseOpenMP.cpp   | 15 ++
 clang/test/OpenMP/metadirective_ast_print.c   | 20 +--
 .../metadirective_device_arch_codegen.cpp |  2 +-
 .../metadirective_device_isa_codegen.cpp  |  4 ++--
 ...etadirective_device_isa_codegen_amdgcn.cpp |  4 ++--
 .../metadirective_device_kind_codegen.c   |  2 +-
 .../metadirective_device_kind_codegen.cpp |  2 +-
 clang/test/OpenMP/metadirective_empty.cpp |  4 ++--
 .../metadirective_implementation_codegen.c| 12 +--
 .../metadirective_implementation_codegen.cpp  | 12 +--
 clang/test/OpenMP/metadirective_messages.cpp  | 12 +++
 12 files changed, 58 insertions(+), 35 deletions(-)

diff --git a/clang/include/clang/Basic/DiagnosticParseKinds.td 
b/clang/include/clang/Basic/DiagnosticParseKinds.td
index c513dab810d1f53..4b8449e9ee9b629 100644
--- a/clang/include/clang/Basic/DiagnosticParseKinds.td
+++ b/clang/include/clang/Basic/DiagnosticParseKinds.td
@@ -1657,6 +1657,10 @@ def err_omp_expected_colon : Error<"missing ':' in %0">;
 def err_omp_missing_comma : Error< "missing ',' after %0">;
 def err_omp_expected_context_selector
 : Error<"expected valid context selector in %0">;
+def err_omp_unknown_clause
+: Error<"unknown clause '%0' in %1">;
+def warn_omp_default_deprecated : Warning<"'default' clause for"
+  " 'metadirective' is deprecated; use 'otherwise' instead">, 
InGroup;
 def err_omp_requires_out_inout_depend_type : Error<
   "reserved locator 'omp_all_memory' requires 'out' or 'inout' "
   "dependency types">;
diff --git a/clang/lib/Parse/ParseOpenMP.cpp b/clang/lib/Parse/ParseOpenMP.cpp
index 89b83938f352dff..673806ef28b9fc6 100644
--- a/clang/lib/Parse/ParseOpenMP.cpp
+++ b/clang/lib/Parse/ParseOpenMP.cpp
@@ -2743,6 +2743,15 @@ StmtResult 
Parser::ParseOpenMPDeclarativeOrExecutableDirective(
   OpenMPClauseKind CKind = Tok.isAnnotation()
? OMPC_unknown
: getOpenMPClauseKind(PP.getSpelling(Tok));
+  // Check if the clause is unrecognized.
+  if (CKind == OMPC_unknown) {
+Diag(Tok, diag::err_omp_unknown_clause)
+<< PP.getSpelling(Tok) << "metadirective";
+return Directive;
+  }
+  if(CKind == OMPC_default) {
+Diag(Tok, diag::warn_omp_default_deprecated);
+  }
   SourceLocation Loc = ConsumeToken();
 
   // Parse '('.
@@ -2769,6 +2778,12 @@ StmtResult 
Parser::ParseOpenMPDeclarativeOrExecutableDirective(
   return Directive;
 }
   }
+  if (CKind == OMPC_otherwise) {
+// Check for 'otherwise' keyword.
+if (Tok.is(tok::identifier) && Tok.getIdentifierInfo()->getName() == 
"otherwise") {
+ConsumeToken();  // Consume 'otherwise'
+}
+  }
   // Skip Directive for now. We will parse directive in the second 
iteration
   int paren = 0;
   while (Tok.isNot(tok::r_paren) || paren != 0) {
diff --git a/clang/test/OpenMP/metadirective_ast_print.c 
b/clang/test/OpenMP/metadirective_ast_print.c
index d9ff7e764521607..28efaac5949427b 100644
--- a/clang/test/OpenMP/metadirective_ast_print.c
+++ b/clang/test/OpenMP/metadirective_ast_print.c
@@ -15,18 +15,18 @@ void bar(void);
 #define N 10
 void foo(void) {
 #pragma omp metadirective when(device = {kind(cpu)} \
-   : parallel) default()
+   : parallel) otherwise()
   bar();
 #pragma omp metadirective when(implementation = {vendor(score(0)  \
 : llvm)}, \
device = {kind(cpu)}   \
-   : parallel) default(target teams)
+   : parallel) otherwise(target teams)
   bar();
 #pragma omp metadirective when(device = {kind(gpu)}
 \
: target teams) when(implementation = 
{vendor(llvm)} \
-: parallel) default()
+: parallel) otherwise()
   bar();
-#pragma omp metadirective default(target) when(implementation = 
{vendor(score(5)  \
+#pragma omp metadirective otherwise(target) when(implementation = 
{vendor(score(5)  \
 : 
llvm)}, \
device = {kind(cpu, host)}  
   \
: parallel)
@@ -40,15 +40,15 @@ void foo(void) {
   for (int i = 0; i < 100; i++)

[clang] default clause replaced by otherwise clause for metadirective in OpenMP 5.2 (PR #125648)

2025-02-06 Thread Urvi Rav via cfe-commits

ravurvi20 wrote:

> Thank you for this patch. I wonder: was this spelling change introduced in 
> 5.2? If so, does the compiler after this patch still support the 5.1 spelling 
> when providing this as the OpenMP version (`-fopenmp-version=5.1`)

Yes, otherwise clause was introduced in OpenMP 5.2 version 
([Metadirective](https://www.openmp.org/spec-html/5.2/openmpse45.html)). I have 
added a condition where, for OpenMP 5.2 or later, the compiler generates a 
warning for the default clause, while for OpenMP 5.1 and earlier, the default 
clause is accepted without warnings.


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


[clang] default clause replaced by otherwise clause for metadirective in OpenMP 5.2 (PR #125648)

2025-02-06 Thread Urvi Rav via cfe-commits

https://github.com/ravurvi20 updated 
https://github.com/llvm/llvm-project/pull/125648

>From 189dd3cc2230ea5752969f02f119b6ee30e3df69 Mon Sep 17 00:00:00 2001
From: Urvi Rav 
Date: Tue, 4 Feb 2025 01:35:41 -0600
Subject: [PATCH 1/4] default clause replaced by otherwise clause for
 metadirective

---
 .../clang/Basic/DiagnosticParseKinds.td   |  4 
 clang/lib/Parse/ParseOpenMP.cpp   | 15 ++
 clang/test/OpenMP/metadirective_ast_print.c   | 20 +--
 .../metadirective_device_arch_codegen.cpp |  2 +-
 .../metadirective_device_isa_codegen.cpp  |  4 ++--
 ...etadirective_device_isa_codegen_amdgcn.cpp |  4 ++--
 .../metadirective_device_kind_codegen.c   |  2 +-
 .../metadirective_device_kind_codegen.cpp |  2 +-
 clang/test/OpenMP/metadirective_empty.cpp |  4 ++--
 .../metadirective_implementation_codegen.c| 12 +--
 .../metadirective_implementation_codegen.cpp  | 12 +--
 clang/test/OpenMP/metadirective_messages.cpp  | 12 +++
 12 files changed, 58 insertions(+), 35 deletions(-)

diff --git a/clang/include/clang/Basic/DiagnosticParseKinds.td 
b/clang/include/clang/Basic/DiagnosticParseKinds.td
index c513dab810d1f53..4b8449e9ee9b629 100644
--- a/clang/include/clang/Basic/DiagnosticParseKinds.td
+++ b/clang/include/clang/Basic/DiagnosticParseKinds.td
@@ -1657,6 +1657,10 @@ def err_omp_expected_colon : Error<"missing ':' in %0">;
 def err_omp_missing_comma : Error< "missing ',' after %0">;
 def err_omp_expected_context_selector
 : Error<"expected valid context selector in %0">;
+def err_omp_unknown_clause
+: Error<"unknown clause '%0' in %1">;
+def warn_omp_default_deprecated : Warning<"'default' clause for"
+  " 'metadirective' is deprecated; use 'otherwise' instead">, 
InGroup;
 def err_omp_requires_out_inout_depend_type : Error<
   "reserved locator 'omp_all_memory' requires 'out' or 'inout' "
   "dependency types">;
diff --git a/clang/lib/Parse/ParseOpenMP.cpp b/clang/lib/Parse/ParseOpenMP.cpp
index 89b83938f352dff..673806ef28b9fc6 100644
--- a/clang/lib/Parse/ParseOpenMP.cpp
+++ b/clang/lib/Parse/ParseOpenMP.cpp
@@ -2743,6 +2743,15 @@ StmtResult 
Parser::ParseOpenMPDeclarativeOrExecutableDirective(
   OpenMPClauseKind CKind = Tok.isAnnotation()
? OMPC_unknown
: getOpenMPClauseKind(PP.getSpelling(Tok));
+  // Check if the clause is unrecognized.
+  if (CKind == OMPC_unknown) {
+Diag(Tok, diag::err_omp_unknown_clause)
+<< PP.getSpelling(Tok) << "metadirective";
+return Directive;
+  }
+  if(CKind == OMPC_default) {
+Diag(Tok, diag::warn_omp_default_deprecated);
+  }
   SourceLocation Loc = ConsumeToken();
 
   // Parse '('.
@@ -2769,6 +2778,12 @@ StmtResult 
Parser::ParseOpenMPDeclarativeOrExecutableDirective(
   return Directive;
 }
   }
+  if (CKind == OMPC_otherwise) {
+// Check for 'otherwise' keyword.
+if (Tok.is(tok::identifier) && Tok.getIdentifierInfo()->getName() == 
"otherwise") {
+ConsumeToken();  // Consume 'otherwise'
+}
+  }
   // Skip Directive for now. We will parse directive in the second 
iteration
   int paren = 0;
   while (Tok.isNot(tok::r_paren) || paren != 0) {
diff --git a/clang/test/OpenMP/metadirective_ast_print.c 
b/clang/test/OpenMP/metadirective_ast_print.c
index d9ff7e764521607..28efaac5949427b 100644
--- a/clang/test/OpenMP/metadirective_ast_print.c
+++ b/clang/test/OpenMP/metadirective_ast_print.c
@@ -15,18 +15,18 @@ void bar(void);
 #define N 10
 void foo(void) {
 #pragma omp metadirective when(device = {kind(cpu)} \
-   : parallel) default()
+   : parallel) otherwise()
   bar();
 #pragma omp metadirective when(implementation = {vendor(score(0)  \
 : llvm)}, \
device = {kind(cpu)}   \
-   : parallel) default(target teams)
+   : parallel) otherwise(target teams)
   bar();
 #pragma omp metadirective when(device = {kind(gpu)}
 \
: target teams) when(implementation = 
{vendor(llvm)} \
-: parallel) default()
+: parallel) otherwise()
   bar();
-#pragma omp metadirective default(target) when(implementation = 
{vendor(score(5)  \
+#pragma omp metadirective otherwise(target) when(implementation = 
{vendor(score(5)  \
 : 
llvm)}, \
device = {kind(cpu, host)}  
   \
: parallel)
@@ -40,15 +40,15 @@ void foo(void) {
   for (int i = 0; i < 100; i++)

[clang] default clause replaced by otherwise clause for metadirective in OpenMP 5.2 (PR #125648)

2025-02-06 Thread Urvi Rav via cfe-commits

https://github.com/ravurvi20 updated 
https://github.com/llvm/llvm-project/pull/125648

>From 189dd3cc2230ea5752969f02f119b6ee30e3df69 Mon Sep 17 00:00:00 2001
From: Urvi Rav 
Date: Tue, 4 Feb 2025 01:35:41 -0600
Subject: [PATCH 1/5] default clause replaced by otherwise clause for
 metadirective

---
 .../clang/Basic/DiagnosticParseKinds.td   |  4 
 clang/lib/Parse/ParseOpenMP.cpp   | 15 ++
 clang/test/OpenMP/metadirective_ast_print.c   | 20 +--
 .../metadirective_device_arch_codegen.cpp |  2 +-
 .../metadirective_device_isa_codegen.cpp  |  4 ++--
 ...etadirective_device_isa_codegen_amdgcn.cpp |  4 ++--
 .../metadirective_device_kind_codegen.c   |  2 +-
 .../metadirective_device_kind_codegen.cpp |  2 +-
 clang/test/OpenMP/metadirective_empty.cpp |  4 ++--
 .../metadirective_implementation_codegen.c| 12 +--
 .../metadirective_implementation_codegen.cpp  | 12 +--
 clang/test/OpenMP/metadirective_messages.cpp  | 12 +++
 12 files changed, 58 insertions(+), 35 deletions(-)

diff --git a/clang/include/clang/Basic/DiagnosticParseKinds.td 
b/clang/include/clang/Basic/DiagnosticParseKinds.td
index c513dab810d1f53..4b8449e9ee9b629 100644
--- a/clang/include/clang/Basic/DiagnosticParseKinds.td
+++ b/clang/include/clang/Basic/DiagnosticParseKinds.td
@@ -1657,6 +1657,10 @@ def err_omp_expected_colon : Error<"missing ':' in %0">;
 def err_omp_missing_comma : Error< "missing ',' after %0">;
 def err_omp_expected_context_selector
 : Error<"expected valid context selector in %0">;
+def err_omp_unknown_clause
+: Error<"unknown clause '%0' in %1">;
+def warn_omp_default_deprecated : Warning<"'default' clause for"
+  " 'metadirective' is deprecated; use 'otherwise' instead">, 
InGroup;
 def err_omp_requires_out_inout_depend_type : Error<
   "reserved locator 'omp_all_memory' requires 'out' or 'inout' "
   "dependency types">;
diff --git a/clang/lib/Parse/ParseOpenMP.cpp b/clang/lib/Parse/ParseOpenMP.cpp
index 89b83938f352dff..673806ef28b9fc6 100644
--- a/clang/lib/Parse/ParseOpenMP.cpp
+++ b/clang/lib/Parse/ParseOpenMP.cpp
@@ -2743,6 +2743,15 @@ StmtResult 
Parser::ParseOpenMPDeclarativeOrExecutableDirective(
   OpenMPClauseKind CKind = Tok.isAnnotation()
? OMPC_unknown
: getOpenMPClauseKind(PP.getSpelling(Tok));
+  // Check if the clause is unrecognized.
+  if (CKind == OMPC_unknown) {
+Diag(Tok, diag::err_omp_unknown_clause)
+<< PP.getSpelling(Tok) << "metadirective";
+return Directive;
+  }
+  if(CKind == OMPC_default) {
+Diag(Tok, diag::warn_omp_default_deprecated);
+  }
   SourceLocation Loc = ConsumeToken();
 
   // Parse '('.
@@ -2769,6 +2778,12 @@ StmtResult 
Parser::ParseOpenMPDeclarativeOrExecutableDirective(
   return Directive;
 }
   }
+  if (CKind == OMPC_otherwise) {
+// Check for 'otherwise' keyword.
+if (Tok.is(tok::identifier) && Tok.getIdentifierInfo()->getName() == 
"otherwise") {
+ConsumeToken();  // Consume 'otherwise'
+}
+  }
   // Skip Directive for now. We will parse directive in the second 
iteration
   int paren = 0;
   while (Tok.isNot(tok::r_paren) || paren != 0) {
diff --git a/clang/test/OpenMP/metadirective_ast_print.c 
b/clang/test/OpenMP/metadirective_ast_print.c
index d9ff7e764521607..28efaac5949427b 100644
--- a/clang/test/OpenMP/metadirective_ast_print.c
+++ b/clang/test/OpenMP/metadirective_ast_print.c
@@ -15,18 +15,18 @@ void bar(void);
 #define N 10
 void foo(void) {
 #pragma omp metadirective when(device = {kind(cpu)} \
-   : parallel) default()
+   : parallel) otherwise()
   bar();
 #pragma omp metadirective when(implementation = {vendor(score(0)  \
 : llvm)}, \
device = {kind(cpu)}   \
-   : parallel) default(target teams)
+   : parallel) otherwise(target teams)
   bar();
 #pragma omp metadirective when(device = {kind(gpu)}
 \
: target teams) when(implementation = 
{vendor(llvm)} \
-: parallel) default()
+: parallel) otherwise()
   bar();
-#pragma omp metadirective default(target) when(implementation = 
{vendor(score(5)  \
+#pragma omp metadirective otherwise(target) when(implementation = 
{vendor(score(5)  \
 : 
llvm)}, \
device = {kind(cpu, host)}  
   \
: parallel)
@@ -40,15 +40,15 @@ void foo(void) {
   for (int i = 0; i < 100; i++)

[clang] default clause replaced by otherwise clause for metadirective in OpenMP 5.2 (PR #125648)

2025-02-10 Thread Urvi Rav via cfe-commits

ravurvi20 wrote:

@mjklemm I addressed the changes that you requested. Kindly review it and let 
me know if any further modifications are required. 

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


[clang] [llvm] default clause replaced by otherwise clause for metadirective in OpenMP 5.2 (PR #125035)

2025-01-30 Thread Urvi Rav via cfe-commits

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


[clang] [llvm] default clause replaced by otherwise clause in metadirective in OpenMP 5.2 (PR #124550)

2025-01-27 Thread Urvi Rav via cfe-commits

https://github.com/ravurvi20 created 
https://github.com/llvm/llvm-project/pull/124550

This PR replaces the `default` clause with the `otherwise` clause for the 
`metadirective` in OpenMP. The `otherwise` clause serves as a fallback 
condition when no directive from the `when` clauses is selected. In the `when` 
clause, context selectors define traits that are evaluated to determine the 
directive to be applied.

>From 6c3312653b9891125cf5d8678e575d4e5f15db69 Mon Sep 17 00:00:00 2001
From: Urvi Rav 
Date: Mon, 27 Jan 2025 08:12:15 -0600
Subject: [PATCH] default clause replaced by otherwise clause in metadirective

---
 .../clang/Basic/DiagnosticParseKinds.td   |  4 
 clang/lib/Basic/OpenMPKinds.cpp   |  2 ++
 clang/lib/Parse/ParseOpenMP.cpp   | 15 ++
 clang/test/OpenMP/metadirective_ast_print.c   | 20 +--
 .../metadirective_device_arch_codegen.cpp |  2 +-
 .../metadirective_device_isa_codegen.cpp  |  4 ++--
 ...etadirective_device_isa_codegen_amdgcn.cpp |  4 ++--
 .../metadirective_device_kind_codegen.c   |  2 +-
 .../metadirective_device_kind_codegen.cpp |  2 +-
 clang/test/OpenMP/metadirective_empty.cpp |  4 ++--
 .../metadirective_implementation_codegen.c| 12 +--
 .../metadirective_implementation_codegen.cpp  | 12 +--
 clang/test/OpenMP/metadirective_messages.cpp  | 11 ++
 llvm/include/llvm/Frontend/OpenMP/OMP.td  |  5 +
 14 files changed, 64 insertions(+), 35 deletions(-)

diff --git a/clang/include/clang/Basic/DiagnosticParseKinds.td 
b/clang/include/clang/Basic/DiagnosticParseKinds.td
index 3309f59a981fc1..5b7cc463a7d08e 100644
--- a/clang/include/clang/Basic/DiagnosticParseKinds.td
+++ b/clang/include/clang/Basic/DiagnosticParseKinds.td
@@ -1647,6 +1647,10 @@ def err_omp_expected_colon : Error<"missing ':' in %0">;
 def err_omp_missing_comma : Error< "missing ',' after %0">;
 def err_omp_expected_context_selector
 : Error<"expected valid context selector in %0">;
+def err_omp_unknown_clause
+: Error<"unknown clause '%0' in %1">;
+def warn_omp_default_deprecated : Warning<"'default' clause for"
+  " 'metadirective' is deprecated; use 'otherwise' instead">, 
InGroup;
 def err_omp_requires_out_inout_depend_type : Error<
   "reserved locator 'omp_all_memory' requires 'out' or 'inout' "
   "dependency types">;
diff --git a/clang/lib/Basic/OpenMPKinds.cpp b/clang/lib/Basic/OpenMPKinds.cpp
index 62a13f01481b28..a093f7a3b260ff 100644
--- a/clang/lib/Basic/OpenMPKinds.cpp
+++ b/clang/lib/Basic/OpenMPKinds.cpp
@@ -246,6 +246,7 @@ unsigned clang::getOpenMPSimpleClauseType(OpenMPClauseKind 
Kind, StringRef Str,
   case OMPC_uses_allocators:
   case OMPC_affinity:
   case OMPC_when:
+  case OMPC_otherwise:
   case OMPC_append_args:
 break;
   default:
@@ -580,6 +581,7 @@ const char 
*clang::getOpenMPSimpleClauseTypeName(OpenMPClauseKind Kind,
   case OMPC_uses_allocators:
   case OMPC_affinity:
   case OMPC_when:
+  case OMPC_otherwise:
   case OMPC_append_args:
 break;
   default:
diff --git a/clang/lib/Parse/ParseOpenMP.cpp b/clang/lib/Parse/ParseOpenMP.cpp
index 89b83938f352df..673806ef28b9fc 100644
--- a/clang/lib/Parse/ParseOpenMP.cpp
+++ b/clang/lib/Parse/ParseOpenMP.cpp
@@ -2743,6 +2743,15 @@ StmtResult 
Parser::ParseOpenMPDeclarativeOrExecutableDirective(
   OpenMPClauseKind CKind = Tok.isAnnotation()
? OMPC_unknown
: getOpenMPClauseKind(PP.getSpelling(Tok));
+  // Check if the clause is unrecognized.
+  if (CKind == OMPC_unknown) {
+Diag(Tok, diag::err_omp_unknown_clause)
+<< PP.getSpelling(Tok) << "metadirective";
+return Directive;
+  }
+  if(CKind == OMPC_default) {
+Diag(Tok, diag::warn_omp_default_deprecated);
+  }
   SourceLocation Loc = ConsumeToken();
 
   // Parse '('.
@@ -2769,6 +2778,12 @@ StmtResult 
Parser::ParseOpenMPDeclarativeOrExecutableDirective(
   return Directive;
 }
   }
+  if (CKind == OMPC_otherwise) {
+// Check for 'otherwise' keyword.
+if (Tok.is(tok::identifier) && Tok.getIdentifierInfo()->getName() == 
"otherwise") {
+ConsumeToken();  // Consume 'otherwise'
+}
+  }
   // Skip Directive for now. We will parse directive in the second 
iteration
   int paren = 0;
   while (Tok.isNot(tok::r_paren) || paren != 0) {
diff --git a/clang/test/OpenMP/metadirective_ast_print.c 
b/clang/test/OpenMP/metadirective_ast_print.c
index d9ff7e76452160..28efaac5949427 100644
--- a/clang/test/OpenMP/metadirective_ast_print.c
+++ b/clang/test/OpenMP/metadirective_ast_print.c
@@ -15,18 +15,18 @@ void bar(void);
 #define N 10
 void foo(void) {
 #pragma omp metadirective when(device = {kind(cpu)} \
-   : parallel) default()
+   : parallel) otherwise()
   bar();
 #pragma omp metadirective when(implementation = 

[clang] [llvm] default clause replaced by otherwise clause in metadirective in OpenMP 5.2 (PR #124550)

2025-01-27 Thread Urvi Rav via cfe-commits

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


[clang] [llvm] default clause replaced by otherwise clause in metadirective in OpenMP 5.2 (PR #124550)

2025-01-27 Thread Urvi Rav via cfe-commits

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


[clang] [llvm] default clause replaced by otherwise clause in metadirective in OpenMP 5.2 (PR #125035)

2025-01-29 Thread Urvi Rav via cfe-commits

https://github.com/ravurvi20 created 
https://github.com/llvm/llvm-project/pull/125035

This PR replaces the `default` clause with the `otherwise` clause for the 
`metadirective` in OpenMP. The `otherwise` clause serves as a fallback 
condition when no directive from the `when` clauses is selected. In the `when` 
clause, context selectors define traits evaluated to determine the directive to 
be applied.

>From 6c3312653b9891125cf5d8678e575d4e5f15db69 Mon Sep 17 00:00:00 2001
From: Urvi Rav 
Date: Mon, 27 Jan 2025 08:12:15 -0600
Subject: [PATCH] default clause replaced by otherwise clause in metadirective

---
 .../clang/Basic/DiagnosticParseKinds.td   |  4 
 clang/lib/Basic/OpenMPKinds.cpp   |  2 ++
 clang/lib/Parse/ParseOpenMP.cpp   | 15 ++
 clang/test/OpenMP/metadirective_ast_print.c   | 20 +--
 .../metadirective_device_arch_codegen.cpp |  2 +-
 .../metadirective_device_isa_codegen.cpp  |  4 ++--
 ...etadirective_device_isa_codegen_amdgcn.cpp |  4 ++--
 .../metadirective_device_kind_codegen.c   |  2 +-
 .../metadirective_device_kind_codegen.cpp |  2 +-
 clang/test/OpenMP/metadirective_empty.cpp |  4 ++--
 .../metadirective_implementation_codegen.c| 12 +--
 .../metadirective_implementation_codegen.cpp  | 12 +--
 clang/test/OpenMP/metadirective_messages.cpp  | 11 ++
 llvm/include/llvm/Frontend/OpenMP/OMP.td  |  5 +
 14 files changed, 64 insertions(+), 35 deletions(-)

diff --git a/clang/include/clang/Basic/DiagnosticParseKinds.td 
b/clang/include/clang/Basic/DiagnosticParseKinds.td
index 3309f59a981fc1..5b7cc463a7d08e 100644
--- a/clang/include/clang/Basic/DiagnosticParseKinds.td
+++ b/clang/include/clang/Basic/DiagnosticParseKinds.td
@@ -1647,6 +1647,10 @@ def err_omp_expected_colon : Error<"missing ':' in %0">;
 def err_omp_missing_comma : Error< "missing ',' after %0">;
 def err_omp_expected_context_selector
 : Error<"expected valid context selector in %0">;
+def err_omp_unknown_clause
+: Error<"unknown clause '%0' in %1">;
+def warn_omp_default_deprecated : Warning<"'default' clause for"
+  " 'metadirective' is deprecated; use 'otherwise' instead">, 
InGroup;
 def err_omp_requires_out_inout_depend_type : Error<
   "reserved locator 'omp_all_memory' requires 'out' or 'inout' "
   "dependency types">;
diff --git a/clang/lib/Basic/OpenMPKinds.cpp b/clang/lib/Basic/OpenMPKinds.cpp
index 62a13f01481b28..a093f7a3b260ff 100644
--- a/clang/lib/Basic/OpenMPKinds.cpp
+++ b/clang/lib/Basic/OpenMPKinds.cpp
@@ -246,6 +246,7 @@ unsigned clang::getOpenMPSimpleClauseType(OpenMPClauseKind 
Kind, StringRef Str,
   case OMPC_uses_allocators:
   case OMPC_affinity:
   case OMPC_when:
+  case OMPC_otherwise:
   case OMPC_append_args:
 break;
   default:
@@ -580,6 +581,7 @@ const char 
*clang::getOpenMPSimpleClauseTypeName(OpenMPClauseKind Kind,
   case OMPC_uses_allocators:
   case OMPC_affinity:
   case OMPC_when:
+  case OMPC_otherwise:
   case OMPC_append_args:
 break;
   default:
diff --git a/clang/lib/Parse/ParseOpenMP.cpp b/clang/lib/Parse/ParseOpenMP.cpp
index 89b83938f352df..673806ef28b9fc 100644
--- a/clang/lib/Parse/ParseOpenMP.cpp
+++ b/clang/lib/Parse/ParseOpenMP.cpp
@@ -2743,6 +2743,15 @@ StmtResult 
Parser::ParseOpenMPDeclarativeOrExecutableDirective(
   OpenMPClauseKind CKind = Tok.isAnnotation()
? OMPC_unknown
: getOpenMPClauseKind(PP.getSpelling(Tok));
+  // Check if the clause is unrecognized.
+  if (CKind == OMPC_unknown) {
+Diag(Tok, diag::err_omp_unknown_clause)
+<< PP.getSpelling(Tok) << "metadirective";
+return Directive;
+  }
+  if(CKind == OMPC_default) {
+Diag(Tok, diag::warn_omp_default_deprecated);
+  }
   SourceLocation Loc = ConsumeToken();
 
   // Parse '('.
@@ -2769,6 +2778,12 @@ StmtResult 
Parser::ParseOpenMPDeclarativeOrExecutableDirective(
   return Directive;
 }
   }
+  if (CKind == OMPC_otherwise) {
+// Check for 'otherwise' keyword.
+if (Tok.is(tok::identifier) && Tok.getIdentifierInfo()->getName() == 
"otherwise") {
+ConsumeToken();  // Consume 'otherwise'
+}
+  }
   // Skip Directive for now. We will parse directive in the second 
iteration
   int paren = 0;
   while (Tok.isNot(tok::r_paren) || paren != 0) {
diff --git a/clang/test/OpenMP/metadirective_ast_print.c 
b/clang/test/OpenMP/metadirective_ast_print.c
index d9ff7e76452160..28efaac5949427 100644
--- a/clang/test/OpenMP/metadirective_ast_print.c
+++ b/clang/test/OpenMP/metadirective_ast_print.c
@@ -15,18 +15,18 @@ void bar(void);
 #define N 10
 void foo(void) {
 #pragma omp metadirective when(device = {kind(cpu)} \
-   : parallel) default()
+   : parallel) otherwise()
   bar();
 #pragma omp metadirective when(implementation = {vendor(s

[clang] [llvm] default clause replaced by otherwise clause in metadirective in OpenMP 5.2 (PR #124550)

2025-01-29 Thread Urvi Rav via cfe-commits

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


[clang] [llvm] default clause replaced by otherwise clause in metadirective in OpenMP 5.2 (PR #124550)

2025-01-29 Thread Urvi Rav via cfe-commits

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


[clang] default clause replaced by otherwise clause for metadirective in OpenMP 5.2 (PR #125648)

2025-02-16 Thread Urvi Rav via cfe-commits

ravurvi20 wrote:

ping @jplehr 

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


[clang] default clause replaced by otherwise clause for metadirective in OpenMP 5.2 (PR #125648)

2025-02-16 Thread Urvi Rav via cfe-commits

ravurvi20 wrote:

ping @mjklemm 

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


[clang] default clause replaced by otherwise clause for metadirective in OpenMP 5.2 (PR #125648)

2025-02-20 Thread Urvi Rav via cfe-commits

https://github.com/ravurvi20 updated 
https://github.com/llvm/llvm-project/pull/125648

>From 189dd3cc2230ea5752969f02f119b6ee30e3df69 Mon Sep 17 00:00:00 2001
From: Urvi Rav 
Date: Tue, 4 Feb 2025 01:35:41 -0600
Subject: [PATCH 1/6] default clause replaced by otherwise clause for
 metadirective

---
 .../clang/Basic/DiagnosticParseKinds.td   |  4 
 clang/lib/Parse/ParseOpenMP.cpp   | 15 ++
 clang/test/OpenMP/metadirective_ast_print.c   | 20 +--
 .../metadirective_device_arch_codegen.cpp |  2 +-
 .../metadirective_device_isa_codegen.cpp  |  4 ++--
 ...etadirective_device_isa_codegen_amdgcn.cpp |  4 ++--
 .../metadirective_device_kind_codegen.c   |  2 +-
 .../metadirective_device_kind_codegen.cpp |  2 +-
 clang/test/OpenMP/metadirective_empty.cpp |  4 ++--
 .../metadirective_implementation_codegen.c| 12 +--
 .../metadirective_implementation_codegen.cpp  | 12 +--
 clang/test/OpenMP/metadirective_messages.cpp  | 12 +++
 12 files changed, 58 insertions(+), 35 deletions(-)

diff --git a/clang/include/clang/Basic/DiagnosticParseKinds.td 
b/clang/include/clang/Basic/DiagnosticParseKinds.td
index c513dab810d1f..4b8449e9ee9b6 100644
--- a/clang/include/clang/Basic/DiagnosticParseKinds.td
+++ b/clang/include/clang/Basic/DiagnosticParseKinds.td
@@ -1657,6 +1657,10 @@ def err_omp_expected_colon : Error<"missing ':' in %0">;
 def err_omp_missing_comma : Error< "missing ',' after %0">;
 def err_omp_expected_context_selector
 : Error<"expected valid context selector in %0">;
+def err_omp_unknown_clause
+: Error<"unknown clause '%0' in %1">;
+def warn_omp_default_deprecated : Warning<"'default' clause for"
+  " 'metadirective' is deprecated; use 'otherwise' instead">, 
InGroup;
 def err_omp_requires_out_inout_depend_type : Error<
   "reserved locator 'omp_all_memory' requires 'out' or 'inout' "
   "dependency types">;
diff --git a/clang/lib/Parse/ParseOpenMP.cpp b/clang/lib/Parse/ParseOpenMP.cpp
index 89b83938f352d..673806ef28b9f 100644
--- a/clang/lib/Parse/ParseOpenMP.cpp
+++ b/clang/lib/Parse/ParseOpenMP.cpp
@@ -2743,6 +2743,15 @@ StmtResult 
Parser::ParseOpenMPDeclarativeOrExecutableDirective(
   OpenMPClauseKind CKind = Tok.isAnnotation()
? OMPC_unknown
: getOpenMPClauseKind(PP.getSpelling(Tok));
+  // Check if the clause is unrecognized.
+  if (CKind == OMPC_unknown) {
+Diag(Tok, diag::err_omp_unknown_clause)
+<< PP.getSpelling(Tok) << "metadirective";
+return Directive;
+  }
+  if(CKind == OMPC_default) {
+Diag(Tok, diag::warn_omp_default_deprecated);
+  }
   SourceLocation Loc = ConsumeToken();
 
   // Parse '('.
@@ -2769,6 +2778,12 @@ StmtResult 
Parser::ParseOpenMPDeclarativeOrExecutableDirective(
   return Directive;
 }
   }
+  if (CKind == OMPC_otherwise) {
+// Check for 'otherwise' keyword.
+if (Tok.is(tok::identifier) && Tok.getIdentifierInfo()->getName() == 
"otherwise") {
+ConsumeToken();  // Consume 'otherwise'
+}
+  }
   // Skip Directive for now. We will parse directive in the second 
iteration
   int paren = 0;
   while (Tok.isNot(tok::r_paren) || paren != 0) {
diff --git a/clang/test/OpenMP/metadirective_ast_print.c 
b/clang/test/OpenMP/metadirective_ast_print.c
index d9ff7e7645216..28efaac594942 100644
--- a/clang/test/OpenMP/metadirective_ast_print.c
+++ b/clang/test/OpenMP/metadirective_ast_print.c
@@ -15,18 +15,18 @@ void bar(void);
 #define N 10
 void foo(void) {
 #pragma omp metadirective when(device = {kind(cpu)} \
-   : parallel) default()
+   : parallel) otherwise()
   bar();
 #pragma omp metadirective when(implementation = {vendor(score(0)  \
 : llvm)}, \
device = {kind(cpu)}   \
-   : parallel) default(target teams)
+   : parallel) otherwise(target teams)
   bar();
 #pragma omp metadirective when(device = {kind(gpu)}
 \
: target teams) when(implementation = 
{vendor(llvm)} \
-: parallel) default()
+: parallel) otherwise()
   bar();
-#pragma omp metadirective default(target) when(implementation = 
{vendor(score(5)  \
+#pragma omp metadirective otherwise(target) when(implementation = 
{vendor(score(5)  \
 : 
llvm)}, \
device = {kind(cpu, host)}  
   \
: parallel)
@@ -40,15 +40,15 @@ void foo(void) {
   for (int i = 0; i < 100; i++)
 ;
 #pra

[clang] default clause replaced by otherwise clause for metadirective in OpenMP 5.2 (PR #125648)

2025-02-20 Thread Urvi Rav via cfe-commits

ravurvi20 wrote:

> Did anybody run the OpenMP VV suite before and after this change? Curious to 
> know if that improves results.

The changes I implemented are related to parsing, specifically addressing the 
deprecation of the default clause. These modifications do not impact the 
results, as they primarily refine how parsing is handled. Previously, keywords 
such as default, otherwise, or other variations were all parsed without 
distinction. With my changes, the parsing behavior now aligns with the expected 
standard—supporting default for OpenMP versions lower than 5.2 and otherwise 
for higher versions. Additionally, a warning is now generated when default is 
used in higher versions.

I also validated these changes by running the OpenMP VV suite to ensure 
correctness.

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


[clang] default clause replaced by otherwise clause for metadirective in OpenMP 5.2 (PR #125648)

2025-02-20 Thread Urvi Rav via cfe-commits

https://github.com/ravurvi20 updated 
https://github.com/llvm/llvm-project/pull/125648

>From 189dd3cc2230ea5752969f02f119b6ee30e3df69 Mon Sep 17 00:00:00 2001
From: Urvi Rav 
Date: Tue, 4 Feb 2025 01:35:41 -0600
Subject: [PATCH 1/6] default clause replaced by otherwise clause for
 metadirective

---
 .../clang/Basic/DiagnosticParseKinds.td   |  4 
 clang/lib/Parse/ParseOpenMP.cpp   | 15 ++
 clang/test/OpenMP/metadirective_ast_print.c   | 20 +--
 .../metadirective_device_arch_codegen.cpp |  2 +-
 .../metadirective_device_isa_codegen.cpp  |  4 ++--
 ...etadirective_device_isa_codegen_amdgcn.cpp |  4 ++--
 .../metadirective_device_kind_codegen.c   |  2 +-
 .../metadirective_device_kind_codegen.cpp |  2 +-
 clang/test/OpenMP/metadirective_empty.cpp |  4 ++--
 .../metadirective_implementation_codegen.c| 12 +--
 .../metadirective_implementation_codegen.cpp  | 12 +--
 clang/test/OpenMP/metadirective_messages.cpp  | 12 +++
 12 files changed, 58 insertions(+), 35 deletions(-)

diff --git a/clang/include/clang/Basic/DiagnosticParseKinds.td 
b/clang/include/clang/Basic/DiagnosticParseKinds.td
index c513dab810d1f..4b8449e9ee9b6 100644
--- a/clang/include/clang/Basic/DiagnosticParseKinds.td
+++ b/clang/include/clang/Basic/DiagnosticParseKinds.td
@@ -1657,6 +1657,10 @@ def err_omp_expected_colon : Error<"missing ':' in %0">;
 def err_omp_missing_comma : Error< "missing ',' after %0">;
 def err_omp_expected_context_selector
 : Error<"expected valid context selector in %0">;
+def err_omp_unknown_clause
+: Error<"unknown clause '%0' in %1">;
+def warn_omp_default_deprecated : Warning<"'default' clause for"
+  " 'metadirective' is deprecated; use 'otherwise' instead">, 
InGroup;
 def err_omp_requires_out_inout_depend_type : Error<
   "reserved locator 'omp_all_memory' requires 'out' or 'inout' "
   "dependency types">;
diff --git a/clang/lib/Parse/ParseOpenMP.cpp b/clang/lib/Parse/ParseOpenMP.cpp
index 89b83938f352d..673806ef28b9f 100644
--- a/clang/lib/Parse/ParseOpenMP.cpp
+++ b/clang/lib/Parse/ParseOpenMP.cpp
@@ -2743,6 +2743,15 @@ StmtResult 
Parser::ParseOpenMPDeclarativeOrExecutableDirective(
   OpenMPClauseKind CKind = Tok.isAnnotation()
? OMPC_unknown
: getOpenMPClauseKind(PP.getSpelling(Tok));
+  // Check if the clause is unrecognized.
+  if (CKind == OMPC_unknown) {
+Diag(Tok, diag::err_omp_unknown_clause)
+<< PP.getSpelling(Tok) << "metadirective";
+return Directive;
+  }
+  if(CKind == OMPC_default) {
+Diag(Tok, diag::warn_omp_default_deprecated);
+  }
   SourceLocation Loc = ConsumeToken();
 
   // Parse '('.
@@ -2769,6 +2778,12 @@ StmtResult 
Parser::ParseOpenMPDeclarativeOrExecutableDirective(
   return Directive;
 }
   }
+  if (CKind == OMPC_otherwise) {
+// Check for 'otherwise' keyword.
+if (Tok.is(tok::identifier) && Tok.getIdentifierInfo()->getName() == 
"otherwise") {
+ConsumeToken();  // Consume 'otherwise'
+}
+  }
   // Skip Directive for now. We will parse directive in the second 
iteration
   int paren = 0;
   while (Tok.isNot(tok::r_paren) || paren != 0) {
diff --git a/clang/test/OpenMP/metadirective_ast_print.c 
b/clang/test/OpenMP/metadirective_ast_print.c
index d9ff7e7645216..28efaac594942 100644
--- a/clang/test/OpenMP/metadirective_ast_print.c
+++ b/clang/test/OpenMP/metadirective_ast_print.c
@@ -15,18 +15,18 @@ void bar(void);
 #define N 10
 void foo(void) {
 #pragma omp metadirective when(device = {kind(cpu)} \
-   : parallel) default()
+   : parallel) otherwise()
   bar();
 #pragma omp metadirective when(implementation = {vendor(score(0)  \
 : llvm)}, \
device = {kind(cpu)}   \
-   : parallel) default(target teams)
+   : parallel) otherwise(target teams)
   bar();
 #pragma omp metadirective when(device = {kind(gpu)}
 \
: target teams) when(implementation = 
{vendor(llvm)} \
-: parallel) default()
+: parallel) otherwise()
   bar();
-#pragma omp metadirective default(target) when(implementation = 
{vendor(score(5)  \
+#pragma omp metadirective otherwise(target) when(implementation = 
{vendor(score(5)  \
 : 
llvm)}, \
device = {kind(cpu, host)}  
   \
: parallel)
@@ -40,15 +40,15 @@ void foo(void) {
   for (int i = 0; i < 100; i++)
 ;
 #pra

[clang] default clause replaced by otherwise clause for metadirective in OpenMP 5.2 (PR #128640)

2025-02-24 Thread Urvi Rav via cfe-commits

https://github.com/ravurvi20 created 
https://github.com/llvm/llvm-project/pull/128640

This PR replaces the `default` clause with the `otherwise` clause for the 
`metadirective` in OpenMP. The `otherwise` clause serves as a fallback 
condition when no directive from the when clauses is selected. In the `when` 
clause, context selectors define traits evaluated to determine the directive to 
be applied.
The previous merge was reverted due to a failing test case, which has now been 
resolved.

>From 6ebd5991788608fbd104ea9c23230912044462d3 Mon Sep 17 00:00:00 2001
From: Urvi Rav 
Date: Tue, 25 Feb 2025 00:49:07 -0600
Subject: [PATCH] default clause replaced by otherwise clause for metadirective

---
 .../clang/Basic/DiagnosticParseKinds.td   |  4 ++
 clang/lib/Parse/ParseOpenMP.cpp   | 20 ++
 clang/test/OpenMP/metadirective_messages.cpp  | 61 +--
 3 files changed, 68 insertions(+), 17 deletions(-)

diff --git a/clang/include/clang/Basic/DiagnosticParseKinds.td 
b/clang/include/clang/Basic/DiagnosticParseKinds.td
index c513dab810d1f..4b8449e9ee9b6 100644
--- a/clang/include/clang/Basic/DiagnosticParseKinds.td
+++ b/clang/include/clang/Basic/DiagnosticParseKinds.td
@@ -1657,6 +1657,10 @@ def err_omp_expected_colon : Error<"missing ':' in %0">;
 def err_omp_missing_comma : Error< "missing ',' after %0">;
 def err_omp_expected_context_selector
 : Error<"expected valid context selector in %0">;
+def err_omp_unknown_clause
+: Error<"unknown clause '%0' in %1">;
+def warn_omp_default_deprecated : Warning<"'default' clause for"
+  " 'metadirective' is deprecated; use 'otherwise' instead">, 
InGroup;
 def err_omp_requires_out_inout_depend_type : Error<
   "reserved locator 'omp_all_memory' requires 'out' or 'inout' "
   "dependency types">;
diff --git a/clang/lib/Parse/ParseOpenMP.cpp b/clang/lib/Parse/ParseOpenMP.cpp
index 42e6aac681c1c..3b86847e937a2 100644
--- a/clang/lib/Parse/ParseOpenMP.cpp
+++ b/clang/lib/Parse/ParseOpenMP.cpp
@@ -2759,6 +2759,19 @@ StmtResult 
Parser::ParseOpenMPDeclarativeOrExecutableDirective(
   OpenMPClauseKind CKind = Tok.isAnnotation()
? OMPC_unknown
: getOpenMPClauseKind(PP.getSpelling(Tok));
+  // Check if the clause is unrecognized.
+  if (getLangOpts().OpenMP < 52 &&
+  (CKind == OMPC_unknown || CKind == OMPC_otherwise)) {
+Diag(Tok, diag::err_omp_unknown_clause)
+<< PP.getSpelling(Tok) << "metadirective";
+  }
+  if (getLangOpts().OpenMP >= 52 && CKind == OMPC_unknown) {
+Diag(Tok, diag::err_omp_unknown_clause)
+<< PP.getSpelling(Tok) << "metadirective";
+  }
+  if (CKind == OMPC_default && getLangOpts().OpenMP >= 52) {
+Diag(Tok, diag::warn_omp_default_deprecated);
+  }
   SourceLocation Loc = ConsumeToken();
 
   // Parse '('.
@@ -2785,6 +2798,13 @@ StmtResult 
Parser::ParseOpenMPDeclarativeOrExecutableDirective(
   return Directive;
 }
   }
+  if (CKind == OMPC_otherwise) {
+// Check for 'otherwise' keyword.
+if (Tok.is(tok::identifier) &&
+Tok.getIdentifierInfo()->getName() == "otherwise") {
+  ConsumeToken(); // Consume 'otherwise'
+}
+  }
   // Skip Directive for now. We will parse directive in the second 
iteration
   int paren = 0;
   while (Tok.isNot(tok::r_paren) || paren != 0) {
diff --git a/clang/test/OpenMP/metadirective_messages.cpp 
b/clang/test/OpenMP/metadirective_messages.cpp
index 7fce9fa446058..40ea37845fdff 100644
--- a/clang/test/OpenMP/metadirective_messages.cpp
+++ b/clang/test/OpenMP/metadirective_messages.cpp
@@ -2,21 +2,48 @@
 
 // RUN: %clang_cc1 -triple=x86_64-pc-linux-gnu -verify -fopenmp-simd -x c++ 
-std=c++14 -fexceptions -fcxx-exceptions %s
 
+// RUN: %clang_cc1 -triple=x86_64-pc-linux-gnu -verify=expected,omp52 -fopenmp 
-fopenmp-version=52 -ferror-limit 100 -o - %s -Wuninitialized
+
 void foo() {
-#pragma omp metadirective // expected-error {{expected expression}}
-  ;
-#pragma omp metadirective when() // expected-error {{expected valid context 
selector in when clause}} expected-error {{expected expression}} 
expected-warning {{expected identifier or string literal describing a context 
set; set skipped}} expected-note {{context set options are: 'construct' 
'device' 'target_device' 'implementation' 'user'}} expected-note {{the ignored 
set spans until here}}
-  ;
-#pragma omp metadirective when(device{}) // expected-warning {{expected '=' 
after the context set name "device"; '=' assumed}} expected-warning {{expected 
identifier or string literal describing a context selector; selector skipped}} 
expected-note {{context selector options are: 'kind' 'arch' 'isa'}} 
expected-note {{the ignored selector spans until here}} expected-error 
{{expected valid context selector in when clause}} expected-error {{expected 
expression}}
-  ;
-#pragma omp metadirecti

[clang] default clause replaced by otherwise clause for metadirective in OpenMP 5.2 (PR #128640)

2025-02-27 Thread Urvi Rav via cfe-commits

ravurvi20 wrote:

Previous commit was reverted due to a failing test case, which has been 
resolved now. Parsing changes have been approved in the previous PR.
[125648](https://github.com/llvm/llvm-project/pull/125648)

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


[clang] default clause replaced by otherwise clause for metadirective in OpenMP 5.2 (PR #128640)

2025-03-24 Thread Urvi Rav via cfe-commits

https://github.com/ravurvi20 updated 
https://github.com/llvm/llvm-project/pull/128640

>From 6ebd5991788608fbd104ea9c23230912044462d3 Mon Sep 17 00:00:00 2001
From: Urvi Rav 
Date: Tue, 25 Feb 2025 00:49:07 -0600
Subject: [PATCH] default clause replaced by otherwise clause for metadirective

---
 .../clang/Basic/DiagnosticParseKinds.td   |  4 ++
 clang/lib/Parse/ParseOpenMP.cpp   | 20 ++
 clang/test/OpenMP/metadirective_messages.cpp  | 61 +--
 3 files changed, 68 insertions(+), 17 deletions(-)

diff --git a/clang/include/clang/Basic/DiagnosticParseKinds.td 
b/clang/include/clang/Basic/DiagnosticParseKinds.td
index c513dab810d1f..4b8449e9ee9b6 100644
--- a/clang/include/clang/Basic/DiagnosticParseKinds.td
+++ b/clang/include/clang/Basic/DiagnosticParseKinds.td
@@ -1657,6 +1657,10 @@ def err_omp_expected_colon : Error<"missing ':' in %0">;
 def err_omp_missing_comma : Error< "missing ',' after %0">;
 def err_omp_expected_context_selector
 : Error<"expected valid context selector in %0">;
+def err_omp_unknown_clause
+: Error<"unknown clause '%0' in %1">;
+def warn_omp_default_deprecated : Warning<"'default' clause for"
+  " 'metadirective' is deprecated; use 'otherwise' instead">, 
InGroup;
 def err_omp_requires_out_inout_depend_type : Error<
   "reserved locator 'omp_all_memory' requires 'out' or 'inout' "
   "dependency types">;
diff --git a/clang/lib/Parse/ParseOpenMP.cpp b/clang/lib/Parse/ParseOpenMP.cpp
index 42e6aac681c1c..3b86847e937a2 100644
--- a/clang/lib/Parse/ParseOpenMP.cpp
+++ b/clang/lib/Parse/ParseOpenMP.cpp
@@ -2759,6 +2759,19 @@ StmtResult 
Parser::ParseOpenMPDeclarativeOrExecutableDirective(
   OpenMPClauseKind CKind = Tok.isAnnotation()
? OMPC_unknown
: getOpenMPClauseKind(PP.getSpelling(Tok));
+  // Check if the clause is unrecognized.
+  if (getLangOpts().OpenMP < 52 &&
+  (CKind == OMPC_unknown || CKind == OMPC_otherwise)) {
+Diag(Tok, diag::err_omp_unknown_clause)
+<< PP.getSpelling(Tok) << "metadirective";
+  }
+  if (getLangOpts().OpenMP >= 52 && CKind == OMPC_unknown) {
+Diag(Tok, diag::err_omp_unknown_clause)
+<< PP.getSpelling(Tok) << "metadirective";
+  }
+  if (CKind == OMPC_default && getLangOpts().OpenMP >= 52) {
+Diag(Tok, diag::warn_omp_default_deprecated);
+  }
   SourceLocation Loc = ConsumeToken();
 
   // Parse '('.
@@ -2785,6 +2798,13 @@ StmtResult 
Parser::ParseOpenMPDeclarativeOrExecutableDirective(
   return Directive;
 }
   }
+  if (CKind == OMPC_otherwise) {
+// Check for 'otherwise' keyword.
+if (Tok.is(tok::identifier) &&
+Tok.getIdentifierInfo()->getName() == "otherwise") {
+  ConsumeToken(); // Consume 'otherwise'
+}
+  }
   // Skip Directive for now. We will parse directive in the second 
iteration
   int paren = 0;
   while (Tok.isNot(tok::r_paren) || paren != 0) {
diff --git a/clang/test/OpenMP/metadirective_messages.cpp 
b/clang/test/OpenMP/metadirective_messages.cpp
index 7fce9fa446058..40ea37845fdff 100644
--- a/clang/test/OpenMP/metadirective_messages.cpp
+++ b/clang/test/OpenMP/metadirective_messages.cpp
@@ -2,21 +2,48 @@
 
 // RUN: %clang_cc1 -triple=x86_64-pc-linux-gnu -verify -fopenmp-simd -x c++ 
-std=c++14 -fexceptions -fcxx-exceptions %s
 
+// RUN: %clang_cc1 -triple=x86_64-pc-linux-gnu -verify=expected,omp52 -fopenmp 
-fopenmp-version=52 -ferror-limit 100 -o - %s -Wuninitialized
+
 void foo() {
-#pragma omp metadirective // expected-error {{expected expression}}
-  ;
-#pragma omp metadirective when() // expected-error {{expected valid context 
selector in when clause}} expected-error {{expected expression}} 
expected-warning {{expected identifier or string literal describing a context 
set; set skipped}} expected-note {{context set options are: 'construct' 
'device' 'target_device' 'implementation' 'user'}} expected-note {{the ignored 
set spans until here}}
-  ;
-#pragma omp metadirective when(device{}) // expected-warning {{expected '=' 
after the context set name "device"; '=' assumed}} expected-warning {{expected 
identifier or string literal describing a context selector; selector skipped}} 
expected-note {{context selector options are: 'kind' 'arch' 'isa'}} 
expected-note {{the ignored selector spans until here}} expected-error 
{{expected valid context selector in when clause}} expected-error {{expected 
expression}}
-  ;
-#pragma omp metadirective when(device{arch(nvptx)}) // expected-error 
{{missing ':' in when clause}} expected-error {{expected expression}} 
expected-warning {{expected '=' after the context set name "device"; '=' 
assumed}}
-  ;
-#pragma omp metadirective when(device{arch(nvptx)}: ) default() // 
expected-warning {{expected '=' after the context set name "device"; '=' 
assumed}}
-  ;
-#pragma omp metadirective when(device = {a

[clang] default clause replaced by otherwise clause for metadirective in OpenMP 5.2 (PR #128640)

2025-03-24 Thread Urvi Rav via cfe-commits

https://github.com/ravurvi20 updated 
https://github.com/llvm/llvm-project/pull/128640

>From 6ebd5991788608fbd104ea9c23230912044462d3 Mon Sep 17 00:00:00 2001
From: Urvi Rav 
Date: Tue, 25 Feb 2025 00:49:07 -0600
Subject: [PATCH] default clause replaced by otherwise clause for metadirective

---
 .../clang/Basic/DiagnosticParseKinds.td   |  4 ++
 clang/lib/Parse/ParseOpenMP.cpp   | 20 ++
 clang/test/OpenMP/metadirective_messages.cpp  | 61 +--
 3 files changed, 68 insertions(+), 17 deletions(-)

diff --git a/clang/include/clang/Basic/DiagnosticParseKinds.td 
b/clang/include/clang/Basic/DiagnosticParseKinds.td
index c513dab810d1f..4b8449e9ee9b6 100644
--- a/clang/include/clang/Basic/DiagnosticParseKinds.td
+++ b/clang/include/clang/Basic/DiagnosticParseKinds.td
@@ -1657,6 +1657,10 @@ def err_omp_expected_colon : Error<"missing ':' in %0">;
 def err_omp_missing_comma : Error< "missing ',' after %0">;
 def err_omp_expected_context_selector
 : Error<"expected valid context selector in %0">;
+def err_omp_unknown_clause
+: Error<"unknown clause '%0' in %1">;
+def warn_omp_default_deprecated : Warning<"'default' clause for"
+  " 'metadirective' is deprecated; use 'otherwise' instead">, 
InGroup;
 def err_omp_requires_out_inout_depend_type : Error<
   "reserved locator 'omp_all_memory' requires 'out' or 'inout' "
   "dependency types">;
diff --git a/clang/lib/Parse/ParseOpenMP.cpp b/clang/lib/Parse/ParseOpenMP.cpp
index 42e6aac681c1c..3b86847e937a2 100644
--- a/clang/lib/Parse/ParseOpenMP.cpp
+++ b/clang/lib/Parse/ParseOpenMP.cpp
@@ -2759,6 +2759,19 @@ StmtResult 
Parser::ParseOpenMPDeclarativeOrExecutableDirective(
   OpenMPClauseKind CKind = Tok.isAnnotation()
? OMPC_unknown
: getOpenMPClauseKind(PP.getSpelling(Tok));
+  // Check if the clause is unrecognized.
+  if (getLangOpts().OpenMP < 52 &&
+  (CKind == OMPC_unknown || CKind == OMPC_otherwise)) {
+Diag(Tok, diag::err_omp_unknown_clause)
+<< PP.getSpelling(Tok) << "metadirective";
+  }
+  if (getLangOpts().OpenMP >= 52 && CKind == OMPC_unknown) {
+Diag(Tok, diag::err_omp_unknown_clause)
+<< PP.getSpelling(Tok) << "metadirective";
+  }
+  if (CKind == OMPC_default && getLangOpts().OpenMP >= 52) {
+Diag(Tok, diag::warn_omp_default_deprecated);
+  }
   SourceLocation Loc = ConsumeToken();
 
   // Parse '('.
@@ -2785,6 +2798,13 @@ StmtResult 
Parser::ParseOpenMPDeclarativeOrExecutableDirective(
   return Directive;
 }
   }
+  if (CKind == OMPC_otherwise) {
+// Check for 'otherwise' keyword.
+if (Tok.is(tok::identifier) &&
+Tok.getIdentifierInfo()->getName() == "otherwise") {
+  ConsumeToken(); // Consume 'otherwise'
+}
+  }
   // Skip Directive for now. We will parse directive in the second 
iteration
   int paren = 0;
   while (Tok.isNot(tok::r_paren) || paren != 0) {
diff --git a/clang/test/OpenMP/metadirective_messages.cpp 
b/clang/test/OpenMP/metadirective_messages.cpp
index 7fce9fa446058..40ea37845fdff 100644
--- a/clang/test/OpenMP/metadirective_messages.cpp
+++ b/clang/test/OpenMP/metadirective_messages.cpp
@@ -2,21 +2,48 @@
 
 // RUN: %clang_cc1 -triple=x86_64-pc-linux-gnu -verify -fopenmp-simd -x c++ 
-std=c++14 -fexceptions -fcxx-exceptions %s
 
+// RUN: %clang_cc1 -triple=x86_64-pc-linux-gnu -verify=expected,omp52 -fopenmp 
-fopenmp-version=52 -ferror-limit 100 -o - %s -Wuninitialized
+
 void foo() {
-#pragma omp metadirective // expected-error {{expected expression}}
-  ;
-#pragma omp metadirective when() // expected-error {{expected valid context 
selector in when clause}} expected-error {{expected expression}} 
expected-warning {{expected identifier or string literal describing a context 
set; set skipped}} expected-note {{context set options are: 'construct' 
'device' 'target_device' 'implementation' 'user'}} expected-note {{the ignored 
set spans until here}}
-  ;
-#pragma omp metadirective when(device{}) // expected-warning {{expected '=' 
after the context set name "device"; '=' assumed}} expected-warning {{expected 
identifier or string literal describing a context selector; selector skipped}} 
expected-note {{context selector options are: 'kind' 'arch' 'isa'}} 
expected-note {{the ignored selector spans until here}} expected-error 
{{expected valid context selector in when clause}} expected-error {{expected 
expression}}
-  ;
-#pragma omp metadirective when(device{arch(nvptx)}) // expected-error 
{{missing ':' in when clause}} expected-error {{expected expression}} 
expected-warning {{expected '=' after the context set name "device"; '=' 
assumed}}
-  ;
-#pragma omp metadirective when(device{arch(nvptx)}: ) default() // 
expected-warning {{expected '=' after the context set name "device"; '=' 
assumed}}
-  ;
-#pragma omp metadirective when(device = {a

[clang] default clause replaced by otherwise clause for metadirective in OpenMP 5.2 (PR #128640)

2025-03-25 Thread Urvi Rav via cfe-commits

https://github.com/ravurvi20 updated 
https://github.com/llvm/llvm-project/pull/128640

>From 6ebd5991788608fbd104ea9c23230912044462d3 Mon Sep 17 00:00:00 2001
From: Urvi Rav 
Date: Tue, 25 Feb 2025 00:49:07 -0600
Subject: [PATCH] default clause replaced by otherwise clause for metadirective

---
 .../clang/Basic/DiagnosticParseKinds.td   |  4 ++
 clang/lib/Parse/ParseOpenMP.cpp   | 20 ++
 clang/test/OpenMP/metadirective_messages.cpp  | 61 +--
 3 files changed, 68 insertions(+), 17 deletions(-)

diff --git a/clang/include/clang/Basic/DiagnosticParseKinds.td 
b/clang/include/clang/Basic/DiagnosticParseKinds.td
index c513dab810d1f..4b8449e9ee9b6 100644
--- a/clang/include/clang/Basic/DiagnosticParseKinds.td
+++ b/clang/include/clang/Basic/DiagnosticParseKinds.td
@@ -1657,6 +1657,10 @@ def err_omp_expected_colon : Error<"missing ':' in %0">;
 def err_omp_missing_comma : Error< "missing ',' after %0">;
 def err_omp_expected_context_selector
 : Error<"expected valid context selector in %0">;
+def err_omp_unknown_clause
+: Error<"unknown clause '%0' in %1">;
+def warn_omp_default_deprecated : Warning<"'default' clause for"
+  " 'metadirective' is deprecated; use 'otherwise' instead">, 
InGroup;
 def err_omp_requires_out_inout_depend_type : Error<
   "reserved locator 'omp_all_memory' requires 'out' or 'inout' "
   "dependency types">;
diff --git a/clang/lib/Parse/ParseOpenMP.cpp b/clang/lib/Parse/ParseOpenMP.cpp
index 42e6aac681c1c..3b86847e937a2 100644
--- a/clang/lib/Parse/ParseOpenMP.cpp
+++ b/clang/lib/Parse/ParseOpenMP.cpp
@@ -2759,6 +2759,19 @@ StmtResult 
Parser::ParseOpenMPDeclarativeOrExecutableDirective(
   OpenMPClauseKind CKind = Tok.isAnnotation()
? OMPC_unknown
: getOpenMPClauseKind(PP.getSpelling(Tok));
+  // Check if the clause is unrecognized.
+  if (getLangOpts().OpenMP < 52 &&
+  (CKind == OMPC_unknown || CKind == OMPC_otherwise)) {
+Diag(Tok, diag::err_omp_unknown_clause)
+<< PP.getSpelling(Tok) << "metadirective";
+  }
+  if (getLangOpts().OpenMP >= 52 && CKind == OMPC_unknown) {
+Diag(Tok, diag::err_omp_unknown_clause)
+<< PP.getSpelling(Tok) << "metadirective";
+  }
+  if (CKind == OMPC_default && getLangOpts().OpenMP >= 52) {
+Diag(Tok, diag::warn_omp_default_deprecated);
+  }
   SourceLocation Loc = ConsumeToken();
 
   // Parse '('.
@@ -2785,6 +2798,13 @@ StmtResult 
Parser::ParseOpenMPDeclarativeOrExecutableDirective(
   return Directive;
 }
   }
+  if (CKind == OMPC_otherwise) {
+// Check for 'otherwise' keyword.
+if (Tok.is(tok::identifier) &&
+Tok.getIdentifierInfo()->getName() == "otherwise") {
+  ConsumeToken(); // Consume 'otherwise'
+}
+  }
   // Skip Directive for now. We will parse directive in the second 
iteration
   int paren = 0;
   while (Tok.isNot(tok::r_paren) || paren != 0) {
diff --git a/clang/test/OpenMP/metadirective_messages.cpp 
b/clang/test/OpenMP/metadirective_messages.cpp
index 7fce9fa446058..40ea37845fdff 100644
--- a/clang/test/OpenMP/metadirective_messages.cpp
+++ b/clang/test/OpenMP/metadirective_messages.cpp
@@ -2,21 +2,48 @@
 
 // RUN: %clang_cc1 -triple=x86_64-pc-linux-gnu -verify -fopenmp-simd -x c++ 
-std=c++14 -fexceptions -fcxx-exceptions %s
 
+// RUN: %clang_cc1 -triple=x86_64-pc-linux-gnu -verify=expected,omp52 -fopenmp 
-fopenmp-version=52 -ferror-limit 100 -o - %s -Wuninitialized
+
 void foo() {
-#pragma omp metadirective // expected-error {{expected expression}}
-  ;
-#pragma omp metadirective when() // expected-error {{expected valid context 
selector in when clause}} expected-error {{expected expression}} 
expected-warning {{expected identifier or string literal describing a context 
set; set skipped}} expected-note {{context set options are: 'construct' 
'device' 'target_device' 'implementation' 'user'}} expected-note {{the ignored 
set spans until here}}
-  ;
-#pragma omp metadirective when(device{}) // expected-warning {{expected '=' 
after the context set name "device"; '=' assumed}} expected-warning {{expected 
identifier or string literal describing a context selector; selector skipped}} 
expected-note {{context selector options are: 'kind' 'arch' 'isa'}} 
expected-note {{the ignored selector spans until here}} expected-error 
{{expected valid context selector in when clause}} expected-error {{expected 
expression}}
-  ;
-#pragma omp metadirective when(device{arch(nvptx)}) // expected-error 
{{missing ':' in when clause}} expected-error {{expected expression}} 
expected-warning {{expected '=' after the context set name "device"; '=' 
assumed}}
-  ;
-#pragma omp metadirective when(device{arch(nvptx)}: ) default() // 
expected-warning {{expected '=' after the context set name "device"; '=' 
assumed}}
-  ;
-#pragma omp metadirective when(device = {a

[clang] default clause replaced by otherwise clause for metadirective in OpenMP 5.2 (PR #128640)

2025-04-02 Thread Urvi Rav via cfe-commits

https://github.com/ravurvi20 updated 
https://github.com/llvm/llvm-project/pull/128640

>From 6ebd5991788608fbd104ea9c23230912044462d3 Mon Sep 17 00:00:00 2001
From: Urvi Rav 
Date: Tue, 25 Feb 2025 00:49:07 -0600
Subject: [PATCH 1/3] default clause replaced by otherwise clause for
 metadirective

---
 .../clang/Basic/DiagnosticParseKinds.td   |  4 ++
 clang/lib/Parse/ParseOpenMP.cpp   | 20 ++
 clang/test/OpenMP/metadirective_messages.cpp  | 61 +--
 3 files changed, 68 insertions(+), 17 deletions(-)

diff --git a/clang/include/clang/Basic/DiagnosticParseKinds.td 
b/clang/include/clang/Basic/DiagnosticParseKinds.td
index c513dab810d1f..4b8449e9ee9b6 100644
--- a/clang/include/clang/Basic/DiagnosticParseKinds.td
+++ b/clang/include/clang/Basic/DiagnosticParseKinds.td
@@ -1657,6 +1657,10 @@ def err_omp_expected_colon : Error<"missing ':' in %0">;
 def err_omp_missing_comma : Error< "missing ',' after %0">;
 def err_omp_expected_context_selector
 : Error<"expected valid context selector in %0">;
+def err_omp_unknown_clause
+: Error<"unknown clause '%0' in %1">;
+def warn_omp_default_deprecated : Warning<"'default' clause for"
+  " 'metadirective' is deprecated; use 'otherwise' instead">, 
InGroup;
 def err_omp_requires_out_inout_depend_type : Error<
   "reserved locator 'omp_all_memory' requires 'out' or 'inout' "
   "dependency types">;
diff --git a/clang/lib/Parse/ParseOpenMP.cpp b/clang/lib/Parse/ParseOpenMP.cpp
index 42e6aac681c1c..3b86847e937a2 100644
--- a/clang/lib/Parse/ParseOpenMP.cpp
+++ b/clang/lib/Parse/ParseOpenMP.cpp
@@ -2759,6 +2759,19 @@ StmtResult 
Parser::ParseOpenMPDeclarativeOrExecutableDirective(
   OpenMPClauseKind CKind = Tok.isAnnotation()
? OMPC_unknown
: getOpenMPClauseKind(PP.getSpelling(Tok));
+  // Check if the clause is unrecognized.
+  if (getLangOpts().OpenMP < 52 &&
+  (CKind == OMPC_unknown || CKind == OMPC_otherwise)) {
+Diag(Tok, diag::err_omp_unknown_clause)
+<< PP.getSpelling(Tok) << "metadirective";
+  }
+  if (getLangOpts().OpenMP >= 52 && CKind == OMPC_unknown) {
+Diag(Tok, diag::err_omp_unknown_clause)
+<< PP.getSpelling(Tok) << "metadirective";
+  }
+  if (CKind == OMPC_default && getLangOpts().OpenMP >= 52) {
+Diag(Tok, diag::warn_omp_default_deprecated);
+  }
   SourceLocation Loc = ConsumeToken();
 
   // Parse '('.
@@ -2785,6 +2798,13 @@ StmtResult 
Parser::ParseOpenMPDeclarativeOrExecutableDirective(
   return Directive;
 }
   }
+  if (CKind == OMPC_otherwise) {
+// Check for 'otherwise' keyword.
+if (Tok.is(tok::identifier) &&
+Tok.getIdentifierInfo()->getName() == "otherwise") {
+  ConsumeToken(); // Consume 'otherwise'
+}
+  }
   // Skip Directive for now. We will parse directive in the second 
iteration
   int paren = 0;
   while (Tok.isNot(tok::r_paren) || paren != 0) {
diff --git a/clang/test/OpenMP/metadirective_messages.cpp 
b/clang/test/OpenMP/metadirective_messages.cpp
index 7fce9fa446058..40ea37845fdff 100644
--- a/clang/test/OpenMP/metadirective_messages.cpp
+++ b/clang/test/OpenMP/metadirective_messages.cpp
@@ -2,21 +2,48 @@
 
 // RUN: %clang_cc1 -triple=x86_64-pc-linux-gnu -verify -fopenmp-simd -x c++ 
-std=c++14 -fexceptions -fcxx-exceptions %s
 
+// RUN: %clang_cc1 -triple=x86_64-pc-linux-gnu -verify=expected,omp52 -fopenmp 
-fopenmp-version=52 -ferror-limit 100 -o - %s -Wuninitialized
+
 void foo() {
-#pragma omp metadirective // expected-error {{expected expression}}
-  ;
-#pragma omp metadirective when() // expected-error {{expected valid context 
selector in when clause}} expected-error {{expected expression}} 
expected-warning {{expected identifier or string literal describing a context 
set; set skipped}} expected-note {{context set options are: 'construct' 
'device' 'target_device' 'implementation' 'user'}} expected-note {{the ignored 
set spans until here}}
-  ;
-#pragma omp metadirective when(device{}) // expected-warning {{expected '=' 
after the context set name "device"; '=' assumed}} expected-warning {{expected 
identifier or string literal describing a context selector; selector skipped}} 
expected-note {{context selector options are: 'kind' 'arch' 'isa'}} 
expected-note {{the ignored selector spans until here}} expected-error 
{{expected valid context selector in when clause}} expected-error {{expected 
expression}}
-  ;
-#pragma omp metadirective when(device{arch(nvptx)}) // expected-error 
{{missing ':' in when clause}} expected-error {{expected expression}} 
expected-warning {{expected '=' after the context set name "device"; '=' 
assumed}}
-  ;
-#pragma omp metadirective when(device{arch(nvptx)}: ) default() // 
expected-warning {{expected '=' after the context set name "device"; '=' 
assumed}}
-  ;
-#pragma omp metadirective when(device

[clang] default clause replaced by otherwise clause for metadirective in OpenMP 5.2 (PR #128640)

2025-04-01 Thread Urvi Rav via cfe-commits

https://github.com/ravurvi20 updated 
https://github.com/llvm/llvm-project/pull/128640

>From 6ebd5991788608fbd104ea9c23230912044462d3 Mon Sep 17 00:00:00 2001
From: Urvi Rav 
Date: Tue, 25 Feb 2025 00:49:07 -0600
Subject: [PATCH 1/2] default clause replaced by otherwise clause for
 metadirective

---
 .../clang/Basic/DiagnosticParseKinds.td   |  4 ++
 clang/lib/Parse/ParseOpenMP.cpp   | 20 ++
 clang/test/OpenMP/metadirective_messages.cpp  | 61 +--
 3 files changed, 68 insertions(+), 17 deletions(-)

diff --git a/clang/include/clang/Basic/DiagnosticParseKinds.td 
b/clang/include/clang/Basic/DiagnosticParseKinds.td
index c513dab810d1f..4b8449e9ee9b6 100644
--- a/clang/include/clang/Basic/DiagnosticParseKinds.td
+++ b/clang/include/clang/Basic/DiagnosticParseKinds.td
@@ -1657,6 +1657,10 @@ def err_omp_expected_colon : Error<"missing ':' in %0">;
 def err_omp_missing_comma : Error< "missing ',' after %0">;
 def err_omp_expected_context_selector
 : Error<"expected valid context selector in %0">;
+def err_omp_unknown_clause
+: Error<"unknown clause '%0' in %1">;
+def warn_omp_default_deprecated : Warning<"'default' clause for"
+  " 'metadirective' is deprecated; use 'otherwise' instead">, 
InGroup;
 def err_omp_requires_out_inout_depend_type : Error<
   "reserved locator 'omp_all_memory' requires 'out' or 'inout' "
   "dependency types">;
diff --git a/clang/lib/Parse/ParseOpenMP.cpp b/clang/lib/Parse/ParseOpenMP.cpp
index 42e6aac681c1c..3b86847e937a2 100644
--- a/clang/lib/Parse/ParseOpenMP.cpp
+++ b/clang/lib/Parse/ParseOpenMP.cpp
@@ -2759,6 +2759,19 @@ StmtResult 
Parser::ParseOpenMPDeclarativeOrExecutableDirective(
   OpenMPClauseKind CKind = Tok.isAnnotation()
? OMPC_unknown
: getOpenMPClauseKind(PP.getSpelling(Tok));
+  // Check if the clause is unrecognized.
+  if (getLangOpts().OpenMP < 52 &&
+  (CKind == OMPC_unknown || CKind == OMPC_otherwise)) {
+Diag(Tok, diag::err_omp_unknown_clause)
+<< PP.getSpelling(Tok) << "metadirective";
+  }
+  if (getLangOpts().OpenMP >= 52 && CKind == OMPC_unknown) {
+Diag(Tok, diag::err_omp_unknown_clause)
+<< PP.getSpelling(Tok) << "metadirective";
+  }
+  if (CKind == OMPC_default && getLangOpts().OpenMP >= 52) {
+Diag(Tok, diag::warn_omp_default_deprecated);
+  }
   SourceLocation Loc = ConsumeToken();
 
   // Parse '('.
@@ -2785,6 +2798,13 @@ StmtResult 
Parser::ParseOpenMPDeclarativeOrExecutableDirective(
   return Directive;
 }
   }
+  if (CKind == OMPC_otherwise) {
+// Check for 'otherwise' keyword.
+if (Tok.is(tok::identifier) &&
+Tok.getIdentifierInfo()->getName() == "otherwise") {
+  ConsumeToken(); // Consume 'otherwise'
+}
+  }
   // Skip Directive for now. We will parse directive in the second 
iteration
   int paren = 0;
   while (Tok.isNot(tok::r_paren) || paren != 0) {
diff --git a/clang/test/OpenMP/metadirective_messages.cpp 
b/clang/test/OpenMP/metadirective_messages.cpp
index 7fce9fa446058..40ea37845fdff 100644
--- a/clang/test/OpenMP/metadirective_messages.cpp
+++ b/clang/test/OpenMP/metadirective_messages.cpp
@@ -2,21 +2,48 @@
 
 // RUN: %clang_cc1 -triple=x86_64-pc-linux-gnu -verify -fopenmp-simd -x c++ 
-std=c++14 -fexceptions -fcxx-exceptions %s
 
+// RUN: %clang_cc1 -triple=x86_64-pc-linux-gnu -verify=expected,omp52 -fopenmp 
-fopenmp-version=52 -ferror-limit 100 -o - %s -Wuninitialized
+
 void foo() {
-#pragma omp metadirective // expected-error {{expected expression}}
-  ;
-#pragma omp metadirective when() // expected-error {{expected valid context 
selector in when clause}} expected-error {{expected expression}} 
expected-warning {{expected identifier or string literal describing a context 
set; set skipped}} expected-note {{context set options are: 'construct' 
'device' 'target_device' 'implementation' 'user'}} expected-note {{the ignored 
set spans until here}}
-  ;
-#pragma omp metadirective when(device{}) // expected-warning {{expected '=' 
after the context set name "device"; '=' assumed}} expected-warning {{expected 
identifier or string literal describing a context selector; selector skipped}} 
expected-note {{context selector options are: 'kind' 'arch' 'isa'}} 
expected-note {{the ignored selector spans until here}} expected-error 
{{expected valid context selector in when clause}} expected-error {{expected 
expression}}
-  ;
-#pragma omp metadirective when(device{arch(nvptx)}) // expected-error 
{{missing ':' in when clause}} expected-error {{expected expression}} 
expected-warning {{expected '=' after the context set name "device"; '=' 
assumed}}
-  ;
-#pragma omp metadirective when(device{arch(nvptx)}: ) default() // 
expected-warning {{expected '=' after the context set name "device"; '=' 
assumed}}
-  ;
-#pragma omp metadirective when(device

[clang] default clause replaced by otherwise clause for metadirective in OpenMP 5.2 (PR #128640)

2025-03-24 Thread Urvi Rav via cfe-commits

ravurvi20 wrote:

@mjklemm could you please approve this PR. There was minor change which has 
been fixed now.

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


[clang] default clause replaced by otherwise clause for metadirective in OpenMP 5.2 (PR #128640)

2025-04-02 Thread Urvi Rav via cfe-commits


@@ -2759,6 +2759,19 @@ StmtResult 
Parser::ParseOpenMPDeclarativeOrExecutableDirective(
   OpenMPClauseKind CKind = Tok.isAnnotation()
? OMPC_unknown
: getOpenMPClauseKind(PP.getSpelling(Tok));
+  // Check if the clause is unrecognized.
+  if (getLangOpts().OpenMP < 52 &&
+  (CKind == OMPC_unknown || CKind == OMPC_otherwise)) {
+Diag(Tok, diag::err_omp_unknown_clause)
+<< PP.getSpelling(Tok) << "metadirective";
+  }
+  if (getLangOpts().OpenMP >= 52 && CKind == OMPC_unknown) {
+Diag(Tok, diag::err_omp_unknown_clause)
+<< PP.getSpelling(Tok) << "metadirective";
+  }

ravurvi20 wrote:

@kparzysz I have made the requested modifications to the code based on your 
suggestions. Please review it and provide your feedback.

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


[clang] default clause replaced by otherwise clause for metadirective in OpenMP 5.2 (PR #128640)

2025-04-03 Thread Urvi Rav via cfe-commits


@@ -2759,6 +2759,19 @@ StmtResult 
Parser::ParseOpenMPDeclarativeOrExecutableDirective(
   OpenMPClauseKind CKind = Tok.isAnnotation()
? OMPC_unknown
: getOpenMPClauseKind(PP.getSpelling(Tok));
+  // Check if the clause is unrecognized.
+  if (getLangOpts().OpenMP < 52 &&
+  (CKind == OMPC_unknown || CKind == OMPC_otherwise)) {
+Diag(Tok, diag::err_omp_unknown_clause)
+<< PP.getSpelling(Tok) << "metadirective";
+  }
+  if (getLangOpts().OpenMP >= 52 && CKind == OMPC_unknown) {
+Diag(Tok, diag::err_omp_unknown_clause)
+<< PP.getSpelling(Tok) << "metadirective";
+  }

ravurvi20 wrote:

ping @kparzysz 

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


[clang] default clause replaced by otherwise clause for metadirective in OpenMP 5.2 (PR #128640)

2025-04-28 Thread Urvi Rav via cfe-commits


@@ -2759,6 +2759,18 @@ StmtResult 
Parser::ParseOpenMPDeclarativeOrExecutableDirective(
   OpenMPClauseKind CKind = Tok.isAnnotation()
? OMPC_unknown
: getOpenMPClauseKind(PP.getSpelling(Tok));
+  // Check if the clause is unrecognized.
+  if (CKind == OMPC_unknown) {
+Diag(Tok, diag::err_omp_unknown_clause)
+<< PP.getSpelling(Tok) << "metadirective";

ravurvi20 wrote:

ping @alexey-bataev 

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


[clang] default clause replaced by otherwise clause for metadirective in OpenMP 5.2 (PR #128640)

2025-04-27 Thread Urvi Rav via cfe-commits


@@ -2759,6 +2759,18 @@ StmtResult 
Parser::ParseOpenMPDeclarativeOrExecutableDirective(
   OpenMPClauseKind CKind = Tok.isAnnotation()
? OMPC_unknown
: getOpenMPClauseKind(PP.getSpelling(Tok));
+  // Check if the clause is unrecognized.
+  if (CKind == OMPC_unknown) {
+Diag(Tok, diag::err_omp_unknown_clause)
+<< PP.getSpelling(Tok) << "metadirective";

ravurvi20 wrote:

@alexey-bataev I have addressed it and modified the error messages. Could 
please take a look at it again.


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


[clang] default clause replaced by otherwise clause for metadirective in OpenMP 5.2 (PR #128640)

2025-04-26 Thread Urvi Rav via cfe-commits

https://github.com/ravurvi20 updated 
https://github.com/llvm/llvm-project/pull/128640

>From 6ebd5991788608fbd104ea9c23230912044462d3 Mon Sep 17 00:00:00 2001
From: Urvi Rav 
Date: Tue, 25 Feb 2025 00:49:07 -0600
Subject: [PATCH 1/5] default clause replaced by otherwise clause for
 metadirective

---
 .../clang/Basic/DiagnosticParseKinds.td   |  4 ++
 clang/lib/Parse/ParseOpenMP.cpp   | 20 ++
 clang/test/OpenMP/metadirective_messages.cpp  | 61 +--
 3 files changed, 68 insertions(+), 17 deletions(-)

diff --git a/clang/include/clang/Basic/DiagnosticParseKinds.td 
b/clang/include/clang/Basic/DiagnosticParseKinds.td
index c513dab810d1f..4b8449e9ee9b6 100644
--- a/clang/include/clang/Basic/DiagnosticParseKinds.td
+++ b/clang/include/clang/Basic/DiagnosticParseKinds.td
@@ -1657,6 +1657,10 @@ def err_omp_expected_colon : Error<"missing ':' in %0">;
 def err_omp_missing_comma : Error< "missing ',' after %0">;
 def err_omp_expected_context_selector
 : Error<"expected valid context selector in %0">;
+def err_omp_unknown_clause
+: Error<"unknown clause '%0' in %1">;
+def warn_omp_default_deprecated : Warning<"'default' clause for"
+  " 'metadirective' is deprecated; use 'otherwise' instead">, 
InGroup;
 def err_omp_requires_out_inout_depend_type : Error<
   "reserved locator 'omp_all_memory' requires 'out' or 'inout' "
   "dependency types">;
diff --git a/clang/lib/Parse/ParseOpenMP.cpp b/clang/lib/Parse/ParseOpenMP.cpp
index 42e6aac681c1c..3b86847e937a2 100644
--- a/clang/lib/Parse/ParseOpenMP.cpp
+++ b/clang/lib/Parse/ParseOpenMP.cpp
@@ -2759,6 +2759,19 @@ StmtResult 
Parser::ParseOpenMPDeclarativeOrExecutableDirective(
   OpenMPClauseKind CKind = Tok.isAnnotation()
? OMPC_unknown
: getOpenMPClauseKind(PP.getSpelling(Tok));
+  // Check if the clause is unrecognized.
+  if (getLangOpts().OpenMP < 52 &&
+  (CKind == OMPC_unknown || CKind == OMPC_otherwise)) {
+Diag(Tok, diag::err_omp_unknown_clause)
+<< PP.getSpelling(Tok) << "metadirective";
+  }
+  if (getLangOpts().OpenMP >= 52 && CKind == OMPC_unknown) {
+Diag(Tok, diag::err_omp_unknown_clause)
+<< PP.getSpelling(Tok) << "metadirective";
+  }
+  if (CKind == OMPC_default && getLangOpts().OpenMP >= 52) {
+Diag(Tok, diag::warn_omp_default_deprecated);
+  }
   SourceLocation Loc = ConsumeToken();
 
   // Parse '('.
@@ -2785,6 +2798,13 @@ StmtResult 
Parser::ParseOpenMPDeclarativeOrExecutableDirective(
   return Directive;
 }
   }
+  if (CKind == OMPC_otherwise) {
+// Check for 'otherwise' keyword.
+if (Tok.is(tok::identifier) &&
+Tok.getIdentifierInfo()->getName() == "otherwise") {
+  ConsumeToken(); // Consume 'otherwise'
+}
+  }
   // Skip Directive for now. We will parse directive in the second 
iteration
   int paren = 0;
   while (Tok.isNot(tok::r_paren) || paren != 0) {
diff --git a/clang/test/OpenMP/metadirective_messages.cpp 
b/clang/test/OpenMP/metadirective_messages.cpp
index 7fce9fa446058..40ea37845fdff 100644
--- a/clang/test/OpenMP/metadirective_messages.cpp
+++ b/clang/test/OpenMP/metadirective_messages.cpp
@@ -2,21 +2,48 @@
 
 // RUN: %clang_cc1 -triple=x86_64-pc-linux-gnu -verify -fopenmp-simd -x c++ 
-std=c++14 -fexceptions -fcxx-exceptions %s
 
+// RUN: %clang_cc1 -triple=x86_64-pc-linux-gnu -verify=expected,omp52 -fopenmp 
-fopenmp-version=52 -ferror-limit 100 -o - %s -Wuninitialized
+
 void foo() {
-#pragma omp metadirective // expected-error {{expected expression}}
-  ;
-#pragma omp metadirective when() // expected-error {{expected valid context 
selector in when clause}} expected-error {{expected expression}} 
expected-warning {{expected identifier or string literal describing a context 
set; set skipped}} expected-note {{context set options are: 'construct' 
'device' 'target_device' 'implementation' 'user'}} expected-note {{the ignored 
set spans until here}}
-  ;
-#pragma omp metadirective when(device{}) // expected-warning {{expected '=' 
after the context set name "device"; '=' assumed}} expected-warning {{expected 
identifier or string literal describing a context selector; selector skipped}} 
expected-note {{context selector options are: 'kind' 'arch' 'isa'}} 
expected-note {{the ignored selector spans until here}} expected-error 
{{expected valid context selector in when clause}} expected-error {{expected 
expression}}
-  ;
-#pragma omp metadirective when(device{arch(nvptx)}) // expected-error 
{{missing ':' in when clause}} expected-error {{expected expression}} 
expected-warning {{expected '=' after the context set name "device"; '=' 
assumed}}
-  ;
-#pragma omp metadirective when(device{arch(nvptx)}: ) default() // 
expected-warning {{expected '=' after the context set name "device"; '=' 
assumed}}
-  ;
-#pragma omp metadirective when(device

[clang] default clause replaced by otherwise clause for metadirective in OpenMP 5.2 (PR #128640)

2025-04-30 Thread Urvi Rav via cfe-commits

ravurvi20 wrote:

Thankyou. Updated OpenMPSupport.rst file.

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


[clang] default clause replaced by otherwise clause for metadirective in OpenMP 5.2 (PR #128640)

2025-04-30 Thread Urvi Rav via cfe-commits

https://github.com/ravurvi20 updated 
https://github.com/llvm/llvm-project/pull/128640

>From 6ebd5991788608fbd104ea9c23230912044462d3 Mon Sep 17 00:00:00 2001
From: Urvi Rav 
Date: Tue, 25 Feb 2025 00:49:07 -0600
Subject: [PATCH 1/7] default clause replaced by otherwise clause for
 metadirective

---
 .../clang/Basic/DiagnosticParseKinds.td   |  4 ++
 clang/lib/Parse/ParseOpenMP.cpp   | 20 ++
 clang/test/OpenMP/metadirective_messages.cpp  | 61 +--
 3 files changed, 68 insertions(+), 17 deletions(-)

diff --git a/clang/include/clang/Basic/DiagnosticParseKinds.td 
b/clang/include/clang/Basic/DiagnosticParseKinds.td
index c513dab810d1f..4b8449e9ee9b6 100644
--- a/clang/include/clang/Basic/DiagnosticParseKinds.td
+++ b/clang/include/clang/Basic/DiagnosticParseKinds.td
@@ -1657,6 +1657,10 @@ def err_omp_expected_colon : Error<"missing ':' in %0">;
 def err_omp_missing_comma : Error< "missing ',' after %0">;
 def err_omp_expected_context_selector
 : Error<"expected valid context selector in %0">;
+def err_omp_unknown_clause
+: Error<"unknown clause '%0' in %1">;
+def warn_omp_default_deprecated : Warning<"'default' clause for"
+  " 'metadirective' is deprecated; use 'otherwise' instead">, 
InGroup;
 def err_omp_requires_out_inout_depend_type : Error<
   "reserved locator 'omp_all_memory' requires 'out' or 'inout' "
   "dependency types">;
diff --git a/clang/lib/Parse/ParseOpenMP.cpp b/clang/lib/Parse/ParseOpenMP.cpp
index 42e6aac681c1c..3b86847e937a2 100644
--- a/clang/lib/Parse/ParseOpenMP.cpp
+++ b/clang/lib/Parse/ParseOpenMP.cpp
@@ -2759,6 +2759,19 @@ StmtResult 
Parser::ParseOpenMPDeclarativeOrExecutableDirective(
   OpenMPClauseKind CKind = Tok.isAnnotation()
? OMPC_unknown
: getOpenMPClauseKind(PP.getSpelling(Tok));
+  // Check if the clause is unrecognized.
+  if (getLangOpts().OpenMP < 52 &&
+  (CKind == OMPC_unknown || CKind == OMPC_otherwise)) {
+Diag(Tok, diag::err_omp_unknown_clause)
+<< PP.getSpelling(Tok) << "metadirective";
+  }
+  if (getLangOpts().OpenMP >= 52 && CKind == OMPC_unknown) {
+Diag(Tok, diag::err_omp_unknown_clause)
+<< PP.getSpelling(Tok) << "metadirective";
+  }
+  if (CKind == OMPC_default && getLangOpts().OpenMP >= 52) {
+Diag(Tok, diag::warn_omp_default_deprecated);
+  }
   SourceLocation Loc = ConsumeToken();
 
   // Parse '('.
@@ -2785,6 +2798,13 @@ StmtResult 
Parser::ParseOpenMPDeclarativeOrExecutableDirective(
   return Directive;
 }
   }
+  if (CKind == OMPC_otherwise) {
+// Check for 'otherwise' keyword.
+if (Tok.is(tok::identifier) &&
+Tok.getIdentifierInfo()->getName() == "otherwise") {
+  ConsumeToken(); // Consume 'otherwise'
+}
+  }
   // Skip Directive for now. We will parse directive in the second 
iteration
   int paren = 0;
   while (Tok.isNot(tok::r_paren) || paren != 0) {
diff --git a/clang/test/OpenMP/metadirective_messages.cpp 
b/clang/test/OpenMP/metadirective_messages.cpp
index 7fce9fa446058..40ea37845fdff 100644
--- a/clang/test/OpenMP/metadirective_messages.cpp
+++ b/clang/test/OpenMP/metadirective_messages.cpp
@@ -2,21 +2,48 @@
 
 // RUN: %clang_cc1 -triple=x86_64-pc-linux-gnu -verify -fopenmp-simd -x c++ 
-std=c++14 -fexceptions -fcxx-exceptions %s
 
+// RUN: %clang_cc1 -triple=x86_64-pc-linux-gnu -verify=expected,omp52 -fopenmp 
-fopenmp-version=52 -ferror-limit 100 -o - %s -Wuninitialized
+
 void foo() {
-#pragma omp metadirective // expected-error {{expected expression}}
-  ;
-#pragma omp metadirective when() // expected-error {{expected valid context 
selector in when clause}} expected-error {{expected expression}} 
expected-warning {{expected identifier or string literal describing a context 
set; set skipped}} expected-note {{context set options are: 'construct' 
'device' 'target_device' 'implementation' 'user'}} expected-note {{the ignored 
set spans until here}}
-  ;
-#pragma omp metadirective when(device{}) // expected-warning {{expected '=' 
after the context set name "device"; '=' assumed}} expected-warning {{expected 
identifier or string literal describing a context selector; selector skipped}} 
expected-note {{context selector options are: 'kind' 'arch' 'isa'}} 
expected-note {{the ignored selector spans until here}} expected-error 
{{expected valid context selector in when clause}} expected-error {{expected 
expression}}
-  ;
-#pragma omp metadirective when(device{arch(nvptx)}) // expected-error 
{{missing ':' in when clause}} expected-error {{expected expression}} 
expected-warning {{expected '=' after the context set name "device"; '=' 
assumed}}
-  ;
-#pragma omp metadirective when(device{arch(nvptx)}: ) default() // 
expected-warning {{expected '=' after the context set name "device"; '=' 
assumed}}
-  ;
-#pragma omp metadirective when(device

[clang] default clause replaced by otherwise clause for metadirective in OpenMP 5.2 (PR #128640)

2025-04-30 Thread Urvi Rav via cfe-commits


@@ -1,105 +1,33 @@
-// RUN: %clang_cc1 -verify -fopenmp -x c++ -triple x86_64-unknown-linux 
-emit-llvm %s -o - | FileCheck %s
-// expected-no-diagnostics
-
+// RUN: %clang_cc1 -verify -fopenmp -fopenmp-version=52 -DOMP52 -triple 
x86_64-unknown-unknown -emit-llvm %s -o - | FileCheck %s

ravurvi20 wrote:

In this case, I’ve only changed the printed spelling from default to otherwise 
for OpenMP metadirective. This is purely a printing change — no new AST nodes 
or data structures were introduced or modified. The existing AST structure 
remains unchanged. The `metadirective_ast_print.c` test case includes all 
relevant checks to verify the updated `-ast-print` output.

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


[clang] default clause replaced by otherwise clause for metadirective in OpenMP 5.2 (PR #128640)

2025-04-30 Thread Urvi Rav via cfe-commits


@@ -1660,6 +1660,10 @@ def err_omp_expected_colon : Error<"missing ':' in %0">;
 def err_omp_missing_comma : Error< "missing ',' after %0">;
 def err_omp_expected_context_selector
 : Error<"expected valid context selector in %0">;
+def err_omp_unknown_clause
+: Error<"expected an OpenMP clause">;
+def warn_omp_default_deprecated : Warning<"'default' clause for"

ravurvi20 wrote:

I agree that consolidating into a single message with arguments would be a 
cleaner approach. For now, I’d appreciate it if we could proceed with this 
version, and I’ll take up the refactoring in a follow-up patch.

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


[clang] default clause replaced by otherwise clause for metadirective in OpenMP 5.2 (PR #128640)

2025-04-29 Thread Urvi Rav via cfe-commits

https://github.com/ravurvi20 updated 
https://github.com/llvm/llvm-project/pull/128640

>From 6ebd5991788608fbd104ea9c23230912044462d3 Mon Sep 17 00:00:00 2001
From: Urvi Rav 
Date: Tue, 25 Feb 2025 00:49:07 -0600
Subject: [PATCH 1/6] default clause replaced by otherwise clause for
 metadirective

---
 .../clang/Basic/DiagnosticParseKinds.td   |  4 ++
 clang/lib/Parse/ParseOpenMP.cpp   | 20 ++
 clang/test/OpenMP/metadirective_messages.cpp  | 61 +--
 3 files changed, 68 insertions(+), 17 deletions(-)

diff --git a/clang/include/clang/Basic/DiagnosticParseKinds.td 
b/clang/include/clang/Basic/DiagnosticParseKinds.td
index c513dab810d1f..4b8449e9ee9b6 100644
--- a/clang/include/clang/Basic/DiagnosticParseKinds.td
+++ b/clang/include/clang/Basic/DiagnosticParseKinds.td
@@ -1657,6 +1657,10 @@ def err_omp_expected_colon : Error<"missing ':' in %0">;
 def err_omp_missing_comma : Error< "missing ',' after %0">;
 def err_omp_expected_context_selector
 : Error<"expected valid context selector in %0">;
+def err_omp_unknown_clause
+: Error<"unknown clause '%0' in %1">;
+def warn_omp_default_deprecated : Warning<"'default' clause for"
+  " 'metadirective' is deprecated; use 'otherwise' instead">, 
InGroup;
 def err_omp_requires_out_inout_depend_type : Error<
   "reserved locator 'omp_all_memory' requires 'out' or 'inout' "
   "dependency types">;
diff --git a/clang/lib/Parse/ParseOpenMP.cpp b/clang/lib/Parse/ParseOpenMP.cpp
index 42e6aac681c1c..3b86847e937a2 100644
--- a/clang/lib/Parse/ParseOpenMP.cpp
+++ b/clang/lib/Parse/ParseOpenMP.cpp
@@ -2759,6 +2759,19 @@ StmtResult 
Parser::ParseOpenMPDeclarativeOrExecutableDirective(
   OpenMPClauseKind CKind = Tok.isAnnotation()
? OMPC_unknown
: getOpenMPClauseKind(PP.getSpelling(Tok));
+  // Check if the clause is unrecognized.
+  if (getLangOpts().OpenMP < 52 &&
+  (CKind == OMPC_unknown || CKind == OMPC_otherwise)) {
+Diag(Tok, diag::err_omp_unknown_clause)
+<< PP.getSpelling(Tok) << "metadirective";
+  }
+  if (getLangOpts().OpenMP >= 52 && CKind == OMPC_unknown) {
+Diag(Tok, diag::err_omp_unknown_clause)
+<< PP.getSpelling(Tok) << "metadirective";
+  }
+  if (CKind == OMPC_default && getLangOpts().OpenMP >= 52) {
+Diag(Tok, diag::warn_omp_default_deprecated);
+  }
   SourceLocation Loc = ConsumeToken();
 
   // Parse '('.
@@ -2785,6 +2798,13 @@ StmtResult 
Parser::ParseOpenMPDeclarativeOrExecutableDirective(
   return Directive;
 }
   }
+  if (CKind == OMPC_otherwise) {
+// Check for 'otherwise' keyword.
+if (Tok.is(tok::identifier) &&
+Tok.getIdentifierInfo()->getName() == "otherwise") {
+  ConsumeToken(); // Consume 'otherwise'
+}
+  }
   // Skip Directive for now. We will parse directive in the second 
iteration
   int paren = 0;
   while (Tok.isNot(tok::r_paren) || paren != 0) {
diff --git a/clang/test/OpenMP/metadirective_messages.cpp 
b/clang/test/OpenMP/metadirective_messages.cpp
index 7fce9fa446058..40ea37845fdff 100644
--- a/clang/test/OpenMP/metadirective_messages.cpp
+++ b/clang/test/OpenMP/metadirective_messages.cpp
@@ -2,21 +2,48 @@
 
 // RUN: %clang_cc1 -triple=x86_64-pc-linux-gnu -verify -fopenmp-simd -x c++ 
-std=c++14 -fexceptions -fcxx-exceptions %s
 
+// RUN: %clang_cc1 -triple=x86_64-pc-linux-gnu -verify=expected,omp52 -fopenmp 
-fopenmp-version=52 -ferror-limit 100 -o - %s -Wuninitialized
+
 void foo() {
-#pragma omp metadirective // expected-error {{expected expression}}
-  ;
-#pragma omp metadirective when() // expected-error {{expected valid context 
selector in when clause}} expected-error {{expected expression}} 
expected-warning {{expected identifier or string literal describing a context 
set; set skipped}} expected-note {{context set options are: 'construct' 
'device' 'target_device' 'implementation' 'user'}} expected-note {{the ignored 
set spans until here}}
-  ;
-#pragma omp metadirective when(device{}) // expected-warning {{expected '=' 
after the context set name "device"; '=' assumed}} expected-warning {{expected 
identifier or string literal describing a context selector; selector skipped}} 
expected-note {{context selector options are: 'kind' 'arch' 'isa'}} 
expected-note {{the ignored selector spans until here}} expected-error 
{{expected valid context selector in when clause}} expected-error {{expected 
expression}}
-  ;
-#pragma omp metadirective when(device{arch(nvptx)}) // expected-error 
{{missing ':' in when clause}} expected-error {{expected expression}} 
expected-warning {{expected '=' after the context set name "device"; '=' 
assumed}}
-  ;
-#pragma omp metadirective when(device{arch(nvptx)}: ) default() // 
expected-warning {{expected '=' after the context set name "device"; '=' 
assumed}}
-  ;
-#pragma omp metadirective when(device

[clang] default clause replaced by otherwise clause for metadirective in OpenMP 5.2 (PR #128640)

2025-04-29 Thread Urvi Rav via cfe-commits

https://github.com/ravurvi20 updated 
https://github.com/llvm/llvm-project/pull/128640

>From 6ebd5991788608fbd104ea9c23230912044462d3 Mon Sep 17 00:00:00 2001
From: Urvi Rav 
Date: Tue, 25 Feb 2025 00:49:07 -0600
Subject: [PATCH 1/6] default clause replaced by otherwise clause for
 metadirective

---
 .../clang/Basic/DiagnosticParseKinds.td   |  4 ++
 clang/lib/Parse/ParseOpenMP.cpp   | 20 ++
 clang/test/OpenMP/metadirective_messages.cpp  | 61 +--
 3 files changed, 68 insertions(+), 17 deletions(-)

diff --git a/clang/include/clang/Basic/DiagnosticParseKinds.td 
b/clang/include/clang/Basic/DiagnosticParseKinds.td
index c513dab810d1f..4b8449e9ee9b6 100644
--- a/clang/include/clang/Basic/DiagnosticParseKinds.td
+++ b/clang/include/clang/Basic/DiagnosticParseKinds.td
@@ -1657,6 +1657,10 @@ def err_omp_expected_colon : Error<"missing ':' in %0">;
 def err_omp_missing_comma : Error< "missing ',' after %0">;
 def err_omp_expected_context_selector
 : Error<"expected valid context selector in %0">;
+def err_omp_unknown_clause
+: Error<"unknown clause '%0' in %1">;
+def warn_omp_default_deprecated : Warning<"'default' clause for"
+  " 'metadirective' is deprecated; use 'otherwise' instead">, 
InGroup;
 def err_omp_requires_out_inout_depend_type : Error<
   "reserved locator 'omp_all_memory' requires 'out' or 'inout' "
   "dependency types">;
diff --git a/clang/lib/Parse/ParseOpenMP.cpp b/clang/lib/Parse/ParseOpenMP.cpp
index 42e6aac681c1c..3b86847e937a2 100644
--- a/clang/lib/Parse/ParseOpenMP.cpp
+++ b/clang/lib/Parse/ParseOpenMP.cpp
@@ -2759,6 +2759,19 @@ StmtResult 
Parser::ParseOpenMPDeclarativeOrExecutableDirective(
   OpenMPClauseKind CKind = Tok.isAnnotation()
? OMPC_unknown
: getOpenMPClauseKind(PP.getSpelling(Tok));
+  // Check if the clause is unrecognized.
+  if (getLangOpts().OpenMP < 52 &&
+  (CKind == OMPC_unknown || CKind == OMPC_otherwise)) {
+Diag(Tok, diag::err_omp_unknown_clause)
+<< PP.getSpelling(Tok) << "metadirective";
+  }
+  if (getLangOpts().OpenMP >= 52 && CKind == OMPC_unknown) {
+Diag(Tok, diag::err_omp_unknown_clause)
+<< PP.getSpelling(Tok) << "metadirective";
+  }
+  if (CKind == OMPC_default && getLangOpts().OpenMP >= 52) {
+Diag(Tok, diag::warn_omp_default_deprecated);
+  }
   SourceLocation Loc = ConsumeToken();
 
   // Parse '('.
@@ -2785,6 +2798,13 @@ StmtResult 
Parser::ParseOpenMPDeclarativeOrExecutableDirective(
   return Directive;
 }
   }
+  if (CKind == OMPC_otherwise) {
+// Check for 'otherwise' keyword.
+if (Tok.is(tok::identifier) &&
+Tok.getIdentifierInfo()->getName() == "otherwise") {
+  ConsumeToken(); // Consume 'otherwise'
+}
+  }
   // Skip Directive for now. We will parse directive in the second 
iteration
   int paren = 0;
   while (Tok.isNot(tok::r_paren) || paren != 0) {
diff --git a/clang/test/OpenMP/metadirective_messages.cpp 
b/clang/test/OpenMP/metadirective_messages.cpp
index 7fce9fa446058..40ea37845fdff 100644
--- a/clang/test/OpenMP/metadirective_messages.cpp
+++ b/clang/test/OpenMP/metadirective_messages.cpp
@@ -2,21 +2,48 @@
 
 // RUN: %clang_cc1 -triple=x86_64-pc-linux-gnu -verify -fopenmp-simd -x c++ 
-std=c++14 -fexceptions -fcxx-exceptions %s
 
+// RUN: %clang_cc1 -triple=x86_64-pc-linux-gnu -verify=expected,omp52 -fopenmp 
-fopenmp-version=52 -ferror-limit 100 -o - %s -Wuninitialized
+
 void foo() {
-#pragma omp metadirective // expected-error {{expected expression}}
-  ;
-#pragma omp metadirective when() // expected-error {{expected valid context 
selector in when clause}} expected-error {{expected expression}} 
expected-warning {{expected identifier or string literal describing a context 
set; set skipped}} expected-note {{context set options are: 'construct' 
'device' 'target_device' 'implementation' 'user'}} expected-note {{the ignored 
set spans until here}}
-  ;
-#pragma omp metadirective when(device{}) // expected-warning {{expected '=' 
after the context set name "device"; '=' assumed}} expected-warning {{expected 
identifier or string literal describing a context selector; selector skipped}} 
expected-note {{context selector options are: 'kind' 'arch' 'isa'}} 
expected-note {{the ignored selector spans until here}} expected-error 
{{expected valid context selector in when clause}} expected-error {{expected 
expression}}
-  ;
-#pragma omp metadirective when(device{arch(nvptx)}) // expected-error 
{{missing ':' in when clause}} expected-error {{expected expression}} 
expected-warning {{expected '=' after the context set name "device"; '=' 
assumed}}
-  ;
-#pragma omp metadirective when(device{arch(nvptx)}: ) default() // 
expected-warning {{expected '=' after the context set name "device"; '=' 
assumed}}
-  ;
-#pragma omp metadirective when(device

[clang] default clause replaced by otherwise clause for metadirective in OpenMP 5.2 (PR #128640)

2025-04-30 Thread Urvi Rav via cfe-commits

https://github.com/ravurvi20 updated 
https://github.com/llvm/llvm-project/pull/128640

>From 6ebd5991788608fbd104ea9c23230912044462d3 Mon Sep 17 00:00:00 2001
From: Urvi Rav 
Date: Tue, 25 Feb 2025 00:49:07 -0600
Subject: [PATCH 1/7] default clause replaced by otherwise clause for
 metadirective

---
 .../clang/Basic/DiagnosticParseKinds.td   |  4 ++
 clang/lib/Parse/ParseOpenMP.cpp   | 20 ++
 clang/test/OpenMP/metadirective_messages.cpp  | 61 +--
 3 files changed, 68 insertions(+), 17 deletions(-)

diff --git a/clang/include/clang/Basic/DiagnosticParseKinds.td 
b/clang/include/clang/Basic/DiagnosticParseKinds.td
index c513dab810d1f..4b8449e9ee9b6 100644
--- a/clang/include/clang/Basic/DiagnosticParseKinds.td
+++ b/clang/include/clang/Basic/DiagnosticParseKinds.td
@@ -1657,6 +1657,10 @@ def err_omp_expected_colon : Error<"missing ':' in %0">;
 def err_omp_missing_comma : Error< "missing ',' after %0">;
 def err_omp_expected_context_selector
 : Error<"expected valid context selector in %0">;
+def err_omp_unknown_clause
+: Error<"unknown clause '%0' in %1">;
+def warn_omp_default_deprecated : Warning<"'default' clause for"
+  " 'metadirective' is deprecated; use 'otherwise' instead">, 
InGroup;
 def err_omp_requires_out_inout_depend_type : Error<
   "reserved locator 'omp_all_memory' requires 'out' or 'inout' "
   "dependency types">;
diff --git a/clang/lib/Parse/ParseOpenMP.cpp b/clang/lib/Parse/ParseOpenMP.cpp
index 42e6aac681c1c..3b86847e937a2 100644
--- a/clang/lib/Parse/ParseOpenMP.cpp
+++ b/clang/lib/Parse/ParseOpenMP.cpp
@@ -2759,6 +2759,19 @@ StmtResult 
Parser::ParseOpenMPDeclarativeOrExecutableDirective(
   OpenMPClauseKind CKind = Tok.isAnnotation()
? OMPC_unknown
: getOpenMPClauseKind(PP.getSpelling(Tok));
+  // Check if the clause is unrecognized.
+  if (getLangOpts().OpenMP < 52 &&
+  (CKind == OMPC_unknown || CKind == OMPC_otherwise)) {
+Diag(Tok, diag::err_omp_unknown_clause)
+<< PP.getSpelling(Tok) << "metadirective";
+  }
+  if (getLangOpts().OpenMP >= 52 && CKind == OMPC_unknown) {
+Diag(Tok, diag::err_omp_unknown_clause)
+<< PP.getSpelling(Tok) << "metadirective";
+  }
+  if (CKind == OMPC_default && getLangOpts().OpenMP >= 52) {
+Diag(Tok, diag::warn_omp_default_deprecated);
+  }
   SourceLocation Loc = ConsumeToken();
 
   // Parse '('.
@@ -2785,6 +2798,13 @@ StmtResult 
Parser::ParseOpenMPDeclarativeOrExecutableDirective(
   return Directive;
 }
   }
+  if (CKind == OMPC_otherwise) {
+// Check for 'otherwise' keyword.
+if (Tok.is(tok::identifier) &&
+Tok.getIdentifierInfo()->getName() == "otherwise") {
+  ConsumeToken(); // Consume 'otherwise'
+}
+  }
   // Skip Directive for now. We will parse directive in the second 
iteration
   int paren = 0;
   while (Tok.isNot(tok::r_paren) || paren != 0) {
diff --git a/clang/test/OpenMP/metadirective_messages.cpp 
b/clang/test/OpenMP/metadirective_messages.cpp
index 7fce9fa446058..40ea37845fdff 100644
--- a/clang/test/OpenMP/metadirective_messages.cpp
+++ b/clang/test/OpenMP/metadirective_messages.cpp
@@ -2,21 +2,48 @@
 
 // RUN: %clang_cc1 -triple=x86_64-pc-linux-gnu -verify -fopenmp-simd -x c++ 
-std=c++14 -fexceptions -fcxx-exceptions %s
 
+// RUN: %clang_cc1 -triple=x86_64-pc-linux-gnu -verify=expected,omp52 -fopenmp 
-fopenmp-version=52 -ferror-limit 100 -o - %s -Wuninitialized
+
 void foo() {
-#pragma omp metadirective // expected-error {{expected expression}}
-  ;
-#pragma omp metadirective when() // expected-error {{expected valid context 
selector in when clause}} expected-error {{expected expression}} 
expected-warning {{expected identifier or string literal describing a context 
set; set skipped}} expected-note {{context set options are: 'construct' 
'device' 'target_device' 'implementation' 'user'}} expected-note {{the ignored 
set spans until here}}
-  ;
-#pragma omp metadirective when(device{}) // expected-warning {{expected '=' 
after the context set name "device"; '=' assumed}} expected-warning {{expected 
identifier or string literal describing a context selector; selector skipped}} 
expected-note {{context selector options are: 'kind' 'arch' 'isa'}} 
expected-note {{the ignored selector spans until here}} expected-error 
{{expected valid context selector in when clause}} expected-error {{expected 
expression}}
-  ;
-#pragma omp metadirective when(device{arch(nvptx)}) // expected-error 
{{missing ':' in when clause}} expected-error {{expected expression}} 
expected-warning {{expected '=' after the context set name "device"; '=' 
assumed}}
-  ;
-#pragma omp metadirective when(device{arch(nvptx)}: ) default() // 
expected-warning {{expected '=' after the context set name "device"; '=' 
assumed}}
-  ;
-#pragma omp metadirective when(device

[clang] default clause replaced by otherwise clause for metadirective in OpenMP 5.2 (PR #128640)

2025-04-30 Thread Urvi Rav via cfe-commits

https://github.com/ravurvi20 updated 
https://github.com/llvm/llvm-project/pull/128640

>From 6ebd5991788608fbd104ea9c23230912044462d3 Mon Sep 17 00:00:00 2001
From: Urvi Rav 
Date: Tue, 25 Feb 2025 00:49:07 -0600
Subject: [PATCH 1/9] default clause replaced by otherwise clause for
 metadirective

---
 .../clang/Basic/DiagnosticParseKinds.td   |  4 ++
 clang/lib/Parse/ParseOpenMP.cpp   | 20 ++
 clang/test/OpenMP/metadirective_messages.cpp  | 61 +--
 3 files changed, 68 insertions(+), 17 deletions(-)

diff --git a/clang/include/clang/Basic/DiagnosticParseKinds.td 
b/clang/include/clang/Basic/DiagnosticParseKinds.td
index c513dab810d1f..4b8449e9ee9b6 100644
--- a/clang/include/clang/Basic/DiagnosticParseKinds.td
+++ b/clang/include/clang/Basic/DiagnosticParseKinds.td
@@ -1657,6 +1657,10 @@ def err_omp_expected_colon : Error<"missing ':' in %0">;
 def err_omp_missing_comma : Error< "missing ',' after %0">;
 def err_omp_expected_context_selector
 : Error<"expected valid context selector in %0">;
+def err_omp_unknown_clause
+: Error<"unknown clause '%0' in %1">;
+def warn_omp_default_deprecated : Warning<"'default' clause for"
+  " 'metadirective' is deprecated; use 'otherwise' instead">, 
InGroup;
 def err_omp_requires_out_inout_depend_type : Error<
   "reserved locator 'omp_all_memory' requires 'out' or 'inout' "
   "dependency types">;
diff --git a/clang/lib/Parse/ParseOpenMP.cpp b/clang/lib/Parse/ParseOpenMP.cpp
index 42e6aac681c1c..3b86847e937a2 100644
--- a/clang/lib/Parse/ParseOpenMP.cpp
+++ b/clang/lib/Parse/ParseOpenMP.cpp
@@ -2759,6 +2759,19 @@ StmtResult 
Parser::ParseOpenMPDeclarativeOrExecutableDirective(
   OpenMPClauseKind CKind = Tok.isAnnotation()
? OMPC_unknown
: getOpenMPClauseKind(PP.getSpelling(Tok));
+  // Check if the clause is unrecognized.
+  if (getLangOpts().OpenMP < 52 &&
+  (CKind == OMPC_unknown || CKind == OMPC_otherwise)) {
+Diag(Tok, diag::err_omp_unknown_clause)
+<< PP.getSpelling(Tok) << "metadirective";
+  }
+  if (getLangOpts().OpenMP >= 52 && CKind == OMPC_unknown) {
+Diag(Tok, diag::err_omp_unknown_clause)
+<< PP.getSpelling(Tok) << "metadirective";
+  }
+  if (CKind == OMPC_default && getLangOpts().OpenMP >= 52) {
+Diag(Tok, diag::warn_omp_default_deprecated);
+  }
   SourceLocation Loc = ConsumeToken();
 
   // Parse '('.
@@ -2785,6 +2798,13 @@ StmtResult 
Parser::ParseOpenMPDeclarativeOrExecutableDirective(
   return Directive;
 }
   }
+  if (CKind == OMPC_otherwise) {
+// Check for 'otherwise' keyword.
+if (Tok.is(tok::identifier) &&
+Tok.getIdentifierInfo()->getName() == "otherwise") {
+  ConsumeToken(); // Consume 'otherwise'
+}
+  }
   // Skip Directive for now. We will parse directive in the second 
iteration
   int paren = 0;
   while (Tok.isNot(tok::r_paren) || paren != 0) {
diff --git a/clang/test/OpenMP/metadirective_messages.cpp 
b/clang/test/OpenMP/metadirective_messages.cpp
index 7fce9fa446058..40ea37845fdff 100644
--- a/clang/test/OpenMP/metadirective_messages.cpp
+++ b/clang/test/OpenMP/metadirective_messages.cpp
@@ -2,21 +2,48 @@
 
 // RUN: %clang_cc1 -triple=x86_64-pc-linux-gnu -verify -fopenmp-simd -x c++ 
-std=c++14 -fexceptions -fcxx-exceptions %s
 
+// RUN: %clang_cc1 -triple=x86_64-pc-linux-gnu -verify=expected,omp52 -fopenmp 
-fopenmp-version=52 -ferror-limit 100 -o - %s -Wuninitialized
+
 void foo() {
-#pragma omp metadirective // expected-error {{expected expression}}
-  ;
-#pragma omp metadirective when() // expected-error {{expected valid context 
selector in when clause}} expected-error {{expected expression}} 
expected-warning {{expected identifier or string literal describing a context 
set; set skipped}} expected-note {{context set options are: 'construct' 
'device' 'target_device' 'implementation' 'user'}} expected-note {{the ignored 
set spans until here}}
-  ;
-#pragma omp metadirective when(device{}) // expected-warning {{expected '=' 
after the context set name "device"; '=' assumed}} expected-warning {{expected 
identifier or string literal describing a context selector; selector skipped}} 
expected-note {{context selector options are: 'kind' 'arch' 'isa'}} 
expected-note {{the ignored selector spans until here}} expected-error 
{{expected valid context selector in when clause}} expected-error {{expected 
expression}}
-  ;
-#pragma omp metadirective when(device{arch(nvptx)}) // expected-error 
{{missing ':' in when clause}} expected-error {{expected expression}} 
expected-warning {{expected '=' after the context set name "device"; '=' 
assumed}}
-  ;
-#pragma omp metadirective when(device{arch(nvptx)}: ) default() // 
expected-warning {{expected '=' after the context set name "device"; '=' 
assumed}}
-  ;
-#pragma omp metadirective when(device

[clang] default clause replaced by otherwise clause for metadirective in OpenMP 5.2 (PR #128640)

2025-04-13 Thread Urvi Rav via cfe-commits


@@ -2759,6 +2759,19 @@ StmtResult 
Parser::ParseOpenMPDeclarativeOrExecutableDirective(
   OpenMPClauseKind CKind = Tok.isAnnotation()
? OMPC_unknown
: getOpenMPClauseKind(PP.getSpelling(Tok));
+  // Check if the clause is unrecognized.
+  if (getLangOpts().OpenMP < 52 &&
+  (CKind == OMPC_unknown || CKind == OMPC_otherwise)) {
+Diag(Tok, diag::err_omp_unknown_clause)
+<< PP.getSpelling(Tok) << "metadirective";
+  }
+  if (getLangOpts().OpenMP >= 52 && CKind == OMPC_unknown) {
+Diag(Tok, diag::err_omp_unknown_clause)
+<< PP.getSpelling(Tok) << "metadirective";
+  }

ravurvi20 wrote:

ping @kparzysz 

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


[clang] default clause replaced by otherwise clause for metadirective in OpenMP 5.2 (PR #128640)

2025-04-24 Thread Urvi Rav via cfe-commits

ravurvi20 wrote:

@alexey-bataev I have pushed the requested changes. Could you please approve 
this PR.

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


[clang] default clause replaced by otherwise clause for metadirective in OpenMP 5.2 (PR #128640)

2025-04-25 Thread Urvi Rav via cfe-commits


@@ -1660,6 +1660,10 @@ def err_omp_expected_colon : Error<"missing ':' in %0">;
 def err_omp_missing_comma : Error< "missing ',' after %0">;
 def err_omp_expected_context_selector
 : Error<"expected valid context selector in %0">;
+def err_omp_unknown_clause

ravurvi20 wrote:

Thanks for the suggestion. I've already used `err_omp_unexpected_clause` for 
the `OMPC_otherwise` case in OpenMP versions prior to 5.2, as suggested 
earlier. For `OMPC_unknown`, I'm using `err_omp_unknown_clause`, which aligns 
with the guidance to treat `OMPC_unknown` and `OMPC_otherwise` separately.

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


[clang] default clause replaced by otherwise clause for metadirective in OpenMP 5.2 (PR #128640)

2025-04-25 Thread Urvi Rav via cfe-commits


@@ -1660,6 +1660,10 @@ def err_omp_expected_colon : Error<"missing ':' in %0">;
 def err_omp_missing_comma : Error< "missing ',' after %0">;
 def err_omp_expected_context_selector
 : Error<"expected valid context selector in %0">;
+def err_omp_unknown_clause
+: Error<"expected an OpenMP clause">;
+def warn_omp_default_deprecated : Warning<"'default' clause for"

ravurvi20 wrote:

Since default is being deprecated not disallowed in metadirective I had put a 
warning instead on using an error (err_omp_deprecate_old_syntax).

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


[clang] default clause replaced by otherwise clause for metadirective in OpenMP 5.2 (PR #128640)

2025-04-25 Thread Urvi Rav via cfe-commits


@@ -78,10 +78,7 @@ void foo(void) {
   for (int i = 0; i < 16; i++)
 ;
 
-#pragma omp metadirective when(user = {condition(0)}   \
-  : parallel for) otherwise()
-  for (int i=0; i<10; i++)
-;
+

ravurvi20 wrote:

Since for versions prior to 5.2 default is valid so moved it in a way that if 
the version is 5.2 or greater otherwise condition should run else the default 
condition.

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


[clang] default clause replaced by otherwise clause for metadirective in OpenMP 5.2 (PR #128640)

2025-04-25 Thread Urvi Rav via cfe-commits

https://github.com/ravurvi20 updated 
https://github.com/llvm/llvm-project/pull/128640

>From 6ebd5991788608fbd104ea9c23230912044462d3 Mon Sep 17 00:00:00 2001
From: Urvi Rav 
Date: Tue, 25 Feb 2025 00:49:07 -0600
Subject: [PATCH 1/4] default clause replaced by otherwise clause for
 metadirective

---
 .../clang/Basic/DiagnosticParseKinds.td   |  4 ++
 clang/lib/Parse/ParseOpenMP.cpp   | 20 ++
 clang/test/OpenMP/metadirective_messages.cpp  | 61 +--
 3 files changed, 68 insertions(+), 17 deletions(-)

diff --git a/clang/include/clang/Basic/DiagnosticParseKinds.td 
b/clang/include/clang/Basic/DiagnosticParseKinds.td
index c513dab810d1f..4b8449e9ee9b6 100644
--- a/clang/include/clang/Basic/DiagnosticParseKinds.td
+++ b/clang/include/clang/Basic/DiagnosticParseKinds.td
@@ -1657,6 +1657,10 @@ def err_omp_expected_colon : Error<"missing ':' in %0">;
 def err_omp_missing_comma : Error< "missing ',' after %0">;
 def err_omp_expected_context_selector
 : Error<"expected valid context selector in %0">;
+def err_omp_unknown_clause
+: Error<"unknown clause '%0' in %1">;
+def warn_omp_default_deprecated : Warning<"'default' clause for"
+  " 'metadirective' is deprecated; use 'otherwise' instead">, 
InGroup;
 def err_omp_requires_out_inout_depend_type : Error<
   "reserved locator 'omp_all_memory' requires 'out' or 'inout' "
   "dependency types">;
diff --git a/clang/lib/Parse/ParseOpenMP.cpp b/clang/lib/Parse/ParseOpenMP.cpp
index 42e6aac681c1c..3b86847e937a2 100644
--- a/clang/lib/Parse/ParseOpenMP.cpp
+++ b/clang/lib/Parse/ParseOpenMP.cpp
@@ -2759,6 +2759,19 @@ StmtResult 
Parser::ParseOpenMPDeclarativeOrExecutableDirective(
   OpenMPClauseKind CKind = Tok.isAnnotation()
? OMPC_unknown
: getOpenMPClauseKind(PP.getSpelling(Tok));
+  // Check if the clause is unrecognized.
+  if (getLangOpts().OpenMP < 52 &&
+  (CKind == OMPC_unknown || CKind == OMPC_otherwise)) {
+Diag(Tok, diag::err_omp_unknown_clause)
+<< PP.getSpelling(Tok) << "metadirective";
+  }
+  if (getLangOpts().OpenMP >= 52 && CKind == OMPC_unknown) {
+Diag(Tok, diag::err_omp_unknown_clause)
+<< PP.getSpelling(Tok) << "metadirective";
+  }
+  if (CKind == OMPC_default && getLangOpts().OpenMP >= 52) {
+Diag(Tok, diag::warn_omp_default_deprecated);
+  }
   SourceLocation Loc = ConsumeToken();
 
   // Parse '('.
@@ -2785,6 +2798,13 @@ StmtResult 
Parser::ParseOpenMPDeclarativeOrExecutableDirective(
   return Directive;
 }
   }
+  if (CKind == OMPC_otherwise) {
+// Check for 'otherwise' keyword.
+if (Tok.is(tok::identifier) &&
+Tok.getIdentifierInfo()->getName() == "otherwise") {
+  ConsumeToken(); // Consume 'otherwise'
+}
+  }
   // Skip Directive for now. We will parse directive in the second 
iteration
   int paren = 0;
   while (Tok.isNot(tok::r_paren) || paren != 0) {
diff --git a/clang/test/OpenMP/metadirective_messages.cpp 
b/clang/test/OpenMP/metadirective_messages.cpp
index 7fce9fa446058..40ea37845fdff 100644
--- a/clang/test/OpenMP/metadirective_messages.cpp
+++ b/clang/test/OpenMP/metadirective_messages.cpp
@@ -2,21 +2,48 @@
 
 // RUN: %clang_cc1 -triple=x86_64-pc-linux-gnu -verify -fopenmp-simd -x c++ 
-std=c++14 -fexceptions -fcxx-exceptions %s
 
+// RUN: %clang_cc1 -triple=x86_64-pc-linux-gnu -verify=expected,omp52 -fopenmp 
-fopenmp-version=52 -ferror-limit 100 -o - %s -Wuninitialized
+
 void foo() {
-#pragma omp metadirective // expected-error {{expected expression}}
-  ;
-#pragma omp metadirective when() // expected-error {{expected valid context 
selector in when clause}} expected-error {{expected expression}} 
expected-warning {{expected identifier or string literal describing a context 
set; set skipped}} expected-note {{context set options are: 'construct' 
'device' 'target_device' 'implementation' 'user'}} expected-note {{the ignored 
set spans until here}}
-  ;
-#pragma omp metadirective when(device{}) // expected-warning {{expected '=' 
after the context set name "device"; '=' assumed}} expected-warning {{expected 
identifier or string literal describing a context selector; selector skipped}} 
expected-note {{context selector options are: 'kind' 'arch' 'isa'}} 
expected-note {{the ignored selector spans until here}} expected-error 
{{expected valid context selector in when clause}} expected-error {{expected 
expression}}
-  ;
-#pragma omp metadirective when(device{arch(nvptx)}) // expected-error 
{{missing ':' in when clause}} expected-error {{expected expression}} 
expected-warning {{expected '=' after the context set name "device"; '=' 
assumed}}
-  ;
-#pragma omp metadirective when(device{arch(nvptx)}: ) default() // 
expected-warning {{expected '=' after the context set name "device"; '=' 
assumed}}
-  ;
-#pragma omp metadirective when(device

[clang] default clause replaced by otherwise clause for metadirective in OpenMP 5.2 (PR #128640)

2025-04-25 Thread Urvi Rav via cfe-commits

https://github.com/ravurvi20 updated 
https://github.com/llvm/llvm-project/pull/128640

>From 6ebd5991788608fbd104ea9c23230912044462d3 Mon Sep 17 00:00:00 2001
From: Urvi Rav 
Date: Tue, 25 Feb 2025 00:49:07 -0600
Subject: [PATCH 1/4] default clause replaced by otherwise clause for
 metadirective

---
 .../clang/Basic/DiagnosticParseKinds.td   |  4 ++
 clang/lib/Parse/ParseOpenMP.cpp   | 20 ++
 clang/test/OpenMP/metadirective_messages.cpp  | 61 +--
 3 files changed, 68 insertions(+), 17 deletions(-)

diff --git a/clang/include/clang/Basic/DiagnosticParseKinds.td 
b/clang/include/clang/Basic/DiagnosticParseKinds.td
index c513dab810d1f..4b8449e9ee9b6 100644
--- a/clang/include/clang/Basic/DiagnosticParseKinds.td
+++ b/clang/include/clang/Basic/DiagnosticParseKinds.td
@@ -1657,6 +1657,10 @@ def err_omp_expected_colon : Error<"missing ':' in %0">;
 def err_omp_missing_comma : Error< "missing ',' after %0">;
 def err_omp_expected_context_selector
 : Error<"expected valid context selector in %0">;
+def err_omp_unknown_clause
+: Error<"unknown clause '%0' in %1">;
+def warn_omp_default_deprecated : Warning<"'default' clause for"
+  " 'metadirective' is deprecated; use 'otherwise' instead">, 
InGroup;
 def err_omp_requires_out_inout_depend_type : Error<
   "reserved locator 'omp_all_memory' requires 'out' or 'inout' "
   "dependency types">;
diff --git a/clang/lib/Parse/ParseOpenMP.cpp b/clang/lib/Parse/ParseOpenMP.cpp
index 42e6aac681c1c..3b86847e937a2 100644
--- a/clang/lib/Parse/ParseOpenMP.cpp
+++ b/clang/lib/Parse/ParseOpenMP.cpp
@@ -2759,6 +2759,19 @@ StmtResult 
Parser::ParseOpenMPDeclarativeOrExecutableDirective(
   OpenMPClauseKind CKind = Tok.isAnnotation()
? OMPC_unknown
: getOpenMPClauseKind(PP.getSpelling(Tok));
+  // Check if the clause is unrecognized.
+  if (getLangOpts().OpenMP < 52 &&
+  (CKind == OMPC_unknown || CKind == OMPC_otherwise)) {
+Diag(Tok, diag::err_omp_unknown_clause)
+<< PP.getSpelling(Tok) << "metadirective";
+  }
+  if (getLangOpts().OpenMP >= 52 && CKind == OMPC_unknown) {
+Diag(Tok, diag::err_omp_unknown_clause)
+<< PP.getSpelling(Tok) << "metadirective";
+  }
+  if (CKind == OMPC_default && getLangOpts().OpenMP >= 52) {
+Diag(Tok, diag::warn_omp_default_deprecated);
+  }
   SourceLocation Loc = ConsumeToken();
 
   // Parse '('.
@@ -2785,6 +2798,13 @@ StmtResult 
Parser::ParseOpenMPDeclarativeOrExecutableDirective(
   return Directive;
 }
   }
+  if (CKind == OMPC_otherwise) {
+// Check for 'otherwise' keyword.
+if (Tok.is(tok::identifier) &&
+Tok.getIdentifierInfo()->getName() == "otherwise") {
+  ConsumeToken(); // Consume 'otherwise'
+}
+  }
   // Skip Directive for now. We will parse directive in the second 
iteration
   int paren = 0;
   while (Tok.isNot(tok::r_paren) || paren != 0) {
diff --git a/clang/test/OpenMP/metadirective_messages.cpp 
b/clang/test/OpenMP/metadirective_messages.cpp
index 7fce9fa446058..40ea37845fdff 100644
--- a/clang/test/OpenMP/metadirective_messages.cpp
+++ b/clang/test/OpenMP/metadirective_messages.cpp
@@ -2,21 +2,48 @@
 
 // RUN: %clang_cc1 -triple=x86_64-pc-linux-gnu -verify -fopenmp-simd -x c++ 
-std=c++14 -fexceptions -fcxx-exceptions %s
 
+// RUN: %clang_cc1 -triple=x86_64-pc-linux-gnu -verify=expected,omp52 -fopenmp 
-fopenmp-version=52 -ferror-limit 100 -o - %s -Wuninitialized
+
 void foo() {
-#pragma omp metadirective // expected-error {{expected expression}}
-  ;
-#pragma omp metadirective when() // expected-error {{expected valid context 
selector in when clause}} expected-error {{expected expression}} 
expected-warning {{expected identifier or string literal describing a context 
set; set skipped}} expected-note {{context set options are: 'construct' 
'device' 'target_device' 'implementation' 'user'}} expected-note {{the ignored 
set spans until here}}
-  ;
-#pragma omp metadirective when(device{}) // expected-warning {{expected '=' 
after the context set name "device"; '=' assumed}} expected-warning {{expected 
identifier or string literal describing a context selector; selector skipped}} 
expected-note {{context selector options are: 'kind' 'arch' 'isa'}} 
expected-note {{the ignored selector spans until here}} expected-error 
{{expected valid context selector in when clause}} expected-error {{expected 
expression}}
-  ;
-#pragma omp metadirective when(device{arch(nvptx)}) // expected-error 
{{missing ':' in when clause}} expected-error {{expected expression}} 
expected-warning {{expected '=' after the context set name "device"; '=' 
assumed}}
-  ;
-#pragma omp metadirective when(device{arch(nvptx)}: ) default() // 
expected-warning {{expected '=' after the context set name "device"; '=' 
assumed}}
-  ;
-#pragma omp metadirective when(device

[clang] default clause replaced by otherwise clause for metadirective in OpenMP 5.2 (PR #128640)

2025-04-29 Thread Urvi Rav via cfe-commits


@@ -1660,6 +1660,10 @@ def err_omp_expected_colon : Error<"missing ':' in %0">;
 def err_omp_missing_comma : Error< "missing ',' after %0">;
 def err_omp_expected_context_selector
 : Error<"expected valid context selector in %0">;
+def err_omp_unknown_clause
+: Error<"expected an OpenMP clause">;
+def warn_omp_default_deprecated : Warning<"'default' clause for"

ravurvi20 wrote:

Most of the deprecated clauses have their own warning messages without 
operands. 


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


[clang] default clause replaced by otherwise clause for metadirective in OpenMP 5.2 (PR #128640)

2025-04-26 Thread Urvi Rav via cfe-commits

https://github.com/ravurvi20 updated 
https://github.com/llvm/llvm-project/pull/128640

>From 6ebd5991788608fbd104ea9c23230912044462d3 Mon Sep 17 00:00:00 2001
From: Urvi Rav 
Date: Tue, 25 Feb 2025 00:49:07 -0600
Subject: [PATCH 1/5] default clause replaced by otherwise clause for
 metadirective

---
 .../clang/Basic/DiagnosticParseKinds.td   |  4 ++
 clang/lib/Parse/ParseOpenMP.cpp   | 20 ++
 clang/test/OpenMP/metadirective_messages.cpp  | 61 +--
 3 files changed, 68 insertions(+), 17 deletions(-)

diff --git a/clang/include/clang/Basic/DiagnosticParseKinds.td 
b/clang/include/clang/Basic/DiagnosticParseKinds.td
index c513dab810d1f..4b8449e9ee9b6 100644
--- a/clang/include/clang/Basic/DiagnosticParseKinds.td
+++ b/clang/include/clang/Basic/DiagnosticParseKinds.td
@@ -1657,6 +1657,10 @@ def err_omp_expected_colon : Error<"missing ':' in %0">;
 def err_omp_missing_comma : Error< "missing ',' after %0">;
 def err_omp_expected_context_selector
 : Error<"expected valid context selector in %0">;
+def err_omp_unknown_clause
+: Error<"unknown clause '%0' in %1">;
+def warn_omp_default_deprecated : Warning<"'default' clause for"
+  " 'metadirective' is deprecated; use 'otherwise' instead">, 
InGroup;
 def err_omp_requires_out_inout_depend_type : Error<
   "reserved locator 'omp_all_memory' requires 'out' or 'inout' "
   "dependency types">;
diff --git a/clang/lib/Parse/ParseOpenMP.cpp b/clang/lib/Parse/ParseOpenMP.cpp
index 42e6aac681c1c..3b86847e937a2 100644
--- a/clang/lib/Parse/ParseOpenMP.cpp
+++ b/clang/lib/Parse/ParseOpenMP.cpp
@@ -2759,6 +2759,19 @@ StmtResult 
Parser::ParseOpenMPDeclarativeOrExecutableDirective(
   OpenMPClauseKind CKind = Tok.isAnnotation()
? OMPC_unknown
: getOpenMPClauseKind(PP.getSpelling(Tok));
+  // Check if the clause is unrecognized.
+  if (getLangOpts().OpenMP < 52 &&
+  (CKind == OMPC_unknown || CKind == OMPC_otherwise)) {
+Diag(Tok, diag::err_omp_unknown_clause)
+<< PP.getSpelling(Tok) << "metadirective";
+  }
+  if (getLangOpts().OpenMP >= 52 && CKind == OMPC_unknown) {
+Diag(Tok, diag::err_omp_unknown_clause)
+<< PP.getSpelling(Tok) << "metadirective";
+  }
+  if (CKind == OMPC_default && getLangOpts().OpenMP >= 52) {
+Diag(Tok, diag::warn_omp_default_deprecated);
+  }
   SourceLocation Loc = ConsumeToken();
 
   // Parse '('.
@@ -2785,6 +2798,13 @@ StmtResult 
Parser::ParseOpenMPDeclarativeOrExecutableDirective(
   return Directive;
 }
   }
+  if (CKind == OMPC_otherwise) {
+// Check for 'otherwise' keyword.
+if (Tok.is(tok::identifier) &&
+Tok.getIdentifierInfo()->getName() == "otherwise") {
+  ConsumeToken(); // Consume 'otherwise'
+}
+  }
   // Skip Directive for now. We will parse directive in the second 
iteration
   int paren = 0;
   while (Tok.isNot(tok::r_paren) || paren != 0) {
diff --git a/clang/test/OpenMP/metadirective_messages.cpp 
b/clang/test/OpenMP/metadirective_messages.cpp
index 7fce9fa446058..40ea37845fdff 100644
--- a/clang/test/OpenMP/metadirective_messages.cpp
+++ b/clang/test/OpenMP/metadirective_messages.cpp
@@ -2,21 +2,48 @@
 
 // RUN: %clang_cc1 -triple=x86_64-pc-linux-gnu -verify -fopenmp-simd -x c++ 
-std=c++14 -fexceptions -fcxx-exceptions %s
 
+// RUN: %clang_cc1 -triple=x86_64-pc-linux-gnu -verify=expected,omp52 -fopenmp 
-fopenmp-version=52 -ferror-limit 100 -o - %s -Wuninitialized
+
 void foo() {
-#pragma omp metadirective // expected-error {{expected expression}}
-  ;
-#pragma omp metadirective when() // expected-error {{expected valid context 
selector in when clause}} expected-error {{expected expression}} 
expected-warning {{expected identifier or string literal describing a context 
set; set skipped}} expected-note {{context set options are: 'construct' 
'device' 'target_device' 'implementation' 'user'}} expected-note {{the ignored 
set spans until here}}
-  ;
-#pragma omp metadirective when(device{}) // expected-warning {{expected '=' 
after the context set name "device"; '=' assumed}} expected-warning {{expected 
identifier or string literal describing a context selector; selector skipped}} 
expected-note {{context selector options are: 'kind' 'arch' 'isa'}} 
expected-note {{the ignored selector spans until here}} expected-error 
{{expected valid context selector in when clause}} expected-error {{expected 
expression}}
-  ;
-#pragma omp metadirective when(device{arch(nvptx)}) // expected-error 
{{missing ':' in when clause}} expected-error {{expected expression}} 
expected-warning {{expected '=' after the context set name "device"; '=' 
assumed}}
-  ;
-#pragma omp metadirective when(device{arch(nvptx)}: ) default() // 
expected-warning {{expected '=' after the context set name "device"; '=' 
assumed}}
-  ;
-#pragma omp metadirective when(device