blob: ce7d6e2a83888ca23c7d781aec5b403493766641 [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
Ted Kremenek1309f9a2010-01-25 04:41:41 +000014#include "clang/Checker/PathSensitive/GRStateTrait.h"
15#include "clang/Checker/PathSensitive/GRState.h"
16#include "clang/Checker/PathSensitive/GRTransferFuncs.h"
Ted Kremenek05125f12008-08-27 23:13:01 +000017#include "llvm/ADT/SmallSet.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
Zhongxing Xu57d3b762010-03-04 09:04:52 +000026const GRState *GRState::setAnalysisContext(AnalysisContext *ctx) const {
27 GRState NewState = *this;
28 NewState.Env.setAnalysisContext(ctx);
29 return StateMgr->getPersistentState(NewState);
30}
31
Ted Kremenek1c72ef02008-08-16 00:49:49 +000032GRStateManager::~GRStateManager() {
33 for (std::vector<GRState::Printer*>::iterator I=Printers.begin(),
34 E=Printers.end(); I!=E; ++I)
35 delete *I;
Mike Stump1eb44332009-09-09 15:08:12 +000036
Ted Kremenek1c72ef02008-08-16 00:49:49 +000037 for (GDMContextsTy::iterator I=GDMContexts.begin(), E=GDMContexts.end();
38 I!=E; ++I)
39 I->second.second(I->second.first);
40}
41
Ted Kremenek4adc81e2008-08-13 04:27:00 +000042const GRState*
Ted Kremenek2ed14be2008-12-05 00:47:52 +000043GRStateManager::RemoveDeadBindings(const GRState* state, Stmt* Loc,
Ted Kremenek241677a2009-01-21 22:26:05 +000044 SymbolReaper& SymReaper) {
45
Ted Kremenekb87d9092008-02-08 19:17:19 +000046 // This code essentially performs a "mark-and-sweep" of the VariableBindings.
47 // The roots are any Block-level exprs and Decls that our liveness algorithm
48 // tells us are live. We then see what Decls they may reference, and keep
49 // those around. This code more than likely can be made faster, and the
50 // frequency of which this method is called should be experimented with
Ted Kremenek9e240492008-10-04 05:50:14 +000051 // for optimum performance.
52 llvm::SmallVector<const MemRegion*, 10> RegionRoots;
Ted Kremenek2ed14be2008-12-05 00:47:52 +000053 GRState NewState = *state;
Ted Kremenekf59bf482008-07-17 18:38:48 +000054
Ted Kremenek0fb0bc42009-08-27 01:39:13 +000055 NewState.Env = EnvMgr.RemoveDeadBindings(NewState.Env, Loc, SymReaper,
Ted Kremenek5dc27462009-03-03 02:51:43 +000056 state, RegionRoots);
Ted Kremenek016f52f2008-02-08 21:10:02 +000057
Ted Kremenekf59bf482008-07-17 18:38:48 +000058 // Clean up the store.
Zhongxing Xu72119c42010-02-05 05:34:29 +000059 NewState.St = StoreMgr->RemoveDeadBindings(NewState.St, Loc, SymReaper,
60 RegionRoots);
Ted Kremenekffdbefd2008-08-17 03:10:22 +000061
Ted Kremenek2ed14be2008-12-05 00:47:52 +000062 return ConstraintMgr->RemoveDeadBindings(getPersistentState(NewState),
Ted Kremenek241677a2009-01-21 22:26:05 +000063 SymReaper);
Ted Kremenekb87d9092008-02-08 19:17:19 +000064}
Ted Kremenek862d5bb2008-02-06 00:54:14 +000065
Ted Kremenek76500d02009-06-23 20:38:51 +000066const GRState *GRState::unbindLoc(Loc LV) const {
67 Store OldStore = getStore();
Ted Kremenek0fb0bc42009-08-27 01:39:13 +000068 Store NewStore = getStateManager().StoreMgr->Remove(OldStore, LV);
Mike Stump1eb44332009-09-09 15:08:12 +000069
Ted Kremenek4323a572008-07-10 22:03:41 +000070 if (NewStore == OldStore)
Ted Kremenek76500d02009-06-23 20:38:51 +000071 return this;
Mike Stump1eb44332009-09-09 15:08:12 +000072
Ted Kremenek76500d02009-06-23 20:38:51 +000073 GRState NewSt = *this;
Ted Kremenek4323a572008-07-10 22:03:41 +000074 NewSt.St = NewStore;
Mike Stump1eb44332009-09-09 15:08:12 +000075 return getStateManager().getPersistentState(NewSt);
Ted Kremenek4323a572008-07-10 22:03:41 +000076}
77
Ted Kremenek13976632010-02-08 16:18:51 +000078SVal GRState::getSValAsScalarOrLoc(const MemRegion *R) const {
Ted Kremenek233e9132009-06-24 22:15:30 +000079 // We only want to do fetches from regions that we can actually bind
80 // values. For example, SymbolicRegions of type 'id<...>' cannot
81 // have direct bindings (but their can be bindings on their subregions).
82 if (!R->isBoundable())
83 return UnknownVal();
84
85 if (const TypedRegion *TR = dyn_cast<TypedRegion>(R)) {
Ted Kremenek0fb0bc42009-08-27 01:39:13 +000086 QualType T = TR->getValueType(getStateManager().getContext());
Ted Kremenek233e9132009-06-24 22:15:30 +000087 if (Loc::IsLocType(T) || T->isIntegerType())
Ted Kremenek13976632010-02-08 16:18:51 +000088 return getSVal(R);
Ted Kremenek233e9132009-06-24 22:15:30 +000089 }
90
91 return UnknownVal();
92}
93
Ted Kremenek4f596c22009-06-27 00:24:54 +000094
Ted Kremenek8e029342009-08-27 22:17:37 +000095const GRState *GRState::BindExpr(const Stmt* Ex, SVal V, bool Invalidate) const{
Ted Kremenek0fb0bc42009-08-27 01:39:13 +000096 Environment NewEnv = getStateManager().EnvMgr.BindExpr(Env, Ex, V,
Mike Stump1eb44332009-09-09 15:08:12 +000097 Invalidate);
Ted Kremenek4f596c22009-06-27 00:24:54 +000098 if (NewEnv == Env)
99 return this;
Ted Kremenek6d2c6572009-08-27 22:15:20 +0000100
Ted Kremenek4f596c22009-06-27 00:24:54 +0000101 GRState NewSt = *this;
102 NewSt.Env = NewEnv;
Ted Kremenek0fb0bc42009-08-27 01:39:13 +0000103 return getStateManager().getPersistentState(NewSt);
Ted Kremenek4f596c22009-06-27 00:24:54 +0000104}
105
Zhongxing Xu17fd8632009-08-17 06:19:58 +0000106const GRState* GRStateManager::getInitialState(const LocationContext *InitLoc) {
Ted Kremenek6d2c6572009-08-27 22:15:20 +0000107 GRState State(this,
Mike Stump1eb44332009-09-09 15:08:12 +0000108 EnvMgr.getInitialEnvironment(InitLoc->getAnalysisContext()),
Zhongxing Xu17fd8632009-08-17 06:19:58 +0000109 StoreMgr->getInitialStore(InitLoc),
110 GDMFactory.GetEmptyMap());
Ted Kremenekcaa37242008-08-19 16:51:45 +0000111
Zhongxing Xu17fd8632009-08-17 06:19:58 +0000112 return getPersistentState(State);
Ted Kremenek9153f732008-02-05 07:17:49 +0000113}
114
Ted Kremenek4adc81e2008-08-13 04:27:00 +0000115const GRState* GRStateManager::getPersistentState(GRState& State) {
Mike Stump1eb44332009-09-09 15:08:12 +0000116
Ted Kremenek9153f732008-02-05 07:17:49 +0000117 llvm::FoldingSetNodeID ID;
Mike Stump1eb44332009-09-09 15:08:12 +0000118 State.Profile(ID);
Ted Kremeneke7d22112008-02-11 19:21:59 +0000119 void* InsertPos;
Mike Stump1eb44332009-09-09 15:08:12 +0000120
Ted Kremenek4adc81e2008-08-13 04:27:00 +0000121 if (GRState* I = StateSet.FindNodeOrInsertPos(ID, InsertPos))
Ted Kremenek9153f732008-02-05 07:17:49 +0000122 return I;
Mike Stump1eb44332009-09-09 15:08:12 +0000123
Ted Kremenek4adc81e2008-08-13 04:27:00 +0000124 GRState* I = (GRState*) Alloc.Allocate<GRState>();
Mike Stump1eb44332009-09-09 15:08:12 +0000125 new (I) GRState(State);
Ted Kremenek9153f732008-02-05 07:17:49 +0000126 StateSet.InsertNode(I, InsertPos);
127 return I;
128}
Ted Kremeneke7d22112008-02-11 19:21:59 +0000129
Ted Kremenek67f28532009-06-17 22:02:04 +0000130const GRState* GRState::makeWithStore(Store store) const {
131 GRState NewSt = *this;
Zhongxing Xu4193eca2008-12-20 06:32:12 +0000132 NewSt.St = store;
Ted Kremenek0fb0bc42009-08-27 01:39:13 +0000133 return getStateManager().getPersistentState(NewSt);
Zhongxing Xu4193eca2008-12-20 06:32:12 +0000134}
135
Ted Kremenek1c72ef02008-08-16 00:49:49 +0000136//===----------------------------------------------------------------------===//
137// State pretty-printing.
138//===----------------------------------------------------------------------===//
Ted Kremenek461f9772008-03-11 18:57:24 +0000139
Ted Kremenek53ba0b62009-06-24 23:06:47 +0000140void GRState::print(llvm::raw_ostream& Out, const char* nl,
Mike Stump1eb44332009-09-09 15:08:12 +0000141 const char* sep) const {
Ted Kremeneka622d8c2008-08-19 22:24:03 +0000142 // Print the store.
Ted Kremenek0fb0bc42009-08-27 01:39:13 +0000143 GRStateManager &Mgr = getStateManager();
144 Mgr.getStoreManager().print(getStore(), Out, nl, sep);
Mike Stump1eb44332009-09-09 15:08:12 +0000145
Ted Kremenek0fb0bc42009-08-27 01:39:13 +0000146 CFG &C = *getAnalysisContext().getCFG();
Mike Stump1eb44332009-09-09 15:08:12 +0000147
Ted Kremeneke7d22112008-02-11 19:21:59 +0000148 // Print Subexpression bindings.
Ted Kremeneka622d8c2008-08-19 22:24:03 +0000149 bool isFirst = true;
Mike Stump1eb44332009-09-09 15:08:12 +0000150
151 for (Environment::iterator I = Env.begin(), E = Env.end(); I != E; ++I) {
Ted Kremenek0fb0bc42009-08-27 01:39:13 +0000152 if (C.isBlkExpr(I.getKey()))
153 continue;
Mike Stump1eb44332009-09-09 15:08:12 +0000154
Ted Kremeneke7d22112008-02-11 19:21:59 +0000155 if (isFirst) {
Ted Kremenek59894f92008-03-04 18:30:35 +0000156 Out << nl << nl << "Sub-Expressions:" << nl;
Ted Kremeneke7d22112008-02-11 19:21:59 +0000157 isFirst = false;
158 }
Ted Kremenek59894f92008-03-04 18:30:35 +0000159 else { Out << nl; }
Mike Stump1eb44332009-09-09 15:08:12 +0000160
Ted Kremeneke7d22112008-02-11 19:21:59 +0000161 Out << " (" << (void*) I.getKey() << ") ";
Chris Lattnere4f21422009-06-30 01:26:17 +0000162 LangOptions LO; // FIXME.
163 I.getKey()->printPretty(Out, 0, PrintingPolicy(LO));
Ted Kremenek6f9b3a42009-07-13 23:53:06 +0000164 Out << " : " << I.getData();
Ted Kremeneke7d22112008-02-11 19:21:59 +0000165 }
Mike Stump1eb44332009-09-09 15:08:12 +0000166
Ted Kremeneke7d22112008-02-11 19:21:59 +0000167 // Print block-expression bindings.
Ted Kremeneke7d22112008-02-11 19:21:59 +0000168 isFirst = true;
Ted Kremenek0fb0bc42009-08-27 01:39:13 +0000169
170 for (Environment::iterator I = Env.begin(), E = Env.end(); I != E; ++I) {
171 if (!C.isBlkExpr(I.getKey()))
172 continue;
Ted Kremeneke7d22112008-02-11 19:21:59 +0000173
174 if (isFirst) {
Ted Kremenek59894f92008-03-04 18:30:35 +0000175 Out << nl << nl << "Block-level Expressions:" << nl;
Ted Kremeneke7d22112008-02-11 19:21:59 +0000176 isFirst = false;
177 }
Ted Kremenek59894f92008-03-04 18:30:35 +0000178 else { Out << nl; }
Mike Stump1eb44332009-09-09 15:08:12 +0000179
Ted Kremeneke7d22112008-02-11 19:21:59 +0000180 Out << " (" << (void*) I.getKey() << ") ";
Chris Lattnere4f21422009-06-30 01:26:17 +0000181 LangOptions LO; // FIXME.
182 I.getKey()->printPretty(Out, 0, PrintingPolicy(LO));
Ted Kremenek6f9b3a42009-07-13 23:53:06 +0000183 Out << " : " << I.getData();
Ted Kremeneke7d22112008-02-11 19:21:59 +0000184 }
Mike Stump1eb44332009-09-09 15:08:12 +0000185
Ted Kremenek0fb0bc42009-08-27 01:39:13 +0000186 Mgr.getConstraintManager().print(this, Out, nl, sep);
Mike Stump1eb44332009-09-09 15:08:12 +0000187
Ted Kremenekb65be702009-06-18 01:23:53 +0000188 // Print checker-specific data.
Ted Kremenek0fb0bc42009-08-27 01:39:13 +0000189 for (std::vector<Printer*>::iterator I = Mgr.Printers.begin(),
190 E = Mgr.Printers.end(); I != E; ++I) {
Ted Kremenekb65be702009-06-18 01:23:53 +0000191 (*I)->Print(Out, this, nl, sep);
192 }
Ted Kremeneke7d22112008-02-11 19:21:59 +0000193}
Ted Kremenek729a9a22008-07-17 23:15:45 +0000194
Ted Kremenek53ba0b62009-06-24 23:06:47 +0000195void GRState::printDOT(llvm::raw_ostream& Out) const {
Ted Kremenek1c72ef02008-08-16 00:49:49 +0000196 print(Out, "\\l", "\\|");
197}
198
Ted Kremenekb65be702009-06-18 01:23:53 +0000199void GRState::printStdErr() const {
Ted Kremenek53ba0b62009-06-24 23:06:47 +0000200 print(llvm::errs());
Ted Kremenek1c72ef02008-08-16 00:49:49 +0000201}
202
Ted Kremenek72cd17f2008-08-14 21:16:54 +0000203//===----------------------------------------------------------------------===//
204// Generic Data Map.
205//===----------------------------------------------------------------------===//
206
207void* const* GRState::FindGDM(void* K) const {
208 return GDM.lookup(K);
209}
210
Ted Kremenek1c72ef02008-08-16 00:49:49 +0000211void*
212GRStateManager::FindGDMContext(void* K,
213 void* (*CreateContext)(llvm::BumpPtrAllocator&),
214 void (*DeleteContext)(void*)) {
Mike Stump1eb44332009-09-09 15:08:12 +0000215
Ted Kremenek1c72ef02008-08-16 00:49:49 +0000216 std::pair<void*, void (*)(void*)>& p = GDMContexts[K];
217 if (!p.first) {
218 p.first = CreateContext(Alloc);
219 p.second = DeleteContext;
220 }
Mike Stump1eb44332009-09-09 15:08:12 +0000221
Ted Kremenek1c72ef02008-08-16 00:49:49 +0000222 return p.first;
223}
224
Zhongxing Xu4230da62008-11-03 05:18:34 +0000225const GRState* GRStateManager::addGDM(const GRState* St, void* Key, void* Data){
Ted Kremenek72cd17f2008-08-14 21:16:54 +0000226 GRState::GenericDataMap M1 = St->getGDM();
227 GRState::GenericDataMap M2 = GDMFactory.Add(M1, Key, Data);
Mike Stump1eb44332009-09-09 15:08:12 +0000228
Ted Kremenek72cd17f2008-08-14 21:16:54 +0000229 if (M1 == M2)
230 return St;
Mike Stump1eb44332009-09-09 15:08:12 +0000231
Ted Kremenek72cd17f2008-08-14 21:16:54 +0000232 GRState NewSt = *St;
233 NewSt.GDM = M2;
234 return getPersistentState(NewSt);
235}
Ted Kremenek584def72008-07-22 00:46:16 +0000236
237//===----------------------------------------------------------------------===//
Ted Kremenek5216ad72009-02-14 03:16:10 +0000238// Utility.
239//===----------------------------------------------------------------------===//
240
Ted Kremenek5dc27462009-03-03 02:51:43 +0000241namespace {
Kovarththanan Rajaratnamba5fb5a2009-11-28 06:07:30 +0000242class ScanReachableSymbols : public SubRegionMap::Visitor {
Ted Kremenek5dc27462009-03-03 02:51:43 +0000243 typedef llvm::DenseSet<const MemRegion*> VisitedRegionsTy;
244
245 VisitedRegionsTy visited;
Ted Kremenek47fed902009-06-18 01:33:24 +0000246 const GRState *state;
Ted Kremenek5dc27462009-03-03 02:51:43 +0000247 SymbolVisitor &visitor;
248 llvm::OwningPtr<SubRegionMap> SRM;
249public:
Mike Stump1eb44332009-09-09 15:08:12 +0000250
Ted Kremenek47fed902009-06-18 01:33:24 +0000251 ScanReachableSymbols(const GRState *st, SymbolVisitor& v)
252 : state(st), visitor(v) {}
Mike Stump1eb44332009-09-09 15:08:12 +0000253
Ted Kremenek5dc27462009-03-03 02:51:43 +0000254 bool scan(nonloc::CompoundVal val);
255 bool scan(SVal val);
256 bool scan(const MemRegion *R);
Mike Stump1eb44332009-09-09 15:08:12 +0000257
Ted Kremenek5dc27462009-03-03 02:51:43 +0000258 // From SubRegionMap::Visitor.
259 bool Visit(const MemRegion* Parent, const MemRegion* SubRegion) {
260 return scan(SubRegion);
261 }
262};
263}
264
265bool ScanReachableSymbols::scan(nonloc::CompoundVal val) {
Ted Kremenek5216ad72009-02-14 03:16:10 +0000266 for (nonloc::CompoundVal::iterator I=val.begin(), E=val.end(); I!=E; ++I)
Ted Kremenek5dc27462009-03-03 02:51:43 +0000267 if (!scan(*I))
268 return false;
Ted Kremenek5216ad72009-02-14 03:16:10 +0000269
270 return true;
271}
Mike Stump1eb44332009-09-09 15:08:12 +0000272
Ted Kremenek5dc27462009-03-03 02:51:43 +0000273bool ScanReachableSymbols::scan(SVal val) {
274 if (loc::MemRegionVal *X = dyn_cast<loc::MemRegionVal>(&val))
275 return scan(X->getRegion());
Ted Kremenek380022d2009-03-30 18:45:36 +0000276
Zhongxing Xu951b3342010-01-11 07:40:00 +0000277 if (nonloc::LocAsInteger *X = dyn_cast<nonloc::LocAsInteger>(&val))
278 return scan(X->getLoc());
279
Ted Kremenek380022d2009-03-30 18:45:36 +0000280 if (SymbolRef Sym = val.getAsSymbol())
281 return visitor.VisitSymbol(Sym);
Mike Stump1eb44332009-09-09 15:08:12 +0000282
Ted Kremenek5216ad72009-02-14 03:16:10 +0000283 if (nonloc::CompoundVal *X = dyn_cast<nonloc::CompoundVal>(&val))
Ted Kremenek5dc27462009-03-03 02:51:43 +0000284 return scan(*X);
Mike Stump1eb44332009-09-09 15:08:12 +0000285
Ted Kremenek5216ad72009-02-14 03:16:10 +0000286 return true;
287}
Mike Stump1eb44332009-09-09 15:08:12 +0000288
Ted Kremenek5dc27462009-03-03 02:51:43 +0000289bool ScanReachableSymbols::scan(const MemRegion *R) {
Ted Kremenek1cb151e2009-03-04 00:13:10 +0000290 if (isa<MemSpaceRegion>(R) || visited.count(R))
Ted Kremenek5dc27462009-03-03 02:51:43 +0000291 return true;
Mike Stump1eb44332009-09-09 15:08:12 +0000292
Ted Kremenek5dc27462009-03-03 02:51:43 +0000293 visited.insert(R);
294
295 // If this is a symbolic region, visit the symbol for the region.
296 if (const SymbolicRegion *SR = dyn_cast<SymbolicRegion>(R))
297 if (!visitor.VisitSymbol(SR->getSymbol()))
298 return false;
Mike Stump1eb44332009-09-09 15:08:12 +0000299
Ted Kremenek5dc27462009-03-03 02:51:43 +0000300 // If this is a subregion, also visit the parent regions.
301 if (const SubRegion *SR = dyn_cast<SubRegion>(R))
Ted Kremenek6076e0a2009-03-03 18:15:30 +0000302 if (!scan(SR->getSuperRegion()))
Ted Kremenek5dc27462009-03-03 02:51:43 +0000303 return false;
Mike Stump1eb44332009-09-09 15:08:12 +0000304
Ted Kremenek5dc27462009-03-03 02:51:43 +0000305 // Now look at the binding to this region (if any).
Ted Kremenek13976632010-02-08 16:18:51 +0000306 if (!scan(state->getSValAsScalarOrLoc(R)))
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 subregions.
310 if (!SRM.get())
Zhongxing Xuf5416bd2010-02-05 05:18:47 +0000311 SRM.reset(state->getStateManager().getStoreManager().
312 getSubRegionMap(state->getStore()));
Mike Stump1eb44332009-09-09 15:08:12 +0000313
Ted Kremenek5dc27462009-03-03 02:51:43 +0000314 return SRM->iterSubRegions(R, *this);
315}
316
Ted Kremenek47fed902009-06-18 01:33:24 +0000317bool GRState::scanReachableSymbols(SVal val, SymbolVisitor& visitor) const {
318 ScanReachableSymbols S(this, visitor);
Ted Kremenek5dc27462009-03-03 02:51:43 +0000319 return S.scan(val);
320}
Ted Kremenek5216ad72009-02-14 03:16:10 +0000321
Ted Kremenek9dce71f2009-11-26 02:32:19 +0000322bool GRState::scanReachableSymbols(const SVal *I, const SVal *E,
323 SymbolVisitor &visitor) const {
324 ScanReachableSymbols S(this, visitor);
325 for ( ; I != E; ++I) {
Ted Kremenek43f19f72009-12-01 17:50:25 +0000326 if (!S.scan(*I))
327 return false;
Ted Kremenek9dce71f2009-11-26 02:32:19 +0000328 }
Ted Kremenek43f19f72009-12-01 17:50:25 +0000329 return true;
Ted Kremenek9dce71f2009-11-26 02:32:19 +0000330}
331
332bool GRState::scanReachableSymbols(const MemRegion * const *I,
333 const MemRegion * const *E,
334 SymbolVisitor &visitor) const {
335 ScanReachableSymbols S(this, visitor);
336 for ( ; I != E; ++I) {
Ted Kremenek43f19f72009-12-01 17:50:25 +0000337 if (!S.scan(*I))
338 return false;
Ted Kremenek9dce71f2009-11-26 02:32:19 +0000339 }
Ted Kremenek43f19f72009-12-01 17:50:25 +0000340 return true;
Ted Kremenek9dce71f2009-11-26 02:32:19 +0000341}
342
Ted Kremenek5216ad72009-02-14 03:16:10 +0000343//===----------------------------------------------------------------------===//
Ted Kremenek584def72008-07-22 00:46:16 +0000344// Queries.
345//===----------------------------------------------------------------------===//
346
Ted Kremenek5f85e172009-07-22 22:35:28 +0000347bool GRStateManager::isEqual(const GRState* state, const Expr* Ex,
Ted Kremenek1c72ef02008-08-16 00:49:49 +0000348 const llvm::APSInt& Y) {
Mike Stump1eb44332009-09-09 15:08:12 +0000349
Ted Kremenek13976632010-02-08 16:18:51 +0000350 SVal V = state->getSVal(Ex);
Mike Stump1eb44332009-09-09 15:08:12 +0000351
Zhongxing Xu1c96b242008-10-17 05:57:07 +0000352 if (loc::ConcreteInt* X = dyn_cast<loc::ConcreteInt>(&V))
Ted Kremenek584def72008-07-22 00:46:16 +0000353 return X->getValue() == Y;
354
Zhongxing Xu1c96b242008-10-17 05:57:07 +0000355 if (nonloc::ConcreteInt* X = dyn_cast<nonloc::ConcreteInt>(&V))
Ted Kremenek584def72008-07-22 00:46:16 +0000356 return X->getValue() == Y;
Mike Stump1eb44332009-09-09 15:08:12 +0000357
Ted Kremenek380022d2009-03-30 18:45:36 +0000358 if (SymbolRef Sym = V.getAsSymbol())
359 return ConstraintMgr->isEqual(state, Sym, Y);
360
Ted Kremenek584def72008-07-22 00:46:16 +0000361 return false;
362}
Mike Stump1eb44332009-09-09 15:08:12 +0000363
Ted Kremenek5f85e172009-07-22 22:35:28 +0000364bool GRStateManager::isEqual(const GRState* state, const Expr* Ex, uint64_t x) {
Ted Kremenek044b6f02009-04-09 16:13:17 +0000365 return isEqual(state, Ex, getBasicVals().getValue(x, Ex->getType()));
Ted Kremenek584def72008-07-22 00:46:16 +0000366}