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