Ted Kremenek | 77349cb | 2008-02-14 22:13:12 +0000 | [diff] [blame] | 1 | //=-- GRExprEngine.cpp - Path-Sensitive Expression-Level Dataflow ---*- C++ -*-= |
Ted Kremenek | 6492485 | 2008-01-31 02:35:41 +0000 | [diff] [blame] | 2 | // |
Ted Kremenek | 4af8431 | 2008-01-31 06:49:09 +0000 | [diff] [blame] | 3 | // The LLVM Compiler Infrastructure |
Ted Kremenek | d27f816 | 2008-01-15 23:55:06 +0000 | [diff] [blame] | 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 | 77349cb | 2008-02-14 22:13:12 +0000 | [diff] [blame] | 10 | // This file defines a meta-engine for path-sensitive dataflow analysis that |
| 11 | // is built on GREngine, but provides the boilerplate to execute transfer |
| 12 | // functions and build the ExplodedGraph at the expression level. |
Ted Kremenek | d27f816 | 2008-01-15 23:55:06 +0000 | [diff] [blame] | 13 | // |
| 14 | //===----------------------------------------------------------------------===// |
| 15 | |
Ted Kremenek | 77349cb | 2008-02-14 22:13:12 +0000 | [diff] [blame] | 16 | #include "clang/Analysis/PathSensitive/GRExprEngine.h" |
Ted Kremenek | e01c987 | 2008-02-14 22:36:46 +0000 | [diff] [blame] | 17 | #include "llvm/Support/Streams.h" |
Ted Kremenek | b387a3f | 2008-02-14 22:16:04 +0000 | [diff] [blame] | 18 | |
Ted Kremenek | 0f5f059 | 2008-02-27 06:07:00 +0000 | [diff] [blame] | 19 | #ifndef NDEBUG |
| 20 | #include "llvm/Support/GraphWriter.h" |
| 21 | #include <sstream> |
| 22 | #endif |
| 23 | |
Ted Kremenek | b387a3f | 2008-02-14 22:16:04 +0000 | [diff] [blame] | 24 | using namespace clang; |
| 25 | using llvm::dyn_cast; |
| 26 | using llvm::cast; |
| 27 | using llvm::APSInt; |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 28 | |
Ted Kremenek | aed9b6a | 2008-02-28 10:21:43 +0000 | [diff] [blame^] | 29 | ValueState* GRExprEngine::getInitialState() { |
Ted Kremenek | 0793263 | 2008-02-27 06:47:26 +0000 | [diff] [blame] | 30 | |
| 31 | // The LiveVariables information already has a compilation of all VarDecls |
| 32 | // used in the function. Iterate through this set, and "symbolicate" |
| 33 | // any VarDecl whose value originally comes from outside the function. |
| 34 | |
| 35 | typedef LiveVariables::AnalysisDataTy LVDataTy; |
| 36 | LVDataTy& D = Liveness.getAnalysisData(); |
| 37 | |
Ted Kremenek | aed9b6a | 2008-02-28 10:21:43 +0000 | [diff] [blame^] | 38 | ValueState StateImpl = *StateMgr.getInitialState(); |
Ted Kremenek | 0793263 | 2008-02-27 06:47:26 +0000 | [diff] [blame] | 39 | |
| 40 | for (LVDataTy::decl_iterator I=D.begin_decl(), E=D.end_decl(); I != E; ++I) { |
| 41 | |
| 42 | VarDecl* VD = cast<VarDecl>(const_cast<ScopedDecl*>(I->first)); |
| 43 | |
| 44 | if (VD->hasGlobalStorage() || isa<ParmVarDecl>(VD)) { |
| 45 | RVal X = RVal::GetSymbolValue(SymMgr, VD); |
| 46 | StateMgr.BindVar(StateImpl, VD, X); |
| 47 | } |
| 48 | } |
| 49 | |
| 50 | return StateMgr.getPersistentState(StateImpl); |
| 51 | } |
| 52 | |
Ted Kremenek | aed9b6a | 2008-02-28 10:21:43 +0000 | [diff] [blame^] | 53 | ValueState* GRExprEngine::SetRVal(ValueState* St, Expr* Ex, RVal V) { |
Ted Kremenek | 3271f8d | 2008-02-07 04:16:04 +0000 | [diff] [blame] | 54 | |
Ted Kremenek | e070a1d | 2008-02-04 21:59:01 +0000 | [diff] [blame] | 55 | if (!StateCleaned) { |
| 56 | St = RemoveDeadBindings(CurrentStmt, St); |
| 57 | StateCleaned = true; |
| 58 | } |
Ted Kremenek | 3271f8d | 2008-02-07 04:16:04 +0000 | [diff] [blame] | 59 | |
Ted Kremenek | e070a1d | 2008-02-04 21:59:01 +0000 | [diff] [blame] | 60 | bool isBlkExpr = false; |
Ted Kremenek | 3271f8d | 2008-02-07 04:16:04 +0000 | [diff] [blame] | 61 | |
Ted Kremenek | aa1c4e5 | 2008-02-21 18:02:17 +0000 | [diff] [blame] | 62 | if (Ex == CurrentStmt) { |
| 63 | isBlkExpr = getCFG().isBlkExpr(Ex); |
Ted Kremenek | e070a1d | 2008-02-04 21:59:01 +0000 | [diff] [blame] | 64 | |
| 65 | if (!isBlkExpr) |
| 66 | return St; |
| 67 | } |
Ted Kremenek | 3271f8d | 2008-02-07 04:16:04 +0000 | [diff] [blame] | 68 | |
Ted Kremenek | 5a7b382 | 2008-02-26 23:37:01 +0000 | [diff] [blame] | 69 | return StateMgr.SetRVal(St, Ex, V, isBlkExpr, false); |
Ted Kremenek | e070a1d | 2008-02-04 21:59:01 +0000 | [diff] [blame] | 70 | } |
| 71 | |
Ted Kremenek | aed9b6a | 2008-02-28 10:21:43 +0000 | [diff] [blame^] | 72 | #if 0 |
| 73 | const ValueState::BufferTy& |
| 74 | GRExprEngine::SetRVal(ValueState* St, Expr* Ex, const RVal::BufferTy& RB, |
| 75 | ValueState::BufferTy& RetBuf) { |
Ted Kremenek | cba2e43 | 2008-02-05 19:35:18 +0000 | [diff] [blame] | 76 | |
| 77 | assert (RetBuf.empty()); |
| 78 | |
Ted Kremenek | aa1c4e5 | 2008-02-21 18:02:17 +0000 | [diff] [blame] | 79 | for (RVal::BufferTy::const_iterator I = RB.begin(), E = RB.end(); I!=E; ++I) |
| 80 | RetBuf.push_back(SetRVal(St, Ex, *I)); |
Ted Kremenek | cba2e43 | 2008-02-05 19:35:18 +0000 | [diff] [blame] | 81 | |
| 82 | return RetBuf; |
| 83 | } |
Ted Kremenek | aed9b6a | 2008-02-28 10:21:43 +0000 | [diff] [blame^] | 84 | #endif |
Ted Kremenek | cba2e43 | 2008-02-05 19:35:18 +0000 | [diff] [blame] | 85 | |
Ted Kremenek | aed9b6a | 2008-02-28 10:21:43 +0000 | [diff] [blame^] | 86 | ValueState* GRExprEngine::SetRVal(ValueState* St, LVal LV, RVal RV) { |
Ted Kremenek | e070a1d | 2008-02-04 21:59:01 +0000 | [diff] [blame] | 87 | |
| 88 | if (!StateCleaned) { |
| 89 | St = RemoveDeadBindings(CurrentStmt, St); |
| 90 | StateCleaned = true; |
| 91 | } |
| 92 | |
Ted Kremenek | aa1c4e5 | 2008-02-21 18:02:17 +0000 | [diff] [blame] | 93 | return StateMgr.SetRVal(St, LV, RV); |
Ted Kremenek | e070a1d | 2008-02-04 21:59:01 +0000 | [diff] [blame] | 94 | } |
| 95 | |
Ted Kremenek | aed9b6a | 2008-02-28 10:21:43 +0000 | [diff] [blame^] | 96 | ValueState* GRExprEngine::MarkBranch(ValueState* St, Stmt* Terminator, |
| 97 | bool branchTaken) { |
Ted Kremenek | 05a2378 | 2008-02-26 19:05:15 +0000 | [diff] [blame] | 98 | |
| 99 | switch (Terminator->getStmtClass()) { |
| 100 | default: |
| 101 | return St; |
| 102 | |
| 103 | case Stmt::BinaryOperatorClass: { // '&&' and '||' |
| 104 | |
| 105 | BinaryOperator* B = cast<BinaryOperator>(Terminator); |
| 106 | BinaryOperator::Opcode Op = B->getOpcode(); |
| 107 | |
| 108 | assert (Op == BinaryOperator::LAnd || Op == BinaryOperator::LOr); |
| 109 | |
| 110 | // For &&, if we take the true branch, then the value of the whole |
| 111 | // expression is that of the RHS expression. |
| 112 | // |
| 113 | // For ||, if we take the false branch, then the value of the whole |
| 114 | // expression is that of the RHS expression. |
| 115 | |
| 116 | Expr* Ex = (Op == BinaryOperator::LAnd && branchTaken) || |
| 117 | (Op == BinaryOperator::LOr && !branchTaken) |
| 118 | ? B->getRHS() : B->getLHS(); |
| 119 | |
Ted Kremenek | 4a4e524 | 2008-02-28 09:25:22 +0000 | [diff] [blame] | 120 | return SetBlkExprRVal(St, B, UndefinedVal(Ex)); |
Ted Kremenek | 05a2378 | 2008-02-26 19:05:15 +0000 | [diff] [blame] | 121 | } |
| 122 | |
| 123 | case Stmt::ConditionalOperatorClass: { // ?: |
| 124 | |
| 125 | ConditionalOperator* C = cast<ConditionalOperator>(Terminator); |
| 126 | |
| 127 | // For ?, if branchTaken == true then the value is either the LHS or |
| 128 | // the condition itself. (GNU extension). |
| 129 | |
| 130 | Expr* Ex; |
| 131 | |
| 132 | if (branchTaken) |
| 133 | Ex = C->getLHS() ? C->getLHS() : C->getCond(); |
| 134 | else |
| 135 | Ex = C->getRHS(); |
| 136 | |
Ted Kremenek | 4a4e524 | 2008-02-28 09:25:22 +0000 | [diff] [blame] | 137 | return SetBlkExprRVal(St, C, UndefinedVal(Ex)); |
Ted Kremenek | 05a2378 | 2008-02-26 19:05:15 +0000 | [diff] [blame] | 138 | } |
| 139 | |
| 140 | case Stmt::ChooseExprClass: { // ?: |
| 141 | |
| 142 | ChooseExpr* C = cast<ChooseExpr>(Terminator); |
| 143 | |
| 144 | Expr* Ex = branchTaken ? C->getLHS() : C->getRHS(); |
Ted Kremenek | 4a4e524 | 2008-02-28 09:25:22 +0000 | [diff] [blame] | 145 | return SetBlkExprRVal(St, C, UndefinedVal(Ex)); |
Ted Kremenek | 05a2378 | 2008-02-26 19:05:15 +0000 | [diff] [blame] | 146 | } |
| 147 | } |
| 148 | } |
| 149 | |
Ted Kremenek | 4d4dd85 | 2008-02-13 17:41:41 +0000 | [diff] [blame] | 150 | void GRExprEngine::ProcessBranch(Expr* Condition, Stmt* Term, |
Ted Kremenek | aa1c4e5 | 2008-02-21 18:02:17 +0000 | [diff] [blame] | 151 | BranchNodeBuilder& builder) { |
Ted Kremenek | b38911f | 2008-01-30 23:03:39 +0000 | [diff] [blame] | 152 | |
Ted Kremenek | e7d2211 | 2008-02-11 19:21:59 +0000 | [diff] [blame] | 153 | // Remove old bindings for subexpressions. |
Ted Kremenek | aed9b6a | 2008-02-28 10:21:43 +0000 | [diff] [blame^] | 154 | ValueState* PrevState = StateMgr.RemoveSubExprBindings(builder.getState()); |
Ted Kremenek | f233d48 | 2008-02-05 00:26:40 +0000 | [diff] [blame] | 155 | |
Ted Kremenek | b233183 | 2008-02-15 22:29:00 +0000 | [diff] [blame] | 156 | // Check for NULL conditions; e.g. "for(;;)" |
| 157 | if (!Condition) { |
| 158 | builder.markInfeasible(false); |
| 159 | |
| 160 | // Get the current block counter. |
| 161 | GRBlockCounter BC = builder.getBlockCounter(); |
| 162 | unsigned BlockID = builder.getTargetBlock(true)->getBlockID(); |
| 163 | unsigned NumVisited = BC.getNumVisited(BlockID); |
| 164 | |
| 165 | if (NumVisited < 1) builder.generateNode(PrevState, true); |
| 166 | else builder.markInfeasible(true); |
| 167 | |
| 168 | return; |
| 169 | } |
| 170 | |
Ted Kremenek | aa1c4e5 | 2008-02-21 18:02:17 +0000 | [diff] [blame] | 171 | RVal V = GetRVal(PrevState, Condition); |
Ted Kremenek | b38911f | 2008-01-30 23:03:39 +0000 | [diff] [blame] | 172 | |
| 173 | switch (V.getBaseKind()) { |
| 174 | default: |
| 175 | break; |
| 176 | |
Ted Kremenek | aa1c4e5 | 2008-02-21 18:02:17 +0000 | [diff] [blame] | 177 | case RVal::UnknownKind: |
Ted Kremenek | 58b3321 | 2008-02-26 19:40:44 +0000 | [diff] [blame] | 178 | builder.generateNode(MarkBranch(PrevState, Term, true), true); |
| 179 | builder.generateNode(MarkBranch(PrevState, Term, false), false); |
Ted Kremenek | b38911f | 2008-01-30 23:03:39 +0000 | [diff] [blame] | 180 | return; |
| 181 | |
Ted Kremenek | 4a4e524 | 2008-02-28 09:25:22 +0000 | [diff] [blame] | 182 | case RVal::UndefinedKind: { |
Ted Kremenek | b38911f | 2008-01-30 23:03:39 +0000 | [diff] [blame] | 183 | NodeTy* N = builder.generateNode(PrevState, true); |
| 184 | |
| 185 | if (N) { |
| 186 | N->markAsSink(); |
Ted Kremenek | 4a4e524 | 2008-02-28 09:25:22 +0000 | [diff] [blame] | 187 | UndefBranches.insert(N); |
Ted Kremenek | b38911f | 2008-01-30 23:03:39 +0000 | [diff] [blame] | 188 | } |
| 189 | |
| 190 | builder.markInfeasible(false); |
| 191 | return; |
| 192 | } |
| 193 | } |
Ted Kremenek | b233183 | 2008-02-15 22:29:00 +0000 | [diff] [blame] | 194 | |
Ted Kremenek | 8e49dd6 | 2008-02-12 18:08:17 +0000 | [diff] [blame] | 195 | // Get the current block counter. |
| 196 | GRBlockCounter BC = builder.getBlockCounter(); |
Ted Kremenek | d9435bf | 2008-02-12 19:49:57 +0000 | [diff] [blame] | 197 | unsigned BlockID = builder.getTargetBlock(true)->getBlockID(); |
| 198 | unsigned NumVisited = BC.getNumVisited(BlockID); |
Ted Kremenek | f233d48 | 2008-02-05 00:26:40 +0000 | [diff] [blame] | 199 | |
Ted Kremenek | 8e49dd6 | 2008-02-12 18:08:17 +0000 | [diff] [blame] | 200 | if (isa<nonlval::ConcreteInt>(V) || |
| 201 | BC.getNumVisited(builder.getTargetBlock(true)->getBlockID()) < 1) { |
| 202 | |
| 203 | // Process the true branch. |
Ted Kremenek | b38911f | 2008-01-30 23:03:39 +0000 | [diff] [blame] | 204 | |
Ted Kremenek | 8e49dd6 | 2008-02-12 18:08:17 +0000 | [diff] [blame] | 205 | bool isFeasible = true; |
| 206 | |
Ted Kremenek | aed9b6a | 2008-02-28 10:21:43 +0000 | [diff] [blame^] | 207 | ValueState* St = Assume(PrevState, V, true, isFeasible); |
Ted Kremenek | 8e49dd6 | 2008-02-12 18:08:17 +0000 | [diff] [blame] | 208 | |
| 209 | if (isFeasible) |
Ted Kremenek | 05a2378 | 2008-02-26 19:05:15 +0000 | [diff] [blame] | 210 | builder.generateNode(MarkBranch(St, Term, true), true); |
Ted Kremenek | 8e49dd6 | 2008-02-12 18:08:17 +0000 | [diff] [blame] | 211 | else |
| 212 | builder.markInfeasible(true); |
Ted Kremenek | b38911f | 2008-01-30 23:03:39 +0000 | [diff] [blame] | 213 | } |
Ted Kremenek | 8e49dd6 | 2008-02-12 18:08:17 +0000 | [diff] [blame] | 214 | else |
| 215 | builder.markInfeasible(true); |
Ted Kremenek | b38911f | 2008-01-30 23:03:39 +0000 | [diff] [blame] | 216 | |
Ted Kremenek | d9435bf | 2008-02-12 19:49:57 +0000 | [diff] [blame] | 217 | BlockID = builder.getTargetBlock(false)->getBlockID(); |
| 218 | NumVisited = BC.getNumVisited(BlockID); |
Ted Kremenek | b38911f | 2008-01-30 23:03:39 +0000 | [diff] [blame] | 219 | |
Ted Kremenek | 8e49dd6 | 2008-02-12 18:08:17 +0000 | [diff] [blame] | 220 | if (isa<nonlval::ConcreteInt>(V) || |
| 221 | BC.getNumVisited(builder.getTargetBlock(false)->getBlockID()) < 1) { |
| 222 | |
| 223 | // Process the false branch. |
| 224 | |
| 225 | bool isFeasible = false; |
| 226 | |
Ted Kremenek | aed9b6a | 2008-02-28 10:21:43 +0000 | [diff] [blame^] | 227 | ValueState* St = Assume(PrevState, V, false, isFeasible); |
Ted Kremenek | 8e49dd6 | 2008-02-12 18:08:17 +0000 | [diff] [blame] | 228 | |
| 229 | if (isFeasible) |
Ted Kremenek | 05a2378 | 2008-02-26 19:05:15 +0000 | [diff] [blame] | 230 | builder.generateNode(MarkBranch(St, Term, false), false); |
Ted Kremenek | 8e49dd6 | 2008-02-12 18:08:17 +0000 | [diff] [blame] | 231 | else |
| 232 | builder.markInfeasible(false); |
| 233 | } |
Ted Kremenek | f233d48 | 2008-02-05 00:26:40 +0000 | [diff] [blame] | 234 | else |
| 235 | builder.markInfeasible(false); |
Ted Kremenek | 71c29bd | 2008-01-29 23:32:35 +0000 | [diff] [blame] | 236 | } |
| 237 | |
Ted Kremenek | 4d4dd85 | 2008-02-13 17:41:41 +0000 | [diff] [blame] | 238 | /// ProcessIndirectGoto - Called by GRCoreEngine. Used to generate successor |
Ted Kremenek | 754607e | 2008-02-13 00:24:44 +0000 | [diff] [blame] | 239 | /// nodes by processing the 'effects' of a computed goto jump. |
Ted Kremenek | 4d4dd85 | 2008-02-13 17:41:41 +0000 | [diff] [blame] | 240 | void GRExprEngine::ProcessIndirectGoto(IndirectGotoNodeBuilder& builder) { |
Ted Kremenek | 754607e | 2008-02-13 00:24:44 +0000 | [diff] [blame] | 241 | |
Ted Kremenek | aed9b6a | 2008-02-28 10:21:43 +0000 | [diff] [blame^] | 242 | ValueState* St = builder.getState(); |
Ted Kremenek | aa1c4e5 | 2008-02-21 18:02:17 +0000 | [diff] [blame] | 243 | RVal V = GetRVal(St, builder.getTarget()); |
Ted Kremenek | 754607e | 2008-02-13 00:24:44 +0000 | [diff] [blame] | 244 | |
| 245 | // Three possibilities: |
| 246 | // |
| 247 | // (1) We know the computed label. |
Ted Kremenek | 4a4e524 | 2008-02-28 09:25:22 +0000 | [diff] [blame] | 248 | // (2) The label is NULL (or some other constant), or Undefined. |
Ted Kremenek | 754607e | 2008-02-13 00:24:44 +0000 | [diff] [blame] | 249 | // (3) We have no clue about the label. Dispatch to all targets. |
| 250 | // |
| 251 | |
| 252 | typedef IndirectGotoNodeBuilder::iterator iterator; |
| 253 | |
| 254 | if (isa<lval::GotoLabel>(V)) { |
| 255 | LabelStmt* L = cast<lval::GotoLabel>(V).getLabel(); |
| 256 | |
| 257 | for (iterator I=builder.begin(), E=builder.end(); I != E; ++I) { |
Ted Kremenek | 24f1a96 | 2008-02-13 17:27:37 +0000 | [diff] [blame] | 258 | if (I.getLabel() == L) { |
| 259 | builder.generateNode(I, St); |
Ted Kremenek | 754607e | 2008-02-13 00:24:44 +0000 | [diff] [blame] | 260 | return; |
| 261 | } |
| 262 | } |
| 263 | |
| 264 | assert (false && "No block with label."); |
| 265 | return; |
| 266 | } |
| 267 | |
Ted Kremenek | 4a4e524 | 2008-02-28 09:25:22 +0000 | [diff] [blame] | 268 | if (isa<lval::ConcreteInt>(V) || isa<UndefinedVal>(V)) { |
Ted Kremenek | 754607e | 2008-02-13 00:24:44 +0000 | [diff] [blame] | 269 | // Dispatch to the first target and mark it as a sink. |
Ted Kremenek | 24f1a96 | 2008-02-13 17:27:37 +0000 | [diff] [blame] | 270 | NodeTy* N = builder.generateNode(builder.begin(), St, true); |
Ted Kremenek | 4a4e524 | 2008-02-28 09:25:22 +0000 | [diff] [blame] | 271 | UndefBranches.insert(N); |
Ted Kremenek | 754607e | 2008-02-13 00:24:44 +0000 | [diff] [blame] | 272 | return; |
| 273 | } |
| 274 | |
| 275 | // This is really a catch-all. We don't support symbolics yet. |
| 276 | |
Ted Kremenek | aa1c4e5 | 2008-02-21 18:02:17 +0000 | [diff] [blame] | 277 | assert (V.isUnknown()); |
Ted Kremenek | 754607e | 2008-02-13 00:24:44 +0000 | [diff] [blame] | 278 | |
| 279 | for (iterator I=builder.begin(), E=builder.end(); I != E; ++I) |
Ted Kremenek | 24f1a96 | 2008-02-13 17:27:37 +0000 | [diff] [blame] | 280 | builder.generateNode(I, St); |
Ted Kremenek | 754607e | 2008-02-13 00:24:44 +0000 | [diff] [blame] | 281 | } |
Ted Kremenek | f233d48 | 2008-02-05 00:26:40 +0000 | [diff] [blame] | 282 | |
Ted Kremenek | daeb9a7 | 2008-02-13 23:08:21 +0000 | [diff] [blame] | 283 | /// ProcessSwitch - Called by GRCoreEngine. Used to generate successor |
| 284 | /// nodes by processing the 'effects' of a switch statement. |
| 285 | void GRExprEngine::ProcessSwitch(SwitchNodeBuilder& builder) { |
| 286 | |
| 287 | typedef SwitchNodeBuilder::iterator iterator; |
| 288 | |
Ted Kremenek | aed9b6a | 2008-02-28 10:21:43 +0000 | [diff] [blame^] | 289 | ValueState* St = builder.getState(); |
Ted Kremenek | 692416c | 2008-02-18 22:57:02 +0000 | [diff] [blame] | 290 | Expr* CondE = builder.getCondition(); |
Ted Kremenek | aa1c4e5 | 2008-02-21 18:02:17 +0000 | [diff] [blame] | 291 | RVal CondV = GetRVal(St, CondE); |
Ted Kremenek | daeb9a7 | 2008-02-13 23:08:21 +0000 | [diff] [blame] | 292 | |
Ted Kremenek | 4a4e524 | 2008-02-28 09:25:22 +0000 | [diff] [blame] | 293 | if (CondV.isUndef()) { |
Ted Kremenek | daeb9a7 | 2008-02-13 23:08:21 +0000 | [diff] [blame] | 294 | NodeTy* N = builder.generateDefaultCaseNode(St, true); |
Ted Kremenek | 4a4e524 | 2008-02-28 09:25:22 +0000 | [diff] [blame] | 295 | UndefBranches.insert(N); |
Ted Kremenek | daeb9a7 | 2008-02-13 23:08:21 +0000 | [diff] [blame] | 296 | return; |
| 297 | } |
| 298 | |
Ted Kremenek | aed9b6a | 2008-02-28 10:21:43 +0000 | [diff] [blame^] | 299 | ValueState* DefaultSt = St; |
Ted Kremenek | daeb9a7 | 2008-02-13 23:08:21 +0000 | [diff] [blame] | 300 | |
| 301 | // While most of this can be assumed (such as the signedness), having it |
| 302 | // just computed makes sure everything makes the same assumptions end-to-end. |
Ted Kremenek | 692416c | 2008-02-18 22:57:02 +0000 | [diff] [blame] | 303 | |
| 304 | unsigned bits = getContext().getTypeSize(CondE->getType(), |
| 305 | CondE->getExprLoc()); |
| 306 | |
Ted Kremenek | daeb9a7 | 2008-02-13 23:08:21 +0000 | [diff] [blame] | 307 | APSInt V1(bits, false); |
| 308 | APSInt V2 = V1; |
| 309 | |
Ted Kremenek | aa1c4e5 | 2008-02-21 18:02:17 +0000 | [diff] [blame] | 310 | for (iterator I = builder.begin(), EI = builder.end(); I != EI; ++I) { |
Ted Kremenek | daeb9a7 | 2008-02-13 23:08:21 +0000 | [diff] [blame] | 311 | |
| 312 | CaseStmt* Case = cast<CaseStmt>(I.getCase()); |
| 313 | |
| 314 | // Evaluate the case. |
| 315 | if (!Case->getLHS()->isIntegerConstantExpr(V1, getContext(), 0, true)) { |
| 316 | assert (false && "Case condition must evaluate to an integer constant."); |
| 317 | return; |
| 318 | } |
| 319 | |
| 320 | // Get the RHS of the case, if it exists. |
| 321 | |
| 322 | if (Expr* E = Case->getRHS()) { |
| 323 | if (!E->isIntegerConstantExpr(V2, getContext(), 0, true)) { |
| 324 | assert (false && |
| 325 | "Case condition (RHS) must evaluate to an integer constant."); |
| 326 | return ; |
| 327 | } |
| 328 | |
| 329 | assert (V1 <= V2); |
| 330 | } |
| 331 | else V2 = V1; |
| 332 | |
| 333 | // FIXME: Eventually we should replace the logic below with a range |
| 334 | // comparison, rather than concretize the values within the range. |
Ted Kremenek | aa1c4e5 | 2008-02-21 18:02:17 +0000 | [diff] [blame] | 335 | // This should be easy once we have "ranges" for NonLVals. |
Ted Kremenek | daeb9a7 | 2008-02-13 23:08:21 +0000 | [diff] [blame] | 336 | |
| 337 | do { |
| 338 | nonlval::ConcreteInt CaseVal(ValMgr.getValue(V1)); |
| 339 | |
Ted Kremenek | aa1c4e5 | 2008-02-21 18:02:17 +0000 | [diff] [blame] | 340 | RVal Res = EvalBinOp(BinaryOperator::EQ, CondV, CaseVal); |
Ted Kremenek | daeb9a7 | 2008-02-13 23:08:21 +0000 | [diff] [blame] | 341 | |
| 342 | // Now "assume" that the case matches. |
Ted Kremenek | 692416c | 2008-02-18 22:57:02 +0000 | [diff] [blame] | 343 | bool isFeasible = false; |
Ted Kremenek | daeb9a7 | 2008-02-13 23:08:21 +0000 | [diff] [blame] | 344 | |
Ted Kremenek | aed9b6a | 2008-02-28 10:21:43 +0000 | [diff] [blame^] | 345 | ValueState* StNew = Assume(St, Res, true, isFeasible); |
Ted Kremenek | daeb9a7 | 2008-02-13 23:08:21 +0000 | [diff] [blame] | 346 | |
| 347 | if (isFeasible) { |
| 348 | builder.generateCaseStmtNode(I, StNew); |
| 349 | |
| 350 | // If CondV evaluates to a constant, then we know that this |
| 351 | // is the *only* case that we can take, so stop evaluating the |
| 352 | // others. |
| 353 | if (isa<nonlval::ConcreteInt>(CondV)) |
| 354 | return; |
| 355 | } |
| 356 | |
| 357 | // Now "assume" that the case doesn't match. Add this state |
| 358 | // to the default state (if it is feasible). |
| 359 | |
Ted Kremenek | 6cb0b54 | 2008-02-14 19:37:24 +0000 | [diff] [blame] | 360 | StNew = Assume(DefaultSt, Res, false, isFeasible); |
Ted Kremenek | daeb9a7 | 2008-02-13 23:08:21 +0000 | [diff] [blame] | 361 | |
| 362 | if (isFeasible) |
| 363 | DefaultSt = StNew; |
| 364 | |
| 365 | // Concretize the next value in the range. |
| 366 | ++V1; |
| 367 | |
| 368 | } while (V1 < V2); |
| 369 | } |
| 370 | |
| 371 | // If we reach here, than we know that the default branch is |
| 372 | // possible. |
| 373 | builder.generateDefaultCaseNode(DefaultSt); |
| 374 | } |
| 375 | |
| 376 | |
Ted Kremenek | 4d4dd85 | 2008-02-13 17:41:41 +0000 | [diff] [blame] | 377 | void GRExprEngine::VisitLogicalExpr(BinaryOperator* B, NodeTy* Pred, |
Ted Kremenek | aa1c4e5 | 2008-02-21 18:02:17 +0000 | [diff] [blame] | 378 | NodeSet& Dst) { |
Ted Kremenek | 9dca062 | 2008-02-19 00:22:37 +0000 | [diff] [blame] | 379 | |
Ted Kremenek | 05a2378 | 2008-02-26 19:05:15 +0000 | [diff] [blame] | 380 | assert (B->getOpcode() == BinaryOperator::LAnd || |
| 381 | B->getOpcode() == BinaryOperator::LOr); |
| 382 | |
| 383 | assert (B == CurrentStmt && getCFG().isBlkExpr(B)); |
| 384 | |
Ted Kremenek | aed9b6a | 2008-02-28 10:21:43 +0000 | [diff] [blame^] | 385 | ValueState* St = Pred->getState(); |
Ted Kremenek | 05a2378 | 2008-02-26 19:05:15 +0000 | [diff] [blame] | 386 | RVal X = GetBlkExprRVal(St, B); |
| 387 | |
Ted Kremenek | 4a4e524 | 2008-02-28 09:25:22 +0000 | [diff] [blame] | 388 | assert (X.isUndef()); |
Ted Kremenek | 05a2378 | 2008-02-26 19:05:15 +0000 | [diff] [blame] | 389 | |
Ted Kremenek | 4a4e524 | 2008-02-28 09:25:22 +0000 | [diff] [blame] | 390 | Expr* Ex = (Expr*) cast<UndefinedVal>(X).getData(); |
Ted Kremenek | 05a2378 | 2008-02-26 19:05:15 +0000 | [diff] [blame] | 391 | |
| 392 | assert (Ex); |
| 393 | |
| 394 | if (Ex == B->getRHS()) { |
| 395 | |
| 396 | X = GetBlkExprRVal(St, Ex); |
| 397 | |
Ted Kremenek | 4a4e524 | 2008-02-28 09:25:22 +0000 | [diff] [blame] | 398 | // Handle undefined values. |
Ted Kremenek | 58b3321 | 2008-02-26 19:40:44 +0000 | [diff] [blame] | 399 | |
Ted Kremenek | 4a4e524 | 2008-02-28 09:25:22 +0000 | [diff] [blame] | 400 | if (X.isUndef()) { |
Ted Kremenek | 58b3321 | 2008-02-26 19:40:44 +0000 | [diff] [blame] | 401 | Nodify(Dst, B, Pred, SetBlkExprRVal(St, B, X)); |
| 402 | return; |
| 403 | } |
| 404 | |
Ted Kremenek | 05a2378 | 2008-02-26 19:05:15 +0000 | [diff] [blame] | 405 | // We took the RHS. Because the value of the '&&' or '||' expression must |
| 406 | // evaluate to 0 or 1, we must assume the value of the RHS evaluates to 0 |
| 407 | // or 1. Alternatively, we could take a lazy approach, and calculate this |
| 408 | // value later when necessary. We don't have the machinery in place for |
| 409 | // this right now, and since most logical expressions are used for branches, |
| 410 | // the payoff is not likely to be large. Instead, we do eager evaluation. |
| 411 | |
| 412 | bool isFeasible = false; |
Ted Kremenek | aed9b6a | 2008-02-28 10:21:43 +0000 | [diff] [blame^] | 413 | ValueState* NewState = Assume(St, X, true, isFeasible); |
Ted Kremenek | 05a2378 | 2008-02-26 19:05:15 +0000 | [diff] [blame] | 414 | |
| 415 | if (isFeasible) |
| 416 | Nodify(Dst, B, Pred, SetBlkExprRVal(NewState, B, MakeConstantVal(1U, B))); |
| 417 | |
| 418 | isFeasible = false; |
| 419 | NewState = Assume(St, X, false, isFeasible); |
| 420 | |
| 421 | if (isFeasible) |
| 422 | Nodify(Dst, B, Pred, SetBlkExprRVal(NewState, B, MakeConstantVal(0U, B))); |
Ted Kremenek | f233d48 | 2008-02-05 00:26:40 +0000 | [diff] [blame] | 423 | } |
| 424 | else { |
Ted Kremenek | 05a2378 | 2008-02-26 19:05:15 +0000 | [diff] [blame] | 425 | // We took the LHS expression. Depending on whether we are '&&' or |
| 426 | // '||' we know what the value of the expression is via properties of |
| 427 | // the short-circuiting. |
| 428 | |
| 429 | X = MakeConstantVal( B->getOpcode() == BinaryOperator::LAnd ? 0U : 1U, B); |
| 430 | Nodify(Dst, B, Pred, SetBlkExprRVal(St, B, X)); |
Ted Kremenek | f233d48 | 2008-02-05 00:26:40 +0000 | [diff] [blame] | 431 | } |
Ted Kremenek | f233d48 | 2008-02-05 00:26:40 +0000 | [diff] [blame] | 432 | } |
Ted Kremenek | 05a2378 | 2008-02-26 19:05:15 +0000 | [diff] [blame] | 433 | |
Ted Kremenek | f233d48 | 2008-02-05 00:26:40 +0000 | [diff] [blame] | 434 | |
Ted Kremenek | 4d4dd85 | 2008-02-13 17:41:41 +0000 | [diff] [blame] | 435 | void GRExprEngine::ProcessStmt(Stmt* S, StmtNodeBuilder& builder) { |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 436 | |
Ted Kremenek | aa1c4e5 | 2008-02-21 18:02:17 +0000 | [diff] [blame] | 437 | Builder = &builder; |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 438 | StmtEntryNode = builder.getLastNode(); |
| 439 | CurrentStmt = S; |
| 440 | NodeSet Dst; |
| 441 | StateCleaned = false; |
| 442 | |
| 443 | Visit(S, StmtEntryNode, Dst); |
| 444 | |
| 445 | // If no nodes were generated, generate a new node that has all the |
| 446 | // dead mappings removed. |
Ted Kremenek | aa1c4e5 | 2008-02-21 18:02:17 +0000 | [diff] [blame] | 447 | |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 448 | if (Dst.size() == 1 && *Dst.begin() == StmtEntryNode) { |
Ted Kremenek | aed9b6a | 2008-02-28 10:21:43 +0000 | [diff] [blame^] | 449 | ValueState* St = RemoveDeadBindings(S, StmtEntryNode->getState()); |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 450 | builder.generateNode(S, St, StmtEntryNode); |
| 451 | } |
Ted Kremenek | f84469b | 2008-01-18 00:41:32 +0000 | [diff] [blame] | 452 | |
Ted Kremenek | aa1c4e5 | 2008-02-21 18:02:17 +0000 | [diff] [blame] | 453 | // For safety, NULL out these variables. |
| 454 | |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 455 | CurrentStmt = NULL; |
| 456 | StmtEntryNode = NULL; |
| 457 | Builder = NULL; |
Ted Kremenek | d27f816 | 2008-01-15 23:55:06 +0000 | [diff] [blame] | 458 | } |
| 459 | |
Ted Kremenek | 4d4dd85 | 2008-02-13 17:41:41 +0000 | [diff] [blame] | 460 | GRExprEngine::NodeTy* |
Ted Kremenek | aed9b6a | 2008-02-28 10:21:43 +0000 | [diff] [blame^] | 461 | GRExprEngine::Nodify(NodeSet& Dst, Stmt* S, NodeTy* Pred, ValueState* St) { |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 462 | |
| 463 | // If the state hasn't changed, don't generate a new node. |
Ted Kremenek | 7e59336 | 2008-02-07 15:20:13 +0000 | [diff] [blame] | 464 | if (St == Pred->getState()) |
Ted Kremenek | d131c4f | 2008-02-07 05:48:01 +0000 | [diff] [blame] | 465 | return NULL; |
Ted Kremenek | cb448ca | 2008-01-16 00:53:15 +0000 | [diff] [blame] | 466 | |
Ted Kremenek | d131c4f | 2008-02-07 05:48:01 +0000 | [diff] [blame] | 467 | NodeTy* N = Builder->generateNode(S, St, Pred); |
| 468 | Dst.Add(N); |
Ted Kremenek | aa1c4e5 | 2008-02-21 18:02:17 +0000 | [diff] [blame] | 469 | |
Ted Kremenek | d131c4f | 2008-02-07 05:48:01 +0000 | [diff] [blame] | 470 | return N; |
Ted Kremenek | cb448ca | 2008-01-16 00:53:15 +0000 | [diff] [blame] | 471 | } |
Ted Kremenek | d27f816 | 2008-01-15 23:55:06 +0000 | [diff] [blame] | 472 | |
Ted Kremenek | aed9b6a | 2008-02-28 10:21:43 +0000 | [diff] [blame^] | 473 | #if 0 |
Ted Kremenek | 4d4dd85 | 2008-02-13 17:41:41 +0000 | [diff] [blame] | 474 | void GRExprEngine::Nodify(NodeSet& Dst, Stmt* S, NodeTy* Pred, |
Ted Kremenek | aed9b6a | 2008-02-28 10:21:43 +0000 | [diff] [blame^] | 475 | const ValueState::BufferTy& SB) { |
Ted Kremenek | cba2e43 | 2008-02-05 19:35:18 +0000 | [diff] [blame] | 476 | |
Ted Kremenek | aed9b6a | 2008-02-28 10:21:43 +0000 | [diff] [blame^] | 477 | for (ValueState::BufferTy::const_iterator I=SB.begin(), E=SB.end(); I!=E; ++I) |
Ted Kremenek | cba2e43 | 2008-02-05 19:35:18 +0000 | [diff] [blame] | 478 | Nodify(Dst, S, Pred, *I); |
| 479 | } |
Ted Kremenek | aed9b6a | 2008-02-28 10:21:43 +0000 | [diff] [blame^] | 480 | #endif |
Ted Kremenek | cba2e43 | 2008-02-05 19:35:18 +0000 | [diff] [blame] | 481 | |
Ted Kremenek | 44842c2 | 2008-02-13 18:06:44 +0000 | [diff] [blame] | 482 | void GRExprEngine::VisitDeclRefExpr(DeclRefExpr* D, NodeTy* Pred, NodeSet& Dst){ |
Ted Kremenek | aa1c4e5 | 2008-02-21 18:02:17 +0000 | [diff] [blame] | 483 | |
Ted Kremenek | 3271f8d | 2008-02-07 04:16:04 +0000 | [diff] [blame] | 484 | if (D != CurrentStmt) { |
| 485 | Dst.Add(Pred); // No-op. Simply propagate the current state unchanged. |
| 486 | return; |
| 487 | } |
| 488 | |
| 489 | // If we are here, we are loading the value of the decl and binding |
| 490 | // it to the block-level expression. |
| 491 | |
Ted Kremenek | aed9b6a | 2008-02-28 10:21:43 +0000 | [diff] [blame^] | 492 | ValueState* St = Pred->getState(); |
Ted Kremenek | aa1c4e5 | 2008-02-21 18:02:17 +0000 | [diff] [blame] | 493 | Nodify(Dst, D, Pred, SetRVal(St, D, GetRVal(St, D))); |
Ted Kremenek | 3271f8d | 2008-02-07 04:16:04 +0000 | [diff] [blame] | 494 | } |
| 495 | |
Ted Kremenek | de43424 | 2008-02-19 01:44:53 +0000 | [diff] [blame] | 496 | void GRExprEngine::VisitCall(CallExpr* CE, NodeTy* Pred, |
Ted Kremenek | aa1c4e5 | 2008-02-21 18:02:17 +0000 | [diff] [blame] | 497 | CallExpr::arg_iterator AI, |
| 498 | CallExpr::arg_iterator AE, |
Ted Kremenek | de43424 | 2008-02-19 01:44:53 +0000 | [diff] [blame] | 499 | NodeSet& Dst) { |
| 500 | |
Ted Kremenek | aa1c4e5 | 2008-02-21 18:02:17 +0000 | [diff] [blame] | 501 | // Process the arguments. |
| 502 | |
| 503 | if (AI != AE) { |
Ted Kremenek | de43424 | 2008-02-19 01:44:53 +0000 | [diff] [blame] | 504 | |
Ted Kremenek | aa1c4e5 | 2008-02-21 18:02:17 +0000 | [diff] [blame] | 505 | NodeSet DstTmp; |
Ted Kremenek | a6fbe80 | 2008-02-27 00:44:11 +0000 | [diff] [blame] | 506 | |
Ted Kremenek | aa1c4e5 | 2008-02-21 18:02:17 +0000 | [diff] [blame] | 507 | Visit(*AI, Pred, DstTmp); |
Ted Kremenek | a6fbe80 | 2008-02-27 00:44:11 +0000 | [diff] [blame] | 508 | if (DstTmp.empty()) DstTmp.Add(Pred); |
| 509 | |
Ted Kremenek | aa1c4e5 | 2008-02-21 18:02:17 +0000 | [diff] [blame] | 510 | ++AI; |
| 511 | |
| 512 | for (NodeSet::iterator DI=DstTmp.begin(), DE=DstTmp.end(); DI != DE; ++DI) |
| 513 | VisitCall(CE, *DI, AI, AE, Dst); |
Ted Kremenek | de43424 | 2008-02-19 01:44:53 +0000 | [diff] [blame] | 514 | |
| 515 | return; |
| 516 | } |
| 517 | |
| 518 | // If we reach here we have processed all of the arguments. Evaluate |
| 519 | // the callee expression. |
Ted Kremenek | 994a09b | 2008-02-25 21:16:03 +0000 | [diff] [blame] | 520 | NodeSet DstTmp; |
| 521 | Expr* Callee = CE->getCallee()->IgnoreParenCasts(); |
| 522 | |
| 523 | VisitLVal(Callee, Pred, DstTmp); |
Ted Kremenek | 3ef1512 | 2008-02-27 00:46:25 +0000 | [diff] [blame] | 524 | if (DstTmp.empty()) DstTmp.Add(Pred); |
Ted Kremenek | de43424 | 2008-02-19 01:44:53 +0000 | [diff] [blame] | 525 | |
| 526 | // Finally, evaluate the function call. |
Ted Kremenek | aa1c4e5 | 2008-02-21 18:02:17 +0000 | [diff] [blame] | 527 | for (NodeSet::iterator DI = DstTmp.begin(), DE = DstTmp.end(); DI!=DE; ++DI) { |
| 528 | |
Ted Kremenek | aed9b6a | 2008-02-28 10:21:43 +0000 | [diff] [blame^] | 529 | ValueState* St = (*DI)->getState(); |
Ted Kremenek | 994a09b | 2008-02-25 21:16:03 +0000 | [diff] [blame] | 530 | RVal L = GetLVal(St, Callee); |
Ted Kremenek | de43424 | 2008-02-19 01:44:53 +0000 | [diff] [blame] | 531 | |
Ted Kremenek | 4a4e524 | 2008-02-28 09:25:22 +0000 | [diff] [blame] | 532 | // Check for undefined control-flow. |
Ted Kremenek | aa1c4e5 | 2008-02-21 18:02:17 +0000 | [diff] [blame] | 533 | |
Ted Kremenek | 4a4e524 | 2008-02-28 09:25:22 +0000 | [diff] [blame] | 534 | if (L.isUndef()) { |
Ted Kremenek | aa1c4e5 | 2008-02-21 18:02:17 +0000 | [diff] [blame] | 535 | |
Ted Kremenek | de43424 | 2008-02-19 01:44:53 +0000 | [diff] [blame] | 536 | NodeTy* N = Builder->generateNode(CE, St, *DI); |
| 537 | N->markAsSink(); |
Ted Kremenek | 4a4e524 | 2008-02-28 09:25:22 +0000 | [diff] [blame] | 538 | UndefBranches.insert(N); |
Ted Kremenek | de43424 | 2008-02-19 01:44:53 +0000 | [diff] [blame] | 539 | continue; |
| 540 | } |
| 541 | |
Ted Kremenek | 03da0d7 | 2008-02-21 19:46:04 +0000 | [diff] [blame] | 542 | if (L.isUnknown()) { |
| 543 | // Invalidate all arguments passed in by reference (LVals). |
| 544 | for (CallExpr::arg_iterator I = CE->arg_begin(), E = CE->arg_end(); |
| 545 | I != E; ++I) { |
| 546 | RVal V = GetRVal(St, *I); |
Ted Kremenek | aa1c4e5 | 2008-02-21 18:02:17 +0000 | [diff] [blame] | 547 | |
Ted Kremenek | 03da0d7 | 2008-02-21 19:46:04 +0000 | [diff] [blame] | 548 | if (isa<LVal>(V)) |
| 549 | St = SetRVal(St, cast<LVal>(V), UnknownVal()); |
| 550 | } |
| 551 | } |
| 552 | else |
| 553 | St = EvalCall(CE, cast<LVal>(L), (*DI)->getState()); |
| 554 | |
Ted Kremenek | affb215 | 2008-02-27 20:43:44 +0000 | [diff] [blame] | 555 | // Check for the "noreturn" attribute. |
| 556 | |
| 557 | if (isa<lval::FuncVal>(L)) |
| 558 | if (cast<lval::FuncVal>(L).getDecl()->getAttr<NoReturnAttr>()) { |
| 559 | |
| 560 | NodeTy* N = Builder->generateNode(CE, St, *DI); |
| 561 | |
| 562 | if (N) { |
| 563 | N->markAsSink(); |
| 564 | NoReturnCalls.insert(N); |
| 565 | } |
| 566 | |
| 567 | continue; |
| 568 | } |
| 569 | |
Ted Kremenek | 03da0d7 | 2008-02-21 19:46:04 +0000 | [diff] [blame] | 570 | Nodify(Dst, CE, *DI, St); |
Ted Kremenek | de43424 | 2008-02-19 01:44:53 +0000 | [diff] [blame] | 571 | } |
| 572 | } |
| 573 | |
Ted Kremenek | aa1c4e5 | 2008-02-21 18:02:17 +0000 | [diff] [blame] | 574 | void GRExprEngine::VisitCast(Expr* CastE, Expr* Ex, NodeTy* Pred, NodeSet& Dst){ |
Ted Kremenek | 874d63f | 2008-01-24 02:02:54 +0000 | [diff] [blame] | 575 | |
Ted Kremenek | 5d3003a | 2008-02-19 18:52:54 +0000 | [diff] [blame] | 576 | NodeSet S1; |
Ted Kremenek | aa1c4e5 | 2008-02-21 18:02:17 +0000 | [diff] [blame] | 577 | Visit(Ex, Pred, S1); |
Ted Kremenek | 874d63f | 2008-01-24 02:02:54 +0000 | [diff] [blame] | 578 | |
Ted Kremenek | 5d3003a | 2008-02-19 18:52:54 +0000 | [diff] [blame] | 579 | QualType T = CastE->getType(); |
| 580 | |
Ted Kremenek | 402563b | 2008-02-19 18:47:04 +0000 | [diff] [blame] | 581 | // Check for redundant casts or casting to "void" |
| 582 | if (T->isVoidType() || |
Ted Kremenek | aa1c4e5 | 2008-02-21 18:02:17 +0000 | [diff] [blame] | 583 | Ex->getType() == T || |
| 584 | (T->isPointerType() && Ex->getType()->isFunctionType())) { |
Ted Kremenek | 5d3003a | 2008-02-19 18:52:54 +0000 | [diff] [blame] | 585 | |
Ted Kremenek | aa1c4e5 | 2008-02-21 18:02:17 +0000 | [diff] [blame] | 586 | for (NodeSet::iterator I1 = S1.begin(), E1 = S1.end(); I1 != E1; ++I1) |
Ted Kremenek | 5d3003a | 2008-02-19 18:52:54 +0000 | [diff] [blame] | 587 | Dst.Add(*I1); |
| 588 | |
Ted Kremenek | 874d63f | 2008-01-24 02:02:54 +0000 | [diff] [blame] | 589 | return; |
| 590 | } |
| 591 | |
Ted Kremenek | aa1c4e5 | 2008-02-21 18:02:17 +0000 | [diff] [blame] | 592 | for (NodeSet::iterator I1 = S1.begin(), E1 = S1.end(); I1 != E1; ++I1) { |
Ted Kremenek | 874d63f | 2008-01-24 02:02:54 +0000 | [diff] [blame] | 593 | NodeTy* N = *I1; |
Ted Kremenek | aed9b6a | 2008-02-28 10:21:43 +0000 | [diff] [blame^] | 594 | ValueState* St = N->getState(); |
Ted Kremenek | aa1c4e5 | 2008-02-21 18:02:17 +0000 | [diff] [blame] | 595 | RVal V = GetRVal(St, Ex); |
Ted Kremenek | 9ef1ec9 | 2008-02-21 18:43:30 +0000 | [diff] [blame] | 596 | Nodify(Dst, CastE, N, SetRVal(St, CastE, EvalCast(V, CastE->getType()))); |
Ted Kremenek | 874d63f | 2008-01-24 02:02:54 +0000 | [diff] [blame] | 597 | } |
Ted Kremenek | 9de04c4 | 2008-01-24 20:55:43 +0000 | [diff] [blame] | 598 | } |
| 599 | |
Ted Kremenek | 4d4dd85 | 2008-02-13 17:41:41 +0000 | [diff] [blame] | 600 | void GRExprEngine::VisitDeclStmt(DeclStmt* DS, GRExprEngine::NodeTy* Pred, |
Ted Kremenek | aa1c4e5 | 2008-02-21 18:02:17 +0000 | [diff] [blame] | 601 | GRExprEngine::NodeSet& Dst) { |
Ted Kremenek | 9de04c4 | 2008-01-24 20:55:43 +0000 | [diff] [blame] | 602 | |
Ted Kremenek | aed9b6a | 2008-02-28 10:21:43 +0000 | [diff] [blame^] | 603 | ValueState* St = Pred->getState(); |
Ted Kremenek | 9de04c4 | 2008-01-24 20:55:43 +0000 | [diff] [blame] | 604 | |
| 605 | for (const ScopedDecl* D = DS->getDecl(); D; D = D->getNextDeclarator()) |
Ted Kremenek | 403c181 | 2008-01-28 22:51:57 +0000 | [diff] [blame] | 606 | if (const VarDecl* VD = dyn_cast<VarDecl>(D)) { |
Ted Kremenek | c2c95b0 | 2008-02-19 00:29:51 +0000 | [diff] [blame] | 607 | |
| 608 | // FIXME: Add support for local arrays. |
| 609 | if (VD->getType()->isArrayType()) |
| 610 | continue; |
| 611 | |
Ted Kremenek | b0ab212 | 2008-02-27 19:21:33 +0000 | [diff] [blame] | 612 | const Expr* Ex = VD->getInit(); |
Ted Kremenek | aa1c4e5 | 2008-02-21 18:02:17 +0000 | [diff] [blame] | 613 | |
Ted Kremenek | b0ab212 | 2008-02-27 19:21:33 +0000 | [diff] [blame] | 614 | if (!VD->hasGlobalStorage() || VD->getStorageClass() == VarDecl::Static) { |
| 615 | |
| 616 | // In this context, Static => Local variable. |
| 617 | |
| 618 | assert (!VD->getStorageClass() == VarDecl::Static || |
| 619 | !isa<FileVarDecl>(VD)); |
| 620 | |
| 621 | // If there is no initializer, set the value of the |
Ted Kremenek | 4a4e524 | 2008-02-28 09:25:22 +0000 | [diff] [blame] | 622 | // variable to "Undefined". |
Ted Kremenek | b0ab212 | 2008-02-27 19:21:33 +0000 | [diff] [blame] | 623 | // |
| 624 | // FIXME: static variables may have an initializer, but the second |
| 625 | // time a function is called those values may not be current. |
| 626 | |
| 627 | St = SetRVal(St, lval::DeclVal(VD), |
Ted Kremenek | 4a4e524 | 2008-02-28 09:25:22 +0000 | [diff] [blame] | 628 | Ex ? GetRVal(St, Ex) : UndefinedVal()); |
Ted Kremenek | b0ab212 | 2008-02-27 19:21:33 +0000 | [diff] [blame] | 629 | } |
Ted Kremenek | 403c181 | 2008-01-28 22:51:57 +0000 | [diff] [blame] | 630 | } |
Ted Kremenek | 9de04c4 | 2008-01-24 20:55:43 +0000 | [diff] [blame] | 631 | |
| 632 | Nodify(Dst, DS, Pred, St); |
| 633 | |
Ted Kremenek | aa1c4e5 | 2008-02-21 18:02:17 +0000 | [diff] [blame] | 634 | if (Dst.empty()) { Dst.Add(Pred); } |
Ted Kremenek | 9de04c4 | 2008-01-24 20:55:43 +0000 | [diff] [blame] | 635 | } |
Ted Kremenek | 874d63f | 2008-01-24 02:02:54 +0000 | [diff] [blame] | 636 | |
Ted Kremenek | f233d48 | 2008-02-05 00:26:40 +0000 | [diff] [blame] | 637 | |
Ted Kremenek | aa1c4e5 | 2008-02-21 18:02:17 +0000 | [diff] [blame] | 638 | void GRExprEngine::VisitGuardedExpr(Expr* Ex, Expr* L, Expr* R, |
Ted Kremenek | f233d48 | 2008-02-05 00:26:40 +0000 | [diff] [blame] | 639 | NodeTy* Pred, NodeSet& Dst) { |
| 640 | |
Ted Kremenek | 05a2378 | 2008-02-26 19:05:15 +0000 | [diff] [blame] | 641 | assert (Ex == CurrentStmt && getCFG().isBlkExpr(Ex)); |
| 642 | |
Ted Kremenek | aed9b6a | 2008-02-28 10:21:43 +0000 | [diff] [blame^] | 643 | ValueState* St = Pred->getState(); |
Ted Kremenek | 05a2378 | 2008-02-26 19:05:15 +0000 | [diff] [blame] | 644 | RVal X = GetBlkExprRVal(St, Ex); |
Ted Kremenek | f233d48 | 2008-02-05 00:26:40 +0000 | [diff] [blame] | 645 | |
Ted Kremenek | 4a4e524 | 2008-02-28 09:25:22 +0000 | [diff] [blame] | 646 | assert (X.isUndef()); |
Ted Kremenek | f233d48 | 2008-02-05 00:26:40 +0000 | [diff] [blame] | 647 | |
Ted Kremenek | 4a4e524 | 2008-02-28 09:25:22 +0000 | [diff] [blame] | 648 | Expr* SE = (Expr*) cast<UndefinedVal>(X).getData(); |
Ted Kremenek | 05a2378 | 2008-02-26 19:05:15 +0000 | [diff] [blame] | 649 | |
| 650 | assert (SE); |
| 651 | |
| 652 | X = GetBlkExprRVal(St, SE); |
Ted Kremenek | 5a7b382 | 2008-02-26 23:37:01 +0000 | [diff] [blame] | 653 | |
| 654 | // Make sure that we invalidate the previous binding. |
| 655 | Nodify(Dst, Ex, Pred, StateMgr.SetRVal(St, Ex, X, true, true)); |
Ted Kremenek | f233d48 | 2008-02-05 00:26:40 +0000 | [diff] [blame] | 656 | } |
| 657 | |
Ted Kremenek | d9435bf | 2008-02-12 19:49:57 +0000 | [diff] [blame] | 658 | /// VisitSizeOfAlignOfTypeExpr - Transfer function for sizeof(type). |
Ted Kremenek | aa1c4e5 | 2008-02-21 18:02:17 +0000 | [diff] [blame] | 659 | void GRExprEngine::VisitSizeOfAlignOfTypeExpr(SizeOfAlignOfTypeExpr* Ex, |
| 660 | NodeTy* Pred, |
| 661 | NodeSet& Dst) { |
Ted Kremenek | 9ef1ec9 | 2008-02-21 18:43:30 +0000 | [diff] [blame] | 662 | |
| 663 | assert (Ex->isSizeOf() && "FIXME: AlignOf(Expr) not yet implemented."); |
Ted Kremenek | d9435bf | 2008-02-12 19:49:57 +0000 | [diff] [blame] | 664 | |
| 665 | // 6.5.3.4 sizeof: "The result type is an integer." |
| 666 | |
Ted Kremenek | aa1c4e5 | 2008-02-21 18:02:17 +0000 | [diff] [blame] | 667 | QualType T = Ex->getArgumentType(); |
Ted Kremenek | 9ef1ec9 | 2008-02-21 18:43:30 +0000 | [diff] [blame] | 668 | |
Ted Kremenek | aa1c4e5 | 2008-02-21 18:02:17 +0000 | [diff] [blame] | 669 | |
Ted Kremenek | 297d0d7 | 2008-02-21 18:15:29 +0000 | [diff] [blame] | 670 | // FIXME: Add support for VLAs. |
Eli Friedman | d868856 | 2008-02-15 12:28:27 +0000 | [diff] [blame] | 671 | if (!T.getTypePtr()->isConstantSizeType()) |
Ted Kremenek | d9435bf | 2008-02-12 19:49:57 +0000 | [diff] [blame] | 672 | return; |
| 673 | |
Ted Kremenek | 297d0d7 | 2008-02-21 18:15:29 +0000 | [diff] [blame] | 674 | |
| 675 | uint64_t size = 1; // Handle sizeof(void) |
| 676 | |
| 677 | if (T != getContext().VoidTy) { |
| 678 | SourceLocation Loc = Ex->getExprLoc(); |
| 679 | size = getContext().getTypeSize(T, Loc) / 8; |
| 680 | } |
Ted Kremenek | d9435bf | 2008-02-12 19:49:57 +0000 | [diff] [blame] | 681 | |
Ted Kremenek | aa1c4e5 | 2008-02-21 18:02:17 +0000 | [diff] [blame] | 682 | Nodify(Dst, Ex, Pred, |
| 683 | SetRVal(Pred->getState(), Ex, |
Ted Kremenek | 297d0d7 | 2008-02-21 18:15:29 +0000 | [diff] [blame] | 684 | NonLVal::MakeVal(ValMgr, size, Ex->getType()))); |
Ted Kremenek | d9435bf | 2008-02-12 19:49:57 +0000 | [diff] [blame] | 685 | |
| 686 | } |
| 687 | |
Ted Kremenek | d8e9f0d | 2008-02-20 04:02:35 +0000 | [diff] [blame] | 688 | void GRExprEngine::VisitDeref(UnaryOperator* U, NodeTy* Pred, NodeSet& Dst) { |
| 689 | |
Ted Kremenek | aa1c4e5 | 2008-02-21 18:02:17 +0000 | [diff] [blame] | 690 | Expr* Ex = U->getSubExpr()->IgnoreParens(); |
Ted Kremenek | d8e9f0d | 2008-02-20 04:02:35 +0000 | [diff] [blame] | 691 | |
| 692 | NodeSet DstTmp; |
| 693 | |
Ted Kremenek | 018c15f | 2008-02-26 03:44:25 +0000 | [diff] [blame] | 694 | if (isa<DeclRefExpr>(Ex)) |
Ted Kremenek | d8e9f0d | 2008-02-20 04:02:35 +0000 | [diff] [blame] | 695 | DstTmp.Add(Pred); |
| 696 | else |
Ted Kremenek | aa1c4e5 | 2008-02-21 18:02:17 +0000 | [diff] [blame] | 697 | Visit(Ex, Pred, DstTmp); |
Ted Kremenek | d8e9f0d | 2008-02-20 04:02:35 +0000 | [diff] [blame] | 698 | |
Ted Kremenek | aa1c4e5 | 2008-02-21 18:02:17 +0000 | [diff] [blame] | 699 | for (NodeSet::iterator I = DstTmp.begin(), DE = DstTmp.end(); I != DE; ++I) { |
Ted Kremenek | d8e9f0d | 2008-02-20 04:02:35 +0000 | [diff] [blame] | 700 | |
| 701 | NodeTy* N = *I; |
Ted Kremenek | aed9b6a | 2008-02-28 10:21:43 +0000 | [diff] [blame^] | 702 | ValueState* St = N->getState(); |
Ted Kremenek | d8e9f0d | 2008-02-20 04:02:35 +0000 | [diff] [blame] | 703 | |
| 704 | // FIXME: Bifurcate when dereferencing a symbolic with no constraints? |
| 705 | |
Ted Kremenek | aa1c4e5 | 2008-02-21 18:02:17 +0000 | [diff] [blame] | 706 | RVal V = GetRVal(St, Ex); |
Ted Kremenek | d8e9f0d | 2008-02-20 04:02:35 +0000 | [diff] [blame] | 707 | |
Ted Kremenek | 4a4e524 | 2008-02-28 09:25:22 +0000 | [diff] [blame] | 708 | // Check for dereferences of undefined values. |
Ted Kremenek | aa1c4e5 | 2008-02-21 18:02:17 +0000 | [diff] [blame] | 709 | |
Ted Kremenek | 4a4e524 | 2008-02-28 09:25:22 +0000 | [diff] [blame] | 710 | if (V.isUndef()) { |
Ted Kremenek | aa1c4e5 | 2008-02-21 18:02:17 +0000 | [diff] [blame] | 711 | |
Ted Kremenek | d8e9f0d | 2008-02-20 04:02:35 +0000 | [diff] [blame] | 712 | NodeTy* Succ = Builder->generateNode(U, St, N); |
| 713 | |
| 714 | if (Succ) { |
| 715 | Succ->markAsSink(); |
Ted Kremenek | 4a4e524 | 2008-02-28 09:25:22 +0000 | [diff] [blame] | 716 | UndefDeref.insert(Succ); |
Ted Kremenek | d8e9f0d | 2008-02-20 04:02:35 +0000 | [diff] [blame] | 717 | } |
| 718 | |
| 719 | continue; |
| 720 | } |
| 721 | |
Ted Kremenek | aa1c4e5 | 2008-02-21 18:02:17 +0000 | [diff] [blame] | 722 | // Check for dereferences of unknown values. Treat as No-Ops. |
| 723 | |
| 724 | if (V.isUnknown()) { |
Ted Kremenek | d8e9f0d | 2008-02-20 04:02:35 +0000 | [diff] [blame] | 725 | Dst.Add(N); |
| 726 | continue; |
| 727 | } |
| 728 | |
| 729 | // After a dereference, one of two possible situations arise: |
| 730 | // (1) A crash, because the pointer was NULL. |
| 731 | // (2) The pointer is not NULL, and the dereference works. |
| 732 | // |
| 733 | // We add these assumptions. |
| 734 | |
Ted Kremenek | aa1c4e5 | 2008-02-21 18:02:17 +0000 | [diff] [blame] | 735 | LVal LV = cast<LVal>(V); |
Ted Kremenek | d8e9f0d | 2008-02-20 04:02:35 +0000 | [diff] [blame] | 736 | bool isFeasibleNotNull; |
| 737 | |
| 738 | // "Assume" that the pointer is Not-NULL. |
Ted Kremenek | aa1c4e5 | 2008-02-21 18:02:17 +0000 | [diff] [blame] | 739 | |
Ted Kremenek | aed9b6a | 2008-02-28 10:21:43 +0000 | [diff] [blame^] | 740 | ValueState* StNotNull = Assume(St, LV, true, isFeasibleNotNull); |
Ted Kremenek | d8e9f0d | 2008-02-20 04:02:35 +0000 | [diff] [blame] | 741 | |
| 742 | if (isFeasibleNotNull) { |
Ted Kremenek | d8e9f0d | 2008-02-20 04:02:35 +0000 | [diff] [blame] | 743 | |
| 744 | // FIXME: Currently symbolic analysis "generates" new symbols |
| 745 | // for the contents of values. We need a better approach. |
| 746 | |
Ted Kremenek | aa1c4e5 | 2008-02-21 18:02:17 +0000 | [diff] [blame] | 747 | Nodify(Dst, U, N, SetRVal(StNotNull, U, |
| 748 | GetRVal(StNotNull, LV, U->getType()))); |
Ted Kremenek | d8e9f0d | 2008-02-20 04:02:35 +0000 | [diff] [blame] | 749 | } |
| 750 | |
| 751 | bool isFeasibleNull; |
| 752 | |
Ted Kremenek | aa1c4e5 | 2008-02-21 18:02:17 +0000 | [diff] [blame] | 753 | // Now "assume" that the pointer is NULL. |
| 754 | |
Ted Kremenek | aed9b6a | 2008-02-28 10:21:43 +0000 | [diff] [blame^] | 755 | ValueState* StNull = Assume(St, LV, false, isFeasibleNull); |
Ted Kremenek | d8e9f0d | 2008-02-20 04:02:35 +0000 | [diff] [blame] | 756 | |
| 757 | if (isFeasibleNull) { |
Ted Kremenek | aa1c4e5 | 2008-02-21 18:02:17 +0000 | [diff] [blame] | 758 | |
Ted Kremenek | d8e9f0d | 2008-02-20 04:02:35 +0000 | [diff] [blame] | 759 | // We don't use "Nodify" here because the node will be a sink |
| 760 | // and we have no intention of processing it later. |
Ted Kremenek | aa1c4e5 | 2008-02-21 18:02:17 +0000 | [diff] [blame] | 761 | |
Ted Kremenek | d8e9f0d | 2008-02-20 04:02:35 +0000 | [diff] [blame] | 762 | NodeTy* NullNode = Builder->generateNode(U, StNull, N); |
| 763 | |
| 764 | if (NullNode) { |
Ted Kremenek | aa1c4e5 | 2008-02-21 18:02:17 +0000 | [diff] [blame] | 765 | |
Ted Kremenek | d8e9f0d | 2008-02-20 04:02:35 +0000 | [diff] [blame] | 766 | NullNode->markAsSink(); |
| 767 | |
Ted Kremenek | aa1c4e5 | 2008-02-21 18:02:17 +0000 | [diff] [blame] | 768 | if (isFeasibleNotNull) ImplicitNullDeref.insert(NullNode); |
| 769 | else ExplicitNullDeref.insert(NullNode); |
Ted Kremenek | d8e9f0d | 2008-02-20 04:02:35 +0000 | [diff] [blame] | 770 | } |
| 771 | } |
| 772 | } |
| 773 | } |
| 774 | |
Ted Kremenek | aa1c4e5 | 2008-02-21 18:02:17 +0000 | [diff] [blame] | 775 | void GRExprEngine::VisitUnaryOperator(UnaryOperator* U, NodeTy* Pred, |
| 776 | NodeSet& Dst) { |
Ted Kremenek | 3271f8d | 2008-02-07 04:16:04 +0000 | [diff] [blame] | 777 | |
Ted Kremenek | 7b8009a | 2008-01-24 02:28:56 +0000 | [diff] [blame] | 778 | NodeSet S1; |
Ted Kremenek | 3271f8d | 2008-02-07 04:16:04 +0000 | [diff] [blame] | 779 | |
Ted Kremenek | d8e9f0d | 2008-02-20 04:02:35 +0000 | [diff] [blame] | 780 | assert (U->getOpcode() != UnaryOperator::Deref); |
Ted Kremenek | aa1c4e5 | 2008-02-21 18:02:17 +0000 | [diff] [blame] | 781 | assert (U->getOpcode() != UnaryOperator::SizeOf); |
| 782 | assert (U->getOpcode() != UnaryOperator::AlignOf); |
| 783 | |
| 784 | bool use_GetLVal = false; |
Ted Kremenek | d8e9f0d | 2008-02-20 04:02:35 +0000 | [diff] [blame] | 785 | |
| 786 | switch (U->getOpcode()) { |
| 787 | case UnaryOperator::PostInc: |
| 788 | case UnaryOperator::PostDec: |
| 789 | case UnaryOperator::PreInc: |
| 790 | case UnaryOperator::PreDec: |
| 791 | case UnaryOperator::AddrOf: |
Ted Kremenek | aa1c4e5 | 2008-02-21 18:02:17 +0000 | [diff] [blame] | 792 | // Evalue subexpression as an LVal. |
| 793 | use_GetLVal = true; |
| 794 | VisitLVal(U->getSubExpr(), Pred, S1); |
Ted Kremenek | d8e9f0d | 2008-02-20 04:02:35 +0000 | [diff] [blame] | 795 | break; |
| 796 | |
| 797 | default: |
| 798 | Visit(U->getSubExpr(), Pred, S1); |
| 799 | break; |
| 800 | } |
| 801 | |
Ted Kremenek | aa1c4e5 | 2008-02-21 18:02:17 +0000 | [diff] [blame] | 802 | for (NodeSet::iterator I1 = S1.begin(), E1 = S1.end(); I1 != E1; ++I1) { |
Ted Kremenek | d8e9f0d | 2008-02-20 04:02:35 +0000 | [diff] [blame] | 803 | |
Ted Kremenek | 7b8009a | 2008-01-24 02:28:56 +0000 | [diff] [blame] | 804 | NodeTy* N1 = *I1; |
Ted Kremenek | aed9b6a | 2008-02-28 10:21:43 +0000 | [diff] [blame^] | 805 | ValueState* St = N1->getState(); |
Ted Kremenek | aa1c4e5 | 2008-02-21 18:02:17 +0000 | [diff] [blame] | 806 | |
| 807 | RVal SubV = use_GetLVal ? GetLVal(St, U->getSubExpr()) : |
| 808 | GetRVal(St, U->getSubExpr()); |
| 809 | |
| 810 | if (SubV.isUnknown()) { |
| 811 | Dst.Add(N1); |
| 812 | continue; |
| 813 | } |
| 814 | |
Ted Kremenek | 4a4e524 | 2008-02-28 09:25:22 +0000 | [diff] [blame] | 815 | if (SubV.isUndef()) { |
Ted Kremenek | aa1c4e5 | 2008-02-21 18:02:17 +0000 | [diff] [blame] | 816 | Nodify(Dst, U, N1, SetRVal(St, U, SubV)); |
| 817 | continue; |
| 818 | } |
Ted Kremenek | 7b8009a | 2008-01-24 02:28:56 +0000 | [diff] [blame] | 819 | |
Ted Kremenek | 50d0ac2 | 2008-02-15 22:09:30 +0000 | [diff] [blame] | 820 | if (U->isIncrementDecrementOp()) { |
Ted Kremenek | d8e9f0d | 2008-02-20 04:02:35 +0000 | [diff] [blame] | 821 | |
| 822 | // Handle ++ and -- (both pre- and post-increment). |
| 823 | |
Ted Kremenek | aa1c4e5 | 2008-02-21 18:02:17 +0000 | [diff] [blame] | 824 | LVal SubLV = cast<LVal>(SubV); |
| 825 | RVal V = GetRVal(St, SubLV, U->getType()); |
| 826 | |
Ted Kremenek | 89063af | 2008-02-21 19:15:37 +0000 | [diff] [blame] | 827 | if (V.isUnknown()) { |
| 828 | Dst.Add(N1); |
| 829 | continue; |
| 830 | } |
Ted Kremenek | aa1c4e5 | 2008-02-21 18:02:17 +0000 | [diff] [blame] | 831 | |
Ted Kremenek | 4a4e524 | 2008-02-28 09:25:22 +0000 | [diff] [blame] | 832 | // Propagate undefined values. |
| 833 | if (V.isUndef()) { |
Ted Kremenek | aa1c4e5 | 2008-02-21 18:02:17 +0000 | [diff] [blame] | 834 | Nodify(Dst, U, N1, SetRVal(St, U, V)); |
| 835 | continue; |
| 836 | } |
| 837 | |
Ted Kremenek | 443003b | 2008-02-21 19:29:23 +0000 | [diff] [blame] | 838 | // Handle all other values. |
Ted Kremenek | 50d0ac2 | 2008-02-15 22:09:30 +0000 | [diff] [blame] | 839 | |
| 840 | BinaryOperator::Opcode Op = U->isIncrementOp() ? BinaryOperator::Add |
| 841 | : BinaryOperator::Sub; |
| 842 | |
Ted Kremenek | 443003b | 2008-02-21 19:29:23 +0000 | [diff] [blame] | 843 | RVal Result = EvalBinOp(Op, V, MakeConstantVal(1U, U)); |
Ted Kremenek | 50d0ac2 | 2008-02-15 22:09:30 +0000 | [diff] [blame] | 844 | |
| 845 | if (U->isPostfix()) |
Ted Kremenek | aa1c4e5 | 2008-02-21 18:02:17 +0000 | [diff] [blame] | 846 | St = SetRVal(SetRVal(St, U, V), SubLV, Result); |
Ted Kremenek | 50d0ac2 | 2008-02-15 22:09:30 +0000 | [diff] [blame] | 847 | else |
Ted Kremenek | aa1c4e5 | 2008-02-21 18:02:17 +0000 | [diff] [blame] | 848 | St = SetRVal(SetRVal(St, U, Result), SubLV, Result); |
Ted Kremenek | 50d0ac2 | 2008-02-15 22:09:30 +0000 | [diff] [blame] | 849 | |
Ted Kremenek | aa1c4e5 | 2008-02-21 18:02:17 +0000 | [diff] [blame] | 850 | Nodify(Dst, U, N1, St); |
Ted Kremenek | 50d0ac2 | 2008-02-15 22:09:30 +0000 | [diff] [blame] | 851 | continue; |
| 852 | } |
| 853 | |
| 854 | // Handle all other unary operators. |
| 855 | |
Ted Kremenek | 7b8009a | 2008-01-24 02:28:56 +0000 | [diff] [blame] | 856 | switch (U->getOpcode()) { |
Ted Kremenek | cf78b6a | 2008-02-06 22:50:25 +0000 | [diff] [blame] | 857 | |
Ted Kremenek | aa1c4e5 | 2008-02-21 18:02:17 +0000 | [diff] [blame] | 858 | case UnaryOperator::Minus: |
| 859 | St = SetRVal(St, U, EvalMinus(U, cast<NonLVal>(SubV))); |
Ted Kremenek | dacbb4f | 2008-01-24 08:20:02 +0000 | [diff] [blame] | 860 | break; |
Ted Kremenek | dacbb4f | 2008-01-24 08:20:02 +0000 | [diff] [blame] | 861 | |
Ted Kremenek | aa1c4e5 | 2008-02-21 18:02:17 +0000 | [diff] [blame] | 862 | case UnaryOperator::Not: |
| 863 | St = SetRVal(St, U, EvalComplement(cast<NonLVal>(SubV))); |
Ted Kremenek | 90e4203 | 2008-02-20 04:12:31 +0000 | [diff] [blame] | 864 | break; |
Ted Kremenek | 90e4203 | 2008-02-20 04:12:31 +0000 | [diff] [blame] | 865 | |
Ted Kremenek | aa1c4e5 | 2008-02-21 18:02:17 +0000 | [diff] [blame] | 866 | case UnaryOperator::LNot: |
Ted Kremenek | c5d3b4c | 2008-02-04 16:58:30 +0000 | [diff] [blame] | 867 | |
Ted Kremenek | c60f0f7 | 2008-02-06 17:56:00 +0000 | [diff] [blame] | 868 | // C99 6.5.3.3: "The expression !E is equivalent to (0==E)." |
| 869 | // |
| 870 | // Note: technically we do "E == 0", but this is the same in the |
| 871 | // transfer functions as "0 == E". |
Ted Kremenek | aa1c4e5 | 2008-02-21 18:02:17 +0000 | [diff] [blame] | 872 | |
| 873 | if (isa<LVal>(SubV)) { |
| 874 | lval::ConcreteInt V(ValMgr.getZeroWithPtrWidth()); |
| 875 | RVal Result = EvalBinOp(BinaryOperator::EQ, cast<LVal>(SubV), V); |
| 876 | St = SetRVal(St, U, Result); |
Ted Kremenek | c60f0f7 | 2008-02-06 17:56:00 +0000 | [diff] [blame] | 877 | } |
| 878 | else { |
Ted Kremenek | f7ca696 | 2008-02-22 00:42:36 +0000 | [diff] [blame] | 879 | Expr* Ex = U->getSubExpr(); |
| 880 | nonlval::ConcreteInt V(ValMgr.getValue(0, Ex->getType())); |
Ted Kremenek | aa1c4e5 | 2008-02-21 18:02:17 +0000 | [diff] [blame] | 881 | RVal Result = EvalBinOp(BinaryOperator::EQ, cast<NonLVal>(SubV), V); |
| 882 | St = SetRVal(St, U, Result); |
Ted Kremenek | c60f0f7 | 2008-02-06 17:56:00 +0000 | [diff] [blame] | 883 | } |
| 884 | |
| 885 | break; |
Ted Kremenek | c60f0f7 | 2008-02-06 17:56:00 +0000 | [diff] [blame] | 886 | |
Ted Kremenek | 6492485 | 2008-01-31 02:35:41 +0000 | [diff] [blame] | 887 | case UnaryOperator::AddrOf: { |
Ted Kremenek | aa1c4e5 | 2008-02-21 18:02:17 +0000 | [diff] [blame] | 888 | assert (isa<LVal>(SubV)); |
| 889 | St = SetRVal(St, U, SubV); |
Ted Kremenek | 6492485 | 2008-01-31 02:35:41 +0000 | [diff] [blame] | 890 | break; |
| 891 | } |
Ted Kremenek | d131c4f | 2008-02-07 05:48:01 +0000 | [diff] [blame] | 892 | |
Ted Kremenek | 7b8009a | 2008-01-24 02:28:56 +0000 | [diff] [blame] | 893 | default: ; |
| 894 | assert (false && "Not implemented."); |
Ted Kremenek | aa1c4e5 | 2008-02-21 18:02:17 +0000 | [diff] [blame] | 895 | } |
| 896 | |
| 897 | Nodify(Dst, U, N1, St); |
Ted Kremenek | 7b8009a | 2008-01-24 02:28:56 +0000 | [diff] [blame] | 898 | } |
| 899 | } |
| 900 | |
Ted Kremenek | aa1c4e5 | 2008-02-21 18:02:17 +0000 | [diff] [blame] | 901 | void GRExprEngine::VisitSizeOfExpr(UnaryOperator* U, NodeTy* Pred, |
| 902 | NodeSet& Dst) { |
Ted Kremenek | d8e9f0d | 2008-02-20 04:02:35 +0000 | [diff] [blame] | 903 | |
Ted Kremenek | aa1c4e5 | 2008-02-21 18:02:17 +0000 | [diff] [blame] | 904 | QualType T = U->getSubExpr()->getType(); |
Ted Kremenek | d8e9f0d | 2008-02-20 04:02:35 +0000 | [diff] [blame] | 905 | |
Ted Kremenek | aa1c4e5 | 2008-02-21 18:02:17 +0000 | [diff] [blame] | 906 | // FIXME: Add support for VLAs. |
| 907 | if (!T.getTypePtr()->isConstantSizeType()) |
| 908 | return; |
| 909 | |
| 910 | SourceLocation Loc = U->getExprLoc(); |
| 911 | uint64_t size = getContext().getTypeSize(T, Loc) / 8; |
Ted Kremenek | aed9b6a | 2008-02-28 10:21:43 +0000 | [diff] [blame^] | 912 | ValueState* St = Pred->getState(); |
Ted Kremenek | aa1c4e5 | 2008-02-21 18:02:17 +0000 | [diff] [blame] | 913 | St = SetRVal(St, U, NonLVal::MakeVal(ValMgr, size, U->getType(), Loc)); |
| 914 | |
| 915 | Nodify(Dst, U, Pred, St); |
| 916 | } |
| 917 | |
| 918 | void GRExprEngine::VisitLVal(Expr* Ex, NodeTy* Pred, NodeSet& Dst) { |
Ted Kremenek | 2ad8868 | 2008-02-27 07:04:16 +0000 | [diff] [blame] | 919 | |
| 920 | if (Ex != CurrentStmt && getCFG().isBlkExpr(Ex)) { |
| 921 | Dst.Add(Pred); |
| 922 | return; |
| 923 | } |
Ted Kremenek | aa1c4e5 | 2008-02-21 18:02:17 +0000 | [diff] [blame] | 924 | |
| 925 | Ex = Ex->IgnoreParens(); |
| 926 | |
Ted Kremenek | 0793263 | 2008-02-27 06:47:26 +0000 | [diff] [blame] | 927 | if (isa<DeclRefExpr>(Ex)) { |
Ted Kremenek | 3271f8d | 2008-02-07 04:16:04 +0000 | [diff] [blame] | 928 | Dst.Add(Pred); |
Ted Kremenek | 5b6dc2d | 2008-02-07 01:08:27 +0000 | [diff] [blame] | 929 | return; |
Ted Kremenek | 3271f8d | 2008-02-07 04:16:04 +0000 | [diff] [blame] | 930 | } |
Ted Kremenek | 5b6dc2d | 2008-02-07 01:08:27 +0000 | [diff] [blame] | 931 | |
Ted Kremenek | aa1c4e5 | 2008-02-21 18:02:17 +0000 | [diff] [blame] | 932 | if (UnaryOperator* U = dyn_cast<UnaryOperator>(Ex)) { |
Ted Kremenek | 5b6dc2d | 2008-02-07 01:08:27 +0000 | [diff] [blame] | 933 | if (U->getOpcode() == UnaryOperator::Deref) { |
Ted Kremenek | aa1c4e5 | 2008-02-21 18:02:17 +0000 | [diff] [blame] | 934 | Ex = U->getSubExpr()->IgnoreParens(); |
Ted Kremenek | d8e9f0d | 2008-02-20 04:02:35 +0000 | [diff] [blame] | 935 | |
Ted Kremenek | aa1c4e5 | 2008-02-21 18:02:17 +0000 | [diff] [blame] | 936 | if (isa<DeclRefExpr>(Ex)) |
Ted Kremenek | d8e9f0d | 2008-02-20 04:02:35 +0000 | [diff] [blame] | 937 | Dst.Add(Pred); |
| 938 | else |
Ted Kremenek | aa1c4e5 | 2008-02-21 18:02:17 +0000 | [diff] [blame] | 939 | Visit(Ex, Pred, Dst); |
Ted Kremenek | d8e9f0d | 2008-02-20 04:02:35 +0000 | [diff] [blame] | 940 | |
Ted Kremenek | 5b6dc2d | 2008-02-07 01:08:27 +0000 | [diff] [blame] | 941 | return; |
| 942 | } |
| 943 | } |
| 944 | |
Ted Kremenek | aa1c4e5 | 2008-02-21 18:02:17 +0000 | [diff] [blame] | 945 | Visit(Ex, Pred, Dst); |
Ted Kremenek | 5b6dc2d | 2008-02-07 01:08:27 +0000 | [diff] [blame] | 946 | } |
| 947 | |
Ted Kremenek | 4d4dd85 | 2008-02-13 17:41:41 +0000 | [diff] [blame] | 948 | void GRExprEngine::VisitBinaryOperator(BinaryOperator* B, |
Ted Kremenek | daeb9a7 | 2008-02-13 23:08:21 +0000 | [diff] [blame] | 949 | GRExprEngine::NodeTy* Pred, |
| 950 | GRExprEngine::NodeSet& Dst) { |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 951 | NodeSet S1; |
Ted Kremenek | 5b6dc2d | 2008-02-07 01:08:27 +0000 | [diff] [blame] | 952 | |
| 953 | if (B->isAssignmentOp()) |
Ted Kremenek | aa1c4e5 | 2008-02-21 18:02:17 +0000 | [diff] [blame] | 954 | VisitLVal(B->getLHS(), Pred, S1); |
Ted Kremenek | 5b6dc2d | 2008-02-07 01:08:27 +0000 | [diff] [blame] | 955 | else |
| 956 | Visit(B->getLHS(), Pred, S1); |
Ted Kremenek | cb448ca | 2008-01-16 00:53:15 +0000 | [diff] [blame] | 957 | |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 958 | for (NodeSet::iterator I1=S1.begin(), E1=S1.end(); I1 != E1; ++I1) { |
Ted Kremenek | aa1c4e5 | 2008-02-21 18:02:17 +0000 | [diff] [blame] | 959 | |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 960 | NodeTy* N1 = *I1; |
Ted Kremenek | e00fe3f | 2008-01-17 00:52:48 +0000 | [diff] [blame] | 961 | |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 962 | // When getting the value for the LHS, check if we are in an assignment. |
Ted Kremenek | aa1c4e5 | 2008-02-21 18:02:17 +0000 | [diff] [blame] | 963 | // In such cases, we want to (initially) treat the LHS as an LVal, |
| 964 | // so we use GetLVal instead of GetRVal so that DeclRefExpr's are |
| 965 | // evaluated to LValDecl's instead of to an NonLVal. |
| 966 | |
| 967 | RVal LeftV = B->isAssignmentOp() ? GetLVal(N1->getState(), B->getLHS()) |
| 968 | : GetRVal(N1->getState(), B->getLHS()); |
Ted Kremenek | cb448ca | 2008-01-16 00:53:15 +0000 | [diff] [blame] | 969 | |
Ted Kremenek | aa1c4e5 | 2008-02-21 18:02:17 +0000 | [diff] [blame] | 970 | // Visit the RHS... |
| 971 | |
| 972 | NodeSet S2; |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 973 | Visit(B->getRHS(), N1, S2); |
Ted Kremenek | aa1c4e5 | 2008-02-21 18:02:17 +0000 | [diff] [blame] | 974 | |
| 975 | // Process the binary operator. |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 976 | |
Ted Kremenek | aa1c4e5 | 2008-02-21 18:02:17 +0000 | [diff] [blame] | 977 | for (NodeSet::iterator I2 = S2.begin(), E2 = S2.end(); I2 != E2; ++I2) { |
Ted Kremenek | cf78b6a | 2008-02-06 22:50:25 +0000 | [diff] [blame] | 978 | |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 979 | NodeTy* N2 = *I2; |
Ted Kremenek | aed9b6a | 2008-02-28 10:21:43 +0000 | [diff] [blame^] | 980 | ValueState* St = N2->getState(); |
Ted Kremenek | 3c8d0c5 | 2008-02-25 18:42:54 +0000 | [diff] [blame] | 981 | Expr* RHS = B->getRHS(); |
| 982 | RVal RightV = GetRVal(St, RHS); |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 983 | |
Ted Kremenek | cf78b6a | 2008-02-06 22:50:25 +0000 | [diff] [blame] | 984 | BinaryOperator::Opcode Op = B->getOpcode(); |
| 985 | |
Ted Kremenek | 3c8d0c5 | 2008-02-25 18:42:54 +0000 | [diff] [blame] | 986 | if ((Op == BinaryOperator::Div || Op == BinaryOperator::Rem) |
| 987 | && RHS->getType()->isIntegerType()) { |
Ted Kremenek | d763eb9 | 2008-02-26 02:15:56 +0000 | [diff] [blame] | 988 | |
Ted Kremenek | 4a4e524 | 2008-02-28 09:25:22 +0000 | [diff] [blame] | 989 | // Check if the denominator is undefined. |
Ted Kremenek | 3c8d0c5 | 2008-02-25 18:42:54 +0000 | [diff] [blame] | 990 | |
Ted Kremenek | 0015541 | 2008-02-26 22:27:51 +0000 | [diff] [blame] | 991 | if (!RightV.isUnknown()) { |
| 992 | |
Ted Kremenek | 4a4e524 | 2008-02-28 09:25:22 +0000 | [diff] [blame] | 993 | if (RightV.isUndef()) { |
| 994 | NodeTy* DivUndef = Builder->generateNode(B, St, N2); |
Ted Kremenek | 0015541 | 2008-02-26 22:27:51 +0000 | [diff] [blame] | 995 | |
Ted Kremenek | 4a4e524 | 2008-02-28 09:25:22 +0000 | [diff] [blame] | 996 | if (DivUndef) { |
| 997 | DivUndef->markAsSink(); |
| 998 | BadDivides.insert(DivUndef); |
Ted Kremenek | 0015541 | 2008-02-26 22:27:51 +0000 | [diff] [blame] | 999 | } |
| 1000 | |
| 1001 | continue; |
| 1002 | } |
| 1003 | |
| 1004 | // Check for divide/remainder-by-zero. |
| 1005 | // |
Ted Kremenek | 4a4e524 | 2008-02-28 09:25:22 +0000 | [diff] [blame] | 1006 | // First, "assume" that the denominator is 0 or undefined. |
Ted Kremenek | d763eb9 | 2008-02-26 02:15:56 +0000 | [diff] [blame] | 1007 | |
Ted Kremenek | 0015541 | 2008-02-26 22:27:51 +0000 | [diff] [blame] | 1008 | bool isFeasible = false; |
Ted Kremenek | aed9b6a | 2008-02-28 10:21:43 +0000 | [diff] [blame^] | 1009 | ValueState* ZeroSt = Assume(St, RightV, false, isFeasible); |
Ted Kremenek | 0015541 | 2008-02-26 22:27:51 +0000 | [diff] [blame] | 1010 | |
| 1011 | if (isFeasible) { |
| 1012 | NodeTy* DivZeroNode = Builder->generateNode(B, ZeroSt, N2); |
| 1013 | |
| 1014 | if (DivZeroNode) { |
| 1015 | DivZeroNode->markAsSink(); |
| 1016 | BadDivides.insert(DivZeroNode); |
| 1017 | } |
Ted Kremenek | d763eb9 | 2008-02-26 02:15:56 +0000 | [diff] [blame] | 1018 | } |
| 1019 | |
Ted Kremenek | 0015541 | 2008-02-26 22:27:51 +0000 | [diff] [blame] | 1020 | // Second, "assume" that the denominator cannot be 0. |
Ted Kremenek | d763eb9 | 2008-02-26 02:15:56 +0000 | [diff] [blame] | 1021 | |
Ted Kremenek | 0015541 | 2008-02-26 22:27:51 +0000 | [diff] [blame] | 1022 | isFeasible = false; |
| 1023 | St = Assume(St, RightV, true, isFeasible); |
Ted Kremenek | 07d83aa | 2008-02-25 17:51:31 +0000 | [diff] [blame] | 1024 | |
Ted Kremenek | 0015541 | 2008-02-26 22:27:51 +0000 | [diff] [blame] | 1025 | if (!isFeasible) |
| 1026 | continue; |
Ted Kremenek | 07d83aa | 2008-02-25 17:51:31 +0000 | [diff] [blame] | 1027 | } |
| 1028 | |
Ted Kremenek | 07d83aa | 2008-02-25 17:51:31 +0000 | [diff] [blame] | 1029 | // Fall-through. The logic below processes the divide. |
| 1030 | } |
| 1031 | |
Ted Kremenek | cf78b6a | 2008-02-06 22:50:25 +0000 | [diff] [blame] | 1032 | if (Op <= BinaryOperator::Or) { |
| 1033 | |
Ted Kremenek | aa1c4e5 | 2008-02-21 18:02:17 +0000 | [diff] [blame] | 1034 | // Process non-assignements except commas or short-circuited |
| 1035 | // logical expressions (LAnd and LOr). |
| 1036 | |
| 1037 | RVal Result = EvalBinOp(Op, LeftV, RightV); |
| 1038 | |
| 1039 | if (Result.isUnknown()) { |
| 1040 | Dst.Add(N2); |
Ted Kremenek | 5b6dc2d | 2008-02-07 01:08:27 +0000 | [diff] [blame] | 1041 | continue; |
| 1042 | } |
| 1043 | |
Ted Kremenek | aa1c4e5 | 2008-02-21 18:02:17 +0000 | [diff] [blame] | 1044 | Nodify(Dst, B, N2, SetRVal(St, B, Result)); |
Ted Kremenek | cf78b6a | 2008-02-06 22:50:25 +0000 | [diff] [blame] | 1045 | continue; |
| 1046 | } |
Ted Kremenek | aa1c4e5 | 2008-02-21 18:02:17 +0000 | [diff] [blame] | 1047 | |
| 1048 | // Process assignments. |
| 1049 | |
| 1050 | switch (Op) { |
| 1051 | |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 1052 | case BinaryOperator::Assign: { |
Ted Kremenek | aa1c4e5 | 2008-02-21 18:02:17 +0000 | [diff] [blame] | 1053 | |
| 1054 | // Simple assignments. |
Ted Kremenek | 9dca062 | 2008-02-19 00:22:37 +0000 | [diff] [blame] | 1055 | |
Ted Kremenek | 4a4e524 | 2008-02-28 09:25:22 +0000 | [diff] [blame] | 1056 | if (LeftV.isUndef()) { |
| 1057 | HandleUndefinedStore(B, N2); |
Ted Kremenek | aa1c4e5 | 2008-02-21 18:02:17 +0000 | [diff] [blame] | 1058 | continue; |
| 1059 | } |
| 1060 | |
| 1061 | if (LeftV.isUnknown()) { |
| 1062 | St = SetRVal(St, B, RightV); |
| 1063 | break; |
| 1064 | } |
Ted Kremenek | 9dca062 | 2008-02-19 00:22:37 +0000 | [diff] [blame] | 1065 | |
Ted Kremenek | aa1c4e5 | 2008-02-21 18:02:17 +0000 | [diff] [blame] | 1066 | St = SetRVal(SetRVal(St, B, RightV), cast<LVal>(LeftV), RightV); |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 1067 | break; |
| 1068 | } |
| 1069 | |
Ted Kremenek | aa1c4e5 | 2008-02-21 18:02:17 +0000 | [diff] [blame] | 1070 | // Compound assignment operators. |
Ted Kremenek | 687af80 | 2008-01-29 19:43:15 +0000 | [diff] [blame] | 1071 | |
Ted Kremenek | aa1c4e5 | 2008-02-21 18:02:17 +0000 | [diff] [blame] | 1072 | default: { |
Ted Kremenek | 9dca062 | 2008-02-19 00:22:37 +0000 | [diff] [blame] | 1073 | |
Ted Kremenek | 0015541 | 2008-02-26 22:27:51 +0000 | [diff] [blame] | 1074 | assert (B->isCompoundAssignmentOp()); |
| 1075 | |
| 1076 | if (Op >= BinaryOperator::AndAssign) |
| 1077 | ((int&) Op) -= (BinaryOperator::AndAssign - BinaryOperator::And); |
| 1078 | else |
| 1079 | ((int&) Op) -= BinaryOperator::MulAssign; |
| 1080 | |
Ted Kremenek | 4a4e524 | 2008-02-28 09:25:22 +0000 | [diff] [blame] | 1081 | // Check if the LHS is undefined. |
Ted Kremenek | aa1c4e5 | 2008-02-21 18:02:17 +0000 | [diff] [blame] | 1082 | |
Ted Kremenek | 4a4e524 | 2008-02-28 09:25:22 +0000 | [diff] [blame] | 1083 | if (LeftV.isUndef()) { |
| 1084 | HandleUndefinedStore(B, N2); |
Ted Kremenek | aa1c4e5 | 2008-02-21 18:02:17 +0000 | [diff] [blame] | 1085 | continue; |
| 1086 | } |
| 1087 | |
| 1088 | if (LeftV.isUnknown()) { |
| 1089 | |
| 1090 | // While we do not know the location to store RightV, |
| 1091 | // the entire expression does evaluate to RightV. |
| 1092 | |
| 1093 | if (RightV.isUnknown()) { |
| 1094 | Dst.Add(N2); |
| 1095 | continue; |
| 1096 | } |
| 1097 | |
| 1098 | St = SetRVal(St, B, RightV); |
Ted Kremenek | 9dca062 | 2008-02-19 00:22:37 +0000 | [diff] [blame] | 1099 | break; |
| 1100 | } |
| 1101 | |
Ted Kremenek | aa1c4e5 | 2008-02-21 18:02:17 +0000 | [diff] [blame] | 1102 | // At this pointer we know that the LHS evaluates to an LVal |
| 1103 | // that is neither "Unknown" or "Unintialized." |
| 1104 | |
| 1105 | LVal LeftLV = cast<LVal>(LeftV); |
| 1106 | |
Ted Kremenek | aa1c4e5 | 2008-02-21 18:02:17 +0000 | [diff] [blame] | 1107 | // Fetch the value of the LHS (the value of the variable, etc.). |
| 1108 | |
| 1109 | RVal V = GetRVal(N1->getState(), LeftLV, B->getLHS()->getType()); |
| 1110 | |
Ted Kremenek | 4a4e524 | 2008-02-28 09:25:22 +0000 | [diff] [blame] | 1111 | // Propagate undefined value (left-side). We |
| 1112 | // propogate undefined values for the RHS below when |
Ted Kremenek | 0015541 | 2008-02-26 22:27:51 +0000 | [diff] [blame] | 1113 | // we also check for divide-by-zero. |
Ted Kremenek | aa1c4e5 | 2008-02-21 18:02:17 +0000 | [diff] [blame] | 1114 | |
Ted Kremenek | 4a4e524 | 2008-02-28 09:25:22 +0000 | [diff] [blame] | 1115 | if (V.isUndef()) { |
Ted Kremenek | aa1c4e5 | 2008-02-21 18:02:17 +0000 | [diff] [blame] | 1116 | St = SetRVal(St, B, V); |
| 1117 | break; |
| 1118 | } |
| 1119 | |
| 1120 | // Propagate unknown values. |
| 1121 | |
Ted Kremenek | 89063af | 2008-02-21 19:15:37 +0000 | [diff] [blame] | 1122 | if (V.isUnknown()) { |
| 1123 | Dst.Add(N2); |
| 1124 | continue; |
| 1125 | } |
Ted Kremenek | aa1c4e5 | 2008-02-21 18:02:17 +0000 | [diff] [blame] | 1126 | |
| 1127 | if (RightV.isUnknown()) { |
| 1128 | St = SetRVal(SetRVal(St, LeftLV, RightV), B, RightV); |
| 1129 | break; |
| 1130 | } |
| 1131 | |
Ted Kremenek | 0015541 | 2008-02-26 22:27:51 +0000 | [diff] [blame] | 1132 | // At this point: |
| 1133 | // |
Ted Kremenek | 4a4e524 | 2008-02-28 09:25:22 +0000 | [diff] [blame] | 1134 | // The LHS is not Undef/Unknown. |
Ted Kremenek | 0015541 | 2008-02-26 22:27:51 +0000 | [diff] [blame] | 1135 | // The RHS is not Unknown. |
Ted Kremenek | cf78b6a | 2008-02-06 22:50:25 +0000 | [diff] [blame] | 1136 | |
Ted Kremenek | 9ef1ec9 | 2008-02-21 18:43:30 +0000 | [diff] [blame] | 1137 | // Get the computation type. |
| 1138 | QualType CTy = cast<CompoundAssignOperator>(B)->getComputationType(); |
| 1139 | |
| 1140 | // Perform promotions. |
| 1141 | V = EvalCast(V, CTy); |
Ted Kremenek | 61e090c | 2008-02-21 18:46:24 +0000 | [diff] [blame] | 1142 | RightV = EvalCast(RightV, CTy); |
Ted Kremenek | 9ef1ec9 | 2008-02-21 18:43:30 +0000 | [diff] [blame] | 1143 | |
| 1144 | // Evaluate operands and promote to result type. |
Ted Kremenek | 07d83aa | 2008-02-25 17:51:31 +0000 | [diff] [blame] | 1145 | |
Ted Kremenek | 3c8d0c5 | 2008-02-25 18:42:54 +0000 | [diff] [blame] | 1146 | if ((Op == BinaryOperator::Div || Op == BinaryOperator::Rem) |
| 1147 | && RHS->getType()->isIntegerType()) { |
| 1148 | |
Ted Kremenek | 4a4e524 | 2008-02-28 09:25:22 +0000 | [diff] [blame] | 1149 | // Check if the denominator is undefined. |
Ted Kremenek | d763eb9 | 2008-02-26 02:15:56 +0000 | [diff] [blame] | 1150 | |
Ted Kremenek | 4a4e524 | 2008-02-28 09:25:22 +0000 | [diff] [blame] | 1151 | if (RightV.isUndef()) { |
| 1152 | NodeTy* DivUndef = Builder->generateNode(B, St, N2); |
Ted Kremenek | d763eb9 | 2008-02-26 02:15:56 +0000 | [diff] [blame] | 1153 | |
Ted Kremenek | 4a4e524 | 2008-02-28 09:25:22 +0000 | [diff] [blame] | 1154 | if (DivUndef) { |
| 1155 | DivUndef->markAsSink(); |
| 1156 | BadDivides.insert(DivUndef); |
Ted Kremenek | d763eb9 | 2008-02-26 02:15:56 +0000 | [diff] [blame] | 1157 | } |
| 1158 | |
| 1159 | continue; |
| 1160 | } |
Ted Kremenek | 0015541 | 2008-02-26 22:27:51 +0000 | [diff] [blame] | 1161 | |
Ted Kremenek | 07d83aa | 2008-02-25 17:51:31 +0000 | [diff] [blame] | 1162 | // First, "assume" that the denominator is 0. |
| 1163 | |
| 1164 | bool isFeasible = false; |
Ted Kremenek | aed9b6a | 2008-02-28 10:21:43 +0000 | [diff] [blame^] | 1165 | ValueState* ZeroSt = Assume(St, RightV, false, isFeasible); |
Ted Kremenek | 07d83aa | 2008-02-25 17:51:31 +0000 | [diff] [blame] | 1166 | |
| 1167 | if (isFeasible) { |
| 1168 | NodeTy* DivZeroNode = Builder->generateNode(B, ZeroSt, N2); |
| 1169 | |
| 1170 | if (DivZeroNode) { |
| 1171 | DivZeroNode->markAsSink(); |
Ted Kremenek | d763eb9 | 2008-02-26 02:15:56 +0000 | [diff] [blame] | 1172 | BadDivides.insert(DivZeroNode); |
Ted Kremenek | 07d83aa | 2008-02-25 17:51:31 +0000 | [diff] [blame] | 1173 | } |
| 1174 | } |
| 1175 | |
| 1176 | // Second, "assume" that the denominator cannot be 0. |
| 1177 | |
| 1178 | isFeasible = false; |
| 1179 | St = Assume(St, RightV, true, isFeasible); |
| 1180 | |
| 1181 | if (!isFeasible) |
| 1182 | continue; |
| 1183 | |
| 1184 | // Fall-through. The logic below processes the divide. |
| 1185 | } |
Ted Kremenek | 0015541 | 2008-02-26 22:27:51 +0000 | [diff] [blame] | 1186 | else { |
| 1187 | |
Ted Kremenek | 4a4e524 | 2008-02-28 09:25:22 +0000 | [diff] [blame] | 1188 | // Propagate undefined values (right-side). |
Ted Kremenek | 0015541 | 2008-02-26 22:27:51 +0000 | [diff] [blame] | 1189 | |
Ted Kremenek | 4a4e524 | 2008-02-28 09:25:22 +0000 | [diff] [blame] | 1190 | if (RightV.isUndef()) { |
Ted Kremenek | 0015541 | 2008-02-26 22:27:51 +0000 | [diff] [blame] | 1191 | St = SetRVal(SetRVal(St, B, RightV), LeftLV, RightV); |
| 1192 | break; |
| 1193 | } |
| 1194 | |
| 1195 | } |
Ted Kremenek | 07d83aa | 2008-02-25 17:51:31 +0000 | [diff] [blame] | 1196 | |
Ted Kremenek | 9ef1ec9 | 2008-02-21 18:43:30 +0000 | [diff] [blame] | 1197 | RVal Result = EvalCast(EvalBinOp(Op, V, RightV), B->getType()); |
Ted Kremenek | aa1c4e5 | 2008-02-21 18:02:17 +0000 | [diff] [blame] | 1198 | St = SetRVal(SetRVal(St, B, Result), LeftLV, Result); |
Ted Kremenek | cf78b6a | 2008-02-06 22:50:25 +0000 | [diff] [blame] | 1199 | } |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 1200 | } |
Ted Kremenek | aa1c4e5 | 2008-02-21 18:02:17 +0000 | [diff] [blame] | 1201 | |
| 1202 | Nodify(Dst, B, N2, St); |
Ted Kremenek | cb448ca | 2008-01-16 00:53:15 +0000 | [diff] [blame] | 1203 | } |
Ted Kremenek | d27f816 | 2008-01-15 23:55:06 +0000 | [diff] [blame] | 1204 | } |
Ted Kremenek | d27f816 | 2008-01-15 23:55:06 +0000 | [diff] [blame] | 1205 | } |
Ted Kremenek | ee98546 | 2008-01-16 18:18:48 +0000 | [diff] [blame] | 1206 | |
Ted Kremenek | 4a4e524 | 2008-02-28 09:25:22 +0000 | [diff] [blame] | 1207 | void GRExprEngine::HandleUndefinedStore(Stmt* S, NodeTy* Pred) { |
Ted Kremenek | 9dca062 | 2008-02-19 00:22:37 +0000 | [diff] [blame] | 1208 | NodeTy* N = Builder->generateNode(S, Pred->getState(), Pred); |
| 1209 | N->markAsSink(); |
Ted Kremenek | 4a4e524 | 2008-02-28 09:25:22 +0000 | [diff] [blame] | 1210 | UndefStores.insert(N); |
Ted Kremenek | 9dca062 | 2008-02-19 00:22:37 +0000 | [diff] [blame] | 1211 | } |
Ted Kremenek | 1ccd31c | 2008-01-16 19:42:59 +0000 | [diff] [blame] | 1212 | |
Ted Kremenek | 9dca062 | 2008-02-19 00:22:37 +0000 | [diff] [blame] | 1213 | void GRExprEngine::Visit(Stmt* S, NodeTy* Pred, NodeSet& Dst) { |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 1214 | |
| 1215 | // FIXME: add metadata to the CFG so that we can disable |
| 1216 | // this check when we KNOW that there is no block-level subexpression. |
| 1217 | // The motivation is that this check requires a hashtable lookup. |
| 1218 | |
| 1219 | if (S != CurrentStmt && getCFG().isBlkExpr(S)) { |
| 1220 | Dst.Add(Pred); |
| 1221 | return; |
| 1222 | } |
| 1223 | |
| 1224 | switch (S->getStmtClass()) { |
Ted Kremenek | 230aaab | 2008-02-12 21:37:25 +0000 | [diff] [blame] | 1225 | |
| 1226 | default: |
| 1227 | // Cases we intentionally have "default" handle: |
Ted Kremenek | 189c305 | 2008-02-26 19:17:09 +0000 | [diff] [blame] | 1228 | // AddrLabelExpr, IntegerLiteral, CharacterLiteral |
Ted Kremenek | 230aaab | 2008-02-12 21:37:25 +0000 | [diff] [blame] | 1229 | |
| 1230 | Dst.Add(Pred); // No-op. Simply propagate the current state unchanged. |
| 1231 | break; |
| 1232 | |
Ted Kremenek | d70b62e | 2008-02-08 20:29:23 +0000 | [diff] [blame] | 1233 | case Stmt::BinaryOperatorClass: { |
| 1234 | BinaryOperator* B = cast<BinaryOperator>(S); |
Ted Kremenek | f233d48 | 2008-02-05 00:26:40 +0000 | [diff] [blame] | 1235 | |
Ted Kremenek | d70b62e | 2008-02-08 20:29:23 +0000 | [diff] [blame] | 1236 | if (B->isLogicalOp()) { |
| 1237 | VisitLogicalExpr(B, Pred, Dst); |
Ted Kremenek | f233d48 | 2008-02-05 00:26:40 +0000 | [diff] [blame] | 1238 | break; |
| 1239 | } |
Ted Kremenek | d70b62e | 2008-02-08 20:29:23 +0000 | [diff] [blame] | 1240 | else if (B->getOpcode() == BinaryOperator::Comma) { |
Ted Kremenek | aed9b6a | 2008-02-28 10:21:43 +0000 | [diff] [blame^] | 1241 | ValueState* St = Pred->getState(); |
Ted Kremenek | aa1c4e5 | 2008-02-21 18:02:17 +0000 | [diff] [blame] | 1242 | Nodify(Dst, B, Pred, SetRVal(St, B, GetRVal(St, B->getRHS()))); |
Ted Kremenek | da9bd09 | 2008-02-08 07:05:39 +0000 | [diff] [blame] | 1243 | break; |
| 1244 | } |
Ted Kremenek | d9435bf | 2008-02-12 19:49:57 +0000 | [diff] [blame] | 1245 | |
| 1246 | VisitBinaryOperator(cast<BinaryOperator>(S), Pred, Dst); |
| 1247 | break; |
| 1248 | } |
Ted Kremenek | de43424 | 2008-02-19 01:44:53 +0000 | [diff] [blame] | 1249 | |
| 1250 | case Stmt::CallExprClass: { |
| 1251 | CallExpr* C = cast<CallExpr>(S); |
| 1252 | VisitCall(C, Pred, C->arg_begin(), C->arg_end(), Dst); |
| 1253 | break; |
| 1254 | } |
Ted Kremenek | d9435bf | 2008-02-12 19:49:57 +0000 | [diff] [blame] | 1255 | |
| 1256 | case Stmt::CastExprClass: { |
| 1257 | CastExpr* C = cast<CastExpr>(S); |
| 1258 | VisitCast(C, C->getSubExpr(), Pred, Dst); |
| 1259 | break; |
Ted Kremenek | d70b62e | 2008-02-08 20:29:23 +0000 | [diff] [blame] | 1260 | } |
Ted Kremenek | 189c305 | 2008-02-26 19:17:09 +0000 | [diff] [blame] | 1261 | |
Ted Kremenek | aa1c4e5 | 2008-02-21 18:02:17 +0000 | [diff] [blame] | 1262 | // FIXME: ChooseExpr is really a constant. We need to fix |
| 1263 | // the CFG do not model them as explicit control-flow. |
| 1264 | |
Ted Kremenek | d9435bf | 2008-02-12 19:49:57 +0000 | [diff] [blame] | 1265 | case Stmt::ChooseExprClass: { // __builtin_choose_expr |
| 1266 | ChooseExpr* C = cast<ChooseExpr>(S); |
| 1267 | VisitGuardedExpr(C, C->getLHS(), C->getRHS(), Pred, Dst); |
| 1268 | break; |
| 1269 | } |
Ted Kremenek | f233d48 | 2008-02-05 00:26:40 +0000 | [diff] [blame] | 1270 | |
Ted Kremenek | b4ae33f | 2008-01-23 23:38:00 +0000 | [diff] [blame] | 1271 | case Stmt::CompoundAssignOperatorClass: |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 1272 | VisitBinaryOperator(cast<BinaryOperator>(S), Pred, Dst); |
| 1273 | break; |
| 1274 | |
Ted Kremenek | d9435bf | 2008-02-12 19:49:57 +0000 | [diff] [blame] | 1275 | case Stmt::ConditionalOperatorClass: { // '?' operator |
| 1276 | ConditionalOperator* C = cast<ConditionalOperator>(S); |
| 1277 | VisitGuardedExpr(C, C->getLHS(), C->getRHS(), Pred, Dst); |
| 1278 | break; |
| 1279 | } |
| 1280 | |
| 1281 | case Stmt::DeclRefExprClass: |
| 1282 | VisitDeclRefExpr(cast<DeclRefExpr>(S), Pred, Dst); |
| 1283 | break; |
| 1284 | |
| 1285 | case Stmt::DeclStmtClass: |
| 1286 | VisitDeclStmt(cast<DeclStmt>(S), Pred, Dst); |
| 1287 | break; |
| 1288 | |
| 1289 | case Stmt::ImplicitCastExprClass: { |
| 1290 | ImplicitCastExpr* C = cast<ImplicitCastExpr>(S); |
| 1291 | VisitCast(C, C->getSubExpr(), Pred, Dst); |
| 1292 | break; |
| 1293 | } |
| 1294 | |
| 1295 | case Stmt::ParenExprClass: |
| 1296 | Visit(cast<ParenExpr>(S)->getSubExpr(), Pred, Dst); |
| 1297 | break; |
| 1298 | |
| 1299 | case Stmt::SizeOfAlignOfTypeExprClass: |
| 1300 | VisitSizeOfAlignOfTypeExpr(cast<SizeOfAlignOfTypeExpr>(S), Pred, Dst); |
| 1301 | break; |
| 1302 | |
Ted Kremenek | da9bd09 | 2008-02-08 07:05:39 +0000 | [diff] [blame] | 1303 | case Stmt::StmtExprClass: { |
Ted Kremenek | d70b62e | 2008-02-08 20:29:23 +0000 | [diff] [blame] | 1304 | StmtExpr* SE = cast<StmtExpr>(S); |
| 1305 | |
Ted Kremenek | aed9b6a | 2008-02-28 10:21:43 +0000 | [diff] [blame^] | 1306 | ValueState* St = Pred->getState(); |
Ted Kremenek | d70b62e | 2008-02-08 20:29:23 +0000 | [diff] [blame] | 1307 | Expr* LastExpr = cast<Expr>(*SE->getSubStmt()->body_rbegin()); |
Ted Kremenek | aa1c4e5 | 2008-02-21 18:02:17 +0000 | [diff] [blame] | 1308 | Nodify(Dst, SE, Pred, SetRVal(St, SE, GetRVal(St, LastExpr))); |
Ted Kremenek | da9bd09 | 2008-02-08 07:05:39 +0000 | [diff] [blame] | 1309 | break; |
| 1310 | } |
| 1311 | |
Ted Kremenek | aa1c4e5 | 2008-02-21 18:02:17 +0000 | [diff] [blame] | 1312 | // FIXME: We may wish to always bind state to ReturnStmts so |
| 1313 | // that users can quickly query what was the state at the |
| 1314 | // exit points of a function. |
| 1315 | |
Ted Kremenek | d9435bf | 2008-02-12 19:49:57 +0000 | [diff] [blame] | 1316 | case Stmt::ReturnStmtClass: { |
Ted Kremenek | 5b6dc2d | 2008-02-07 01:08:27 +0000 | [diff] [blame] | 1317 | if (Expr* R = cast<ReturnStmt>(S)->getRetValue()) |
| 1318 | Visit(R, Pred, Dst); |
| 1319 | else |
| 1320 | Dst.Add(Pred); |
| 1321 | |
| 1322 | break; |
Ted Kremenek | d9435bf | 2008-02-12 19:49:57 +0000 | [diff] [blame] | 1323 | } |
Ted Kremenek | 5b6dc2d | 2008-02-07 01:08:27 +0000 | [diff] [blame] | 1324 | |
Ted Kremenek | d8e9f0d | 2008-02-20 04:02:35 +0000 | [diff] [blame] | 1325 | case Stmt::UnaryOperatorClass: { |
| 1326 | UnaryOperator* U = cast<UnaryOperator>(S); |
| 1327 | |
Ted Kremenek | aa1c4e5 | 2008-02-21 18:02:17 +0000 | [diff] [blame] | 1328 | switch (U->getOpcode()) { |
| 1329 | case UnaryOperator::Deref: VisitDeref(U, Pred, Dst); break; |
| 1330 | case UnaryOperator::Plus: Visit(U->getSubExpr(), Pred, Dst); break; |
| 1331 | case UnaryOperator::SizeOf: VisitSizeOfExpr(U, Pred, Dst); break; |
| 1332 | default: VisitUnaryOperator(U, Pred, Dst); break; |
| 1333 | } |
Ted Kremenek | d8e9f0d | 2008-02-20 04:02:35 +0000 | [diff] [blame] | 1334 | |
Ted Kremenek | 9de04c4 | 2008-01-24 20:55:43 +0000 | [diff] [blame] | 1335 | break; |
Ted Kremenek | d8e9f0d | 2008-02-20 04:02:35 +0000 | [diff] [blame] | 1336 | } |
Ted Kremenek | 79649df | 2008-01-17 18:25:22 +0000 | [diff] [blame] | 1337 | } |
Ted Kremenek | 1ccd31c | 2008-01-16 19:42:59 +0000 | [diff] [blame] | 1338 | } |
| 1339 | |
Ted Kremenek | ee98546 | 2008-01-16 18:18:48 +0000 | [diff] [blame] | 1340 | //===----------------------------------------------------------------------===// |
Ted Kremenek | b38911f | 2008-01-30 23:03:39 +0000 | [diff] [blame] | 1341 | // "Assume" logic. |
| 1342 | //===----------------------------------------------------------------------===// |
| 1343 | |
Ted Kremenek | aed9b6a | 2008-02-28 10:21:43 +0000 | [diff] [blame^] | 1344 | ValueState* GRExprEngine::Assume(ValueState* St, LVal Cond, |
Ted Kremenek | 692416c | 2008-02-18 22:57:02 +0000 | [diff] [blame] | 1345 | bool Assumption, |
Ted Kremenek | aa1c4e5 | 2008-02-21 18:02:17 +0000 | [diff] [blame] | 1346 | bool& isFeasible) { |
Ted Kremenek | a6e4d21 | 2008-02-01 06:36:40 +0000 | [diff] [blame] | 1347 | switch (Cond.getSubKind()) { |
| 1348 | default: |
Ted Kremenek | aa1c4e5 | 2008-02-21 18:02:17 +0000 | [diff] [blame] | 1349 | assert (false && "'Assume' not implemented for this LVal."); |
Ted Kremenek | a6e4d21 | 2008-02-01 06:36:40 +0000 | [diff] [blame] | 1350 | return St; |
| 1351 | |
Ted Kremenek | 862d5bb | 2008-02-06 00:54:14 +0000 | [diff] [blame] | 1352 | case lval::SymbolValKind: |
| 1353 | if (Assumption) |
| 1354 | return AssumeSymNE(St, cast<lval::SymbolVal>(Cond).getSymbol(), |
| 1355 | ValMgr.getZeroWithPtrWidth(), isFeasible); |
| 1356 | else |
| 1357 | return AssumeSymEQ(St, cast<lval::SymbolVal>(Cond).getSymbol(), |
| 1358 | ValMgr.getZeroWithPtrWidth(), isFeasible); |
| 1359 | |
Ted Kremenek | 08b6625 | 2008-02-06 04:31:33 +0000 | [diff] [blame] | 1360 | |
Ted Kremenek | 329f854 | 2008-02-05 21:52:21 +0000 | [diff] [blame] | 1361 | case lval::DeclValKind: |
Ted Kremenek | dc3936b | 2008-02-22 00:54:56 +0000 | [diff] [blame] | 1362 | case lval::FuncValKind: |
| 1363 | case lval::GotoLabelKind: |
Ted Kremenek | a6e4d21 | 2008-02-01 06:36:40 +0000 | [diff] [blame] | 1364 | isFeasible = Assumption; |
| 1365 | return St; |
Ted Kremenek | 862d5bb | 2008-02-06 00:54:14 +0000 | [diff] [blame] | 1366 | |
Ted Kremenek | 329f854 | 2008-02-05 21:52:21 +0000 | [diff] [blame] | 1367 | case lval::ConcreteIntKind: { |
| 1368 | bool b = cast<lval::ConcreteInt>(Cond).getValue() != 0; |
Ted Kremenek | a6e4d21 | 2008-02-01 06:36:40 +0000 | [diff] [blame] | 1369 | isFeasible = b ? Assumption : !Assumption; |
| 1370 | return St; |
| 1371 | } |
| 1372 | } |
Ted Kremenek | b38911f | 2008-01-30 23:03:39 +0000 | [diff] [blame] | 1373 | } |
| 1374 | |
Ted Kremenek | aed9b6a | 2008-02-28 10:21:43 +0000 | [diff] [blame^] | 1375 | ValueState* GRExprEngine::Assume(ValueState* St, NonLVal Cond, |
Ted Kremenek | 862d5bb | 2008-02-06 00:54:14 +0000 | [diff] [blame] | 1376 | bool Assumption, |
Ted Kremenek | aa1c4e5 | 2008-02-21 18:02:17 +0000 | [diff] [blame] | 1377 | bool& isFeasible) { |
Ted Kremenek | b38911f | 2008-01-30 23:03:39 +0000 | [diff] [blame] | 1378 | switch (Cond.getSubKind()) { |
| 1379 | default: |
Ted Kremenek | aa1c4e5 | 2008-02-21 18:02:17 +0000 | [diff] [blame] | 1380 | assert (false && "'Assume' not implemented for this NonLVal."); |
Ted Kremenek | b38911f | 2008-01-30 23:03:39 +0000 | [diff] [blame] | 1381 | return St; |
| 1382 | |
Ted Kremenek | feb01f6 | 2008-02-06 17:32:17 +0000 | [diff] [blame] | 1383 | |
| 1384 | case nonlval::SymbolValKind: { |
Ted Kremenek | 230aaab | 2008-02-12 21:37:25 +0000 | [diff] [blame] | 1385 | nonlval::SymbolVal& SV = cast<nonlval::SymbolVal>(Cond); |
Ted Kremenek | feb01f6 | 2008-02-06 17:32:17 +0000 | [diff] [blame] | 1386 | SymbolID sym = SV.getSymbol(); |
| 1387 | |
| 1388 | if (Assumption) |
| 1389 | return AssumeSymNE(St, sym, ValMgr.getValue(0, SymMgr.getType(sym)), |
| 1390 | isFeasible); |
| 1391 | else |
| 1392 | return AssumeSymEQ(St, sym, ValMgr.getValue(0, SymMgr.getType(sym)), |
| 1393 | isFeasible); |
| 1394 | } |
| 1395 | |
Ted Kremenek | 08b6625 | 2008-02-06 04:31:33 +0000 | [diff] [blame] | 1396 | case nonlval::SymIntConstraintValKind: |
| 1397 | return |
| 1398 | AssumeSymInt(St, Assumption, |
| 1399 | cast<nonlval::SymIntConstraintVal>(Cond).getConstraint(), |
| 1400 | isFeasible); |
| 1401 | |
Ted Kremenek | 329f854 | 2008-02-05 21:52:21 +0000 | [diff] [blame] | 1402 | case nonlval::ConcreteIntKind: { |
| 1403 | bool b = cast<nonlval::ConcreteInt>(Cond).getValue() != 0; |
Ted Kremenek | b38911f | 2008-01-30 23:03:39 +0000 | [diff] [blame] | 1404 | isFeasible = b ? Assumption : !Assumption; |
| 1405 | return St; |
| 1406 | } |
| 1407 | } |
| 1408 | } |
| 1409 | |
Ted Kremenek | aed9b6a | 2008-02-28 10:21:43 +0000 | [diff] [blame^] | 1410 | ValueState* |
| 1411 | GRExprEngine::AssumeSymNE(ValueState* St, SymbolID sym, |
Ted Kremenek | 862d5bb | 2008-02-06 00:54:14 +0000 | [diff] [blame] | 1412 | const llvm::APSInt& V, bool& isFeasible) { |
Ted Kremenek | 692416c | 2008-02-18 22:57:02 +0000 | [diff] [blame] | 1413 | |
Ted Kremenek | 862d5bb | 2008-02-06 00:54:14 +0000 | [diff] [blame] | 1414 | // First, determine if sym == X, where X != V. |
Ted Kremenek | aed9b6a | 2008-02-28 10:21:43 +0000 | [diff] [blame^] | 1415 | if (const llvm::APSInt* X = St->getSymVal(sym)) { |
Ted Kremenek | 862d5bb | 2008-02-06 00:54:14 +0000 | [diff] [blame] | 1416 | isFeasible = *X != V; |
| 1417 | return St; |
| 1418 | } |
| 1419 | |
| 1420 | // Second, determine if sym != V. |
Ted Kremenek | aed9b6a | 2008-02-28 10:21:43 +0000 | [diff] [blame^] | 1421 | if (St->isNotEqual(sym, V)) { |
Ted Kremenek | 862d5bb | 2008-02-06 00:54:14 +0000 | [diff] [blame] | 1422 | isFeasible = true; |
| 1423 | return St; |
| 1424 | } |
| 1425 | |
| 1426 | // If we reach here, sym is not a constant and we don't know if it is != V. |
| 1427 | // Make that assumption. |
| 1428 | |
| 1429 | isFeasible = true; |
| 1430 | return StateMgr.AddNE(St, sym, V); |
| 1431 | } |
| 1432 | |
Ted Kremenek | aed9b6a | 2008-02-28 10:21:43 +0000 | [diff] [blame^] | 1433 | ValueState* |
| 1434 | GRExprEngine::AssumeSymEQ(ValueState* St, SymbolID sym, |
Ted Kremenek | 862d5bb | 2008-02-06 00:54:14 +0000 | [diff] [blame] | 1435 | const llvm::APSInt& V, bool& isFeasible) { |
| 1436 | |
| 1437 | // First, determine if sym == X, where X != V. |
Ted Kremenek | aed9b6a | 2008-02-28 10:21:43 +0000 | [diff] [blame^] | 1438 | if (const llvm::APSInt* X = St->getSymVal(sym)) { |
Ted Kremenek | 862d5bb | 2008-02-06 00:54:14 +0000 | [diff] [blame] | 1439 | isFeasible = *X == V; |
| 1440 | return St; |
| 1441 | } |
| 1442 | |
| 1443 | // Second, determine if sym != V. |
Ted Kremenek | aed9b6a | 2008-02-28 10:21:43 +0000 | [diff] [blame^] | 1444 | if (St->isNotEqual(sym, V)) { |
Ted Kremenek | 862d5bb | 2008-02-06 00:54:14 +0000 | [diff] [blame] | 1445 | isFeasible = false; |
| 1446 | return St; |
| 1447 | } |
| 1448 | |
| 1449 | // If we reach here, sym is not a constant and we don't know if it is == V. |
| 1450 | // Make that assumption. |
| 1451 | |
| 1452 | isFeasible = true; |
| 1453 | return StateMgr.AddEQ(St, sym, V); |
| 1454 | } |
Ted Kremenek | b38911f | 2008-01-30 23:03:39 +0000 | [diff] [blame] | 1455 | |
Ted Kremenek | aed9b6a | 2008-02-28 10:21:43 +0000 | [diff] [blame^] | 1456 | ValueState* |
| 1457 | GRExprEngine::AssumeSymInt(ValueState* St, bool Assumption, |
Ted Kremenek | 08b6625 | 2008-02-06 04:31:33 +0000 | [diff] [blame] | 1458 | const SymIntConstraint& C, bool& isFeasible) { |
| 1459 | |
| 1460 | switch (C.getOpcode()) { |
| 1461 | default: |
| 1462 | // No logic yet for other operators. |
| 1463 | return St; |
| 1464 | |
| 1465 | case BinaryOperator::EQ: |
| 1466 | if (Assumption) |
| 1467 | return AssumeSymEQ(St, C.getSymbol(), C.getInt(), isFeasible); |
| 1468 | else |
| 1469 | return AssumeSymNE(St, C.getSymbol(), C.getInt(), isFeasible); |
| 1470 | |
| 1471 | case BinaryOperator::NE: |
| 1472 | if (Assumption) |
| 1473 | return AssumeSymNE(St, C.getSymbol(), C.getInt(), isFeasible); |
| 1474 | else |
| 1475 | return AssumeSymEQ(St, C.getSymbol(), C.getInt(), isFeasible); |
| 1476 | } |
| 1477 | } |
| 1478 | |
Ted Kremenek | b38911f | 2008-01-30 23:03:39 +0000 | [diff] [blame] | 1479 | //===----------------------------------------------------------------------===// |
Ted Kremenek | e01c987 | 2008-02-14 22:36:46 +0000 | [diff] [blame] | 1480 | // Visualization. |
Ted Kremenek | ee98546 | 2008-01-16 18:18:48 +0000 | [diff] [blame] | 1481 | //===----------------------------------------------------------------------===// |
| 1482 | |
Ted Kremenek | aa66a32 | 2008-01-16 21:46:15 +0000 | [diff] [blame] | 1483 | #ifndef NDEBUG |
Ted Kremenek | 4d4dd85 | 2008-02-13 17:41:41 +0000 | [diff] [blame] | 1484 | static GRExprEngine* GraphPrintCheckerState; |
Ted Kremenek | 3b4f670 | 2008-01-30 23:24:39 +0000 | [diff] [blame] | 1485 | |
Ted Kremenek | aa66a32 | 2008-01-16 21:46:15 +0000 | [diff] [blame] | 1486 | namespace llvm { |
| 1487 | template<> |
Ted Kremenek | 4d4dd85 | 2008-02-13 17:41:41 +0000 | [diff] [blame] | 1488 | struct VISIBILITY_HIDDEN DOTGraphTraits<GRExprEngine::NodeTy*> : |
Ted Kremenek | aa66a32 | 2008-01-16 21:46:15 +0000 | [diff] [blame] | 1489 | public DefaultDOTGraphTraits { |
Ted Kremenek | 016f52f | 2008-02-08 21:10:02 +0000 | [diff] [blame] | 1490 | |
Ted Kremenek | aed9b6a | 2008-02-28 10:21:43 +0000 | [diff] [blame^] | 1491 | static void PrintVarBindings(std::ostream& Out, ValueState* St) { |
Ted Kremenek | 016f52f | 2008-02-08 21:10:02 +0000 | [diff] [blame] | 1492 | |
| 1493 | Out << "Variables:\\l"; |
| 1494 | |
Ted Kremenek | 9ff731d | 2008-01-24 22:27:20 +0000 | [diff] [blame] | 1495 | bool isFirst = true; |
| 1496 | |
Ted Kremenek | aed9b6a | 2008-02-28 10:21:43 +0000 | [diff] [blame^] | 1497 | for (ValueState::vb_iterator I=St->vb_begin(), E=St->vb_end(); I!=E;++I) { |
Ted Kremenek | 016f52f | 2008-02-08 21:10:02 +0000 | [diff] [blame] | 1498 | |
| 1499 | if (isFirst) |
| 1500 | isFirst = false; |
| 1501 | else |
| 1502 | Out << "\\l"; |
| 1503 | |
| 1504 | Out << ' ' << I.getKey()->getName() << " : "; |
| 1505 | I.getData().print(Out); |
| 1506 | } |
| 1507 | |
| 1508 | } |
| 1509 | |
Ted Kremenek | e7d2211 | 2008-02-11 19:21:59 +0000 | [diff] [blame] | 1510 | |
Ted Kremenek | aed9b6a | 2008-02-28 10:21:43 +0000 | [diff] [blame^] | 1511 | static void PrintSubExprBindings(std::ostream& Out, ValueState* St){ |
Ted Kremenek | e7d2211 | 2008-02-11 19:21:59 +0000 | [diff] [blame] | 1512 | |
| 1513 | bool isFirst = true; |
| 1514 | |
Ted Kremenek | aed9b6a | 2008-02-28 10:21:43 +0000 | [diff] [blame^] | 1515 | for (ValueState::seb_iterator I=St->seb_begin(), E=St->seb_end();I!=E;++I) { |
Ted Kremenek | e7d2211 | 2008-02-11 19:21:59 +0000 | [diff] [blame] | 1516 | |
| 1517 | if (isFirst) { |
| 1518 | Out << "\\l\\lSub-Expressions:\\l"; |
| 1519 | isFirst = false; |
| 1520 | } |
| 1521 | else |
| 1522 | Out << "\\l"; |
| 1523 | |
| 1524 | Out << " (" << (void*) I.getKey() << ") "; |
| 1525 | I.getKey()->printPretty(Out); |
| 1526 | Out << " : "; |
| 1527 | I.getData().print(Out); |
| 1528 | } |
| 1529 | } |
| 1530 | |
Ted Kremenek | aed9b6a | 2008-02-28 10:21:43 +0000 | [diff] [blame^] | 1531 | static void PrintBlkExprBindings(std::ostream& Out, ValueState* St){ |
Ted Kremenek | e7d2211 | 2008-02-11 19:21:59 +0000 | [diff] [blame] | 1532 | |
Ted Kremenek | 016f52f | 2008-02-08 21:10:02 +0000 | [diff] [blame] | 1533 | bool isFirst = true; |
| 1534 | |
Ted Kremenek | aed9b6a | 2008-02-28 10:21:43 +0000 | [diff] [blame^] | 1535 | for (ValueState::beb_iterator I=St->beb_begin(), E=St->beb_end(); I!=E;++I){ |
Ted Kremenek | 9ff731d | 2008-01-24 22:27:20 +0000 | [diff] [blame] | 1536 | if (isFirst) { |
Ted Kremenek | e7d2211 | 2008-02-11 19:21:59 +0000 | [diff] [blame] | 1537 | Out << "\\l\\lBlock-level Expressions:\\l"; |
Ted Kremenek | 9ff731d | 2008-01-24 22:27:20 +0000 | [diff] [blame] | 1538 | isFirst = false; |
| 1539 | } |
| 1540 | else |
| 1541 | Out << "\\l"; |
Ted Kremenek | 016f52f | 2008-02-08 21:10:02 +0000 | [diff] [blame] | 1542 | |
Ted Kremenek | e7d2211 | 2008-02-11 19:21:59 +0000 | [diff] [blame] | 1543 | Out << " (" << (void*) I.getKey() << ") "; |
| 1544 | I.getKey()->printPretty(Out); |
Ted Kremenek | 9ff731d | 2008-01-24 22:27:20 +0000 | [diff] [blame] | 1545 | Out << " : "; |
| 1546 | I.getData().print(Out); |
| 1547 | } |
| 1548 | } |
| 1549 | |
Ted Kremenek | aed9b6a | 2008-02-28 10:21:43 +0000 | [diff] [blame^] | 1550 | static void PrintEQ(std::ostream& Out, ValueState* St) { |
| 1551 | ValueState::ConstEqTy CE = St->ConstEq; |
Ted Kremenek | ed4de31 | 2008-02-06 03:56:15 +0000 | [diff] [blame] | 1552 | |
| 1553 | if (CE.isEmpty()) |
| 1554 | return; |
| 1555 | |
| 1556 | Out << "\\l\\|'==' constraints:"; |
| 1557 | |
Ted Kremenek | aa1c4e5 | 2008-02-21 18:02:17 +0000 | [diff] [blame] | 1558 | for (ValueState::ConstEqTy::iterator I=CE.begin(), E=CE.end(); I!=E;++I) |
Ted Kremenek | ed4de31 | 2008-02-06 03:56:15 +0000 | [diff] [blame] | 1559 | Out << "\\l $" << I.getKey() << " : " << I.getData()->toString(); |
| 1560 | } |
| 1561 | |
Ted Kremenek | aed9b6a | 2008-02-28 10:21:43 +0000 | [diff] [blame^] | 1562 | static void PrintNE(std::ostream& Out, ValueState* St) { |
| 1563 | ValueState::ConstNotEqTy NE = St->ConstNotEq; |
Ted Kremenek | ed4de31 | 2008-02-06 03:56:15 +0000 | [diff] [blame] | 1564 | |
| 1565 | if (NE.isEmpty()) |
| 1566 | return; |
| 1567 | |
| 1568 | Out << "\\l\\|'!=' constraints:"; |
| 1569 | |
Ted Kremenek | aa1c4e5 | 2008-02-21 18:02:17 +0000 | [diff] [blame] | 1570 | for (ValueState::ConstNotEqTy::iterator I=NE.begin(), EI=NE.end(); |
Ted Kremenek | ed4de31 | 2008-02-06 03:56:15 +0000 | [diff] [blame] | 1571 | I != EI; ++I){ |
| 1572 | |
| 1573 | Out << "\\l $" << I.getKey() << " : "; |
| 1574 | bool isFirst = true; |
| 1575 | |
| 1576 | ValueState::IntSetTy::iterator J=I.getData().begin(), |
| 1577 | EJ=I.getData().end(); |
| 1578 | for ( ; J != EJ; ++J) { |
| 1579 | if (isFirst) isFirst = false; |
| 1580 | else Out << ", "; |
| 1581 | |
| 1582 | Out << (*J)->toString(); |
| 1583 | } |
| 1584 | } |
Ted Kremenek | a3fadfc | 2008-02-14 22:54:53 +0000 | [diff] [blame] | 1585 | } |
| 1586 | |
| 1587 | static std::string getNodeAttributes(const GRExprEngine::NodeTy* N, void*) { |
| 1588 | |
| 1589 | if (GraphPrintCheckerState->isImplicitNullDeref(N) || |
Ted Kremenek | 9dca062 | 2008-02-19 00:22:37 +0000 | [diff] [blame] | 1590 | GraphPrintCheckerState->isExplicitNullDeref(N) || |
Ted Kremenek | 4a4e524 | 2008-02-28 09:25:22 +0000 | [diff] [blame] | 1591 | GraphPrintCheckerState->isUndefDeref(N) || |
| 1592 | GraphPrintCheckerState->isUndefStore(N) || |
| 1593 | GraphPrintCheckerState->isUndefControlFlow(N) || |
Ted Kremenek | d87a321 | 2008-02-26 21:31:18 +0000 | [diff] [blame] | 1594 | GraphPrintCheckerState->isBadDivide(N)) |
Ted Kremenek | a3fadfc | 2008-02-14 22:54:53 +0000 | [diff] [blame] | 1595 | return "color=\"red\",style=\"filled\""; |
| 1596 | |
| 1597 | return ""; |
| 1598 | } |
Ted Kremenek | ed4de31 | 2008-02-06 03:56:15 +0000 | [diff] [blame] | 1599 | |
Ted Kremenek | 4d4dd85 | 2008-02-13 17:41:41 +0000 | [diff] [blame] | 1600 | static std::string getNodeLabel(const GRExprEngine::NodeTy* N, void*) { |
Ted Kremenek | aa66a32 | 2008-01-16 21:46:15 +0000 | [diff] [blame] | 1601 | std::ostringstream Out; |
Ted Kremenek | 803c9ed | 2008-01-23 22:30:44 +0000 | [diff] [blame] | 1602 | |
| 1603 | // Program Location. |
Ted Kremenek | aa66a32 | 2008-01-16 21:46:15 +0000 | [diff] [blame] | 1604 | ProgramPoint Loc = N->getLocation(); |
| 1605 | |
| 1606 | switch (Loc.getKind()) { |
| 1607 | case ProgramPoint::BlockEntranceKind: |
| 1608 | Out << "Block Entrance: B" |
| 1609 | << cast<BlockEntrance>(Loc).getBlock()->getBlockID(); |
| 1610 | break; |
| 1611 | |
| 1612 | case ProgramPoint::BlockExitKind: |
| 1613 | assert (false); |
| 1614 | break; |
| 1615 | |
| 1616 | case ProgramPoint::PostStmtKind: { |
| 1617 | const PostStmt& L = cast<PostStmt>(Loc); |
Ted Kremenek | 9ff731d | 2008-01-24 22:27:20 +0000 | [diff] [blame] | 1618 | Out << L.getStmt()->getStmtClassName() << ':' |
| 1619 | << (void*) L.getStmt() << ' '; |
| 1620 | |
Ted Kremenek | aa66a32 | 2008-01-16 21:46:15 +0000 | [diff] [blame] | 1621 | L.getStmt()->printPretty(Out); |
Ted Kremenek | d131c4f | 2008-02-07 05:48:01 +0000 | [diff] [blame] | 1622 | |
| 1623 | if (GraphPrintCheckerState->isImplicitNullDeref(N)) { |
| 1624 | Out << "\\|Implicit-Null Dereference.\\l"; |
| 1625 | } |
Ted Kremenek | 63a4f69 | 2008-02-07 06:04:18 +0000 | [diff] [blame] | 1626 | else if (GraphPrintCheckerState->isExplicitNullDeref(N)) { |
| 1627 | Out << "\\|Explicit-Null Dereference.\\l"; |
| 1628 | } |
Ted Kremenek | 4a4e524 | 2008-02-28 09:25:22 +0000 | [diff] [blame] | 1629 | else if (GraphPrintCheckerState->isUndefDeref(N)) { |
| 1630 | Out << "\\|Dereference of undefialied value.\\l"; |
Ted Kremenek | b533912 | 2008-02-19 20:53:06 +0000 | [diff] [blame] | 1631 | } |
Ted Kremenek | 4a4e524 | 2008-02-28 09:25:22 +0000 | [diff] [blame] | 1632 | else if (GraphPrintCheckerState->isUndefStore(N)) { |
| 1633 | Out << "\\|Store to Undefined LVal."; |
Ted Kremenek | 9dca062 | 2008-02-19 00:22:37 +0000 | [diff] [blame] | 1634 | } |
Ted Kremenek | d87a321 | 2008-02-26 21:31:18 +0000 | [diff] [blame] | 1635 | else if (GraphPrintCheckerState->isBadDivide(N)) { |
Ted Kremenek | 4a4e524 | 2008-02-28 09:25:22 +0000 | [diff] [blame] | 1636 | Out << "\\|Divide-by zero or undefined value."; |
Ted Kremenek | d87a321 | 2008-02-26 21:31:18 +0000 | [diff] [blame] | 1637 | } |
Ted Kremenek | d131c4f | 2008-02-07 05:48:01 +0000 | [diff] [blame] | 1638 | |
Ted Kremenek | aa66a32 | 2008-01-16 21:46:15 +0000 | [diff] [blame] | 1639 | break; |
| 1640 | } |
| 1641 | |
| 1642 | default: { |
| 1643 | const BlockEdge& E = cast<BlockEdge>(Loc); |
| 1644 | Out << "Edge: (B" << E.getSrc()->getBlockID() << ", B" |
| 1645 | << E.getDst()->getBlockID() << ')'; |
Ted Kremenek | b38911f | 2008-01-30 23:03:39 +0000 | [diff] [blame] | 1646 | |
| 1647 | if (Stmt* T = E.getSrc()->getTerminator()) { |
| 1648 | Out << "\\|Terminator: "; |
| 1649 | E.getSrc()->printTerminator(Out); |
| 1650 | |
Ted Kremenek | daeb9a7 | 2008-02-13 23:08:21 +0000 | [diff] [blame] | 1651 | if (isa<SwitchStmt>(T)) { |
| 1652 | Stmt* Label = E.getDst()->getLabel(); |
| 1653 | |
| 1654 | if (Label) { |
| 1655 | if (CaseStmt* C = dyn_cast<CaseStmt>(Label)) { |
| 1656 | Out << "\\lcase "; |
| 1657 | C->getLHS()->printPretty(Out); |
| 1658 | |
| 1659 | if (Stmt* RHS = C->getRHS()) { |
| 1660 | Out << " .. "; |
| 1661 | RHS->printPretty(Out); |
| 1662 | } |
| 1663 | |
| 1664 | Out << ":"; |
| 1665 | } |
| 1666 | else { |
| 1667 | assert (isa<DefaultStmt>(Label)); |
| 1668 | Out << "\\ldefault:"; |
| 1669 | } |
| 1670 | } |
| 1671 | else |
| 1672 | Out << "\\l(implicit) default:"; |
| 1673 | } |
| 1674 | else if (isa<IndirectGotoStmt>(T)) { |
Ted Kremenek | b38911f | 2008-01-30 23:03:39 +0000 | [diff] [blame] | 1675 | // FIXME |
| 1676 | } |
| 1677 | else { |
| 1678 | Out << "\\lCondition: "; |
| 1679 | if (*E.getSrc()->succ_begin() == E.getDst()) |
| 1680 | Out << "true"; |
| 1681 | else |
| 1682 | Out << "false"; |
| 1683 | } |
| 1684 | |
| 1685 | Out << "\\l"; |
| 1686 | } |
Ted Kremenek | 3b4f670 | 2008-01-30 23:24:39 +0000 | [diff] [blame] | 1687 | |
Ted Kremenek | 4a4e524 | 2008-02-28 09:25:22 +0000 | [diff] [blame] | 1688 | if (GraphPrintCheckerState->isUndefControlFlow(N)) { |
| 1689 | Out << "\\|Control-flow based on\\lUndefined value.\\l"; |
Ted Kremenek | 3b4f670 | 2008-01-30 23:24:39 +0000 | [diff] [blame] | 1690 | } |
Ted Kremenek | aa66a32 | 2008-01-16 21:46:15 +0000 | [diff] [blame] | 1691 | } |
| 1692 | } |
| 1693 | |
Ted Kremenek | aed9b6a | 2008-02-28 10:21:43 +0000 | [diff] [blame^] | 1694 | Out << "\\|StateID: " << (void*) N->getState() << "\\|"; |
Ted Kremenek | 016f52f | 2008-02-08 21:10:02 +0000 | [diff] [blame] | 1695 | |
Ted Kremenek | aed9b6a | 2008-02-28 10:21:43 +0000 | [diff] [blame^] | 1696 | N->getState()->printDOT(Out); |
Ted Kremenek | 803c9ed | 2008-01-23 22:30:44 +0000 | [diff] [blame] | 1697 | |
Ted Kremenek | 803c9ed | 2008-01-23 22:30:44 +0000 | [diff] [blame] | 1698 | Out << "\\l"; |
Ted Kremenek | aa66a32 | 2008-01-16 21:46:15 +0000 | [diff] [blame] | 1699 | return Out.str(); |
| 1700 | } |
| 1701 | }; |
| 1702 | } // end llvm namespace |
| 1703 | #endif |
| 1704 | |
Ted Kremenek | e01c987 | 2008-02-14 22:36:46 +0000 | [diff] [blame] | 1705 | void GRExprEngine::ViewGraph() { |
Ted Kremenek | aa66a32 | 2008-01-16 21:46:15 +0000 | [diff] [blame] | 1706 | #ifndef NDEBUG |
Ted Kremenek | e01c987 | 2008-02-14 22:36:46 +0000 | [diff] [blame] | 1707 | GraphPrintCheckerState = this; |
| 1708 | llvm::ViewGraph(*G.roots_begin(), "GRExprEngine"); |
Ted Kremenek | 3b4f670 | 2008-01-30 23:24:39 +0000 | [diff] [blame] | 1709 | GraphPrintCheckerState = NULL; |
Ted Kremenek | e01c987 | 2008-02-14 22:36:46 +0000 | [diff] [blame] | 1710 | #endif |
Ted Kremenek | ee98546 | 2008-01-16 18:18:48 +0000 | [diff] [blame] | 1711 | } |