blob: c5fcdd92e1c66ed0e38737d6c475afafa18ed276 [file] [log] [blame]
Zhongxing Xu2fc32592009-04-29 01:50:12 +00001// RUN: clang-cc -analyze -checker-cfref -analyzer-store=region --verify %s
Zhongxing Xu2fc32592009-04-29 01:50:12 +00002
Zhongxing Xub1080ed2009-04-29 05:59:48 +00003// Test if the 'storage' region gets properly initialized after it is cast to
4// 'struct sockaddr *'.
5
Zhongxing Xu62231072009-04-29 02:37:26 +00006#include <sys/socket.h>
Zhongxing Xuc58e7852009-04-28 13:52:13 +00007void f(int sock) {
8 struct sockaddr_storage storage;
9 struct sockaddr* sockaddr = (struct sockaddr*)&storage;
10 socklen_t addrlen = sizeof(storage);
11 getsockname(sock, sockaddr, &addrlen);
12 switch (sockaddr->sa_family) { // no-warning
13 default:
14 ;
15 }
16}
Zhongxing Xu88c675f2009-06-18 06:29:10 +000017
18struct s {
19 struct s *value;
20};
21
22// ElementRegion and cast-to pointee type may be of the same size:
23// 'struct s **' and 'int'.
24
25int f1(struct s **pval) {
26 int *tbool = ((void*)0);
27 struct s *t = *pval;
28 pval = &(t->value);
29 tbool = (int *)pval;
30 char c = (unsigned char) *tbool;
31}
32