r345747 - [analyzer] Re-add custom OSIterator rule for RetainCountChecker
George Karpenkov via cfe-commits
cfe-commits at lists.llvm.org
Wed Oct 31 10:38:46 PDT 2018
Author: george.karpenkov
Date: Wed Oct 31 10:38:46 2018
New Revision: 345747
URL: http://llvm.org/viewvc/llvm-project?rev=345747&view=rev
Log:
[analyzer] Re-add custom OSIterator rule for RetainCountChecker
Turns out the rule is quite ubiquitous.
Revert of https://reviews.llvm.org/D53628
Modified:
cfe/trunk/lib/StaticAnalyzer/Core/RetainSummaryManager.cpp
cfe/trunk/test/Analysis/osobject-retain-release.cpp
Modified: cfe/trunk/lib/StaticAnalyzer/Core/RetainSummaryManager.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/RetainSummaryManager.cpp?rev=345747&r1=345746&r2=345747&view=diff
==============================================================================
--- cfe/trunk/lib/StaticAnalyzer/Core/RetainSummaryManager.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/RetainSummaryManager.cpp Wed Oct 31 10:38:46 2018
@@ -69,6 +69,10 @@ static bool isOSObjectDynamicCast(String
return S == "safeMetaCast";
}
+static bool isOSIteratorSubclass(const Decl *D) {
+ return isSubclass(D, "OSIterator");
+}
+
static bool hasRCAnnotation(const Decl *D, StringRef rcAnnotation) {
for (const auto *Ann : D->specific_attrs<AnnotateAttr>()) {
if (Ann->getAnnotation() == rcAnnotation)
@@ -235,11 +239,12 @@ RetainSummaryManager::generateSummary(co
if (isOSObjectDynamicCast(II->getName()))
return getDefaultSummary();
- // All objects returned with functions starting with "get" are getters.
- if (II->getName().startswith("get")) {
- return getOSSummaryGetRule(FD);
- } else {
+ // All objects returned with functions *not* starting with
+ // get, or iterators, are returned at +1.
+ if (!II->getName().startswith("get") || isOSIteratorSubclass(PD)) {
return getOSSummaryCreateRule(FD);
+ } else {
+ return getOSSummaryGetRule(FD);
}
}
}
Modified: cfe/trunk/test/Analysis/osobject-retain-release.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/osobject-retain-release.cpp?rev=345747&r1=345746&r2=345747&view=diff
==============================================================================
--- cfe/trunk/test/Analysis/osobject-retain-release.cpp (original)
+++ cfe/trunk/test/Analysis/osobject-retain-release.cpp Wed Oct 31 10:38:46 2018
@@ -23,6 +23,9 @@ struct OSObject {
static const OSMetaClass * const metaClass;
};
+struct OSIterator : public OSObject {
+};
+
struct OSArray : public OSObject {
unsigned int getCount();
@@ -33,6 +36,8 @@ struct OSArray : public OSObject {
return nullptr;
}
+ OSIterator * getIterator();
+
static OS_RETURNS_NOT_RETAINED OSArray *MaskedGetter();
static OS_RETURNS_RETAINED OSArray *getOoopsActuallyCreate();
@@ -49,6 +54,11 @@ struct OSMetaClassBase {
static OSObject *safeMetaCast(const OSObject *inst, const OSMetaClass *meta);
};
+void check_custom_iterator_rule(OSArray *arr) {
+ OSIterator *it = arr->getIterator();
+ it->release();
+}
+
void check_no_invalidation() {
OSArray *arr = OSArray::withCapacity(10); // expected-note{{Call to function 'withCapacity' returns an OSObject of type struct OSArray * with a +1 retain count}}
OtherStruct::doNothingToArray(arr);
More information about the cfe-commits
mailing list