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