Ted Kremenek | dbdbaaf | 2010-03-20 21:06:02 +0000 | [diff] [blame] | 1 | //=- AnalysisBasedWarnings.cpp - Sema warnings based on libAnalysis -*- C++ -*-=// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file defines analysis_warnings::[Policy,Executor]. |
| 11 | // Together they are used by Sema to issue warnings based on inexpensive |
| 12 | // static analysis algorithms in libAnalysis. |
| 13 | // |
| 14 | //===----------------------------------------------------------------------===// |
| 15 | |
Douglas Gregor | e737f50 | 2010-08-12 20:07:10 +0000 | [diff] [blame] | 16 | #include "clang/Sema/AnalysisBasedWarnings.h" |
John McCall | 2d88708 | 2010-08-25 22:03:47 +0000 | [diff] [blame] | 17 | #include "clang/Sema/SemaInternal.h" |
Ted Kremenek | 351ba91 | 2011-02-23 01:52:04 +0000 | [diff] [blame] | 18 | #include "clang/Sema/ScopeInfo.h" |
Ted Kremenek | d068aab | 2010-03-20 21:11:09 +0000 | [diff] [blame] | 19 | #include "clang/Basic/SourceManager.h" |
Caitlin Sadowski | 75f23ae | 2011-09-09 16:04:02 +0000 | [diff] [blame] | 20 | #include "clang/Basic/SourceLocation.h" |
Ted Kremenek | fbb178a | 2011-01-21 19:41:46 +0000 | [diff] [blame] | 21 | #include "clang/Lex/Preprocessor.h" |
John McCall | 7cd088e | 2010-08-24 07:21:54 +0000 | [diff] [blame] | 22 | #include "clang/AST/DeclObjC.h" |
John McCall | 384aff8 | 2010-08-25 07:42:41 +0000 | [diff] [blame] | 23 | #include "clang/AST/DeclCXX.h" |
Ted Kremenek | dbdbaaf | 2010-03-20 21:06:02 +0000 | [diff] [blame] | 24 | #include "clang/AST/ExprObjC.h" |
| 25 | #include "clang/AST/ExprCXX.h" |
| 26 | #include "clang/AST/StmtObjC.h" |
| 27 | #include "clang/AST/StmtCXX.h" |
Ted Kremenek | 6f41715 | 2011-04-04 20:56:00 +0000 | [diff] [blame] | 28 | #include "clang/AST/EvaluatedExprVisitor.h" |
Caitlin Sadowski | 3ac1fbc | 2011-08-23 18:46:34 +0000 | [diff] [blame] | 29 | #include "clang/AST/StmtVisitor.h" |
Ted Kremenek | dbdbaaf | 2010-03-20 21:06:02 +0000 | [diff] [blame] | 30 | #include "clang/Analysis/AnalysisContext.h" |
| 31 | #include "clang/Analysis/CFG.h" |
| 32 | #include "clang/Analysis/Analyses/ReachableCode.h" |
Ted Kremenek | 351ba91 | 2011-02-23 01:52:04 +0000 | [diff] [blame] | 33 | #include "clang/Analysis/Analyses/CFGReachabilityAnalysis.h" |
Caitlin Sadowski | 402aa06 | 2011-09-09 16:11:56 +0000 | [diff] [blame] | 34 | #include "clang/Analysis/Analyses/ThreadSafety.h" |
Ted Kremenek | 351ba91 | 2011-02-23 01:52:04 +0000 | [diff] [blame] | 35 | #include "clang/Analysis/CFGStmtMap.h" |
Ted Kremenek | 6f34213 | 2011-03-15 03:17:07 +0000 | [diff] [blame] | 36 | #include "clang/Analysis/Analyses/UninitializedValues.h" |
Ted Kremenek | dbdbaaf | 2010-03-20 21:06:02 +0000 | [diff] [blame] | 37 | #include "llvm/ADT/BitVector.h" |
Caitlin Sadowski | 3ac1fbc | 2011-08-23 18:46:34 +0000 | [diff] [blame] | 38 | #include "llvm/ADT/FoldingSet.h" |
| 39 | #include "llvm/ADT/ImmutableMap.h" |
| 40 | #include "llvm/ADT/PostOrderIterator.h" |
| 41 | #include "llvm/ADT/SmallVector.h" |
Caitlin Sadowski | 75f23ae | 2011-09-09 16:04:02 +0000 | [diff] [blame] | 42 | #include "llvm/ADT/StringRef.h" |
Ted Kremenek | dbdbaaf | 2010-03-20 21:06:02 +0000 | [diff] [blame] | 43 | #include "llvm/Support/Casting.h" |
Caitlin Sadowski | 3ac1fbc | 2011-08-23 18:46:34 +0000 | [diff] [blame] | 44 | #include <algorithm> |
| 45 | #include <vector> |
Ted Kremenek | dbdbaaf | 2010-03-20 21:06:02 +0000 | [diff] [blame] | 46 | |
| 47 | using namespace clang; |
| 48 | |
| 49 | //===----------------------------------------------------------------------===// |
| 50 | // Unreachable code analysis. |
| 51 | //===----------------------------------------------------------------------===// |
| 52 | |
| 53 | namespace { |
| 54 | class UnreachableCodeHandler : public reachable_code::Callback { |
| 55 | Sema &S; |
| 56 | public: |
| 57 | UnreachableCodeHandler(Sema &s) : S(s) {} |
| 58 | |
| 59 | void HandleUnreachable(SourceLocation L, SourceRange R1, SourceRange R2) { |
| 60 | S.Diag(L, diag::warn_unreachable) << R1 << R2; |
| 61 | } |
| 62 | }; |
| 63 | } |
| 64 | |
| 65 | /// CheckUnreachable - Check for unreachable code. |
| 66 | static void CheckUnreachable(Sema &S, AnalysisContext &AC) { |
| 67 | UnreachableCodeHandler UC(S); |
| 68 | reachable_code::FindUnreachableCode(AC, UC); |
| 69 | } |
| 70 | |
| 71 | //===----------------------------------------------------------------------===// |
| 72 | // Check for missing return value. |
| 73 | //===----------------------------------------------------------------------===// |
| 74 | |
John McCall | 16565aa | 2010-05-16 09:34:11 +0000 | [diff] [blame] | 75 | enum ControlFlowKind { |
| 76 | UnknownFallThrough, |
| 77 | NeverFallThrough, |
| 78 | MaybeFallThrough, |
| 79 | AlwaysFallThrough, |
| 80 | NeverFallThroughOrReturn |
| 81 | }; |
Ted Kremenek | dbdbaaf | 2010-03-20 21:06:02 +0000 | [diff] [blame] | 82 | |
| 83 | /// CheckFallThrough - Check that we don't fall off the end of a |
| 84 | /// Statement that should return a value. |
| 85 | /// |
| 86 | /// \returns AlwaysFallThrough iff we always fall off the end of the statement, |
| 87 | /// MaybeFallThrough iff we might or might not fall off the end, |
| 88 | /// NeverFallThroughOrReturn iff we never fall off the end of the statement or |
| 89 | /// return. We assume NeverFallThrough iff we never fall off the end of the |
| 90 | /// statement but we may return. We assume that functions not marked noreturn |
| 91 | /// will return. |
| 92 | static ControlFlowKind CheckFallThrough(AnalysisContext &AC) { |
| 93 | CFG *cfg = AC.getCFG(); |
John McCall | 16565aa | 2010-05-16 09:34:11 +0000 | [diff] [blame] | 94 | if (cfg == 0) return UnknownFallThrough; |
Ted Kremenek | dbdbaaf | 2010-03-20 21:06:02 +0000 | [diff] [blame] | 95 | |
| 96 | // The CFG leaves in dead things, and we don't want the dead code paths to |
| 97 | // confuse us, so we mark all live things first. |
Ted Kremenek | dbdbaaf | 2010-03-20 21:06:02 +0000 | [diff] [blame] | 98 | llvm::BitVector live(cfg->getNumBlockIDs()); |
Ted Kremenek | 0f3b4ca | 2011-08-23 23:05:11 +0000 | [diff] [blame] | 99 | unsigned count = reachable_code::ScanReachableFromBlock(&cfg->getEntry(), |
Ted Kremenek | dbdbaaf | 2010-03-20 21:06:02 +0000 | [diff] [blame] | 100 | live); |
| 101 | |
| 102 | bool AddEHEdges = AC.getAddEHEdges(); |
| 103 | if (!AddEHEdges && count != cfg->getNumBlockIDs()) |
| 104 | // When there are things remaining dead, and we didn't add EH edges |
| 105 | // from CallExprs to the catch clauses, we have to go back and |
| 106 | // mark them as live. |
| 107 | for (CFG::iterator I = cfg->begin(), E = cfg->end(); I != E; ++I) { |
| 108 | CFGBlock &b = **I; |
| 109 | if (!live[b.getBlockID()]) { |
| 110 | if (b.pred_begin() == b.pred_end()) { |
| 111 | if (b.getTerminator() && isa<CXXTryStmt>(b.getTerminator())) |
| 112 | // When not adding EH edges from calls, catch clauses |
| 113 | // can otherwise seem dead. Avoid noting them as dead. |
Ted Kremenek | 0f3b4ca | 2011-08-23 23:05:11 +0000 | [diff] [blame] | 114 | count += reachable_code::ScanReachableFromBlock(&b, live); |
Ted Kremenek | dbdbaaf | 2010-03-20 21:06:02 +0000 | [diff] [blame] | 115 | continue; |
| 116 | } |
| 117 | } |
| 118 | } |
| 119 | |
| 120 | // Now we know what is live, we check the live precessors of the exit block |
| 121 | // and look for fall through paths, being careful to ignore normal returns, |
| 122 | // and exceptional paths. |
| 123 | bool HasLiveReturn = false; |
| 124 | bool HasFakeEdge = false; |
| 125 | bool HasPlainEdge = false; |
| 126 | bool HasAbnormalEdge = false; |
Ted Kremenek | 90b828a | 2010-09-09 00:06:07 +0000 | [diff] [blame] | 127 | |
| 128 | // Ignore default cases that aren't likely to be reachable because all |
| 129 | // enums in a switch(X) have explicit case statements. |
| 130 | CFGBlock::FilterOptions FO; |
| 131 | FO.IgnoreDefaultsWithCoveredEnums = 1; |
| 132 | |
| 133 | for (CFGBlock::filtered_pred_iterator |
| 134 | I = cfg->getExit().filtered_pred_start_end(FO); I.hasMore(); ++I) { |
| 135 | const CFGBlock& B = **I; |
Ted Kremenek | dbdbaaf | 2010-03-20 21:06:02 +0000 | [diff] [blame] | 136 | if (!live[B.getBlockID()]) |
| 137 | continue; |
Ted Kremenek | 5811f59 | 2011-01-26 04:49:52 +0000 | [diff] [blame] | 138 | |
| 139 | // Destructors can appear after the 'return' in the CFG. This is |
| 140 | // normal. We need to look pass the destructors for the return |
| 141 | // statement (if it exists). |
| 142 | CFGBlock::const_reverse_iterator ri = B.rbegin(), re = B.rend(); |
Ted Kremenek | c9f8f5a | 2011-03-02 20:32:29 +0000 | [diff] [blame] | 143 | bool hasNoReturnDtor = false; |
| 144 | |
Ted Kremenek | 5811f59 | 2011-01-26 04:49:52 +0000 | [diff] [blame] | 145 | for ( ; ri != re ; ++ri) { |
| 146 | CFGElement CE = *ri; |
Ted Kremenek | c9f8f5a | 2011-03-02 20:32:29 +0000 | [diff] [blame] | 147 | |
| 148 | // FIXME: The right solution is to just sever the edges in the |
| 149 | // CFG itself. |
| 150 | if (const CFGImplicitDtor *iDtor = ri->getAs<CFGImplicitDtor>()) |
Ted Kremenek | c5aff44 | 2011-03-03 01:21:32 +0000 | [diff] [blame] | 151 | if (iDtor->isNoReturn(AC.getASTContext())) { |
Ted Kremenek | c9f8f5a | 2011-03-02 20:32:29 +0000 | [diff] [blame] | 152 | hasNoReturnDtor = true; |
| 153 | HasFakeEdge = true; |
| 154 | break; |
| 155 | } |
| 156 | |
Ted Kremenek | 5811f59 | 2011-01-26 04:49:52 +0000 | [diff] [blame] | 157 | if (isa<CFGStmt>(CE)) |
| 158 | break; |
| 159 | } |
| 160 | |
Ted Kremenek | c9f8f5a | 2011-03-02 20:32:29 +0000 | [diff] [blame] | 161 | if (hasNoReturnDtor) |
| 162 | continue; |
| 163 | |
Ted Kremenek | 5811f59 | 2011-01-26 04:49:52 +0000 | [diff] [blame] | 164 | // No more CFGElements in the block? |
| 165 | if (ri == re) { |
Ted Kremenek | dbdbaaf | 2010-03-20 21:06:02 +0000 | [diff] [blame] | 166 | if (B.getTerminator() && isa<CXXTryStmt>(B.getTerminator())) { |
| 167 | HasAbnormalEdge = true; |
| 168 | continue; |
| 169 | } |
Ted Kremenek | dbdbaaf | 2010-03-20 21:06:02 +0000 | [diff] [blame] | 170 | // A labeled empty statement, or the entry block... |
| 171 | HasPlainEdge = true; |
| 172 | continue; |
| 173 | } |
Ted Kremenek | f39e6a3 | 2011-01-25 22:50:47 +0000 | [diff] [blame] | 174 | |
Ted Kremenek | 5811f59 | 2011-01-26 04:49:52 +0000 | [diff] [blame] | 175 | CFGStmt CS = cast<CFGStmt>(*ri); |
Ted Kremenek | f1d10d9 | 2011-08-23 23:05:04 +0000 | [diff] [blame] | 176 | const Stmt *S = CS.getStmt(); |
Ted Kremenek | dbdbaaf | 2010-03-20 21:06:02 +0000 | [diff] [blame] | 177 | if (isa<ReturnStmt>(S)) { |
| 178 | HasLiveReturn = true; |
| 179 | continue; |
| 180 | } |
| 181 | if (isa<ObjCAtThrowStmt>(S)) { |
| 182 | HasFakeEdge = true; |
| 183 | continue; |
| 184 | } |
| 185 | if (isa<CXXThrowExpr>(S)) { |
| 186 | HasFakeEdge = true; |
| 187 | continue; |
| 188 | } |
| 189 | if (const AsmStmt *AS = dyn_cast<AsmStmt>(S)) { |
| 190 | if (AS->isMSAsm()) { |
| 191 | HasFakeEdge = true; |
| 192 | HasLiveReturn = true; |
| 193 | continue; |
| 194 | } |
| 195 | } |
| 196 | if (isa<CXXTryStmt>(S)) { |
| 197 | HasAbnormalEdge = true; |
| 198 | continue; |
| 199 | } |
| 200 | |
| 201 | bool NoReturnEdge = false; |
Ted Kremenek | f1d10d9 | 2011-08-23 23:05:04 +0000 | [diff] [blame] | 202 | if (const CallExpr *C = dyn_cast<CallExpr>(S)) { |
John McCall | 259d48e | 2010-04-30 07:10:06 +0000 | [diff] [blame] | 203 | if (std::find(B.succ_begin(), B.succ_end(), &cfg->getExit()) |
| 204 | == B.succ_end()) { |
Ted Kremenek | dbdbaaf | 2010-03-20 21:06:02 +0000 | [diff] [blame] | 205 | HasAbnormalEdge = true; |
| 206 | continue; |
| 207 | } |
Ted Kremenek | f1d10d9 | 2011-08-23 23:05:04 +0000 | [diff] [blame] | 208 | const Expr *CEE = C->getCallee()->IgnoreParenCasts(); |
John McCall | 1de8533 | 2011-05-11 07:19:11 +0000 | [diff] [blame] | 209 | QualType calleeType = CEE->getType(); |
| 210 | if (calleeType == AC.getASTContext().BoundMemberTy) { |
| 211 | calleeType = Expr::findBoundMemberType(CEE); |
| 212 | assert(!calleeType.isNull() && "analyzing unresolved call?"); |
| 213 | } |
| 214 | if (getFunctionExtInfo(calleeType).getNoReturn()) { |
Ted Kremenek | dbdbaaf | 2010-03-20 21:06:02 +0000 | [diff] [blame] | 215 | NoReturnEdge = true; |
| 216 | HasFakeEdge = true; |
Ted Kremenek | f1d10d9 | 2011-08-23 23:05:04 +0000 | [diff] [blame] | 217 | } else if (const DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(CEE)) { |
| 218 | const ValueDecl *VD = DRE->getDecl(); |
Ted Kremenek | dbdbaaf | 2010-03-20 21:06:02 +0000 | [diff] [blame] | 219 | if (VD->hasAttr<NoReturnAttr>()) { |
| 220 | NoReturnEdge = true; |
| 221 | HasFakeEdge = true; |
| 222 | } |
| 223 | } |
| 224 | } |
| 225 | // FIXME: Add noreturn message sends. |
| 226 | if (NoReturnEdge == false) |
| 227 | HasPlainEdge = true; |
| 228 | } |
| 229 | if (!HasPlainEdge) { |
| 230 | if (HasLiveReturn) |
| 231 | return NeverFallThrough; |
| 232 | return NeverFallThroughOrReturn; |
| 233 | } |
| 234 | if (HasAbnormalEdge || HasFakeEdge || HasLiveReturn) |
| 235 | return MaybeFallThrough; |
| 236 | // This says AlwaysFallThrough for calls to functions that are not marked |
| 237 | // noreturn, that don't return. If people would like this warning to be more |
| 238 | // accurate, such functions should be marked as noreturn. |
| 239 | return AlwaysFallThrough; |
| 240 | } |
| 241 | |
Dan Gohman | 3c46e8d | 2010-07-26 21:25:24 +0000 | [diff] [blame] | 242 | namespace { |
| 243 | |
Ted Kremenek | dbdbaaf | 2010-03-20 21:06:02 +0000 | [diff] [blame] | 244 | struct CheckFallThroughDiagnostics { |
| 245 | unsigned diag_MaybeFallThrough_HasNoReturn; |
| 246 | unsigned diag_MaybeFallThrough_ReturnsNonVoid; |
| 247 | unsigned diag_AlwaysFallThrough_HasNoReturn; |
| 248 | unsigned diag_AlwaysFallThrough_ReturnsNonVoid; |
| 249 | unsigned diag_NeverFallThroughOrReturn; |
| 250 | bool funMode; |
Argyrios Kyrtzidis | 0827408 | 2010-12-15 18:44:22 +0000 | [diff] [blame] | 251 | SourceLocation FuncLoc; |
Ted Kremenek | d064fdc | 2010-03-23 00:13:23 +0000 | [diff] [blame] | 252 | |
Douglas Gregor | ca7eaee | 2010-04-16 23:28:44 +0000 | [diff] [blame] | 253 | static CheckFallThroughDiagnostics MakeForFunction(const Decl *Func) { |
Ted Kremenek | dbdbaaf | 2010-03-20 21:06:02 +0000 | [diff] [blame] | 254 | CheckFallThroughDiagnostics D; |
Argyrios Kyrtzidis | 0827408 | 2010-12-15 18:44:22 +0000 | [diff] [blame] | 255 | D.FuncLoc = Func->getLocation(); |
Ted Kremenek | dbdbaaf | 2010-03-20 21:06:02 +0000 | [diff] [blame] | 256 | D.diag_MaybeFallThrough_HasNoReturn = |
| 257 | diag::warn_falloff_noreturn_function; |
| 258 | D.diag_MaybeFallThrough_ReturnsNonVoid = |
| 259 | diag::warn_maybe_falloff_nonvoid_function; |
| 260 | D.diag_AlwaysFallThrough_HasNoReturn = |
| 261 | diag::warn_falloff_noreturn_function; |
| 262 | D.diag_AlwaysFallThrough_ReturnsNonVoid = |
| 263 | diag::warn_falloff_nonvoid_function; |
Douglas Gregor | ca7eaee | 2010-04-16 23:28:44 +0000 | [diff] [blame] | 264 | |
| 265 | // Don't suggest that virtual functions be marked "noreturn", since they |
| 266 | // might be overridden by non-noreturn functions. |
| 267 | bool isVirtualMethod = false; |
| 268 | if (const CXXMethodDecl *Method = dyn_cast<CXXMethodDecl>(Func)) |
| 269 | isVirtualMethod = Method->isVirtual(); |
| 270 | |
| 271 | if (!isVirtualMethod) |
| 272 | D.diag_NeverFallThroughOrReturn = |
| 273 | diag::warn_suggest_noreturn_function; |
| 274 | else |
| 275 | D.diag_NeverFallThroughOrReturn = 0; |
| 276 | |
Ted Kremenek | dbdbaaf | 2010-03-20 21:06:02 +0000 | [diff] [blame] | 277 | D.funMode = true; |
| 278 | return D; |
| 279 | } |
Ted Kremenek | d064fdc | 2010-03-23 00:13:23 +0000 | [diff] [blame] | 280 | |
Ted Kremenek | dbdbaaf | 2010-03-20 21:06:02 +0000 | [diff] [blame] | 281 | static CheckFallThroughDiagnostics MakeForBlock() { |
| 282 | CheckFallThroughDiagnostics D; |
| 283 | D.diag_MaybeFallThrough_HasNoReturn = |
| 284 | diag::err_noreturn_block_has_return_expr; |
| 285 | D.diag_MaybeFallThrough_ReturnsNonVoid = |
| 286 | diag::err_maybe_falloff_nonvoid_block; |
| 287 | D.diag_AlwaysFallThrough_HasNoReturn = |
| 288 | diag::err_noreturn_block_has_return_expr; |
| 289 | D.diag_AlwaysFallThrough_ReturnsNonVoid = |
| 290 | diag::err_falloff_nonvoid_block; |
| 291 | D.diag_NeverFallThroughOrReturn = |
| 292 | diag::warn_suggest_noreturn_block; |
| 293 | D.funMode = false; |
| 294 | return D; |
| 295 | } |
Ted Kremenek | d064fdc | 2010-03-23 00:13:23 +0000 | [diff] [blame] | 296 | |
Ted Kremenek | dbdbaaf | 2010-03-20 21:06:02 +0000 | [diff] [blame] | 297 | bool checkDiagnostics(Diagnostic &D, bool ReturnsVoid, |
| 298 | bool HasNoReturn) const { |
| 299 | if (funMode) { |
Argyrios Kyrtzidis | 0827408 | 2010-12-15 18:44:22 +0000 | [diff] [blame] | 300 | return (ReturnsVoid || |
| 301 | D.getDiagnosticLevel(diag::warn_maybe_falloff_nonvoid_function, |
| 302 | FuncLoc) == Diagnostic::Ignored) |
| 303 | && (!HasNoReturn || |
| 304 | D.getDiagnosticLevel(diag::warn_noreturn_function_has_return_expr, |
| 305 | FuncLoc) == Diagnostic::Ignored) |
| 306 | && (!ReturnsVoid || |
| 307 | D.getDiagnosticLevel(diag::warn_suggest_noreturn_block, FuncLoc) |
| 308 | == Diagnostic::Ignored); |
Ted Kremenek | dbdbaaf | 2010-03-20 21:06:02 +0000 | [diff] [blame] | 309 | } |
Ted Kremenek | d064fdc | 2010-03-23 00:13:23 +0000 | [diff] [blame] | 310 | |
Ted Kremenek | dbdbaaf | 2010-03-20 21:06:02 +0000 | [diff] [blame] | 311 | // For blocks. |
| 312 | return ReturnsVoid && !HasNoReturn |
Argyrios Kyrtzidis | 0827408 | 2010-12-15 18:44:22 +0000 | [diff] [blame] | 313 | && (!ReturnsVoid || |
| 314 | D.getDiagnosticLevel(diag::warn_suggest_noreturn_block, FuncLoc) |
| 315 | == Diagnostic::Ignored); |
Ted Kremenek | dbdbaaf | 2010-03-20 21:06:02 +0000 | [diff] [blame] | 316 | } |
| 317 | }; |
| 318 | |
Dan Gohman | 3c46e8d | 2010-07-26 21:25:24 +0000 | [diff] [blame] | 319 | } |
| 320 | |
Ted Kremenek | dbdbaaf | 2010-03-20 21:06:02 +0000 | [diff] [blame] | 321 | /// CheckFallThroughForFunctionDef - Check that we don't fall off the end of a |
| 322 | /// function that should return a value. Check that we don't fall off the end |
| 323 | /// of a noreturn function. We assume that functions and blocks not marked |
| 324 | /// noreturn will return. |
| 325 | static void CheckFallThroughForBody(Sema &S, const Decl *D, const Stmt *Body, |
Ted Kremenek | 3ed6fc0 | 2011-02-23 01:51:48 +0000 | [diff] [blame] | 326 | const BlockExpr *blkExpr, |
Ted Kremenek | dbdbaaf | 2010-03-20 21:06:02 +0000 | [diff] [blame] | 327 | const CheckFallThroughDiagnostics& CD, |
| 328 | AnalysisContext &AC) { |
| 329 | |
| 330 | bool ReturnsVoid = false; |
| 331 | bool HasNoReturn = false; |
| 332 | |
| 333 | if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) { |
| 334 | ReturnsVoid = FD->getResultType()->isVoidType(); |
| 335 | HasNoReturn = FD->hasAttr<NoReturnAttr>() || |
Rafael Espindola | 264ba48 | 2010-03-30 20:24:48 +0000 | [diff] [blame] | 336 | FD->getType()->getAs<FunctionType>()->getNoReturnAttr(); |
Ted Kremenek | dbdbaaf | 2010-03-20 21:06:02 +0000 | [diff] [blame] | 337 | } |
| 338 | else if (const ObjCMethodDecl *MD = dyn_cast<ObjCMethodDecl>(D)) { |
| 339 | ReturnsVoid = MD->getResultType()->isVoidType(); |
| 340 | HasNoReturn = MD->hasAttr<NoReturnAttr>(); |
| 341 | } |
| 342 | else if (isa<BlockDecl>(D)) { |
Ted Kremenek | 3ed6fc0 | 2011-02-23 01:51:48 +0000 | [diff] [blame] | 343 | QualType BlockTy = blkExpr->getType(); |
Ted Kremenek | d064fdc | 2010-03-23 00:13:23 +0000 | [diff] [blame] | 344 | if (const FunctionType *FT = |
Ted Kremenek | dbdbaaf | 2010-03-20 21:06:02 +0000 | [diff] [blame] | 345 | BlockTy->getPointeeType()->getAs<FunctionType>()) { |
| 346 | if (FT->getResultType()->isVoidType()) |
| 347 | ReturnsVoid = true; |
| 348 | if (FT->getNoReturnAttr()) |
| 349 | HasNoReturn = true; |
| 350 | } |
| 351 | } |
| 352 | |
| 353 | Diagnostic &Diags = S.getDiagnostics(); |
| 354 | |
| 355 | // Short circuit for compilation speed. |
| 356 | if (CD.checkDiagnostics(Diags, ReturnsVoid, HasNoReturn)) |
| 357 | return; |
Ted Kremenek | d064fdc | 2010-03-23 00:13:23 +0000 | [diff] [blame] | 358 | |
Ted Kremenek | dbdbaaf | 2010-03-20 21:06:02 +0000 | [diff] [blame] | 359 | // FIXME: Function try block |
| 360 | if (const CompoundStmt *Compound = dyn_cast<CompoundStmt>(Body)) { |
| 361 | switch (CheckFallThrough(AC)) { |
John McCall | 16565aa | 2010-05-16 09:34:11 +0000 | [diff] [blame] | 362 | case UnknownFallThrough: |
| 363 | break; |
| 364 | |
Ted Kremenek | dbdbaaf | 2010-03-20 21:06:02 +0000 | [diff] [blame] | 365 | case MaybeFallThrough: |
| 366 | if (HasNoReturn) |
| 367 | S.Diag(Compound->getRBracLoc(), |
| 368 | CD.diag_MaybeFallThrough_HasNoReturn); |
| 369 | else if (!ReturnsVoid) |
| 370 | S.Diag(Compound->getRBracLoc(), |
| 371 | CD.diag_MaybeFallThrough_ReturnsNonVoid); |
| 372 | break; |
| 373 | case AlwaysFallThrough: |
| 374 | if (HasNoReturn) |
| 375 | S.Diag(Compound->getRBracLoc(), |
| 376 | CD.diag_AlwaysFallThrough_HasNoReturn); |
| 377 | else if (!ReturnsVoid) |
| 378 | S.Diag(Compound->getRBracLoc(), |
| 379 | CD.diag_AlwaysFallThrough_ReturnsNonVoid); |
| 380 | break; |
| 381 | case NeverFallThroughOrReturn: |
Chandler Carruth | b0656ec | 2011-08-31 09:01:53 +0000 | [diff] [blame] | 382 | if (ReturnsVoid && !HasNoReturn && CD.diag_NeverFallThroughOrReturn) { |
| 383 | if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) { |
| 384 | S.Diag(Compound->getLBracLoc(), CD.diag_NeverFallThroughOrReturn) |
Douglas Gregor | b332109 | 2011-09-10 00:56:20 +0000 | [diff] [blame] | 385 | << 0 << FD; |
| 386 | } else if (const ObjCMethodDecl *MD = dyn_cast<ObjCMethodDecl>(D)) { |
| 387 | S.Diag(Compound->getLBracLoc(), CD.diag_NeverFallThroughOrReturn) |
| 388 | << 1 << MD; |
Chandler Carruth | b0656ec | 2011-08-31 09:01:53 +0000 | [diff] [blame] | 389 | } else { |
| 390 | S.Diag(Compound->getLBracLoc(), CD.diag_NeverFallThroughOrReturn); |
| 391 | } |
| 392 | } |
Ted Kremenek | dbdbaaf | 2010-03-20 21:06:02 +0000 | [diff] [blame] | 393 | break; |
| 394 | case NeverFallThrough: |
| 395 | break; |
| 396 | } |
| 397 | } |
| 398 | } |
| 399 | |
| 400 | //===----------------------------------------------------------------------===// |
Ted Kremenek | 610068c | 2011-01-15 02:58:47 +0000 | [diff] [blame] | 401 | // -Wuninitialized |
| 402 | //===----------------------------------------------------------------------===// |
| 403 | |
Ted Kremenek | 6f41715 | 2011-04-04 20:56:00 +0000 | [diff] [blame] | 404 | namespace { |
Chandler Carruth | 9f64946 | 2011-04-05 06:48:00 +0000 | [diff] [blame] | 405 | /// ContainsReference - A visitor class to search for references to |
| 406 | /// a particular declaration (the needle) within any evaluated component of an |
| 407 | /// expression (recursively). |
Ted Kremenek | 6f41715 | 2011-04-04 20:56:00 +0000 | [diff] [blame] | 408 | class ContainsReference : public EvaluatedExprVisitor<ContainsReference> { |
Chandler Carruth | 9f64946 | 2011-04-05 06:48:00 +0000 | [diff] [blame] | 409 | bool FoundReference; |
| 410 | const DeclRefExpr *Needle; |
| 411 | |
Ted Kremenek | 6f41715 | 2011-04-04 20:56:00 +0000 | [diff] [blame] | 412 | public: |
Chandler Carruth | 9f64946 | 2011-04-05 06:48:00 +0000 | [diff] [blame] | 413 | ContainsReference(ASTContext &Context, const DeclRefExpr *Needle) |
| 414 | : EvaluatedExprVisitor<ContainsReference>(Context), |
| 415 | FoundReference(false), Needle(Needle) {} |
| 416 | |
| 417 | void VisitExpr(Expr *E) { |
Ted Kremenek | 6f41715 | 2011-04-04 20:56:00 +0000 | [diff] [blame] | 418 | // Stop evaluating if we already have a reference. |
Chandler Carruth | 9f64946 | 2011-04-05 06:48:00 +0000 | [diff] [blame] | 419 | if (FoundReference) |
Ted Kremenek | 6f41715 | 2011-04-04 20:56:00 +0000 | [diff] [blame] | 420 | return; |
Chandler Carruth | 9f64946 | 2011-04-05 06:48:00 +0000 | [diff] [blame] | 421 | |
| 422 | EvaluatedExprVisitor<ContainsReference>::VisitExpr(E); |
Ted Kremenek | 6f41715 | 2011-04-04 20:56:00 +0000 | [diff] [blame] | 423 | } |
Chandler Carruth | 9f64946 | 2011-04-05 06:48:00 +0000 | [diff] [blame] | 424 | |
| 425 | void VisitDeclRefExpr(DeclRefExpr *E) { |
| 426 | if (E == Needle) |
| 427 | FoundReference = true; |
| 428 | else |
| 429 | EvaluatedExprVisitor<ContainsReference>::VisitDeclRefExpr(E); |
Ted Kremenek | 6f41715 | 2011-04-04 20:56:00 +0000 | [diff] [blame] | 430 | } |
Chandler Carruth | 9f64946 | 2011-04-05 06:48:00 +0000 | [diff] [blame] | 431 | |
| 432 | bool doesContainReference() const { return FoundReference; } |
Ted Kremenek | 6f41715 | 2011-04-04 20:56:00 +0000 | [diff] [blame] | 433 | }; |
| 434 | } |
| 435 | |
David Blaikie | 4f4f349 | 2011-09-10 05:35:08 +0000 | [diff] [blame^] | 436 | static bool SuggestInitializationFixit(Sema &S, const VarDecl *VD) { |
| 437 | // Don't issue a fixit if there is already an initializer. |
| 438 | if (VD->getInit()) |
| 439 | return false; |
| 440 | |
| 441 | // Suggest possible initialization (if any). |
| 442 | const char *initialization = 0; |
| 443 | QualType VariableTy = VD->getType().getCanonicalType(); |
| 444 | |
| 445 | if (VariableTy->isObjCObjectPointerType() || |
| 446 | VariableTy->isBlockPointerType()) { |
| 447 | // Check if 'nil' is defined. |
| 448 | if (S.PP.getMacroInfo(&S.getASTContext().Idents.get("nil"))) |
| 449 | initialization = " = nil"; |
| 450 | else |
| 451 | initialization = " = 0"; |
| 452 | } |
| 453 | else if (VariableTy->isRealFloatingType()) |
| 454 | initialization = " = 0.0"; |
| 455 | else if (VariableTy->isBooleanType() && S.Context.getLangOptions().CPlusPlus) |
| 456 | initialization = " = false"; |
| 457 | else if (VariableTy->isEnumeralType()) |
| 458 | return false; |
| 459 | else if (VariableTy->isPointerType() || VariableTy->isMemberPointerType()) { |
| 460 | if (S.Context.getLangOptions().CPlusPlus0x) |
| 461 | initialization = " = nullptr"; |
| 462 | // Check if 'NULL' is defined. |
| 463 | else if (S.PP.getMacroInfo(&S.getASTContext().Idents.get("NULL"))) |
| 464 | initialization = " = NULL"; |
| 465 | else |
| 466 | initialization = " = 0"; |
| 467 | } |
| 468 | else if (VariableTy->isScalarType()) |
| 469 | initialization = " = 0"; |
| 470 | |
| 471 | if (initialization) { |
| 472 | SourceLocation loc = S.PP.getLocForEndOfToken(VD->getLocEnd()); |
| 473 | S.Diag(loc, diag::note_var_fixit_add_initialization) << VD->getDeclName() |
| 474 | << FixItHint::CreateInsertion(loc, initialization); |
| 475 | return true; |
| 476 | } |
| 477 | return false; |
| 478 | } |
| 479 | |
Chandler Carruth | 262d50e | 2011-04-05 18:27:05 +0000 | [diff] [blame] | 480 | /// DiagnoseUninitializedUse -- Helper function for diagnosing uses of an |
| 481 | /// uninitialized variable. This manages the different forms of diagnostic |
| 482 | /// emitted for particular types of uses. Returns true if the use was diagnosed |
| 483 | /// as a warning. If a pariticular use is one we omit warnings for, returns |
| 484 | /// false. |
| 485 | static bool DiagnoseUninitializedUse(Sema &S, const VarDecl *VD, |
Chandler Carruth | 64fb959 | 2011-04-05 18:18:08 +0000 | [diff] [blame] | 486 | const Expr *E, bool isAlwaysUninit) { |
Chandler Carruth | 4c4983b | 2011-04-05 18:18:05 +0000 | [diff] [blame] | 487 | bool isSelfInit = false; |
| 488 | |
| 489 | if (const DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(E)) { |
| 490 | if (isAlwaysUninit) { |
| 491 | // Inspect the initializer of the variable declaration which is |
| 492 | // being referenced prior to its initialization. We emit |
| 493 | // specialized diagnostics for self-initialization, and we |
| 494 | // specifically avoid warning about self references which take the |
| 495 | // form of: |
| 496 | // |
| 497 | // int x = x; |
| 498 | // |
| 499 | // This is used to indicate to GCC that 'x' is intentionally left |
| 500 | // uninitialized. Proven code paths which access 'x' in |
| 501 | // an uninitialized state after this will still warn. |
| 502 | // |
| 503 | // TODO: Should we suppress maybe-uninitialized warnings for |
| 504 | // variables initialized in this way? |
| 505 | if (const Expr *Initializer = VD->getInit()) { |
| 506 | if (DRE == Initializer->IgnoreParenImpCasts()) |
Chandler Carruth | 262d50e | 2011-04-05 18:27:05 +0000 | [diff] [blame] | 507 | return false; |
Chandler Carruth | 4c4983b | 2011-04-05 18:18:05 +0000 | [diff] [blame] | 508 | |
| 509 | ContainsReference CR(S.Context, DRE); |
| 510 | CR.Visit(const_cast<Expr*>(Initializer)); |
| 511 | isSelfInit = CR.doesContainReference(); |
| 512 | } |
| 513 | if (isSelfInit) { |
| 514 | S.Diag(DRE->getLocStart(), |
| 515 | diag::warn_uninit_self_reference_in_init) |
| 516 | << VD->getDeclName() << VD->getLocation() << DRE->getSourceRange(); |
| 517 | } else { |
| 518 | S.Diag(DRE->getLocStart(), diag::warn_uninit_var) |
| 519 | << VD->getDeclName() << DRE->getSourceRange(); |
| 520 | } |
| 521 | } else { |
| 522 | S.Diag(DRE->getLocStart(), diag::warn_maybe_uninit_var) |
| 523 | << VD->getDeclName() << DRE->getSourceRange(); |
| 524 | } |
| 525 | } else { |
| 526 | const BlockExpr *BE = cast<BlockExpr>(E); |
| 527 | S.Diag(BE->getLocStart(), |
| 528 | isAlwaysUninit ? diag::warn_uninit_var_captured_by_block |
| 529 | : diag::warn_maybe_uninit_var_captured_by_block) |
| 530 | << VD->getDeclName(); |
| 531 | } |
| 532 | |
| 533 | // Report where the variable was declared when the use wasn't within |
David Blaikie | 4f4f349 | 2011-09-10 05:35:08 +0000 | [diff] [blame^] | 534 | // the initializer of that declaration & we didn't already suggest |
| 535 | // an initialization fixit. |
| 536 | if (!isSelfInit && !SuggestInitializationFixit(S, VD)) |
Chandler Carruth | 4c4983b | 2011-04-05 18:18:05 +0000 | [diff] [blame] | 537 | S.Diag(VD->getLocStart(), diag::note_uninit_var_def) |
| 538 | << VD->getDeclName(); |
| 539 | |
Chandler Carruth | 262d50e | 2011-04-05 18:27:05 +0000 | [diff] [blame] | 540 | return true; |
Chandler Carruth | 64fb959 | 2011-04-05 18:18:08 +0000 | [diff] [blame] | 541 | } |
| 542 | |
Ted Kremenek | f7bafc7 | 2011-03-15 04:57:38 +0000 | [diff] [blame] | 543 | typedef std::pair<const Expr*, bool> UninitUse; |
| 544 | |
Ted Kremenek | 610068c | 2011-01-15 02:58:47 +0000 | [diff] [blame] | 545 | namespace { |
Ted Kremenek | 94b1b4d | 2011-01-21 19:41:41 +0000 | [diff] [blame] | 546 | struct SLocSort { |
Ted Kremenek | f7bafc7 | 2011-03-15 04:57:38 +0000 | [diff] [blame] | 547 | bool operator()(const UninitUse &a, const UninitUse &b) { |
| 548 | SourceLocation aLoc = a.first->getLocStart(); |
| 549 | SourceLocation bLoc = b.first->getLocStart(); |
Ted Kremenek | 94b1b4d | 2011-01-21 19:41:41 +0000 | [diff] [blame] | 550 | return aLoc.getRawEncoding() < bLoc.getRawEncoding(); |
| 551 | } |
| 552 | }; |
| 553 | |
Ted Kremenek | 610068c | 2011-01-15 02:58:47 +0000 | [diff] [blame] | 554 | class UninitValsDiagReporter : public UninitVariablesHandler { |
| 555 | Sema &S; |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 556 | typedef SmallVector<UninitUse, 2> UsesVec; |
Ted Kremenek | 94b1b4d | 2011-01-21 19:41:41 +0000 | [diff] [blame] | 557 | typedef llvm::DenseMap<const VarDecl *, UsesVec*> UsesMap; |
| 558 | UsesMap *uses; |
| 559 | |
Ted Kremenek | 610068c | 2011-01-15 02:58:47 +0000 | [diff] [blame] | 560 | public: |
Ted Kremenek | 94b1b4d | 2011-01-21 19:41:41 +0000 | [diff] [blame] | 561 | UninitValsDiagReporter(Sema &S) : S(S), uses(0) {} |
| 562 | ~UninitValsDiagReporter() { |
| 563 | flushDiagnostics(); |
| 564 | } |
Ted Kremenek | 610068c | 2011-01-15 02:58:47 +0000 | [diff] [blame] | 565 | |
Ted Kremenek | f7bafc7 | 2011-03-15 04:57:38 +0000 | [diff] [blame] | 566 | void handleUseOfUninitVariable(const Expr *ex, const VarDecl *vd, |
| 567 | bool isAlwaysUninit) { |
Ted Kremenek | 94b1b4d | 2011-01-21 19:41:41 +0000 | [diff] [blame] | 568 | if (!uses) |
| 569 | uses = new UsesMap(); |
| 570 | |
| 571 | UsesVec *&vec = (*uses)[vd]; |
| 572 | if (!vec) |
| 573 | vec = new UsesVec(); |
| 574 | |
Ted Kremenek | f7bafc7 | 2011-03-15 04:57:38 +0000 | [diff] [blame] | 575 | vec->push_back(std::make_pair(ex, isAlwaysUninit)); |
Ted Kremenek | 94b1b4d | 2011-01-21 19:41:41 +0000 | [diff] [blame] | 576 | } |
| 577 | |
| 578 | void flushDiagnostics() { |
| 579 | if (!uses) |
| 580 | return; |
Ted Kremenek | 609e317 | 2011-02-02 23:35:53 +0000 | [diff] [blame] | 581 | |
Ted Kremenek | 94b1b4d | 2011-01-21 19:41:41 +0000 | [diff] [blame] | 582 | for (UsesMap::iterator i = uses->begin(), e = uses->end(); i != e; ++i) { |
| 583 | const VarDecl *vd = i->first; |
| 584 | UsesVec *vec = i->second; |
Ted Kremenek | 609e317 | 2011-02-02 23:35:53 +0000 | [diff] [blame] | 585 | |
Ted Kremenek | 94b1b4d | 2011-01-21 19:41:41 +0000 | [diff] [blame] | 586 | // Sort the uses by their SourceLocations. While not strictly |
| 587 | // guaranteed to produce them in line/column order, this will provide |
| 588 | // a stable ordering. |
| 589 | std::sort(vec->begin(), vec->end(), SLocSort()); |
| 590 | |
Chandler Carruth | 64fb959 | 2011-04-05 18:18:08 +0000 | [diff] [blame] | 591 | for (UsesVec::iterator vi = vec->begin(), ve = vec->end(); vi != ve; |
| 592 | ++vi) { |
David Blaikie | 4f4f349 | 2011-09-10 05:35:08 +0000 | [diff] [blame^] | 593 | if (DiagnoseUninitializedUse(S, vd, vi->first, |
Chandler Carruth | 262d50e | 2011-04-05 18:27:05 +0000 | [diff] [blame] | 594 | /*isAlwaysUninit=*/vi->second)) |
David Blaikie | 4f4f349 | 2011-09-10 05:35:08 +0000 | [diff] [blame^] | 595 | // Skip further diagnostics for this variable. We try to warn only on |
| 596 | // the first point at which a variable is used uninitialized. |
| 597 | break; |
Chandler Carruth | 64fb959 | 2011-04-05 18:18:08 +0000 | [diff] [blame] | 598 | } |
Ted Kremenek | d40066b | 2011-04-04 23:29:12 +0000 | [diff] [blame] | 599 | |
Ted Kremenek | 94b1b4d | 2011-01-21 19:41:41 +0000 | [diff] [blame] | 600 | delete vec; |
| 601 | } |
| 602 | delete uses; |
Ted Kremenek | 610068c | 2011-01-15 02:58:47 +0000 | [diff] [blame] | 603 | } |
| 604 | }; |
| 605 | } |
| 606 | |
Caitlin Sadowski | 3ac1fbc | 2011-08-23 18:46:34 +0000 | [diff] [blame] | 607 | |
| 608 | //===----------------------------------------------------------------------===// |
| 609 | // -Wthread-safety |
| 610 | //===----------------------------------------------------------------------===// |
Caitlin Sadowski | 75f23ae | 2011-09-09 16:04:02 +0000 | [diff] [blame] | 611 | namespace clang { |
| 612 | namespace thread_safety { |
| 613 | typedef std::pair<SourceLocation, PartialDiagnostic> DelayedDiag; |
| 614 | typedef llvm::SmallVector<DelayedDiag, 4> DiagList; |
| 615 | |
Caitlin Sadowski | 75f23ae | 2011-09-09 16:04:02 +0000 | [diff] [blame] | 616 | struct SortDiagBySourceLocation { |
| 617 | Sema &S; |
| 618 | SortDiagBySourceLocation(Sema &S) : S(S) {} |
| 619 | |
| 620 | bool operator()(const DelayedDiag &left, const DelayedDiag &right) { |
| 621 | // Although this call will be slow, this is only called when outputting |
| 622 | // multiple warnings. |
| 623 | return S.getSourceManager().isBeforeInTranslationUnit(left.first, |
| 624 | right.first); |
| 625 | } |
| 626 | }; |
| 627 | |
Caitlin Sadowski | 75f23ae | 2011-09-09 16:04:02 +0000 | [diff] [blame] | 628 | class ThreadSafetyReporter : public clang::thread_safety::ThreadSafetyHandler { |
| 629 | Sema &S; |
| 630 | DiagList Warnings; |
| 631 | |
| 632 | // Helper functions |
| 633 | void warnLockMismatch(unsigned DiagID, Name LockName, SourceLocation Loc) { |
| 634 | PartialDiagnostic Warning = S.PDiag(DiagID) << LockName; |
| 635 | Warnings.push_back(DelayedDiag(Loc, Warning)); |
| 636 | } |
| 637 | |
| 638 | public: |
| 639 | ThreadSafetyReporter(Sema &S) : S(S) {} |
| 640 | |
| 641 | /// \brief Emit all buffered diagnostics in order of sourcelocation. |
| 642 | /// We need to output diagnostics produced while iterating through |
| 643 | /// the lockset in deterministic order, so this function orders diagnostics |
| 644 | /// and outputs them. |
| 645 | void emitDiagnostics() { |
| 646 | SortDiagBySourceLocation SortDiagBySL(S); |
| 647 | sort(Warnings.begin(), Warnings.end(), SortDiagBySL); |
| 648 | for (DiagList::iterator I = Warnings.begin(), E = Warnings.end(); |
| 649 | I != E; ++I) |
| 650 | S.Diag(I->first, I->second); |
| 651 | } |
| 652 | |
Caitlin Sadowski | 99107eb | 2011-09-09 16:21:55 +0000 | [diff] [blame] | 653 | void handleInvalidLockExp(SourceLocation Loc) { |
| 654 | PartialDiagnostic Warning = S.PDiag(diag::warn_cannot_resolve_lock) << Loc; |
| 655 | Warnings.push_back(DelayedDiag(Loc, Warning)); |
| 656 | } |
Caitlin Sadowski | 75f23ae | 2011-09-09 16:04:02 +0000 | [diff] [blame] | 657 | void handleUnmatchedUnlock(Name LockName, SourceLocation Loc) { |
| 658 | warnLockMismatch(diag::warn_unlock_but_no_lock, LockName, Loc); |
| 659 | } |
| 660 | |
| 661 | void handleDoubleLock(Name LockName, SourceLocation Loc) { |
| 662 | warnLockMismatch(diag::warn_double_lock, LockName, Loc); |
| 663 | } |
| 664 | |
| 665 | void handleMutexHeldEndOfScope(Name LockName, SourceLocation Loc){ |
| 666 | warnLockMismatch(diag::warn_lock_at_end_of_scope, LockName, Loc); |
| 667 | } |
| 668 | |
| 669 | void handleNoLockLoopEntry(Name LockName, SourceLocation Loc) { |
| 670 | warnLockMismatch(diag::warn_expecting_lock_held_on_loop, LockName, Loc); |
| 671 | } |
| 672 | |
| 673 | void handleNoUnlock(Name LockName, llvm::StringRef FunName, |
| 674 | SourceLocation Loc) { |
| 675 | PartialDiagnostic Warning = |
| 676 | S.PDiag(diag::warn_no_unlock) << LockName << FunName; |
| 677 | Warnings.push_back(DelayedDiag(Loc, Warning)); |
| 678 | } |
| 679 | |
| 680 | void handleExclusiveAndShared(Name LockName, SourceLocation Loc1, |
| 681 | SourceLocation Loc2) { |
| 682 | PartialDiagnostic Warning = |
| 683 | S.PDiag(diag::warn_lock_exclusive_and_shared) << LockName; |
| 684 | PartialDiagnostic Note = |
| 685 | S.PDiag(diag::note_lock_exclusive_and_shared) << LockName; |
| 686 | Warnings.push_back(DelayedDiag(Loc1, Warning)); |
| 687 | Warnings.push_back(DelayedDiag(Loc2, Note)); |
| 688 | } |
| 689 | |
| 690 | void handleNoMutexHeld(const NamedDecl *D, ProtectedOperationKind POK, |
| 691 | AccessKind AK, SourceLocation Loc) { |
Caitlin Sadowski | a49d1d8 | 2011-09-09 16:07:55 +0000 | [diff] [blame] | 692 | // FIXME: It would be nice if this case printed without single quotes around |
| 693 | // the phrase 'any mutex' |
| 694 | handleMutexNotHeld(D, POK, "any mutex", getLockKindFromAccessKind(AK), Loc); |
Caitlin Sadowski | 75f23ae | 2011-09-09 16:04:02 +0000 | [diff] [blame] | 695 | } |
| 696 | |
| 697 | void handleMutexNotHeld(const NamedDecl *D, ProtectedOperationKind POK, |
| 698 | Name LockName, LockKind LK, SourceLocation Loc) { |
| 699 | unsigned DiagID; |
| 700 | switch (POK) { |
| 701 | case POK_VarAccess: |
| 702 | DiagID = diag::warn_variable_requires_lock; |
| 703 | break; |
| 704 | case POK_VarDereference: |
| 705 | DiagID = diag::warn_var_deref_requires_lock; |
| 706 | break; |
| 707 | case POK_FunctionCall: |
| 708 | DiagID = diag::warn_fun_requires_lock; |
| 709 | break; |
| 710 | } |
| 711 | PartialDiagnostic Warning = S.PDiag(DiagID) |
| 712 | << D->getName().str() << LockName << LK; |
| 713 | Warnings.push_back(DelayedDiag(Loc, Warning)); |
| 714 | } |
| 715 | |
| 716 | void handleFunExcludesLock(Name FunName, Name LockName, SourceLocation Loc) { |
| 717 | PartialDiagnostic Warning = |
| 718 | S.PDiag(diag::warn_fun_excludes_mutex) << FunName << LockName; |
| 719 | Warnings.push_back(DelayedDiag(Loc, Warning)); |
| 720 | } |
| 721 | }; |
| 722 | } |
| 723 | } |
| 724 | |
Ted Kremenek | 610068c | 2011-01-15 02:58:47 +0000 | [diff] [blame] | 725 | //===----------------------------------------------------------------------===// |
Ted Kremenek | dbdbaaf | 2010-03-20 21:06:02 +0000 | [diff] [blame] | 726 | // AnalysisBasedWarnings - Worker object used by Sema to execute analysis-based |
| 727 | // warnings on a function, method, or block. |
| 728 | //===----------------------------------------------------------------------===// |
| 729 | |
Ted Kremenek | d064fdc | 2010-03-23 00:13:23 +0000 | [diff] [blame] | 730 | clang::sema::AnalysisBasedWarnings::Policy::Policy() { |
| 731 | enableCheckFallThrough = 1; |
| 732 | enableCheckUnreachable = 0; |
Caitlin Sadowski | 3ac1fbc | 2011-08-23 18:46:34 +0000 | [diff] [blame] | 733 | enableThreadSafetyAnalysis = 0; |
Ted Kremenek | d064fdc | 2010-03-23 00:13:23 +0000 | [diff] [blame] | 734 | } |
| 735 | |
Chandler Carruth | 5d98994 | 2011-07-06 16:21:37 +0000 | [diff] [blame] | 736 | clang::sema::AnalysisBasedWarnings::AnalysisBasedWarnings(Sema &s) |
| 737 | : S(s), |
| 738 | NumFunctionsAnalyzed(0), |
Benjamin Kramer | 54cf341 | 2011-07-08 20:38:53 +0000 | [diff] [blame] | 739 | NumFunctionsWithBadCFGs(0), |
Chandler Carruth | 5d98994 | 2011-07-06 16:21:37 +0000 | [diff] [blame] | 740 | NumCFGBlocks(0), |
Benjamin Kramer | 54cf341 | 2011-07-08 20:38:53 +0000 | [diff] [blame] | 741 | MaxCFGBlocksPerFunction(0), |
| 742 | NumUninitAnalysisFunctions(0), |
| 743 | NumUninitAnalysisVariables(0), |
| 744 | MaxUninitAnalysisVariablesPerFunction(0), |
| 745 | NumUninitAnalysisBlockVisits(0), |
| 746 | MaxUninitAnalysisBlockVisitsPerFunction(0) { |
Ted Kremenek | dbdbaaf | 2010-03-20 21:06:02 +0000 | [diff] [blame] | 747 | Diagnostic &D = S.getDiagnostics(); |
Ted Kremenek | d064fdc | 2010-03-23 00:13:23 +0000 | [diff] [blame] | 748 | DefaultPolicy.enableCheckUnreachable = (unsigned) |
Argyrios Kyrtzidis | 0827408 | 2010-12-15 18:44:22 +0000 | [diff] [blame] | 749 | (D.getDiagnosticLevel(diag::warn_unreachable, SourceLocation()) != |
| 750 | Diagnostic::Ignored); |
Caitlin Sadowski | 3ac1fbc | 2011-08-23 18:46:34 +0000 | [diff] [blame] | 751 | DefaultPolicy.enableThreadSafetyAnalysis = (unsigned) |
| 752 | (D.getDiagnosticLevel(diag::warn_double_lock, SourceLocation()) != |
| 753 | Diagnostic::Ignored); |
| 754 | |
Ted Kremenek | dbdbaaf | 2010-03-20 21:06:02 +0000 | [diff] [blame] | 755 | } |
| 756 | |
Ted Kremenek | 351ba91 | 2011-02-23 01:52:04 +0000 | [diff] [blame] | 757 | static void flushDiagnostics(Sema &S, sema::FunctionScopeInfo *fscope) { |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 758 | for (SmallVectorImpl<sema::PossiblyUnreachableDiag>::iterator |
Ted Kremenek | 351ba91 | 2011-02-23 01:52:04 +0000 | [diff] [blame] | 759 | i = fscope->PossiblyUnreachableDiags.begin(), |
| 760 | e = fscope->PossiblyUnreachableDiags.end(); |
| 761 | i != e; ++i) { |
| 762 | const sema::PossiblyUnreachableDiag &D = *i; |
| 763 | S.Diag(D.Loc, D.PD); |
| 764 | } |
| 765 | } |
| 766 | |
Ted Kremenek | d064fdc | 2010-03-23 00:13:23 +0000 | [diff] [blame] | 767 | void clang::sema:: |
| 768 | AnalysisBasedWarnings::IssueWarnings(sema::AnalysisBasedWarnings::Policy P, |
Ted Kremenek | 283a358 | 2011-02-23 01:51:53 +0000 | [diff] [blame] | 769 | sema::FunctionScopeInfo *fscope, |
Ted Kremenek | 3ed6fc0 | 2011-02-23 01:51:48 +0000 | [diff] [blame] | 770 | const Decl *D, const BlockExpr *blkExpr) { |
Ted Kremenek | d068aab | 2010-03-20 21:11:09 +0000 | [diff] [blame] | 771 | |
Ted Kremenek | dbdbaaf | 2010-03-20 21:06:02 +0000 | [diff] [blame] | 772 | // We avoid doing analysis-based warnings when there are errors for |
| 773 | // two reasons: |
| 774 | // (1) The CFGs often can't be constructed (if the body is invalid), so |
| 775 | // don't bother trying. |
| 776 | // (2) The code already has problems; running the analysis just takes more |
| 777 | // time. |
Ted Kremenek | 99e8192 | 2010-04-30 21:49:25 +0000 | [diff] [blame] | 778 | Diagnostic &Diags = S.getDiagnostics(); |
| 779 | |
Ted Kremenek | d064fdc | 2010-03-23 00:13:23 +0000 | [diff] [blame] | 780 | // Do not do any analysis for declarations in system headers if we are |
| 781 | // going to just ignore them. |
Ted Kremenek | 99e8192 | 2010-04-30 21:49:25 +0000 | [diff] [blame] | 782 | if (Diags.getSuppressSystemWarnings() && |
Ted Kremenek | d064fdc | 2010-03-23 00:13:23 +0000 | [diff] [blame] | 783 | S.SourceMgr.isInSystemHeader(D->getLocation())) |
| 784 | return; |
| 785 | |
John McCall | e0054f6 | 2010-08-25 05:56:39 +0000 | [diff] [blame] | 786 | // For code in dependent contexts, we'll do this at instantiation time. |
| 787 | if (cast<DeclContext>(D)->isDependentContext()) |
| 788 | return; |
Ted Kremenek | dbdbaaf | 2010-03-20 21:06:02 +0000 | [diff] [blame] | 789 | |
Ted Kremenek | 351ba91 | 2011-02-23 01:52:04 +0000 | [diff] [blame] | 790 | if (Diags.hasErrorOccurred() || Diags.hasFatalErrorOccurred()) { |
| 791 | // Flush out any possibly unreachable diagnostics. |
| 792 | flushDiagnostics(S, fscope); |
| 793 | return; |
| 794 | } |
| 795 | |
Ted Kremenek | dbdbaaf | 2010-03-20 21:06:02 +0000 | [diff] [blame] | 796 | const Stmt *Body = D->getBody(); |
| 797 | assert(Body); |
| 798 | |
Ted Kremenek | bc5cb8a | 2011-07-21 05:22:47 +0000 | [diff] [blame] | 799 | AnalysisContext AC(D, 0); |
| 800 | |
Ted Kremenek | dbdbaaf | 2010-03-20 21:06:02 +0000 | [diff] [blame] | 801 | // Don't generate EH edges for CallExprs as we'd like to avoid the n^2 |
| 802 | // explosion for destrutors that can result and the compile time hit. |
Ted Kremenek | bc5cb8a | 2011-07-21 05:22:47 +0000 | [diff] [blame] | 803 | AC.getCFGBuildOptions().PruneTriviallyFalseEdges = true; |
| 804 | AC.getCFGBuildOptions().AddEHEdges = false; |
| 805 | AC.getCFGBuildOptions().AddInitializers = true; |
| 806 | AC.getCFGBuildOptions().AddImplicitDtors = true; |
Ted Kremenek | 0c8e5a0 | 2011-07-19 14:18:48 +0000 | [diff] [blame] | 807 | |
| 808 | // Force that certain expressions appear as CFGElements in the CFG. This |
| 809 | // is used to speed up various analyses. |
| 810 | // FIXME: This isn't the right factoring. This is here for initial |
| 811 | // prototyping, but we need a way for analyses to say what expressions they |
| 812 | // expect to always be CFGElements and then fill in the BuildOptions |
| 813 | // appropriately. This is essentially a layering violation. |
Ted Kremenek | 0f3b4ca | 2011-08-23 23:05:11 +0000 | [diff] [blame] | 814 | if (P.enableCheckUnreachable) { |
| 815 | // Unreachable code analysis requires a linearized CFG. |
| 816 | AC.getCFGBuildOptions().setAllAlwaysAdd(); |
| 817 | } |
| 818 | else { |
| 819 | AC.getCFGBuildOptions() |
| 820 | .setAlwaysAdd(Stmt::BinaryOperatorClass) |
| 821 | .setAlwaysAdd(Stmt::BlockExprClass) |
| 822 | .setAlwaysAdd(Stmt::CStyleCastExprClass) |
| 823 | .setAlwaysAdd(Stmt::DeclRefExprClass) |
| 824 | .setAlwaysAdd(Stmt::ImplicitCastExprClass) |
| 825 | .setAlwaysAdd(Stmt::UnaryOperatorClass); |
| 826 | } |
Ted Kremenek | dbdbaaf | 2010-03-20 21:06:02 +0000 | [diff] [blame] | 827 | |
Ted Kremenek | bc5cb8a | 2011-07-21 05:22:47 +0000 | [diff] [blame] | 828 | // Construct the analysis context with the specified CFG build options. |
| 829 | |
Ted Kremenek | 351ba91 | 2011-02-23 01:52:04 +0000 | [diff] [blame] | 830 | // Emit delayed diagnostics. |
| 831 | if (!fscope->PossiblyUnreachableDiags.empty()) { |
| 832 | bool analyzed = false; |
Ted Kremenek | 0d28d36 | 2011-03-10 03:50:34 +0000 | [diff] [blame] | 833 | |
| 834 | // Register the expressions with the CFGBuilder. |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 835 | for (SmallVectorImpl<sema::PossiblyUnreachableDiag>::iterator |
Ted Kremenek | 0d28d36 | 2011-03-10 03:50:34 +0000 | [diff] [blame] | 836 | i = fscope->PossiblyUnreachableDiags.begin(), |
| 837 | e = fscope->PossiblyUnreachableDiags.end(); |
| 838 | i != e; ++i) { |
| 839 | if (const Stmt *stmt = i->stmt) |
| 840 | AC.registerForcedBlockExpression(stmt); |
| 841 | } |
| 842 | |
| 843 | if (AC.getCFG()) { |
| 844 | analyzed = true; |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 845 | for (SmallVectorImpl<sema::PossiblyUnreachableDiag>::iterator |
Ted Kremenek | 0d28d36 | 2011-03-10 03:50:34 +0000 | [diff] [blame] | 846 | i = fscope->PossiblyUnreachableDiags.begin(), |
| 847 | e = fscope->PossiblyUnreachableDiags.end(); |
| 848 | i != e; ++i) |
| 849 | { |
| 850 | const sema::PossiblyUnreachableDiag &D = *i; |
| 851 | bool processed = false; |
| 852 | if (const Stmt *stmt = i->stmt) { |
| 853 | const CFGBlock *block = AC.getBlockForRegisteredExpression(stmt); |
| 854 | assert(block); |
Ted Kremenek | af13d5b | 2011-03-19 01:00:33 +0000 | [diff] [blame] | 855 | if (CFGReverseBlockReachabilityAnalysis *cra = AC.getCFGReachablityAnalysis()) { |
Ted Kremenek | 351ba91 | 2011-02-23 01:52:04 +0000 | [diff] [blame] | 856 | // Can this block be reached from the entrance? |
Ted Kremenek | 0d28d36 | 2011-03-10 03:50:34 +0000 | [diff] [blame] | 857 | if (cra->isReachable(&AC.getCFG()->getEntry(), block)) |
Ted Kremenek | 351ba91 | 2011-02-23 01:52:04 +0000 | [diff] [blame] | 858 | S.Diag(D.Loc, D.PD); |
Ted Kremenek | 0d28d36 | 2011-03-10 03:50:34 +0000 | [diff] [blame] | 859 | processed = true; |
Ted Kremenek | 351ba91 | 2011-02-23 01:52:04 +0000 | [diff] [blame] | 860 | } |
| 861 | } |
Ted Kremenek | 0d28d36 | 2011-03-10 03:50:34 +0000 | [diff] [blame] | 862 | if (!processed) { |
| 863 | // Emit the warning anyway if we cannot map to a basic block. |
| 864 | S.Diag(D.Loc, D.PD); |
| 865 | } |
Ted Kremenek | 351ba91 | 2011-02-23 01:52:04 +0000 | [diff] [blame] | 866 | } |
Ted Kremenek | 0d28d36 | 2011-03-10 03:50:34 +0000 | [diff] [blame] | 867 | } |
Ted Kremenek | 351ba91 | 2011-02-23 01:52:04 +0000 | [diff] [blame] | 868 | |
| 869 | if (!analyzed) |
| 870 | flushDiagnostics(S, fscope); |
| 871 | } |
| 872 | |
| 873 | |
Ted Kremenek | dbdbaaf | 2010-03-20 21:06:02 +0000 | [diff] [blame] | 874 | // Warning: check missing 'return' |
Ted Kremenek | d064fdc | 2010-03-23 00:13:23 +0000 | [diff] [blame] | 875 | if (P.enableCheckFallThrough) { |
Ted Kremenek | dbdbaaf | 2010-03-20 21:06:02 +0000 | [diff] [blame] | 876 | const CheckFallThroughDiagnostics &CD = |
| 877 | (isa<BlockDecl>(D) ? CheckFallThroughDiagnostics::MakeForBlock() |
Douglas Gregor | ca7eaee | 2010-04-16 23:28:44 +0000 | [diff] [blame] | 878 | : CheckFallThroughDiagnostics::MakeForFunction(D)); |
Ted Kremenek | 3ed6fc0 | 2011-02-23 01:51:48 +0000 | [diff] [blame] | 879 | CheckFallThroughForBody(S, D, Body, blkExpr, CD, AC); |
Ted Kremenek | dbdbaaf | 2010-03-20 21:06:02 +0000 | [diff] [blame] | 880 | } |
| 881 | |
| 882 | // Warning: check for unreachable code |
Ted Kremenek | b7e5f14 | 2010-04-08 18:51:44 +0000 | [diff] [blame] | 883 | if (P.enableCheckUnreachable) |
Ted Kremenek | dbdbaaf | 2010-03-20 21:06:02 +0000 | [diff] [blame] | 884 | CheckUnreachable(S, AC); |
Caitlin Sadowski | 75f23ae | 2011-09-09 16:04:02 +0000 | [diff] [blame] | 885 | |
Caitlin Sadowski | 3ac1fbc | 2011-08-23 18:46:34 +0000 | [diff] [blame] | 886 | // Check for thread safety violations |
Caitlin Sadowski | 75f23ae | 2011-09-09 16:04:02 +0000 | [diff] [blame] | 887 | if (P.enableThreadSafetyAnalysis) { |
| 888 | thread_safety::ThreadSafetyReporter Reporter(S); |
| 889 | thread_safety::runThreadSafetyAnalysis(AC, Reporter); |
| 890 | Reporter.emitDiagnostics(); |
| 891 | } |
Caitlin Sadowski | 3ac1fbc | 2011-08-23 18:46:34 +0000 | [diff] [blame] | 892 | |
Ted Kremenek | a8c17a5 | 2011-01-25 19:13:48 +0000 | [diff] [blame] | 893 | if (Diags.getDiagnosticLevel(diag::warn_uninit_var, D->getLocStart()) |
Ted Kremenek | 76709bf | 2011-03-15 05:22:28 +0000 | [diff] [blame] | 894 | != Diagnostic::Ignored || |
| 895 | Diags.getDiagnosticLevel(diag::warn_maybe_uninit_var, D->getLocStart()) |
Ted Kremenek | 610068c | 2011-01-15 02:58:47 +0000 | [diff] [blame] | 896 | != Diagnostic::Ignored) { |
Ted Kremenek | c5e43c1 | 2011-03-17 05:29:57 +0000 | [diff] [blame] | 897 | if (CFG *cfg = AC.getCFG()) { |
Ted Kremenek | c21fed3 | 2011-01-18 21:18:58 +0000 | [diff] [blame] | 898 | UninitValsDiagReporter reporter(S); |
Fariborz Jahanian | 57080fb | 2011-07-16 18:31:33 +0000 | [diff] [blame] | 899 | UninitVariablesAnalysisStats stats; |
Benjamin Kramer | 12efd57 | 2011-07-16 20:13:06 +0000 | [diff] [blame] | 900 | std::memset(&stats, 0, sizeof(UninitVariablesAnalysisStats)); |
Ted Kremenek | a8c17a5 | 2011-01-25 19:13:48 +0000 | [diff] [blame] | 901 | runUninitializedVariablesAnalysis(*cast<DeclContext>(D), *cfg, AC, |
Chandler Carruth | 5d98994 | 2011-07-06 16:21:37 +0000 | [diff] [blame] | 902 | reporter, stats); |
| 903 | |
| 904 | if (S.CollectStats && stats.NumVariablesAnalyzed > 0) { |
| 905 | ++NumUninitAnalysisFunctions; |
| 906 | NumUninitAnalysisVariables += stats.NumVariablesAnalyzed; |
| 907 | NumUninitAnalysisBlockVisits += stats.NumBlockVisits; |
| 908 | MaxUninitAnalysisVariablesPerFunction = |
| 909 | std::max(MaxUninitAnalysisVariablesPerFunction, |
| 910 | stats.NumVariablesAnalyzed); |
| 911 | MaxUninitAnalysisBlockVisitsPerFunction = |
| 912 | std::max(MaxUninitAnalysisBlockVisitsPerFunction, |
| 913 | stats.NumBlockVisits); |
| 914 | } |
Ted Kremenek | 610068c | 2011-01-15 02:58:47 +0000 | [diff] [blame] | 915 | } |
| 916 | } |
Chandler Carruth | 5d98994 | 2011-07-06 16:21:37 +0000 | [diff] [blame] | 917 | |
| 918 | // Collect statistics about the CFG if it was built. |
| 919 | if (S.CollectStats && AC.isCFGBuilt()) { |
| 920 | ++NumFunctionsAnalyzed; |
| 921 | if (CFG *cfg = AC.getCFG()) { |
| 922 | // If we successfully built a CFG for this context, record some more |
| 923 | // detail information about it. |
Chandler Carruth | 3ea4c49 | 2011-07-06 22:21:45 +0000 | [diff] [blame] | 924 | NumCFGBlocks += cfg->getNumBlockIDs(); |
Chandler Carruth | 5d98994 | 2011-07-06 16:21:37 +0000 | [diff] [blame] | 925 | MaxCFGBlocksPerFunction = std::max(MaxCFGBlocksPerFunction, |
Chandler Carruth | 3ea4c49 | 2011-07-06 22:21:45 +0000 | [diff] [blame] | 926 | cfg->getNumBlockIDs()); |
Chandler Carruth | 5d98994 | 2011-07-06 16:21:37 +0000 | [diff] [blame] | 927 | } else { |
| 928 | ++NumFunctionsWithBadCFGs; |
| 929 | } |
| 930 | } |
| 931 | } |
| 932 | |
| 933 | void clang::sema::AnalysisBasedWarnings::PrintStats() const { |
| 934 | llvm::errs() << "\n*** Analysis Based Warnings Stats:\n"; |
| 935 | |
| 936 | unsigned NumCFGsBuilt = NumFunctionsAnalyzed - NumFunctionsWithBadCFGs; |
| 937 | unsigned AvgCFGBlocksPerFunction = |
| 938 | !NumCFGsBuilt ? 0 : NumCFGBlocks/NumCFGsBuilt; |
| 939 | llvm::errs() << NumFunctionsAnalyzed << " functions analyzed (" |
| 940 | << NumFunctionsWithBadCFGs << " w/o CFGs).\n" |
| 941 | << " " << NumCFGBlocks << " CFG blocks built.\n" |
| 942 | << " " << AvgCFGBlocksPerFunction |
| 943 | << " average CFG blocks per function.\n" |
| 944 | << " " << MaxCFGBlocksPerFunction |
| 945 | << " max CFG blocks per function.\n"; |
| 946 | |
| 947 | unsigned AvgUninitVariablesPerFunction = !NumUninitAnalysisFunctions ? 0 |
| 948 | : NumUninitAnalysisVariables/NumUninitAnalysisFunctions; |
| 949 | unsigned AvgUninitBlockVisitsPerFunction = !NumUninitAnalysisFunctions ? 0 |
| 950 | : NumUninitAnalysisBlockVisits/NumUninitAnalysisFunctions; |
| 951 | llvm::errs() << NumUninitAnalysisFunctions |
| 952 | << " functions analyzed for uninitialiazed variables\n" |
| 953 | << " " << NumUninitAnalysisVariables << " variables analyzed.\n" |
| 954 | << " " << AvgUninitVariablesPerFunction |
| 955 | << " average variables per function.\n" |
| 956 | << " " << MaxUninitAnalysisVariablesPerFunction |
| 957 | << " max variables per function.\n" |
| 958 | << " " << NumUninitAnalysisBlockVisits << " block visits.\n" |
| 959 | << " " << AvgUninitBlockVisitsPerFunction |
| 960 | << " average block visits per function.\n" |
| 961 | << " " << MaxUninitAnalysisBlockVisitsPerFunction |
| 962 | << " max block visits per function.\n"; |
Ted Kremenek | dbdbaaf | 2010-03-20 21:06:02 +0000 | [diff] [blame] | 963 | } |