[PATCH] D55158: [analyzer] Rely on os_consumes_this attribute to signify that the method call consumes a reference for "this"

George Karpenkov via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Dec 6 14:10:31 PST 2018


This revision was automatically updated to reflect the committed changes.
Closed by commit rC348533: [analyzer] Rely on os_consumes_this attribute to signify that the method call… (authored by george.karpenkov, committed by ).
Herald added a subscriber: cfe-commits.

Changed prior to commit:
  https://reviews.llvm.org/D55158?vs=176234&id=177044#toc

Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D55158/new/

https://reviews.llvm.org/D55158

Files:
  include/clang/StaticAnalyzer/Core/RetainSummaryManager.h
  lib/StaticAnalyzer/Core/RetainSummaryManager.cpp
  test/Analysis/osobject-retain-release.cpp


Index: include/clang/StaticAnalyzer/Core/RetainSummaryManager.h
===================================================================
--- include/clang/StaticAnalyzer/Core/RetainSummaryManager.h
+++ include/clang/StaticAnalyzer/Core/RetainSummaryManager.h
@@ -369,8 +369,12 @@
   ///  This is only meaningful if the summary applies to an ObjCMessageExpr*.
   ArgEffect getReceiverEffect() const { return Receiver; }
 
+  /// \return the effect on the "this" receiver of the method call.
   ArgEffect getThisEffect() const { return This; }
 
+  /// Set the effect of the method on "this".
+  void setThisEffect(ArgEffect e) { This = e; }
+
   bool isNoop() const {
     return Ret == RetEffect::MakeNoRet() && Receiver == DoNothing
       && DefaultArgEffect == MayEscape && This == DoNothing
Index: test/Analysis/osobject-retain-release.cpp
===================================================================
--- test/Analysis/osobject-retain-release.cpp
+++ test/Analysis/osobject-retain-release.cpp
@@ -5,6 +5,7 @@
 #define OS_CONSUME __attribute__((os_consumed))
 #define OS_RETURNS_RETAINED __attribute__((os_returns_retained))
 #define OS_RETURNS_NOT_RETAINED __attribute__((os_returns_not_retained))
+#define OS_CONSUMES_THIS __attribute__((os_consumes_this))
 
 #define OSTypeID(type)   (type::metaClass)
 
@@ -49,6 +50,11 @@
 
   virtual void consumeReference(OS_CONSUME OSArray *other);
 
+  void putIntoArray(OSArray *array) OS_CONSUMES_THIS;
+
+  template <typename T>
+  void putIntoT(T *owner) OS_CONSUMES_THIS;
+
   static OSArray *generateArrayHasCode() {
     return new OSArray;
   }
@@ -112,6 +118,16 @@
   return 0;
 }
 
+void check_consumes_this(OSArray *owner) {
+  OSArray *arr = new OSArray;
+  arr->putIntoArray(owner);
+}
+
+void check_consumes_this_with_template(OSArray *owner) {
+  OSArray *arr = new OSArray;
+  arr->putIntoT(owner);
+}
+
 void check_free_no_error() {
   OSArray *arr = OSArray::withCapacity(10);
   arr->retain();
Index: lib/StaticAnalyzer/Core/RetainSummaryManager.cpp
===================================================================
--- lib/StaticAnalyzer/Core/RetainSummaryManager.cpp
+++ lib/StaticAnalyzer/Core/RetainSummaryManager.cpp
@@ -759,6 +759,9 @@
   QualType RetTy = FD->getReturnType();
   if (Optional<RetEffect> RetE = getRetEffectFromAnnotations(RetTy, FD))
     Template->setRetEffect(*RetE);
+
+  if (FD->hasAttr<OSConsumesThisAttr>())
+    Template->setThisEffect(DecRef);
 }
 
 void


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D55158.177044.patch
Type: text/x-patch
Size: 2453 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20181206/be0ff84d/attachment.bin>


More information about the cfe-commits mailing list