blob: a10d5a806016d7b1b915711f7e1f1a7f185a1d8b [file] [log] [blame]
Jordan Rosece6644b2012-09-29 01:36:51 +00001// RUN: %clang_cc1 -analyze -analyzer-checker=core,alpha.core %s -analyzer-store=region -verify
Ted Kremenek5c456fe2008-10-18 03:28:48 +00002
3unsigned foo();
4typedef struct bf { unsigned x:2; } bf;
5void bar() {
6 bf y;
7 *(unsigned*)&y = foo();
8 y.x = 1;
9}
Zhongxing Xu5414a5c2009-06-21 13:24:24 +000010
11struct s {
12 int n;
13};
14
15void f() {
16 struct s a;
17 int *p = &(a.n) + 1;
18}
Argyrios Kyrtzidisc2e20d02011-02-03 22:01:32 +000019
20typedef struct {
21 int x,y;
22} Point;
23
24Point getit(void);
25void test() {
26 Point p;
27 (void)(p = getit()).x;
28}
Jordan Rosedd1d7d82012-09-22 01:24:33 +000029
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}