brintos

brintos / llvm-project-archived public Read only

0
0
Text · 3.2 KiB · 8788804 Raw
138 lines · plain
1// RUN: %clang_analyze_cc1 -fblocks -analyzer-checker=osx.cocoa.UnusedIvars -verify -Wno-objc-root-class %s2 3//===--- BEGIN: Delta-debugging reduced headers. --------------------------===//4 5@protocol NSObject6- (id)retain;7- (oneway void)release;8@end9@interface NSObject <NSObject> {}10- (id)init;11+ (id)alloc;12@end13 14//===--- END: Delta-debugging reduced headers. ----------------------------===//15 16// This test case tests the basic functionality of the unused ivar test.17@interface TestA {18@private19  int x; // expected-warning {{Instance variable 'x' in class 'TestA' is never used}}20}21@end22@implementation TestA @end23 24// This test case tests whether the unused ivar check handles blocks that25// reference an instance variable.26@interface TestB : NSObject {27@private28  id _ivar; // no-warning29}30@property (readwrite,retain) id ivar;31@end32 33@implementation TestB34- (id)ivar {35  __attribute__((__blocks__(byref))) id value = ((void*)0);36  void (^b)(void) = ^{ value = _ivar; };37  b();38  return value;39}40 41- (void)setIvar:(id)newValue {42  void (^b)(void) = ^{ [_ivar release]; _ivar = [newValue retain]; };43  b();44}45@end46 47// Confirm that the checker respects [[clang::suppress]].48@interface TestC {49@private50  [[clang::suppress]] int x; // no-warning51}52@end53@implementation TestC @end54 55 56//===----------------------------------------------------------------------===//57// Detect that ivar is in use, if used in category in the same file as the58// implementation.59//===----------------------------------------------------------------------===//60@protocol Protocol626000461- (id) getId;62@end63 64@interface RDar6260004 {65@private66  id x; // no-warning67}68@end69@implementation RDar6260004 @end70@implementation RDar6260004 (Protocol6260004)71- (id) getId {72  return x;73}74@end75 76//===----------------------------------------------------------------------===//77// ivars referenced by lexically nested functions should not be flagged as78// unused79//===----------------------------------------------------------------------===//80@interface RDar7254495 {81@private82  int x; // no-warning83}84@end85 86@implementation RDar725449587int radar_7254495(RDar7254495 *a) {88  return a->x;89}90@end91 92//===----------------------------------------------------------------------===//93// Consult attribute((unused)) to silence warnings about unused instance94// variables.95//===----------------------------------------------------------------------===//96@interface RDar7353683 {97@private98  id x __attribute__((unused));99}100@end101 102@implementation RDar7353683103@end104 105//===----------------------------------------------------------------------===//106// Unused bitfield ivars trigger cause weird diagnostic:107// "Instance variable '' in class..."108//===----------------------------------------------------------------------===//109@interface RDar8481311 {110@private111    unsigned bitfield:1; // expected-warning {{Instance variable 'bitfield' in class 'RDar8481311' is never used}}112}113@end114 115@implementation RDar8481311116@end117 118@class NSString;119@interface Radar11059352_1 {120@private121    NSString *_pathString;122}123@property (readonly, strong) NSString *pathString;124@end125 126@interface Radar11059352 {127@private128Radar11059352_1 *_workspacePath;129}130@end131 132@implementation Radar11059352133 134- (void)useWorkspace {135    NSString *workspacePathString = _workspacePath.pathString;136}137@end138