Jordan Rose | f1e67d7 | 2012-10-17 19:35:37 +0000 | [diff] [blame^] | 1 | // RUN: %clang_cc1 -analyze -analyzer-checker=core,alpha.core,debug.ExprInspection %s -analyzer-store=region -verify |
| 2 | |
| 3 | void clang_analyzer_eval(int); |
Ted Kremenek | 5c456fe | 2008-10-18 03:28:48 +0000 | [diff] [blame] | 4 | |
| 5 | unsigned foo(); |
| 6 | typedef struct bf { unsigned x:2; } bf; |
| 7 | void bar() { |
| 8 | bf y; |
| 9 | *(unsigned*)&y = foo(); |
| 10 | y.x = 1; |
| 11 | } |
Zhongxing Xu | 5414a5c | 2009-06-21 13:24:24 +0000 | [diff] [blame] | 12 | |
| 13 | struct s { |
| 14 | int n; |
| 15 | }; |
| 16 | |
| 17 | void f() { |
| 18 | struct s a; |
| 19 | int *p = &(a.n) + 1; |
| 20 | } |
Argyrios Kyrtzidis | c2e20d0 | 2011-02-03 22:01:32 +0000 | [diff] [blame] | 21 | |
| 22 | typedef struct { |
| 23 | int x,y; |
| 24 | } Point; |
| 25 | |
| 26 | Point getit(void); |
| 27 | void test() { |
| 28 | Point p; |
| 29 | (void)(p = getit()).x; |
| 30 | } |
Jordan Rose | f1e67d7 | 2012-10-17 19:35:37 +0000 | [diff] [blame^] | 31 | |
| 32 | |
| 33 | void testLazyCompoundVal() { |
| 34 | Point p = {42, 0}; |
| 35 | Point q; |
| 36 | clang_analyzer_eval((q = p).x == 42); // expected-warning{{TRUE}} |
| 37 | clang_analyzer_eval(q.x == 42); // expected-warning{{TRUE}} |
| 38 | } |