Ted Kremenek | 565e465 | 2010-02-05 02:06:54 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=region -verify -triple x86_64-apple-darwin9 %s |
| 2 | // RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=region -verify -triple i686-apple-darwin9 %s |
Zhongxing Xu | e184b1e | 2009-03-03 00:28:42 +0000 | [diff] [blame] | 3 | |
| 4 | void f1() { |
| 5 | int a[10]; |
| 6 | int *p = a; |
| 7 | ++p; |
| 8 | } |
Zhongxing Xu | 2b1dc17 | 2009-03-11 07:43:49 +0000 | [diff] [blame] | 9 | |
| 10 | char* foo(); |
| 11 | |
| 12 | void f2() { |
| 13 | char *p = foo(); |
| 14 | ++p; |
| 15 | } |
Zhongxing Xu | 3c4b379 | 2009-03-11 09:15:38 +0000 | [diff] [blame] | 16 | |
Zhongxing Xu | e8cba00 | 2009-03-12 01:55:38 +0000 | [diff] [blame] | 17 | // This test case checks if we get the right rvalue type of a TypedViewRegion. |
| 18 | // The ElementRegion's type depends on the array region's rvalue type. If it was |
| 19 | // a pointer type, we would get a loc::SymbolVal for '*p'. |
Eli Friedman | 0b308ad | 2009-06-04 19:35:30 +0000 | [diff] [blame] | 20 | void* memchr(); |
Zhongxing Xu | 3c4b379 | 2009-03-11 09:15:38 +0000 | [diff] [blame] | 21 | static int |
| 22 | domain_port (const char *domain_b, const char *domain_e, |
| 23 | const char **domain_e_ptr) |
| 24 | { |
| 25 | int port = 0; |
| 26 | |
| 27 | const char *p; |
| 28 | const char *colon = memchr (domain_b, ':', domain_e - domain_b); |
| 29 | |
| 30 | for (p = colon + 1; p < domain_e ; p++) |
| 31 | port = 10 * port + (*p - '0'); |
| 32 | return port; |
| 33 | } |
Zhongxing Xu | 3ce2dc3 | 2009-11-09 05:34:10 +0000 | [diff] [blame] | 34 | |
| 35 | void f3() { |
| 36 | int x, y; |
| 37 | int d = &y - &x; // expected-warning{{Subtraction of two pointers that do not point to the same memory chunk may cause incorrect result.}} |
Zhongxing Xu | adca271 | 2009-11-10 02:37:53 +0000 | [diff] [blame] | 38 | |
| 39 | int a[10]; |
| 40 | int *p = &a[2]; |
| 41 | int *q = &a[8]; |
| 42 | d = q-p; // no-warning |
Zhongxing Xu | 3ce2dc3 | 2009-11-09 05:34:10 +0000 | [diff] [blame] | 43 | } |
Zhongxing Xu | b10a7c2 | 2009-11-09 06:52:44 +0000 | [diff] [blame] | 44 | |
| 45 | void f4() { |
| 46 | int *p; |
| 47 | p = (int*) 0x10000; // expected-warning{{Using a fixed address is not portable because that address will probably not be valid in all environments or platforms.}} |
| 48 | } |
Zhongxing Xu | ede7eb2 | 2009-11-09 13:23:31 +0000 | [diff] [blame] | 49 | |
| 50 | void f5() { |
| 51 | int x, y; |
| 52 | int *p; |
Zhongxing Xu | e4da0eb | 2009-11-09 13:56:44 +0000 | [diff] [blame] | 53 | p = &x + 1; // expected-warning{{Pointer arithmetic done on non-array variables means reliance on memory layout, which is dangerous.}} |
Zhongxing Xu | ede7eb2 | 2009-11-09 13:23:31 +0000 | [diff] [blame] | 54 | |
| 55 | int a[10]; |
| 56 | p = a + 1; // no-warning |
| 57 | } |
Zhongxing Xu | 79234ca | 2009-11-10 02:45:49 +0000 | [diff] [blame] | 58 | |
| 59 | // Allow arithmetic on different symbolic regions. |
| 60 | void f6(int *p, int *q) { |
| 61 | int d = q - p; // no-warning |
| 62 | } |