diff options
Diffstat (limited to 'test/Analysis/misc-ps-region-store.cpp')
-rw-r--r-- | test/Analysis/misc-ps-region-store.cpp | 91 |
1 files changed, 91 insertions, 0 deletions
diff --git a/test/Analysis/misc-ps-region-store.cpp b/test/Analysis/misc-ps-region-store.cpp new file mode 100644 index 0000000..225abb5 --- /dev/null +++ b/test/Analysis/misc-ps-region-store.cpp @@ -0,0 +1,91 @@ +// 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 + +// Test basic handling of references. +char &test1_aux(); +char *test1() { + return &test1_aux(); +} + +// Test test1_aux() evaluates to char &. +char test1_as_rvalue() { + return test1_aux(); +} + +// 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); +} + +// 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); +} + +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; +} + +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; +} + +int test_init_in_condition_while() { + int z = 0; + while (int x = ++z) { // no-warning + if (x == 2) + break; + } + + if (z == 2) + return 0; + + int *p = 0; + *p = 0xDEADBEEF; // no-warning + return 0; +} + + +int test_init_in_condition_for() { + int z = 0; + for (int x = 0; int y = ++z; ++x) { + if (x == y) // no-warning + break; + } + if (z == 1) + return 0; + + int *p = 0; + *p = 0xDEADBEEF; // no-warning + return 0; +} |