misc-ps-region-store.m revision f684d56828c3917a6a4f1037e22cb0c37e5665c2
1// RUN: clang -analyze -checker-cfref --analyzer-store=region --verify -fblocks %s 2 3typedef struct objc_selector *SEL; 4typedef signed char BOOL; 5typedef int NSInteger; 6typedef unsigned int NSUInteger; 7typedef struct _NSZone NSZone; 8@class NSInvocation, NSMethodSignature, NSCoder, NSString, NSEnumerator; 9@protocol NSObject - (BOOL)isEqual:(id)object; @end 10@protocol NSCopying - (id)copyWithZone:(NSZone *)zone; @end 11@protocol NSMutableCopying - (id)mutableCopyWithZone:(NSZone *)zone; @end 12@protocol NSCoding - (void)encodeWithCoder:(NSCoder *)aCoder; @end 13@interface NSObject <NSObject> {} - (id)init; @end 14extern id NSAllocateObject(Class aClass, NSUInteger extraBytes, NSZone *zone); 15@interface NSString : NSObject <NSCopying, NSMutableCopying, NSCoding> 16- (NSUInteger)length; 17+ (id)stringWithUTF8String:(const char *)nullTerminatedCString; 18@end extern NSString * const NSBundleDidLoadNotification; 19@interface NSAssertionHandler : NSObject {} 20+ (NSAssertionHandler *)currentHandler; 21- (void)handleFailureInMethod:(SEL)selector object:(id)object file:(NSString *)fileName lineNumber:(NSInteger)line description:(NSString *)format,...; 22@end 23extern NSString * const NSConnectionReplyMode; 24 25 26//--------------------------------------------------------------------------- 27// Test case 'checkaccess_union' differs for region store and basic store. 28// The basic store doesn't reason about compound literals, so the code 29// below won't fire an "uninitialized value" warning. 30//--------------------------------------------------------------------------- 31 32// PR 2948 (testcase; crash on VisitLValue for union types) 33// http://llvm.org/bugs/show_bug.cgi?id=2948 34 35void checkaccess_union() { 36 int ret = 0, status; 37 if (((((__extension__ (((union { // expected-warning {{ Branch condition evaluates to an uninitialized value.}} 38 __typeof (status) __in; int __i;} 39 ) 40 { 41 .__in = (status)} 42 ).__i))) & 0xff00) >> 8) == 1) 43 ret = 1; 44} 45 46 47// Check our handling of fields being invalidated by function calls. 48struct test2_struct { int x; int y; char* s; }; 49void test2_helper(struct test2_struct* p); 50 51char test2() { 52 struct test2_struct s; 53 test2_help(&s); 54 char *p = 0; 55 56 if (s.x > 1) { 57 if (s.s != 0) { 58 p = "hello"; 59 } 60 } 61 62 if (s.x > 1) { 63 if (s.s != 0) { 64 return *p; 65 } 66 } 67 68 return 'a'; 69} 70 71