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