1 // RUN: %clang_cc1 -triple x86_64-apple-darwin9 -analyze -analyzer-checker=core,core.experimental -analyzer-store=basic -analyzer-constraints=basic -verify -fblocks %s 2 // RUN: %clang_cc1 -triple x86_64-apple-darwin9 -analyze -analyzer-checker=core,core.experimental -analyzer-store=basic -analyzer-constraints=range -verify -fblocks %s 3 // RUN: %clang_cc1 -triple x86_64-apple-darwin9 -analyze -analyzer-checker=core,core.experimental -analyzer-store=region -analyzer-constraints=basic -verify -fblocks %s 4 // RUN: %clang_cc1 -triple x86_64-apple-darwin9 -analyze -analyzer-checker=core,core.experimental -analyzer-store=region -analyzer-constraints=range -verify -fblocks %s 5 6 // <rdar://problem/6440393> - A bunch of misc. failures involving evaluating 7 // these expressions and building CFGs. These tests are here to prevent 8 // regressions. 9 typedef long long int64_t; 10 @class NSString, NSDictionary; 11 typedef long NSInteger; 12 typedef unsigned long NSUInteger; 13 typedef unsigned char Boolean; 14 typedef const struct __CFDictionary * CFDictionaryRef; 15 16 extern Boolean CFDictionaryGetValueIfPresent(CFDictionaryRef theDict, const void *key, const void **value); 17 void shazam(NSUInteger i, unsigned char **out); 18 19 void rdar_6440393_1(NSDictionary *dict) { 20 NSInteger x = 0; 21 unsigned char buf[10], *bufptr = buf; 22 if (!CFDictionaryGetValueIfPresent(0, dict, (void *)&x)) 23 return; 24 shazam(x, &bufptr); 25 } 26 27 // <rdar://problem/6845148> - In this example we got a signedness 28 // mismatch between the literal '0' and the value of 'scrooge'. The 29 // trick is to have the evaluator convert the literal to an unsigned 30 // integer when doing a comparison with the pointer. This happens 31 // because of the transfer function logic of 32 // OSAtomicCompareAndSwap64Barrier, which doesn't have special casts 33 // in place to do this for us. 34 _Bool OSAtomicCompareAndSwap64Barrier( int64_t __oldValue, int64_t __newValue, volatile int64_t *__theValue ); 35 extern id objc_lookUpClass(const char *name); 36 void rdar_6845148(id debug_yourself) { 37 if (!debug_yourself) { 38 const char *wacky = ((void *)0); 39 Class scrooge = wacky ? (Class)objc_lookUpClass(wacky) : ((void *)0); 40 OSAtomicCompareAndSwap64Barrier(0, (int64_t)scrooge, (int64_t*)&debug_yourself); 41 } 42 } 43 void rdar_6845148_b(id debug_yourself) { 44 if (!debug_yourself) { 45 const char *wacky = ((void *)0); 46 Class scrooge = wacky ? (Class)objc_lookUpClass(wacky) : ((void *)0); 47 OSAtomicCompareAndSwap64Barrier((int64_t)scrooge, 0, (int64_t*)&debug_yourself); 48 } 49 } 50