diff options
| author | Ted Kremenek <kremenek@apple.com> | 2010-01-05 02:18:06 +0000 |
|---|---|---|
| committer | Ted Kremenek <kremenek@apple.com> | 2010-01-05 02:18:06 +0000 |
| commit | acd71a456254f3b4b1f9a860ab09f93026b1e0ef (patch) | |
| tree | 4c9fa59f091f7744526ca1ebd231c3b8ae79abf8 /clang/test | |
| parent | a0e1ee828a071b619324cab8ae438c7c3d5198d2 (diff) | |
| download | bcm5719-llvm-acd71a456254f3b4b1f9a860ab09f93026b1e0ef.tar.gz bcm5719-llvm-acd71a456254f3b4b1f9a860ab09f93026b1e0ef.zip | |
Make static analysis support for C++ 'this' expression context-sensitive. Essentially treat 'this' as a implicit parameter to the method call, and associate a region with it.
llvm-svn: 92675
Diffstat (limited to 'clang/test')
| -rw-r--r-- | clang/test/Analysis/misc-ps-region-store.cpp | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/clang/test/Analysis/misc-ps-region-store.cpp b/clang/test/Analysis/misc-ps-region-store.cpp index 225abb5aa19..8b581311878 100644 --- a/clang/test/Analysis/misc-ps-region-store.cpp +++ b/clang/test/Analysis/misc-ps-region-store.cpp @@ -34,6 +34,10 @@ int test3(Test3_Derived x) { return test3_aux(x); } +//===---------------------------------------------------------------------===// +// Test CFG support for C++ condition variables. +//===---------------------------------------------------------------------===// + int test_init_in_condition_aux(); int test_init_in_condition() { if (int x = test_init_in_condition_aux()) { // no-warning @@ -89,3 +93,42 @@ int test_init_in_condition_for() { *p = 0xDEADBEEF; // no-warning return 0; } + +//===---------------------------------------------------------------------===// +// Test handling of 'this' pointer. +//===---------------------------------------------------------------------===// + +class TestHandleThis { + int x; + + TestHandleThis(); + int foo(); + int null_deref_negative(); + int null_deref_positive(); +}; + +int TestHandleThis::foo() { + // Assume that 'x' is initialized. + return x + 1; // no-warning +} + +int TestHandleThis::null_deref_negative() { + x = 10; + if (x == 10) { + return 1; + } + int *p = 0; + *p = 0xDEADBEEF; // no-warning + return 0; +} + +int TestHandleThis::null_deref_positive() { + x = 10; + if (x == 9) { + return 1; + } + int *p = 0; + *p = 0xDEADBEEF; // expected-warning{{null pointer}} + return 0; +} + |

