blob: 1fbbeefd2ae45d6d16d5b850a166bb3b3320e994 [file] [log] [blame]
Ted Kremenekcdc3a892012-08-24 20:39:55 +00001// RUN: %clang_cc1 -triple x86_64-apple-darwin9 -analyze -analyzer-checker=core,alpha.core -analyzer-store=region -analyzer-constraints=range -verify -fblocks %s
Andy Gibbs8e8fb3b2012-10-19 12:44:48 +00002// expected-no-diagnostics
Ted Kremeneka8607d12009-05-01 19:22:20 +00003
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.
Ted Kremenek25258f82009-05-08 00:32:39 +00007typedef long long int64_t;
Ted Kremeneka8607d12009-05-01 19:22:20 +00008@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);
John McCall15e310a2011-02-19 02:53:41 +000015void shazam(NSUInteger i, unsigned char **out);
Ted Kremeneka8607d12009-05-01 19:22:20 +000016
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
Ted Kremenek25258f82009-05-08 00:32:39 +000025// <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}