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