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)
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);
}
}
}
static const OSMetaClass * const metaClass;
};
+struct OSIterator : public OSObject {
+};
+
struct OSArray : public OSObject {
unsigned int getCount();
return nullptr;
}
+ OSIterator * getIterator();
+
static OS_RETURNS_NOT_RETAINED OSArray *MaskedGetter();
static OS_RETURNS_RETAINED OSArray *getOoopsActuallyCreate();
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);