blob: eff8dbb484beba609f53b9cf191982d065b2eb83 [file] [log] [blame]
Zhongxing Xuc14f0972009-04-29 01:50:12 +00001// RUN: clang-cc -analyze -checker-cfref -analyzer-store=region --verify %s
Zhongxing Xuc14f0972009-04-29 01:50:12 +00002
Zhongxing Xu12233fd2009-04-29 05:59:48 +00003// Test if the 'storage' region gets properly initialized after it is cast to
4// 'struct sockaddr *'.
5
Zhongxing Xu892a5f72009-04-29 02:37:26 +00006#include <sys/socket.h>
Eli Friedman7d369cd2009-07-10 20:10:06 +00007#include <sys/types.h>
8
Zhongxing Xu3c3fee02009-04-28 13:52:13 +00009void f(int sock) {
10 struct sockaddr_storage storage;
11 struct sockaddr* sockaddr = (struct sockaddr*)&storage;
12 socklen_t addrlen = sizeof(storage);
13 getsockname(sock, sockaddr, &addrlen);
14 switch (sockaddr->sa_family) { // no-warning
15 default:
16 ;
17 }
18}
Zhongxing Xucea65782009-06-18 06:29:10 +000019
20struct s {
21 struct s *value;
22};
23
Zhongxing Xucea65782009-06-18 06:29:10 +000024int f1(struct s **pval) {
25 int *tbool = ((void*)0);
26 struct s *t = *pval;
27 pval = &(t->value);
Zhongxing Xub21175c2009-06-18 06:49:35 +000028 tbool = (int *)pval; // Should record the cast-to type here.
29 char c = (unsigned char) *tbool; // Should use cast-to type to create symbol.
Zhongxing Xu54fb5362009-06-19 06:00:32 +000030 if (*tbool == -1)
31 3;
Zhongxing Xucea65782009-06-18 06:29:10 +000032}
33
Zhongxing Xucc457622009-06-19 04:51:14 +000034void f2(const char *str) {
35 unsigned char ch, cl, *p;
36
37 p = (unsigned char *)str;
38 ch = *p++; // use cast-to type 'unsigned char' to create element region.
39 cl = *p++;
40 if(!cl)
41 cl = 'a';
42}