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"; }
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"; }
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits