[PATCH] D103081: [analyzer] RetainCountChecker: Disable reference counting for OSMetaClass.
Artem Dergachev via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu May 27 13:12:32 PDT 2021
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG50f17e9d3139: [analyzer] RetainCountChecker: Disable reference counting for OSMetaClass. (authored by georgi_igna, committed by dergachev.a).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D103081/new/
https://reviews.llvm.org/D103081
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
@@ -720,6 +720,16 @@
obj->release();
}
+void test_osmetaclass_release() {
+ const char *name = "no_name";
+ const OSMetaClass *meta = OSMetaClass::copyMetaClassWithName(name);
+ if (!meta) {
+ return;
+ } else {
+ meta->releaseMetaClass();
+ }
+}
+
OSObject *getRuleViolation() {
return new OSObject; // expected-warning{{Potential leak of an object of type 'OSObject'}}
// expected-note at -1{{Operator 'new' returns an OSObject of type 'OSObject' with a +1 retain count}}
Index: clang/test/Analysis/os_object_base.h
===================================================================
--- clang/test/Analysis/os_object_base.h
+++ clang/test/Analysis/os_object_base.h
@@ -67,6 +67,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
@@ -145,14 +145,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: D103081.348368.patch
Type: text/x-patch
Size: 2273 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210527/b6cc3993/attachment-0001.bin>
More information about the cfe-commits
mailing list