From: George Karpenkov Date: Tue, 29 Jan 2019 19:29:07 +0000 (+0000) Subject: [analyzer] [RetainCountChecker] Support 'taggedRetain' and 'taggedRelease' X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=c60730eeebd5ed7caa1bb1b958f1ea0499dd829f;p=clang [analyzer] [RetainCountChecker] Support 'taggedRetain' and 'taggedRelease' Differential Revision: https://reviews.llvm.org/D57211 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@352530 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Analysis/RetainSummaryManager.cpp b/lib/Analysis/RetainSummaryManager.cpp index e43faf0f33..d8b3f818c2 100644 --- a/lib/Analysis/RetainSummaryManager.cpp +++ b/lib/Analysis/RetainSummaryManager.cpp @@ -242,10 +242,10 @@ RetainSummaryManager::getSummaryForOSObject(const FunctionDecl *FD, if (const auto *MD = dyn_cast(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") diff --git a/test/Analysis/os_object_base.h b/test/Analysis/os_object_base.h index 2c69c9acdc..cd59e4f0bc 100644 --- a/test/Analysis/os_object_base.h +++ b/test/Analysis/os_object_base.h @@ -27,6 +27,10 @@ struct OSMetaClassBase { 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(){}; }; diff --git a/test/Analysis/os_smart_ptr.h b/test/Analysis/os_smart_ptr.h index 8faf294f75..48a5ef3df0 100644 --- a/test/Analysis/os_smart_ptr.h +++ b/test/Analysis/os_smart_ptr.h @@ -51,7 +51,6 @@ struct smart_ptr { } T * operator->() const { - OSPTR_LOG("Dereference smart_ptr with %p\n", pointer); return pointer; } @@ -84,6 +83,6 @@ struct smart_ptr { T *pointer; }; -} +} // namespace os #endif /* _OS_SMART_POINTER_H */ diff --git a/test/Analysis/osobject-retain-release.cpp b/test/Analysis/osobject-retain-release.cpp index 467b643410..6cd7eb6d9a 100644 --- a/test/Analysis/osobject-retain-release.cpp +++ b/test/Analysis/osobject-retain-release.cpp @@ -593,12 +593,12 @@ void test_smart_ptr_uaf() { // expected-note@-1{{Returning from constructor for 'smart_ptr'}} // 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 @@ void test_smart_ptr_leak() { // expected-note@-1{{Returning from constructor for 'smart_ptr'}} // 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 @@ void test_free_on_escaped_object_diagnostics() { // 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(); +} +