[PATCH] D102879: rdar://77307290 (Disable retain-count tracking for references to OSMetaClass)

Georgeta Igna via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu May 20 15:05:58 PDT 2021


georgi_igna created this revision.
georgi_igna requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D102879

Files:
  clang/lib/Analysis/RetainSummaryManager.cpp
  clang/test/Analysis/os_object_base.h
  clang/test/Analysis/osobject-retain-release.cpp


Index: clang/test/Analysis/osobject-retain-release.cpp
===================================================================
--- clang/test/Analysis/osobject-retain-release.cpp
+++ clang/test/Analysis/osobject-retain-release.cpp
@@ -721,6 +721,16 @@
   obj->release();
 }
 
+void test_osmetaclass_release(){
+    const char *name = "no_name";
+    const OSMetaClass *meta = OSMetaClass::copyMetaClassWithName(name);
+    if (!meta) {
+        return;
+    } else {
+        meta->releaseMetaClass();
+    }
+}
+
 class SampleClass {
 public:
   OSObjectPtr field;
Index: clang/test/Analysis/os_object_base.h
===================================================================
--- clang/test/Analysis/os_object_base.h
+++ clang/test/Analysis/os_object_base.h
@@ -68,6 +68,8 @@
 struct OSMetaClass : public OSMetaClassBase {
   virtual OSObject * alloc() const;
   static OSObject * allocClassWithName(const char * name);
+  static const OSMetaClass * copyMetaClassWithName(const char * name);
+  void releaseMetaClass() const;
   virtual ~OSMetaClass(){}
 };
 
Index: clang/lib/Analysis/RetainSummaryManager.cpp
===================================================================
--- clang/lib/Analysis/RetainSummaryManager.cpp
+++ clang/lib/Analysis/RetainSummaryManager.cpp
@@ -146,14 +146,20 @@
   return !(match(SubclassM, *D, D->getASTContext()).empty());
 }
 
-static bool isOSObjectSubclass(const Decl *D) {
-  return D && isSubclass(D, "OSMetaClassBase");
+static bool isExactClass(const Decl *D, StringRef ClassName) {
+  using namespace ast_matchers;
+  DeclarationMatcher sameClassM =
+      cxxRecordDecl(hasName(std::string(ClassName)));
+  return !(match(sameClassM, *D, D->getASTContext()).empty());
 }
 
-static bool isOSObjectDynamicCast(StringRef S) {
-  return S == "safeMetaCast";
+static bool isOSObjectSubclass(const Decl *D) {
+  return D && isSubclass(D, "OSMetaClassBase") &&
+         !isExactClass(D, "OSMetaClass");
 }
 
+static bool isOSObjectDynamicCast(StringRef S) { return S == "safeMetaCast"; }
+
 static bool isOSObjectRequiredCast(StringRef S) {
   return S == "requiredMetaCast";
 }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D102879.346868.patch
Type: text/x-patch
Size: 2117 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210520/5a49310f/attachment.bin>


More information about the cfe-commits mailing list