[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 07:09:01 PDT 2026


================
@@ -417,17 +417,32 @@ class ASTWalker : public RecursiveASTVisitor<ASTWalker> {
   }
 
   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(E->getSelectorStartLoc(), Method);
+      report(startLoc, Method);
     }
 
     // If it's a class message, report the interface/class as used
     if (E->getReceiverKind() == ObjCMessageExpr::Class) {
       if (auto *Interface = E->getReceiverInterface()) {
         report(E->getReceiverRange().getBegin(), Interface);
       }
+    } else {
+      if (auto *Interface = E->getReceiverInterface()) {
+        report(startLoc, Interface, RefType::Implicit);
+      }
+      QualType Type = E->getReceiverType();
+      if (const auto *ObjCPtr = Type->getAs<ObjCObjectPointerType>()) {
+        for (auto *Proto : ObjCPtr->quals()) {
+          report(startLoc, Proto, RefType::Implicit);
+        }
+      } else if (const auto *ObjCType = Type->getAs<ObjCObjectType>()) {
+        for (auto *Proto : ObjCType->quals()) {
----------------
nico wrote:

Does the loop in this branch have an effect?

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


More information about the cfe-commits mailing list