summaryrefslogtreecommitdiff
path: root/test/Analysis/unused-ivars.m
blob: 55c482aa8b3f7aa1e5eb4b1e9cdb2032656ba739 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
// RUN: clang -cc1 -fblocks -analyze -warn-objc-unused-ivars %s -verify

//===--- 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}}
}
@end
@implementation TestA @end

// 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;
}

- (void)setIvar:(id)newValue {
  void (^b)() = ^{ [_ivar release]; _ivar = [newValue retain]; };
  b();
}
@end

//===----------------------------------------------------------------------===//
// <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

//===----------------------------------------------------------------------===//
// <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