blob: eac0bd3a0113e0854bc7cf2bf853295b570a26e9 [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
Zhongxing Xu88c675f2009-06-18 06:29:10 +000022int f1(struct s **pval) {
23 int *tbool = ((void*)0);
24 struct s *t = *pval;
25 pval = &(t->value);
Zhongxing Xu59c03ff2009-06-18 06:49:35 +000026 tbool = (int *)pval; // Should record the cast-to type here.
27 char c = (unsigned char) *tbool; // Should use cast-to type to create symbol.
Zhongxing Xu88c675f2009-06-18 06:29:10 +000028}
29