blob: e911d2c0979ee01b5b3bb0b65dfa261f4e2d1475 [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 {
Ted Kremenek94c96982009-03-03 22:06:47 +000037 if (const loc::MemRegionVal *X = dyn_cast<loc::MemRegionVal>(this)) {
38 const MemRegion *R = X->getRegion();
39
40 while (R) {
41 // Blast through region views.
42 if (const TypedViewRegion *View = dyn_cast<TypedViewRegion>(R)) {
43 R = View->getSuperRegion();
44 continue;
45 }
46
47 if (const SymbolicRegion *SymR = dyn_cast<SymbolicRegion>(R))
48 return SymR->getSymbol();
49
50 break;
51 }
52 }
53
Ted Kremeneke0e4ebf2009-03-26 03:35:11 +000054 return 0;
Ted Kremenek94c96982009-03-03 22:06:47 +000055}
56
57/// getAsSymbol - If this Sval wraps a symbol return that SymbolRef.
58/// Otherwise return a SymbolRef where 'isValid()' returns false.
59SymbolRef SVal::getAsSymbol() const {
60 if (const nonloc::SymbolVal *X = dyn_cast<nonloc::SymbolVal>(this))
61 return X->getSymbol();
62
Ted Kremeneke0e4ebf2009-03-26 03:35:11 +000063 if (const nonloc::SymExprVal *X = dyn_cast<nonloc::SymExprVal>(this))
64 if (SymbolRef Y = dyn_cast<SymbolData>(X->getSymbolicExpression()))
65 return Y;
66
Ted Kremenek94c96982009-03-03 22:06:47 +000067 return getAsLocSymbol();
68}
69
Ted Kremeneke0e4ebf2009-03-26 03:35:11 +000070/// getAsSymbolicExpression - If this Sval wraps a symbolic expression then
71/// return that expression. Otherwise return NULL.
72const SymExpr *SVal::getAsSymbolicExpression() const {
73 if (const nonloc::SymExprVal *X = dyn_cast<nonloc::SymExprVal>(this))
74 return X->getSymbolicExpression();
75
76 return getAsSymbol();
77}
78
79bool SVal::symbol_iterator::operator==(const symbol_iterator &X) const {
80 return itr == X.itr;
81}
82
83bool SVal::symbol_iterator::operator!=(const symbol_iterator &X) const {
84 return itr != X.itr;
85}
86
87SVal::symbol_iterator::symbol_iterator(const SymExpr *SE) {
88 itr.push_back(SE);
89 while (!isa<SymbolData>(itr.back())) expand();
90}
91
92SVal::symbol_iterator& SVal::symbol_iterator::operator++() {
93 assert(!itr.empty() && "attempting to iterate on an 'end' iterator");
94 assert(isa<SymbolData>(itr.back()));
95 itr.pop_back();
96 if (!itr.empty())
97 while (!isa<SymbolData>(itr.back())) expand();
98 return *this;
99}
100
101SymbolRef SVal::symbol_iterator::operator*() {
102 assert(!itr.empty() && "attempting to dereference an 'end' iterator");
103 return cast<SymbolData>(itr.back());
104}
105
106void SVal::symbol_iterator::expand() {
107 const SymExpr *SE = itr.back();
108 itr.pop_back();
109
110 if (const SymIntExpr *SIE = dyn_cast<SymIntExpr>(SE)) {
111 itr.push_back(SIE->getLHS());
112 return;
113 }
114 else if (const SymSymExpr *SSE = dyn_cast<SymSymExpr>(SE)) {
115 itr.push_back(SSE->getLHS());
116 itr.push_back(SSE->getRHS());
117 return;
118 }
119
120 assert(false && "unhandled expansion case");
121}
122
Ted Kremenekcf78b6a2008-02-06 22:50:25 +0000123//===----------------------------------------------------------------------===//
Ted Kremeneka6fac4e2008-10-30 18:01:28 +0000124// Other Iterators.
125//===----------------------------------------------------------------------===//
126
127nonloc::CompoundVal::iterator nonloc::CompoundVal::begin() const {
128 return getValue()->begin();
129}
130
131nonloc::CompoundVal::iterator nonloc::CompoundVal::end() const {
132 return getValue()->end();
133}
134
135//===----------------------------------------------------------------------===//
Ted Kremenek40fc5c72008-07-18 15:54:51 +0000136// Useful predicates.
137//===----------------------------------------------------------------------===//
138
Zhongxing Xu1c96b242008-10-17 05:57:07 +0000139bool SVal::isZeroConstant() const {
140 if (isa<loc::ConcreteInt>(*this))
141 return cast<loc::ConcreteInt>(*this).getValue() == 0;
142 else if (isa<nonloc::ConcreteInt>(*this))
143 return cast<nonloc::ConcreteInt>(*this).getValue() == 0;
Ted Kremenek40fc5c72008-07-18 15:54:51 +0000144 else
145 return false;
146}
147
148
149//===----------------------------------------------------------------------===//
Zhongxing Xu1c96b242008-10-17 05:57:07 +0000150// Transfer function dispatch for Non-Locs.
Ted Kremenekcf78b6a2008-02-06 22:50:25 +0000151//===----------------------------------------------------------------------===//
Ted Kremeneka6e4d212008-02-01 06:36:40 +0000152
Zhongxing Xu1c96b242008-10-17 05:57:07 +0000153SVal nonloc::ConcreteInt::EvalBinOp(BasicValueFactory& BasicVals,
Ted Kremenek75b0a1c2008-07-18 15:59:33 +0000154 BinaryOperator::Opcode Op,
Zhongxing Xu1c96b242008-10-17 05:57:07 +0000155 const nonloc::ConcreteInt& R) const {
Ted Kremenekaa1c4e52008-02-21 18:02:17 +0000156
Ted Kremenek75b0a1c2008-07-18 15:59:33 +0000157 const llvm::APSInt* X =
158 BasicVals.EvaluateAPSInt(Op, getValue(), R.getValue());
Ted Kremenek8cc13ea2008-02-28 20:32:03 +0000159
160 if (X)
Zhongxing Xu1c96b242008-10-17 05:57:07 +0000161 return nonloc::ConcreteInt(*X);
Ted Kremenek8cc13ea2008-02-28 20:32:03 +0000162 else
163 return UndefinedVal();
Ted Kremenekcf78b6a2008-02-06 22:50:25 +0000164}
165
Ted Kremenekcf78b6a2008-02-06 22:50:25 +0000166 // Bitwise-Complement.
167
Zhongxing Xu1c96b242008-10-17 05:57:07 +0000168nonloc::ConcreteInt
169nonloc::ConcreteInt::EvalComplement(BasicValueFactory& BasicVals) const {
Ted Kremenek240f1f02008-03-07 20:13:31 +0000170 return BasicVals.getValue(~getValue());
Ted Kremenekcf78b6a2008-02-06 22:50:25 +0000171}
172
Ted Kremenekcf78b6a2008-02-06 22:50:25 +0000173 // Unary Minus.
Ted Kremeneka90ccfe2008-01-31 19:34:24 +0000174
Zhongxing Xu1c96b242008-10-17 05:57:07 +0000175nonloc::ConcreteInt
176nonloc::ConcreteInt::EvalMinus(BasicValueFactory& BasicVals, UnaryOperator* U) const {
Ted Kremenekcf78b6a2008-02-06 22:50:25 +0000177 assert (U->getType() == U->getSubExpr()->getType());
178 assert (U->getType()->isIntegerType());
Ted Kremenek240f1f02008-03-07 20:13:31 +0000179 return BasicVals.getValue(-getValue());
Ted Kremenekc5d3b4c2008-02-04 16:58:30 +0000180}
181
Ted Kremeneka90ccfe2008-01-31 19:34:24 +0000182//===----------------------------------------------------------------------===//
Zhongxing Xu1c96b242008-10-17 05:57:07 +0000183// Transfer function dispatch for Locs.
Ted Kremeneka90ccfe2008-01-31 19:34:24 +0000184//===----------------------------------------------------------------------===//
185
Ted Kremenekccaad9d2008-10-30 17:53:23 +0000186SVal loc::ConcreteInt::EvalBinOp(BasicValueFactory& BasicVals,
187 BinaryOperator::Opcode Op,
188 const loc::ConcreteInt& R) const {
Ted Kremenekcf78b6a2008-02-06 22:50:25 +0000189
190 assert (Op == BinaryOperator::Add || Op == BinaryOperator::Sub ||
191 (Op >= BinaryOperator::LT && Op <= BinaryOperator::NE));
192
Ted Kremenek240f1f02008-03-07 20:13:31 +0000193 const llvm::APSInt* X = BasicVals.EvaluateAPSInt(Op, getValue(), R.getValue());
Ted Kremenek8cc13ea2008-02-28 20:32:03 +0000194
195 if (X)
Zhongxing Xu1c96b242008-10-17 05:57:07 +0000196 return loc::ConcreteInt(*X);
Ted Kremenek8cc13ea2008-02-28 20:32:03 +0000197 else
198 return UndefinedVal();
Ted Kremenekcf78b6a2008-02-06 22:50:25 +0000199}
Ted Kremeneka90ccfe2008-01-31 19:34:24 +0000200
Ted Kremeneka90ccfe2008-01-31 19:34:24 +0000201//===----------------------------------------------------------------------===//
Ted Kremenekda9ae602009-04-08 18:51:08 +0000202// Utility methods for constructing SVals.
203//===----------------------------------------------------------------------===//
204
Ted Kremenek8e5fb282009-04-09 16:46:55 +0000205SVal ValueManager::makeZeroVal(QualType T) {
Ted Kremenekda9ae602009-04-08 18:51:08 +0000206 if (Loc::IsLocType(T))
207 return Loc::MakeNull(BasicVals);
208
209 if (T->isIntegerType())
210 return NonLoc::MakeVal(BasicVals, 0, T);
211
212 // FIXME: Handle floats.
213 // FIXME: Handle structs.
214 return UnknownVal();
215}
216
217//===----------------------------------------------------------------------===//
Zhongxing Xu1c96b242008-10-17 05:57:07 +0000218// Utility methods for constructing Non-Locs.
Ted Kremeneka90ccfe2008-01-31 19:34:24 +0000219//===----------------------------------------------------------------------===//
Zhongxing Xu4193eca2008-12-20 06:32:12 +0000220
Ted Kremenekfc3388d2009-04-10 18:11:44 +0000221NonLoc ValueManager::makeNonLoc(SymbolRef sym) {
Zhongxing Xu4193eca2008-12-20 06:32:12 +0000222 return nonloc::SymbolVal(sym);
223}
224
Ted Kremenekfc3388d2009-04-10 18:11:44 +0000225NonLoc ValueManager::makeNonLoc(const SymExpr *lhs, BinaryOperator::Opcode op,
226 const APSInt& v, QualType T) {
Zhongxing Xua129eb92009-03-25 05:58:37 +0000227 // The Environment ensures we always get a persistent APSInt in
228 // BasicValueFactory, so we don't need to get the APSInt from
229 // BasicValueFactory again.
Ted Kremeneke0e4ebf2009-03-26 03:35:11 +0000230 assert(!Loc::IsLocType(T));
231 return nonloc::SymExprVal(SymMgr.getSymIntExpr(lhs, op, v, T));
Zhongxing Xua129eb92009-03-25 05:58:37 +0000232}
233
Ted Kremenekfc3388d2009-04-10 18:11:44 +0000234NonLoc ValueManager::makeNonLoc(const SymExpr *lhs, BinaryOperator::Opcode op,
235 const SymExpr *rhs, QualType T) {
Zhongxing Xua129eb92009-03-25 05:58:37 +0000236 assert(SymMgr.getType(lhs) == SymMgr.getType(rhs));
Ted Kremeneke0e4ebf2009-03-26 03:35:11 +0000237 assert(!Loc::IsLocType(T));
238 return nonloc::SymExprVal(SymMgr.getSymSymExpr(lhs, op, rhs, T));
Zhongxing Xua129eb92009-03-25 05:58:37 +0000239}
240
Ted Kremenek14553ab2009-01-30 00:08:43 +0000241NonLoc NonLoc::MakeIntVal(BasicValueFactory& BasicVals, uint64_t X,
242 bool isUnsigned) {
243 return nonloc::ConcreteInt(BasicVals.getIntValue(X, isUnsigned));
Zhongxing Xu6613d082008-11-24 02:18:56 +0000244}
Ted Kremeneka90ccfe2008-01-31 19:34:24 +0000245
Zhongxing Xu8b862732008-11-24 09:38:21 +0000246NonLoc NonLoc::MakeVal(BasicValueFactory& BasicVals, uint64_t X,
247 unsigned BitWidth, bool isUnsigned) {
248 return nonloc::ConcreteInt(BasicVals.getValue(X, BitWidth, isUnsigned));
249}
250
Zhongxing Xu1c96b242008-10-17 05:57:07 +0000251NonLoc NonLoc::MakeVal(BasicValueFactory& BasicVals, uint64_t X, QualType T) {
252 return nonloc::ConcreteInt(BasicVals.getValue(X, T));
Ted Kremeneka90ccfe2008-01-31 19:34:24 +0000253}
254
Zhongxing Xu1c96b242008-10-17 05:57:07 +0000255NonLoc NonLoc::MakeVal(BasicValueFactory& BasicVals, IntegerLiteral* I) {
Ted Kremenekaa1c4e52008-02-21 18:02:17 +0000256
Zhongxing Xu1c96b242008-10-17 05:57:07 +0000257 return nonloc::ConcreteInt(BasicVals.getValue(APSInt(I->getValue(),
Ted Kremenekaa1c4e52008-02-21 18:02:17 +0000258 I->getType()->isUnsignedIntegerType())));
Ted Kremeneka90ccfe2008-01-31 19:34:24 +0000259}
260
Zhongxing Xue8a964b2008-11-22 13:21:46 +0000261NonLoc NonLoc::MakeVal(BasicValueFactory& BasicVals, const llvm::APInt& I,
262 bool isUnsigned) {
263 return nonloc::ConcreteInt(BasicVals.getValue(I, isUnsigned));
264}
265
Zhongxing Xu8b862732008-11-24 09:38:21 +0000266NonLoc NonLoc::MakeVal(BasicValueFactory& BasicVals, const llvm::APSInt& I) {
267 return nonloc::ConcreteInt(BasicVals.getValue(I));
268}
269
Zhongxing Xu1c96b242008-10-17 05:57:07 +0000270NonLoc NonLoc::MakeIntTruthVal(BasicValueFactory& BasicVals, bool b) {
271 return nonloc::ConcreteInt(BasicVals.getTruthValue(b));
Ted Kremenekcf78b6a2008-02-06 22:50:25 +0000272}
273
Ted Kremenek1670e402009-04-11 00:11:10 +0000274NonLoc ValueManager::makeTruthVal(bool b, QualType T) {
275 return nonloc::ConcreteInt(BasicVals.getTruthValue(b, T));
276}
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());
Zhongxing Xuec13d922009-04-10 08:45:10 +0000288
289 // If T is of function pointer type, create a CodeTextRegion wrapping a
290 // symbol.
291 if (T->isFunctionPointerType()) {
292 return Loc::MakeVal(MemMgr.getCodeTextRegion(sym, T));
293 }
Ted Kremenekec099f12009-03-18 22:10:22 +0000294
295 if (Loc::IsLocType(T))
Ted Kremenek8d7f5482009-04-09 22:22:44 +0000296 return Loc::MakeVal(MemMgr.getSymbolicRegion(sym));
Ted Kremeneka90ccfe2008-01-31 19:34:24 +0000297
Ted Kremenekec099f12009-03-18 22:10:22 +0000298 // Only handle integers for now.
Zhongxing Xu867418f2009-04-09 05:57:11 +0000299 if (T->isIntegerType() && T->isScalarType())
Ted Kremenekfc3388d2009-04-10 18:11:44 +0000300 return makeNonLoc(sym);
Ted Kremenekec099f12009-03-18 22:10:22 +0000301 }
302
303 return UnknownVal();
Zhongxing Xueabf7762008-11-19 11:03:17 +0000304}
305
Ted Kremenek8d7f5482009-04-09 22:22:44 +0000306SVal ValueManager::getConjuredSymbolVal(const Expr* E, unsigned Count) {
Ted Kremenekbb9b2712009-03-20 20:10:45 +0000307 QualType T = E->getType();
Zhongxing Xu867418f2009-04-09 05:57:11 +0000308 SymbolRef sym = SymMgr.getConjuredSymbol(E, Count);
309
Zhongxing Xuec13d922009-04-10 08:45:10 +0000310 // If T is of function pointer type, create a CodeTextRegion wrapping a
311 // symbol.
312 if (T->isFunctionPointerType()) {
313 return Loc::MakeVal(MemMgr.getCodeTextRegion(sym, T));
314 }
315
Zhongxing Xu867418f2009-04-09 05:57:11 +0000316 if (Loc::IsLocType(T))
Ted Kremenek8d7f5482009-04-09 22:22:44 +0000317 return Loc::MakeVal(MemMgr.getSymbolicRegion(sym));
Zhongxing Xu867418f2009-04-09 05:57:11 +0000318
319 if (T->isIntegerType() && T->isScalarType())
Ted Kremenekfc3388d2009-04-10 18:11:44 +0000320 return makeNonLoc(sym);
Ted Kremenekbb9b2712009-03-20 20:10:45 +0000321
322 return UnknownVal();
323}
324
Ted Kremenek8d7f5482009-04-09 22:22:44 +0000325SVal ValueManager::getConjuredSymbolVal(const Expr* E, QualType T,
326 unsigned Count) {
327
Zhongxing Xufe1635b2009-04-09 06:30:17 +0000328 SymbolRef sym = SymMgr.getConjuredSymbol(E, T, Count);
329
Zhongxing Xuec13d922009-04-10 08:45:10 +0000330 // If T is of function pointer type, create a CodeTextRegion wrapping a
331 // symbol.
332 if (T->isFunctionPointerType()) {
333 return Loc::MakeVal(MemMgr.getCodeTextRegion(sym, T));
334 }
335
Zhongxing Xufe1635b2009-04-09 06:30:17 +0000336 if (Loc::IsLocType(T))
Ted Kremenek8d7f5482009-04-09 22:22:44 +0000337 return Loc::MakeVal(MemMgr.getSymbolicRegion(sym));
Zhongxing Xufe1635b2009-04-09 06:30:17 +0000338
339 if (T->isIntegerType() && T->isScalarType())
Ted Kremenekfc3388d2009-04-10 18:11:44 +0000340 return makeNonLoc(sym);
Zhongxing Xufe1635b2009-04-09 06:30:17 +0000341
342 return UnknownVal();
343}
344
Zhongxing Xuec13d922009-04-10 08:45:10 +0000345SVal ValueManager::getFunctionPointer(const FunctionDecl* FD) {
346 CodeTextRegion* R
347 = MemMgr.getCodeTextRegion(FD, Context.getPointerType(FD->getType()));
348 return Loc::MakeVal(R);
349}
350
Ted Kremenek632e8b82008-10-30 17:44:46 +0000351nonloc::LocAsInteger nonloc::LocAsInteger::Make(BasicValueFactory& Vals, Loc V,
352 unsigned Bits) {
353 return LocAsInteger(Vals.getPersistentSValWithData(V, Bits));
354}
355
Ted Kremenek2a502572008-02-12 21:37:56 +0000356//===----------------------------------------------------------------------===//
Zhongxing Xu1c96b242008-10-17 05:57:07 +0000357// Utility methods for constructing Locs.
Ted Kremenek2a502572008-02-12 21:37:56 +0000358//===----------------------------------------------------------------------===//
359
Zhongxing Xu2fdf5552008-12-09 10:51:19 +0000360Loc Loc::MakeVal(const MemRegion* R) { return loc::MemRegionVal(R); }
361
Zhongxing Xu1c96b242008-10-17 05:57:07 +0000362Loc Loc::MakeVal(AddrLabelExpr* E) { return loc::GotoLabel(E->getLabel()); }
Ted Kremenekcf78b6a2008-02-06 22:50:25 +0000363
Ted Kremenekda9ae602009-04-08 18:51:08 +0000364Loc Loc::MakeNull(BasicValueFactory &BasicVals) {
365 return loc::ConcreteInt(BasicVals.getZeroWithPtrWidth());
366}
367
Ted Kremeneka90ccfe2008-01-31 19:34:24 +0000368//===----------------------------------------------------------------------===//
369// Pretty-Printing.
370//===----------------------------------------------------------------------===//
371
Daniel Dunbar4a77edb2009-03-10 18:00:19 +0000372void SVal::printStdErr() const { print(llvm::errs()); }
Ted Kremenek2a502572008-02-12 21:37:56 +0000373
Zhongxing Xu1c96b242008-10-17 05:57:07 +0000374void SVal::print(std::ostream& Out) const {
Ted Kremenekb8b41612008-10-30 18:35:10 +0000375 llvm::raw_os_ostream out(Out);
376 print(out);
Ted Kremeneka90ccfe2008-01-31 19:34:24 +0000377}
378
Zhongxing Xu9012bff2008-10-24 06:00:12 +0000379void SVal::print(llvm::raw_ostream& Out) const {
380
381 switch (getBaseKind()) {
382
383 case UnknownKind:
384 Out << "Invalid"; break;
385
386 case NonLocKind:
387 cast<NonLoc>(this)->print(Out); break;
388
389 case LocKind:
390 cast<Loc>(this)->print(Out); break;
391
392 case UndefinedKind:
393 Out << "Undefined"; break;
394
395 default:
396 assert (false && "Invalid SVal.");
397 }
398}
399
Zhongxing Xu9012bff2008-10-24 06:00:12 +0000400void NonLoc::print(llvm::raw_ostream& Out) const {
401
402 switch (getSubKind()) {
403
404 case nonloc::ConcreteIntKind:
405 Out << cast<nonloc::ConcreteInt>(this)->getValue().getZExtValue();
406
407 if (cast<nonloc::ConcreteInt>(this)->getValue().isUnsigned())
408 Out << 'U';
409
410 break;
411
412 case nonloc::SymbolValKind:
413 Out << '$' << cast<nonloc::SymbolVal>(this)->getSymbol();
414 break;
415
Ted Kremeneke0e4ebf2009-03-26 03:35:11 +0000416 case nonloc::SymExprValKind: {
417 const nonloc::SymExprVal& C = *cast<nonloc::SymExprVal>(this);
418 const SymExpr *SE = C.getSymbolicExpression();
419 Out << SE;
Zhongxing Xu9012bff2008-10-24 06:00:12 +0000420 break;
421 }
422
423 case nonloc::LocAsIntegerKind: {
424 const nonloc::LocAsInteger& C = *cast<nonloc::LocAsInteger>(this);
425 C.getLoc().print(Out);
426 Out << " [as " << C.getNumBits() << " bit integer]";
427 break;
428 }
429
Ted Kremeneka6fac4e2008-10-30 18:01:28 +0000430 case nonloc::CompoundValKind: {
431 const nonloc::CompoundVal& C = *cast<nonloc::CompoundVal>(this);
Ted Kremenekb8b41612008-10-30 18:35:10 +0000432 Out << " {";
433 bool first = true;
434 for (nonloc::CompoundVal::iterator I=C.begin(), E=C.end(); I!=E; ++I) {
435 if (first) { Out << ' '; first = false; }
436 else Out << ", ";
Ted Kremeneka6fac4e2008-10-30 18:01:28 +0000437 (*I).print(Out);
Ted Kremenekb8b41612008-10-30 18:35:10 +0000438 }
Ted Kremeneka6fac4e2008-10-30 18:01:28 +0000439 Out << " }";
440 break;
441 }
442
Zhongxing Xu9012bff2008-10-24 06:00:12 +0000443 default:
444 assert (false && "Pretty-printed not implemented for this NonLoc.");
445 break;
446 }
447}
448
449void Loc::print(llvm::raw_ostream& Out) const {
450
451 switch (getSubKind()) {
452
453 case loc::ConcreteIntKind:
454 Out << cast<loc::ConcreteInt>(this)->getValue().getZExtValue()
455 << " (Loc)";
456 break;
457
Zhongxing Xu9012bff2008-10-24 06:00:12 +0000458 case loc::GotoLabelKind:
459 Out << "&&"
460 << cast<loc::GotoLabel>(this)->getLabel()->getID()->getName();
461 break;
462
463 case loc::MemRegionKind:
464 Out << '&' << cast<loc::MemRegionVal>(this)->getRegion()->getString();
465 break;
466
467 case loc::FuncValKind:
468 Out << "function "
469 << cast<loc::FuncVal>(this)->getDecl()->getIdentifier()->getName();
470 break;
471
Zhongxing Xu9012bff2008-10-24 06:00:12 +0000472 default:
473 assert (false && "Pretty-printing not implemented for this Loc.");
474 break;
475 }
476}