]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - test/Analysis/reference.cpp
Vendor import of clang trunk r126079:
[FreeBSD/FreeBSD.git] / test / Analysis / reference.cpp
1 // RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=region -analyzer-constraints=range -verify %s
2
3 typedef typeof(sizeof(int)) size_t;
4 void malloc (size_t);
5
6 void f1() {
7   int const &i = 3;  // <--- **FIXME** This is currently not being modeled correctly.
8   int b = i;
9
10   int *p = 0;
11
12   if (b != 3)
13     *p = 1; // no-warning
14 }
15
16 char* ptr();
17 char& ref();
18
19 // These next two tests just shouldn't crash.
20 char t1 () {
21   ref() = 'c';
22   return '0';
23 }
24
25 // just a sanity test, the same behavior as t1()
26 char t2 () {
27   *ptr() = 'c';
28   return '0';
29 }
30
31 // Each of the tests below is repeated with pointers as well as references.
32 // This is mostly a sanity check, but then again, both should work!
33 char t3 () {
34   char& r = ref();
35   r = 'c'; // no-warning
36   if (r) return r;
37   return *(char*)0; // no-warning
38 }
39
40 char t4 () {
41   char* p = ptr();
42   *p = 'c'; // no-warning
43   if (*p) return *p;
44   return *(char*)0; // no-warning
45 }
46
47 char t5 (char& r) {
48   r = 'c'; // no-warning
49   if (r) return r;
50   return *(char*)0; // no-warning
51 }
52
53 char t6 (char* p) {
54   *p = 'c'; // no-warning
55   if (*p) return *p;
56   return *(char*)0; // no-warning
57 }