| Ted Kremenek | 2838799 | 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 | 27f1742 | 2008-10-17 05:57:07 +0000 | [diff] [blame] | 10 | // This file defines SVal, Loc, and NonLoc, classes that represent |
| Ted Kremenek | 2838799 | 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 | d99bd55 | 2010-12-23 19:38:26 +0000 | [diff] [blame] | 15 | #include "clang/StaticAnalyzer/PathSensitive/GRState.h" |
| Daniel Dunbar | 6e8aa53 | 2008-08-11 05:35:13 +0000 | [diff] [blame] | 16 | #include "clang/Basic/IdentifierTable.h" |
| Ted Kremenek | 2838799 | 2008-01-31 19:34:24 +0000 | [diff] [blame] | 17 | |
| 18 | using namespace clang; |
| Ted Kremenek | 98857c9 | 2010-12-23 07:20:52 +0000 | [diff] [blame] | 19 | using namespace ento; |
| Ted Kremenek | 2838799 | 2008-01-31 19:34:24 +0000 | [diff] [blame] | 20 | using llvm::dyn_cast; |
| 21 | using llvm::cast; |
| 22 | using llvm::APSInt; |
| 23 | |
| 24 | //===----------------------------------------------------------------------===// |
| Ted Kremenek | 3e31c26 | 2009-03-26 03:35:11 +0000 | [diff] [blame] | 25 | // Symbol iteration within an SVal. |
| Ted Kremenek | 8e6f6e0 | 2008-02-14 23:25:54 +0000 | [diff] [blame] | 26 | //===----------------------------------------------------------------------===// |
| Ted Kremenek | effdafa | 2008-02-01 06:36:40 +0000 | [diff] [blame] | 27 | |
| Ted Kremenek | 0d2ccff | 2008-04-29 22:17:41 +0000 | [diff] [blame] | 28 | |
| Ted Kremenek | 3e31c26 | 2009-03-26 03:35:11 +0000 | [diff] [blame] | 29 | //===----------------------------------------------------------------------===// |
| 30 | // Utility methods. |
| 31 | //===----------------------------------------------------------------------===// |
| Ted Kremenek | effdafa | 2008-02-01 06:36:40 +0000 | [diff] [blame] | 32 | |
| Zhongxing Xu | 08a2ede | 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; |
| Zhongxing Xu | 08a2ede | 2009-05-12 10:10:00 +0000 | [diff] [blame] | 46 | } |
| 47 | } |
| 48 | |
| 49 | return false; |
| 50 | } |
| 51 | |
| Ted Kremenek | 198a8c5 | 2009-08-28 04:49:15 +0000 | [diff] [blame] | 52 | const FunctionDecl *SVal::getAsFunctionDecl() const { |
| Zhongxing Xu | ac12943 | 2009-04-20 05:24:46 +0000 | [diff] [blame] | 53 | if (const loc::MemRegionVal* X = dyn_cast<loc::MemRegionVal>(this)) { |
| 54 | const MemRegion* R = X->getRegion(); |
| Ted Kremenek | 10a50e7 | 2009-11-25 01:32:22 +0000 | [diff] [blame] | 55 | if (const FunctionTextRegion *CTR = R->getAs<FunctionTextRegion>()) |
| Ted Kremenek | 198a8c5 | 2009-08-28 04:49:15 +0000 | [diff] [blame] | 56 | return CTR->getDecl(); |
| Zhongxing Xu | ac12943 | 2009-04-20 05:24:46 +0000 | [diff] [blame] | 57 | } |
| 58 | |
| Ted Kremenek | 198a8c5 | 2009-08-28 04:49:15 +0000 | [diff] [blame] | 59 | return NULL; |
| Zhongxing Xu | ac12943 | 2009-04-20 05:24:46 +0000 | [diff] [blame] | 60 | } |
| 61 | |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 62 | /// getAsLocSymbol - If this SVal is a location (subclasses Loc) and |
| Zhongxing Xu | ac12943 | 2009-04-20 05:24:46 +0000 | [diff] [blame] | 63 | /// wraps a symbol, return that SymbolRef. Otherwise return 0. |
| 64 | // FIXME: should we consider SymbolRef wrapped in CodeTextRegion? |
| Ted Kremenek | c9747dd | 2009-03-03 22:06:47 +0000 | [diff] [blame] | 65 | SymbolRef SVal::getAsLocSymbol() const { |
| Zhongxing Xu | 5cba6c8 | 2010-08-21 11:00:26 +0000 | [diff] [blame] | 66 | if (const nonloc::LocAsInteger *X = dyn_cast<nonloc::LocAsInteger>(this)) |
| 67 | return X->getLoc().getAsLocSymbol(); |
| 68 | |
| Ted Kremenek | c9747dd | 2009-03-03 22:06:47 +0000 | [diff] [blame] | 69 | if (const loc::MemRegionVal *X = dyn_cast<loc::MemRegionVal>(this)) { |
| Zhongxing Xu | f8f3f9d | 2009-11-10 02:17:20 +0000 | [diff] [blame] | 70 | const MemRegion *R = X->StripCasts(); |
| Ted Kremenek | 4301526 | 2009-07-29 21:43:22 +0000 | [diff] [blame] | 71 | if (const SymbolicRegion *SymR = dyn_cast<SymbolicRegion>(R)) |
| 72 | return SymR->getSymbol(); |
| Ted Kremenek | c9747dd | 2009-03-03 22:06:47 +0000 | [diff] [blame] | 73 | } |
| Ted Kremenek | 4301526 | 2009-07-29 21:43:22 +0000 | [diff] [blame] | 74 | return NULL; |
| Ted Kremenek | c9747dd | 2009-03-03 22:06:47 +0000 | [diff] [blame] | 75 | } |
| 76 | |
| Zhongxing Xu | 1bb6a1a | 2010-03-10 04:58:55 +0000 | [diff] [blame] | 77 | /// Get the symbol in the SVal or its base region. |
| 78 | SymbolRef SVal::getLocSymbolInBase() const { |
| 79 | const loc::MemRegionVal *X = dyn_cast<loc::MemRegionVal>(this); |
| 80 | |
| 81 | if (!X) |
| 82 | return 0; |
| 83 | |
| 84 | const MemRegion *R = X->getRegion(); |
| 85 | |
| 86 | while (const SubRegion *SR = dyn_cast<SubRegion>(R)) { |
| 87 | if (const SymbolicRegion *SymR = dyn_cast<SymbolicRegion>(SR)) |
| 88 | return SymR->getSymbol(); |
| 89 | else |
| 90 | R = SR->getSuperRegion(); |
| 91 | } |
| 92 | |
| 93 | return 0; |
| 94 | } |
| 95 | |
| Ted Kremenek | c9747dd | 2009-03-03 22:06:47 +0000 | [diff] [blame] | 96 | /// getAsSymbol - If this Sval wraps a symbol return that SymbolRef. |
| Zhongxing Xu | ac12943 | 2009-04-20 05:24:46 +0000 | [diff] [blame] | 97 | /// Otherwise return 0. |
| 98 | // FIXME: should we consider SymbolRef wrapped in CodeTextRegion? |
| Ted Kremenek | c9747dd | 2009-03-03 22:06:47 +0000 | [diff] [blame] | 99 | SymbolRef SVal::getAsSymbol() const { |
| 100 | if (const nonloc::SymbolVal *X = dyn_cast<nonloc::SymbolVal>(this)) |
| 101 | return X->getSymbol(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 102 | |
| Ted Kremenek | 3e31c26 | 2009-03-26 03:35:11 +0000 | [diff] [blame] | 103 | if (const nonloc::SymExprVal *X = dyn_cast<nonloc::SymExprVal>(this)) |
| 104 | if (SymbolRef Y = dyn_cast<SymbolData>(X->getSymbolicExpression())) |
| 105 | return Y; |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 106 | |
| Ted Kremenek | c9747dd | 2009-03-03 22:06:47 +0000 | [diff] [blame] | 107 | return getAsLocSymbol(); |
| 108 | } |
| 109 | |
| Ted Kremenek | 3e31c26 | 2009-03-26 03:35:11 +0000 | [diff] [blame] | 110 | /// getAsSymbolicExpression - If this Sval wraps a symbolic expression then |
| 111 | /// return that expression. Otherwise return NULL. |
| 112 | const SymExpr *SVal::getAsSymbolicExpression() const { |
| 113 | if (const nonloc::SymExprVal *X = dyn_cast<nonloc::SymExprVal>(this)) |
| 114 | return X->getSymbolicExpression(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 115 | |
| Ted Kremenek | 3e31c26 | 2009-03-26 03:35:11 +0000 | [diff] [blame] | 116 | return getAsSymbol(); |
| 117 | } |
| 118 | |
| Zhongxing Xu | d0a246f | 2009-06-30 11:52:40 +0000 | [diff] [blame] | 119 | const MemRegion *SVal::getAsRegion() const { |
| 120 | if (const loc::MemRegionVal *X = dyn_cast<loc::MemRegionVal>(this)) |
| 121 | return X->getRegion(); |
| 122 | |
| Zhongxing Xu | cbbf855 | 2010-01-11 06:52:53 +0000 | [diff] [blame] | 123 | if (const nonloc::LocAsInteger *X = dyn_cast<nonloc::LocAsInteger>(this)) { |
| 124 | return X->getLoc().getAsRegion(); |
| 125 | } |
| 126 | |
| Zhongxing Xu | d0a246f | 2009-06-30 11:52:40 +0000 | [diff] [blame] | 127 | return 0; |
| 128 | } |
| 129 | |
| Zhongxing Xu | f8f3f9d | 2009-11-10 02:17:20 +0000 | [diff] [blame] | 130 | const MemRegion *loc::MemRegionVal::StripCasts() const { |
| Ted Kremenek | ccf3335 | 2009-07-29 18:14:27 +0000 | [diff] [blame] | 131 | const MemRegion *R = getRegion(); |
| Zhongxing Xu | f8f3f9d | 2009-11-10 02:17:20 +0000 | [diff] [blame] | 132 | return R ? R->StripCasts() : NULL; |
| Ted Kremenek | ccf3335 | 2009-07-29 18:14:27 +0000 | [diff] [blame] | 133 | } |
| 134 | |
| Ted Kremenek | 3e31c26 | 2009-03-26 03:35:11 +0000 | [diff] [blame] | 135 | bool SVal::symbol_iterator::operator==(const symbol_iterator &X) const { |
| 136 | return itr == X.itr; |
| 137 | } |
| 138 | |
| 139 | bool SVal::symbol_iterator::operator!=(const symbol_iterator &X) const { |
| 140 | return itr != X.itr; |
| 141 | } |
| 142 | |
| 143 | SVal::symbol_iterator::symbol_iterator(const SymExpr *SE) { |
| 144 | itr.push_back(SE); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 145 | while (!isa<SymbolData>(itr.back())) expand(); |
| Ted Kremenek | 3e31c26 | 2009-03-26 03:35:11 +0000 | [diff] [blame] | 146 | } |
| 147 | |
| 148 | SVal::symbol_iterator& SVal::symbol_iterator::operator++() { |
| 149 | assert(!itr.empty() && "attempting to iterate on an 'end' iterator"); |
| 150 | assert(isa<SymbolData>(itr.back())); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 151 | itr.pop_back(); |
| Ted Kremenek | 3e31c26 | 2009-03-26 03:35:11 +0000 | [diff] [blame] | 152 | if (!itr.empty()) |
| 153 | while (!isa<SymbolData>(itr.back())) expand(); |
| 154 | return *this; |
| 155 | } |
| 156 | |
| 157 | SymbolRef SVal::symbol_iterator::operator*() { |
| 158 | assert(!itr.empty() && "attempting to dereference an 'end' iterator"); |
| 159 | return cast<SymbolData>(itr.back()); |
| 160 | } |
| 161 | |
| 162 | void SVal::symbol_iterator::expand() { |
| 163 | const SymExpr *SE = itr.back(); |
| 164 | itr.pop_back(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 165 | |
| Ted Kremenek | 3e31c26 | 2009-03-26 03:35:11 +0000 | [diff] [blame] | 166 | if (const SymIntExpr *SIE = dyn_cast<SymIntExpr>(SE)) { |
| 167 | itr.push_back(SIE->getLHS()); |
| 168 | return; |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 169 | } |
| Ted Kremenek | 3e31c26 | 2009-03-26 03:35:11 +0000 | [diff] [blame] | 170 | else if (const SymSymExpr *SSE = dyn_cast<SymSymExpr>(SE)) { |
| 171 | itr.push_back(SSE->getLHS()); |
| 172 | itr.push_back(SSE->getRHS()); |
| 173 | return; |
| 174 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 175 | |
| Ted Kremenek | 3e31c26 | 2009-03-26 03:35:11 +0000 | [diff] [blame] | 176 | assert(false && "unhandled expansion case"); |
| 177 | } |
| 178 | |
| Zhongxing Xu | bd96bf1 | 2010-02-05 02:26:30 +0000 | [diff] [blame] | 179 | const void *nonloc::LazyCompoundVal::getStore() const { |
| 180 | return static_cast<const LazyCompoundValData*>(Data)->getStore(); |
| Ted Kremenek | fa41714 | 2009-08-06 01:20:57 +0000 | [diff] [blame] | 181 | } |
| 182 | |
| 183 | const TypedRegion *nonloc::LazyCompoundVal::getRegion() const { |
| 184 | return static_cast<const LazyCompoundValData*>(Data)->getRegion(); |
| 185 | } |
| 186 | |
| Ted Kremenek | cdd0be1 | 2008-02-06 22:50:25 +0000 | [diff] [blame] | 187 | //===----------------------------------------------------------------------===// |
| Ted Kremenek | cbdce2e | 2008-10-30 18:01:28 +0000 | [diff] [blame] | 188 | // Other Iterators. |
| 189 | //===----------------------------------------------------------------------===// |
| 190 | |
| 191 | nonloc::CompoundVal::iterator nonloc::CompoundVal::begin() const { |
| 192 | return getValue()->begin(); |
| 193 | } |
| 194 | |
| 195 | nonloc::CompoundVal::iterator nonloc::CompoundVal::end() const { |
| 196 | return getValue()->end(); |
| 197 | } |
| 198 | |
| 199 | //===----------------------------------------------------------------------===// |
| Ted Kremenek | b1c91bf | 2008-07-18 15:54:51 +0000 | [diff] [blame] | 200 | // Useful predicates. |
| 201 | //===----------------------------------------------------------------------===// |
| 202 | |
| Zhongxing Xu | 6c306c8 | 2009-11-09 06:52:44 +0000 | [diff] [blame] | 203 | bool SVal::isConstant() const { |
| 204 | return isa<nonloc::ConcreteInt>(this) || isa<loc::ConcreteInt>(this); |
| 205 | } |
| 206 | |
| Tom Care | 3ff08a8 | 2010-07-06 21:43:29 +0000 | [diff] [blame] | 207 | bool SVal::isConstant(int I) const { |
| Zhongxing Xu | 27f1742 | 2008-10-17 05:57:07 +0000 | [diff] [blame] | 208 | if (isa<loc::ConcreteInt>(*this)) |
| Tom Care | 3ff08a8 | 2010-07-06 21:43:29 +0000 | [diff] [blame] | 209 | return cast<loc::ConcreteInt>(*this).getValue() == I; |
| Zhongxing Xu | 27f1742 | 2008-10-17 05:57:07 +0000 | [diff] [blame] | 210 | else if (isa<nonloc::ConcreteInt>(*this)) |
| Tom Care | 3ff08a8 | 2010-07-06 21:43:29 +0000 | [diff] [blame] | 211 | return cast<nonloc::ConcreteInt>(*this).getValue() == I; |
| Ted Kremenek | b1c91bf | 2008-07-18 15:54:51 +0000 | [diff] [blame] | 212 | else |
| 213 | return false; |
| 214 | } |
| 215 | |
| Tom Care | 3ff08a8 | 2010-07-06 21:43:29 +0000 | [diff] [blame] | 216 | bool SVal::isZeroConstant() const { |
| 217 | return isConstant(0); |
| 218 | } |
| 219 | |
| Ted Kremenek | b1c91bf | 2008-07-18 15:54:51 +0000 | [diff] [blame] | 220 | |
| 221 | //===----------------------------------------------------------------------===// |
| Zhongxing Xu | 27f1742 | 2008-10-17 05:57:07 +0000 | [diff] [blame] | 222 | // Transfer function dispatch for Non-Locs. |
| Ted Kremenek | cdd0be1 | 2008-02-06 22:50:25 +0000 | [diff] [blame] | 223 | //===----------------------------------------------------------------------===// |
| Ted Kremenek | effdafa | 2008-02-01 06:36:40 +0000 | [diff] [blame] | 224 | |
| Ted Kremenek | 90af909 | 2010-12-02 07:49:45 +0000 | [diff] [blame] | 225 | SVal nonloc::ConcreteInt::evalBinOp(SValBuilder &svalBuilder, |
| Ted Kremenek | 1642bda | 2009-06-26 00:05:51 +0000 | [diff] [blame] | 226 | BinaryOperator::Opcode Op, |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 227 | const nonloc::ConcreteInt& R) const { |
| Ted Kremenek | 36f6b04 | 2008-07-18 15:59:33 +0000 | [diff] [blame] | 228 | const llvm::APSInt* X = |
| Ted Kremenek | 90af909 | 2010-12-02 07:49:45 +0000 | [diff] [blame] | 229 | svalBuilder.getBasicValueFactory().evalAPSInt(Op, getValue(), R.getValue()); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 230 | |
| Ted Kremenek | e0c7938 | 2008-02-28 20:32:03 +0000 | [diff] [blame] | 231 | if (X) |
| Zhongxing Xu | 27f1742 | 2008-10-17 05:57:07 +0000 | [diff] [blame] | 232 | return nonloc::ConcreteInt(*X); |
| Ted Kremenek | e0c7938 | 2008-02-28 20:32:03 +0000 | [diff] [blame] | 233 | else |
| 234 | return UndefinedVal(); |
| Ted Kremenek | cdd0be1 | 2008-02-06 22:50:25 +0000 | [diff] [blame] | 235 | } |
| 236 | |
| Zhongxing Xu | 27f1742 | 2008-10-17 05:57:07 +0000 | [diff] [blame] | 237 | nonloc::ConcreteInt |
| Ted Kremenek | 90af909 | 2010-12-02 07:49:45 +0000 | [diff] [blame] | 238 | nonloc::ConcreteInt::evalComplement(SValBuilder &svalBuilder) const { |
| 239 | return svalBuilder.makeIntVal(~getValue()); |
| Ted Kremenek | cdd0be1 | 2008-02-06 22:50:25 +0000 | [diff] [blame] | 240 | } |
| 241 | |
| Ted Kremenek | 90af909 | 2010-12-02 07:49:45 +0000 | [diff] [blame] | 242 | nonloc::ConcreteInt |
| 243 | nonloc::ConcreteInt::evalMinus(SValBuilder &svalBuilder) const { |
| 244 | return svalBuilder.makeIntVal(-getValue()); |
| Ted Kremenek | 2cdfd66 | 2008-02-04 16:58:30 +0000 | [diff] [blame] | 245 | } |
| 246 | |
| Ted Kremenek | 2838799 | 2008-01-31 19:34:24 +0000 | [diff] [blame] | 247 | //===----------------------------------------------------------------------===// |
| Zhongxing Xu | 27f1742 | 2008-10-17 05:57:07 +0000 | [diff] [blame] | 248 | // Transfer function dispatch for Locs. |
| Ted Kremenek | 2838799 | 2008-01-31 19:34:24 +0000 | [diff] [blame] | 249 | //===----------------------------------------------------------------------===// |
| 250 | |
| Ted Kremenek | dc89142 | 2010-12-01 21:57:22 +0000 | [diff] [blame] | 251 | SVal loc::ConcreteInt::evalBinOp(BasicValueFactory& BasicVals, |
| Ted Kremenek | 0e19c03 | 2008-10-30 17:53:23 +0000 | [diff] [blame] | 252 | BinaryOperator::Opcode Op, |
| 253 | const loc::ConcreteInt& R) const { |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 254 | |
| John McCall | e302792 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 255 | assert (Op == BO_Add || Op == BO_Sub || |
| 256 | (Op >= BO_LT && Op <= BO_NE)); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 257 | |
| Ted Kremenek | dc89142 | 2010-12-01 21:57:22 +0000 | [diff] [blame] | 258 | const llvm::APSInt* X = BasicVals.evalAPSInt(Op, getValue(), R.getValue()); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 259 | |
| Ted Kremenek | e0c7938 | 2008-02-28 20:32:03 +0000 | [diff] [blame] | 260 | if (X) |
| Zhongxing Xu | 27f1742 | 2008-10-17 05:57:07 +0000 | [diff] [blame] | 261 | return loc::ConcreteInt(*X); |
| Ted Kremenek | e0c7938 | 2008-02-28 20:32:03 +0000 | [diff] [blame] | 262 | else |
| 263 | return UndefinedVal(); |
| Ted Kremenek | cdd0be1 | 2008-02-06 22:50:25 +0000 | [diff] [blame] | 264 | } |
| Ted Kremenek | 2838799 | 2008-01-31 19:34:24 +0000 | [diff] [blame] | 265 | |
| Ted Kremenek | 2838799 | 2008-01-31 19:34:24 +0000 | [diff] [blame] | 266 | //===----------------------------------------------------------------------===// |
| 267 | // Pretty-Printing. |
| 268 | //===----------------------------------------------------------------------===// |
| 269 | |
| Ted Kremenek | a6904ff | 2009-07-13 23:53:06 +0000 | [diff] [blame] | 270 | void SVal::dump() const { dumpToStream(llvm::errs()); } |
| Ted Kremenek | 736e441 | 2008-02-12 21:37:56 +0000 | [diff] [blame] | 271 | |
| Ted Kremenek | a6904ff | 2009-07-13 23:53:06 +0000 | [diff] [blame] | 272 | void SVal::dumpToStream(llvm::raw_ostream& os) const { |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 273 | switch (getBaseKind()) { |
| Zhongxing Xu | 509bd9e | 2008-10-24 06:00:12 +0000 | [diff] [blame] | 274 | case UnknownKind: |
| Ted Kremenek | c4deb92 | 2010-09-15 03:13:30 +0000 | [diff] [blame] | 275 | os << "Unknown"; |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 276 | break; |
| Zhongxing Xu | 509bd9e | 2008-10-24 06:00:12 +0000 | [diff] [blame] | 277 | case NonLocKind: |
| Ted Kremenek | a6904ff | 2009-07-13 23:53:06 +0000 | [diff] [blame] | 278 | cast<NonLoc>(this)->dumpToStream(os); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 279 | break; |
| Zhongxing Xu | 509bd9e | 2008-10-24 06:00:12 +0000 | [diff] [blame] | 280 | case LocKind: |
| Ted Kremenek | a6904ff | 2009-07-13 23:53:06 +0000 | [diff] [blame] | 281 | cast<Loc>(this)->dumpToStream(os); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 282 | break; |
| Zhongxing Xu | 509bd9e | 2008-10-24 06:00:12 +0000 | [diff] [blame] | 283 | case UndefinedKind: |
| Ted Kremenek | a6904ff | 2009-07-13 23:53:06 +0000 | [diff] [blame] | 284 | os << "Undefined"; |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 285 | break; |
| Zhongxing Xu | 509bd9e | 2008-10-24 06:00:12 +0000 | [diff] [blame] | 286 | default: |
| 287 | assert (false && "Invalid SVal."); |
| 288 | } |
| 289 | } |
| 290 | |
| Ted Kremenek | a6904ff | 2009-07-13 23:53:06 +0000 | [diff] [blame] | 291 | void NonLoc::dumpToStream(llvm::raw_ostream& os) const { |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 292 | switch (getSubKind()) { |
| Ted Kremenek | 08cbe57 | 2010-12-23 02:42:31 +0000 | [diff] [blame] | 293 | case nonloc::ConcreteIntKind: { |
| 294 | const nonloc::ConcreteInt& C = *cast<nonloc::ConcreteInt>(this); |
| Ted Kremenek | fe22d93 | 2010-12-23 02:42:46 +0000 | [diff] [blame] | 295 | if (C.getValue().isUnsigned()) |
| 296 | os << C.getValue().getZExtValue(); |
| 297 | else |
| 298 | os << C.getValue().getSExtValue(); |
| 299 | os << ' ' << (C.getValue().isUnsigned() ? 'U' : 'S') |
| Ted Kremenek | 08cbe57 | 2010-12-23 02:42:31 +0000 | [diff] [blame] | 300 | << C.getValue().getBitWidth() << 'b'; |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 301 | break; |
| Ted Kremenek | 08cbe57 | 2010-12-23 02:42:31 +0000 | [diff] [blame] | 302 | } |
| Zhongxing Xu | 509bd9e | 2008-10-24 06:00:12 +0000 | [diff] [blame] | 303 | case nonloc::SymbolValKind: |
| Ted Kremenek | a6904ff | 2009-07-13 23:53:06 +0000 | [diff] [blame] | 304 | os << '$' << cast<nonloc::SymbolVal>(this)->getSymbol(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 305 | break; |
| Ted Kremenek | 3e31c26 | 2009-03-26 03:35:11 +0000 | [diff] [blame] | 306 | case nonloc::SymExprValKind: { |
| 307 | const nonloc::SymExprVal& C = *cast<nonloc::SymExprVal>(this); |
| 308 | const SymExpr *SE = C.getSymbolicExpression(); |
| Ted Kremenek | a6904ff | 2009-07-13 23:53:06 +0000 | [diff] [blame] | 309 | os << SE; |
| Zhongxing Xu | 509bd9e | 2008-10-24 06:00:12 +0000 | [diff] [blame] | 310 | break; |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 311 | } |
| Zhongxing Xu | 509bd9e | 2008-10-24 06:00:12 +0000 | [diff] [blame] | 312 | case nonloc::LocAsIntegerKind: { |
| 313 | const nonloc::LocAsInteger& C = *cast<nonloc::LocAsInteger>(this); |
| Ted Kremenek | a6904ff | 2009-07-13 23:53:06 +0000 | [diff] [blame] | 314 | os << C.getLoc() << " [as " << C.getNumBits() << " bit integer]"; |
| Zhongxing Xu | 509bd9e | 2008-10-24 06:00:12 +0000 | [diff] [blame] | 315 | break; |
| 316 | } |
| Ted Kremenek | cbdce2e | 2008-10-30 18:01:28 +0000 | [diff] [blame] | 317 | case nonloc::CompoundValKind: { |
| 318 | const nonloc::CompoundVal& C = *cast<nonloc::CompoundVal>(this); |
| Ted Kremenek | e2fb3ce | 2009-07-14 20:21:36 +0000 | [diff] [blame] | 319 | os << "compoundVal{"; |
| Ted Kremenek | e40b698 | 2008-10-30 18:35:10 +0000 | [diff] [blame] | 320 | bool first = true; |
| 321 | for (nonloc::CompoundVal::iterator I=C.begin(), E=C.end(); I!=E; ++I) { |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 322 | if (first) { |
| Ted Kremenek | a6904ff | 2009-07-13 23:53:06 +0000 | [diff] [blame] | 323 | os << ' '; first = false; |
| 324 | } |
| 325 | else |
| 326 | os << ", "; |
| 327 | |
| 328 | (*I).dumpToStream(os); |
| Ted Kremenek | e40b698 | 2008-10-30 18:35:10 +0000 | [diff] [blame] | 329 | } |
| Ted Kremenek | e2fb3ce | 2009-07-14 20:21:36 +0000 | [diff] [blame] | 330 | os << "}"; |
| Ted Kremenek | cbdce2e | 2008-10-30 18:01:28 +0000 | [diff] [blame] | 331 | break; |
| Ted Kremenek | fa41714 | 2009-08-06 01:20:57 +0000 | [diff] [blame] | 332 | } |
| 333 | case nonloc::LazyCompoundValKind: { |
| 334 | const nonloc::LazyCompoundVal &C = *cast<nonloc::LazyCompoundVal>(this); |
| Dan Gohman | 145f3f1 | 2010-04-19 16:39:44 +0000 | [diff] [blame] | 335 | os << "lazyCompoundVal{" << const_cast<void *>(C.getStore()) |
| 336 | << ',' << C.getRegion() |
| Ted Kremenek | fa41714 | 2009-08-06 01:20:57 +0000 | [diff] [blame] | 337 | << '}'; |
| 338 | break; |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 339 | } |
| Zhongxing Xu | 509bd9e | 2008-10-24 06:00:12 +0000 | [diff] [blame] | 340 | default: |
| 341 | assert (false && "Pretty-printed not implemented for this NonLoc."); |
| 342 | break; |
| 343 | } |
| 344 | } |
| 345 | |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 346 | void Loc::dumpToStream(llvm::raw_ostream& os) const { |
| 347 | switch (getSubKind()) { |
| Zhongxing Xu | 509bd9e | 2008-10-24 06:00:12 +0000 | [diff] [blame] | 348 | case loc::ConcreteIntKind: |
| Ted Kremenek | a6904ff | 2009-07-13 23:53:06 +0000 | [diff] [blame] | 349 | os << cast<loc::ConcreteInt>(this)->getValue().getZExtValue() << " (Loc)"; |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 350 | break; |
| Zhongxing Xu | 509bd9e | 2008-10-24 06:00:12 +0000 | [diff] [blame] | 351 | case loc::GotoLabelKind: |
| Ted Kremenek | a6904ff | 2009-07-13 23:53:06 +0000 | [diff] [blame] | 352 | os << "&&" << cast<loc::GotoLabel>(this)->getLabel()->getID()->getName(); |
| Zhongxing Xu | 509bd9e | 2008-10-24 06:00:12 +0000 | [diff] [blame] | 353 | break; |
| Zhongxing Xu | 509bd9e | 2008-10-24 06:00:12 +0000 | [diff] [blame] | 354 | case loc::MemRegionKind: |
| Ted Kremenek | a6904ff | 2009-07-13 23:53:06 +0000 | [diff] [blame] | 355 | os << '&' << cast<loc::MemRegionVal>(this)->getRegion()->getString(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 356 | break; |
| Zhongxing Xu | 509bd9e | 2008-10-24 06:00:12 +0000 | [diff] [blame] | 357 | default: |
| Ted Kremenek | a6904ff | 2009-07-13 23:53:06 +0000 | [diff] [blame] | 358 | assert(false && "Pretty-printing not implemented for this Loc."); |
| Zhongxing Xu | 509bd9e | 2008-10-24 06:00:12 +0000 | [diff] [blame] | 359 | break; |
| 360 | } |
| 361 | } |