xref: /aosp_15_r20/external/clang/test/Analysis/misc-ps-64.m (revision 67e74705e28f6214e480b399dd47ea732279e315)
1*67e74705SXin Li// RUN: %clang_cc1 -triple x86_64-apple-darwin9 -analyze -analyzer-checker=core,alpha.core -analyzer-store=region -analyzer-constraints=range -verify -fblocks %s
2*67e74705SXin Li// expected-no-diagnostics
3*67e74705SXin Li
4*67e74705SXin Li// <rdar://problem/6440393> - A bunch of misc. failures involving evaluating
5*67e74705SXin Li//  these expressions and building CFGs.  These tests are here to prevent
6*67e74705SXin Li//  regressions.
7*67e74705SXin Litypedef long long int64_t;
8*67e74705SXin Li@class NSString, NSDictionary;
9*67e74705SXin Litypedef long NSInteger;
10*67e74705SXin Litypedef unsigned long NSUInteger;
11*67e74705SXin Litypedef unsigned char Boolean;
12*67e74705SXin Litypedef const struct __CFDictionary * CFDictionaryRef;
13*67e74705SXin Li
14*67e74705SXin Liextern Boolean CFDictionaryGetValueIfPresent(CFDictionaryRef theDict, const void *key, const void **value);
15*67e74705SXin Livoid shazam(NSUInteger i, unsigned char **out);
16*67e74705SXin Li
17*67e74705SXin Livoid rdar_6440393_1(NSDictionary *dict) {
18*67e74705SXin Li  NSInteger x = 0;
19*67e74705SXin Li  unsigned char buf[10], *bufptr = buf;
20*67e74705SXin Li  if (!CFDictionaryGetValueIfPresent(0, dict, (void *)&x))
21*67e74705SXin Li    return;
22*67e74705SXin Li  shazam(x, &bufptr);
23*67e74705SXin Li}
24*67e74705SXin Li
25*67e74705SXin Li// <rdar://problem/6845148> - In this example we got a signedness
26*67e74705SXin Li// mismatch between the literal '0' and the value of 'scrooge'.  The
27*67e74705SXin Li// trick is to have the evaluator convert the literal to an unsigned
28*67e74705SXin Li// integer when doing a comparison with the pointer.  This happens
29*67e74705SXin Li// because of the transfer function logic of
30*67e74705SXin Li// OSAtomicCompareAndSwap64Barrier, which doesn't have special casts
31*67e74705SXin Li// in place to do this for us.
32*67e74705SXin Li_Bool OSAtomicCompareAndSwap64Barrier( int64_t __oldValue, int64_t __newValue, volatile int64_t *__theValue );
33*67e74705SXin Liextern id objc_lookUpClass(const char *name);
34*67e74705SXin Livoid rdar_6845148(id debug_yourself) {
35*67e74705SXin Li  if (!debug_yourself) {
36*67e74705SXin Li    const char *wacky = ((void *)0);
37*67e74705SXin Li    Class scrooge = wacky ? (Class)objc_lookUpClass(wacky) : ((void *)0);
38*67e74705SXin Li    OSAtomicCompareAndSwap64Barrier(0, (int64_t)scrooge, (int64_t*)&debug_yourself);
39*67e74705SXin Li  }
40*67e74705SXin Li}
41*67e74705SXin Livoid rdar_6845148_b(id debug_yourself) {
42*67e74705SXin Li  if (!debug_yourself) {
43*67e74705SXin Li    const char *wacky = ((void *)0);
44*67e74705SXin Li    Class scrooge = wacky ? (Class)objc_lookUpClass(wacky) : ((void *)0);
45*67e74705SXin Li    OSAtomicCompareAndSwap64Barrier((int64_t)scrooge, 0, (int64_t*)&debug_yourself);
46*67e74705SXin Li  }
47*67e74705SXin Li}
48