diff options
| author | Alexey Bataev <a.bataev@hotmail.com> | 2019-03-21 19:05:07 +0000 |
|---|---|---|
| committer | Alexey Bataev <a.bataev@hotmail.com> | 2019-03-21 19:05:07 +0000 |
| commit | 441510ef54b94e1ef5df1486e9f84a42cab1ace5 (patch) | |
| tree | 1273ac21e82917b5cf3ea35dd919b3b0e46c7726 /clang | |
| parent | e5e77815b48a11ec9737c0722a365190696dccf9 (diff) | |
| download | bcm5719-llvm-441510ef54b94e1ef5df1486e9f84a42cab1ace5.tar.gz bcm5719-llvm-441510ef54b94e1ef5df1486e9f84a42cab1ace5.zip | |
[OPENMP]Simplify the check for the predefined allocators, NFC.
Previously implemented check required the reevaluation of the already
evaluated predefined allocator kind for the global variables. Patch
simplifies this evaluation and removes extra code.
llvm-svn: 356699
Diffstat (limited to 'clang')
| -rw-r--r-- | clang/lib/Sema/SemaOpenMP.cpp | 46 |
1 files changed, 7 insertions, 39 deletions
diff --git a/clang/lib/Sema/SemaOpenMP.cpp b/clang/lib/Sema/SemaOpenMP.cpp index 5d7ad8c5be6..e54652650ed 100644 --- a/clang/lib/Sema/SemaOpenMP.cpp +++ b/clang/lib/Sema/SemaOpenMP.cpp @@ -2219,35 +2219,22 @@ getAllocatorKind(Sema &S, DSAStackTy *Stack, Expr *Allocator) { return OMPAllocateDeclAttr::OMPDefaultMemAlloc; if (Allocator->isTypeDependent() || Allocator->isValueDependent() || Allocator->isInstantiationDependent() || - Allocator->containsUnexpandedParameterPack() || - !Allocator->isEvaluatable(S.getASTContext())) + Allocator->containsUnexpandedParameterPack()) return OMPAllocateDeclAttr::OMPUserDefinedMemAlloc; - bool Suppress = S.getDiagnostics().getSuppressAllDiagnostics(); - S.getDiagnostics().setSuppressAllDiagnostics(/*Val=*/true); auto AllocatorKindRes = OMPAllocateDeclAttr::OMPUserDefinedMemAlloc; for (int I = OMPAllocateDeclAttr::OMPDefaultMemAlloc; I < OMPAllocateDeclAttr::OMPUserDefinedMemAlloc; ++I) { auto AllocatorKind = static_cast<OMPAllocateDeclAttr::AllocatorTypeTy>(I); Expr *DefAllocator = Stack->getAllocator(AllocatorKind); - // Compare allocator with the predefined allocator and if true - return - // predefined allocator kind. - ExprResult DefAllocRes = S.DefaultLvalueConversion(DefAllocator); - ExprResult AllocRes = S.DefaultLvalueConversion(Allocator); - ExprResult CompareRes = S.CreateBuiltinBinOp( - Allocator->getExprLoc(), BO_EQ, DefAllocRes.get(), AllocRes.get()); - if (!CompareRes.isUsable()) - continue; - bool Result; - if (!CompareRes.get()->EvaluateAsBooleanCondition(Result, - S.getASTContext())) - continue; - if (Result) { + const Expr *AE = Allocator->IgnoreParenImpCasts(); + llvm::FoldingSetNodeID AEId, DAEId; + AE->Profile(AEId, S.getASTContext(), /*Canonical=*/true); + DefAllocator->Profile(DAEId, S.getASTContext(), /*Canonical=*/true); + if (AEId == DAEId) { AllocatorKindRes = AllocatorKind; break; } - } - S.getDiagnostics().setSuppressAllDiagnostics(Suppress); return AllocatorKindRes; } @@ -2325,26 +2312,7 @@ Sema::DeclGroupPtrTy Sema::ActOnOpenMPAllocateDirective( // allocator clause must be a constant expression that evaluates to one of // the predefined memory allocator values. if (Allocator && VD->hasGlobalStorage()) { - bool IsPredefinedAllocator = false; - if (const auto *DRE = - dyn_cast<DeclRefExpr>(Allocator->IgnoreParenImpCasts())) { - if (DRE->getType().isConstant(getASTContext())) { - DeclarationName DN = DRE->getDecl()->getDeclName(); - if (DN.isIdentifier()) { - StringRef PredefinedAllocators[] = { - "omp_default_mem_alloc", "omp_large_cap_mem_alloc", - "omp_const_mem_alloc", "omp_high_bw_mem_alloc", - "omp_low_lat_mem_alloc", "omp_cgroup_mem_alloc", - "omp_pteam_mem_alloc", "omp_thread_mem_alloc", - }; - IsPredefinedAllocator = - llvm::any_of(PredefinedAllocators, [&DN](StringRef S) { - return DN.getAsIdentifierInfo()->isStr(S); - }); - } - } - } - if (!IsPredefinedAllocator) { + if (AllocatorKind == OMPAllocateDeclAttr::OMPUserDefinedMemAlloc) { Diag(Allocator->getExprLoc(), diag::err_omp_expected_predefined_allocator) << Allocator->getSourceRange(); |

