Argyrios Kyrtzidis | c4d2c90 | 2011-02-28 19:49:42 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -analyze -analyzer-checker=core,core.experimental -analyzer-store=region -analyzer-constraints=range -verify %s |
Ted Kremenek | eea72a9 | 2011-07-28 23:07:36 +0000 | [diff] [blame^] | 2 | // XFAIL |
Zhongxing Xu | f45fbad | 2010-12-19 02:26:37 +0000 | [diff] [blame] | 3 | |
Jordy Rose | 5d55376 | 2010-06-04 01:14:56 +0000 | [diff] [blame] | 4 | typedef typeof(sizeof(int)) size_t; |
| 5 | void malloc (size_t); |
Zhongxing Xu | bc37b8d | 2010-01-09 09:16:47 +0000 | [diff] [blame] | 6 | |
| 7 | void f1() { |
Ted Kremenek | 892697d | 2010-12-16 07:46:53 +0000 | [diff] [blame] | 8 | int const &i = 3; // <--- **FIXME** This is currently not being modeled correctly. |
Zhongxing Xu | bc37b8d | 2010-01-09 09:16:47 +0000 | [diff] [blame] | 9 | int b = i; |
Zhongxing Xu | 3cd8bd4 | 2010-01-10 02:52:56 +0000 | [diff] [blame] | 10 | |
| 11 | int *p = 0; |
| 12 | |
| 13 | if (b != 3) |
| 14 | *p = 1; // no-warning |
Zhongxing Xu | bc37b8d | 2010-01-09 09:16:47 +0000 | [diff] [blame] | 15 | } |
Zhongxing Xu | fc61d94 | 2010-06-03 06:23:18 +0000 | [diff] [blame] | 16 | |
| 17 | char* ptr(); |
| 18 | char& ref(); |
| 19 | |
| 20 | // These next two tests just shouldn't crash. |
| 21 | char t1 () { |
| 22 | ref() = 'c'; |
| 23 | return '0'; |
| 24 | } |
| 25 | |
| 26 | // just a sanity test, the same behavior as t1() |
| 27 | char t2 () { |
| 28 | *ptr() = 'c'; |
| 29 | return '0'; |
| 30 | } |
Jordy Rose | 5d55376 | 2010-06-04 01:14:56 +0000 | [diff] [blame] | 31 | |
| 32 | // Each of the tests below is repeated with pointers as well as references. |
| 33 | // This is mostly a sanity check, but then again, both should work! |
| 34 | char t3 () { |
| 35 | char& r = ref(); |
| 36 | r = 'c'; // no-warning |
| 37 | if (r) return r; |
| 38 | return *(char*)0; // no-warning |
| 39 | } |
| 40 | |
| 41 | char t4 () { |
| 42 | char* p = ptr(); |
| 43 | *p = 'c'; // no-warning |
| 44 | if (*p) return *p; |
| 45 | return *(char*)0; // no-warning |
| 46 | } |
| 47 | |
| 48 | char t5 (char& r) { |
| 49 | r = 'c'; // no-warning |
| 50 | if (r) return r; |
| 51 | return *(char*)0; // no-warning |
| 52 | } |
| 53 | |
| 54 | char t6 (char* p) { |
| 55 | *p = 'c'; // no-warning |
| 56 | if (*p) return *p; |
| 57 | return *(char*)0; // no-warning |
| 58 | } |