aboutsummaryrefslogtreecommitdiff
path: root/lib/Analysis/GRExprEngine.cpp
diff options
context:
space:
mode:
authorTed Kremenek <kremenek@apple.com>2009-04-08 18:51:08 +0000
committerTed Kremenek <kremenek@apple.com>2009-04-08 18:51:08 +0000
commitda9ae6088b9543134a6561a412b79530e290408d (patch)
tree97bd1bb0456b487f80ad4a4e85c69cbb77cb447b /lib/Analysis/GRExprEngine.cpp
parente42ac98bc2d50506216b6ef258594bdaa59c47c1 (diff)
Enhance analyzer reasoning about sending messages to nil. A nil receiver returns 0 for scalars of size <= sizeof(void*).
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@68629 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Analysis/GRExprEngine.cpp')
-rw-r--r--lib/Analysis/GRExprEngine.cpp17
1 files changed, 15 insertions, 2 deletions
diff --git a/lib/Analysis/GRExprEngine.cpp b/lib/Analysis/GRExprEngine.cpp
index 06d61cc4b0..b2dfe68197 100644
--- a/lib/Analysis/GRExprEngine.cpp
+++ b/lib/Analysis/GRExprEngine.cpp
@@ -1682,7 +1682,7 @@ void GRExprEngine::VisitObjCMessageExprDispatchHelper(ObjCMessageExpr* ME,
// "Assume" that the receiver is not NULL.
bool isFeasibleNotNull = false;
- Assume(state, L, true, isFeasibleNotNull);
+ const GRState *StNotNull = Assume(state, L, true, isFeasibleNotNull);
// "Assume" that the receiver is NULL.
bool isFeasibleNull = false;
@@ -1724,8 +1724,21 @@ void GRExprEngine::VisitObjCMessageExprDispatchHelper(ObjCMessageExpr* ME,
NilReceiverLargerThanVoidPtrRetExplicit.insert(N);
}
}
+ else {
+ // Handle the safe cases where the return value is 0 if the receiver
+ // is nil.
+ SVal V = SVal::MakeZero(getBasicVals(), ME->getType());
+ MakeNode(Dst, ME, Pred, BindExpr(StNull, ME, V));
+ }
}
}
+
+ // We have handled the cases where the receiver is nil. The remainder
+ // of this method should assume that the receiver is not nil.
+ if (!isFeasibleNotNull)
+ return;
+
+ state = StNotNull;
}
// Check if the "raise" message was sent.
@@ -2445,7 +2458,7 @@ void GRExprEngine::VisitUnaryOperator(UnaryOperator* U, NodeTy* Pred,
// transfer functions as "0 == E".
if (isa<Loc>(V)) {
- loc::ConcreteInt X(getBasicVals().getZeroWithPtrWidth());
+ Loc X = Loc::MakeNull(getBasicVals());
SVal Result = EvalBinOp(BinaryOperator::EQ, cast<Loc>(V), X,
U->getType());
state = BindExpr(state, U, Result);