1 // RUN: %clang_cc1 -triple x86_64-apple-darwin9 -analyze -analyzer-checker=core,alpha.core -analyzer-store=region -verify %s
2
3 // PR 4164: http://llvm.org/bugs/show_bug.cgi?id=4164
4 //
5 // Eventually this should be pulled into misc-ps.m. This is in a separate test
6 // file for now to play around with the specific issues for BasicStoreManager
7 // and StoreManager (i.e., we can make a copy of this file for either
8 // StoreManager should one start to fail in the near future).
9 //
10 // The basic issue is that the VarRegion for 'size' is casted to (char*),
11 // resulting in an ElementRegion. 'getsockopt' is an unknown function that
12 // takes a void*, which means the ElementRegion should get stripped off.
13 typedef unsigned int __uint32_t;
14 typedef __uint32_t __darwin_socklen_t;
15 typedef __darwin_socklen_t socklen_t;
16 int getsockopt(int, int, int, void * restrict, socklen_t * restrict);
17
test1()18 int test1() {
19 int s = -1;
20 int size;
21 socklen_t size_len = sizeof(size);
22 if (getsockopt(s, 0xffff, 0x1001, (char *)&size, &size_len) < 0)
23 return -1;
24
25 return size; // no-warning
26 }
27
28 // Similar case: instead of passing a 'void*', we pass 'char*'. In this
29 // case we pass an ElementRegion to the invalidation logic. Since it is
30 // an ElementRegion that just layers on top of another typed region and the
31 // ElementRegion itself has elements whose type are integral (essentially raw
32 // data) we strip off the ElementRegion when doing the invalidation.
33 int takes_charptr(char* p);
test2()34 int test2() {
35 int size;
36 if (takes_charptr((char*)&size))
37 return -1;
38 return size; // no-warning
39 }
40
41