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