================
@@ -0,0 +1,75 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "FunctionPointerEqualityCheck.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::performance {
+
+void FunctionPointerEqualityCheck::registerMatchers(MatchFinder *Finder) {
+  const auto FunctionPointerType = hasCanonicalType(pointsTo(functionType()));
+
+  // Matching ptr == ptr, but not ptr == nullptr, or ptr == integer (function
+  // pointers to 1 and -1 are frequently used for "invalid" function pointers).
+  //
+  Finder->addMatcher(
+      binaryOperator(hasAnyOperatorName("==", "!="),
+                     hasLHS(hasType(FunctionPointerType)),
+                     hasRHS(hasType(FunctionPointerType)),
+                     unless(hasEitherOperand(ignoringParenCasts(
+                         anyOf(nullPointerConstant(), hasType(isInteger()))))),
+                     unless(isInTemplateInstantiation()))
----------------
ajordanr-google wrote:

I have added an unless clause to avoid matching static_assert, as well as some 
common unevaluated contexts.

https://github.com/llvm/llvm-project/pull/239430
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to