[RISCV] Simplify usage of SplatPat_simm5_plus1. NFC (#125340)
[llvm-project.git] / clang / test / Analysis / unused-ivars.m
blob8788804bf0c33c4aa4afd7f9542f72d16b1518a2
1 // RUN: %clang_analyze_cc1 -fblocks -analyzer-checker=osx.cocoa.UnusedIvars -verify -Wno-objc-root-class %s
3 //===--- BEGIN: Delta-debugging reduced headers. --------------------------===//
5 @protocol NSObject
6 - (id)retain;
7 - (oneway void)release;
8 @end
9 @interface NSObject <NSObject> {}
10 - (id)init;
11 + (id)alloc;
12 @end
14 //===--- END: Delta-debugging reduced headers. ----------------------------===//
16 // This test case tests the basic functionality of the unused ivar test.
17 @interface TestA {
18 @private
19   int x; // expected-warning {{Instance variable 'x' in class 'TestA' is never used}}
21 @end
22 @implementation TestA @end
24 // This test case tests whether the unused ivar check handles blocks that
25 // reference an instance variable.
26 @interface TestB : NSObject {
27 @private
28   id _ivar; // no-warning
30 @property (readwrite,retain) id ivar;
31 @end
33 @implementation TestB
34 - (id)ivar {
35   __attribute__((__blocks__(byref))) id value = ((void*)0);
36   void (^b)(void) = ^{ value = _ivar; };
37   b();
38   return value;
41 - (void)setIvar:(id)newValue {
42   void (^b)(void) = ^{ [_ivar release]; _ivar = [newValue retain]; };
43   b();
45 @end
47 // Confirm that the checker respects [[clang::suppress]].
48 @interface TestC {
49 @private
50   [[clang::suppress]] int x; // no-warning
52 @end
53 @implementation TestC @end
56 //===----------------------------------------------------------------------===//
57 // Detect that ivar is in use, if used in category in the same file as the
58 // implementation.
59 //===----------------------------------------------------------------------===//
60 @protocol Protocol6260004
61 - (id) getId;
62 @end
64 @interface RDar6260004 {
65 @private
66   id x; // no-warning
68 @end
69 @implementation RDar6260004 @end
70 @implementation RDar6260004 (Protocol6260004)
71 - (id) getId {
72   return x;
74 @end
76 //===----------------------------------------------------------------------===//
77 // ivars referenced by lexically nested functions should not be flagged as
78 // unused
79 //===----------------------------------------------------------------------===//
80 @interface RDar7254495 {
81 @private
82   int x; // no-warning
84 @end
86 @implementation RDar7254495
87 int radar_7254495(RDar7254495 *a) {
88   return a->x;
90 @end
92 //===----------------------------------------------------------------------===//
93 // Consult attribute((unused)) to silence warnings about unused instance
94 // variables.
95 //===----------------------------------------------------------------------===//
96 @interface RDar7353683 {
97 @private
98   id x __attribute__((unused));
100 @end
102 @implementation RDar7353683
103 @end
105 //===----------------------------------------------------------------------===//
106 // Unused bitfield ivars trigger cause weird diagnostic:
107 // "Instance variable '' in class..."
108 //===----------------------------------------------------------------------===//
109 @interface RDar8481311 {
110 @private
111     unsigned bitfield:1; // expected-warning {{Instance variable 'bitfield' in class 'RDar8481311' is never used}}
113 @end
115 @implementation RDar8481311
116 @end
118 @class NSString;
119 @interface Radar11059352_1 {
120 @private
121     NSString *_pathString;
123 @property (readonly, strong) NSString *pathString;
124 @end
126 @interface Radar11059352 {
127 @private
128 Radar11059352_1 *_workspacePath;
130 @end
132 @implementation Radar11059352
134 - (void)useWorkspace {
135     NSString *workspacePathString = _workspacePath.pathString;
137 @end