blob: f1694163a20c983915ce498da31a7039d020c408 [file] [log] [blame]
Ted Kremenek565e4652010-02-05 02:06:54 +00001// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=region -analyzer-constraints=range -verify %s
Jordy Rose5d553762010-06-04 01:14:56 +00002typedef typeof(sizeof(int)) size_t;
3void malloc (size_t);
Zhongxing Xubc37b8d2010-01-09 09:16:47 +00004
5void f1() {
6 int const &i = 3;
7 int b = i;
Zhongxing Xu3cd8bd42010-01-10 02:52:56 +00008
9 int *p = 0;
10
11 if (b != 3)
12 *p = 1; // no-warning
Zhongxing Xubc37b8d2010-01-09 09:16:47 +000013}
Zhongxing Xufc61d942010-06-03 06:23:18 +000014
15char* ptr();
16char& ref();
17
18// These next two tests just shouldn't crash.
19char t1 () {
20 ref() = 'c';
21 return '0';
22}
23
24// just a sanity test, the same behavior as t1()
25char t2 () {
26 *ptr() = 'c';
27 return '0';
28}
Jordy Rose5d553762010-06-04 01:14:56 +000029
30// Each of the tests below is repeated with pointers as well as references.
31// This is mostly a sanity check, but then again, both should work!
32char t3 () {
33 char& r = ref();
34 r = 'c'; // no-warning
35 if (r) return r;
36 return *(char*)0; // no-warning
37}
38
39char t4 () {
40 char* p = ptr();
41 *p = 'c'; // no-warning
42 if (*p) return *p;
43 return *(char*)0; // no-warning
44}
45
46char t5 (char& r) {
47 r = 'c'; // no-warning
48 if (r) return r;
49 return *(char*)0; // no-warning
50}
51
52char t6 (char* p) {
53 *p = 'c'; // no-warning
54 if (*p) return *p;
55 return *(char*)0; // no-warning
56}