reference.cpp revision 892697dd2287caf7c29aaaa82909b0e90b8b63fe
1// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=region -analyzer-constraints=range -verify %s 2// XFAIL: * 3typedef typeof(sizeof(int)) size_t; 4void malloc (size_t); 5 6void 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 16char* ptr(); 17char& ref(); 18 19// These next two tests just shouldn't crash. 20char t1 () { 21 ref() = 'c'; 22 return '0'; 23} 24 25// just a sanity test, the same behavior as t1() 26char 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! 33char t3 () { 34 char& r = ref(); 35 r = 'c'; // no-warning 36 if (r) return r; 37 return *(char*)0; // no-warning 38} 39 40char t4 () { 41 char* p = ptr(); 42 *p = 'c'; // no-warning 43 if (*p) return *p; 44 return *(char*)0; // no-warning 45} 46 47char t5 (char& r) { 48 r = 'c'; // no-warning 49 if (r) return r; 50 return *(char*)0; // no-warning 51} 52 53char t6 (char* p) { 54 *p = 'c'; // no-warning 55 if (*p) return *p; 56 return *(char*)0; // no-warning 57} 58