[clang] Check the type of Objective-C++ instance variables in WebKit member variable checkers. (PR #127570)

Ryosuke Niwa via cfe-commits cfe-commits at lists.llvm.org
Tue Feb 18 20:01:25 PST 2025


================
@@ -87,6 +92,31 @@ class RawPtrRefMemberChecker
     }
   }
 
+  void visitObjCDecl(const ObjCContainerDecl *CD) const {
+    if (auto *ID = dyn_cast<ObjCInterfaceDecl>(CD)) {
+      for (auto *Ivar : ID->ivars())
+        visitIvarDecl(CD, Ivar);
+      return;
+    }
+    if (auto *ID = dyn_cast<ObjCImplementationDecl>(CD)) {
+      for (auto *Ivar : ID->ivars())
+        visitIvarDecl(CD, Ivar);
+      return;
+    }
+  }
+
+  void visitIvarDecl(const ObjCContainerDecl *CD,
+                     const ObjCIvarDecl *Ivar) const {
+    const Type *IvarType = Ivar->getType().getTypePtrOrNull();
+    if (!IvarType)
+      return;
+    if (auto *IvarCXXRD = IvarType->getPointeeCXXRecordDecl()) {
----------------
rniwa wrote:

I think so. If `IvarType` isn't a pointer to a C++ type, `getPointeeCXXRecordDecl` can return `nullptr`. e.g. Objective-C interface type.

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


More information about the cfe-commits mailing list