[PATCH] D157933: [OpenMP 5.1] Parsing and Sema support for `scope` construct

2023-08-22 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev accepted this revision.
ABataev added a comment.
This revision is now accepted and ready to land.

LG. Please, update docs/OpenMPSupport.rst


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D157933/new/

https://reviews.llvm.org/D157933

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D157933: [OpenMP 5.1] Parsing and Sema support for `scope` construct

2023-08-22 Thread Fazlay Rabbi via Phabricator via cfe-commits
mdfazlay added a comment.

In D157933#4591627 , @ABataev wrote:

> Could you also add the nesting tests for outer scope directive? Currently it 
> tests only for inner

Added. Please take a look.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D157933/new/

https://reviews.llvm.org/D157933

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D157933: [OpenMP 5.1] Parsing and Sema support for `scope` construct

2023-08-16 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev added a comment.

Could you also add the nesting tests for outer scope directive? Currently it 
tests only for inner


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D157933/new/

https://reviews.llvm.org/D157933

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D157933: [OpenMP 5.1] Parsing and Sema support for `scope` construct

2023-08-15 Thread Fazlay Rabbi via Phabricator via cfe-commits
mdfazlay updated this revision to Diff 550521.
mdfazlay added a comment.

Updated nesting of  regions checks.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D157933/new/

https://reviews.llvm.org/D157933

Files:
  clang/include/clang-c/Index.h
  clang/include/clang/AST/RecursiveASTVisitor.h
  clang/include/clang/AST/StmtOpenMP.h
  clang/include/clang/Basic/StmtNodes.td
  clang/include/clang/Sema/Sema.h
  clang/include/clang/Serialization/ASTBitCodes.h
  clang/lib/AST/StmtOpenMP.cpp
  clang/lib/AST/StmtPrinter.cpp
  clang/lib/AST/StmtProfile.cpp
  clang/lib/Basic/OpenMPKinds.cpp
  clang/lib/CodeGen/CGStmt.cpp
  clang/lib/Parse/ParseOpenMP.cpp
  clang/lib/Sema/SemaExceptionSpec.cpp
  clang/lib/Sema/SemaOpenMP.cpp
  clang/lib/Sema/TreeTransform.h
  clang/lib/Serialization/ASTReaderStmt.cpp
  clang/lib/Serialization/ASTWriterStmt.cpp
  clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
  clang/test/OpenMP/nesting_of_regions.cpp
  clang/test/OpenMP/scope_ast_print.cpp
  clang/test/OpenMP/scope_messages.cpp
  clang/tools/libclang/CIndex.cpp
  clang/tools/libclang/CXCursor.cpp
  llvm/include/llvm/Frontend/OpenMP/OMP.td

Index: llvm/include/llvm/Frontend/OpenMP/OMP.td
===
--- llvm/include/llvm/Frontend/OpenMP/OMP.td
+++ llvm/include/llvm/Frontend/OpenMP/OMP.td
@@ -1979,6 +1979,15 @@
 def OMP_EndAssumes : Directive<"end assumes"> {}
 def OMP_BeginDeclareVariant : Directive<"begin declare variant"> {}
 def OMP_EndDeclareVariant : Directive<"end declare variant"> {}
