Ted Kremenek | a90ccfe | 2008-01-31 19:34:24 +0000 | [diff] [blame] | 1 | //= 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 Xu | 1c96b24 | 2008-10-17 05:57:07 +0000 | [diff] [blame] | 10 | // This file defines SVal, Loc, and NonLoc, classes that represent |
Ted Kremenek | a90ccfe | 2008-01-31 19:34:24 +0000 | [diff] [blame] | 11 | // abstract r-values for use with path-sensitive value tracking. |
| 12 | // |
| 13 | //===----------------------------------------------------------------------===// |
| 14 | |
Ted Kremenek | 9e24049 | 2008-10-04 05:50:14 +0000 | [diff] [blame] | 15 | #include "clang/Analysis/PathSensitive/GRState.h" |
Daniel Dunbar | c4a1dea | 2008-08-11 05:35:13 +0000 | [diff] [blame] | 16 | #include "clang/Basic/IdentifierTable.h" |
Ted Kremenek | d70d0b0 | 2008-02-16 01:12:31 +0000 | [diff] [blame] | 17 | #include "llvm/Support/Streams.h" |
Ted Kremenek | a90ccfe | 2008-01-31 19:34:24 +0000 | [diff] [blame] | 18 | |
| 19 | using namespace clang; |
| 20 | using llvm::dyn_cast; |
| 21 | using llvm::cast; |
| 22 | using llvm::APSInt; |
| 23 | |
| 24 | //===----------------------------------------------------------------------===// |
Ted Kremenek | e0e4ebf | 2009-03-26 03:35:11 +0000 | [diff] [blame] | 25 | // Symbol iteration within an SVal. |
Ted Kremenek | 90e1481 | 2008-02-14 23:25:54 +0000 | [diff] [blame] | 26 | //===----------------------------------------------------------------------===// |
Ted Kremenek | a6e4d21 | 2008-02-01 06:36:40 +0000 | [diff] [blame] | 27 | |
Ted Kremenek | 718c4f7 | 2008-04-29 22:17:41 +0000 | [diff] [blame] | 28 | |
Ted Kremenek | e0e4ebf | 2009-03-26 03:35:11 +0000 | [diff] [blame] | 29 | //===----------------------------------------------------------------------===// |
| 30 | // Utility methods. |
| 31 | //===----------------------------------------------------------------------===// |
Ted Kremenek | a6e4d21 | 2008-02-01 06:36:40 +0000 | [diff] [blame] | 32 | |
Zhongxing Xu | 264e937 | 2009-05-12 10:10:00 +0000 | [diff] [blame] | 33 | bool SVal::hasConjuredSymbol() const { |
| 34 | if (const nonloc::SymbolVal* SV = dyn_cast<nonloc::SymbolVal>(this)) { |
| 35 | SymbolRef sym = SV->getSymbol(); |
| 36 | if (isa<SymbolConjured>(sym)) |
| 37 | return true; |
| 38 | } |
| 39 | |
| 40 | if (const loc::MemRegionVal *RV = dyn_cast<loc::MemRegionVal>(this)) { |
| 41 | const MemRegion *R = RV->getRegion(); |
| 42 | if (const SymbolicRegion *SR = dyn_cast<SymbolicRegion>(R)) { |
| 43 | SymbolRef sym = SR->getSymbol(); |
| 44 | if (isa<SymbolConjured>(sym)) |
| 45 | return true; |
| 46 | } else if (const CodeTextRegion *CTR = dyn_cast<CodeTextRegion>(R)) { |
| 47 | if (CTR->isSymbolic()) { |
| 48 | SymbolRef sym = CTR->getSymbol(); |
| 49 | if (isa<SymbolConjured>(sym)) |
| 50 | return true; |
| 51 | } |
| 52 | } |
| 53 | } |
| 54 | |
| 55 | return false; |
| 56 | } |
| 57 | |
Zhongxing Xu | 369f447 | 2009-04-20 05:24:46 +0000 | [diff] [blame] | 58 | const FunctionDecl* SVal::getAsFunctionDecl() const { |
Zhongxing Xu | 369f447 | 2009-04-20 05:24:46 +0000 | [diff] [blame] | 59 | if (const loc::MemRegionVal* X = dyn_cast<loc::MemRegionVal>(this)) { |
| 60 | const MemRegion* R = X->getRegion(); |
Ted Kremenek | 4abbea6 | 2009-04-21 17:37:26 +0000 | [diff] [blame] | 61 | if (const CodeTextRegion* CTR = R->getAs<CodeTextRegion>()) { |
Zhongxing Xu | 369f447 | 2009-04-20 05:24:46 +0000 | [diff] [blame] | 62 | if (CTR->isDeclared()) |
| 63 | return CTR->getDecl(); |
| 64 | } |
| 65 | } |
| 66 | |
| 67 | return 0; |
| 68 | } |
| 69 | |
Ted Kremenek | 94c9698 | 2009-03-03 22:06:47 +0000 | [diff] [blame] | 70 | /// getAsLocSymbol - If this SVal is a location (subclasses Loc) and |
Zhongxing Xu | 369f447 | 2009-04-20 05:24:46 +0000 | [diff] [blame] | 71 | /// wraps a symbol, return that SymbolRef. Otherwise return 0. |
| 72 | // FIXME: should we consider SymbolRef wrapped in CodeTextRegion? |
Ted Kremenek | 94c9698 | 2009-03-03 22:06:47 +0000 | [diff] [blame] | 73 | SymbolRef SVal::getAsLocSymbol() const { |
Ted Kremenek | 94c9698 | 2009-03-03 22:06:47 +0000 | [diff] [blame] | 74 | if (const loc::MemRegionVal *X = dyn_cast<loc::MemRegionVal>(this)) { |
| 75 | const MemRegion *R = X->getRegion(); |
| 76 | |
| 77 | while (R) { |
| 78 | // Blast through region views. |
| 79 | if (const TypedViewRegion *View = dyn_cast<TypedViewRegion>(R)) { |
| 80 | R = View->getSuperRegion(); |
| 81 | continue; |
| 82 | } |
| 83 | |
| 84 | if (const SymbolicRegion *SymR = dyn_cast<SymbolicRegion>(R)) |
| 85 | return SymR->getSymbol(); |
| 86 | |
| 87 | break; |
| 88 | } |
| 89 | } |
| 90 | |
Ted Kremenek | e0e4ebf | 2009-03-26 03:35:11 +0000 | [diff] [blame] | 91 | return 0; |
Ted Kremenek | 94c9698 | 2009-03-03 22:06:47 +0000 | [diff] [blame] | 92 | } |
| 93 | |
| 94 | /// getAsSymbol - If this Sval wraps a symbol return that SymbolRef. |
Zhongxing Xu | 369f447 | 2009-04-20 05:24:46 +0000 | [diff] [blame] | 95 | /// Otherwise return 0. |
| 96 | // FIXME: should we consider SymbolRef wrapped in CodeTextRegion? |
Ted Kremenek | 94c9698 | 2009-03-03 22:06:47 +0000 | [diff] [blame] | 97 | SymbolRef SVal::getAsSymbol() const { |
| 98 | if (const nonloc::SymbolVal *X = dyn_cast<nonloc::SymbolVal>(this)) |
| 99 | return X->getSymbol(); |
| 100 | |
Ted Kremenek | e0e4ebf | 2009-03-26 03:35:11 +0000 | [diff] [blame] | 101 | if (const nonloc::SymExprVal *X = dyn_cast<nonloc::SymExprVal>(this)) |
| 102 | if (SymbolRef Y = dyn_cast<SymbolData>(X->getSymbolicExpression())) |
| 103 | return Y; |
| 104 | |
Ted Kremenek | 94c9698 | 2009-03-03 22:06:47 +0000 | [diff] [blame] | 105 | return getAsLocSymbol(); |
| 106 | } |
| 107 | |
Ted Kremenek | e0e4ebf | 2009-03-26 03:35:11 +0000 | [diff] [blame] | 108 | /// getAsSymbolicExpression - If this Sval wraps a symbolic expression then |
| 109 | /// return that expression. Otherwise return NULL. |
| 110 | const SymExpr *SVal::getAsSymbolicExpression() const { |
| 111 | if (const nonloc::SymExprVal *X = dyn_cast<nonloc::SymExprVal>(this)) |
| 112 | return X->getSymbolicExpression(); |
| 113 | |
| 114 | return getAsSymbol(); |
| 115 | } |
| 116 | |
Zhongxing Xu | edb883c | 2009-06-30 11:52:40 +0000 | [diff] [blame] | 117 | const MemRegion *SVal::getAsRegion() const { |
| 118 | if (const loc::MemRegionVal *X = dyn_cast<loc::MemRegionVal>(this)) |
| 119 | return X->getRegion(); |
| 120 | |
| 121 | return 0; |
| 122 | } |
| 123 | |
Ted Kremenek | e0e4ebf | 2009-03-26 03:35:11 +0000 | [diff] [blame] | 124 | bool SVal::symbol_iterator::operator==(const symbol_iterator &X) const { |
| 125 | return itr == X.itr; |
| 126 | } |
| 127 | |
| 128 | bool SVal::symbol_iterator::operator!=(const symbol_iterator &X) const { |
| 129 | return itr != X.itr; |
| 130 | } |
| 131 | |
| 132 | SVal::symbol_iterator::symbol_iterator(const SymExpr *SE) { |
| 133 | itr.push_back(SE); |
| 134 | while (!isa<SymbolData>(itr.back())) expand(); |
| 135 | } |
| 136 | |
| 137 | SVal::symbol_iterator& SVal::symbol_iterator::operator++() { |
| 138 | assert(!itr.empty() && "attempting to iterate on an 'end' iterator"); |
| 139 | assert(isa<SymbolData>(itr.back())); |
| 140 | itr.pop_back(); |
| 141 | if (!itr.empty()) |
| 142 | while (!isa<SymbolData>(itr.back())) expand(); |
| 143 | return *this; |
| 144 | } |
| 145 | |
| 146 | SymbolRef SVal::symbol_iterator::operator*() { |
| 147 | assert(!itr.empty() && "attempting to dereference an 'end' iterator"); |
| 148 | return cast<SymbolData>(itr.back()); |
| 149 | } |
| 150 | |
| 151 | void SVal::symbol_iterator::expand() { |
| 152 | const SymExpr *SE = itr.back(); |
| 153 | itr.pop_back(); |
| 154 | |
| 155 | if (const SymIntExpr *SIE = dyn_cast<SymIntExpr>(SE)) { |
| 156 | itr.push_back(SIE->getLHS()); |
| 157 | return; |
| 158 | } |
| 159 | else if (const SymSymExpr *SSE = dyn_cast<SymSymExpr>(SE)) { |
| 160 | itr.push_back(SSE->getLHS()); |
| 161 | itr.push_back(SSE->getRHS()); |
| 162 | return; |
| 163 | } |
| 164 | |
| 165 | assert(false && "unhandled expansion case"); |
| 166 | } |
| 167 | |
Ted Kremenek | cf78b6a | 2008-02-06 22:50:25 +0000 | [diff] [blame] | 168 | //===----------------------------------------------------------------------===// |
Ted Kremenek | a6fac4e | 2008-10-30 18:01:28 +0000 | [diff] [blame] | 169 | // Other Iterators. |
| 170 | //===----------------------------------------------------------------------===// |
| 171 | |
| 172 | nonloc::CompoundVal::iterator nonloc::CompoundVal::begin() const { |
| 173 | return getValue()->begin(); |
| 174 | } |
| 175 | |
| 176 | nonloc::CompoundVal::iterator nonloc::CompoundVal::end() const { |
| 177 | return getValue()->end(); |
| 178 | } |
| 179 | |
| 180 | //===----------------------------------------------------------------------===// |
Ted Kremenek | 40fc5c7 | 2008-07-18 15:54:51 +0000 | [diff] [blame] | 181 | // Useful predicates. |
| 182 | //===----------------------------------------------------------------------===// |
| 183 | |
Zhongxing Xu | 1c96b24 | 2008-10-17 05:57:07 +0000 | [diff] [blame] | 184 | bool SVal::isZeroConstant() const { |
| 185 | if (isa<loc::ConcreteInt>(*this)) |
| 186 | return cast<loc::ConcreteInt>(*this).getValue() == 0; |
| 187 | else if (isa<nonloc::ConcreteInt>(*this)) |
| 188 | return cast<nonloc::ConcreteInt>(*this).getValue() == 0; |
Ted Kremenek | 40fc5c7 | 2008-07-18 15:54:51 +0000 | [diff] [blame] | 189 | else |
| 190 | return false; |
| 191 | } |
| 192 | |
| 193 | |
| 194 | //===----------------------------------------------------------------------===// |
Zhongxing Xu | 1c96b24 | 2008-10-17 05:57:07 +0000 | [diff] [blame] | 195 | // Transfer function dispatch for Non-Locs. |
Ted Kremenek | cf78b6a | 2008-02-06 22:50:25 +0000 | [diff] [blame] | 196 | //===----------------------------------------------------------------------===// |
Ted Kremenek | a6e4d21 | 2008-02-01 06:36:40 +0000 | [diff] [blame] | 197 | |
Ted Kremenek | 6c07bdb | 2009-06-26 00:05:51 +0000 | [diff] [blame] | 198 | SVal nonloc::ConcreteInt::evalBinOp(ValueManager &ValMgr, |
| 199 | BinaryOperator::Opcode Op, |
| 200 | const nonloc::ConcreteInt& R) const { |
Ted Kremenek | 75b0a1c | 2008-07-18 15:59:33 +0000 | [diff] [blame] | 201 | const llvm::APSInt* X = |
Ted Kremenek | 6c07bdb | 2009-06-26 00:05:51 +0000 | [diff] [blame] | 202 | ValMgr.getBasicValueFactory().EvaluateAPSInt(Op, getValue(), R.getValue()); |
Ted Kremenek | 8cc13ea | 2008-02-28 20:32:03 +0000 | [diff] [blame] | 203 | |
| 204 | if (X) |
Zhongxing Xu | 1c96b24 | 2008-10-17 05:57:07 +0000 | [diff] [blame] | 205 | return nonloc::ConcreteInt(*X); |
Ted Kremenek | 8cc13ea | 2008-02-28 20:32:03 +0000 | [diff] [blame] | 206 | else |
| 207 | return UndefinedVal(); |
Ted Kremenek | cf78b6a | 2008-02-06 22:50:25 +0000 | [diff] [blame] | 208 | } |
| 209 | |
Zhongxing Xu | 1c96b24 | 2008-10-17 05:57:07 +0000 | [diff] [blame] | 210 | nonloc::ConcreteInt |
Ted Kremenek | 6c07bdb | 2009-06-26 00:05:51 +0000 | [diff] [blame] | 211 | nonloc::ConcreteInt::evalComplement(ValueManager &ValMgr) const { |
| 212 | return ValMgr.makeIntVal(~getValue()); |
Ted Kremenek | cf78b6a | 2008-02-06 22:50:25 +0000 | [diff] [blame] | 213 | } |
| 214 | |
Ted Kremenek | 6c07bdb | 2009-06-26 00:05:51 +0000 | [diff] [blame] | 215 | nonloc::ConcreteInt nonloc::ConcreteInt::evalMinus(ValueManager &ValMgr) const { |
| 216 | return ValMgr.makeIntVal(-getValue()); |
Ted Kremenek | c5d3b4c | 2008-02-04 16:58:30 +0000 | [diff] [blame] | 217 | } |
| 218 | |
Ted Kremenek | a90ccfe | 2008-01-31 19:34:24 +0000 | [diff] [blame] | 219 | //===----------------------------------------------------------------------===// |
Zhongxing Xu | 1c96b24 | 2008-10-17 05:57:07 +0000 | [diff] [blame] | 220 | // Transfer function dispatch for Locs. |
Ted Kremenek | a90ccfe | 2008-01-31 19:34:24 +0000 | [diff] [blame] | 221 | //===----------------------------------------------------------------------===// |
| 222 | |
Ted Kremenek | ccaad9d | 2008-10-30 17:53:23 +0000 | [diff] [blame] | 223 | SVal loc::ConcreteInt::EvalBinOp(BasicValueFactory& BasicVals, |
| 224 | BinaryOperator::Opcode Op, |
| 225 | const loc::ConcreteInt& R) const { |
Ted Kremenek | cf78b6a | 2008-02-06 22:50:25 +0000 | [diff] [blame] | 226 | |
| 227 | assert (Op == BinaryOperator::Add || Op == BinaryOperator::Sub || |
| 228 | (Op >= BinaryOperator::LT && Op <= BinaryOperator::NE)); |
| 229 | |
Ted Kremenek | 240f1f0 | 2008-03-07 20:13:31 +0000 | [diff] [blame] | 230 | const llvm::APSInt* X = BasicVals.EvaluateAPSInt(Op, getValue(), R.getValue()); |
Ted Kremenek | 8cc13ea | 2008-02-28 20:32:03 +0000 | [diff] [blame] | 231 | |
| 232 | if (X) |
Zhongxing Xu | 1c96b24 | 2008-10-17 05:57:07 +0000 | [diff] [blame] | 233 | return loc::ConcreteInt(*X); |
Ted Kremenek | 8cc13ea | 2008-02-28 20:32:03 +0000 | [diff] [blame] | 234 | else |
| 235 | return UndefinedVal(); |
Ted Kremenek | cf78b6a | 2008-02-06 22:50:25 +0000 | [diff] [blame] | 236 | } |
Ted Kremenek | a90ccfe | 2008-01-31 19:34:24 +0000 | [diff] [blame] | 237 | |
Ted Kremenek | a90ccfe | 2008-01-31 19:34:24 +0000 | [diff] [blame] | 238 | //===----------------------------------------------------------------------===// |
| 239 | // Pretty-Printing. |
| 240 | //===----------------------------------------------------------------------===// |
| 241 | |
Ted Kremenek | 6f9b3a4 | 2009-07-13 23:53:06 +0000 | [diff] [blame] | 242 | void SVal::dump() const { dumpToStream(llvm::errs()); } |
Ted Kremenek | 2a50257 | 2008-02-12 21:37:56 +0000 | [diff] [blame] | 243 | |
Ted Kremenek | 6f9b3a4 | 2009-07-13 23:53:06 +0000 | [diff] [blame] | 244 | void SVal::dumpToStream(llvm::raw_ostream& os) const { |
| 245 | switch (getBaseKind()) { |
Zhongxing Xu | 9012bff | 2008-10-24 06:00:12 +0000 | [diff] [blame] | 246 | case UnknownKind: |
Ted Kremenek | 6f9b3a4 | 2009-07-13 23:53:06 +0000 | [diff] [blame] | 247 | os << "Invalid"; |
| 248 | break; |
Zhongxing Xu | 9012bff | 2008-10-24 06:00:12 +0000 | [diff] [blame] | 249 | case NonLocKind: |
Ted Kremenek | 6f9b3a4 | 2009-07-13 23:53:06 +0000 | [diff] [blame] | 250 | cast<NonLoc>(this)->dumpToStream(os); |
| 251 | break; |
Zhongxing Xu | 9012bff | 2008-10-24 06:00:12 +0000 | [diff] [blame] | 252 | case LocKind: |
Ted Kremenek | 6f9b3a4 | 2009-07-13 23:53:06 +0000 | [diff] [blame] | 253 | cast<Loc>(this)->dumpToStream(os); |
| 254 | break; |
Zhongxing Xu | 9012bff | 2008-10-24 06:00:12 +0000 | [diff] [blame] | 255 | case UndefinedKind: |
Ted Kremenek | 6f9b3a4 | 2009-07-13 23:53:06 +0000 | [diff] [blame] | 256 | os << "Undefined"; |
| 257 | break; |
Zhongxing Xu | 9012bff | 2008-10-24 06:00:12 +0000 | [diff] [blame] | 258 | default: |
| 259 | assert (false && "Invalid SVal."); |
| 260 | } |
| 261 | } |
| 262 | |
Ted Kremenek | 6f9b3a4 | 2009-07-13 23:53:06 +0000 | [diff] [blame] | 263 | void NonLoc::dumpToStream(llvm::raw_ostream& os) const { |
Zhongxing Xu | 9012bff | 2008-10-24 06:00:12 +0000 | [diff] [blame] | 264 | switch (getSubKind()) { |
Zhongxing Xu | 9012bff | 2008-10-24 06:00:12 +0000 | [diff] [blame] | 265 | case nonloc::ConcreteIntKind: |
Ted Kremenek | 6f9b3a4 | 2009-07-13 23:53:06 +0000 | [diff] [blame] | 266 | os << cast<nonloc::ConcreteInt>(this)->getValue().getZExtValue(); |
Zhongxing Xu | 9012bff | 2008-10-24 06:00:12 +0000 | [diff] [blame] | 267 | if (cast<nonloc::ConcreteInt>(this)->getValue().isUnsigned()) |
Ted Kremenek | 6f9b3a4 | 2009-07-13 23:53:06 +0000 | [diff] [blame] | 268 | os << 'U'; |
| 269 | break; |
Zhongxing Xu | 9012bff | 2008-10-24 06:00:12 +0000 | [diff] [blame] | 270 | case nonloc::SymbolValKind: |
Ted Kremenek | 6f9b3a4 | 2009-07-13 23:53:06 +0000 | [diff] [blame] | 271 | os << '$' << cast<nonloc::SymbolVal>(this)->getSymbol(); |
| 272 | break; |
Ted Kremenek | e0e4ebf | 2009-03-26 03:35:11 +0000 | [diff] [blame] | 273 | case nonloc::SymExprValKind: { |
| 274 | const nonloc::SymExprVal& C = *cast<nonloc::SymExprVal>(this); |
| 275 | const SymExpr *SE = C.getSymbolicExpression(); |
Ted Kremenek | 6f9b3a4 | 2009-07-13 23:53:06 +0000 | [diff] [blame] | 276 | os << SE; |
Zhongxing Xu | 9012bff | 2008-10-24 06:00:12 +0000 | [diff] [blame] | 277 | break; |
Ted Kremenek | 6f9b3a4 | 2009-07-13 23:53:06 +0000 | [diff] [blame] | 278 | } |
Zhongxing Xu | 9012bff | 2008-10-24 06:00:12 +0000 | [diff] [blame] | 279 | case nonloc::LocAsIntegerKind: { |
| 280 | const nonloc::LocAsInteger& C = *cast<nonloc::LocAsInteger>(this); |
Ted Kremenek | 6f9b3a4 | 2009-07-13 23:53:06 +0000 | [diff] [blame] | 281 | os << C.getLoc() << " [as " << C.getNumBits() << " bit integer]"; |
Zhongxing Xu | 9012bff | 2008-10-24 06:00:12 +0000 | [diff] [blame] | 282 | break; |
| 283 | } |
Ted Kremenek | a6fac4e | 2008-10-30 18:01:28 +0000 | [diff] [blame] | 284 | case nonloc::CompoundValKind: { |
| 285 | const nonloc::CompoundVal& C = *cast<nonloc::CompoundVal>(this); |
Ted Kremenek | 7b67952 | 2009-07-14 20:21:36 +0000 | [diff] [blame] | 286 | os << "compoundVal{"; |
Ted Kremenek | b8b4161 | 2008-10-30 18:35:10 +0000 | [diff] [blame] | 287 | bool first = true; |
| 288 | for (nonloc::CompoundVal::iterator I=C.begin(), E=C.end(); I!=E; ++I) { |
Ted Kremenek | 6f9b3a4 | 2009-07-13 23:53:06 +0000 | [diff] [blame] | 289 | if (first) { |
| 290 | os << ' '; first = false; |
| 291 | } |
| 292 | else |
| 293 | os << ", "; |
| 294 | |
| 295 | (*I).dumpToStream(os); |
Ted Kremenek | b8b4161 | 2008-10-30 18:35:10 +0000 | [diff] [blame] | 296 | } |
Ted Kremenek | 7b67952 | 2009-07-14 20:21:36 +0000 | [diff] [blame] | 297 | os << "}"; |
Ted Kremenek | a6fac4e | 2008-10-30 18:01:28 +0000 | [diff] [blame] | 298 | break; |
Ted Kremenek | 6f9b3a4 | 2009-07-13 23:53:06 +0000 | [diff] [blame] | 299 | } |
Zhongxing Xu | 9012bff | 2008-10-24 06:00:12 +0000 | [diff] [blame] | 300 | default: |
| 301 | assert (false && "Pretty-printed not implemented for this NonLoc."); |
| 302 | break; |
| 303 | } |
| 304 | } |
| 305 | |
Ted Kremenek | 6f9b3a4 | 2009-07-13 23:53:06 +0000 | [diff] [blame] | 306 | void Loc::dumpToStream(llvm::raw_ostream& os) const { |
Zhongxing Xu | 9012bff | 2008-10-24 06:00:12 +0000 | [diff] [blame] | 307 | switch (getSubKind()) { |
Zhongxing Xu | 9012bff | 2008-10-24 06:00:12 +0000 | [diff] [blame] | 308 | case loc::ConcreteIntKind: |
Ted Kremenek | 6f9b3a4 | 2009-07-13 23:53:06 +0000 | [diff] [blame] | 309 | os << cast<loc::ConcreteInt>(this)->getValue().getZExtValue() << " (Loc)"; |
| 310 | break; |
Zhongxing Xu | 9012bff | 2008-10-24 06:00:12 +0000 | [diff] [blame] | 311 | case loc::GotoLabelKind: |
Ted Kremenek | 6f9b3a4 | 2009-07-13 23:53:06 +0000 | [diff] [blame] | 312 | os << "&&" << cast<loc::GotoLabel>(this)->getLabel()->getID()->getName(); |
Zhongxing Xu | 9012bff | 2008-10-24 06:00:12 +0000 | [diff] [blame] | 313 | break; |
Zhongxing Xu | 9012bff | 2008-10-24 06:00:12 +0000 | [diff] [blame] | 314 | case loc::MemRegionKind: |
Ted Kremenek | 6f9b3a4 | 2009-07-13 23:53:06 +0000 | [diff] [blame] | 315 | os << '&' << cast<loc::MemRegionVal>(this)->getRegion()->getString(); |
| 316 | break; |
Zhongxing Xu | 9012bff | 2008-10-24 06:00:12 +0000 | [diff] [blame] | 317 | default: |
Ted Kremenek | 6f9b3a4 | 2009-07-13 23:53:06 +0000 | [diff] [blame] | 318 | assert(false && "Pretty-printing not implemented for this Loc."); |
Zhongxing Xu | 9012bff | 2008-10-24 06:00:12 +0000 | [diff] [blame] | 319 | break; |
| 320 | } |
| 321 | } |