Ted Kremenek | 565e465 | 2010-02-05 02:06:54 +0000 | [diff] [blame] | 1 | // 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 Kremenek | a8607d1 | 2009-05-01 19:22:20 +0000 | [diff] [blame] | 5 | |
| 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 Kremenek | 25258f8 | 2009-05-08 00:32:39 +0000 | [diff] [blame] | 9 | typedef long long int64_t; |
Ted Kremenek | a8607d1 | 2009-05-01 19:22:20 +0000 | [diff] [blame] | 10 | @class NSString, NSDictionary; |
| 11 | typedef long NSInteger; |
| 12 | typedef unsigned long NSUInteger; |
| 13 | typedef unsigned char Boolean; |
| 14 | typedef const struct __CFDictionary * CFDictionaryRef; |
| 15 | |
| 16 | extern Boolean CFDictionaryGetValueIfPresent(CFDictionaryRef theDict, const void *key, const void **value); |
| 17 | static void shazam(NSUInteger i, unsigned char **out); |
| 18 | |
| 19 | void 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 Kremenek | 25258f8 | 2009-05-08 00:32:39 +0000 | [diff] [blame] | 27 | // <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 ); |
| 35 | extern id objc_lookUpClass(const char *name); |
| 36 | void 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 | } |
| 43 | void 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 | } |