@@ -229,29 +229,36 @@ RetainSummaryManager::isKnownSmartPointer(QualType QT) {
229229const RetainSummary *
230230RetainSummaryManager::getSummaryForOSObject (const FunctionDecl *FD,
231231 StringRef FName, QualType RetTy) {
232+ assert (TrackOSObjects &&
233+ " Requesting a summary for an OSObject but OSObjects are not tracked" );
234+
232235 if (RetTy->isPointerType ()) {
233236 const CXXRecordDecl *PD = RetTy->getPointeeType ()->getAsCXXRecordDecl ();
234237 if (PD && isOSObjectSubclass (PD)) {
235- if (const IdentifierInfo *II = FD->getIdentifier ()) {
236- StringRef FuncName = II->getName ();
237- if (isOSObjectDynamicCast (FuncName) || isOSObjectThisCast (FuncName))
238- return getDefaultSummary ();
239-
240- // All objects returned with functions *not* starting with
241- // get, or iterators, are returned at +1.
242- if ((!FuncName.startswith (" get" ) && !FuncName.startswith (" Get" )) ||
243- isOSIteratorSubclass (PD)) {
244- return getOSSummaryCreateRule (FD);
245- } else {
246- return getOSSummaryGetRule (FD);
247- }
238+ if (isOSObjectDynamicCast (FName) || isOSObjectThisCast (FName))
239+ return getDefaultSummary ();
240+
241+ // TODO: Add support for the slightly common *Matching(table) idiom.
242+ // Cf. IOService::nameMatching() etc. - these function have an unusual
243+ // contract of returning at +0 or +1 depending on their last argument.
244+ if (FName.endswith (" Matching" )) {
245+ return getPersistentStopSummary ();
246+ }
247+
248+ // All objects returned with functions *not* starting with 'get',
249+ // or iterators, are returned at +1.
250+ if ((!FName.startswith (" get" ) && !FName.startswith (" Get" )) ||
251+ isOSIteratorSubclass (PD)) {
252+ return getOSSummaryCreateRule (FD);
253+ } else {
254+ return getOSSummaryGetRule (FD);
248255 }
249256 }
250257 }
251258
252259 if (const auto *MD = dyn_cast<CXXMethodDecl>(FD)) {
253260 const CXXRecordDecl *Parent = MD->getParent ();
254- if (TrackOSObjects && Parent && isOSObjectSubclass (Parent)) {
261+ if (Parent && isOSObjectSubclass (Parent)) {
255262 if (FName == " release" || FName == " taggedRelease" )
256263 return getOSSummaryReleaseRule (FD);
257264
0 commit comments