[cfe-commits] r167537 - in /cfe/trunk: lib/StaticAnalyzer/Checkers/BasicObjCFoundationChecks.cpp lib/StaticAnalyzer/Checkers/Checkers.td test/Analysis/diagnostics/undef-value-param.m test/Analysis/retain-release.m tools/scan-build/scan-build.1 www/analyzer/available_checks.html
Jordan Rose
jordan_rose at apple.com
Wed Nov 7 09:12:37 PST 2012
Author: jrose
Date: Wed Nov 7 11:12:37 2012
New Revision: 167537
URL: http://llvm.org/viewvc/llvm-project?rev=167537&view=rev
Log:
[analyzer] Check that the argument to CFMakeCollectable is non-NULL.
Patch by Sean McBride!
Modified:
cfe/trunk/lib/StaticAnalyzer/Checkers/BasicObjCFoundationChecks.cpp
cfe/trunk/lib/StaticAnalyzer/Checkers/Checkers.td
cfe/trunk/test/Analysis/diagnostics/undef-value-param.m
cfe/trunk/test/Analysis/retain-release.m
cfe/trunk/tools/scan-build/scan-build.1
cfe/trunk/www/analyzer/available_checks.html
Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/BasicObjCFoundationChecks.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/BasicObjCFoundationChecks.cpp?rev=167537&r1=167536&r2=167537&view=diff
==============================================================================
--- cfe/trunk/lib/StaticAnalyzer/Checkers/BasicObjCFoundationChecks.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/BasicObjCFoundationChecks.cpp Wed Nov 7 11:12:37 2012
@@ -363,15 +363,15 @@
}
//===----------------------------------------------------------------------===//
-// CFRetain/CFRelease checking for null arguments.
+// CFRetain/CFRelease/CFMakeCollectable checking for null arguments.
//===----------------------------------------------------------------------===//
namespace {
class CFRetainReleaseChecker : public Checker< check::PreStmt<CallExpr> > {
mutable OwningPtr<APIMisuse> BT;
- mutable IdentifierInfo *Retain, *Release;
+ mutable IdentifierInfo *Retain, *Release, *MakeCollectable;
public:
- CFRetainReleaseChecker(): Retain(0), Release(0) {}
+ CFRetainReleaseChecker(): Retain(0), Release(0), MakeCollectable(0) {}
void checkPreStmt(const CallExpr *CE, CheckerContext &C) const;
};
} // end anonymous namespace
@@ -392,12 +392,14 @@
ASTContext &Ctx = C.getASTContext();
Retain = &Ctx.Idents.get("CFRetain");
Release = &Ctx.Idents.get("CFRelease");
- BT.reset(new APIMisuse("null passed to CFRetain/CFRelease"));
+ MakeCollectable = &Ctx.Idents.get("CFMakeCollectable");
+ BT.reset(
+ new APIMisuse("null passed to CFRetain/CFRelease/CFMakeCollectable"));
}
- // Check if we called CFRetain/CFRelease.
+ // Check if we called CFRetain/CFRelease/CFMakeCollectable.
const IdentifierInfo *FuncII = FD->getIdentifier();
- if (!(FuncII == Retain || FuncII == Release))
+ if (!(FuncII == Retain || FuncII == Release || FuncII == MakeCollectable))
return;
// FIXME: The rest of this just checks that the argument is non-null.
@@ -426,9 +428,15 @@
if (!N)
return;
- const char *description = (FuncII == Retain)
- ? "Null pointer argument in call to CFRetain"
- : "Null pointer argument in call to CFRelease";
+ const char *description;
+ if (FuncII == Retain)
+ description = "Null pointer argument in call to CFRetain";
+ else if (FuncII == Release)
+ description = "Null pointer argument in call to CFRelease";
+ else if (FuncII == MakeCollectable)
+ description = "Null pointer argument in call to CFMakeCollectable";
+ else
+ llvm_unreachable("impossible case");
BugReport *report = new BugReport(*BT, description, N);
report->addRange(Arg->getSourceRange());
Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/Checkers.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/Checkers.td?rev=167537&r1=167536&r2=167537&view=diff
==============================================================================
--- cfe/trunk/lib/StaticAnalyzer/Checkers/Checkers.td (original)
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/Checkers.td Wed Nov 7 11:12:37 2012
@@ -433,7 +433,7 @@
DescFile<"BasicObjCFoundationChecks.cpp">;
def CFRetainReleaseChecker : Checker<"CFRetainRelease">,
- HelpText<"Check for null arguments to CFRetain/CFRelease">,
+ HelpText<"Check for null arguments to CFRetain/CFRelease/CFMakeCollectable">,
DescFile<"BasicObjCFoundationChecks.cpp">;
def CFErrorChecker : Checker<"CFError">,
Modified: cfe/trunk/test/Analysis/diagnostics/undef-value-param.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/diagnostics/undef-value-param.m?rev=167537&r1=167536&r2=167537&view=diff
==============================================================================
--- cfe/trunk/test/Analysis/diagnostics/undef-value-param.m (original)
+++ cfe/trunk/test/Analysis/diagnostics/undef-value-param.m Wed Nov 7 11:12:37 2012
@@ -460,7 +460,7 @@
//CHECK: </array>
//CHECK: <key>description</key><string>Null pointer argument in call to CFRelease</string>
//CHECK: <key>category</key><string>API Misuse (Apple)</string>
-//CHECK: <key>type</key><string>null passed to CFRetain/CFRelease</string>
+//CHECK: <key>type</key><string>null passed to CFRetain/CFRelease/CFMakeCollectable</string>
//CHECK: <key>issue_context_kind</key><string>Objective-C method</string>
//CHECK: <key>issue_context</key><string>test</string>
//CHECK: <key>issue_hash</key><integer>5</integer>
Modified: cfe/trunk/test/Analysis/retain-release.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/retain-release.m?rev=167537&r1=167536&r2=167537&view=diff
==============================================================================
--- cfe/trunk/test/Analysis/retain-release.m (original)
+++ cfe/trunk/test/Analysis/retain-release.m Wed Nov 7 11:12:37 2012
@@ -62,6 +62,7 @@
extern const CFAllocatorRef kCFAllocatorDefault;
extern CFTypeRef CFRetain(CFTypeRef cf);
extern void CFRelease(CFTypeRef cf);
+extern CFTypeRef CFMakeCollectable(CFTypeRef cf);
typedef struct {
}
CFArrayCallBacks;
@@ -508,31 +509,39 @@
CFRelease(*B); // no-warning
}
-// Test when we pass NULL to CFRetain/CFRelease.
+// Test when we pass NULL to CFRetain/CFRelease/CFMakeCollectable.
void f16(int x, CFTypeRef p) {
if (p)
return;
- if (x) {
+ if (x > 0) {
CFRelease(p); // expected-warning{{Null pointer argument in call to CFRelease}}
}
- else {
+ else if (x < 0) {
CFRetain(p); // expected-warning{{Null pointer argument in call to CFRetain}}
}
+ else {
+ CFMakeCollectable(p); // expected-warning{{Null pointer argument in call to CFMakeCollectable}}
+ }
}
// Test that an object is non-null after being CFRetained/CFReleased.
void f17(int x, CFTypeRef p) {
- if (x) {
+ if (x > 0) {
CFRelease(p);
if (!p)
CFRelease(0); // no-warning
}
- else {
+ else if (x < 0) {
CFRetain(p);
if (!p)
CFRetain(0); // no-warning
}
+ else {
+ CFMakeCollectable(p);
+ if (!p)
+ CFMakeCollectable(0); // no-warning
+ }
}
// Test basic tracking of ivars associated with 'self'. For the retain/release
Modified: cfe/trunk/tools/scan-build/scan-build.1
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/scan-build/scan-build.1?rev=167537&r1=167536&r2=167537&view=diff
==============================================================================
--- cfe/trunk/tools/scan-build/scan-build.1 (original)
+++ cfe/trunk/tools/scan-build/scan-build.1 Wed Nov 7 11:12:37 2012
@@ -270,9 +270,10 @@
.Fn CFNumberCreate .
.It osx.coreFoundation.CFRetainRelease
Check for null arguments to
-.Fn CFRetain
+.Fn CFRetain ,
+.Fn CFRelease ,
and
-.Fn CFRelease .
+.Fn CFMakeCollectable .
.It osx.coreFoundation.containers.OutOfBounds
Checks for index out-of-bounds when using the
.Vt CFArray
Modified: cfe/trunk/www/analyzer/available_checks.html
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/www/analyzer/available_checks.html?rev=167537&r1=167536&r2=167537&view=diff
==============================================================================
--- cfe/trunk/www/analyzer/available_checks.html (original)
+++ cfe/trunk/www/analyzer/available_checks.html Wed Nov 7 11:12:37 2012
@@ -125,7 +125,7 @@
<td><b>osx.coreFoundation.CFNumber</b></td><td>Check for proper uses of CFNumberCreate.</td>
</tr>
<tr>
-<td><b>osx.coreFoundation.CFRetainRelease</b></td><td>Check for null arguments to CFRetain/CFRelease.</td>
+<td><b>osx.coreFoundation.CFRetainRelease</b></td><td>Check for null arguments to CFRetain/CFRelease/CFMakeCollectable.</td>
</tr>
<tr>
<td><b>osx.coreFoundation.containers.OutOfBounds</b></td><td>Checks for index out-of-bounds when using 'CFArray' API.</td>
More information about the cfe-commits
mailing list