hanchenye-llvm-project/clang/test/Analysis/casts.c

30 lines
746 B
C
Raw Normal View History

2009-04-29 09:50:12 +08:00
// RUN: clang-cc -analyze -checker-cfref -analyzer-store=region --verify %s
2009-04-28 21:52:13 +08:00
// Test if the 'storage' region gets properly initialized after it is cast to
// 'struct sockaddr *'.
2009-04-29 10:37:26 +08:00
#include <sys/socket.h>
2009-04-28 21:52:13 +08:00
void f(int sock) {
struct sockaddr_storage storage;
struct sockaddr* sockaddr = (struct sockaddr*)&storage;
socklen_t addrlen = sizeof(storage);
getsockname(sock, sockaddr, &addrlen);
switch (sockaddr->sa_family) { // no-warning
default:
;
}
}
struct s {
struct s *value;
};
int f1(struct s **pval) {
int *tbool = ((void*)0);
struct s *t = *pval;
pval = &(t->value);
tbool = (int *)pval; // Should record the cast-to type here.
char c = (unsigned char) *tbool; // Should use cast-to type to create symbol.
}