]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - test/Analysis/reference.cpp
Vendor import of clang trunk r154661:
[FreeBSD/FreeBSD.git] / test / Analysis / reference.cpp
1 // RUN: %clang_cc1 -analyze -analyzer-checker=core,experimental.core -analyzer-store=region -analyzer-constraints=range -verify -Wno-null-dereference %s
2 // XFAIL
3
4 typedef typeof(sizeof(int)) size_t;
5 void malloc (size_t);
6
7 void f1() {
8   int const &i = 3;  // <--- **FIXME** This is currently not being modeled correctly.
9   int b = i;
10
11   int *p = 0;
12
13   if (b != 3)
14     *p = 1; // no-warning
15 }
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 }
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 }