This revision was automatically updated to reflect the committed changes. Closed by commit rC352530: [analyzer] [RetainCountChecker] Support 'taggedRetain' and 'taggedRelease' (authored by george.karpenkov, committed by ). Herald added a subscriber: cfe-commits.
Changed prior to commit: https://reviews.llvm.org/D57211?vs=183449&id=184137#toc Repository: rC Clang CHANGES SINCE LAST ACTION https://reviews.llvm.org/D57211/new/ https://reviews.llvm.org/D57211 Files: lib/Analysis/RetainSummaryManager.cpp test/Analysis/os_object_base.h test/Analysis/os_smart_ptr.h test/Analysis/osobject-retain-release.cpp
Index: test/Analysis/os_smart_ptr.h =================================================================== --- test/Analysis/os_smart_ptr.h +++ test/Analysis/os_smart_ptr.h @@ -51,7 +51,6 @@ } T * operator->() const { - OSPTR_LOG("Dereference smart_ptr with %p\n", pointer); return pointer; } @@ -84,6 +83,6 @@ T *pointer; }; -} +} // namespace os #endif /* _OS_SMART_POINTER_H */ Index: test/Analysis/osobject-retain-release.cpp =================================================================== --- test/Analysis/osobject-retain-release.cpp +++ test/Analysis/osobject-retain-release.cpp @@ -593,12 +593,12 @@ // expected-note@-1{{Returning from constructor for 'smart_ptr<OSObject>'}} // expected-note@os_smart_ptr.h:13{{Taking true branch}} // expected-note@os_smart_ptr.h:14{{Calling 'smart_ptr::_retain'}} - // expected-note@os_smart_ptr.h:72{{Reference count incremented. The object now has a +2 retain count}} + // expected-note@os_smart_ptr.h:71{{Reference count incremented. The object now has a +2 retain count}} // expected-note@os_smart_ptr.h:14{{Returning from 'smart_ptr::_retain'}} } // expected-note{{Calling '~smart_ptr'}} // expected-note@os_smart_ptr.h:35{{Taking true branch}} // expected-note@os_smart_ptr.h:36{{Calling 'smart_ptr::_release'}} - // expected-note@os_smart_ptr.h:77{{Reference count decremented. The object now has a +1 retain count}} + // expected-note@os_smart_ptr.h:76{{Reference count decremented. The object now has a +1 retain count}} // expected-note@os_smart_ptr.h:36{{Returning from 'smart_ptr::_release'}} // expected-note@-5{{Returning from '~smart_ptr'}} obj->release(); // expected-note{{Object released}} @@ -613,12 +613,12 @@ // expected-note@-1{{Returning from constructor for 'smart_ptr<OSObject>'}} // expected-note@os_smart_ptr.h:13{{Taking true branch}} // expected-note@os_smart_ptr.h:14{{Calling 'smart_ptr::_retain'}} - // expected-note@os_smart_ptr.h:72{{Reference count incremented. The object now has a +2 retain count}} + // expected-note@os_smart_ptr.h:71{{Reference count incremented. The object now has a +2 retain count}} // expected-note@os_smart_ptr.h:14{{Returning from 'smart_ptr::_retain'}} } // expected-note{{Calling '~smart_ptr'}} // expected-note@os_smart_ptr.h:35{{Taking true branch}} // expected-note@os_smart_ptr.h:36{{Calling 'smart_ptr::_release'}} - // expected-note@os_smart_ptr.h:77{{Reference count decremented. The object now has a +1 retain count}} + // expected-note@os_smart_ptr.h:76{{Reference count decremented. The object now has a +1 retain count}} // expected-note@os_smart_ptr.h:36{{Returning from 'smart_ptr::_release'}} // expected-note@-5{{Returning from '~smart_ptr'}} } // expected-warning{{Potential leak of an object stored into 'obj'}} @@ -648,3 +648,15 @@ // expected-warning@-1{{'free' called on an object that may be referenced elsewhere}} } +void test_tagged_retain_no_leak() { + OSObject *obj = new OSObject; + obj->taggedRelease(); +} + +void test_tagged_retain_no_uaf() { + OSObject *obj = new OSObject; + obj->taggedRetain(); + obj->release(); + obj->release(); +} + Index: test/Analysis/os_object_base.h =================================================================== --- test/Analysis/os_object_base.h +++ test/Analysis/os_object_base.h @@ -27,6 +27,10 @@ virtual void retain() const; virtual void release() const; + + virtual void taggedRetain(const void * tag = nullptr) const; + virtual void taggedRelease(const void * tag = nullptr) const; + virtual void free(); virtual ~OSMetaClassBase(){}; }; Index: lib/Analysis/RetainSummaryManager.cpp =================================================================== --- lib/Analysis/RetainSummaryManager.cpp +++ lib/Analysis/RetainSummaryManager.cpp @@ -242,10 +242,10 @@ if (const auto *MD = dyn_cast<CXXMethodDecl>(FD)) { const CXXRecordDecl *Parent = MD->getParent(); if (TrackOSObjects && Parent && isOSObjectSubclass(Parent)) { - if (FName == "release") + if (FName == "release" || FName == "taggedRelease") return getOSSummaryReleaseRule(FD); - if (FName == "retain") + if (FName == "retain" || FName == "taggedRetain") return getOSSummaryRetainRule(FD); if (FName == "free")
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits