r199473 - [analyzer] Teach NonNullParamChecker about 'nonnull' attributes on parameters.
Ted Kremenek
kremenek at apple.com
Thu Jan 16 23:15:36 PST 2014
Author: kremenek
Date: Fri Jan 17 01:15:35 2014
New Revision: 199473
URL: http://llvm.org/viewvc/llvm-project?rev=199473&view=rev
Log:
[analyzer] Teach NonNullParamChecker about 'nonnull' attributes on parameters.
Modified:
cfe/trunk/lib/StaticAnalyzer/Checkers/NonNullParamChecker.cpp
cfe/trunk/test/Analysis/nonnull.m
Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/NonNullParamChecker.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/NonNullParamChecker.cpp?rev=199473&r1=199472&r2=199473&view=diff
==============================================================================
--- cfe/trunk/lib/StaticAnalyzer/Checkers/NonNullParamChecker.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/NonNullParamChecker.cpp Fri Jan 17 01:15:35 2014
@@ -43,7 +43,7 @@ public:
} // end anonymous namespace
void NonNullParamChecker::checkPreCall(const CallEvent &Call,
- CheckerContext &C) const {
+ CheckerContext &C) const {
const Decl *FD = Call.getDecl();
if (!FD)
return;
@@ -66,6 +66,12 @@ void NonNullParamChecker::checkPreCall(c
}
bool haveAttrNonNull = Att && Att->isNonNull(idx);
+ if (!haveAttrNonNull) {
+ // Check if the parameter is also marked 'nonnull'.
+ ArrayRef<ParmVarDecl*> parms = Call.parameters();
+ if (idx < parms.size())
+ haveAttrNonNull = parms[idx]->hasAttr<NonNullAttr>();
+ }
if (!haveRefTypeParam && !haveAttrNonNull)
continue;
Modified: cfe/trunk/test/Analysis/nonnull.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/nonnull.m?rev=199473&r1=199472&r2=199473&view=diff
==============================================================================
--- cfe/trunk/test/Analysis/nonnull.m (original)
+++ cfe/trunk/test/Analysis/nonnull.m Fri Jan 17 01:15:35 2014
@@ -2,6 +2,8 @@
@interface MyObject
- (void)takePointer:(void *)ptr __attribute__((nonnull(1)));
+- (void)takePointerArg:(void *)__attribute__((nonnull)) ptr;
+
@end
void testNonNullMethod(int *p, MyObject *obj) {
@@ -21,3 +23,10 @@ void testSubclass(int *p, Subclass *obj)
return;
[obj takePointer:p]; // expected-warning{{nonnull}}
}
+
+void testSubclassArg(int *p, Subclass *obj) {
+ if (p)
+ return;
+ [obj takePointerArg:p]; // expected-warning{{nonnull}}
+}
+
More information about the cfe-commits
mailing list