r352530 - [analyzer] [RetainCountChecker] Support 'taggedRetain' and 'taggedRelease'
George Karpenkov via cfe-commits
cfe-commits at lists.llvm.org
Tue Jan 29 11:29:07 PST 2019
Author: george.karpenkov
Date: Tue Jan 29 11:29:07 2019
New Revision: 352530
URL: http://llvm.org/viewvc/llvm-project?rev=352530&view=rev
Log:
[analyzer] [RetainCountChecker] Support 'taggedRetain' and 'taggedRelease'
Differential Revision: https://reviews.llvm.org/D57211
Modified:
cfe/trunk/lib/Analysis/RetainSummaryManager.cpp
cfe/trunk/test/Analysis/os_object_base.h
cfe/trunk/test/Analysis/os_smart_ptr.h
cfe/trunk/test/Analysis/osobject-retain-release.cpp
Modified: cfe/trunk/lib/Analysis/RetainSummaryManager.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/RetainSummaryManager.cpp?rev=352530&r1=352529&r2=352530&view=diff
==============================================================================
--- cfe/trunk/lib/Analysis/RetainSummaryManager.cpp (original)
+++ cfe/trunk/lib/Analysis/RetainSummaryManager.cpp Tue Jan 29 11:29:07 2019
@@ -242,10 +242,10 @@ RetainSummaryManager::getSummaryForOSObj
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")
Modified: cfe/trunk/test/Analysis/os_object_base.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/os_object_base.h?rev=352530&r1=352529&r2=352530&view=diff
==============================================================================
--- cfe/trunk/test/Analysis/os_object_base.h (original)
+++ cfe/trunk/test/Analysis/os_object_base.h Tue Jan 29 11:29:07 2019
@@ -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(){};
};
Modified: cfe/trunk/test/Analysis/os_smart_ptr.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/os_smart_ptr.h?rev=352530&r1=352529&r2=352530&view=diff
==============================================================================
--- cfe/trunk/test/Analysis/os_smart_ptr.h (original)
+++ cfe/trunk/test/Analysis/os_smart_ptr.h Tue Jan 29 11:29:07 2019
@@ -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 */
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=352530&r1=352529&r2=352530&view=diff
==============================================================================
--- cfe/trunk/test/Analysis/osobject-retain-release.cpp (original)
+++ cfe/trunk/test/Analysis/osobject-retain-release.cpp Tue Jan 29 11:29:07 2019
@@ -593,12 +593,12 @@ void test_smart_ptr_uaf() {
// expected-note at -1{{Returning from constructor for 'smart_ptr<OSObject>'}}
// expected-note at os_smart_ptr.h:13{{Taking true branch}}
// expected-note at os_smart_ptr.h:14{{Calling 'smart_ptr::_retain'}}
- // expected-note at os_smart_ptr.h:72{{Reference count incremented. The object now has a +2 retain count}}
+ // expected-note at os_smart_ptr.h:71{{Reference count incremented. The object now has a +2 retain count}}
// expected-note at os_smart_ptr.h:14{{Returning from 'smart_ptr::_retain'}}
} // expected-note{{Calling '~smart_ptr'}}
// expected-note at os_smart_ptr.h:35{{Taking true branch}}
// expected-note at os_smart_ptr.h:36{{Calling 'smart_ptr::_release'}}
- // expected-note at os_smart_ptr.h:77{{Reference count decremented. The object now has a +1 retain count}}
+ // expected-note at os_smart_ptr.h:76{{Reference count decremented. The object now has a +1 retain count}}
// expected-note at os_smart_ptr.h:36{{Returning from 'smart_ptr::_release'}}
// expected-note at -5{{Returning from '~smart_ptr'}}
obj->release(); // expected-note{{Object released}}
@@ -613,12 +613,12 @@ void test_smart_ptr_leak() {
// expected-note at -1{{Returning from constructor for 'smart_ptr<OSObject>'}}
// expected-note at os_smart_ptr.h:13{{Taking true branch}}
// expected-note at os_smart_ptr.h:14{{Calling 'smart_ptr::_retain'}}
- // expected-note at os_smart_ptr.h:72{{Reference count incremented. The object now has a +2 retain count}}
+ // expected-note at os_smart_ptr.h:71{{Reference count incremented. The object now has a +2 retain count}}
// expected-note at os_smart_ptr.h:14{{Returning from 'smart_ptr::_retain'}}
} // expected-note{{Calling '~smart_ptr'}}
// expected-note at os_smart_ptr.h:35{{Taking true branch}}
// expected-note at os_smart_ptr.h:36{{Calling 'smart_ptr::_release'}}
- // expected-note at os_smart_ptr.h:77{{Reference count decremented. The object now has a +1 retain count}}
+ // expected-note at os_smart_ptr.h:76{{Reference count decremented. The object now has a +1 retain count}}
// expected-note at os_smart_ptr.h:36{{Returning from 'smart_ptr::_release'}}
// expected-note at -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_diagnos
// expected-warning at -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();
+}
+
More information about the cfe-commits
mailing list