blob: eac0bd3a0113e0854bc7cf2bf853295b570a26e9 [file] [log] [blame]
Zhongxing Xu5cd4e4f2009-04-29 01:50:12 +00001// RUN: clang-cc -analyze -checker-cfref -analyzer-store=region --verify %s
Zhongxing Xu5cd4e4f2009-04-29 01:50:12 +00002
Zhongxing Xu3b5bc592009-04-29 05:59:48 +00003// Test if the 'storage' region gets properly initialized after it is cast to
4// 'struct sockaddr *'.
5
Zhongxing Xuc3708df2009-04-29 02:37:26 +00006#include <sys/socket.h>
Zhongxing Xu99f77792009-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 Xue5399952009-06-18 06:29:10 +000017
18struct s {
19 struct s *value;
20};
21
Zhongxing Xue5399952009-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 Xu091e9dd2009-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 Xue5399952009-06-18 06:29:10 +000028}
29