diff options
author | Jordan Rose <jordan_rose@apple.com> | 2012-08-21 00:27:33 +0000 |
---|---|---|
committer | Jordan Rose <jordan_rose@apple.com> | 2012-08-21 00:27:33 +0000 |
commit | a34d4f47321324187ed57948628f5938357ae034 (patch) | |
tree | 1e3f08a03d3d78b2ddd4935d847aee8e18767f5d /test/Analysis/reference.cpp | |
parent | 49795ae2c7cbb0845ed07b6626ac24275234e3d1 (diff) |
[analyzer] Assume that reference symbols are non-null.
By doing this in the constraint managers, we can ensure that ANY reference
whose value we don't know gets the effect, even if it's not a top-level
parameter.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@162246 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/Analysis/reference.cpp')
-rw-r--r-- | test/Analysis/reference.cpp | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/test/Analysis/reference.cpp b/test/Analysis/reference.cpp index 06e4a50e44..d901bfee8a 100644 --- a/test/Analysis/reference.cpp +++ b/test/Analysis/reference.cpp @@ -1,3 +1,4 @@ +// RUN: %clang_cc1 -analyze -analyzer-checker=core,experimental.core,debug.ExprInspection -analyzer-store=region -analyzer-constraints=basic -verify -Wno-null-dereference %s // RUN: %clang_cc1 -analyze -analyzer-checker=core,experimental.core,debug.ExprInspection -analyzer-store=region -analyzer-constraints=range -verify -Wno-null-dereference %s void clang_analyzer_eval(bool); @@ -110,6 +111,16 @@ void testRetroactiveNullReference(int *x) { y = 5; // expected-warning{{Dereference of null pointer}} } +void testReferenceAddress(int &x) { + clang_analyzer_eval(&x != 0); // expected-warning{{TRUE}} + clang_analyzer_eval(&ref() != 0); // expected-warning{{TRUE}} + + struct S { int &x; }; + + extern S *getS(); + clang_analyzer_eval(&getS()->x != 0); // expected-warning{{TRUE}} +} + // ------------------------------------ // False negatives @@ -127,5 +138,11 @@ namespace rdar11212286 { B *x = 0; return *x; // should warn here! } +} + +void testReferenceFieldAddress() { + struct S { int &x; }; + extern S getS(); + clang_analyzer_eval(&getS().x != 0); // expected-warning{{UNKNOWN}} } |