blob: 572d5ec555888183b06d17a40b06e434dcae95e3 [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
221NonLoc NonLoc::MakeVal(SymbolRef sym) {
222 return nonloc::SymbolVal(sym);
223}
224
Ted Kremeneke0e4ebf2009-03-26 03:35:11 +0000225NonLoc NonLoc::MakeVal(SymbolManager& SymMgr, const SymExpr *lhs,
226 BinaryOperator::Opcode op, 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 Kremeneke0e4ebf2009-03-26 03:35:11 +0000234NonLoc NonLoc::MakeVal(SymbolManager& SymMgr, const SymExpr *lhs,
235 BinaryOperator::Opcode op, const SymExpr *rhs,
236QualType T) {
Zhongxing Xua129eb92009-03-25 05:58:37 +0000237 assert(SymMgr.getType(lhs) == SymMgr.getType(rhs));
Ted Kremeneke0e4ebf2009-03-26 03:35:11 +0000238 assert(!Loc::IsLocType(T));
239 return nonloc::SymExprVal(SymMgr.getSymSymExpr(lhs, op, rhs, T));
Zhongxing Xua129eb92009-03-25 05:58:37 +0000240}
241
Ted Kremenek14553ab2009-01-30 00:08:43 +0000242NonLoc NonLoc::MakeIntVal(BasicValueFactory& BasicVals, uint64_t X,
243 bool isUnsigned) {
244 return nonloc::ConcreteInt(BasicVals.getIntValue(X, isUnsigned));
Zhongxing Xu6613d082008-11-24 02:18:56 +0000245}
Ted Kremeneka90ccfe2008-01-31 19:34:24 +0000246
Zhongxing Xu8b862732008-11-24 09:38:21 +0000247NonLoc NonLoc::MakeVal(BasicValueFactory& BasicVals, uint64_t X,
248 unsigned BitWidth, bool isUnsigned) {
249 return nonloc::ConcreteInt(BasicVals.getValue(X, BitWidth, isUnsigned));
250}
251
Zhongxing Xu1c96b242008-10-17 05:57:07 +0000252NonLoc NonLoc::MakeVal(BasicValueFactory& BasicVals, uint64_t X, QualType T) {
253 return nonloc::ConcreteInt(BasicVals.getValue(X, T));
Ted Kremeneka90ccfe2008-01-31 19:34:24 +0000254}
255
Zhongxing Xu1c96b242008-10-17 05:57:07 +0000256NonLoc NonLoc::MakeVal(BasicValueFactory& BasicVals, IntegerLiteral* I) {
Ted Kremenekaa1c4e52008-02-21 18:02:17 +0000257
Zhongxing Xu1c96b242008-10-17 05:57:07 +0000258 return nonloc::ConcreteInt(BasicVals.getValue(APSInt(I->getValue(),
Ted Kremenekaa1c4e52008-02-21 18:02:17 +0000259 I->getType()->isUnsignedIntegerType())));
Ted Kremeneka90ccfe2008-01-31 19:34:24 +0000260}
261
Zhongxing Xue8a964b2008-11-22 13:21:46 +0000262NonLoc NonLoc::MakeVal(BasicValueFactory& BasicVals, const llvm::APInt& I,
263 bool isUnsigned) {
264 return nonloc::ConcreteInt(BasicVals.getValue(I, isUnsigned));
265}
266
Zhongxing Xu8b862732008-11-24 09:38:21 +0000267NonLoc NonLoc::MakeVal(BasicValueFactory& BasicVals, const llvm::APSInt& I) {
268 return nonloc::ConcreteInt(BasicVals.getValue(I));
269}
270
Zhongxing Xu1c96b242008-10-17 05:57:07 +0000271NonLoc NonLoc::MakeIntTruthVal(BasicValueFactory& BasicVals, bool b) {
272 return nonloc::ConcreteInt(BasicVals.getTruthValue(b));
Ted Kremenekcf78b6a2008-02-06 22:50:25 +0000273}
274
Ted Kremenek632e8b82008-10-30 17:44:46 +0000275NonLoc NonLoc::MakeCompoundVal(QualType T, llvm::ImmutableList<SVal> Vals,
Zhongxing Xu6764b722008-10-30 04:58:00 +0000276 BasicValueFactory& BasicVals) {
Ted Kremenek632e8b82008-10-30 17:44:46 +0000277 return nonloc::CompoundVal(BasicVals.getCompoundValData(T, Vals));
Zhongxing Xu6764b722008-10-30 04:58:00 +0000278}
279
Ted Kremenek8d7f5482009-04-09 22:22:44 +0000280SVal ValueManager::getRValueSymbolVal(const MemRegion* R) {
Ted Kremenek9ab6b9c2009-01-22 18:23:34 +0000281 SymbolRef sym = SymMgr.getRegionRValueSymbol(R);
282
Ted Kremenekec099f12009-03-18 22:10:22 +0000283 if (const TypedRegion* TR = dyn_cast<TypedRegion>(R)) {
284 QualType T = TR->getRValueType(SymMgr.getContext());
Zhongxing Xuec13d922009-04-10 08:45:10 +0000285
286 // If T is of function pointer type, create a CodeTextRegion wrapping a
287 // symbol.
288 if (T->isFunctionPointerType()) {
289 return Loc::MakeVal(MemMgr.getCodeTextRegion(sym, T));
290 }
Ted Kremenekec099f12009-03-18 22:10:22 +0000291
292 if (Loc::IsLocType(T))
Ted Kremenek8d7f5482009-04-09 22:22:44 +0000293 return Loc::MakeVal(MemMgr.getSymbolicRegion(sym));
Ted Kremeneka90ccfe2008-01-31 19:34:24 +0000294
Ted Kremenekec099f12009-03-18 22:10:22 +0000295 // Only handle integers for now.
Zhongxing Xu867418f2009-04-09 05:57:11 +0000296 if (T->isIntegerType() && T->isScalarType())
Ted Kremenekec099f12009-03-18 22:10:22 +0000297 return NonLoc::MakeVal(sym);
298 }
299
300 return UnknownVal();
Zhongxing Xueabf7762008-11-19 11:03:17 +0000301}
302
Ted Kremenek8d7f5482009-04-09 22:22:44 +0000303SVal ValueManager::getConjuredSymbolVal(const Expr* E, unsigned Count) {
Ted Kremenekbb9b2712009-03-20 20:10:45 +0000304 QualType T = E->getType();
Zhongxing Xu867418f2009-04-09 05:57:11 +0000305 SymbolRef sym = SymMgr.getConjuredSymbol(E, Count);
306
Zhongxing Xuec13d922009-04-10 08:45:10 +0000307 // If T is of function pointer type, create a CodeTextRegion wrapping a
308 // symbol.
309 if (T->isFunctionPointerType()) {
310 return Loc::MakeVal(MemMgr.getCodeTextRegion(sym, T));
311 }
312
Zhongxing Xu867418f2009-04-09 05:57:11 +0000313 if (Loc::IsLocType(T))
Ted Kremenek8d7f5482009-04-09 22:22:44 +0000314 return Loc::MakeVal(MemMgr.getSymbolicRegion(sym));
Zhongxing Xu867418f2009-04-09 05:57:11 +0000315
316 if (T->isIntegerType() && T->isScalarType())
317 return NonLoc::MakeVal(sym);
Ted Kremenekbb9b2712009-03-20 20:10:45 +0000318
319 return UnknownVal();
320}
321
Ted Kremenek8d7f5482009-04-09 22:22:44 +0000322SVal ValueManager::getConjuredSymbolVal(const Expr* E, QualType T,
323 unsigned Count) {
324
Zhongxing Xufe1635b2009-04-09 06:30:17 +0000325 SymbolRef sym = SymMgr.getConjuredSymbol(E, T, Count);
326
Zhongxing Xuec13d922009-04-10 08:45:10 +0000327 // If T is of function pointer type, create a CodeTextRegion wrapping a
328 // symbol.
329 if (T->isFunctionPointerType()) {
330 return Loc::MakeVal(MemMgr.getCodeTextRegion(sym, T));
331 }
332
Zhongxing Xufe1635b2009-04-09 06:30:17 +0000333 if (Loc::IsLocType(T))
Ted Kremenek8d7f5482009-04-09 22:22:44 +0000334 return Loc::MakeVal(MemMgr.getSymbolicRegion(sym));
Zhongxing Xufe1635b2009-04-09 06:30:17 +0000335
336 if (T->isIntegerType() && T->isScalarType())
337 return NonLoc::MakeVal(sym);
338
339 return UnknownVal();
340}
341
Zhongxing Xuec13d922009-04-10 08:45:10 +0000342SVal ValueManager::getFunctionPointer(const FunctionDecl* FD) {
343 CodeTextRegion* R
344 = MemMgr.getCodeTextRegion(FD, Context.getPointerType(FD->getType()));
345 return Loc::MakeVal(R);
346}
347
Ted Kremenek632e8b82008-10-30 17:44:46 +0000348nonloc::LocAsInteger nonloc::LocAsInteger::Make(BasicValueFactory& Vals, Loc V,
349 unsigned Bits) {
350 return LocAsInteger(Vals.getPersistentSValWithData(V, Bits));
351}
352
Ted Kremenek2a502572008-02-12 21:37:56 +0000353//===----------------------------------------------------------------------===//
Zhongxing Xu1c96b242008-10-17 05:57:07 +0000354// Utility methods for constructing Locs.
Ted Kremenek2a502572008-02-12 21:37:56 +0000355//===----------------------------------------------------------------------===//
356
Zhongxing Xu2fdf5552008-12-09 10:51:19 +0000357Loc Loc::MakeVal(const MemRegion* R) { return loc::MemRegionVal(R); }
358
Zhongxing Xu1c96b242008-10-17 05:57:07 +0000359Loc Loc::MakeVal(AddrLabelExpr* E) { return loc::GotoLabel(E->getLabel()); }
Ted Kremenekcf78b6a2008-02-06 22:50:25 +0000360
Ted Kremenekda9ae602009-04-08 18:51:08 +0000361Loc Loc::MakeNull(BasicValueFactory &BasicVals) {
362 return loc::ConcreteInt(BasicVals.getZeroWithPtrWidth());
363}
364
Ted Kremeneka90ccfe2008-01-31 19:34:24 +0000365//===----------------------------------------------------------------------===//
366// Pretty-Printing.
367//===----------------------------------------------------------------------===//
368
Daniel Dunbar4a77edb2009-03-10 18:00:19 +0000369void SVal::printStdErr() const { print(llvm::errs()); }
Ted Kremenek2a502572008-02-12 21:37:56 +0000370
Zhongxing Xu1c96b242008-10-17 05:57:07 +0000371void SVal::print(std::ostream& Out) const {
Ted Kremenekb8b41612008-10-30 18:35:10 +0000372 llvm::raw_os_ostream out(Out);
373 print(out);
Ted Kremeneka90ccfe2008-01-31 19:34:24 +0000374}
375
Zhongxing Xu9012bff2008-10-24 06:00:12 +0000376void SVal::print(llvm::raw_ostream& Out) const {
377
378 switch (getBaseKind()) {
379
380 case UnknownKind:
381 Out << "Invalid"; break;
382
383 case NonLocKind:
384 cast<NonLoc>(this)->print(Out); break;
385
386 case LocKind:
387 cast<Loc>(this)->print(Out); break;
388
389 case UndefinedKind:
390 Out << "Undefined"; break;
391
392 default:
393 assert (false && "Invalid SVal.");
394 }
395}
396
Zhongxing Xu9012bff2008-10-24 06:00:12 +0000397void NonLoc::print(llvm::raw_ostream& Out) const {
398
399 switch (getSubKind()) {
400
401 case nonloc::ConcreteIntKind:
402 Out << cast<nonloc::ConcreteInt>(this)->getValue().getZExtValue();
403
404 if (cast<nonloc::ConcreteInt>(this)->getValue().isUnsigned())
405 Out << 'U';
406
407 break;
408
409 case nonloc::SymbolValKind:
410 Out << '$' << cast<nonloc::SymbolVal>(this)->getSymbol();
411 break;
412
Ted Kremeneke0e4ebf2009-03-26 03:35:11 +0000413 case nonloc::SymExprValKind: {
414 const nonloc::SymExprVal& C = *cast<nonloc::SymExprVal>(this);
415 const SymExpr *SE = C.getSymbolicExpression();
416 Out << SE;
Zhongxing Xu9012bff2008-10-24 06:00:12 +0000417 break;
418 }
419
420 case nonloc::LocAsIntegerKind: {
421 const nonloc::LocAsInteger& C = *cast<nonloc::LocAsInteger>(this);
422 C.getLoc().print(Out);
423 Out << " [as " << C.getNumBits() << " bit integer]";
424 break;
425 }
426
Ted Kremeneka6fac4e2008-10-30 18:01:28 +0000427 case nonloc::CompoundValKind: {
428 const nonloc::CompoundVal& C = *cast<nonloc::CompoundVal>(this);
Ted Kremenekb8b41612008-10-30 18:35:10 +0000429 Out << " {";
430 bool first = true;
431 for (nonloc::CompoundVal::iterator I=C.begin(), E=C.end(); I!=E; ++I) {
432 if (first) { Out << ' '; first = false; }
433 else Out << ", ";
Ted Kremeneka6fac4e2008-10-30 18:01:28 +0000434 (*I).print(Out);
Ted Kremenekb8b41612008-10-30 18:35:10 +0000435 }
Ted Kremeneka6fac4e2008-10-30 18:01:28 +0000436 Out << " }";
437 break;
438 }
439
Zhongxing Xu9012bff2008-10-24 06:00:12 +0000440 default:
441 assert (false && "Pretty-printed not implemented for this NonLoc.");
442 break;
443 }
444}
445
446void Loc::print(llvm::raw_ostream& Out) const {
447
448 switch (getSubKind()) {
449
450 case loc::ConcreteIntKind:
451 Out << cast<loc::ConcreteInt>(this)->getValue().getZExtValue()
452 << " (Loc)";
453 break;
454
Zhongxing Xu9012bff2008-10-24 06:00:12 +0000455 case loc::GotoLabelKind:
456 Out << "&&"
457 << cast<loc::GotoLabel>(this)->getLabel()->getID()->getName();
458 break;
459
460 case loc::MemRegionKind:
461 Out << '&' << cast<loc::MemRegionVal>(this)->getRegion()->getString();
462 break;
463
464 case loc::FuncValKind:
465 Out << "function "
466 << cast<loc::FuncVal>(this)->getDecl()->getIdentifier()->getName();
467 break;
468
Zhongxing Xu9012bff2008-10-24 06:00:12 +0000469 default:
470 assert (false && "Pretty-printing not implemented for this Loc.");
471 break;
472 }
473}