Allow resolving headers from a PCH even after headers+PCH were moved to another path.
[clang.git] / test / Analysis / casts.c
blob1cb88e611224d8ca51cf4e44bb1a51cec120cabc
1 // RUN: %clang_cc1 -triple x86_64-apple-darwin9 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=region -verify %s
2 // RUN: %clang_cc1 -triple i386-apple-darwin9 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=region -verify %s
4 // Test if the 'storage' region gets properly initialized after it is cast to
5 // 'struct sockaddr *'.
7 typedef unsigned char __uint8_t;
8 typedef unsigned int __uint32_t;
9 typedef __uint32_t __darwin_socklen_t;
10 typedef __uint8_t sa_family_t;
11 typedef __darwin_socklen_t socklen_t;
12 struct sockaddr { sa_family_t sa_family; };
13 struct sockaddr_storage {};
15 void getsockname();
17 void f(int sock) {
18 struct sockaddr_storage storage;
19 struct sockaddr* sockaddr = (struct sockaddr*)&storage;
20 socklen_t addrlen = sizeof(storage);
21 getsockname(sock, sockaddr, &addrlen);
22 switch (sockaddr->sa_family) { // no-warning
23 default:
28 struct s {
29 struct s *value;
32 void f1(struct s **pval) {
33 int *tbool = ((void*)0);
34 struct s *t = *pval;
35 pval = &(t->value);
36 tbool = (int *)pval; // use the cast-to type 'int *' to create element region.
37 char c = (unsigned char) *tbool; // Should use cast-to type to create symbol.
38 if (*tbool == -1) // here load the element region with the correct type 'int'
39 (void)3;
42 void f2(const char *str) {
43 unsigned char ch, cl, *p;
45 p = (unsigned char *)str;
46 ch = *p++; // use cast-to type 'unsigned char' to create element region.
47 cl = *p++;
48 if(!cl)
49 cl = 'a';
52 // Test cast VariableSizeArray to pointer does not crash.
53 void *memcpy(void *, void const *, unsigned long);
54 typedef unsigned char Byte;
55 void doit(char *data, int len) {
56 if (len) {
57 Byte buf[len];
58 memcpy(buf, data, len);
62 // PR 6013 and 6035 - Test that a cast of a pointer to long and then to int does not crash SValuator.
63 void pr6013_6035_test(void *p) {
64 unsigned int foo;
65 foo = ((long)(p));
66 (void) foo;