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