diff --git a/clang/include/clang-c/Index.h b/clang/include/clang-c/Index.h --- a/clang/include/clang-c/Index.h +++ b/clang/include/clang-c/Index.h @@ -2136,7 +2136,11 @@ */ CXCursor_OMPErrorDirective = 305, - CXCursor_LastStmt = CXCursor_OMPErrorDirective, + /** OpenMP scope directive. + */ + CXCursor_OMPScopeDirective = 306, + + CXCursor_LastStmt = CXCursor_OMPScopeDirective, /** * Cursor that represents the translation unit itself. diff --git a/clang/include/clang/AST/RecursiveASTVisitor.h b/clang/include/clang/AST/RecursiveASTVisitor.h --- a/clang/include/clang/AST/RecursiveASTVisitor.h +++ b/clang/include/clang/AST/RecursiveASTVisitor.h @@ -2980,6 +2980,9 @@ DEF_TRAVERSE_STMT(OMPSectionDirective, { TRY_TO(TraverseOMPExecutableDirective(S)); }) +DEF_TRAVERSE_STMT(OMPScopeDirective, + { TRY_TO(TraverseOMPExecutableDirective(S)); }) + DEF_TRAVERSE_STMT(OMPSingleDirective, { TRY_TO(TraverseOMPExecutableDirective(S)); }) diff --git a/clang/include/clang/AST/StmtOpenMP.h b/clang/include/clang/AST/StmtOpenMP.h --- a/clang/include/clang/AST/StmtOpenMP.h +++ b/clang/include/clang/AST/StmtOpenMP.h @@ -1914,6 +1914,57 @@ } }; +/// This represents '#pragma omp scope' directive. +/// \code +/// #pragma omp scope private(a,b) nowait +/// \endcode +/// In this example directive '#pragma omp scope' has clauses 'private' with +/// the variables 'a' and 'b' and nowait. +/// +class OMPScopeDirective final : public OMPExecutableDirective { + friend class ASTStmtReader; + friend class OMPExecutableDirective; + + /// Build directive with the given start and end location. + /// + /// \param StartLoc Starting location of the directive kind. + /// \param EndLoc Ending location of the directive. + /// + OMPScopeDirective(SourceLocation StartLoc, SourceLocation EndLoc) + : OMPExecutableDirective(OMPScopeDirectiveClass, llvm::omp::OMPD_scope, + StartLoc, EndLoc) {} + + /// Build an empty directive. + /// + explicit OMPScopeDirective() + : OMPExecutableDirective(OMPScopeDirectiveClass, llvm::omp::OMPD_scope, + SourceLocation(), SourceLocation()) {} + +public: + /// Creates directive. + /// + /// \param C AST context. + /// \param StartLoc Starting location of the directive kind. + /// \param EndLoc Ending Location of the directive. + /// \param AssociatedStmt Statement, associated with the directive. + /// + static OMPScopeDirective *Create(const ASTContext &C, SourceLocation StartLoc, + SourceLocation EndLoc, + ArrayRef Clauses, + Stmt *AssociatedStmt); + + /// Creates an empty directive. + /// + /// \param C AST context. + /// + static OMPScopeDirective *CreateEmpty(const ASTContext &C, + unsigned NumClauses, EmptyShell); + + static bool classof(const Stmt *T) { + return T->getStmtClass() == OMPScopeDirectiveClass; + } +}; + /// This represents '#pragma omp single' directive. /// /// \code diff --git a/clang/include/clang/Basic/StmtNodes.td b/clang/include/clang/Basic/StmtNodes.td --- a/clang/include/clang/Basic/StmtNodes.td +++ b/clang/include/clang/Basic/StmtNodes.td @@ -259,6 +259,7 @@ def OMPTeamsDirective : StmtNode; def OMPCancellationPointDirective : StmtNode; def OMPCancelDirective : StmtNode; +def OMPScopeDirective : StmtNode; def OMPTaskLoopDirective : StmtNode; def OMPTaskLoopSimdDirective : StmtNode; def OMPMasterTaskLoopDirective : StmtNode; diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h --- a/clang/include/clang/Sema/Sema.h +++ b/clang/include/clang/Sema/Sema.h @@ -11526,6 +11526,11 @@ /// associated statement. StmtResult ActOnOpenMPSectionDirective(Stmt *AStmt, SourceLocation StartLoc, SourceLocation EndLoc); + /// Called on well-formed '\#pragma omp scope' after parsing of the + /// associated statement. + StmtResult ActOnOpenMPScopeDirective(ArrayRef Clauses, + Stmt *AStmt, SourceLocation StartLoc, + SourceLocation EndLoc); /// Called on well-formed '\#pragma omp single' after parsing of the /// associated statement. StmtResult ActOnOpenMPSingleDirective(ArrayRef Clauses, diff --git a/clang/include/clang/Serialization/ASTBitCodes.h b/clang/include/clang/Serialization/ASTBitCodes.h --- a/clang/include/clang/Serialization/ASTBitCodes.h +++ b/clang/include/clang/Serialization/ASTBitCodes.h @@ -1995,6 +1995,7 @@ STMT_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_FOR_DIRECTIVE, STMT_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_FOR_SIMD_DIRECTIVE, STMT_OMP_TARGET_TEAMS_DISTRIBUTE_SIMD_DIRECTIVE, + STMT_OMP_SCOPE_DIRECTIVE, STMT_OMP_INTEROP_DIRECTIVE, STMT_OMP_DISPATCH_DIRECTIVE, STMT_OMP_MASKED_DIRECTIVE, diff --git a/clang/lib/AST/StmtOpenMP.cpp b/clang/lib/AST/StmtOpenMP.cpp --- a/clang/lib/AST/StmtOpenMP.cpp +++ b/clang/lib/AST/StmtOpenMP.cpp @@ -529,6 +529,23 @@ /*HasAssociatedStmt=*/true); } +OMPScopeDirective *OMPScopeDirective::Create(const ASTContext &C, + SourceLocation StartLoc, + SourceLocation EndLoc, + ArrayRef Clauses, + Stmt *AssociatedStmt) { + return createDirective(C, Clauses, AssociatedStmt, + /*NumChildren=*/0, StartLoc, + EndLoc); +} + +OMPScopeDirective *OMPScopeDirective::CreateEmpty(const ASTContext &C, + unsigned NumClauses, + EmptyShell) { + return createEmptyDirective(C, NumClauses, + /*HasAssociatedStmt=*/true); +} + OMPSingleDirective *OMPSingleDirective::Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc, diff --git a/clang/lib/AST/StmtPrinter.cpp b/clang/lib/AST/StmtPrinter.cpp --- a/clang/lib/AST/StmtPrinter.cpp +++ b/clang/lib/AST/StmtPrinter.cpp @@ -777,6 +777,11 @@ PrintOMPExecutableDirective(Node); } +void StmtPrinter::VisitOMPScopeDirective(OMPScopeDirective *Node) { + Indent() << "#pragma omp scope"; + PrintOMPExecutableDirective(Node); +} + void StmtPrinter::VisitOMPSingleDirective(OMPSingleDirective *Node) { Indent() << "#pragma omp single"; PrintOMPExecutableDirective(Node); diff --git a/clang/lib/AST/StmtProfile.cpp b/clang/lib/AST/StmtProfile.cpp --- a/clang/lib/AST/StmtProfile.cpp +++ b/clang/lib/AST/StmtProfile.cpp @@ -996,6 +996,10 @@ VisitOMPExecutableDirective(S); } +void StmtProfiler::VisitOMPScopeDirective(const OMPScopeDirective *S) { + VisitOMPExecutableDirective(S); +} + void StmtProfiler::VisitOMPSingleDirective(const OMPSingleDirective *S) { VisitOMPExecutableDirective(S); } diff --git a/clang/lib/Basic/OpenMPKinds.cpp b/clang/lib/Basic/OpenMPKinds.cpp --- a/clang/lib/Basic/OpenMPKinds.cpp +++ b/clang/lib/Basic/OpenMPKinds.cpp @@ -848,6 +848,7 @@ case OMPD_atomic: case OMPD_target_data: case OMPD_distribute_simd: + case OMPD_scope: case OMPD_dispatch: CaptureRegions.push_back(OMPD_unknown); break; diff --git a/clang/lib/CodeGen/CGStmt.cpp b/clang/lib/CodeGen/CGStmt.cpp --- a/clang/lib/CodeGen/CGStmt.cpp +++ b/clang/lib/CodeGen/CGStmt.cpp @@ -409,6 +409,8 @@ case Stmt::OMPDispatchDirectiveClass: llvm_unreachable("Dispatch directive not supported yet."); break; + case Stmt::OMPScopeDirectiveClass: + llvm_unreachable("scope not supported with FE outlining"); case Stmt::OMPMaskedDirectiveClass: EmitOMPMaskedDirective(cast(*S)); break; diff --git a/clang/lib/Parse/ParseOpenMP.cpp b/clang/lib/Parse/ParseOpenMP.cpp --- a/clang/lib/Parse/ParseOpenMP.cpp +++ b/clang/lib/Parse/ParseOpenMP.cpp @@ -2418,6 +2418,7 @@ case OMPD_distribute_simd: case OMPD_target_parallel_for_simd: case OMPD_target_simd: + case OMPD_scope: case OMPD_teams_distribute: case OMPD_teams_distribute_simd: case OMPD_teams_distribute_parallel_for_simd: @@ -2810,6 +2811,7 @@ case OMPD_target_teams_loop: case OMPD_parallel_loop: case OMPD_target_parallel_loop: + case OMPD_scope: case OMPD_taskloop: case OMPD_taskloop_simd: case OMPD_master_taskloop: diff --git a/clang/lib/Sema/SemaExceptionSpec.cpp b/clang/lib/Sema/SemaExceptionSpec.cpp --- a/clang/lib/Sema/SemaExceptionSpec.cpp +++ b/clang/lib/Sema/SemaExceptionSpec.cpp @@ -1496,6 +1496,7 @@ case Stmt::OMPTargetTeamsDistributeParallelForSimdDirectiveClass: case Stmt::OMPTargetTeamsDistributeSimdDirectiveClass: case Stmt::OMPTargetUpdateDirectiveClass: + case Stmt::OMPScopeDirectiveClass: case Stmt::OMPTaskDirectiveClass: case Stmt::OMPTaskgroupDirectiveClass: case Stmt::OMPTaskLoopDirectiveClass: diff --git a/clang/lib/Sema/SemaOpenMP.cpp b/clang/lib/Sema/SemaOpenMP.cpp --- a/clang/lib/Sema/SemaOpenMP.cpp +++ b/clang/lib/Sema/SemaOpenMP.cpp @@ -3687,6 +3687,7 @@ S->getDirectiveKind() == OMPD_section || S->getDirectiveKind() == OMPD_master || S->getDirectiveKind() == OMPD_masked || + S->getDirectiveKind() == OMPD_scope || isOpenMPLoopTransformationDirective(S->getDirectiveKind())) { Visit(S->getAssociatedStmt()); return; @@ -4297,6 +4298,7 @@ case OMPD_distribute: case OMPD_distribute_simd: case OMPD_ordered: + case OMPD_scope: case OMPD_target_data: case OMPD_dispatch: { Sema::CapturedParamNameType Params[] = { @@ -5108,7 +5110,10 @@ diag::note_omp_previous_critical_region); return true; } - } else if (CurrentRegion == OMPD_barrier) { + } else if (CurrentRegion == OMPD_barrier || CurrentRegion == OMPD_scope) { + // OpenMP 5.1 [2.22, Nesting of Regions] + // A scope region may not be closely nested inside a worksharing, loop, + // task, taskloop, critical, ordered, atomic, or masked region. // OpenMP 5.1 [2.22, Nesting of Regions] // A barrier region may not be closely nested inside a worksharing, loop, // task, taskloop, critical, ordered, atomic, or masked region. @@ -6330,6 +6335,10 @@ if (LangOpts.OpenMP >= 50) AllowedNameModifiers.push_back(OMPD_simd); break; + case OMPD_scope: + Res = + ActOnOpenMPScopeDirective(ClausesWithImplicit, AStmt, StartLoc, EndLoc); + break; case OMPD_parallel_master: Res = ActOnOpenMPParallelMasterDirective(ClausesWithImplicit, AStmt, StartLoc, EndLoc); @@ -23749,6 +23758,17 @@ Vars); } +StmtResult Sema::ActOnOpenMPScopeDirective(ArrayRef Clauses, + Stmt *AStmt, SourceLocation StartLoc, + SourceLocation EndLoc) { + if (!AStmt) + return StmtError(); + + setFunctionHasBranchProtectedScope(); + + return OMPScopeDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt); +} + OMPClause *Sema::ActOnOpenMPInclusiveClause(ArrayRef VarList, SourceLocation StartLoc, SourceLocation LParenLoc, diff --git a/clang/lib/Sema/TreeTransform.h b/clang/lib/Sema/TreeTransform.h --- a/clang/lib/Sema/TreeTransform.h +++ b/clang/lib/Sema/TreeTransform.h @@ -8919,6 +8919,17 @@ return Res; } +template +StmtResult +TreeTransform::TransformOMPScopeDirective(OMPScopeDirective *D) { + DeclarationNameInfo DirName; + getDerived().getSema().StartOpenMPDSABlock(OMPD_scope, DirName, nullptr, + D->getBeginLoc()); + StmtResult Res = getDerived().TransformOMPExecutableDirective(D); + getDerived().getSema().EndOpenMPDSABlock(Res.get()); + return Res; +} + template StmtResult TreeTransform::TransformOMPSingleDirective(OMPSingleDirective *D) { diff --git a/clang/lib/Serialization/ASTReaderStmt.cpp b/clang/lib/Serialization/ASTReaderStmt.cpp --- a/clang/lib/Serialization/ASTReaderStmt.cpp +++ b/clang/lib/Serialization/ASTReaderStmt.cpp @@ -2390,6 +2390,11 @@ D->setHasCancel(Record.readBool()); } +void ASTStmtReader::VisitOMPScopeDirective(OMPScopeDirective *D) { + VisitStmt(D); + VisitOMPExecutableDirective(D); +} + void ASTStmtReader::VisitOMPSingleDirective(OMPSingleDirective *D) { VisitStmt(D); VisitOMPExecutableDirective(D); @@ -3351,6 +3356,11 @@ S = OMPSectionDirective::CreateEmpty(Context, Empty); break; + case STMT_OMP_SCOPE_DIRECTIVE: + S = OMPScopeDirective::CreateEmpty( + Context, Record[ASTStmtReader::NumStmtFields], Empty); + break; + case STMT_OMP_SINGLE_DIRECTIVE: S = OMPSingleDirective::CreateEmpty( Context, Record[ASTStmtReader::NumStmtFields], Empty); diff --git a/clang/lib/Serialization/ASTWriterStmt.cpp b/clang/lib/Serialization/ASTWriterStmt.cpp --- a/clang/lib/Serialization/ASTWriterStmt.cpp +++ b/clang/lib/Serialization/ASTWriterStmt.cpp @@ -2307,6 +2307,12 @@ Code = serialization::STMT_OMP_SECTION_DIRECTIVE; } +void ASTStmtWriter::VisitOMPScopeDirective(OMPScopeDirective *D) { + VisitStmt(D); + VisitOMPExecutableDirective(D); + Code = serialization::STMT_OMP_SCOPE_DIRECTIVE; +} + void ASTStmtWriter::VisitOMPSingleDirective(OMPSingleDirective *D) { VisitStmt(D); VisitOMPExecutableDirective(D); diff --git a/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp b/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp --- a/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp +++ b/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp @@ -1746,6 +1746,7 @@ case Stmt::OMPForSimdDirectiveClass: case Stmt::OMPSectionsDirectiveClass: case Stmt::OMPSectionDirectiveClass: + case Stmt::OMPScopeDirectiveClass: case Stmt::OMPSingleDirectiveClass: case Stmt::OMPMasterDirectiveClass: case Stmt::OMPCriticalDirectiveClass: diff --git a/clang/test/OpenMP/scope_ast_print.cpp b/clang/test/OpenMP/scope_ast_print.cpp new file mode 100644 --- /dev/null +++ b/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 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-dump-all %s | FileCheck %s --check-prefix=DUMP + +#ifndef HEADER +#define HEADER +int foo1() { + int a; + int i = 1; + #pragma omp scope private(a) reduction(+:i) nowait + { + a = 123; + ++i; + } + return i; +} + +//DUMP: FunctionDecl {{.*}}foo1 'int ()' +//DUMP: OMPScopeDirective +//DUMP: OMPPrivateClause +//DUMP: DeclRefExpr {{.*}}'int' lvalue Var{{.*}}'a' 'int' +//DUMP: OMPReductionClause +//DUMP: DeclRefExpr {{.*}}'int' lvalue Var{{.*}}'i' 'int' +//DUMP: OMPNowaitClause +//PRINT: #pragma omp scope private(a) reduction(+: i) nowait + +template +T run() { + T a; + T b; + + #pragma omp scope private(a) reduction(*:b) + { + b *= a; + } + return b; +} + +int template_test() { + double d; + d = run(); + return 0; +} + +//DUMP: FunctionTemplateDecl {{.*}}run +//DUMP: TemplateTypeParmDecl {{.*}}referenced typename depth 0 index 0 T +//DUMP: FunctionDecl {{.*}}run 'T ()' +//DUMP: OMPScopeDirective +//DUMP: OMPPrivateClause +//DUMP: DeclRefExpr {{.*}}'T' lvalue Var {{.*}} 'a' 'T' +//DUMP: OMPReductionClause +//DUMP: DeclRefExpr {{.*}}'T' lvalue Var {{.*}} 'b' 'T' +//DUMP: FunctionDecl {{.*}}used run 'double ()' +//DUMP: TemplateArgument type 'double' +//DUMP: BuiltinType {{.*}}'double' +//DUMP: OMPScopeDirective +//DUMP: OMPPrivateClause +//DUMP: DeclRefExpr {{.*}}'double':'double' lvalue Var {{.*}} 'a' 'double':'double' +//DUMP: OMPReductionClause +//DUMP: DeclRefExpr {{.*}}'double':'double' lvalue Var {{.*}} 'b' 'double':'double' +//PRINT: #pragma omp scope private(a) reduction(*: b) +#endif // HEADER diff --git a/clang/test/OpenMP/scope_messages.cpp b/clang/test/OpenMP/scope_messages.cpp new file mode 100644 --- /dev/null +++ b/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' region}} + bar(); + } + +#pragma omp critical + { +#pragma omp scope // expected-error {{region cannot be closely nested inside 'critical' region}} + bar(); + } + +#pragma omp parallel for + for (int i = 0; i < 10; ++i) { +#pragma omp scope // expected-error {{region cannot be closely nested inside 'parallel for' region}} + bar(); + } + +#pragma omp parallel 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 parallel master + { +#pragma omp scope // expected-error {{region cannot be closely nested inside 'parallel master' region}} + bar(); + } + +#pragma omp parallel sections + { +#pragma omp scope // expected-error {{region cannot be closely nested inside 'parallel sections' region}} + bar(); + } + +#pragma omp task + { +#pragma omp scope // expected-error {{region cannot be closely nested inside 'task' region}} + bar(); + } + +#pragma omp ordered + { +#pragma omp scope // expected-error {{region cannot be closely nested inside 'ordered' region}} + bar(); + } + +#pragma omp atomic + // expected-error@+2 {{the statement for 'atomic' must be an expression statement of form '++x;', '--x;', 'x++;', 'x--;', 'x binop= expr;', 'x = x binop expr' or 'x = expr binop x', where x is an lvalue expression with scalar type}} + // expected-note@+1 {{expected an expression statement}} + { +#pragma omp scope // expected-error {{OpenMP constructs may not be nested inside an atomic region}} + bar(); + } + +#pragma omp target +#pragma omp teams + { +#pragma omp scope // expected-error {{region cannot be closely nested inside 'teams' region; perhaps you forget to enclose 'omp scope' directive into a parallel region?}} + bar(); + } + +#pragma omp taskloop + for (int i = 0; i < 10; ++i) { +#pragma omp scope // expected-error {{region cannot be closely nested inside 'taskloop' region}} + bar(); + } + +#pragma omp target +#pragma omp teams +#pragma omp distribute parallel for + for (int i = 0; i < 10; ++i) { +#pragma omp scope // expected-error {{region cannot be closely nested inside 'distribute parallel for' region}} + bar(); + } + +#pragma omp target +#pragma omp teams +#pragma omp distribute parallel 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 target 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 target +#pragma omp teams distribute 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 target +#pragma omp teams distribute parallel 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 target +#pragma omp teams distribute parallel for + for (int i = 0; i < 10; ++i) { +#pragma omp scope // expected-error {{region cannot be closely nested inside 'teams distribute parallel for' region}} + bar(); + } + +#pragma omp target teams + { +#pragma omp scope // expected-error {{region cannot be closely nested inside 'target teams' region; perhaps you forget to enclose 'omp scope' directive into a parallel region?}} + bar(); + } + +#pragma omp target teams distribute parallel for + for (int i = 0; i < 10; ++i) { +#pragma omp scope // expected-error {{region cannot be closely nested inside 'target teams distribute parallel for' region}} + bar(); + } + +#pragma omp target teams distribute parallel 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 target teams distribute 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 simd + for (int i = 0; i < 10; ++i) { +#pragma omp scope // expected-error {{OpenMP constructs may not be nested inside a simd region}} + bar(); + } +} diff --git a/clang/tools/libclang/CIndex.cpp b/clang/tools/libclang/CIndex.cpp --- a/clang/tools/libclang/CIndex.cpp +++ b/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: diff --git a/clang/tools/libclang/CXCursor.cpp b/clang/tools/libclang/CXCursor.cpp --- a/clang/tools/libclang/CXCursor.cpp +++ b/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; diff --git a/llvm/include/llvm/Frontend/OpenMP/OMP.td b/llvm/include/llvm/Frontend/OpenMP/OMP.td --- a/llvm/include/llvm/Frontend/OpenMP/OMP.td +++ b/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,