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