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