Index: clang/include/clang/AST/OpenMPClause.h =================================================================== --- clang/include/clang/AST/OpenMPClause.h +++ clang/include/clang/AST/OpenMPClause.h @@ -827,6 +827,38 @@ } }; +/// This represents 'dynamic_allocators' clause in the '#pragma omp requires' +/// directive. +/// +/// \code +/// #pragma omp requires dynamic_allocators +/// \endcode +/// In this example directive '#pragma omp requires' has 'dynamic_allocators' +/// clause. +class OMPDynamicAllocatorsClause final : public OMPClause { +public: + friend class OMPClauseReader; + /// Build 'dynamic_allocators' clause. + /// + /// \param StartLoc Starting location of the clause. + /// \param EndLoc Ending location of the clause. + OMPDynamicAllocatorsClause(SourceLocation StartLoc, SourceLocation EndLoc) + : OMPClause(OMPC_dynamic_allocators, StartLoc, EndLoc) {} + + /// Build an empty clause. + OMPDynamicAllocatorsClause() + : OMPClause(OMPC_dynamic_allocators, SourceLocation(), SourceLocation()) { + } + + child_range children() { + return child_range(child_iterator(), child_iterator()); + } + + static bool classof(const OMPClause *T) { + return T->getClauseKind() == OMPC_dynamic_allocators; + } +}; + /// This represents 'schedule' clause in the '#pragma omp ...' directive. /// /// \code Index: clang/include/clang/AST/RecursiveASTVisitor.h =================================================================== --- clang/include/clang/AST/RecursiveASTVisitor.h +++ clang/include/clang/AST/RecursiveASTVisitor.h @@ -2880,6 +2880,12 @@ } template +bool RecursiveASTVisitor::VisitOMPDynamicAllocatorsClause( + OMPDynamicAllocatorsClause *) { + return true; +} + +template bool RecursiveASTVisitor::VisitOMPScheduleClause(OMPScheduleClause *C) { TRY_TO(VisitOMPClauseWithPreInit(C)); Index: clang/include/clang/Basic/OpenMPKinds.def =================================================================== --- clang/include/clang/Basic/OpenMPKinds.def +++ clang/include/clang/Basic/OpenMPKinds.def @@ -282,6 +282,7 @@ OPENMP_CLAUSE(unified_address, OMPUnifiedAddressClause) OPENMP_CLAUSE(unified_shared_memory, OMPUnifiedSharedMemoryClause) OPENMP_CLAUSE(reverse_offload, OMPReverseOffloadClause) +OPENMP_CLAUSE(dynamic_allocators, OMPDynamicAllocatorsClause) // Clauses allowed for OpenMP directive 'parallel'. OPENMP_PARALLEL_CLAUSE(if) @@ -467,6 +468,7 @@ OPENMP_REQUIRES_CLAUSE(unified_address) OPENMP_REQUIRES_CLAUSE(unified_shared_memory) OPENMP_REQUIRES_CLAUSE(reverse_offload) +OPENMP_REQUIRES_CLAUSE(dynamic_allocators) // Clauses allowed for OpenMP directive 'target data'. OPENMP_TARGET_DATA_CLAUSE(if) Index: clang/include/clang/Sema/Sema.h =================================================================== --- clang/include/clang/Sema/Sema.h +++ clang/include/clang/Sema/Sema.h @@ -9176,6 +9176,10 @@ OMPClause *ActOnOpenMPReverseOffloadClause(SourceLocation StartLoc, SourceLocation EndLoc); + /// Called on well-formed 'dynamic_allocators' clause. + OMPClause *ActOnOpenMPDynamicAllocatorsClause(SourceLocation StartLoc, + SourceLocation EndLoc); + OMPClause *ActOnOpenMPVarListClause( OpenMPClauseKind Kind, ArrayRef Vars, Expr *TailExpr, SourceLocation StartLoc, SourceLocation LParenLoc, Index: clang/lib/AST/OpenMPClause.cpp =================================================================== --- clang/lib/AST/OpenMPClause.cpp +++ clang/lib/AST/OpenMPClause.cpp @@ -109,6 +109,7 @@ case OMPC_unified_address: case OMPC_unified_shared_memory: case OMPC_reverse_offload: + case OMPC_dynamic_allocators: break; } @@ -181,6 +182,7 @@ case OMPC_unified_address: case OMPC_unified_shared_memory: case OMPC_reverse_offload: + case OMPC_dynamic_allocators: break; } Index: clang/lib/AST/StmtPrinter.cpp =================================================================== --- clang/lib/AST/StmtPrinter.cpp +++ clang/lib/AST/StmtPrinter.cpp @@ -709,6 +709,11 @@ OS << "reverse_offload"; } +void OMPClausePrinter::VisitOMPDynamicAllocatorsClause( + OMPDynamicAllocatorsClause *) { + OS << "dynamic_allocators"; +} + void OMPClausePrinter::VisitOMPScheduleClause(OMPScheduleClause *Node) { OS << "schedule("; if (Node->getFirstScheduleModifier() != OMPC_SCHEDULE_MODIFIER_unknown) { Index: clang/lib/AST/StmtProfile.cpp =================================================================== --- clang/lib/AST/StmtProfile.cpp +++ clang/lib/AST/StmtProfile.cpp @@ -476,6 +476,9 @@ void OMPClauseProfiler::VisitOMPReverseOffloadClause( const OMPReverseOffloadClause *C) {} +void OMPClauseProfiler::VisitOMPDynamicAllocatorsClause( + const OMPDynamicAllocatorsClause *C) {} + void OMPClauseProfiler::VisitOMPScheduleClause(const OMPScheduleClause *C) { VistOMPClauseWithPreInit(C); if (auto *S = C->getChunkSize()) Index: clang/lib/Basic/OpenMPKinds.cpp =================================================================== --- clang/lib/Basic/OpenMPKinds.cpp +++ clang/lib/Basic/OpenMPKinds.cpp @@ -171,6 +171,7 @@ case OMPC_unified_address: case OMPC_unified_shared_memory: case OMPC_reverse_offload: + case OMPC_dynamic_allocators: break; } llvm_unreachable("Invalid OpenMP simple clause kind"); @@ -315,6 +316,7 @@ case OMPC_unified_address: case OMPC_unified_shared_memory: case OMPC_reverse_offload: + case OMPC_dynamic_allocators: break; } llvm_unreachable("Invalid OpenMP simple clause kind"); Index: clang/lib/CodeGen/CGStmtOpenMP.cpp =================================================================== --- clang/lib/CodeGen/CGStmtOpenMP.cpp +++ clang/lib/CodeGen/CGStmtOpenMP.cpp @@ -3901,6 +3901,7 @@ case OMPC_unified_address: case OMPC_unified_shared_memory: case OMPC_reverse_offload: + case OMPC_dynamic_allocators: llvm_unreachable("Clause is not allowed in 'omp atomic'."); } } Index: clang/lib/Parse/ParseOpenMP.cpp =================================================================== --- clang/lib/Parse/ParseOpenMP.cpp +++ clang/lib/Parse/ParseOpenMP.cpp @@ -1381,6 +1381,7 @@ case OMPC_unified_address: case OMPC_unified_shared_memory: case OMPC_reverse_offload: + case OMPC_dynamic_allocators: // OpenMP [2.7.1, Restrictions, p. 9] // Only one ordered clause can appear on a loop directive. // OpenMP [2.7.1, Restrictions, C/C++, p. 4] Index: clang/lib/Sema/SemaOpenMP.cpp =================================================================== --- clang/lib/Sema/SemaOpenMP.cpp +++ clang/lib/Sema/SemaOpenMP.cpp @@ -8013,6 +8013,7 @@ case OMPC_unified_address: case OMPC_unified_shared_memory: case OMPC_reverse_offload: + case OMPC_dynamic_allocators: llvm_unreachable("Clause is not allowed."); } return Res; @@ -8537,6 +8538,7 @@ case OMPC_unified_address: case OMPC_unified_shared_memory: case OMPC_reverse_offload: + case OMPC_dynamic_allocators: llvm_unreachable("Unexpected OpenMP clause."); } return CaptureRegion; @@ -8857,6 +8859,7 @@ case OMPC_unified_address: case OMPC_unified_shared_memory: case OMPC_reverse_offload: + case OMPC_dynamic_allocators: llvm_unreachable("Clause is not allowed."); } return Res; @@ -9016,6 +9019,7 @@ case OMPC_unified_address: case OMPC_unified_shared_memory: case OMPC_reverse_offload: + case OMPC_dynamic_allocators: llvm_unreachable("Clause is not allowed."); } return Res; @@ -9180,6 +9184,9 @@ case OMPC_reverse_offload: Res = ActOnOpenMPReverseOffloadClause(StartLoc, EndLoc); break; + case OMPC_dynamic_allocators: + Res = ActOnOpenMPDynamicAllocatorsClause(StartLoc, EndLoc); + break; case OMPC_if: case OMPC_final: case OMPC_num_threads: @@ -9295,6 +9302,11 @@ return new (Context) OMPReverseOffloadClause(StartLoc, EndLoc); } +OMPClause *Sema::ActOnOpenMPDynamicAllocatorsClause(SourceLocation StartLoc, + SourceLocation EndLoc) { + return new (Context) OMPDynamicAllocatorsClause(StartLoc, EndLoc); +} + OMPClause *Sema::ActOnOpenMPVarListClause( OpenMPClauseKind Kind, ArrayRef VarList, Expr *TailExpr, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation ColonLoc, @@ -9405,6 +9417,7 @@ case OMPC_unified_address: case OMPC_unified_shared_memory: case OMPC_reverse_offload: + case OMPC_dynamic_allocators: llvm_unreachable("Clause is not allowed."); } return Res; Index: clang/lib/Sema/TreeTransform.h =================================================================== --- clang/lib/Sema/TreeTransform.h +++ clang/lib/Sema/TreeTransform.h @@ -8450,6 +8450,13 @@ } template +OMPClause *TreeTransform::TransformOMPDynamicAllocatorsClause( + OMPDynamicAllocatorsClause *C) { + llvm_unreachable( + "dynamic_allocators clause cannot appear in dependent context"); +} + +template OMPClause * TreeTransform::TransformOMPPrivateClause(OMPPrivateClause *C) { llvm::SmallVector Vars; Index: clang/lib/Serialization/ASTReader.cpp =================================================================== --- clang/lib/Serialization/ASTReader.cpp +++ clang/lib/Serialization/ASTReader.cpp @@ -11729,6 +11729,9 @@ case OMPC_reverse_offload: C = new (Context) OMPReverseOffloadClause(); break; + case OMPC_dynamic_allocators: + C = new (Context) OMPDynamicAllocatorsClause(); + break; case OMPC_private: C = OMPPrivateClause::CreateEmpty(Context, Record.readInt()); break; @@ -11964,6 +11967,10 @@ void OMPClauseReader::VisitOMPReverseOffloadClause(OMPReverseOffloadClause *) {} +void +OMPClauseReader::VisitOMPDynamicAllocatorsClause(OMPDynamicAllocatorsClause *) { +} + void OMPClauseReader::VisitOMPPrivateClause(OMPPrivateClause *C) { C->setLParenLoc(Record.readSourceLocation()); unsigned NumVars = C->varlist_size(); Index: clang/lib/Serialization/ASTWriter.cpp =================================================================== --- clang/lib/Serialization/ASTWriter.cpp +++ clang/lib/Serialization/ASTWriter.cpp @@ -6937,3 +6937,7 @@ OMPUnifiedSharedMemoryClause *) {} void OMPClauseWriter::VisitOMPReverseOffloadClause(OMPReverseOffloadClause *) {} + +void +OMPClauseWriter::VisitOMPDynamicAllocatorsClause(OMPDynamicAllocatorsClause *) { +} Index: clang/test/OpenMP/requires_unified_address_ast_print.cpp =================================================================== --- clang/test/OpenMP/requires_unified_address_ast_print.cpp +++ clang/test/OpenMP/requires_unified_address_ast_print.cpp @@ -19,4 +19,7 @@ #pragma omp requires reverse_offload // CHECK:#pragma omp requires reverse_offload +#pragma omp requires dynamic_allocators +// CHECK:#pragma omp requires dynamic_allocators + #endif Index: clang/test/OpenMP/requires_unified_address_messages.cpp =================================================================== --- clang/test/OpenMP/requires_unified_address_messages.cpp +++ clang/test/OpenMP/requires_unified_address_messages.cpp @@ -14,6 +14,11 @@ #pragma omp requires reverse_offload, reverse_offload // expected-error {{Only one reverse_offload clause can appear on a requires directive in a single translation unit}} expected-error {{directive '#pragma omp requires' cannot contain more than one 'reverse_offload' clause}} +#pragma omp requires dynamic_allocators // expected-note {{dynamic_allocators clause previously used here}} expected-note {{dynamic_allocators clause previously used here}} + +#pragma omp requires dynamic_allocators, dynamic_allocators // expected-error {{Only one dynamic_allocators clause can appear on a requires directive in a single translation unit}} expected-error {{directive '#pragma omp requires' cannot contain more than one 'dynamic_allocators' clause}} + + #pragma omp requires // expected-error {{expected at least one clause on '#pragma omp requires' directive}} #pragma omp requires invalid_clause // expected-warning {{extra tokens at the end of '#pragma omp requires' are ignored}} expected-error {{expected at least one clause on '#pragma omp requires' directive}} @@ -24,7 +29,7 @@ #pragma omp requires invalid_clause unified_address // expected-warning {{extra tokens at the end of '#pragma omp requires' are ignored}} expected-error {{expected at least one clause on '#pragma omp requires' directive}} -#pragma omp requires unified_shared_memory, unified_address, reverse_offload // expected-error {{Only one unified_shared_memory clause can appear on a requires directive in a single translation unit}} expected-error{{Only one unified_address clause can appear on a requires directive in a single translation unit}} expected-error{{Only one reverse_offload clause can appear on a requires directive in a single translation unit}} +#pragma omp requires unified_shared_memory, unified_address, reverse_offload, dynamic_allocators // expected-error {{Only one unified_shared_memory clause can appear on a requires directive in a single translation unit}} expected-error{{Only one unified_address clause can appear on a requires directive in a single translation unit}} expected-error{{Only one reverse_offload clause can appear on a requires directive in a single translation unit}} expected-error{{Only one dynamic_allocators clause can appear on a requires directive in a single translation unit}} namespace A { #pragma omp requires unified_address // expected-error {{Only one unified_address clause can appear on a requires directive in a single translation unit}} Index: clang/tools/libclang/CIndex.cpp =================================================================== --- clang/tools/libclang/CIndex.cpp +++ clang/tools/libclang/CIndex.cpp @@ -2216,6 +2216,9 @@ void OMPClauseEnqueue::VisitOMPReverseOffloadClause( const OMPReverseOffloadClause *) {} +void OMPClauseEnqueue::VisitOMPDynamicAllocatorsClause( + const OMPDynamicAllocatorsClause *) {} + void OMPClauseEnqueue::VisitOMPDeviceClause(const OMPDeviceClause *C) { Visitor->AddStmt(C->getDevice()); }