Skip to content

Conversation

@kazutakahirata
Copy link
Contributor

The code in question uses llvm::all_of and llvm::identity to see if
every pointer is nonnull:

Ptr1 && Ptr2 && Ptr3 && ...

This patch simplifies the expression by checking for the absence of
nullptr with !llvm::is_contained.

The code in question uses llvm::all_of and llvm::identity to see if
every pointer is nonnull:

  Ptr1 && Ptr2 && Ptr3 && ...

This patch simplifies the expression by checking for the absence of
nullptr with !llvm::is_contained.
@llvmbot llvmbot added clang Clang issues not falling into any other category clang:frontend Language frontend issues, e.g. anything involving "Sema" labels Sep 12, 2025
@llvmbot
Copy link
Member

llvmbot commented Sep 12, 2025

@llvm/pr-subscribers-clang

Author: Kazu Hirata (kazutakahirata)

Changes

The code in question uses llvm::all_of and llvm::identity to see if
every pointer is nonnull:

Ptr1 && Ptr2 && Ptr3 && ...

This patch simplifies the expression by checking for the absence of
nullptr with !llvm::is_contained.


Full diff: https://github.com/llvm/llvm-project/pull/158213.diff

1 Files Affected:

  • (modified) clang/lib/Sema/HeuristicResolver.cpp (+1-2)
diff --git a/clang/lib/Sema/HeuristicResolver.cpp b/clang/lib/Sema/HeuristicResolver.cpp
index 6d79f3feeaace..29840a430292e 100644
--- a/clang/lib/Sema/HeuristicResolver.cpp
+++ b/clang/lib/Sema/HeuristicResolver.cpp
@@ -13,7 +13,6 @@
 #include "clang/AST/ExprCXX.h"
 #include "clang/AST/TemplateBase.h"
 #include "clang/AST/Type.h"
-#include "llvm/ADT/identity.h"
 
 namespace clang {
 
@@ -562,7 +561,7 @@ HeuristicResolverImpl::getFunctionProtoTypeLoc(const Expr *Fn) {
     // In some edge cases the AST can contain a "trivial" FunctionProtoTypeLoc
     // which has null parameters. Avoid these as they don't contain useful
     // information.
-    if (llvm::all_of(F.getParams(), llvm::identity<ParmVarDecl *>()))
+    if (!llvm::is_contained(F.getParams(), nullptr))
       return F;
   }
 

@kazutakahirata kazutakahirata merged commit 0d7f66d into llvm:main Sep 12, 2025
12 checks passed
@kazutakahirata kazutakahirata deleted the cleanup_20250911_is_contained_clang_Sema branch September 12, 2025 14:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

clang:frontend Language frontend issues, e.g. anything involving "Sema" clang Clang issues not falling into any other category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants