diff options
author | Alexey Bataev <a.bataev@hotmail.com> | 2019-03-19 20:33:44 +0000 |
---|---|---|
committer | Alexey Bataev <a.bataev@hotmail.com> | 2019-03-19 20:33:44 +0000 |
commit | 282555ad826818b10e85defbc56e2eb51782c941 (patch) | |
tree | 50bc9e09e8fd4abf70f9eb903b5bf55b5e998775 /clang/lib/Sema/SemaOpenMP.cpp | |
parent | a0feccdf5692389920206444aea6b34105554c7f (diff) | |
download | bcm5719-llvm-282555ad826818b10e85defbc56e2eb51782c941.tar.gz bcm5719-llvm-282555ad826818b10e85defbc56e2eb51782c941.zip |
[OPENMP]Warn if the different allocator is used for the variable.
If the allocator was specified for the variable and next one is found
with the different allocator, the warning is emitted, and the allocator
is ignored.
llvm-svn: 356513
Diffstat (limited to 'clang/lib/Sema/SemaOpenMP.cpp')
-rw-r--r-- | clang/lib/Sema/SemaOpenMP.cpp | 71 |
1 files changed, 66 insertions, 5 deletions
diff --git a/clang/lib/Sema/SemaOpenMP.cpp b/clang/lib/Sema/SemaOpenMP.cpp index 794ca2bee70..8b35371e0e3 100644 --- a/clang/lib/Sema/SemaOpenMP.cpp +++ b/clang/lib/Sema/SemaOpenMP.cpp @@ -2216,6 +2216,61 @@ Sema::DeclGroupPtrTy Sema::ActOnOpenMPAllocateDirective( if (isa<ParmVarDecl>(VD)) continue; + // If the used several times in the allocate directive, the same allocator + // must be used. + if (VD->hasAttr<OMPAllocateDeclAttr>()) { + const auto *A = VD->getAttr<OMPAllocateDeclAttr>(); + const Expr *PrevAllocator = A->getAllocator(); + bool AllocatorsMatch = false; + if (Allocator && PrevAllocator) { + const Expr *AE = Allocator->IgnoreParenImpCasts(); + const Expr *PAE = PrevAllocator->IgnoreParenImpCasts(); + llvm::FoldingSetNodeID AEId, PAEId; + AE->Profile(AEId, Context, /*Canonical=*/true); + PAE->Profile(PAEId, Context, /*Canonical=*/true); + AllocatorsMatch = AEId == PAEId; + } else if (!Allocator && !PrevAllocator) { + AllocatorsMatch = true; + } else { + const Expr *AE = Allocator ? Allocator : PrevAllocator; + // In this case the specified allocator must be the default one. + AE = AE->IgnoreParenImpCasts(); + if (const auto *DRE = dyn_cast<DeclRefExpr>(AE)) { + DeclarationName DN = DRE->getDecl()->getDeclName(); + AllocatorsMatch = + DN.isIdentifier() && + DN.getAsIdentifierInfo()->isStr("omp_default_mem_alloc"); + } + } + if (!AllocatorsMatch) { + SmallString<256> AllocatorBuffer; + llvm::raw_svector_ostream AllocatorStream(AllocatorBuffer); + if (Allocator) + Allocator->printPretty(AllocatorStream, nullptr, getPrintingPolicy()); + SmallString<256> PrevAllocatorBuffer; + llvm::raw_svector_ostream PrevAllocatorStream(PrevAllocatorBuffer); + if (PrevAllocator) + PrevAllocator->printPretty(PrevAllocatorStream, nullptr, + getPrintingPolicy()); + + SourceLocation AllocatorLoc = + Allocator ? Allocator->getExprLoc() : RefExpr->getExprLoc(); + SourceRange AllocatorRange = + Allocator ? Allocator->getSourceRange() : RefExpr->getSourceRange(); + SourceLocation PrevAllocatorLoc = + PrevAllocator ? PrevAllocator->getExprLoc() : A->getLocation(); + SourceRange PrevAllocatorRange = + PrevAllocator ? PrevAllocator->getSourceRange() : A->getRange(); + Diag(AllocatorLoc, diag::warn_omp_used_different_allocator) + << (Allocator ? 1 : 0) << AllocatorStream.str() + << (PrevAllocator ? 1 : 0) << PrevAllocatorStream.str() + << AllocatorRange; + Diag(PrevAllocatorLoc, diag::note_omp_previous_allocator) + << PrevAllocatorRange; + continue; + } + } + // OpenMP, 2.11.3 allocate Directive, Restrictions, C / C++ // If a list item has a static storage type, the allocator expression in the // allocator clause must be a constant expression that evaluates to one of @@ -2254,11 +2309,17 @@ Sema::DeclGroupPtrTy Sema::ActOnOpenMPAllocateDirective( } Vars.push_back(RefExpr); - Attr *A = OMPAllocateDeclAttr::CreateImplicit(Context, Allocator, - DE->getSourceRange()); - VD->addAttr(A); - if (ASTMutationListener *ML = Context.getASTMutationListener()) - ML->DeclarationMarkedOpenMPAllocate(VD, A); + if ((!Allocator || (Allocator && !Allocator->isTypeDependent() && + !Allocator->isValueDependent() && + !Allocator->isInstantiationDependent() && + !Allocator->containsUnexpandedParameterPack())) && + !VD->hasAttr<OMPAllocateDeclAttr>()) { + Attr *A = OMPAllocateDeclAttr::CreateImplicit(Context, Allocator, + DE->getSourceRange()); + VD->addAttr(A); + if (ASTMutationListener *ML = Context.getASTMutationListener()) + ML->DeclarationMarkedOpenMPAllocate(VD, A); + } } if (Vars.empty()) return nullptr; |