]> granicus.if.org Git - clang/commitdiff
[analyzer] [RetainCountChecker] Support 'taggedRetain' and 'taggedRelease'
authorGeorge Karpenkov <ekarpenkov@apple.com>
Tue, 29 Jan 2019 19:29:07 +0000 (19:29 +0000)
committerGeorge Karpenkov <ekarpenkov@apple.com>
Tue, 29 Jan 2019 19:29:07 +0000 (19:29 +0000)
Differential Revision: https://reviews.llvm.org/D57211

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@352530 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Analysis/RetainSummaryManager.cpp
test/Analysis/os_object_base.h
test/Analysis/os_smart_ptr.h
test/Analysis/osobject-retain-release.cpp

index e43faf0f3307526fc5759740f83cd8c6cbcd2e28..d8b3f818c2467170d4a7cc9b7755ceb8eae2d548 100644 (file)
@@ -242,10 +242,10 @@ RetainSummaryManager::getSummaryForOSObject(const FunctionDecl *FD,
   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")
index 2c69c9acdcfa1230424e3f46d071e77f2508d005..cd59e4f0bca09829b9c65f85164a24e756988441 100644 (file)
@@ -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(){};
 };
index 8faf294f75187079b354f29d811dd38257783223..48a5ef3df042f49cb84b0c49b4db32b704d6f782 100644 (file)
@@ -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 */
index 467b6434100a9b524b9a3abde777b9cd5b33497e..6cd7eb6d9af31cc194858aedcc0b632903675530 100644 (file)
@@ -593,12 +593,12 @@ void test_smart_ptr_uaf() {
    // 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 @@ void test_smart_ptr_leak() {
    // 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 @@ 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();
+}
+