brintos

brintos / llvm-project-archived public Read only

0
0
Text · 3.5 KiB · 240479b Raw
120 lines · plain
1// RUN: %clang_analyze_cc1 -analyzer-checker=core,alpha.core -analyzer-checker=deadcode.DeadStores,osx.cocoa.RetainCount -fblocks -verify -Wno-objc-root-class %s2 3typedef signed char BOOL;4typedef unsigned int NSUInteger;5typedef struct _NSZone NSZone;6@class NSInvocation, NSMethodSignature, NSCoder, NSString, NSEnumerator;7@protocol NSObject  - (BOOL)isEqual:(id)object; @end8@protocol NSCopying  - (id)copyWithZone:(NSZone *)zone; @end9@protocol NSCoding  - (void)encodeWithCoder:(NSCoder *)aCoder; @end10@interface NSObject <NSObject> {} @end11extern id NSAllocateObject(Class aClass, NSUInteger extraBytes, NSZone *zone);12@interface NSValue : NSObject <NSCopying, NSCoding>  - (void)getValue:(void *)value; @end13typedef float CGFloat;14typedef struct _NSPoint {} NSRange;15@interface NSValue (NSValueRangeExtensions)  + (NSValue *)valueWithRange:(NSRange)range;16- (BOOL)containsObject:(id)anObject;17@end18@class NSURLAuthenticationChallenge;19@interface NSResponder : NSObject <NSCoding> {} @end20@class NSArray, NSDictionary, NSString;21@interface NSObject (NSKeyValueBindingCreation)22+ (void)exposeBinding:(NSString *)binding;23- (NSArray *)exposedBindings;24@end25extern NSString *NSAlignmentBinding;26 27// This test case was reported as a false positive due to a bug in the28// LiveVariables <-> deadcode.DeadStores interplay.  We should not flag a warning29// here.  The test case was reported in:30//  http://lists.llvm.org/pipermail/cfe-dev/2008-July/002157.html31void DeadStoreTest(NSObject *anObject) {32  NSArray *keys;33  if ((keys = [anObject exposedBindings]) &&   // no-warning34      ([keys containsObject:@"name"] && [keys containsObject:@"icon"])) {}35}36 37// This test case was a false positive due to how clang models38// pointer types and ObjC object pointer types differently.  Here39// we don't warn about a dead store because 'nil' is assigned to40// an object pointer for the sake of defensive programming.41void rdar_7631278(NSObject *x) {42  x = ((void*)0);43}44 45// This test case issuing a bogus warning for the declaration of 'isExec'46// because the compound statement for the @synchronized was being visited47// twice by the LiveVariables analysis.48BOOL baz_rdar8527823(void);49void foo_rdar8527823(void);50@interface RDar852782351- (void) bar_rbar8527823;52@end53@implementation RDar852782354- (void) bar_rbar852782355{56 @synchronized(self) {57   BOOL isExec = baz_rdar8527823(); // no-warning58   if (isExec) foo_rdar8527823();59 }60}61@end62 63// Don't flag dead stores to assignments to self within a nested assignment.64@interface Rdar794768665- (id) init;66@end67 68@interface Rdar7947686_B : Rdar794768669- (id) init;70@end71 72@implementation Rdar7947686_B73- (id) init {74  id x = (self = [super init]);75  // expected-warning@-1 {{Although the value stored to 'self'}}76  return x;77}78@end79 80// Don't flag dead stores when a variable is captured in a block used81// by a property access.82@interface RDar1059135583@property (assign) int x;84@end85 86RDar10591355 *rdar10591355_aux(void);87 88void rdar10591355(void) {89  RDar10591355 *p = rdar10591355_aux();90  ^{ (void) p.x; }();91}92 93@interface Radar11059352_1 {94@private95    int *_pathString;96}97@property int *pathString;98@end99@interface Radar11059352 {100@private101Radar11059352_1 *_Path;102}103@end104@implementation Radar11059352105 106- (int*)usePath {107    Radar11059352_1 *xxxxx = _Path; // no warning108    int *wp = xxxxx.pathString;109    return wp;110}111@end112 113id test_objc_precise_lifetime_foo(void);114void test_objc_precise_lifetime(void) {115  __attribute__((objc_precise_lifetime)) id dead = test_objc_precise_lifetime_foo(); // no-warning116  dead = 0;117  dead = test_objc_precise_lifetime_foo(); // no-warning118  dead = 0;119}120