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