misc-ps-region-store.cpp revision 4c508a12cedcf2896412a3700c1b2a35bf339828
1// RUN: %clang_cc1 -triple i386-apple-darwin9 -analyze -analyzer-experimental-internal-checks -checker-cfref -analyzer-store=region -verify -fblocks -analyzer-opt-analyze-nested-blocks %s 2// RUN: %clang_cc1 -triple x86_64-apple-darwin9 -analyze -analyzer-experimental-internal-checks -checker-cfref -analyzer-store=region -verify -fblocks -analyzer-opt-analyze-nested-blocks %s 3 4// Test basic handling of references. 5char &test1_aux(); 6char *test1() { 7 return &test1_aux(); 8} 9 10// Test test1_aux() evaluates to char &. 11char test1_as_rvalue() { 12 return test1_aux(); 13} 14 15// Test passing a value as a reference. The 'const' in test2_aux() adds 16// an ImplicitCastExpr, which is evaluated as an lvalue. 17int test2_aux(const int &n); 18int test2(int n) { 19 return test2_aux(n); 20} 21 22int test2_b_aux(const short &n); 23int test2_b(int n) { 24 return test2_b_aux(n); 25} 26 27// Test getting the lvalue of a derived and converting it to a base. This 28// previously crashed. 29class Test3_Base {}; 30class Test3_Derived : public Test3_Base {}; 31 32int test3_aux(Test3_Base &x); 33int test3(Test3_Derived x) { 34 return test3_aux(x); 35} 36 37int test_init_in_condition_aux(); 38int test_init_in_condition() { 39 if (int x = test_init_in_condition_aux()) { // no-warning 40 return 1; 41 } 42 return 0; 43} 44 45int test_init_in_condition_switch() { 46 switch (int x = test_init_in_condition_aux()) { // no-warning 47 case 1: 48 return 0; 49 case 2: 50 if (x == 2) 51 return 0; 52 else { 53 // Unreachable. 54 int *p = 0; 55 *p = 0xDEADBEEF; // no-warning 56 } 57 default: 58 break; 59 } 60 return 0; 61} 62 63int test_init_in_condition_while() { 64 int y = 1; 65 while (int x = test_init_in_condition_aux()) { // no-warning 66 if (!x) { 67 y = 0; 68 break; 69 } 70 } 71 if (!y) { 72 int *p = 0; 73 *p = 0xDEADBEEF; // no-warning 74 } 75 return 0; 76} 77