summaryrefslogtreecommitdiffstats
path: root/clang/lib/StaticAnalyzer/Core/CallEvent.cpp
diff options
context:
space:
mode:
authorJordan Rose <jordan_rose@apple.com>2012-09-05 17:11:26 +0000
committerJordan Rose <jordan_rose@apple.com>2012-09-05 17:11:26 +0000
commitfcdda36149ba4428bef3c6e3985f086c7b5cd939 (patch)
treed907fe55963f41df30917dab5a8fdefce5fd8146 /clang/lib/StaticAnalyzer/Core/CallEvent.cpp
parentd1a08b6e43761ac7f4b38297a271c7320577aacd (diff)
downloadbcm5719-llvm-fcdda36149ba4428bef3c6e3985f086c7b5cd939.tar.gz
bcm5719-llvm-fcdda36149ba4428bef3c6e3985f086c7b5cd939.zip
[analyzer] Be more forgiving about calling methods on struct rvalues.
The problem is that the value of 'this' in a C++ member function call should always be a region (or NULL). However, if the object is an rvalue, it has no associated region (only a conjured symbol or LazyCompoundVal). For now, we handle this in two ways: 1) Actually respect MaterializeTemporaryExpr. Before, it was relying on CXXConstructExpr to create temporary regions for all struct values. Now it just does the right thing: if the value is not in a temporary region, create one. 2) Have CallEvent recognize the case where its 'this' pointer is a non-region, and just return UnknownVal to keep from confusing clients. The long-term problem is being tracked internally in <rdar://problem/12137950>, but this makes many test cases pass. llvm-svn: 163220
Diffstat (limited to 'clang/lib/StaticAnalyzer/Core/CallEvent.cpp')
-rw-r--r--clang/lib/StaticAnalyzer/Core/CallEvent.cpp19
1 files changed, 19 insertions, 0 deletions
diff --git a/clang/lib/StaticAnalyzer/Core/CallEvent.cpp b/clang/lib/StaticAnalyzer/Core/CallEvent.cpp
index 9a2ec0f9c6b..1cfa394a07c 100644
--- a/clang/lib/StaticAnalyzer/Core/CallEvent.cpp
+++ b/clang/lib/StaticAnalyzer/Core/CallEvent.cpp
@@ -384,6 +384,25 @@ void CXXInstanceCall::getExtraInvalidatedRegions(RegionList &Regions) const {
Regions.push_back(R);
}
+SVal CXXInstanceCall::getCXXThisVal() const {
+ const Expr *Base = getCXXThisExpr();
+ // FIXME: This doesn't handle an overloaded ->* operator.
+ if (!Base)
+ return UnknownVal();
+
+ SVal ThisVal = getSVal(Base);
+
+ // FIXME: This is only necessary because we can call member functions on
+ // struct rvalues, which do not have regions we can use for a 'this' pointer.
+ // Ideally this should eventually be changed to an assert, i.e. all
+ // non-Unknown, non-null 'this' values should be loc::MemRegionVals.
+ if (isa<DefinedSVal>(ThisVal))
+ if (!ThisVal.getAsRegion() && !ThisVal.isConstant())
+ return UnknownVal();
+
+ return ThisVal;
+}
+
RuntimeDefinition CXXInstanceCall::getRuntimeDefinition() const {
// Do we have a decl at all?
OpenPOWER on IntegriCloud