+def OMP_scope : Directive<"scope"> {
+  let allowedClauses = [
+VersionedClause,
+VersionedClause,
+  ];
+  let allowedOnceClauses = [
+VersionedClause
+  ];
+}
 def OMP_ParallelWorkshare : Directive<"parallel workshare"> {
   let allowedClauses = [
 VersionedClause,
Index: clang/tools/libclang/CXCursor.cpp
===
--- clang/tools/libclang/CXCursor.cpp
+++ clang/tools/libclang/CXCursor.cpp
@@ -680,6 +680,9 @@
   case Stmt::OMPSectionDirectiveClass:
 K = CXCursor_OMPSectionDirective;
 break;
+  case Stmt::OMPScopeDirectiveClass:
+K = CXCursor_OMPScopeDirective;
+break;
   case Stmt::OMPSingleDirectiveClass:
 K = CXCursor_OMPSingleDirective;
 break;
Index: clang/tools/libclang/CIndex.cpp
===
--- clang/tools/libclang/CIndex.cpp
+++ clang/tools/libclang/CIndex.cpp
@@ -5889,6 +5889,8 @@
 return cxstring::createRef("OMPSectionsDirective");
   case CXCursor_OMPSectionDirective:
 return cxstring::createRef("OMPSectionDirective");
+  case CXCursor_OMPScopeDirective:
+return cxstring::createRef("OMPScopeDirective");
   case CXCursor_OMPSingleDirective:
 return cxstring::createRef("OMPSingleDirective");
   case CXCursor_OMPMasterDirective:
Index: clang/test/OpenMP/scope_messages.cpp
===
--- /dev/null
+++ clang/test/OpenMP/scope_messages.cpp
@@ -0,0 +1,13 @@
+// RUN: %clang_cc1 -fopenmp -fopenmp-version=51 %s -verify=expected,omp51
+// RUN: %clang_cc1 -fopenmp -fopenmp-version=51 %s -verify=expected,omp51
+
+void test1()
+{
+  int var1;
+  int var2;
+  int var3 = 1;
+
+  // expected-error@+1 {{directive '#pragma omp scope' cannot contain more than one 'nowait' clause}} //omp51-error@+1{{unexpected OpenMP clause 'firstprivate' in directive '#pragma omp scope'}}
+  #pragma omp scope private(var1) firstprivate(var3) nowait nowait
+  { var1 = 123; ++var2; var3 = 2;}
+}
Index: clang/test/OpenMP/scope_ast_print.cpp
===
--- /dev/null
+++ clang/test/OpenMP/scope_ast_print.cpp
@@ -0,0 +1,88 @@
+//RUN: %clang_cc1 -triple x86_64-pc-linux-gnu\
+//RUN:   -fopenmp -fopenmp-version=51 \
+//RUN:   -x c++ -std=c++14 -fexceptions -fcxx-exceptions   \
+//RUN:   -Wno-source-uses-openmp -Wno-openmp-clauses   \
+//RUN:   -ast-print %s | FileCheck %s --check-prefix=PRINT
+
+//RUN: %clang_cc1 -triple x86_64-pc-linux-gnu\
+//RUN:   -fopenmp -fopenmp-version=51 \
+//RUN:   -x c++ -std=c++14 -fexceptions -fcxx-exceptions   \
+//RUN:   -Wno-source-uses-openmp -Wno-openmp-clauses   \
+//RUN:   -ast-dump %s | FileCheck %s --check-prefix=DUMP
+
+//RUN: %clang_cc1 -triple x86_64-pc-linux-gnu\
+//RUN:   -fopenmp -fopenmp-version=51 \
+//RUN:   -x c++ -std=c++14 -fexceptions -fcxx-exceptions   \
+//RUN:   -Wno-source-uses-openmp -Wno-openmp-clauses   \
+//RUN:   -emit-pch -o %t %s
+
+//RUN: %clang_cc1 -triple x86_64-pc-linux-gnu\
+//RUN:   -fopenmp -fopenmp-version=51 \
+//RUN:   -x c++ -std=c++14 -fexceptions -fcxx-exceptions   \
+//RUN:   -Wno-source-uses-openmp -Wno-openmp-clauses   \
+//RUN:   -include-pch %t -ast-print %s | FileCheck %s --check-prefix=PRINT
+
+//RUN: %clang_cc1 -triple 

[PATCH] D157933: [OpenMP 5.1] Parsing and Sema support for `scope` construct

2023-08-14 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev added a comment.

In D157933#4587164 , @mdfazlay wrote:

> In D157933#4586816 , @ABataev wrote:
>
>> Need to add the tests (and the checks, if required) for the nesting of the 
>> regions
>
> I think I have the nesting of regions checks in //scope_messages.cpp//. Do 
> you prefer to have those checks in //nesting_of_regions.cpp// file?

Yes, extend this one


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D157933/new/

https://reviews.llvm.org/D157933

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D157933: [OpenMP 5.1] Parsing and Sema support for `scope` construct

2023-08-14 Thread Fazlay Rabbi via Phabricator via cfe-commits
mdfazlay added a comment.

In D157933#4586816 , @ABataev wrote:

> Need to add the tests (and the checks, if required) for the nesting of the 
> regions

I think I have the nesting of regions checks in //scope_messages.cpp//. Do you 
prefer to have those checks in //nesting_of_regions.cpp// file?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D157933/new/

https://reviews.llvm.org/D157933

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D157933: [OpenMP 5.1] Parsing and Sema support for `scope` construct

2023-08-14 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev added a comment.

Need to add the tests (and the checks, if required) for the nesting of the 
regions


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D157933/new/

https://reviews.llvm.org/D157933

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D157933: [OpenMP 5.1] Parsing and Sema support for `scope` construct

2023-08-14 Thread Fazlay Rabbi via Phabricator via cfe-commits
mdfazlay created this revision.
mdfazlay added reviewers: ABataev, jyu2, mikerice.
Herald added subscribers: steakhal, martong, arphaman, guansong, yaxunl.
Herald added a reviewer: NoQ.
Herald added a project: All.
mdfazlay requested review of this revision.
Herald added a reviewer: jdoerfert.
Herald added subscribers: llvm-commits, cfe-commits, jplehr, sstefan1.
Herald added projects: clang, LLVM.

//#pragma omp scope [clause[ [,] clause] ... ]//
structured-block

where clause is one of the following:

private(list)
reduction([reduction-modifier ,] reduction-identifier : list)
nowait

Reference:
(1) OpenMP 5.1 Specification - Section 2.9 (Page 106)


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D157933

Files:
  clang/include/clang-c/Index.h
  clang/include/clang/AST/RecursiveASTVisitor.h
  clang/include/clang/AST/StmtOpenMP.h
  clang/include/clang/Basic/StmtNodes.td
  clang/include/clang/Sema/Sema.h
  clang/include/clang/Serialization/ASTBitCodes.h
  clang/lib/AST/StmtOpenMP.cpp
  clang/lib/AST/StmtPrinter.cpp
  clang/lib/AST/StmtProfile.cpp
  clang/lib/Basic/OpenMPKinds.cpp
  clang/lib/CodeGen/CGStmt.cpp
  clang/lib/Parse/ParseOpenMP.cpp
  clang/lib/Sema/SemaExceptionSpec.cpp
  clang/lib/Sema/SemaOpenMP.cpp
  clang/lib/Sema/TreeTransform.h
  clang/lib/Serialization/ASTReaderStmt.cpp
  clang/lib/Serialization/ASTWriterStmt.cpp
  clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
  clang/test/OpenMP/scope_ast_print.cpp
  clang/test/OpenMP/scope_messages.cpp
  clang/tools/libclang/CIndex.cpp
  clang/tools/libclang/CXCursor.cpp
  llvm/include/llvm/Frontend/OpenMP/OMP.td

Index: llvm/include/llvm/Frontend/OpenMP/OMP.td
===
--- llvm/include/llvm/Frontend/OpenMP/OMP.td
+++ llvm/include/llvm/Frontend/OpenMP/OMP.td
@@ -1979,6 +1979,15 @@
 def OMP_EndAssumes : Directive<"end assumes"> {}
 def OMP_BeginDeclareVariant : Directive<"begin declare variant"> {}
 def OMP_EndDeclareVariant : Directive<"end declare variant"> {}
+def OMP_scope : Directive<"scope"> {
+  let allowedClauses = [
+VersionedClause,
+VersionedClause,
+  ];
+  let allowedOnceClauses = [
+VersionedClause
+  ];
+}
 def OMP_ParallelWorkshare : Directive<"parallel workshare"> {
   let allowedClauses = [
 VersionedClause,
Index: clang/tools/libclang/CXCursor.cpp
===
--- clang/tools/libclang/CXCursor.cpp
+++ clang/tools/libclang/CXCursor.cpp
@@ -680,6 +680,9 @@
   case Stmt::OMPSectionDirectiveClass:
 K = CXCursor_OMPSectionDirective;
 break;
+  case Stmt::OMPScopeDirectiveClass:
+K = CXCursor_OMPScopeDirective;
+break;
   case Stmt::OMPSingleDirectiveClass:
 K = CXCursor_OMPSingleDirective;
 break;
Index: clang/tools/libclang/CIndex.cpp
===
--- clang/tools/libclang/CIndex.cpp
+++ clang/tools/libclang/CIndex.cpp
@@ -5889,6 +5889,8 @@
 return cxstring::createRef("OMPSectionsDirective");
   case CXCursor_OMPSectionDirective:
 return cxstring::createRef("OMPSectionDirective");
+  case CXCursor_OMPScopeDirective:
+return cxstring::createRef("OMPScopeDirective");
   case CXCursor_OMPSingleDirective:
 return cxstring::createRef("OMPSingleDirective");
   case CXCursor_OMPMasterDirective:
Index: clang/test/OpenMP/scope_messages.cpp
===
--- /dev/null
+++ clang/test/OpenMP/scope_messages.cpp
@@ -0,0 +1,192 @@
+// RUN: %clang_cc1 -fopenmp -fopenmp-version=51 %s -verify=expected,omp51
+// RUN: %clang_cc1 -fopenmp -fopenmp-version=51 %s -verify=expected,omp51
+
+void test1()
+{
+  int var1;
+  int var2;
+  int var3 = 1;
+
+  // expected-error@+1 {{directive '#pragma omp scope' cannot contain more than one 'nowait' clause}} //omp51-error@+1{{unexpected OpenMP clause 'firstprivate' in directive '#pragma omp scope'}}
+  #pragma omp scope private(var1) firstprivate(var3) nowait nowait
+  { var1 = 123; ++var2; var3 = 2;}
+}
+
+void bar();
+
+void test2() {
+#pragma omp for
+  for (int i = 0; i < 10; ++i) {
+#pragma omp scope // expected-error {{region cannot be closely nested inside 'for' region}}
+bar();
+  }
+
+#pragma omp for simd
+  for (int i = 0; i < 10; ++i) {
+#pragma omp scope // expected-error {{OpenMP constructs may not be nested inside a simd region}}
+bar();
+  }
+
+#pragma omp sections
+  {
+#pragma omp scope // expected-error {{region cannot be closely nested inside 'sections' region}}
+bar();
+  }
+
+#pragma omp sections
+  {
+#pragma omp section
+{
+#pragma omp scope // expected-error {{region cannot be closely nested inside 'section' region}}
+  bar();
+}
+  }
+
+#pragma omp single
+  {
+#pragma omp scope // expected-error {{region cannot be closely nested inside 'single' region}}
+bar();
+  }
+
+#pragma omp master
+  {
+#pragma omp scope // expected-error {{region cannot be closely nested inside 'master'