| // RUN: clang-cc -triple i386-apple-darwin9 -analyze -checker-cfref --analyzer-store=region --verify -fblocks %s && |
| // RUN: clang-cc -triple x86_64-apple-darwin9 -analyze -checker-cfref --analyzer-store=region --verify -fblocks %s |
| |
| typedef struct objc_selector *SEL; |
| typedef signed char BOOL; |
| typedef int NSInteger; |
| typedef unsigned int NSUInteger; |
| typedef struct _NSZone NSZone; |
| @class NSInvocation, NSMethodSignature, NSCoder, NSString, NSEnumerator; |
| @protocol NSObject - (BOOL)isEqual:(id)object; @end |
| @protocol NSCopying - (id)copyWithZone:(NSZone *)zone; @end |
| @protocol NSMutableCopying - (id)mutableCopyWithZone:(NSZone *)zone; @end |
| @protocol NSCoding - (void)encodeWithCoder:(NSCoder *)aCoder; @end |
| @interface NSObject <NSObject> {} - (id)init; @end |
| extern id NSAllocateObject(Class aClass, NSUInteger extraBytes, NSZone *zone); |
| @interface NSString : NSObject <NSCopying, NSMutableCopying, NSCoding> |
| - (NSUInteger)length; |
| + (id)stringWithUTF8String:(const char *)nullTerminatedCString; |
| @end extern NSString * const NSBundleDidLoadNotification; |
| @interface NSAssertionHandler : NSObject {} |
| + (NSAssertionHandler *)currentHandler; |
| - (void)handleFailureInMethod:(SEL)selector object:(id)object file:(NSString *)fileName lineNumber:(NSInteger)line description:(NSString *)format,...; |
| @end |
| extern NSString * const NSConnectionReplyMode; |
| |
| |
| //--------------------------------------------------------------------------- |
| // Test case 'checkaccess_union' differs for region store and basic store. |
| // The basic store doesn't reason about compound literals, so the code |
| // below won't fire an "uninitialized value" warning. |
| //--------------------------------------------------------------------------- |
| |
| // PR 2948 (testcase; crash on VisitLValue for union types) |
| // http://llvm.org/bugs/show_bug.cgi?id=2948 |
| |
| void checkaccess_union() { |
| int ret = 0, status; |
| if (((((__extension__ (((union { // expected-warning {{ Branch condition evaluates to an uninitialized value.}} |
| __typeof (status) __in; int __i;} |
| ) |
| { |
| .__in = (status)} |
| ).__i))) & 0xff00) >> 8) == 1) |
| ret = 1; |
| } |
| |
| |
| // Check our handling of fields being invalidated by function calls. |
| struct test2_struct { int x; int y; char* s; }; |
| void test2_helper(struct test2_struct* p); |
| |
| char test2() { |
| struct test2_struct s; |
| test2_help(&s); |
| char *p = 0; |
| |
| if (s.x > 1) { |
| if (s.s != 0) { |
| p = "hello"; |
| } |
| } |
| |
| if (s.x > 1) { |
| if (s.s != 0) { |
| return *p; |
| } |
| } |
| |
| return 'a'; |
| } |
| |
| // BasicStore handles this case incorrectly because it doesn't reason about |
| // the value pointed to by 'x' and thus creates different symbolic values |
| // at the declarations of 'a' and 'b' respectively. RegionStore handles |
| // it correctly. See the companion test in 'misc-ps-basic-store.m'. |
| void test_trivial_symbolic_comparison_pointer_parameter(int *x) { |
| int a = *x; |
| int b = *x; |
| if (a != b) { |
| int *p = 0; |
| *p = 0xDEADBEEF; // no-warning |
| } |
| } |
| |
| // This is a modified test from 'misc-ps.m'. Here we have the extra |
| // NULL dereferences which are pruned out by RegionStore's symbolic reasoning |
| // of fields. |
| typedef struct _BStruct { void *grue; } BStruct; |
| void testB_aux(void *ptr); |
| |
| void testB(BStruct *b) { |
| { |
| int *__gruep__ = ((int *)&((b)->grue)); |
| int __gruev__ = *__gruep__; |
| int __gruev2__ = *__gruep__; |
| if (__gruev__ != __gruev2__) { |
| int *p = 0; |
| *p = 0xDEADBEEF; // no-warning |
| } |
| |
| testB_aux(__gruep__); |
| } |
| { |
| int *__gruep__ = ((int *)&((b)->grue)); |
| int __gruev__ = *__gruep__; |
| int __gruev2__ = *__gruep__; |
| if (__gruev__ != __gruev2__) { |
| int *p = 0; |
| *p = 0xDEADBEEF; // no-warning |
| } |
| |
| if (~0 != __gruev__) {} |
| } |
| } |
| |
| void testB_2(BStruct *b) { |
| { |
| int **__gruep__ = ((int **)&((b)->grue)); |
| int *__gruev__ = *__gruep__; |
| testB_aux(__gruep__); |
| } |
| { |
| int **__gruep__ = ((int **)&((b)->grue)); |
| int *__gruev__ = *__gruep__; |
| if ((int*)~0 != __gruev__) {} |
| } |
| } |