blob: dcda8d7667d1c66ad353669984eb2665ccf4a55e [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
Ted Kremeneka8607d12009-05-01 19:22:20 +00002
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.
Ted Kremenek25258f82009-05-08 00:32:39 +00006typedef long long int64_t;
Ted Kremeneka8607d12009-05-01 19:22:20 +00007@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);
John McCall15e310a2011-02-19 02:53:41 +000014void shazam(NSUInteger i, unsigned char **out);
Ted Kremeneka8607d12009-05-01 19:22:20 +000015
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
Ted Kremenek25258f82009-05-08 00:32:39 +000024// <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}