Ted Kremenek | 13ed7fe | 2007-09-14 22:49:21 +0000 | [diff] [blame] | 1 | //==- UninitializedValues.cpp - Find Unintialized Values --------*- C++ --*-==// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | 0bc735f | 2007-12-29 19:59:25 +0000 | [diff] [blame] | 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
Ted Kremenek | 13ed7fe | 2007-09-14 22:49:21 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file implements Uninitialized Values analysis for source-level CFGs. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
Ted Kremenek | cf6e41b | 2007-12-21 21:42:19 +0000 | [diff] [blame] | 14 | #include "clang/Analysis/Analyses/UninitializedValues.h" |
Ted Kremenek | 11de5cb | 2007-09-20 21:42:55 +0000 | [diff] [blame] | 15 | #include "clang/Analysis/Visitors/CFGRecStmtDeclVisitor.h" |
Ted Kremenek | cd5860c | 2007-09-17 19:59:27 +0000 | [diff] [blame] | 16 | #include "clang/Analysis/LocalCheckers.h" |
| 17 | #include "clang/Basic/Diagnostic.h" |
| 18 | #include "clang/AST/ASTContext.h" |
Ted Kremenek | 1de632b | 2007-09-25 21:00:24 +0000 | [diff] [blame] | 19 | #include "clang/Analysis/FlowSensitive/DataflowSolver.h" |
Ted Kremenek | c2b51d8 | 2008-01-08 18:19:08 +0000 | [diff] [blame] | 20 | #include "llvm/Support/Compiler.h" |
Ted Kremenek | 13ed7fe | 2007-09-14 22:49:21 +0000 | [diff] [blame] | 21 | |
Ted Kremenek | cd5860c | 2007-09-17 19:59:27 +0000 | [diff] [blame] | 22 | #include "llvm/ADT/SmallPtrSet.h" |
| 23 | |
Ted Kremenek | 13ed7fe | 2007-09-14 22:49:21 +0000 | [diff] [blame] | 24 | using namespace clang; |
| 25 | |
Ted Kremenek | cd5860c | 2007-09-17 19:59:27 +0000 | [diff] [blame] | 26 | //===----------------------------------------------------------------------===// |
Ted Kremenek | 13ed7fe | 2007-09-14 22:49:21 +0000 | [diff] [blame] | 27 | // Dataflow initialization logic. |
Ted Kremenek | cd5860c | 2007-09-17 19:59:27 +0000 | [diff] [blame] | 28 | //===----------------------------------------------------------------------===// |
Ted Kremenek | 13ed7fe | 2007-09-14 22:49:21 +0000 | [diff] [blame] | 29 | |
| 30 | namespace { |
| 31 | |
Ted Kremenek | c2b51d8 | 2008-01-08 18:19:08 +0000 | [diff] [blame] | 32 | class VISIBILITY_HIDDEN RegisterDecls |
| 33 | : public CFGRecStmtDeclVisitor<RegisterDecls> { |
| 34 | |
Ted Kremenek | 56d516d | 2007-09-17 17:14:52 +0000 | [diff] [blame] | 35 | UninitializedValues::AnalysisDataTy& AD; |
Ted Kremenek | 13ed7fe | 2007-09-14 22:49:21 +0000 | [diff] [blame] | 36 | public: |
Ted Kremenek | 11e7218 | 2007-10-01 20:33:52 +0000 | [diff] [blame] | 37 | RegisterDecls(UninitializedValues::AnalysisDataTy& ad) : AD(ad) {} |
Ted Kremenek | 13ed7fe | 2007-09-14 22:49:21 +0000 | [diff] [blame] | 38 | |
Ted Kremenek | aead153 | 2007-09-27 18:20:22 +0000 | [diff] [blame] | 39 | void VisitBlockVarDecl(BlockVarDecl* VD) { AD.Register(VD); } |
Ted Kremenek | 9f9141c | 2007-11-20 03:01:58 +0000 | [diff] [blame] | 40 | CFG& getCFG() { return AD.getCFG(); } |
Ted Kremenek | 13ed7fe | 2007-09-14 22:49:21 +0000 | [diff] [blame] | 41 | }; |
| 42 | |
| 43 | } // end anonymous namespace |
| 44 | |
| 45 | void UninitializedValues::InitializeValues(const CFG& cfg) { |
Ted Kremenek | 11e7218 | 2007-10-01 20:33:52 +0000 | [diff] [blame] | 46 | RegisterDecls R(getAnalysisData()); |
Ted Kremenek | a90b0d1 | 2007-09-18 20:59:00 +0000 | [diff] [blame] | 47 | cfg.VisitBlockStmts(R); |
Ted Kremenek | 13ed7fe | 2007-09-14 22:49:21 +0000 | [diff] [blame] | 48 | } |
| 49 | |
Ted Kremenek | cd5860c | 2007-09-17 19:59:27 +0000 | [diff] [blame] | 50 | //===----------------------------------------------------------------------===// |
Ted Kremenek | 13ed7fe | 2007-09-14 22:49:21 +0000 | [diff] [blame] | 51 | // Transfer functions. |
Ted Kremenek | cd5860c | 2007-09-17 19:59:27 +0000 | [diff] [blame] | 52 | //===----------------------------------------------------------------------===// |
Ted Kremenek | 13ed7fe | 2007-09-14 22:49:21 +0000 | [diff] [blame] | 53 | |
| 54 | namespace { |
Ted Kremenek | c2b51d8 | 2008-01-08 18:19:08 +0000 | [diff] [blame] | 55 | class VISIBILITY_HIDDEN TransferFuncs |
| 56 | : public CFGStmtVisitor<TransferFuncs,bool> { |
| 57 | |
Ted Kremenek | 13ed7fe | 2007-09-14 22:49:21 +0000 | [diff] [blame] | 58 | UninitializedValues::ValTy V; |
Ted Kremenek | 56d516d | 2007-09-17 17:14:52 +0000 | [diff] [blame] | 59 | UninitializedValues::AnalysisDataTy& AD; |
Ted Kremenek | 13ed7fe | 2007-09-14 22:49:21 +0000 | [diff] [blame] | 60 | public: |
Ted Kremenek | a1de8c7 | 2007-09-28 00:09:38 +0000 | [diff] [blame] | 61 | TransferFuncs(UninitializedValues::AnalysisDataTy& ad) : AD(ad) { |
Ted Kremenek | 2bf5514 | 2007-09-17 20:49:30 +0000 | [diff] [blame] | 62 | V.resetValues(AD); |
Ted Kremenek | 13ed7fe | 2007-09-14 22:49:21 +0000 | [diff] [blame] | 63 | } |
| 64 | |
| 65 | UninitializedValues::ValTy& getVal() { return V; } |
Ted Kremenek | 9f9141c | 2007-11-20 03:01:58 +0000 | [diff] [blame] | 66 | CFG& getCFG() { return AD.getCFG(); } |
Ted Kremenek | 56d516d | 2007-09-17 17:14:52 +0000 | [diff] [blame] | 67 | |
Ted Kremenek | 20ee4fb | 2007-09-17 18:31:23 +0000 | [diff] [blame] | 68 | bool VisitDeclRefExpr(DeclRefExpr* DR); |
| 69 | bool VisitBinaryOperator(BinaryOperator* B); |
| 70 | bool VisitUnaryOperator(UnaryOperator* U); |
| 71 | bool VisitStmt(Stmt* S); |
| 72 | bool VisitCallExpr(CallExpr* C); |
Ted Kremenek | cd5860c | 2007-09-17 19:59:27 +0000 | [diff] [blame] | 73 | bool VisitDeclStmt(DeclStmt* D); |
Ted Kremenek | a1de8c7 | 2007-09-28 00:09:38 +0000 | [diff] [blame] | 74 | bool VisitConditionalOperator(ConditionalOperator* C); |
| 75 | |
| 76 | bool Visit(Stmt *S); |
| 77 | bool BlockStmt_VisitExpr(Expr* E); |
Ted Kremenek | 20ee4fb | 2007-09-17 18:31:23 +0000 | [diff] [blame] | 78 | |
Ted Kremenek | 43a1698 | 2007-09-18 21:43:18 +0000 | [diff] [blame] | 79 | BlockVarDecl* FindBlockVarDecl(Stmt* S); |
Ted Kremenek | 13ed7fe | 2007-09-14 22:49:21 +0000 | [diff] [blame] | 80 | }; |
Ted Kremenek | aead153 | 2007-09-27 18:20:22 +0000 | [diff] [blame] | 81 | |
| 82 | static const bool Initialized = true; |
| 83 | static const bool Uninitialized = false; |
Ted Kremenek | 20ee4fb | 2007-09-17 18:31:23 +0000 | [diff] [blame] | 84 | |
Ted Kremenek | 20ee4fb | 2007-09-17 18:31:23 +0000 | [diff] [blame] | 85 | bool TransferFuncs::VisitDeclRefExpr(DeclRefExpr* DR) { |
Ted Kremenek | 2bf5514 | 2007-09-17 20:49:30 +0000 | [diff] [blame] | 86 | if (BlockVarDecl* VD = dyn_cast<BlockVarDecl>(DR->getDecl())) { |
Ted Kremenek | 43a1698 | 2007-09-18 21:43:18 +0000 | [diff] [blame] | 87 | if (AD.Observer) AD.Observer->ObserveDeclRefExpr(V,AD,DR,VD); |
Ted Kremenek | a1de8c7 | 2007-09-28 00:09:38 +0000 | [diff] [blame] | 88 | |
| 89 | // Pseudo-hack to prevent cascade of warnings. If an accessed variable |
| 90 | // is uninitialized, then we are already going to flag a warning for |
| 91 | // this variable, which a "source" of uninitialized values. |
| 92 | // We can otherwise do a full "taint" of uninitialized values. The |
| 93 | // client has both options by toggling AD.FullUninitTaint. |
| 94 | |
| 95 | return AD.FullUninitTaint ? V(VD,AD) : Initialized; |
Ted Kremenek | 20ee4fb | 2007-09-17 18:31:23 +0000 | [diff] [blame] | 96 | } |
Ted Kremenek | aead153 | 2007-09-27 18:20:22 +0000 | [diff] [blame] | 97 | else return Initialized; |
Ted Kremenek | 43a1698 | 2007-09-18 21:43:18 +0000 | [diff] [blame] | 98 | } |
| 99 | |
| 100 | BlockVarDecl* TransferFuncs::FindBlockVarDecl(Stmt *S) { |
Ted Kremenek | a1de8c7 | 2007-09-28 00:09:38 +0000 | [diff] [blame] | 101 | for (;;) |
Ted Kremenek | 43a1698 | 2007-09-18 21:43:18 +0000 | [diff] [blame] | 102 | if (ParenExpr* P = dyn_cast<ParenExpr>(S)) { |
Ted Kremenek | a1de8c7 | 2007-09-28 00:09:38 +0000 | [diff] [blame] | 103 | S = P->getSubExpr(); continue; |
Ted Kremenek | 43a1698 | 2007-09-18 21:43:18 +0000 | [diff] [blame] | 104 | } |
Ted Kremenek | a1de8c7 | 2007-09-28 00:09:38 +0000 | [diff] [blame] | 105 | else if (DeclRefExpr* DR = dyn_cast<DeclRefExpr>(S)) { |
Ted Kremenek | 43a1698 | 2007-09-18 21:43:18 +0000 | [diff] [blame] | 106 | if (BlockVarDecl* VD = dyn_cast<BlockVarDecl>(DR->getDecl())) |
| 107 | return VD; |
Ted Kremenek | ff7c538 | 2007-11-24 20:07:36 +0000 | [diff] [blame] | 108 | else |
| 109 | return NULL; |
Ted Kremenek | a1de8c7 | 2007-09-28 00:09:38 +0000 | [diff] [blame] | 110 | } |
| 111 | else return NULL; |
Ted Kremenek | 20ee4fb | 2007-09-17 18:31:23 +0000 | [diff] [blame] | 112 | } |
| 113 | |
| 114 | bool TransferFuncs::VisitBinaryOperator(BinaryOperator* B) { |
Ted Kremenek | 6ce2b63 | 2007-09-28 21:08:51 +0000 | [diff] [blame] | 115 | if (BlockVarDecl* VD = FindBlockVarDecl(B->getLHS())) |
| 116 | if (B->isAssignmentOp()) { |
Ted Kremenek | ff7c538 | 2007-11-24 20:07:36 +0000 | [diff] [blame] | 117 | if (B->getOpcode() == BinaryOperator::Assign) |
| 118 | return V(VD,AD) = Visit(B->getRHS()); |
| 119 | else // Handle +=, -=, *=, etc. We do want '&', not '&&'. |
| 120 | return V(VD,AD) = Visit(B->getLHS()) & Visit(B->getRHS()); |
Ted Kremenek | 6ce2b63 | 2007-09-28 21:08:51 +0000 | [diff] [blame] | 121 | } |
| 122 | |
Ted Kremenek | 20ee4fb | 2007-09-17 18:31:23 +0000 | [diff] [blame] | 123 | return VisitStmt(B); |
| 124 | } |
| 125 | |
Ted Kremenek | cd5860c | 2007-09-17 19:59:27 +0000 | [diff] [blame] | 126 | bool TransferFuncs::VisitDeclStmt(DeclStmt* S) { |
Ted Kremenek | cd5860c | 2007-09-17 19:59:27 +0000 | [diff] [blame] | 127 | for (ScopedDecl* D = S->getDecl(); D != NULL; D = D->getNextDeclarator()) |
Ted Kremenek | aead153 | 2007-09-27 18:20:22 +0000 | [diff] [blame] | 128 | if (BlockVarDecl* VD = dyn_cast<BlockVarDecl>(D)) { |
Ted Kremenek | a1de8c7 | 2007-09-28 00:09:38 +0000 | [diff] [blame] | 129 | if (Stmt* I = VD->getInit()) |
| 130 | V(VD,AD) = AD.FullUninitTaint ? V(cast<Expr>(I),AD) : Initialized; |
Ted Kremenek | 81a56ec | 2007-12-13 05:14:22 +0000 | [diff] [blame] | 131 | else { |
| 132 | // Special case for declarations of array types. For things like: |
| 133 | // |
| 134 | // char x[10]; |
| 135 | // |
| 136 | // we should treat "x" as being initialized, because the variable |
| 137 | // "x" really refers to the memory block. Clearly x[1] is |
| 138 | // uninitialized, but expressions like "(char *) x" really do refer to |
| 139 | // an initialized value. This simple dataflow analysis does not reason |
| 140 | // about the contents of arrays, although it could be potentially |
| 141 | // extended to do so if the array were of constant size. |
| 142 | if (VD->getType()->isArrayType()) |
| 143 | V(VD,AD) = Initialized; |
| 144 | else |
| 145 | V(VD,AD) = Uninitialized; |
| 146 | } |
Ted Kremenek | aead153 | 2007-09-27 18:20:22 +0000 | [diff] [blame] | 147 | } |
Ted Kremenek | cd5860c | 2007-09-17 19:59:27 +0000 | [diff] [blame] | 148 | |
Ted Kremenek | a1de8c7 | 2007-09-28 00:09:38 +0000 | [diff] [blame] | 149 | return Uninitialized; // Value is never consumed. |
Ted Kremenek | cd5860c | 2007-09-17 19:59:27 +0000 | [diff] [blame] | 150 | } |
| 151 | |
Ted Kremenek | 20ee4fb | 2007-09-17 18:31:23 +0000 | [diff] [blame] | 152 | bool TransferFuncs::VisitCallExpr(CallExpr* C) { |
Ted Kremenek | 59d1827 | 2007-09-18 21:47:41 +0000 | [diff] [blame] | 153 | VisitChildren(C); |
Ted Kremenek | aead153 | 2007-09-27 18:20:22 +0000 | [diff] [blame] | 154 | return Initialized; |
Ted Kremenek | 20ee4fb | 2007-09-17 18:31:23 +0000 | [diff] [blame] | 155 | } |
| 156 | |
| 157 | bool TransferFuncs::VisitUnaryOperator(UnaryOperator* U) { |
Ted Kremenek | 8d9ebae | 2007-12-13 04:47:15 +0000 | [diff] [blame] | 158 | switch (U->getOpcode()) { |
| 159 | case UnaryOperator::AddrOf: |
| 160 | if (BlockVarDecl* VD = FindBlockVarDecl(U->getSubExpr())) |
| 161 | return V(VD,AD) = Initialized; |
| 162 | |
| 163 | break; |
| 164 | |
| 165 | case UnaryOperator::SizeOf: |
| 166 | return Initialized; |
| 167 | |
| 168 | default: |
| 169 | break; |
| 170 | } |
Ted Kremenek | 20ee4fb | 2007-09-17 18:31:23 +0000 | [diff] [blame] | 171 | |
Ted Kremenek | a1de8c7 | 2007-09-28 00:09:38 +0000 | [diff] [blame] | 172 | return Visit(U->getSubExpr()); |
| 173 | } |
| 174 | |
| 175 | bool TransferFuncs::VisitConditionalOperator(ConditionalOperator* C) { |
| 176 | Visit(C->getCond()); |
Anders Carlsson | 3907323 | 2007-11-30 19:04:31 +0000 | [diff] [blame] | 177 | |
| 178 | bool rhsResult = Visit(C->getRHS()); |
| 179 | // Handle the GNU extension for missing LHS. |
| 180 | if (Expr *lhs = C->getLHS()) |
| 181 | return Visit(lhs) & rhsResult; // Yes: we want &, not &&. |
| 182 | else |
| 183 | return rhsResult; |
Ted Kremenek | 20ee4fb | 2007-09-17 18:31:23 +0000 | [diff] [blame] | 184 | } |
| 185 | |
| 186 | bool TransferFuncs::VisitStmt(Stmt* S) { |
Ted Kremenek | aead153 | 2007-09-27 18:20:22 +0000 | [diff] [blame] | 187 | bool x = Initialized; |
Ted Kremenek | 20ee4fb | 2007-09-17 18:31:23 +0000 | [diff] [blame] | 188 | |
| 189 | // We don't stop at the first subexpression that is Uninitialized because |
| 190 | // evaluating some subexpressions may result in propogating "Uninitialized" |
| 191 | // or "Initialized" to variables referenced in the other subexpressions. |
| 192 | for (Stmt::child_iterator I=S->child_begin(), E=S->child_end(); I!=E; ++I) |
Ted Kremenek | a1de8c7 | 2007-09-28 00:09:38 +0000 | [diff] [blame] | 193 | if (*I && Visit(*I) == Uninitialized) x = Uninitialized; |
Ted Kremenek | 20ee4fb | 2007-09-17 18:31:23 +0000 | [diff] [blame] | 194 | |
| 195 | return x; |
| 196 | } |
Ted Kremenek | a1de8c7 | 2007-09-28 00:09:38 +0000 | [diff] [blame] | 197 | |
| 198 | bool TransferFuncs::Visit(Stmt *S) { |
| 199 | if (AD.isTracked(static_cast<Expr*>(S))) return V(static_cast<Expr*>(S),AD); |
| 200 | else return static_cast<CFGStmtVisitor<TransferFuncs,bool>*>(this)->Visit(S); |
| 201 | } |
Ted Kremenek | 20ee4fb | 2007-09-17 18:31:23 +0000 | [diff] [blame] | 202 | |
| 203 | bool TransferFuncs::BlockStmt_VisitExpr(Expr* E) { |
Ted Kremenek | 33d4aab | 2008-01-26 00:03:27 +0000 | [diff] [blame] | 204 | bool x = static_cast<CFGStmtVisitor<TransferFuncs,bool>*>(this)->Visit(E); |
| 205 | if (AD.isTracked(E)) V(E,AD) = x; |
| 206 | return x; |
Ted Kremenek | 20ee4fb | 2007-09-17 18:31:23 +0000 | [diff] [blame] | 207 | } |
| 208 | |
Ted Kremenek | 13ed7fe | 2007-09-14 22:49:21 +0000 | [diff] [blame] | 209 | } // end anonymous namespace |
| 210 | |
Ted Kremenek | cd5860c | 2007-09-17 19:59:27 +0000 | [diff] [blame] | 211 | //===----------------------------------------------------------------------===// |
Ted Kremenek | 13ed7fe | 2007-09-14 22:49:21 +0000 | [diff] [blame] | 212 | // Merge operator. |
Ted Kremenek | 20ee4fb | 2007-09-17 18:31:23 +0000 | [diff] [blame] | 213 | // |
| 214 | // In our transfer functions we take the approach that any |
| 215 | // combination of unintialized values, e.g. Unitialized + ___ = Unitialized. |
| 216 | // |
| 217 | // Merges take the opposite approach. |
| 218 | // |
Ted Kremenek | a90b0d1 | 2007-09-18 20:59:00 +0000 | [diff] [blame] | 219 | // In the merge of dataflow values we prefer unsoundness, and |
Ted Kremenek | 20ee4fb | 2007-09-17 18:31:23 +0000 | [diff] [blame] | 220 | // prefer false negatives to false positives. At merges, if a value for a |
| 221 | // tracked Decl is EVER initialized in any of the predecessors we treat it as |
| 222 | // initialized at the confluence point. |
Ted Kremenek | cd5860c | 2007-09-17 19:59:27 +0000 | [diff] [blame] | 223 | //===----------------------------------------------------------------------===// |
Ted Kremenek | 13ed7fe | 2007-09-14 22:49:21 +0000 | [diff] [blame] | 224 | |
| 225 | namespace { |
Ted Kremenek | aead153 | 2007-09-27 18:20:22 +0000 | [diff] [blame] | 226 | typedef ExprDeclBitVector_Types::Union Merge; |
| 227 | typedef DataflowSolver<UninitializedValues,TransferFuncs,Merge> Solver; |
| 228 | } |
Ted Kremenek | 13ed7fe | 2007-09-14 22:49:21 +0000 | [diff] [blame] | 229 | |
Ted Kremenek | cd5860c | 2007-09-17 19:59:27 +0000 | [diff] [blame] | 230 | //===----------------------------------------------------------------------===// |
| 231 | // Unitialized values checker. Scan an AST and flag variable uses |
| 232 | //===----------------------------------------------------------------------===// |
Ted Kremenek | 13ed7fe | 2007-09-14 22:49:21 +0000 | [diff] [blame] | 233 | |
Ted Kremenek | cd5860c | 2007-09-17 19:59:27 +0000 | [diff] [blame] | 234 | UninitializedValues_ValueTypes::ObserverTy::~ObserverTy() {} |
| 235 | |
| 236 | namespace { |
Ted Kremenek | c2b51d8 | 2008-01-08 18:19:08 +0000 | [diff] [blame] | 237 | class VISIBILITY_HIDDEN UninitializedValuesChecker |
| 238 | : public UninitializedValues::ObserverTy { |
| 239 | |
Ted Kremenek | cd5860c | 2007-09-17 19:59:27 +0000 | [diff] [blame] | 240 | ASTContext &Ctx; |
| 241 | Diagnostic &Diags; |
Ted Kremenek | 2bf5514 | 2007-09-17 20:49:30 +0000 | [diff] [blame] | 242 | llvm::SmallPtrSet<BlockVarDecl*,10> AlreadyWarned; |
Ted Kremenek | cd5860c | 2007-09-17 19:59:27 +0000 | [diff] [blame] | 243 | |
| 244 | public: |
| 245 | UninitializedValuesChecker(ASTContext &ctx, Diagnostic &diags) |
| 246 | : Ctx(ctx), Diags(diags) {} |
| 247 | |
| 248 | virtual void ObserveDeclRefExpr(UninitializedValues::ValTy& V, |
| 249 | UninitializedValues::AnalysisDataTy& AD, |
Ted Kremenek | 2bf5514 | 2007-09-17 20:49:30 +0000 | [diff] [blame] | 250 | DeclRefExpr* DR, BlockVarDecl* VD) { |
Ted Kremenek | cd5860c | 2007-09-17 19:59:27 +0000 | [diff] [blame] | 251 | |
Ted Kremenek | 43a1698 | 2007-09-18 21:43:18 +0000 | [diff] [blame] | 252 | assert ( AD.isTracked(VD) && "Unknown VarDecl."); |
| 253 | |
Ted Kremenek | aead153 | 2007-09-27 18:20:22 +0000 | [diff] [blame] | 254 | if (V(VD,AD) == Uninitialized) |
Ted Kremenek | cd5860c | 2007-09-17 19:59:27 +0000 | [diff] [blame] | 255 | if (AlreadyWarned.insert(VD)) |
Ted Kremenek | 9c728dc | 2007-12-12 22:39:36 +0000 | [diff] [blame] | 256 | Diags.Report(Ctx.getFullLoc(DR->getSourceRange().getBegin()), |
| 257 | diag::warn_uninit_val); |
Ted Kremenek | cd5860c | 2007-09-17 19:59:27 +0000 | [diff] [blame] | 258 | } |
| 259 | }; |
Ted Kremenek | cd5860c | 2007-09-17 19:59:27 +0000 | [diff] [blame] | 260 | } // end anonymous namespace |
| 261 | |
Ted Kremenek | 2bf5514 | 2007-09-17 20:49:30 +0000 | [diff] [blame] | 262 | namespace clang { |
Ted Kremenek | a1de8c7 | 2007-09-28 00:09:38 +0000 | [diff] [blame] | 263 | void CheckUninitializedValues(CFG& cfg, ASTContext &Ctx, Diagnostic &Diags, |
| 264 | bool FullUninitTaint) { |
Ted Kremenek | 13ed7fe | 2007-09-14 22:49:21 +0000 | [diff] [blame] | 265 | |
Ted Kremenek | cd5860c | 2007-09-17 19:59:27 +0000 | [diff] [blame] | 266 | // Compute the unitialized values information. |
Ted Kremenek | 11e7218 | 2007-10-01 20:33:52 +0000 | [diff] [blame] | 267 | UninitializedValues U(cfg); |
Ted Kremenek | a1de8c7 | 2007-09-28 00:09:38 +0000 | [diff] [blame] | 268 | U.getAnalysisData().FullUninitTaint = FullUninitTaint; |
Ted Kremenek | 13ed7fe | 2007-09-14 22:49:21 +0000 | [diff] [blame] | 269 | Solver S(U); |
Ted Kremenek | cd5860c | 2007-09-17 19:59:27 +0000 | [diff] [blame] | 270 | S.runOnCFG(cfg); |
| 271 | |
| 272 | // Scan for DeclRefExprs that use uninitialized values. |
| 273 | UninitializedValuesChecker Observer(Ctx,Diags); |
| 274 | U.getAnalysisData().Observer = &Observer; |
Ted Kremenek | 294a7c9 | 2007-09-18 21:08:21 +0000 | [diff] [blame] | 275 | S.runOnAllBlocks(cfg); |
Ted Kremenek | 13ed7fe | 2007-09-14 22:49:21 +0000 | [diff] [blame] | 276 | } |
Ted Kremenek | 294a7c9 | 2007-09-18 21:08:21 +0000 | [diff] [blame] | 277 | } // end namespace clang |