r190835 - [analyzer] Stop tracking the objects with attribute cleanup in the RetainCountChecker.
Anna Zaks
ganna at apple.com
Mon Sep 16 17:53:28 PDT 2013
Author: zaks
Date: Mon Sep 16 19:53:28 2013
New Revision: 190835
URL: http://llvm.org/viewvc/llvm-project?rev=190835&view=rev
Log:
[analyzer] Stop tracking the objects with attribute cleanup in the RetainCountChecker.
This suppresses false positive leaks. We stop tracking a value if it is assigned to a variable declared with a cleanup attribute.
Modified:
cfe/trunk/lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp
cfe/trunk/test/Analysis/retain-release.m
Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp?rev=190835&r1=190834&r2=190835&view=diff
==============================================================================
--- cfe/trunk/lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp Mon Sep 16 19:53:28 2013
@@ -3356,6 +3356,16 @@ void RetainCountChecker::checkBind(SVal
}
}
+ // If we are storing the value into an auto function scope variable annotated
+ // with (__attribute__((cleanup))), stop tracking the value to avoid leak
+ // false positives.
+ if (const VarRegion *LVR = dyn_cast_or_null<VarRegion>(loc.getAsRegion())) {
+ const VarDecl *VD = LVR->getDecl();
+ if (VD->getAttr<CleanupAttr>()) {
+ escapes = true;
+ }
+ }
+
// If our store can represent the binding and we aren't storing to something
// that doesn't have local storage then just return and have the simulation
// state continue as is.
Modified: cfe/trunk/test/Analysis/retain-release.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/retain-release.m?rev=190835&r1=190834&r2=190835&view=diff
==============================================================================
--- cfe/trunk/test/Analysis/retain-release.m (original)
+++ cfe/trunk/test/Analysis/retain-release.m Mon Sep 16 19:53:28 2013
@@ -2022,6 +2022,20 @@ void rdar13783514(xpc_connection_t conne
xpc_connection_set_finalizer_f(connection, releaseAfterXPC);
} // no-warning
+// Do not report leaks when object is cleaned up with __attribute__((cleanup ..)).
+inline static void cleanupFunction(void *tp) {
+ CFTypeRef x = *(CFTypeRef *)tp;
+ if (x) {
+ CFRelease(x);
+ }
+}
+#define ADDCLEANUP __attribute__((cleanup(cleanupFunction)))
+void foo() {
+ ADDCLEANUP CFStringRef myString;
+ myString = CFStringCreateWithCString(0, "hello world", kCFStringEncodingUTF8);
+ ADDCLEANUP CFStringRef myString2 =
+ CFStringCreateWithCString(0, "hello world", kCFStringEncodingUTF8);
+}
// CHECK: <key>diagnostics</key>
// CHECK-NEXT: <array>
More information about the cfe-commits
mailing list