42 lines · c
1// RUN: %clang_analyze_cc1 -triple x86_64-apple-darwin9 -analyzer-checker=core,alpha.core -verify %s2// expected-no-diagnostics3 4// PR 4164: http://llvm.org/bugs/show_bug.cgi?id=41645//6// Eventually this should be pulled into misc-ps.m. This is in a separate test7// file for now to play around with the specific issues for BasicStoreManager8// and StoreManager (i.e., we can make a copy of this file for either9// 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 that13// takes a void*, which means the ElementRegion should get stripped off.14typedef unsigned int __uint32_t;15typedef __uint32_t __darwin_socklen_t;16typedef __darwin_socklen_t socklen_t;17int getsockopt(int, int, int, void * restrict, socklen_t * restrict);18 19int 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-warning27}28 29// Similar case: instead of passing a 'void*', we pass 'char*'. In this30// case we pass an ElementRegion to the invalidation logic. Since it is31// an ElementRegion that just layers on top of another typed region and the32// ElementRegion itself has elements whose type are integral (essentially raw33// data) we strip off the ElementRegion when doing the invalidation.34int takes_charptr(char* p);35int test2(void) {36 int size;37 if (takes_charptr((char*)&size))38 return -1;39 return size; // no-warning40}41 42