[clang-tools-extra] [include-cleaner] Avoid reporting redundant ObjC method and property decls (PR #216857)

Nico Weber via cfe-commits cfe-commits at lists.llvm.org
Mon Aug 17 19:00:52 PDT 2026


================
@@ -460,29 +460,80 @@ class ASTWalker : public RecursiveASTVisitor<ASTWalker> {
     return true;
   }
 
-  bool VisitObjCMessageExpr(ObjCMessageExpr *E) {
-    auto StartLoc = E->getSelectorStartLoc();
-    // Identify the selector and the method declaration
-    if (auto *Method = E->getMethodDecl()) {
-      // Report the method as a used symbol
-      report(StartLoc, Method);
+  /// Determines whether a protocol is already covered by the receiver's type,
+  /// either through adopted protocol qualifiers (e.g. `id<Proto>` or an
+  /// inheriting sub-protocol) or through class conformance on the receiver
+  /// interface (e.g. `MyClass <Proto>`).
+  bool IsProtocolCoveredByReceiver(ObjCProtocolDecl *Proto,
+                                   const ObjCObjectPointerType *ObjCPtr,
+                                   ObjCInterfaceDecl *IFace) {
+    if (ObjCPtr) {
+      ASTContext &Ctx = Proto->getASTContext();
+      for (auto *ReceiverProto : ObjCPtr->quals())
+        if (Ctx.ProtocolCompatibleWithProtocol(Proto, ReceiverProto))
+          return true;
     }
+    return IFace && IFace->ClassImplementsProtocol(Proto, true);
----------------
nico wrote:

Please insert a `/*lookupCategory=*/` in front of the `true` (without a space). Else the `true` is pretty mysterious.

https://github.com/llvm/llvm-project/pull/216857


More information about the cfe-commits mailing list