From c52c89a5ebd7e7aea7944a666445807e8be26b1e Mon Sep 17 00:00:00 2001 From: Ted Kremenek Date: Wed, 30 Apr 2008 21:05:35 +0000 Subject: [PATCH] When creating LVals for array entries, canonicalize entries with a 0 index. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@50497 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Analysis/GRExprEngine.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/Analysis/GRExprEngine.cpp b/lib/Analysis/GRExprEngine.cpp index 80e9af3190..877bd09a28 100644 --- a/lib/Analysis/GRExprEngine.cpp +++ b/lib/Analysis/GRExprEngine.cpp @@ -803,7 +803,15 @@ void GRExprEngine::VisitArraySubscriptExpr(ArraySubscriptExpr* A, NodeTy* Pred, ValueState* St = GetState(*I2); RVal BaseV = GetRVal(St, Base); RVal IdxV = GetRVal(St, Idx); - RVal V = lval::ArrayOffset::Make(BasicVals, BaseV, IdxV); + + // If IdxV is 0, return just BaseV. + + bool useBase = false; + + if (nonlval::ConcreteInt* IdxInt = dyn_cast(&IdxV)) + useBase = IdxInt->getValue() == 0; + + RVal V = useBase ? BaseV : lval::ArrayOffset::Make(BasicVals, BaseV,IdxV); if (asLVal) MakeNode(Dst, A, *I2, SetRVal(St, A, V));