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