[cfe-commits] r78409 - in /cfe/trunk: lib/Analysis/CheckObjCUnusedIVars.cpp test/Analysis/unused-ivars.m

Daniel Dunbar daniel at zuster.org
Fri Aug 7 18:27:14 PDT 2009


Rather nit picky, but does the test case really need to be that big?
Seems like this, or something close, works:
--
@interface A { int x; } @end

void f1(void ^(void));

@implementation A
-(void) im0 {
  f1(^() { x = 10; });
}
@end
--

 - Daniel

On Fri, Aug 7, 2009 at 2:13 PM, Ted Kremenek<kremenek at apple.com> wrote:
> Author: kremenek
> Date: Fri Aug  7 16:13:23 2009
> New Revision: 78409
>
> URL: http://llvm.org/viewvc/llvm-project?rev=78409&view=rev
> Log:
> Fix: <rdar://problem/7075531> static analyzer wrongly detects unused ivars used in blocks
>
> Modified:
>    cfe/trunk/lib/Analysis/CheckObjCUnusedIVars.cpp
>    cfe/trunk/test/Analysis/unused-ivars.m
>
> Modified: cfe/trunk/lib/Analysis/CheckObjCUnusedIVars.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/CheckObjCUnusedIVars.cpp?rev=78409&r1=78408&r2=78409&view=diff
>
> ==============================================================================
> --- cfe/trunk/lib/Analysis/CheckObjCUnusedIVars.cpp (original)
> +++ cfe/trunk/lib/Analysis/CheckObjCUnusedIVars.cpp Fri Aug  7 16:13:23 2009
> @@ -30,14 +30,20 @@
>   if (!S)
>     return;
>
> -  if (const ObjCIvarRefExpr* Ex = dyn_cast<ObjCIvarRefExpr>(S)) {
> -    const ObjCIvarDecl* D = Ex->getDecl();
> +  if (const ObjCIvarRefExpr *Ex = dyn_cast<ObjCIvarRefExpr>(S)) {
> +    const ObjCIvarDecl *D = Ex->getDecl();
>     IvarUsageMap::iterator I = M.find(D);
>     if (I != M.end())
>       I->second = Used;
>     return;
>   }
>
> +  // Blocks can reference an instance variable of a class.
> +  if (const BlockExpr *BE = dyn_cast<BlockExpr>(S)) {
> +    Scan(M, BE->getBody());
> +    return;
> +  }
> +
>   for (Stmt::const_child_iterator I=S->child_begin(),E=S->child_end(); I!=E;++I)
>     Scan(M, *I);
>  }
>
> Modified: cfe/trunk/test/Analysis/unused-ivars.m
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/unused-ivars.m?rev=78409&r1=78408&r2=78409&view=diff
>
> ==============================================================================
> --- cfe/trunk/test/Analysis/unused-ivars.m (original)
> +++ cfe/trunk/test/Analysis/unused-ivars.m Fri Aug  7 16:13:23 2009
> @@ -1,10 +1,45 @@
> -// RUN: clang-cc -analyze -warn-objc-unused-ivars %s -verify
> +// RUN: clang-cc -triple x86_64-apple-darwin10 -analyze -warn-objc-unused-ivars %s -verify
>
> - at interface A
> -{
> -  @private int x; // expected-warning {{Instance variable 'x' in class 'A' is never used}}
> +//===--- BEGIN: Delta-debugging reduced headers. --------------------------===//
> +
> + at protocol NSObject
> +- (id)retain;
> +- (oneway void)release;
> + at end
> + at interface NSObject <NSObject> {}
> +- (id)init;
> ++ (id)alloc;
> + at end
> +
> +//===--- END: Delta-debugging reduced headers. ----------------------------===//
> +
> +// This test case tests the basic functionality of the unused ivar test.
> + at interface TestA {
> + at private
> +  int x; // expected-warning {{Instance variable 'x' in class 'TestA' is never used}}
>  }
>  @end
> + at implementation TestA @end
>
> - at implementation A @end
> +// This test case tests whether the unused ivar check handles blocks that
> +// reference an instance variable. (<rdar://problem/7075531>)
> + at interface TestB : NSObject {
> + at private
> +  id _ivar; // no-warning
> +}
> + at property (readwrite,retain) id ivar;
> + at end
> +
> + at implementation TestB
> +- (id)ivar {
> +  __attribute__((__blocks__(byref))) id value = ((void*)0);
> +  void (^b)() = ^{ value = _ivar; };
> +  b();
> +  return value;
> +}
>
> +- (void)setIvar:(id)newValue {
> +  void (^b)() = ^{ [_ivar release]; _ivar = [newValue retain]; };
> +  b();
> +}
> + at end
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
>




More information about the cfe-commits mailing list