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