[clang] [Sema] Use llvm::erase_if (NFC) (PR #96068)

Kazu Hirata via cfe-commits cfe-commits at lists.llvm.org
Wed Jun 19 06:16:36 PDT 2024


https://github.com/kazutakahirata created https://github.com/llvm/llvm-project/pull/96068

While I am at it, I'm constructing SmallVector directly from ArrayRef.

>From 85dd4232f6510055a536bd5f7f0ce21a06295dfd Mon Sep 17 00:00:00 2001
From: Kazu Hirata <kazu at google.com>
Date: Wed, 19 Jun 2024 06:06:15 -0700
Subject: [PATCH] [Sema] Use llvm::erase_if (NFC)

While I am at it, I'm constructing SmallVector directly from ArrayRef.
---
 clang/lib/Sema/SemaOpenACC.cpp | 24 ++++++++----------------
 1 file changed, 8 insertions(+), 16 deletions(-)

diff --git a/clang/lib/Sema/SemaOpenACC.cpp b/clang/lib/Sema/SemaOpenACC.cpp
index 97586a037eee4..cf207be33175c 100644
--- a/clang/lib/Sema/SemaOpenACC.cpp
+++ b/clang/lib/Sema/SemaOpenACC.cpp
@@ -841,14 +841,10 @@ OpenACCClause *SemaOpenACCClauseVisitor::VisitAttachClause(
 
   // ActOnVar ensured that everything is a valid variable reference, but we
   // still have to make sure it is a pointer type.
-  llvm::SmallVector<Expr *> VarList{Clause.getVarList().begin(),
-                                    Clause.getVarList().end()};
-  VarList.erase(std::remove_if(VarList.begin(), VarList.end(),
-                               [&](Expr *E) {
-                                 return SemaRef.CheckVarIsPointerType(
-                                     OpenACCClauseKind::Attach, E);
-                               }),
-                VarList.end());
+  llvm::SmallVector<Expr *> VarList{Clause.getVarList()};
+  llvm::erase_if(VarList, [&](Expr *E) {
+    return SemaRef.CheckVarIsPointerType(OpenACCClauseKind::Attach, E);
+  });
   Clause.setVarListDetails(VarList,
                            /*IsReadOnly=*/false, /*IsZero=*/false);
   return OpenACCAttachClause::Create(Ctx, Clause.getBeginLoc(),
@@ -866,14 +862,10 @@ OpenACCClause *SemaOpenACCClauseVisitor::VisitDevicePtrClause(
 
   // ActOnVar ensured that everything is a valid variable reference, but we
   // still have to make sure it is a pointer type.
-  llvm::SmallVector<Expr *> VarList{Clause.getVarList().begin(),
-                                    Clause.getVarList().end()};
-  VarList.erase(std::remove_if(VarList.begin(), VarList.end(),
-                               [&](Expr *E) {
-                                 return SemaRef.CheckVarIsPointerType(
-                                     OpenACCClauseKind::DevicePtr, E);
-                               }),
-                VarList.end());
+  llvm::SmallVector<Expr *> VarList{Clause.getVarList()};
+  llvm::erase_if(VarList, [&](Expr *E) {
+    return SemaRef.CheckVarIsPointerType(OpenACCClauseKind::DevicePtr, E);
+  });
   Clause.setVarListDetails(VarList,
                            /*IsReadOnly=*/false, /*IsZero=*/false);
 



More information about the cfe-commits mailing list