Author: abataev Date: Fri Mar 22 08:25:12 2019 New Revision: 356758 URL: http://llvm.org/viewvc/llvm-project?rev=356758&view=rev Log: [OPENMP]Allow no allocator clause in target regions with requires dynamic_allocators.
According to the OpenMP 5.0, 2.11.3 allocate Directive, Restrictions, allocate directives that appear in a target region must specify an allocator clause unless a requires directive with the dynamic_allocators clause is present in the same compilation unit. Patch adds a check for a presence of the requires directive with the dynamic_allocators clause. Modified: cfe/trunk/lib/Sema/SemaOpenMP.cpp cfe/trunk/test/OpenMP/nvptx_allocate_messages.cpp Modified: cfe/trunk/lib/Sema/SemaOpenMP.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaOpenMP.cpp?rev=356758&r1=356757&r2=356758&view=diff ============================================================================== --- cfe/trunk/lib/Sema/SemaOpenMP.cpp (original) +++ cfe/trunk/lib/Sema/SemaOpenMP.cpp Fri Mar 22 08:25:12 2019 @@ -422,6 +422,16 @@ public: RequiresDecls.push_back(RD); } + /// Checks if the defined 'requires' directive has specified type of clause. + template <typename ClauseType> + bool hasRequiresDeclWithClause() { + return llvm::any_of(RequiresDecls, [](const OMPRequiresDecl *D) { + return llvm::any_of(D->clauselists(), [](const OMPClause *C) { + return isa<ClauseType>(C); + }); + }); + } + /// Checks for a duplicate clause amongst previously declared requires /// directives bool hasDuplicateRequiresClause(ArrayRef<OMPClause *> ClauseList) const { @@ -2244,7 +2254,8 @@ Sema::DeclGroupPtrTy Sema::ActOnOpenMPAl assert(Clauses.size() <= 1 && "Expected at most one clause."); Expr *Allocator = nullptr; if (Clauses.empty()) { - if (LangOpts.OpenMPIsDevice) + if (LangOpts.OpenMPIsDevice && + !DSAStack->hasRequiresDeclWithClause<OMPDynamicAllocatorsClause>()) targetDiag(Loc, diag::err_expected_allocator_clause); } else { Allocator = cast<OMPAllocatorClause>(Clauses.back())->getAllocator(); Modified: cfe/trunk/test/OpenMP/nvptx_allocate_messages.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/OpenMP/nvptx_allocate_messages.cpp?rev=356758&r1=356757&r2=356758&view=diff ============================================================================== --- cfe/trunk/test/OpenMP/nvptx_allocate_messages.cpp (original) +++ cfe/trunk/test/OpenMP/nvptx_allocate_messages.cpp Fri Mar 22 08:25:12 2019 @@ -1,17 +1,22 @@ // RUN: %clang_cc1 -verify -fopenmp -triple x86_64-apple-darwin10.6.0 -fopenmp-targets=nvptx64-nvidia-cuda -emit-llvm-bc -o %t-host.bc %s // RUN: %clang_cc1 -verify -DDEVICE -fopenmp -triple nvptx64-nvidia-cuda -fopenmp-targets=nvptx64-nvidia-cuda -fsyntax-only %s -fopenmp-is-device -fopenmp-host-ir-file-path %t-host.bc -#ifndef DEVICE +// RUN: %clang_cc1 -verify -DDEVICE -DREQUIRES -fopenmp -triple nvptx64-nvidia-cuda -fopenmp-targets=nvptx64-nvidia-cuda -fsyntax-only %s -fopenmp-is-device -fopenmp-host-ir-file-path %t-host.bc +#if !defined(DEVICE) || defined(REQUIRES) // expected-no-diagnostics #endif // DEVICE #ifndef HEADER #define HEADER +#if defined(REQUIRES) && defined(DEVICE) +#pragma omp requires dynamic_allocators +#endif // REQUIRES && DEVICE + int bar() { int res = 0; -#ifdef DEVICE +#if defined(DEVICE) && !defined(REQUIRES) // expected-error@+2 {{expected an 'allocator' clause inside of the target region; provide an 'allocator' clause or use 'requires' directive with the 'dynamic_allocators' clause}} -#endif // DEVICE +#endif // DEVICE && !REQUIRES #pragma omp allocate(res) return 0; } @@ -65,13 +70,13 @@ int main () { #pragma omp allocate(a) allocator(omp_thread_mem_alloc) a=2; double b = 3; -#ifdef DEVICE +#if defined(DEVICE) && !defined(REQUIRES) // expected-error@+2 {{expected an 'allocator' clause inside of the target region; provide an 'allocator' clause or use 'requires' directive with the 'dynamic_allocators' clause}} -#endif // DEVICE +#endif // DEVICE && !REQUIRES #pragma omp allocate(b) -#ifdef DEVICE +#if defined(DEVICE) && !defined(REQUIRES) // expected-note@+2 {{called by 'main'}} -#endif // DEVICE +#endif // DEVICE && !REQUIRES return (foo<int>() + bar()); } _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits