1// RUN: %clang_cc1 -triple x86_64-apple-darwin9 -analyze -analyzer-checker=core,alpha.core -analyzer-store=region -verify %s
2// expected-no-diagnostics
4// PR 4164: http://llvm.org/bugs/show_bug.cgi?id=4164
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).
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.
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);
19int test1() {
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;
26  return size; // no-warning
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.
34int takes_charptr(char* p);
35int test2() {
36  int size;
37  if (takes_charptr((char*)&size))
38    return -1;
39  return size; // no-warning