2009-12-17 09:44:13 +08:00
|
|
|
// 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
|
|
|
|
// 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
|
|
|
|
|
2009-12-19 04:13:39 +08:00
|
|
|
// Test basic handling of references.
|
2009-12-17 09:44:13 +08:00
|
|
|
char &test1_aux();
|
|
|
|
char *test1() {
|
|
|
|
return &test1_aux();
|
|
|
|
}
|
2009-12-19 04:13:39 +08:00
|
|
|
|
2009-12-19 11:17:55 +08:00
|
|
|
// Test test1_aux() evaluates to char &.
|
2009-12-19 04:13:39 +08:00
|
|
|
char test1_as_rvalue() {
|
|
|
|
return test1_aux();
|
|
|
|
}
|
|
|
|
|
2009-12-23 08:26:16 +08:00
|
|
|
// Test passing a value as a reference. The 'const' in test2_aux() adds
|
|
|
|
// an ImplicitCastExpr, which is evaluated as an lvalue.
|
|
|
|
int test2_aux(const int &n);
|
|
|
|
int test2(int n) {
|
|
|
|
return test2_aux(n);
|
|
|
|
}
|
|
|
|
|
|
|
|
int test2_b_aux(const short &n);
|
|
|
|
int test2_b(int n) {
|
|
|
|
return test2_b_aux(n);
|
|
|
|
}
|
2009-12-23 09:19:20 +08:00
|
|
|
|
|
|
|
// Test getting the lvalue of a derived and converting it to a base. This
|
|
|
|
// previously crashed.
|
|
|
|
class Test3_Base {};
|
|
|
|
class Test3_Derived : public Test3_Base {};
|
|
|
|
|
|
|
|
int test3_aux(Test3_Base &x);
|
|
|
|
int test3(Test3_Derived x) {
|
|
|
|
return test3_aux(x);
|
|
|
|
}
|
|
|
|
|
2009-12-23 12:49:01 +08:00
|
|
|
int test_init_in_condition_aux();
|
|
|
|
int test_init_in_condition() {
|
|
|
|
if (int x = test_init_in_condition_aux()) { // no-warning
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
2009-12-24 08:40:03 +08:00
|
|
|
|
|
|
|
int test_init_in_condition_switch() {
|
|
|
|
switch (int x = test_init_in_condition_aux()) { // no-warning
|
|
|
|
case 1:
|
|
|
|
return 0;
|
|
|
|
case 2:
|
|
|
|
if (x == 2)
|
|
|
|
return 0;
|
|
|
|
else {
|
|
|
|
// Unreachable.
|
|
|
|
int *p = 0;
|
|
|
|
*p = 0xDEADBEEF; // no-warning
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|