Ted Kremenek | 240f1f0 | 2008-03-07 20:13:31 +0000 | [diff] [blame] | 1 | //=== BasicValueFactory.cpp - Basic values for Path Sens analysis --*- C++ -*-// |
Ted Kremenek | d70d0b0 | 2008-02-16 01:12:31 +0000 | [diff] [blame] | 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 | // |
Ted Kremenek | 240f1f0 | 2008-03-07 20:13:31 +0000 | [diff] [blame] | 10 | // This file defines BasicValueFactory, a class that manages the lifetime |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 11 | // of APSInt objects and symbolic constraints used by GRExprEngine |
Ted Kremenek | 240f1f0 | 2008-03-07 20:13:31 +0000 | [diff] [blame] | 12 | // and related classes. |
Ted Kremenek | d70d0b0 | 2008-02-16 01:12:31 +0000 | [diff] [blame] | 13 | // |
| 14 | //===----------------------------------------------------------------------===// |
| 15 | |
Ted Kremenek | 240f1f0 | 2008-03-07 20:13:31 +0000 | [diff] [blame] | 16 | #include "clang/Analysis/PathSensitive/BasicValueFactory.h" |
Ted Kremenek | d70d0b0 | 2008-02-16 01:12:31 +0000 | [diff] [blame] | 17 | |
| 18 | using namespace clang; |
| 19 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 20 | void CompoundValData::Profile(llvm::FoldingSetNodeID& ID, QualType T, |
Ted Kremenek | 632e8b8 | 2008-10-30 17:44:46 +0000 | [diff] [blame] | 21 | llvm::ImmutableList<SVal> L) { |
Zhongxing Xu | 6764b72 | 2008-10-30 04:58:00 +0000 | [diff] [blame] | 22 | T.Profile(ID); |
Ted Kremenek | 632e8b8 | 2008-10-30 17:44:46 +0000 | [diff] [blame] | 23 | ID.AddPointer(L.getInternalPointer()); |
Zhongxing Xu | 6764b72 | 2008-10-30 04:58:00 +0000 | [diff] [blame] | 24 | } |
| 25 | |
Ted Kremenek | a5e81f1 | 2009-08-06 01:20:57 +0000 | [diff] [blame] | 26 | void LazyCompoundValData::Profile(llvm::FoldingSetNodeID& ID, |
| 27 | const GRState *state, |
| 28 | const TypedRegion *region) { |
| 29 | ID.AddPointer(state); |
| 30 | ID.AddPointer(region); |
| 31 | } |
| 32 | |
Zhongxing Xu | 1c96b24 | 2008-10-17 05:57:07 +0000 | [diff] [blame] | 33 | typedef std::pair<SVal, uintptr_t> SValData; |
| 34 | typedef std::pair<SVal, SVal> SValPair; |
Ted Kremenek | 4d0348b | 2008-04-29 23:24:44 +0000 | [diff] [blame] | 35 | |
Ted Kremenek | 0fe33bc | 2008-04-22 21:10:18 +0000 | [diff] [blame] | 36 | namespace llvm { |
Zhongxing Xu | 1c96b24 | 2008-10-17 05:57:07 +0000 | [diff] [blame] | 37 | template<> struct FoldingSetTrait<SValData> { |
| 38 | static inline void Profile(const SValData& X, llvm::FoldingSetNodeID& ID) { |
Ted Kremenek | 0fe33bc | 2008-04-22 21:10:18 +0000 | [diff] [blame] | 39 | X.first.Profile(ID); |
Ted Kremenek | 718c4f7 | 2008-04-29 22:17:41 +0000 | [diff] [blame] | 40 | ID.AddPointer( (void*) X.second); |
Ted Kremenek | 0fe33bc | 2008-04-22 21:10:18 +0000 | [diff] [blame] | 41 | } |
| 42 | }; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 43 | |
Zhongxing Xu | 1c96b24 | 2008-10-17 05:57:07 +0000 | [diff] [blame] | 44 | template<> struct FoldingSetTrait<SValPair> { |
| 45 | static inline void Profile(const SValPair& X, llvm::FoldingSetNodeID& ID) { |
Ted Kremenek | 4d0348b | 2008-04-29 23:24:44 +0000 | [diff] [blame] | 46 | X.first.Profile(ID); |
| 47 | X.second.Profile(ID); |
| 48 | } |
| 49 | }; |
Ted Kremenek | 0fe33bc | 2008-04-22 21:10:18 +0000 | [diff] [blame] | 50 | } |
| 51 | |
Zhongxing Xu | 1c96b24 | 2008-10-17 05:57:07 +0000 | [diff] [blame] | 52 | typedef llvm::FoldingSet<llvm::FoldingSetNodeWrapper<SValData> > |
| 53 | PersistentSValsTy; |
Ted Kremenek | 0fe33bc | 2008-04-22 21:10:18 +0000 | [diff] [blame] | 54 | |
Zhongxing Xu | 1c96b24 | 2008-10-17 05:57:07 +0000 | [diff] [blame] | 55 | typedef llvm::FoldingSet<llvm::FoldingSetNodeWrapper<SValPair> > |
| 56 | PersistentSValPairsTy; |
Ted Kremenek | 4d0348b | 2008-04-29 23:24:44 +0000 | [diff] [blame] | 57 | |
Ted Kremenek | 240f1f0 | 2008-03-07 20:13:31 +0000 | [diff] [blame] | 58 | BasicValueFactory::~BasicValueFactory() { |
Ted Kremenek | d70d0b0 | 2008-02-16 01:12:31 +0000 | [diff] [blame] | 59 | // Note that the dstor for the contents of APSIntSet will never be called, |
| 60 | // so we iterate over the set and invoke the dstor for each APSInt. This |
| 61 | // frees an aux. memory allocated to represent very large constants. |
| 62 | for (APSIntSetTy::iterator I=APSIntSet.begin(), E=APSIntSet.end(); I!=E; ++I) |
| 63 | I->getValue().~APSInt(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 64 | |
| 65 | delete (PersistentSValsTy*) PersistentSVals; |
Zhongxing Xu | 1c96b24 | 2008-10-17 05:57:07 +0000 | [diff] [blame] | 66 | delete (PersistentSValPairsTy*) PersistentSValPairs; |
Ted Kremenek | d70d0b0 | 2008-02-16 01:12:31 +0000 | [diff] [blame] | 67 | } |
| 68 | |
Ted Kremenek | 240f1f0 | 2008-03-07 20:13:31 +0000 | [diff] [blame] | 69 | const llvm::APSInt& BasicValueFactory::getValue(const llvm::APSInt& X) { |
Ted Kremenek | d70d0b0 | 2008-02-16 01:12:31 +0000 | [diff] [blame] | 70 | llvm::FoldingSetNodeID ID; |
| 71 | void* InsertPos; |
| 72 | typedef llvm::FoldingSetNodeWrapper<llvm::APSInt> FoldNodeTy; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 73 | |
Ted Kremenek | d70d0b0 | 2008-02-16 01:12:31 +0000 | [diff] [blame] | 74 | X.Profile(ID); |
| 75 | FoldNodeTy* P = APSIntSet.FindNodeOrInsertPos(ID, InsertPos); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 76 | |
| 77 | if (!P) { |
Ted Kremenek | d70d0b0 | 2008-02-16 01:12:31 +0000 | [diff] [blame] | 78 | P = (FoldNodeTy*) BPAlloc.Allocate<FoldNodeTy>(); |
| 79 | new (P) FoldNodeTy(X); |
| 80 | APSIntSet.InsertNode(P, InsertPos); |
| 81 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 82 | |
Ted Kremenek | d70d0b0 | 2008-02-16 01:12:31 +0000 | [diff] [blame] | 83 | return *P; |
| 84 | } |
| 85 | |
Zhongxing Xu | e8a964b | 2008-11-22 13:21:46 +0000 | [diff] [blame] | 86 | const llvm::APSInt& BasicValueFactory::getValue(const llvm::APInt& X, |
| 87 | bool isUnsigned) { |
| 88 | llvm::APSInt V(X, isUnsigned); |
| 89 | return getValue(V); |
| 90 | } |
| 91 | |
Ted Kremenek | 240f1f0 | 2008-03-07 20:13:31 +0000 | [diff] [blame] | 92 | const llvm::APSInt& BasicValueFactory::getValue(uint64_t X, unsigned BitWidth, |
Ted Kremenek | d70d0b0 | 2008-02-16 01:12:31 +0000 | [diff] [blame] | 93 | bool isUnsigned) { |
| 94 | llvm::APSInt V(BitWidth, isUnsigned); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 95 | V = X; |
Ted Kremenek | d70d0b0 | 2008-02-16 01:12:31 +0000 | [diff] [blame] | 96 | return getValue(V); |
| 97 | } |
| 98 | |
Ted Kremenek | 240f1f0 | 2008-03-07 20:13:31 +0000 | [diff] [blame] | 99 | const llvm::APSInt& BasicValueFactory::getValue(uint64_t X, QualType T) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 100 | |
Chris Lattner | 98be494 | 2008-03-05 18:54:05 +0000 | [diff] [blame] | 101 | unsigned bits = Ctx.getTypeSize(T); |
Ted Kremenek | fa6228d | 2009-03-11 02:52:39 +0000 | [diff] [blame] | 102 | llvm::APSInt V(bits, T->isUnsignedIntegerType() || Loc::IsLocType(T)); |
Ted Kremenek | d70d0b0 | 2008-02-16 01:12:31 +0000 | [diff] [blame] | 103 | V = X; |
| 104 | return getValue(V); |
| 105 | } |
| 106 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 107 | const CompoundValData* |
Ted Kremenek | 632e8b8 | 2008-10-30 17:44:46 +0000 | [diff] [blame] | 108 | BasicValueFactory::getCompoundValData(QualType T, |
| 109 | llvm::ImmutableList<SVal> Vals) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 110 | |
Zhongxing Xu | 6764b72 | 2008-10-30 04:58:00 +0000 | [diff] [blame] | 111 | llvm::FoldingSetNodeID ID; |
Ted Kremenek | 632e8b8 | 2008-10-30 17:44:46 +0000 | [diff] [blame] | 112 | CompoundValData::Profile(ID, T, Vals); |
Zhongxing Xu | 6764b72 | 2008-10-30 04:58:00 +0000 | [diff] [blame] | 113 | void* InsertPos; |
| 114 | |
| 115 | CompoundValData* D = CompoundValDataSet.FindNodeOrInsertPos(ID, InsertPos); |
| 116 | |
| 117 | if (!D) { |
| 118 | D = (CompoundValData*) BPAlloc.Allocate<CompoundValData>(); |
Ted Kremenek | 632e8b8 | 2008-10-30 17:44:46 +0000 | [diff] [blame] | 119 | new (D) CompoundValData(T, Vals); |
Zhongxing Xu | 6764b72 | 2008-10-30 04:58:00 +0000 | [diff] [blame] | 120 | CompoundValDataSet.InsertNode(D, InsertPos); |
| 121 | } |
| 122 | |
| 123 | return D; |
| 124 | } |
| 125 | |
Ted Kremenek | a5e81f1 | 2009-08-06 01:20:57 +0000 | [diff] [blame] | 126 | const LazyCompoundValData* |
| 127 | BasicValueFactory::getLazyCompoundValData(const GRState *state, |
| 128 | const TypedRegion *region) { |
| 129 | llvm::FoldingSetNodeID ID; |
| 130 | LazyCompoundValData::Profile(ID, state, region); |
| 131 | void* InsertPos; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 132 | |
Ted Kremenek | a5e81f1 | 2009-08-06 01:20:57 +0000 | [diff] [blame] | 133 | LazyCompoundValData *D = |
| 134 | LazyCompoundValDataSet.FindNodeOrInsertPos(ID, InsertPos); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 135 | |
Ted Kremenek | a5e81f1 | 2009-08-06 01:20:57 +0000 | [diff] [blame] | 136 | if (!D) { |
| 137 | D = (LazyCompoundValData*) BPAlloc.Allocate<LazyCompoundValData>(); |
| 138 | new (D) LazyCompoundValData(state, region); |
| 139 | LazyCompoundValDataSet.InsertNode(D, InsertPos); |
| 140 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 141 | |
Ted Kremenek | a5e81f1 | 2009-08-06 01:20:57 +0000 | [diff] [blame] | 142 | return D; |
| 143 | } |
| 144 | |
Ted Kremenek | 8cc13ea | 2008-02-28 20:32:03 +0000 | [diff] [blame] | 145 | const llvm::APSInt* |
Ted Kremenek | 240f1f0 | 2008-03-07 20:13:31 +0000 | [diff] [blame] | 146 | BasicValueFactory::EvaluateAPSInt(BinaryOperator::Opcode Op, |
Ted Kremenek | d70d0b0 | 2008-02-16 01:12:31 +0000 | [diff] [blame] | 147 | const llvm::APSInt& V1, const llvm::APSInt& V2) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 148 | |
Ted Kremenek | d70d0b0 | 2008-02-16 01:12:31 +0000 | [diff] [blame] | 149 | switch (Op) { |
| 150 | default: |
| 151 | assert (false && "Invalid Opcode."); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 152 | |
Ted Kremenek | d70d0b0 | 2008-02-16 01:12:31 +0000 | [diff] [blame] | 153 | case BinaryOperator::Mul: |
Ted Kremenek | 8cc13ea | 2008-02-28 20:32:03 +0000 | [diff] [blame] | 154 | return &getValue( V1 * V2 ); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 155 | |
Ted Kremenek | d70d0b0 | 2008-02-16 01:12:31 +0000 | [diff] [blame] | 156 | case BinaryOperator::Div: |
Ted Kremenek | 8cc13ea | 2008-02-28 20:32:03 +0000 | [diff] [blame] | 157 | return &getValue( V1 / V2 ); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 158 | |
Ted Kremenek | d70d0b0 | 2008-02-16 01:12:31 +0000 | [diff] [blame] | 159 | case BinaryOperator::Rem: |
Ted Kremenek | 8cc13ea | 2008-02-28 20:32:03 +0000 | [diff] [blame] | 160 | return &getValue( V1 % V2 ); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 161 | |
Ted Kremenek | d70d0b0 | 2008-02-16 01:12:31 +0000 | [diff] [blame] | 162 | case BinaryOperator::Add: |
Ted Kremenek | 8cc13ea | 2008-02-28 20:32:03 +0000 | [diff] [blame] | 163 | return &getValue( V1 + V2 ); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 164 | |
Ted Kremenek | d70d0b0 | 2008-02-16 01:12:31 +0000 | [diff] [blame] | 165 | case BinaryOperator::Sub: |
Ted Kremenek | 8cc13ea | 2008-02-28 20:32:03 +0000 | [diff] [blame] | 166 | return &getValue( V1 - V2 ); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 167 | |
Ted Kremenek | 8cc13ea | 2008-02-28 20:32:03 +0000 | [diff] [blame] | 168 | case BinaryOperator::Shl: { |
| 169 | |
| 170 | // FIXME: This logic should probably go higher up, where we can |
| 171 | // test these conditions symbolically. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 172 | |
Ted Kremenek | 8cc13ea | 2008-02-28 20:32:03 +0000 | [diff] [blame] | 173 | // FIXME: Expand these checks to include all undefined behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 174 | |
Ted Kremenek | 8cc13ea | 2008-02-28 20:32:03 +0000 | [diff] [blame] | 175 | if (V2.isSigned() && V2.isNegative()) |
| 176 | return NULL; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 177 | |
Ted Kremenek | 8cc13ea | 2008-02-28 20:32:03 +0000 | [diff] [blame] | 178 | uint64_t Amt = V2.getZExtValue(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 179 | |
Ted Kremenek | 8cc13ea | 2008-02-28 20:32:03 +0000 | [diff] [blame] | 180 | if (Amt > V1.getBitWidth()) |
| 181 | return NULL; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 182 | |
Ted Kremenek | 8cc13ea | 2008-02-28 20:32:03 +0000 | [diff] [blame] | 183 | return &getValue( V1.operator<<( (unsigned) Amt )); |
| 184 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 185 | |
Ted Kremenek | 8cc13ea | 2008-02-28 20:32:03 +0000 | [diff] [blame] | 186 | case BinaryOperator::Shr: { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 187 | |
Ted Kremenek | 8cc13ea | 2008-02-28 20:32:03 +0000 | [diff] [blame] | 188 | // FIXME: This logic should probably go higher up, where we can |
| 189 | // test these conditions symbolically. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 190 | |
Ted Kremenek | 8cc13ea | 2008-02-28 20:32:03 +0000 | [diff] [blame] | 191 | // FIXME: Expand these checks to include all undefined behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 192 | |
Ted Kremenek | 8cc13ea | 2008-02-28 20:32:03 +0000 | [diff] [blame] | 193 | if (V2.isSigned() && V2.isNegative()) |
| 194 | return NULL; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 195 | |
Ted Kremenek | 8cc13ea | 2008-02-28 20:32:03 +0000 | [diff] [blame] | 196 | uint64_t Amt = V2.getZExtValue(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 197 | |
Ted Kremenek | 8cc13ea | 2008-02-28 20:32:03 +0000 | [diff] [blame] | 198 | if (Amt > V1.getBitWidth()) |
| 199 | return NULL; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 200 | |
Ted Kremenek | 8cc13ea | 2008-02-28 20:32:03 +0000 | [diff] [blame] | 201 | return &getValue( V1.operator>>( (unsigned) Amt )); |
| 202 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 203 | |
Ted Kremenek | d70d0b0 | 2008-02-16 01:12:31 +0000 | [diff] [blame] | 204 | case BinaryOperator::LT: |
Ted Kremenek | 8cc13ea | 2008-02-28 20:32:03 +0000 | [diff] [blame] | 205 | return &getTruthValue( V1 < V2 ); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 206 | |
Ted Kremenek | d70d0b0 | 2008-02-16 01:12:31 +0000 | [diff] [blame] | 207 | case BinaryOperator::GT: |
Ted Kremenek | 8cc13ea | 2008-02-28 20:32:03 +0000 | [diff] [blame] | 208 | return &getTruthValue( V1 > V2 ); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 209 | |
Ted Kremenek | d70d0b0 | 2008-02-16 01:12:31 +0000 | [diff] [blame] | 210 | case BinaryOperator::LE: |
Ted Kremenek | 8cc13ea | 2008-02-28 20:32:03 +0000 | [diff] [blame] | 211 | return &getTruthValue( V1 <= V2 ); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 212 | |
Ted Kremenek | d70d0b0 | 2008-02-16 01:12:31 +0000 | [diff] [blame] | 213 | case BinaryOperator::GE: |
Ted Kremenek | 8cc13ea | 2008-02-28 20:32:03 +0000 | [diff] [blame] | 214 | return &getTruthValue( V1 >= V2 ); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 215 | |
Ted Kremenek | d70d0b0 | 2008-02-16 01:12:31 +0000 | [diff] [blame] | 216 | case BinaryOperator::EQ: |
Ted Kremenek | 8cc13ea | 2008-02-28 20:32:03 +0000 | [diff] [blame] | 217 | return &getTruthValue( V1 == V2 ); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 218 | |
Ted Kremenek | d70d0b0 | 2008-02-16 01:12:31 +0000 | [diff] [blame] | 219 | case BinaryOperator::NE: |
Ted Kremenek | 8cc13ea | 2008-02-28 20:32:03 +0000 | [diff] [blame] | 220 | return &getTruthValue( V1 != V2 ); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 221 | |
Ted Kremenek | d70d0b0 | 2008-02-16 01:12:31 +0000 | [diff] [blame] | 222 | // Note: LAnd, LOr, Comma are handled specially by higher-level logic. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 223 | |
Ted Kremenek | d70d0b0 | 2008-02-16 01:12:31 +0000 | [diff] [blame] | 224 | case BinaryOperator::And: |
Ted Kremenek | 8cc13ea | 2008-02-28 20:32:03 +0000 | [diff] [blame] | 225 | return &getValue( V1 & V2 ); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 226 | |
Ted Kremenek | d70d0b0 | 2008-02-16 01:12:31 +0000 | [diff] [blame] | 227 | case BinaryOperator::Or: |
Ted Kremenek | 8cc13ea | 2008-02-28 20:32:03 +0000 | [diff] [blame] | 228 | return &getValue( V1 | V2 ); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 229 | |
Ted Kremenek | 1caf26a | 2008-02-19 20:53:37 +0000 | [diff] [blame] | 230 | case BinaryOperator::Xor: |
Ted Kremenek | 8cc13ea | 2008-02-28 20:32:03 +0000 | [diff] [blame] | 231 | return &getValue( V1 ^ V2 ); |
Ted Kremenek | d70d0b0 | 2008-02-16 01:12:31 +0000 | [diff] [blame] | 232 | } |
| 233 | } |
Ted Kremenek | 0fe33bc | 2008-04-22 21:10:18 +0000 | [diff] [blame] | 234 | |
| 235 | |
Zhongxing Xu | 1c96b24 | 2008-10-17 05:57:07 +0000 | [diff] [blame] | 236 | const std::pair<SVal, uintptr_t>& |
| 237 | BasicValueFactory::getPersistentSValWithData(const SVal& V, uintptr_t Data) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 238 | |
Ted Kremenek | 0fe33bc | 2008-04-22 21:10:18 +0000 | [diff] [blame] | 239 | // Lazily create the folding set. |
Zhongxing Xu | 1c96b24 | 2008-10-17 05:57:07 +0000 | [diff] [blame] | 240 | if (!PersistentSVals) PersistentSVals = new PersistentSValsTy(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 241 | |
Ted Kremenek | 0fe33bc | 2008-04-22 21:10:18 +0000 | [diff] [blame] | 242 | llvm::FoldingSetNodeID ID; |
| 243 | void* InsertPos; |
| 244 | V.Profile(ID); |
Ted Kremenek | 718c4f7 | 2008-04-29 22:17:41 +0000 | [diff] [blame] | 245 | ID.AddPointer((void*) Data); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 246 | |
Zhongxing Xu | 1c96b24 | 2008-10-17 05:57:07 +0000 | [diff] [blame] | 247 | PersistentSValsTy& Map = *((PersistentSValsTy*) PersistentSVals); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 248 | |
Zhongxing Xu | 1c96b24 | 2008-10-17 05:57:07 +0000 | [diff] [blame] | 249 | typedef llvm::FoldingSetNodeWrapper<SValData> FoldNodeTy; |
Ted Kremenek | 0fe33bc | 2008-04-22 21:10:18 +0000 | [diff] [blame] | 250 | FoldNodeTy* P = Map.FindNodeOrInsertPos(ID, InsertPos); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 251 | |
| 252 | if (!P) { |
Ted Kremenek | 0fe33bc | 2008-04-22 21:10:18 +0000 | [diff] [blame] | 253 | P = (FoldNodeTy*) BPAlloc.Allocate<FoldNodeTy>(); |
Ted Kremenek | 718c4f7 | 2008-04-29 22:17:41 +0000 | [diff] [blame] | 254 | new (P) FoldNodeTy(std::make_pair(V, Data)); |
Ted Kremenek | 0fe33bc | 2008-04-22 21:10:18 +0000 | [diff] [blame] | 255 | Map.InsertNode(P, InsertPos); |
| 256 | } |
| 257 | |
Ted Kremenek | 718c4f7 | 2008-04-29 22:17:41 +0000 | [diff] [blame] | 258 | return P->getValue(); |
Ted Kremenek | 0fe33bc | 2008-04-22 21:10:18 +0000 | [diff] [blame] | 259 | } |
Ted Kremenek | 4d0348b | 2008-04-29 23:24:44 +0000 | [diff] [blame] | 260 | |
Zhongxing Xu | 1c96b24 | 2008-10-17 05:57:07 +0000 | [diff] [blame] | 261 | const std::pair<SVal, SVal>& |
| 262 | BasicValueFactory::getPersistentSValPair(const SVal& V1, const SVal& V2) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 263 | |
Ted Kremenek | 4d0348b | 2008-04-29 23:24:44 +0000 | [diff] [blame] | 264 | // Lazily create the folding set. |
Zhongxing Xu | 1c96b24 | 2008-10-17 05:57:07 +0000 | [diff] [blame] | 265 | if (!PersistentSValPairs) PersistentSValPairs = new PersistentSValPairsTy(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 266 | |
Ted Kremenek | 4d0348b | 2008-04-29 23:24:44 +0000 | [diff] [blame] | 267 | llvm::FoldingSetNodeID ID; |
| 268 | void* InsertPos; |
| 269 | V1.Profile(ID); |
| 270 | V2.Profile(ID); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 271 | |
Zhongxing Xu | 1c96b24 | 2008-10-17 05:57:07 +0000 | [diff] [blame] | 272 | PersistentSValPairsTy& Map = *((PersistentSValPairsTy*) PersistentSValPairs); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 273 | |
Zhongxing Xu | 1c96b24 | 2008-10-17 05:57:07 +0000 | [diff] [blame] | 274 | typedef llvm::FoldingSetNodeWrapper<SValPair> FoldNodeTy; |
Ted Kremenek | 4d0348b | 2008-04-29 23:24:44 +0000 | [diff] [blame] | 275 | FoldNodeTy* P = Map.FindNodeOrInsertPos(ID, InsertPos); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 276 | |
| 277 | if (!P) { |
Ted Kremenek | 4d0348b | 2008-04-29 23:24:44 +0000 | [diff] [blame] | 278 | P = (FoldNodeTy*) BPAlloc.Allocate<FoldNodeTy>(); |
| 279 | new (P) FoldNodeTy(std::make_pair(V1, V2)); |
| 280 | Map.InsertNode(P, InsertPos); |
| 281 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 282 | |
Ted Kremenek | 4d0348b | 2008-04-29 23:24:44 +0000 | [diff] [blame] | 283 | return P->getValue(); |
| 284 | } |
| 285 | |
Zhongxing Xu | 1c96b24 | 2008-10-17 05:57:07 +0000 | [diff] [blame] | 286 | const SVal* BasicValueFactory::getPersistentSVal(SVal X) { |
| 287 | return &getPersistentSValWithData(X, 0).first; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 288 | } |
Ted Kremenek | 7360fda | 2008-09-18 23:09:54 +0000 | [diff] [blame] | 289 | |
| 290 | |