blob: a2b3dcf7384b21950a4dc260c5f27e9b30e6f67a [file] [log] [blame]
Jordan Rose6f61df32012-09-28 17:15:12 +00001// RUN: %clang_cc1 -analyze -analyzer-checker=core,alpha.core,debug.ExprInspection %s -analyzer-store=region -verify
2
3void clang_analyzer_eval(int);
Ted Kremenek5c456fe2008-10-18 03:28:48 +00004
5unsigned foo();
6typedef struct bf { unsigned x:2; } bf;
7void bar() {
8 bf y;
9 *(unsigned*)&y = foo();
10 y.x = 1;
11}
Zhongxing Xu5414a5c2009-06-21 13:24:24 +000012
13struct s {
14 int n;
15};
16
17void f() {
18 struct s a;
19 int *p = &(a.n) + 1;
20}
Argyrios Kyrtzidisc2e20d02011-02-03 22:01:32 +000021
22typedef struct {
23 int x,y;
24} Point;
25
26Point getit(void);
27void test() {
28 Point p;
29 (void)(p = getit()).x;
30}
Jordan Rosedd1d7d82012-09-22 01:24:33 +000031
32
33void testNullAddress() {
34 Point *p = 0;
35 int *px = &p->x; // expected-warning{{Access to field 'x' results in a dereference of a null pointer (loaded from variable 'p')}}
36 *px = 1; // No warning because analysis stops at the previous line.
37}
Jordan Rose6f61df32012-09-28 17:15:12 +000038
39void testLazyCompoundVal() {
40 Point p = {42, 0};
41 Point q;
42 clang_analyzer_eval((q = p).x == 42); // expected-warning{{TRUE}}
43 clang_analyzer_eval(q.x == 42); // expected-warning{{TRUE}}
44}