diff options
author | Ted Kremenek <kremenek@apple.com> | 2011-08-16 21:37:52 +0000 |
---|---|---|
committer | Ted Kremenek <kremenek@apple.com> | 2011-08-16 21:37:52 +0000 |
commit | 5bd04952d4ae7ca894f583583208f0cec4735a90 (patch) | |
tree | 200aed41b1a624647181db29894b784e0d54ae60 | |
parent | 08b86531ade68727c56918f162816075b87c864a (diff) |
[analyzer] teach ExprEngine about loads from static C++ class fields. Fixes <rdar://problem/9948787>.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@137760 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/StaticAnalyzer/Core/ExprEngine.cpp | 9 | ||||
-rw-r--r-- | test/Analysis/misc-ps-region-store.cpp | 27 |
2 files changed, 35 insertions, 1 deletions
diff --git a/lib/StaticAnalyzer/Core/ExprEngine.cpp b/lib/StaticAnalyzer/Core/ExprEngine.cpp index 1ea90047fa..916734b4e7 100644 --- a/lib/StaticAnalyzer/Core/ExprEngine.cpp +++ b/lib/StaticAnalyzer/Core/ExprEngine.cpp @@ -1380,7 +1380,14 @@ void ExprEngine::VisitLvalArraySubscriptExpr(const ArraySubscriptExpr *A, void ExprEngine::VisitMemberExpr(const MemberExpr *M, ExplodedNode *Pred, ExplodedNodeSet &Dst) { - FieldDecl *field = dyn_cast<FieldDecl>(M->getMemberDecl()); + Decl *member = M->getMemberDecl(); + if (VarDecl *VD = dyn_cast<VarDecl>(member)) { + assert(M->isLValue()); + VisitCommonDeclRefExpr(M, VD, Pred, Dst); + return; + } + + FieldDecl *field = dyn_cast<FieldDecl>(member); if (!field) // FIXME: skipping member expressions for non-fields return; diff --git a/test/Analysis/misc-ps-region-store.cpp b/test/Analysis/misc-ps-region-store.cpp index f27b910e1a..1d055d5968 100644 --- a/test/Analysis/misc-ps-region-store.cpp +++ b/test/Analysis/misc-ps-region-store.cpp @@ -414,3 +414,30 @@ void TestAssignIntoSymbolicOffset::test(int x, int y) { } } +// Test loads from static fields. This previously triggered an uninitialized +// value warning. +class ClassWithStatic { +public: + static const unsigned value = 1; +}; + +int rdar9948787_negative() { + ClassWithStatic classWithStatic; + unsigned value = classWithStatic.value; + if (value == 1) + return 1; + int *p = 0; + *p = 0xDEADBEEF; // no-warning + return 0; +} + +int rdar9948787_positive() { + ClassWithStatic classWithStatic; + unsigned value = classWithStatic.value; + if (value == 0) + return 1; + int *p = 0; + *p = 0xDEADBEEF; // expected-warning {{null}} + return 0; +} + |