blob: b16e922776e53c6f1b9180cb2fb404c698a4bca5 [file] [log] [blame]
Ted Kremenek53ba0b62009-06-24 23:06:47 +00001//= GRState.cpp - Path-Sensitive "State" for tracking values -----*- C++ -*--=//
Ted Kremenek9153f732008-02-05 07:17:49 +00002//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
Ted Kremenek53ba0b62009-06-24 23:06:47 +000010// This file implements GRState and GRStateManager.
Ted Kremenek9153f732008-02-05 07:17:49 +000011//
12//===----------------------------------------------------------------------===//
13
Benjamin Kramer5e2d2c22010-03-27 21:19:47 +000014#include "clang/Analysis/CFG.h"
Ted Kremenek1309f9a2010-01-25 04:41:41 +000015#include "clang/Checker/PathSensitive/GRStateTrait.h"
16#include "clang/Checker/PathSensitive/GRState.h"
17#include "clang/Checker/PathSensitive/GRTransferFuncs.h"
Chris Lattner405674c2008-08-23 22:23:37 +000018#include "llvm/Support/raw_ostream.h"
Ted Kremenek05125f12008-08-27 23:13:01 +000019
Ted Kremenekf66ea2cd2008-02-04 21:59:22 +000020using namespace clang;
21
Ted Kremenek05125f12008-08-27 23:13:01 +000022// Give the vtable for ConstraintManager somewhere to live.
Ted Kremenek53ba0b62009-06-24 23:06:47 +000023// FIXME: Move this elsewhere.
Ted Kremenek05125f12008-08-27 23:13:01 +000024ConstraintManager::~ConstraintManager() {}
25
Ted Kremenek1c72ef02008-08-16 00:49:49 +000026GRStateManager::~GRStateManager() {
27 for (std::vector<GRState::Printer*>::iterator I=Printers.begin(),
28 E=Printers.end(); I!=E; ++I)
29 delete *I;
Mike Stump1eb44332009-09-09 15:08:12 +000030
Ted Kremenek1c72ef02008-08-16 00:49:49 +000031 for (GDMContextsTy::iterator I=GDMContexts.begin(), E=GDMContexts.end();
32 I!=E; ++I)
33 I->second.second(I->second.first);
34}
35
Ted Kremenek4adc81e2008-08-13 04:27:00 +000036const GRState*
Ted Kremenek2ed14be2008-12-05 00:47:52 +000037GRStateManager::RemoveDeadBindings(const GRState* state, Stmt* Loc,
Zhongxing Xu17ddf1c2010-03-17 03:35:08 +000038 const StackFrameContext *LCtx,
Ted Kremenek241677a2009-01-21 22:26:05 +000039 SymbolReaper& SymReaper) {
40
Ted Kremenekb87d9092008-02-08 19:17:19 +000041 // This code essentially performs a "mark-and-sweep" of the VariableBindings.
42 // The roots are any Block-level exprs and Decls that our liveness algorithm
43 // tells us are live. We then see what Decls they may reference, and keep
44 // those around. This code more than likely can be made faster, and the
45 // frequency of which this method is called should be experimented with
Ted Kremenek9e240492008-10-04 05:50:14 +000046 // for optimum performance.
47 llvm::SmallVector<const MemRegion*, 10> RegionRoots;
Ted Kremenek2ed14be2008-12-05 00:47:52 +000048 GRState NewState = *state;
Ted Kremenekf59bf482008-07-17 18:38:48 +000049
Ted Kremenek0fb0bc42009-08-27 01:39:13 +000050 NewState.Env = EnvMgr.RemoveDeadBindings(NewState.Env, Loc, SymReaper,
Ted Kremenek5dc27462009-03-03 02:51:43 +000051 state, RegionRoots);
Ted Kremenek016f52f2008-02-08 21:10:02 +000052
Ted Kremenekf59bf482008-07-17 18:38:48 +000053 // Clean up the store.
Zhongxing Xu95798982010-05-26 03:27:35 +000054 const GRState *s = StoreMgr->RemoveDeadBindings(NewState, Loc, LCtx,
55 SymReaper, RegionRoots);
Ted Kremenekffdbefd2008-08-17 03:10:22 +000056
Zhongxing Xu95798982010-05-26 03:27:35 +000057 return ConstraintMgr->RemoveDeadBindings(s, SymReaper);
Ted Kremenekb87d9092008-02-08 19:17:19 +000058}
Ted Kremenek862d5bb2008-02-06 00:54:14 +000059
Ted Kremenek76500d02009-06-23 20:38:51 +000060const GRState *GRState::unbindLoc(Loc LV) const {
61 Store OldStore = getStore();
Ted Kremenek0fb0bc42009-08-27 01:39:13 +000062 Store NewStore = getStateManager().StoreMgr->Remove(OldStore, LV);
Mike Stump1eb44332009-09-09 15:08:12 +000063
Ted Kremenek4323a572008-07-10 22:03:41 +000064 if (NewStore == OldStore)
Ted Kremenek76500d02009-06-23 20:38:51 +000065 return this;
Mike Stump1eb44332009-09-09 15:08:12 +000066
Ted Kremenek76500d02009-06-23 20:38:51 +000067 GRState NewSt = *this;
Ted Kremenek4323a572008-07-10 22:03:41 +000068 NewSt.St = NewStore;
Mike Stump1eb44332009-09-09 15:08:12 +000069 return getStateManager().getPersistentState(NewSt);
Ted Kremenek4323a572008-07-10 22:03:41 +000070}
71
Ted Kremenek13976632010-02-08 16:18:51 +000072SVal GRState::getSValAsScalarOrLoc(const MemRegion *R) const {
Ted Kremenek233e9132009-06-24 22:15:30 +000073 // We only want to do fetches from regions that we can actually bind
74 // values. For example, SymbolicRegions of type 'id<...>' cannot
75 // have direct bindings (but their can be bindings on their subregions).
76 if (!R->isBoundable())
77 return UnknownVal();
78
79 if (const TypedRegion *TR = dyn_cast<TypedRegion>(R)) {
Ted Kremenek0fb0bc42009-08-27 01:39:13 +000080 QualType T = TR->getValueType(getStateManager().getContext());
Ted Kremenek233e9132009-06-24 22:15:30 +000081 if (Loc::IsLocType(T) || T->isIntegerType())
Ted Kremenek13976632010-02-08 16:18:51 +000082 return getSVal(R);
Ted Kremenek233e9132009-06-24 22:15:30 +000083 }
84
85 return UnknownVal();
86}
87
Ted Kremenek4f596c22009-06-27 00:24:54 +000088
Ted Kremenek8e029342009-08-27 22:17:37 +000089const GRState *GRState::BindExpr(const Stmt* Ex, SVal V, bool Invalidate) const{
Ted Kremenek0fb0bc42009-08-27 01:39:13 +000090 Environment NewEnv = getStateManager().EnvMgr.BindExpr(Env, Ex, V,
Mike Stump1eb44332009-09-09 15:08:12 +000091 Invalidate);
Ted Kremenek4f596c22009-06-27 00:24:54 +000092 if (NewEnv == Env)
93 return this;
Ted Kremenek6d2c6572009-08-27 22:15:20 +000094
Ted Kremenek4f596c22009-06-27 00:24:54 +000095 GRState NewSt = *this;
96 NewSt.Env = NewEnv;
Ted Kremenek0fb0bc42009-08-27 01:39:13 +000097 return getStateManager().getPersistentState(NewSt);
Ted Kremenek4f596c22009-06-27 00:24:54 +000098}
99
Zhongxing Xu17fd8632009-08-17 06:19:58 +0000100const GRState* GRStateManager::getInitialState(const LocationContext *InitLoc) {
Ted Kremenek6d2c6572009-08-27 22:15:20 +0000101 GRState State(this,
Zhongxing Xuc179a7f2010-03-05 04:45:36 +0000102 EnvMgr.getInitialEnvironment(),
Zhongxing Xu17fd8632009-08-17 06:19:58 +0000103 StoreMgr->getInitialStore(InitLoc),
104 GDMFactory.GetEmptyMap());
Ted Kremenekcaa37242008-08-19 16:51:45 +0000105
Zhongxing Xu17fd8632009-08-17 06:19:58 +0000106 return getPersistentState(State);
Ted Kremenek9153f732008-02-05 07:17:49 +0000107}
108
Ted Kremenek4adc81e2008-08-13 04:27:00 +0000109const GRState* GRStateManager::getPersistentState(GRState& State) {
Mike Stump1eb44332009-09-09 15:08:12 +0000110
Ted Kremenek9153f732008-02-05 07:17:49 +0000111 llvm::FoldingSetNodeID ID;
Mike Stump1eb44332009-09-09 15:08:12 +0000112 State.Profile(ID);
Ted Kremeneke7d22112008-02-11 19:21:59 +0000113 void* InsertPos;
Mike Stump1eb44332009-09-09 15:08:12 +0000114
Ted Kremenek4adc81e2008-08-13 04:27:00 +0000115 if (GRState* I = StateSet.FindNodeOrInsertPos(ID, InsertPos))
Ted Kremenek9153f732008-02-05 07:17:49 +0000116 return I;
Mike Stump1eb44332009-09-09 15:08:12 +0000117
Ted Kremenek4adc81e2008-08-13 04:27:00 +0000118 GRState* I = (GRState*) Alloc.Allocate<GRState>();
Mike Stump1eb44332009-09-09 15:08:12 +0000119 new (I) GRState(State);
Ted Kremenek9153f732008-02-05 07:17:49 +0000120 StateSet.InsertNode(I, InsertPos);
121 return I;
122}
Ted Kremeneke7d22112008-02-11 19:21:59 +0000123
Ted Kremenek67f28532009-06-17 22:02:04 +0000124const GRState* GRState::makeWithStore(Store store) const {
125 GRState NewSt = *this;
Zhongxing Xu4193eca2008-12-20 06:32:12 +0000126 NewSt.St = store;
Ted Kremenek0fb0bc42009-08-27 01:39:13 +0000127 return getStateManager().getPersistentState(NewSt);
Zhongxing Xu4193eca2008-12-20 06:32:12 +0000128}
129
Ted Kremenek1c72ef02008-08-16 00:49:49 +0000130//===----------------------------------------------------------------------===//
131// State pretty-printing.
132//===----------------------------------------------------------------------===//
Ted Kremenek461f9772008-03-11 18:57:24 +0000133
Zhongxing Xuc179a7f2010-03-05 04:45:36 +0000134void GRState::print(llvm::raw_ostream& Out, CFG &C, const char* nl,
Mike Stump1eb44332009-09-09 15:08:12 +0000135 const char* sep) const {
Ted Kremeneka622d8c2008-08-19 22:24:03 +0000136 // Print the store.
Ted Kremenek0fb0bc42009-08-27 01:39:13 +0000137 GRStateManager &Mgr = getStateManager();
138 Mgr.getStoreManager().print(getStore(), Out, nl, sep);
Mike Stump1eb44332009-09-09 15:08:12 +0000139
Ted Kremeneke7d22112008-02-11 19:21:59 +0000140 // Print Subexpression bindings.
Ted Kremeneka622d8c2008-08-19 22:24:03 +0000141 bool isFirst = true;
Mike Stump1eb44332009-09-09 15:08:12 +0000142
143 for (Environment::iterator I = Env.begin(), E = Env.end(); I != E; ++I) {
Ted Kremenek0fb0bc42009-08-27 01:39:13 +0000144 if (C.isBlkExpr(I.getKey()))
145 continue;
Mike Stump1eb44332009-09-09 15:08:12 +0000146
Ted Kremeneke7d22112008-02-11 19:21:59 +0000147 if (isFirst) {
Ted Kremenek59894f92008-03-04 18:30:35 +0000148 Out << nl << nl << "Sub-Expressions:" << nl;
Ted Kremeneke7d22112008-02-11 19:21:59 +0000149 isFirst = false;
150 }
Ted Kremenek59894f92008-03-04 18:30:35 +0000151 else { Out << nl; }
Mike Stump1eb44332009-09-09 15:08:12 +0000152
Ted Kremeneke7d22112008-02-11 19:21:59 +0000153 Out << " (" << (void*) I.getKey() << ") ";
Chris Lattnere4f21422009-06-30 01:26:17 +0000154 LangOptions LO; // FIXME.
155 I.getKey()->printPretty(Out, 0, PrintingPolicy(LO));
Ted Kremenek6f9b3a42009-07-13 23:53:06 +0000156 Out << " : " << I.getData();
Ted Kremeneke7d22112008-02-11 19:21:59 +0000157 }
Mike Stump1eb44332009-09-09 15:08:12 +0000158
Ted Kremeneke7d22112008-02-11 19:21:59 +0000159 // Print block-expression bindings.
Ted Kremeneke7d22112008-02-11 19:21:59 +0000160 isFirst = true;
Ted Kremenek0fb0bc42009-08-27 01:39:13 +0000161
162 for (Environment::iterator I = Env.begin(), E = Env.end(); I != E; ++I) {
163 if (!C.isBlkExpr(I.getKey()))
164 continue;
Ted Kremeneke7d22112008-02-11 19:21:59 +0000165
166 if (isFirst) {
Ted Kremenek59894f92008-03-04 18:30:35 +0000167 Out << nl << nl << "Block-level Expressions:" << nl;
Ted Kremeneke7d22112008-02-11 19:21:59 +0000168 isFirst = false;
169 }
Ted Kremenek59894f92008-03-04 18:30:35 +0000170 else { Out << nl; }
Mike Stump1eb44332009-09-09 15:08:12 +0000171
Ted Kremeneke7d22112008-02-11 19:21:59 +0000172 Out << " (" << (void*) I.getKey() << ") ";
Chris Lattnere4f21422009-06-30 01:26:17 +0000173 LangOptions LO; // FIXME.
174 I.getKey()->printPretty(Out, 0, PrintingPolicy(LO));
Ted Kremenek6f9b3a42009-07-13 23:53:06 +0000175 Out << " : " << I.getData();
Ted Kremeneke7d22112008-02-11 19:21:59 +0000176 }
Mike Stump1eb44332009-09-09 15:08:12 +0000177
Ted Kremenek0fb0bc42009-08-27 01:39:13 +0000178 Mgr.getConstraintManager().print(this, Out, nl, sep);
Mike Stump1eb44332009-09-09 15:08:12 +0000179
Ted Kremenekb65be702009-06-18 01:23:53 +0000180 // Print checker-specific data.
Ted Kremenek0fb0bc42009-08-27 01:39:13 +0000181 for (std::vector<Printer*>::iterator I = Mgr.Printers.begin(),
182 E = Mgr.Printers.end(); I != E; ++I) {
Ted Kremenekb65be702009-06-18 01:23:53 +0000183 (*I)->Print(Out, this, nl, sep);
184 }
Ted Kremeneke7d22112008-02-11 19:21:59 +0000185}
Ted Kremenek729a9a22008-07-17 23:15:45 +0000186
Zhongxing Xuc179a7f2010-03-05 04:45:36 +0000187void GRState::printDOT(llvm::raw_ostream& Out, CFG &C) const {
188 print(Out, C, "\\l", "\\|");
Ted Kremenek1c72ef02008-08-16 00:49:49 +0000189}
190
Zhongxing Xuc179a7f2010-03-05 04:45:36 +0000191void GRState::printStdErr(CFG &C) const {
192 print(llvm::errs(), C);
Ted Kremenek1c72ef02008-08-16 00:49:49 +0000193}
194
Ted Kremenek72cd17f2008-08-14 21:16:54 +0000195//===----------------------------------------------------------------------===//
196// Generic Data Map.
197//===----------------------------------------------------------------------===//
198
199void* const* GRState::FindGDM(void* K) const {
200 return GDM.lookup(K);
201}
202
Ted Kremenek1c72ef02008-08-16 00:49:49 +0000203void*
204GRStateManager::FindGDMContext(void* K,
205 void* (*CreateContext)(llvm::BumpPtrAllocator&),
206 void (*DeleteContext)(void*)) {
Mike Stump1eb44332009-09-09 15:08:12 +0000207
Ted Kremenek1c72ef02008-08-16 00:49:49 +0000208 std::pair<void*, void (*)(void*)>& p = GDMContexts[K];
209 if (!p.first) {
210 p.first = CreateContext(Alloc);
211 p.second = DeleteContext;
212 }
Mike Stump1eb44332009-09-09 15:08:12 +0000213
Ted Kremenek1c72ef02008-08-16 00:49:49 +0000214 return p.first;
215}
216
Zhongxing Xu4230da62008-11-03 05:18:34 +0000217const GRState* GRStateManager::addGDM(const GRState* St, void* Key, void* Data){
Ted Kremenek72cd17f2008-08-14 21:16:54 +0000218 GRState::GenericDataMap M1 = St->getGDM();
219 GRState::GenericDataMap M2 = GDMFactory.Add(M1, Key, Data);
Mike Stump1eb44332009-09-09 15:08:12 +0000220
Ted Kremenek72cd17f2008-08-14 21:16:54 +0000221 if (M1 == M2)
222 return St;
Mike Stump1eb44332009-09-09 15:08:12 +0000223
Ted Kremenek72cd17f2008-08-14 21:16:54 +0000224 GRState NewSt = *St;
225 NewSt.GDM = M2;
226 return getPersistentState(NewSt);
227}
Ted Kremenek584def72008-07-22 00:46:16 +0000228
Zhongxing Xu0541d102010-03-25 01:39:39 +0000229const GRState *GRStateManager::removeGDM(const GRState *state, void *Key) {
230 GRState::GenericDataMap OldM = state->getGDM();
231 GRState::GenericDataMap NewM = GDMFactory.Remove(OldM, Key);
232
233 if (NewM == OldM)
234 return state;
235
236 GRState NewState = *state;
237 NewState.GDM = NewM;
238 return getPersistentState(NewState);
239}
240
Ted Kremenek584def72008-07-22 00:46:16 +0000241//===----------------------------------------------------------------------===//
Ted Kremenek5216ad72009-02-14 03:16:10 +0000242// Utility.
243//===----------------------------------------------------------------------===//
244
Ted Kremenek5dc27462009-03-03 02:51:43 +0000245namespace {
Kovarththanan Rajaratnamba5fb5a2009-11-28 06:07:30 +0000246class ScanReachableSymbols : public SubRegionMap::Visitor {
Ted Kremenek5dc27462009-03-03 02:51:43 +0000247 typedef llvm::DenseSet<const MemRegion*> VisitedRegionsTy;
248
249 VisitedRegionsTy visited;
Ted Kremenek47fed902009-06-18 01:33:24 +0000250 const GRState *state;
Ted Kremenek5dc27462009-03-03 02:51:43 +0000251 SymbolVisitor &visitor;
252 llvm::OwningPtr<SubRegionMap> SRM;
253public:
Mike Stump1eb44332009-09-09 15:08:12 +0000254
Ted Kremenek47fed902009-06-18 01:33:24 +0000255 ScanReachableSymbols(const GRState *st, SymbolVisitor& v)
256 : state(st), visitor(v) {}
Mike Stump1eb44332009-09-09 15:08:12 +0000257
Ted Kremenek5dc27462009-03-03 02:51:43 +0000258 bool scan(nonloc::CompoundVal val);
259 bool scan(SVal val);
260 bool scan(const MemRegion *R);
Mike Stump1eb44332009-09-09 15:08:12 +0000261
Ted Kremenek5dc27462009-03-03 02:51:43 +0000262 // From SubRegionMap::Visitor.
263 bool Visit(const MemRegion* Parent, const MemRegion* SubRegion) {
264 return scan(SubRegion);
265 }
266};
267}
268
269bool ScanReachableSymbols::scan(nonloc::CompoundVal val) {
Ted Kremenek5216ad72009-02-14 03:16:10 +0000270 for (nonloc::CompoundVal::iterator I=val.begin(), E=val.end(); I!=E; ++I)
Ted Kremenek5dc27462009-03-03 02:51:43 +0000271 if (!scan(*I))
272 return false;
Ted Kremenek5216ad72009-02-14 03:16:10 +0000273
274 return true;
275}
Mike Stump1eb44332009-09-09 15:08:12 +0000276
Ted Kremenek5dc27462009-03-03 02:51:43 +0000277bool ScanReachableSymbols::scan(SVal val) {
278 if (loc::MemRegionVal *X = dyn_cast<loc::MemRegionVal>(&val))
279 return scan(X->getRegion());
Ted Kremenek380022d2009-03-30 18:45:36 +0000280
Zhongxing Xu951b3342010-01-11 07:40:00 +0000281 if (nonloc::LocAsInteger *X = dyn_cast<nonloc::LocAsInteger>(&val))
282 return scan(X->getLoc());
283
Ted Kremenek380022d2009-03-30 18:45:36 +0000284 if (SymbolRef Sym = val.getAsSymbol())
285 return visitor.VisitSymbol(Sym);
Mike Stump1eb44332009-09-09 15:08:12 +0000286
Ted Kremenek5216ad72009-02-14 03:16:10 +0000287 if (nonloc::CompoundVal *X = dyn_cast<nonloc::CompoundVal>(&val))
Ted Kremenek5dc27462009-03-03 02:51:43 +0000288 return scan(*X);
Mike Stump1eb44332009-09-09 15:08:12 +0000289
Ted Kremenek5216ad72009-02-14 03:16:10 +0000290 return true;
291}
Mike Stump1eb44332009-09-09 15:08:12 +0000292
Ted Kremenek5dc27462009-03-03 02:51:43 +0000293bool ScanReachableSymbols::scan(const MemRegion *R) {
Ted Kremenek1cb151e2009-03-04 00:13:10 +0000294 if (isa<MemSpaceRegion>(R) || visited.count(R))
Ted Kremenek5dc27462009-03-03 02:51:43 +0000295 return true;
Mike Stump1eb44332009-09-09 15:08:12 +0000296
Ted Kremenek5dc27462009-03-03 02:51:43 +0000297 visited.insert(R);
298
299 // If this is a symbolic region, visit the symbol for the region.
300 if (const SymbolicRegion *SR = dyn_cast<SymbolicRegion>(R))
301 if (!visitor.VisitSymbol(SR->getSymbol()))
302 return false;
Mike Stump1eb44332009-09-09 15:08:12 +0000303
Ted Kremenek5dc27462009-03-03 02:51:43 +0000304 // If this is a subregion, also visit the parent regions.
305 if (const SubRegion *SR = dyn_cast<SubRegion>(R))
Ted Kremenek6076e0a2009-03-03 18:15:30 +0000306 if (!scan(SR->getSuperRegion()))
Ted Kremenek5dc27462009-03-03 02:51:43 +0000307 return false;
Mike Stump1eb44332009-09-09 15:08:12 +0000308
Ted Kremenek5dc27462009-03-03 02:51:43 +0000309 // Now look at the binding to this region (if any).
Ted Kremenek13976632010-02-08 16:18:51 +0000310 if (!scan(state->getSValAsScalarOrLoc(R)))
Ted Kremenek5dc27462009-03-03 02:51:43 +0000311 return false;
Mike Stump1eb44332009-09-09 15:08:12 +0000312
Ted Kremenek5dc27462009-03-03 02:51:43 +0000313 // Now look at the subregions.
314 if (!SRM.get())
Zhongxing Xuf5416bd2010-02-05 05:18:47 +0000315 SRM.reset(state->getStateManager().getStoreManager().
316 getSubRegionMap(state->getStore()));
Mike Stump1eb44332009-09-09 15:08:12 +0000317
Ted Kremenek5dc27462009-03-03 02:51:43 +0000318 return SRM->iterSubRegions(R, *this);
319}
320
Ted Kremenek47fed902009-06-18 01:33:24 +0000321bool GRState::scanReachableSymbols(SVal val, SymbolVisitor& visitor) const {
322 ScanReachableSymbols S(this, visitor);
Ted Kremenek5dc27462009-03-03 02:51:43 +0000323 return S.scan(val);
324}
Ted Kremenek5216ad72009-02-14 03:16:10 +0000325
Ted Kremenek9dce71f2009-11-26 02:32:19 +0000326bool GRState::scanReachableSymbols(const SVal *I, const SVal *E,
327 SymbolVisitor &visitor) const {
328 ScanReachableSymbols S(this, visitor);
329 for ( ; I != E; ++I) {
Ted Kremenek43f19f72009-12-01 17:50:25 +0000330 if (!S.scan(*I))
331 return false;
Ted Kremenek9dce71f2009-11-26 02:32:19 +0000332 }
Ted Kremenek43f19f72009-12-01 17:50:25 +0000333 return true;
Ted Kremenek9dce71f2009-11-26 02:32:19 +0000334}
335
336bool GRState::scanReachableSymbols(const MemRegion * const *I,
337 const MemRegion * const *E,
338 SymbolVisitor &visitor) const {
339 ScanReachableSymbols S(this, visitor);
340 for ( ; I != E; ++I) {
Ted Kremenek43f19f72009-12-01 17:50:25 +0000341 if (!S.scan(*I))
342 return false;
Ted Kremenek9dce71f2009-11-26 02:32:19 +0000343 }
Ted Kremenek43f19f72009-12-01 17:50:25 +0000344 return true;
Ted Kremenek9dce71f2009-11-26 02:32:19 +0000345}
346
Ted Kremenek5216ad72009-02-14 03:16:10 +0000347//===----------------------------------------------------------------------===//
Ted Kremenek584def72008-07-22 00:46:16 +0000348// Queries.
349//===----------------------------------------------------------------------===//
350
Ted Kremenek5f85e172009-07-22 22:35:28 +0000351bool GRStateManager::isEqual(const GRState* state, const Expr* Ex,
Ted Kremenek1c72ef02008-08-16 00:49:49 +0000352 const llvm::APSInt& Y) {
Mike Stump1eb44332009-09-09 15:08:12 +0000353
Ted Kremenek13976632010-02-08 16:18:51 +0000354 SVal V = state->getSVal(Ex);
Mike Stump1eb44332009-09-09 15:08:12 +0000355
Zhongxing Xu1c96b242008-10-17 05:57:07 +0000356 if (loc::ConcreteInt* X = dyn_cast<loc::ConcreteInt>(&V))
Ted Kremenek584def72008-07-22 00:46:16 +0000357 return X->getValue() == Y;
358
Zhongxing Xu1c96b242008-10-17 05:57:07 +0000359 if (nonloc::ConcreteInt* X = dyn_cast<nonloc::ConcreteInt>(&V))
Ted Kremenek584def72008-07-22 00:46:16 +0000360 return X->getValue() == Y;
Mike Stump1eb44332009-09-09 15:08:12 +0000361
Ted Kremenek380022d2009-03-30 18:45:36 +0000362 if (SymbolRef Sym = V.getAsSymbol())
363 return ConstraintMgr->isEqual(state, Sym, Y);
364
Ted Kremenek584def72008-07-22 00:46:16 +0000365 return false;
366}
Mike Stump1eb44332009-09-09 15:08:12 +0000367
Ted Kremenek5f85e172009-07-22 22:35:28 +0000368bool GRStateManager::isEqual(const GRState* state, const Expr* Ex, uint64_t x) {
Ted Kremenek044b6f02009-04-09 16:13:17 +0000369 return isEqual(state, Ex, getBasicVals().getValue(x, Ex->getType()));
Ted Kremenek584def72008-07-22 00:46:16 +0000370}