r174787 - [analyzer] Invalidation checker: move the "missing implementation" check

Anna Zaks ganna at apple.com
Fri Feb 8 17:09:27 PST 2013


Author: zaks
Date: Fri Feb  8 19:09:27 2013
New Revision: 174787

URL: http://llvm.org/viewvc/llvm-project?rev=174787&view=rev
Log:
[analyzer] Invalidation checker: move the "missing implementation" check

The missing definition check should be in the same category as the
missing ivar validation - in this case, the intent is to invalidate in
the given class, as described in the declaration, but the implementation
does not perform the invalidation. Whereas the MissingInvalidationMethod
checker checks the cases where the method intention is not to
invalidate. The second checker has potential to have a much higher false
positive rate.

Modified:
    cfe/trunk/lib/StaticAnalyzer/Checkers/IvarInvalidationChecker.cpp
    cfe/trunk/test/Analysis/objc_invalidation.m

Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/IvarInvalidationChecker.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/IvarInvalidationChecker.cpp?rev=174787&r1=174786&r2=174787&view=diff
==============================================================================
--- cfe/trunk/lib/StaticAnalyzer/Checkers/IvarInvalidationChecker.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/IvarInvalidationChecker.cpp Fri Feb  8 19:09:27 2013
@@ -51,8 +51,7 @@ struct ChecksFilter {
   DefaultBool check_InstanceVariableInvalidation;
 };
 
-class IvarInvalidationCheckerImpl :
-  public Checker<check::ASTDecl<ObjCImplementationDecl> > {
+class IvarInvalidationCheckerImpl {
 
   typedef llvm::SmallSetVector<const ObjCMethodDecl*, 2> MethodSet;
   typedef llvm::DenseMap<const ObjCMethodDecl*,
@@ -471,12 +470,20 @@ visit(const ObjCImplementationDecl *Impl
   containsInvalidationMethod(InterfaceD, Info, /*LookForPartial*/ false);
 
   // Report an error in case none of the invalidation methods are declared.
-  if (!Info.needsInvalidation() && Filter.check_MissingInvalidationMethod) {
-    reportNoInvalidationMethod(FirstIvarDecl, IvarToPopertyMap, InterfaceD,
-                               /*MissingDeclaration*/ true);
+  if (!Info.needsInvalidation()) {
+    if (Filter.check_MissingInvalidationMethod)
+      reportNoInvalidationMethod(FirstIvarDecl, IvarToPopertyMap, InterfaceD,
+                                 /*MissingDeclaration*/ true);
+    // If there are no invalidation methods, there is no ivar validation work
+    // to be done.
     return;
   }
 
+  // Only check if Ivars are invalidated when InstanceVariableInvalidation
+  // has been requested.
+  if (!Filter.check_InstanceVariableInvalidation)
+    return;
+
   // Check that all ivars are invalidated by the invalidation methods.
   bool AtImplementationContainsAtLeastOneInvalidationMethod = false;
   for (MethodSet::iterator I = Info.InvalidationMethods.begin(),
@@ -489,11 +496,6 @@ visit(const ObjCImplementationDecl *Impl
     if (D && D->hasBody()) {
       AtImplementationContainsAtLeastOneInvalidationMethod = true;
 
-      // Only check if Ivars are invalidated when InstanceVariableInvalidation
-      // has been requested.
-      if (!Filter.check_InstanceVariableInvalidation)
-        break;
-
       // Get a copy of ivars needing invalidation.
       IvarSet IvarsI = Ivars;
 
@@ -517,8 +519,7 @@ visit(const ObjCImplementationDecl *Impl
   }
 
   // Report an error in case none of the invalidation methods are implemented.
-  if (!AtImplementationContainsAtLeastOneInvalidationMethod &&
-      Filter.check_MissingInvalidationMethod)
+  if (!AtImplementationContainsAtLeastOneInvalidationMethod)
     reportNoInvalidationMethod(FirstIvarDecl, IvarToPopertyMap, InterfaceD,
                                /*MissingDeclaration*/ false);
 }

Modified: cfe/trunk/test/Analysis/objc_invalidation.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/objc_invalidation.m?rev=174787&r1=174786&r2=174787&view=diff
==============================================================================
--- cfe/trunk/test/Analysis/objc_invalidation.m (original)
+++ cfe/trunk/test/Analysis/objc_invalidation.m Fri Feb  8 19:09:27 2013
@@ -250,7 +250,7 @@ extern void NSLog(NSString *format, ...)
 
 @interface MissingInvalidationMethod : Foo <FooBar_Protocol>
 @property (assign) MissingInvalidationMethod *foobar15_warn;
-#if RUN_MISSING_INVALIDATION_METHOD
+#if RUN_IVAR_INVALIDATION
 // expected-warning at -2 {{Property foobar15_warn needs to be invalidated; no invalidation method is defined in the @implementation for MissingInvalidationMethod}}
 #endif
 @end
@@ -259,7 +259,7 @@ extern void NSLog(NSString *format, ...)
 
 @interface MissingInvalidationMethod2 : Foo <FooBar_Protocol> {
   Foo *Ivar1;
-#if RUN_MISSING_INVALIDATION_METHOD
+#if RUN_IVAR_INVALIDATION
 // expected-warning at -2 {{Instance variable Ivar1 needs to be invalidated; no invalidation method is defined in the @implementation for MissingInvalidationMethod2}}
 #endif
 }





More information about the cfe-commits mailing list