blob: acc4111b70ca146a6f8c9c5901512a04926a2908 [file] [log] [blame]
Ted Kremeneka90ccfe2008-01-31 19:34:24 +00001//= RValues.cpp - Abstract RValues for Path-Sens. Value Tracking -*- C++ -*-==//
2//
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//
Zhongxing Xu1c96b242008-10-17 05:57:07 +000010// This file defines SVal, Loc, and NonLoc, classes that represent
Ted Kremeneka90ccfe2008-01-31 19:34:24 +000011// abstract r-values for use with path-sensitive value tracking.
12//
13//===----------------------------------------------------------------------===//
14
Ted Kremenek9e240492008-10-04 05:50:14 +000015#include "clang/Analysis/PathSensitive/GRState.h"
Daniel Dunbarc4a1dea2008-08-11 05:35:13 +000016#include "clang/Basic/IdentifierTable.h"
Ted Kremenekd70d0b02008-02-16 01:12:31 +000017#include "llvm/Support/Streams.h"
Ted Kremeneka90ccfe2008-01-31 19:34:24 +000018
19using namespace clang;
20using llvm::dyn_cast;
21using llvm::cast;
22using llvm::APSInt;
23
24//===----------------------------------------------------------------------===//
Ted Kremeneke0e4ebf2009-03-26 03:35:11 +000025// Symbol iteration within an SVal.
Ted Kremenek90e14812008-02-14 23:25:54 +000026//===----------------------------------------------------------------------===//
Ted Kremeneka6e4d212008-02-01 06:36:40 +000027
Ted Kremenek718c4f72008-04-29 22:17:41 +000028
Ted Kremeneke0e4ebf2009-03-26 03:35:11 +000029//===----------------------------------------------------------------------===//
30// Utility methods.
31//===----------------------------------------------------------------------===//
Ted Kremeneka6e4d212008-02-01 06:36:40 +000032
Ted Kremenek94c96982009-03-03 22:06:47 +000033/// getAsLocSymbol - If this SVal is a location (subclasses Loc) and
34/// wraps a symbol, return that SymbolRef. Otherwise return a SymbolRef
35/// where 'isValid()' returns false.
36SymbolRef SVal::getAsLocSymbol() const {
37 if (const loc::SymbolVal *X = dyn_cast<loc::SymbolVal>(this))
38 return X->getSymbol();
39
40 if (const loc::MemRegionVal *X = dyn_cast<loc::MemRegionVal>(this)) {
41 const MemRegion *R = X->getRegion();
42
43 while (R) {
44 // Blast through region views.
45 if (const TypedViewRegion *View = dyn_cast<TypedViewRegion>(R)) {
46 R = View->getSuperRegion();
47 continue;
48 }
49
50 if (const SymbolicRegion *SymR = dyn_cast<SymbolicRegion>(R))
51 return SymR->getSymbol();
52
53 break;
54 }
55 }
56
Ted Kremeneke0e4ebf2009-03-26 03:35:11 +000057 return 0;
Ted Kremenek94c96982009-03-03 22:06:47 +000058}
59
60/// getAsSymbol - If this Sval wraps a symbol return that SymbolRef.
61/// Otherwise return a SymbolRef where 'isValid()' returns false.
62SymbolRef SVal::getAsSymbol() const {
63 if (const nonloc::SymbolVal *X = dyn_cast<nonloc::SymbolVal>(this))
64 return X->getSymbol();
65
Ted Kremeneke0e4ebf2009-03-26 03:35:11 +000066 if (const nonloc::SymExprVal *X = dyn_cast<nonloc::SymExprVal>(this))
67 if (SymbolRef Y = dyn_cast<SymbolData>(X->getSymbolicExpression()))
68 return Y;
69
Ted Kremenek94c96982009-03-03 22:06:47 +000070 return getAsLocSymbol();
71}
72
Ted Kremeneke0e4ebf2009-03-26 03:35:11 +000073/// getAsSymbolicExpression - If this Sval wraps a symbolic expression then
74/// return that expression. Otherwise return NULL.
75const SymExpr *SVal::getAsSymbolicExpression() const {
76 if (const nonloc::SymExprVal *X = dyn_cast<nonloc::SymExprVal>(this))
77 return X->getSymbolicExpression();
78
79 return getAsSymbol();
80}
81
82bool SVal::symbol_iterator::operator==(const symbol_iterator &X) const {
83 return itr == X.itr;
84}
85
86bool SVal::symbol_iterator::operator!=(const symbol_iterator &X) const {
87 return itr != X.itr;
88}
89
90SVal::symbol_iterator::symbol_iterator(const SymExpr *SE) {
91 itr.push_back(SE);
92 while (!isa<SymbolData>(itr.back())) expand();
93}
94
95SVal::symbol_iterator& SVal::symbol_iterator::operator++() {
96 assert(!itr.empty() && "attempting to iterate on an 'end' iterator");
97 assert(isa<SymbolData>(itr.back()));
98 itr.pop_back();
99 if (!itr.empty())
100 while (!isa<SymbolData>(itr.back())) expand();
101 return *this;
102}
103
104SymbolRef SVal::symbol_iterator::operator*() {
105 assert(!itr.empty() && "attempting to dereference an 'end' iterator");
106 return cast<SymbolData>(itr.back());
107}
108
109void SVal::symbol_iterator::expand() {
110 const SymExpr *SE = itr.back();
111 itr.pop_back();
112
113 if (const SymIntExpr *SIE = dyn_cast<SymIntExpr>(SE)) {
114 itr.push_back(SIE->getLHS());
115 return;
116 }
117 else if (const SymSymExpr *SSE = dyn_cast<SymSymExpr>(SE)) {
118 itr.push_back(SSE->getLHS());
119 itr.push_back(SSE->getRHS());
120 return;
121 }
122
123 assert(false && "unhandled expansion case");
124}
125
Ted Kremenekcf78b6a2008-02-06 22:50:25 +0000126//===----------------------------------------------------------------------===//
Ted Kremeneka6fac4e2008-10-30 18:01:28 +0000127// Other Iterators.
128//===----------------------------------------------------------------------===//
129
130nonloc::CompoundVal::iterator nonloc::CompoundVal::begin() const {
131 return getValue()->begin();
132}
133
134nonloc::CompoundVal::iterator nonloc::CompoundVal::end() const {
135 return getValue()->end();
136}
137
138//===----------------------------------------------------------------------===//
Ted Kremenek40fc5c72008-07-18 15:54:51 +0000139// Useful predicates.
140//===----------------------------------------------------------------------===//
141
Zhongxing Xu1c96b242008-10-17 05:57:07 +0000142bool SVal::isZeroConstant() const {
143 if (isa<loc::ConcreteInt>(*this))
144 return cast<loc::ConcreteInt>(*this).getValue() == 0;
145 else if (isa<nonloc::ConcreteInt>(*this))
146 return cast<nonloc::ConcreteInt>(*this).getValue() == 0;
Ted Kremenek40fc5c72008-07-18 15:54:51 +0000147 else
148 return false;
149}
150
151
152//===----------------------------------------------------------------------===//
Zhongxing Xu1c96b242008-10-17 05:57:07 +0000153// Transfer function dispatch for Non-Locs.
Ted Kremenekcf78b6a2008-02-06 22:50:25 +0000154//===----------------------------------------------------------------------===//
Ted Kremeneka6e4d212008-02-01 06:36:40 +0000155
Zhongxing Xu1c96b242008-10-17 05:57:07 +0000156SVal nonloc::ConcreteInt::EvalBinOp(BasicValueFactory& BasicVals,
Ted Kremenek75b0a1c2008-07-18 15:59:33 +0000157 BinaryOperator::Opcode Op,
Zhongxing Xu1c96b242008-10-17 05:57:07 +0000158 const nonloc::ConcreteInt& R) const {
Ted Kremenekaa1c4e52008-02-21 18:02:17 +0000159
Ted Kremenek75b0a1c2008-07-18 15:59:33 +0000160 const llvm::APSInt* X =
161 BasicVals.EvaluateAPSInt(Op, getValue(), R.getValue());
Ted Kremenek8cc13ea2008-02-28 20:32:03 +0000162
163 if (X)
Zhongxing Xu1c96b242008-10-17 05:57:07 +0000164 return nonloc::ConcreteInt(*X);
Ted Kremenek8cc13ea2008-02-28 20:32:03 +0000165 else
166 return UndefinedVal();
Ted Kremenekcf78b6a2008-02-06 22:50:25 +0000167}
168
Ted Kremenekcf78b6a2008-02-06 22:50:25 +0000169 // Bitwise-Complement.
170
Zhongxing Xu1c96b242008-10-17 05:57:07 +0000171nonloc::ConcreteInt
172nonloc::ConcreteInt::EvalComplement(BasicValueFactory& BasicVals) const {
Ted Kremenek240f1f02008-03-07 20:13:31 +0000173 return BasicVals.getValue(~getValue());
Ted Kremenekcf78b6a2008-02-06 22:50:25 +0000174}
175
Ted Kremenekcf78b6a2008-02-06 22:50:25 +0000176 // Unary Minus.
Ted Kremeneka90ccfe2008-01-31 19:34:24 +0000177
Zhongxing Xu1c96b242008-10-17 05:57:07 +0000178nonloc::ConcreteInt
179nonloc::ConcreteInt::EvalMinus(BasicValueFactory& BasicVals, UnaryOperator* U) const {
Ted Kremenekcf78b6a2008-02-06 22:50:25 +0000180 assert (U->getType() == U->getSubExpr()->getType());
181 assert (U->getType()->isIntegerType());
Ted Kremenek240f1f02008-03-07 20:13:31 +0000182 return BasicVals.getValue(-getValue());
Ted Kremenekc5d3b4c2008-02-04 16:58:30 +0000183}
184
Ted Kremeneka90ccfe2008-01-31 19:34:24 +0000185//===----------------------------------------------------------------------===//
Zhongxing Xu1c96b242008-10-17 05:57:07 +0000186// Transfer function dispatch for Locs.
Ted Kremeneka90ccfe2008-01-31 19:34:24 +0000187//===----------------------------------------------------------------------===//
188
Ted Kremenekccaad9d2008-10-30 17:53:23 +0000189SVal loc::ConcreteInt::EvalBinOp(BasicValueFactory& BasicVals,
190 BinaryOperator::Opcode Op,
191 const loc::ConcreteInt& R) const {
Ted Kremenekcf78b6a2008-02-06 22:50:25 +0000192
193 assert (Op == BinaryOperator::Add || Op == BinaryOperator::Sub ||
194 (Op >= BinaryOperator::LT && Op <= BinaryOperator::NE));
195
Ted Kremenek240f1f02008-03-07 20:13:31 +0000196 const llvm::APSInt* X = BasicVals.EvaluateAPSInt(Op, getValue(), R.getValue());
Ted Kremenek8cc13ea2008-02-28 20:32:03 +0000197
198 if (X)
Zhongxing Xu1c96b242008-10-17 05:57:07 +0000199 return loc::ConcreteInt(*X);
Ted Kremenek8cc13ea2008-02-28 20:32:03 +0000200 else
201 return UndefinedVal();
Ted Kremenekcf78b6a2008-02-06 22:50:25 +0000202}
Ted Kremeneka90ccfe2008-01-31 19:34:24 +0000203
Ted Kremeneka90ccfe2008-01-31 19:34:24 +0000204//===----------------------------------------------------------------------===//
Ted Kremenekda9ae602009-04-08 18:51:08 +0000205// Utility methods for constructing SVals.
206//===----------------------------------------------------------------------===//
207
Ted Kremenek8e5fb282009-04-09 16:46:55 +0000208SVal ValueManager::makeZeroVal(QualType T) {
Ted Kremenekda9ae602009-04-08 18:51:08 +0000209 if (Loc::IsLocType(T))
210 return Loc::MakeNull(BasicVals);
211
212 if (T->isIntegerType())
213 return NonLoc::MakeVal(BasicVals, 0, T);
214
215 // FIXME: Handle floats.
216 // FIXME: Handle structs.
217 return UnknownVal();
218}
219
220//===----------------------------------------------------------------------===//
Zhongxing Xu1c96b242008-10-17 05:57:07 +0000221// Utility methods for constructing Non-Locs.
Ted Kremeneka90ccfe2008-01-31 19:34:24 +0000222//===----------------------------------------------------------------------===//
Zhongxing Xu4193eca2008-12-20 06:32:12 +0000223
224NonLoc NonLoc::MakeVal(SymbolRef sym) {
225 return nonloc::SymbolVal(sym);
226}
227
Ted Kremeneke0e4ebf2009-03-26 03:35:11 +0000228NonLoc NonLoc::MakeVal(SymbolManager& SymMgr, const SymExpr *lhs,
229 BinaryOperator::Opcode op, const APSInt& v, QualType T) {
Zhongxing Xua129eb92009-03-25 05:58:37 +0000230 // The Environment ensures we always get a persistent APSInt in
231 // BasicValueFactory, so we don't need to get the APSInt from
232 // BasicValueFactory again.
Ted Kremeneke0e4ebf2009-03-26 03:35:11 +0000233 assert(!Loc::IsLocType(T));
234 return nonloc::SymExprVal(SymMgr.getSymIntExpr(lhs, op, v, T));
Zhongxing Xua129eb92009-03-25 05:58:37 +0000235}
236
Ted Kremeneke0e4ebf2009-03-26 03:35:11 +0000237NonLoc NonLoc::MakeVal(SymbolManager& SymMgr, const SymExpr *lhs,
238 BinaryOperator::Opcode op, const SymExpr *rhs,
239QualType T) {
Zhongxing Xua129eb92009-03-25 05:58:37 +0000240 assert(SymMgr.getType(lhs) == SymMgr.getType(rhs));
Ted Kremeneke0e4ebf2009-03-26 03:35:11 +0000241 assert(!Loc::IsLocType(T));
242 return nonloc::SymExprVal(SymMgr.getSymSymExpr(lhs, op, rhs, T));
Zhongxing Xua129eb92009-03-25 05:58:37 +0000243}
244
Ted Kremenek14553ab2009-01-30 00:08:43 +0000245NonLoc NonLoc::MakeIntVal(BasicValueFactory& BasicVals, uint64_t X,
246 bool isUnsigned) {
247 return nonloc::ConcreteInt(BasicVals.getIntValue(X, isUnsigned));
Zhongxing Xu6613d082008-11-24 02:18:56 +0000248}
Ted Kremeneka90ccfe2008-01-31 19:34:24 +0000249
Zhongxing Xu8b862732008-11-24 09:38:21 +0000250NonLoc NonLoc::MakeVal(BasicValueFactory& BasicVals, uint64_t X,
251 unsigned BitWidth, bool isUnsigned) {
252 return nonloc::ConcreteInt(BasicVals.getValue(X, BitWidth, isUnsigned));
253}
254
Zhongxing Xu1c96b242008-10-17 05:57:07 +0000255NonLoc NonLoc::MakeVal(BasicValueFactory& BasicVals, uint64_t X, QualType T) {
256 return nonloc::ConcreteInt(BasicVals.getValue(X, T));
Ted Kremeneka90ccfe2008-01-31 19:34:24 +0000257}
258
Zhongxing Xu1c96b242008-10-17 05:57:07 +0000259NonLoc NonLoc::MakeVal(BasicValueFactory& BasicVals, IntegerLiteral* I) {
Ted Kremenekaa1c4e52008-02-21 18:02:17 +0000260
Zhongxing Xu1c96b242008-10-17 05:57:07 +0000261 return nonloc::ConcreteInt(BasicVals.getValue(APSInt(I->getValue(),
Ted Kremenekaa1c4e52008-02-21 18:02:17 +0000262 I->getType()->isUnsignedIntegerType())));
Ted Kremeneka90ccfe2008-01-31 19:34:24 +0000263}
264
Zhongxing Xue8a964b2008-11-22 13:21:46 +0000265NonLoc NonLoc::MakeVal(BasicValueFactory& BasicVals, const llvm::APInt& I,
266 bool isUnsigned) {
267 return nonloc::ConcreteInt(BasicVals.getValue(I, isUnsigned));
268}
269
Zhongxing Xu8b862732008-11-24 09:38:21 +0000270NonLoc NonLoc::MakeVal(BasicValueFactory& BasicVals, const llvm::APSInt& I) {
271 return nonloc::ConcreteInt(BasicVals.getValue(I));
272}
273
Zhongxing Xu1c96b242008-10-17 05:57:07 +0000274NonLoc NonLoc::MakeIntTruthVal(BasicValueFactory& BasicVals, bool b) {
275 return nonloc::ConcreteInt(BasicVals.getTruthValue(b));
Ted Kremenekcf78b6a2008-02-06 22:50:25 +0000276}
277
Ted Kremenek632e8b82008-10-30 17:44:46 +0000278NonLoc NonLoc::MakeCompoundVal(QualType T, llvm::ImmutableList<SVal> Vals,
Zhongxing Xu6764b722008-10-30 04:58:00 +0000279 BasicValueFactory& BasicVals) {
Ted Kremenek632e8b82008-10-30 17:44:46 +0000280 return nonloc::CompoundVal(BasicVals.getCompoundValData(T, Vals));
Zhongxing Xu6764b722008-10-30 04:58:00 +0000281}
282
Ted Kremenek8d7f5482009-04-09 22:22:44 +0000283SVal ValueManager::getRValueSymbolVal(const MemRegion* R) {
Ted Kremenek9ab6b9c2009-01-22 18:23:34 +0000284 SymbolRef sym = SymMgr.getRegionRValueSymbol(R);
285
Ted Kremenekec099f12009-03-18 22:10:22 +0000286 if (const TypedRegion* TR = dyn_cast<TypedRegion>(R)) {
287 QualType T = TR->getRValueType(SymMgr.getContext());
288
289 if (Loc::IsLocType(T))
Ted Kremenek8d7f5482009-04-09 22:22:44 +0000290 return Loc::MakeVal(MemMgr.getSymbolicRegion(sym));
Ted Kremeneka90ccfe2008-01-31 19:34:24 +0000291
Ted Kremenekec099f12009-03-18 22:10:22 +0000292 // Only handle integers for now.
Zhongxing Xu867418f2009-04-09 05:57:11 +0000293 if (T->isIntegerType() && T->isScalarType())
Ted Kremenekec099f12009-03-18 22:10:22 +0000294 return NonLoc::MakeVal(sym);
295 }
296
297 return UnknownVal();
Zhongxing Xueabf7762008-11-19 11:03:17 +0000298}
299
Ted Kremenek8d7f5482009-04-09 22:22:44 +0000300SVal ValueManager::getConjuredSymbolVal(const Expr* E, unsigned Count) {
Ted Kremenekbb9b2712009-03-20 20:10:45 +0000301 QualType T = E->getType();
Zhongxing Xu867418f2009-04-09 05:57:11 +0000302 SymbolRef sym = SymMgr.getConjuredSymbol(E, Count);
303
304 if (Loc::IsLocType(T))
Ted Kremenek8d7f5482009-04-09 22:22:44 +0000305 return Loc::MakeVal(MemMgr.getSymbolicRegion(sym));
Zhongxing Xu867418f2009-04-09 05:57:11 +0000306
307 if (T->isIntegerType() && T->isScalarType())
308 return NonLoc::MakeVal(sym);
Ted Kremenekbb9b2712009-03-20 20:10:45 +0000309
310 return UnknownVal();
311}
312
Ted Kremenek8d7f5482009-04-09 22:22:44 +0000313SVal ValueManager::getConjuredSymbolVal(const Expr* E, QualType T,
314 unsigned Count) {
315
Zhongxing Xufe1635b2009-04-09 06:30:17 +0000316 SymbolRef sym = SymMgr.getConjuredSymbol(E, T, Count);
317
318 if (Loc::IsLocType(T))
Ted Kremenek8d7f5482009-04-09 22:22:44 +0000319 return Loc::MakeVal(MemMgr.getSymbolicRegion(sym));
Zhongxing Xufe1635b2009-04-09 06:30:17 +0000320
321 if (T->isIntegerType() && T->isScalarType())
322 return NonLoc::MakeVal(sym);
323
324 return UnknownVal();
325}
326
Ted Kremenek632e8b82008-10-30 17:44:46 +0000327nonloc::LocAsInteger nonloc::LocAsInteger::Make(BasicValueFactory& Vals, Loc V,
328 unsigned Bits) {
329 return LocAsInteger(Vals.getPersistentSValWithData(V, Bits));
330}
331
Ted Kremenek2a502572008-02-12 21:37:56 +0000332//===----------------------------------------------------------------------===//
Zhongxing Xu1c96b242008-10-17 05:57:07 +0000333// Utility methods for constructing Locs.
Ted Kremenek2a502572008-02-12 21:37:56 +0000334//===----------------------------------------------------------------------===//
335
Zhongxing Xu2fdf5552008-12-09 10:51:19 +0000336Loc Loc::MakeVal(const MemRegion* R) { return loc::MemRegionVal(R); }
337
Zhongxing Xu1c96b242008-10-17 05:57:07 +0000338Loc Loc::MakeVal(AddrLabelExpr* E) { return loc::GotoLabel(E->getLabel()); }
Ted Kremenekcf78b6a2008-02-06 22:50:25 +0000339
Ted Kremenekda9ae602009-04-08 18:51:08 +0000340Loc Loc::MakeNull(BasicValueFactory &BasicVals) {
341 return loc::ConcreteInt(BasicVals.getZeroWithPtrWidth());
342}
343
Ted Kremeneka90ccfe2008-01-31 19:34:24 +0000344//===----------------------------------------------------------------------===//
345// Pretty-Printing.
346//===----------------------------------------------------------------------===//
347
Daniel Dunbar4a77edb2009-03-10 18:00:19 +0000348void SVal::printStdErr() const { print(llvm::errs()); }
Ted Kremenek2a502572008-02-12 21:37:56 +0000349
Zhongxing Xu1c96b242008-10-17 05:57:07 +0000350void SVal::print(std::ostream& Out) const {
Ted Kremenekb8b41612008-10-30 18:35:10 +0000351 llvm::raw_os_ostream out(Out);
352 print(out);
Ted Kremeneka90ccfe2008-01-31 19:34:24 +0000353}
354
Zhongxing Xu9012bff2008-10-24 06:00:12 +0000355void SVal::print(llvm::raw_ostream& Out) const {
356
357 switch (getBaseKind()) {
358
359 case UnknownKind:
360 Out << "Invalid"; break;
361
362 case NonLocKind:
363 cast<NonLoc>(this)->print(Out); break;
364
365 case LocKind:
366 cast<Loc>(this)->print(Out); break;
367
368 case UndefinedKind:
369 Out << "Undefined"; break;
370
371 default:
372 assert (false && "Invalid SVal.");
373 }
374}
375
Zhongxing Xu9012bff2008-10-24 06:00:12 +0000376void NonLoc::print(llvm::raw_ostream& Out) const {
377
378 switch (getSubKind()) {
379
380 case nonloc::ConcreteIntKind:
381 Out << cast<nonloc::ConcreteInt>(this)->getValue().getZExtValue();
382
383 if (cast<nonloc::ConcreteInt>(this)->getValue().isUnsigned())
384 Out << 'U';
385
386 break;
387
388 case nonloc::SymbolValKind:
389 Out << '$' << cast<nonloc::SymbolVal>(this)->getSymbol();
390 break;
391
Ted Kremeneke0e4ebf2009-03-26 03:35:11 +0000392 case nonloc::SymExprValKind: {
393 const nonloc::SymExprVal& C = *cast<nonloc::SymExprVal>(this);
394 const SymExpr *SE = C.getSymbolicExpression();
395 Out << SE;
Zhongxing Xu9012bff2008-10-24 06:00:12 +0000396 break;
397 }
398
399 case nonloc::LocAsIntegerKind: {
400 const nonloc::LocAsInteger& C = *cast<nonloc::LocAsInteger>(this);
401 C.getLoc().print(Out);
402 Out << " [as " << C.getNumBits() << " bit integer]";
403 break;
404 }
405
Ted Kremeneka6fac4e2008-10-30 18:01:28 +0000406 case nonloc::CompoundValKind: {
407 const nonloc::CompoundVal& C = *cast<nonloc::CompoundVal>(this);
Ted Kremenekb8b41612008-10-30 18:35:10 +0000408 Out << " {";
409 bool first = true;
410 for (nonloc::CompoundVal::iterator I=C.begin(), E=C.end(); I!=E; ++I) {
411 if (first) { Out << ' '; first = false; }
412 else Out << ", ";
Ted Kremeneka6fac4e2008-10-30 18:01:28 +0000413 (*I).print(Out);
Ted Kremenekb8b41612008-10-30 18:35:10 +0000414 }
Ted Kremeneka6fac4e2008-10-30 18:01:28 +0000415 Out << " }";
416 break;
417 }
418
Zhongxing Xu9012bff2008-10-24 06:00:12 +0000419 default:
420 assert (false && "Pretty-printed not implemented for this NonLoc.");
421 break;
422 }
423}
424
425void Loc::print(llvm::raw_ostream& Out) const {
426
427 switch (getSubKind()) {
428
429 case loc::ConcreteIntKind:
430 Out << cast<loc::ConcreteInt>(this)->getValue().getZExtValue()
431 << " (Loc)";
432 break;
433
434 case loc::SymbolValKind:
435 Out << '$' << cast<loc::SymbolVal>(this)->getSymbol();
436 break;
437
438 case loc::GotoLabelKind:
439 Out << "&&"
440 << cast<loc::GotoLabel>(this)->getLabel()->getID()->getName();
441 break;
442
443 case loc::MemRegionKind:
444 Out << '&' << cast<loc::MemRegionVal>(this)->getRegion()->getString();
445 break;
446
447 case loc::FuncValKind:
448 Out << "function "
449 << cast<loc::FuncVal>(this)->getDecl()->getIdentifier()->getName();
450 break;
451
Zhongxing Xu9012bff2008-10-24 06:00:12 +0000452 default:
453 assert (false && "Pretty-printing not implemented for this Loc.");
454 break;
455 }
456}