[clang-tools-extra] [include-cleaner] Ensure receiver headers are kept when accessing ObjC properties (PR #212633)

Nico Weber via cfe-commits cfe-commits at lists.llvm.org
Sat Aug 1 06:27:48 PDT 2026


================
@@ -458,6 +458,35 @@ class ASTWalker : public RecursiveASTVisitor<ASTWalker> {
       if (auto *Setter = E->getImplicitPropertySetter())
         report(E->getLocation(), Setter);
     }
+
+    // Report the receiver to ensure its declaring header is kept.
+    if (E->isObjectReceiver()) {
+      QualType Type = E->getBase()->IgnoreImpCasts()->getType();
+      if (const auto *ObjCPtr = Type->getAs<ObjCObjectPointerType>()) {
+        if (auto *Interface = ObjCPtr->getInterfaceDecl()) {
+          report(E->getLocation(), Interface, RefType::Implicit);
+        }
+        for (const auto *Proto : ObjCPtr->quals()) {
+          report(E->getLocation(), const_cast<ObjCProtocolDecl *>(Proto),
+                 RefType::Implicit);
+        }
+      }
+    } else if (E->isClassReceiver()) {
----------------
nico wrote:

Do any of the tests fail if it's removed?

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


More information about the cfe-commits mailing list