From: Alexey Bataev Date: Thu, 21 Mar 2019 19:05:07 +0000 (+0000) Subject: [OPENMP]Simplify the check for the predefined allocators, NFC. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=cd6203d849e5085306ca6ea9be7beeb189726b70;p=clang [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. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@356699 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaOpenMP.cpp b/lib/Sema/SemaOpenMP.cpp index 5d7ad8c5be..e54652650e 100644 --- a/lib/Sema/SemaOpenMP.cpp +++ b/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(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(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();