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