fields.c revision ce6644bc1e921833f9b3c10cf7d4a0b78e8d5dc9
1// RUN: %clang_cc1 -analyze -analyzer-checker=core,alpha.core %s -analyzer-store=region -verify
2
3unsigned foo();
4typedef struct bf { unsigned x:2; } bf;
5void bar() {
6  bf y;
7  *(unsigned*)&y = foo();
8  y.x = 1;
9}
10
11struct s {
12  int n;
13};
14
15void f() {
16  struct s a;
17  int *p = &(a.n) + 1;
18}
19
20typedef struct {
21  int x,y;
22} Point;
23
24Point getit(void);
25void test() {
26  Point p;
27  (void)(p = getit()).x;
28}
29
30
31void testNullAddress() {
32  Point *p = 0;
33  int *px = &p->x; // expected-warning{{Access to field 'x' results in a dereference of a null pointer (loaded from variable 'p')}}
34  *px = 1; // No warning because analysis stops at the previous line.
35}
36