2012-04-07 02:12:22 +08:00
|
|
|
// RUN: %clang_cc1 -fblocks -analyze -analyzer-checker=osx.cocoa.UnusedIvars -verify -Wno-objc-root-class %s
|
2008-07-24 02:21:36 +08:00
|
|
|
|
2009-08-08 05:13:23 +08:00
|
|
|
//===--- BEGIN: Delta-debugging reduced headers. --------------------------===//
|
|
|
|
|
|
|
|
@protocol NSObject
|
|
|
|
- (id)retain;
|
|
|
|
- (oneway void)release;
|
|
|
|
@end
|
|
|
|
@interface NSObject <NSObject> {}
|
|
|
|
- (id)init;
|
|
|
|
+ (id)alloc;
|
|
|
|
@end
|
|
|
|
|
|
|
|
//===--- END: Delta-debugging reduced headers. ----------------------------===//
|
|
|
|
|
|
|
|
// This test case tests the basic functionality of the unused ivar test.
|
|
|
|
@interface TestA {
|
|
|
|
@private
|
|
|
|
int x; // expected-warning {{Instance variable 'x' in class 'TestA' is never used}}
|
2008-07-24 02:21:36 +08:00
|
|
|
}
|
|
|
|
@end
|
2009-08-08 05:13:23 +08:00
|
|
|
@implementation TestA @end
|
2008-07-24 02:21:36 +08:00
|
|
|
|
2009-08-08 05:13:23 +08:00
|
|
|
// This test case tests whether the unused ivar check handles blocks that
|
|
|
|
// reference an instance variable. (<rdar://problem/7075531>)
|
|
|
|
@interface TestB : NSObject {
|
|
|
|
@private
|
|
|
|
id _ivar; // no-warning
|
|
|
|
}
|
|
|
|
@property (readwrite,retain) id ivar;
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation TestB
|
|
|
|
- (id)ivar {
|
|
|
|
__attribute__((__blocks__(byref))) id value = ((void*)0);
|
|
|
|
void (^b)() = ^{ value = _ivar; };
|
|
|
|
b();
|
|
|
|
return value;
|
|
|
|
}
|
2008-07-24 02:21:36 +08:00
|
|
|
|
2009-08-08 05:13:23 +08:00
|
|
|
- (void)setIvar:(id)newValue {
|
|
|
|
void (^b)() = ^{ [_ivar release]; _ivar = [newValue retain]; };
|
|
|
|
b();
|
|
|
|
}
|
|
|
|
@end
|
2009-10-29 06:18:22 +08:00
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// <rdar://problem/6260004> Detect that ivar is in use, if used in category
|
|
|
|
// in the same file as the implementation
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
@protocol Protocol6260004
|
|
|
|
- (id) getId;
|
|
|
|
@end
|
|
|
|
|
|
|
|
@interface RDar6260004 {
|
|
|
|
@private
|
|
|
|
id x; // no-warning
|
|
|
|
}
|
|
|
|
@end
|
|
|
|
@implementation RDar6260004 @end
|
|
|
|
@implementation RDar6260004 (Protocol6260004)
|
|
|
|
- (id) getId {
|
|
|
|
return x;
|
|
|
|
}
|
|
|
|
@end
|
|
|
|
|
2009-11-20 12:31:57 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// <rdar://problem/7254495> - ivars referenced by lexically nested functions
|
|
|
|
// should not be flagged as unused
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
@interface RDar7254495 {
|
|
|
|
@private
|
|
|
|
int x; // no-warning
|
|
|
|
}
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation RDar7254495
|
|
|
|
int radar_7254495(RDar7254495 *a) {
|
|
|
|
return a->x;
|
|
|
|
}
|
|
|
|
@end
|
2010-02-25 11:26:55 +08:00
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// <rdar://problem/7353683> - consult attribute((unused)) to silence warnings
|
|
|
|
// about unused instance variables
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
@interface RDar7353683 {
|
|
|
|
@private
|
|
|
|
id x __attribute__((unused));
|
|
|
|
}
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation RDar7353683
|
|
|
|
@end
|
2010-10-28 10:16:22 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// <rdar://problem/8481311> Unused bitfield ivars trigger cause weird
|
2011-08-12 13:49:51 +08:00
|
|
|
// diagnostic: "Instance variable '' in class..."
|
2010-10-28 10:16:22 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
2010-02-25 11:26:55 +08:00
|
|
|
|
2010-10-28 10:16:22 +08:00
|
|
|
@interface RDar8481311 {
|
|
|
|
@private
|
|
|
|
unsigned bitfield:1; // expected-warning {{Instance variable 'bitfield' in class 'RDar8481311' is never used}}
|
|
|
|
}
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation RDar8481311
|
|
|
|
@end
|
2012-05-16 06:31:56 +08:00
|
|
|
|
|
|
|
@class NSString;
|
|
|
|
@interface Radar11059352_1 {
|
|
|
|
@private
|
|
|
|
NSString *_pathString;
|
|
|
|
}
|
|
|
|
@property (readonly, strong) NSString *pathString;
|
|
|
|
@end
|
|
|
|
|
|
|
|
@interface Radar11059352 {
|
|
|
|
@private
|
|
|
|
Radar11059352_1 *_workspacePath;
|
|
|
|
}
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation Radar11059352
|
|
|
|
|
|
|
|
- (void)useWorkspace {
|
|
|
|
NSString *workspacePathString = _workspacePath.pathString;
|
|
|
|
}
|
|
|
|
@end
|