r348533 - [analyzer] Rely on os_consumes_this attribute to signify that the method call consumes a reference for "this"
George Karpenkov via cfe-commits
cfe-commits at lists.llvm.org
Thu Dec 6 14:07:12 PST 2018
Author: george.karpenkov
Date: Thu Dec 6 14:07:12 2018
New Revision: 348533
URL: http://llvm.org/viewvc/llvm-project?rev=348533&view=rev
Log:
[analyzer] Rely on os_consumes_this attribute to signify that the method call consumes a reference for "this"
Differential Revision: https://reviews.llvm.org/D55158
Modified:
cfe/trunk/include/clang/StaticAnalyzer/Core/RetainSummaryManager.h
cfe/trunk/lib/StaticAnalyzer/Core/RetainSummaryManager.cpp
cfe/trunk/test/Analysis/osobject-retain-release.cpp
Modified: cfe/trunk/include/clang/StaticAnalyzer/Core/RetainSummaryManager.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/StaticAnalyzer/Core/RetainSummaryManager.h?rev=348533&r1=348532&r2=348533&view=diff
==============================================================================
--- cfe/trunk/include/clang/StaticAnalyzer/Core/RetainSummaryManager.h (original)
+++ cfe/trunk/include/clang/StaticAnalyzer/Core/RetainSummaryManager.h Thu Dec 6 14:07:12 2018
@@ -369,8 +369,12 @@ public:
/// 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
Modified: cfe/trunk/lib/StaticAnalyzer/Core/RetainSummaryManager.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/RetainSummaryManager.cpp?rev=348533&r1=348532&r2=348533&view=diff
==============================================================================
--- cfe/trunk/lib/StaticAnalyzer/Core/RetainSummaryManager.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/RetainSummaryManager.cpp Thu Dec 6 14:07:12 2018
@@ -759,6 +759,9 @@ RetainSummaryManager::updateSummaryFromA
QualType RetTy = FD->getReturnType();
if (Optional<RetEffect> RetE = getRetEffectFromAnnotations(RetTy, FD))
Template->setRetEffect(*RetE);
+
+ if (FD->hasAttr<OSConsumesThisAttr>())
+ Template->setThisEffect(DecRef);
}
void
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=348533&r1=348532&r2=348533&view=diff
==============================================================================
--- cfe/trunk/test/Analysis/osobject-retain-release.cpp (original)
+++ cfe/trunk/test/Analysis/osobject-retain-release.cpp Thu Dec 6 14:07:12 2018
@@ -5,6 +5,7 @@ struct OSMetaClass;
#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 @@ struct OSArray : public OSObject {
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 @@ unsigned int check_attribute_indirect_pr
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();
More information about the cfe-commits
mailing list