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