summaryrefslogtreecommitdiffstats
path: root/clang/lib/Sema/SemaOpenMP.cpp
diff options
context:
space:
mode:
authorAlexey Bataev <a.bataev@hotmail.com>2019-03-28 19:15:36 +0000
committerAlexey Bataev <a.bataev@hotmail.com>2019-03-28 19:15:36 +0000
commit471171c4c94ced4b0421049d6949c13bdce256f7 (patch)
tree87f2b2613af4be365f5667dab1e5d8321747f8f7 /clang/lib/Sema/SemaOpenMP.cpp
parentceb3de5d25668f78b27f8d7e9f1d541eb6cd4ce2 (diff)
downloadbcm5719-llvm-471171c4c94ced4b0421049d6949c13bdce256f7.tar.gz
bcm5719-llvm-471171c4c94ced4b0421049d6949c13bdce256f7.zip
[OPENMP]Add check for undefined behavior with thread allocators on
target and task-based directives. According to OpenMP 5.0, 2.11.4 allocate Clause, Restrictions, For task, taskloop or target directives, allocation requests to memory allocators with the trait access set to thread result in unspecified behavior. Patch introduces a check for omp_thread_mem_alloc predefined allocator on target- and trask-based directives. llvm-svn: 357205
Diffstat (limited to 'clang/lib/Sema/SemaOpenMP.cpp')
-rw-r--r--clang/lib/Sema/SemaOpenMP.cpp33
1 files changed, 33 insertions, 0 deletions
diff --git a/clang/lib/Sema/SemaOpenMP.cpp b/clang/lib/Sema/SemaOpenMP.cpp
index b4c8a644a39..0971277de75 100644
--- a/clang/lib/Sema/SemaOpenMP.cpp
+++ b/clang/lib/Sema/SemaOpenMP.cpp
@@ -3640,6 +3640,33 @@ static bool checkIfClauses(Sema &S, OpenMPDirectiveKind Kind,
return ErrorFound;
}
+static bool checkAllocateClauses(Sema &S, DSAStackTy *Stack,
+ ArrayRef<OMPClause *> Clauses) {
+ assert(!S.CurContext->isDependentContext() &&
+ "Expected non-dependent context.");
+ bool IsCorrect = true;
+ auto AllocateRange =
+ llvm::make_filter_range(Clauses, OMPAllocateClause::classof);
+ for (OMPClause *C : AllocateRange) {
+ auto *AC = cast<OMPAllocateClause>(C);
+ OMPAllocateDeclAttr::AllocatorTypeTy AllocatorKind =
+ getAllocatorKind(S, Stack, AC->getAllocator());
+ // OpenMP, 2.11.4 allocate Clause, Restrictions.
+ // For task, taskloop or target directives, allocation requests to memory
+ // allocators with the trait access set to thread result in unspecified
+ // behavior.
+ if (AllocatorKind == OMPAllocateDeclAttr::OMPThreadMemAlloc &&
+ (isOpenMPTaskingDirective(Stack->getCurrentDirective()) ||
+ isOpenMPTargetExecutionDirective(Stack->getCurrentDirective()))) {
+ S.Diag(AC->getAllocator()->getExprLoc(),
+ diag::warn_omp_allocate_thread_on_task_target_directive)
+ << getOpenMPDirectiveName(Stack->getCurrentDirective());
+ continue;
+ }
+ }
+ return !IsCorrect;
+}
+
StmtResult Sema::ActOnOpenMPExecutableDirective(
OpenMPDirectiveKind Kind, const DeclarationNameInfo &DirName,
OpenMPDirectiveKind CancelRegion, ArrayRef<OMPClause *> Clauses,
@@ -3973,6 +4000,12 @@ StmtResult Sema::ActOnOpenMPExecutableDirective(
ErrorFound = checkIfClauses(*this, Kind, Clauses, AllowedNameModifiers) ||
ErrorFound;
+ // Check allocate clauses.
+ if (!CurContext->isDependentContext()) {
+ ErrorFound = checkAllocateClauses(*this, DSAStack, ClausesWithImplicit) ||
+ ErrorFound;
+ }
+
if (ErrorFound)
return StmtError();
OpenPOWER on IntegriCloud