blob: b9eecfcf1feb7f980b240b236c1736a528e05720 [file] [log] [blame]
Daniel Dunbar8b576972009-11-08 01:45:36 +00001// RUN: clang-cc -analyze -checker-cfref -analyzer-store=region -verify -triple x86_64-apple-darwin9 %s
Daniel Dunbara45cf5b2009-03-24 02:24:46 +00002// RUN: clang-cc -analyze -checker-cfref -analyzer-store=region -verify -triple i686-apple-darwin9 %s
Zhongxing Xu6765d442009-03-03 00:28:42 +00003
4void f1() {
5 int a[10];
6 int *p = a;
7 ++p;
8}
Zhongxing Xu507202e2009-03-11 07:43:49 +00009
10char* foo();
11
12void f2() {
13 char *p = foo();
14 ++p;
15}
Zhongxing Xuf6b6a392009-03-11 09:15:38 +000016
Zhongxing Xuca026912009-03-12 01:55:38 +000017// 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 Friedman8001b352009-06-04 19:35:30 +000020void* memchr();
Zhongxing Xuf6b6a392009-03-11 09:15:38 +000021static int
22domain_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 Xu86b1e012009-11-09 05:34:10 +000034
35void 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.}}
38}
Zhongxing Xu6c306c82009-11-09 06:52:44 +000039
40void f4() {
41 int *p;
42 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.}}
43}