[clang] [Sema] Avoid repeated hash lookups (NFC) (PR #126674)
Kazu Hirata via cfe-commits
cfe-commits at lists.llvm.org
Mon Feb 10 22:05:23 PST 2025
https://github.com/kazutakahirata created https://github.com/llvm/llvm-project/pull/126674
None
>From 46fda036a1b2955b66421e3dfcba52f8391325b3 Mon Sep 17 00:00:00 2001
From: Kazu Hirata <kazu at google.com>
Date: Mon, 10 Feb 2025 08:02:15 -0800
Subject: [PATCH] [Sema] Avoid repeated hash lookups (NFC)
---
clang/lib/Sema/SemaOpenMP.cpp | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/clang/lib/Sema/SemaOpenMP.cpp b/clang/lib/Sema/SemaOpenMP.cpp
index 376995d624e2830..39ce65381a98ca1 100644
--- a/clang/lib/Sema/SemaOpenMP.cpp
+++ b/clang/lib/Sema/SemaOpenMP.cpp
@@ -5078,7 +5078,8 @@ static bool checkIfClauses(Sema &S, OpenMPDirectiveKind Kind,
// At most one if clause without a directive-name-modifier can appear on
// the directive.
OpenMPDirectiveKind CurNM = IC->getNameModifier();
- if (FoundNameModifiers[CurNM]) {
+ auto &FNM = FoundNameModifiers[CurNM];
+ if (FNM) {
S.Diag(C->getBeginLoc(), diag::err_omp_more_one_clause)
<< getOpenMPDirectiveName(Kind) << getOpenMPClauseName(OMPC_if)
<< (CurNM != OMPD_unknown) << getOpenMPDirectiveName(CurNM);
@@ -5087,7 +5088,7 @@ static bool checkIfClauses(Sema &S, OpenMPDirectiveKind Kind,
NameModifierLoc.push_back(IC->getNameModifierLoc());
++NamedModifiersNumber;
}
- FoundNameModifiers[CurNM] = IC;
+ FNM = IC;
if (CurNM == OMPD_unknown)
continue;
// Check if the specified name modifier is allowed for the current
@@ -6759,16 +6760,15 @@ SemaOpenMP::DeclGroupPtrTy SemaOpenMP::ActOnOpenMPDeclareSimdDirective(
->getCanonicalDecl() == CanonPVD) {
// OpenMP [2.8.1, simd construct, Restrictions]
// A list-item cannot appear in more than one aligned clause.
- if (AlignedArgs.count(CanonPVD) > 0) {
+ auto [It, Inserted] = AlignedArgs.try_emplace(CanonPVD, E);
+ if (!Inserted) {
Diag(E->getExprLoc(), diag::err_omp_used_in_clause_twice)
<< 1 << getOpenMPClauseName(OMPC_aligned)
<< E->getSourceRange();
- Diag(AlignedArgs[CanonPVD]->getExprLoc(),
- diag::note_omp_explicit_dsa)
+ Diag(It->second->getExprLoc(), diag::note_omp_explicit_dsa)
<< getOpenMPClauseName(OMPC_aligned);
continue;
}
- AlignedArgs[CanonPVD] = E;
QualType QTy = PVD->getType()
.getNonReferenceType()
.getUnqualifiedType()
More information about the cfe-commits
mailing list